-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1bad093
commit 9cca147
Showing
9 changed files
with
175 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/com/itsmaxymoo/aliasshowtext/textfunction/GetDistance2D.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.itsmaxymoo.aliasshowtext.textfunction; | ||
|
||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
public class GetDistance2D extends TextFunction { | ||
@Override | ||
public Pattern getRegex() { | ||
return Pattern.compile("(distance2d) +-?[0-9]+ +-?[0-9]+"); | ||
} | ||
|
||
@Override | ||
public String compute(CommandSender sender, String[] args) throws InvalidSenderTypeException { | ||
if (!(sender instanceof Player)) { | ||
throw new InvalidSenderTypeException("You must be a player!"); | ||
} | ||
|
||
Player player = (Player) sender; | ||
|
||
int tx, tz; | ||
|
||
try { | ||
tx = Integer.parseInt(args[1]); | ||
tz = Integer.parseInt(args[2]); | ||
} catch (NumberFormatException e) { | ||
return "ERROR"; | ||
} | ||
|
||
int px = player.getLocation().getBlockX(); | ||
int pz = player.getLocation().getBlockZ(); | ||
|
||
return "" + Math.round( | ||
Math.sqrt(Math.pow(tx - px, 2) + Math.pow(tz - pz, 2)) | ||
); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/itsmaxymoo/aliasshowtext/textfunction/GetDistance3D.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.itsmaxymoo.aliasshowtext.textfunction; | ||
|
||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
public class GetDistance3D extends TextFunction { | ||
@Override | ||
public Pattern getRegex() { | ||
return Pattern.compile("(distance3d) +-?[0-9]+ +-?[0-9]+ +-?[0-9]+"); | ||
} | ||
|
||
@Override | ||
public String compute(CommandSender sender, String[] args) throws InvalidSenderTypeException { | ||
if (!(sender instanceof Player)) { | ||
throw new InvalidSenderTypeException("You must be a player!"); | ||
} | ||
|
||
Player player = (Player) sender; | ||
|
||
int tx, ty, tz; | ||
|
||
try { | ||
tx = Integer.parseInt(args[1]); | ||
ty = Integer.parseInt(args[2]); | ||
tz = Integer.parseInt(args[3]); | ||
} catch (NumberFormatException e) { | ||
return "ERROR"; | ||
} | ||
|
||
int px = player.getLocation().getBlockX(); | ||
int py = player.getLocation().getBlockY(); | ||
int pz = player.getLocation().getBlockZ(); | ||
|
||
return "" + Math.round( | ||
Math.sqrt(Math.pow(tx - px, 2) + Math.pow(ty - py, 2) + Math.pow(tz - pz, 2)) | ||
); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/itsmaxymoo/aliasshowtext/textfunction/InvalidSenderTypeException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.itsmaxymoo.aliasshowtext.textfunction; | ||
|
||
public class InvalidSenderTypeException extends Exception{ | ||
public InvalidSenderTypeException(String message){ | ||
super(message); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/itsmaxymoo/aliasshowtext/textfunction/TextFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.itsmaxymoo.aliasshowtext.textfunction; | ||
|
||
import org.bukkit.command.CommandSender; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
public abstract class TextFunction { | ||
public abstract Pattern getRegex(); | ||
|
||
public abstract String compute(CommandSender sender, String[] args) throws InvalidSenderTypeException; | ||
} |