fixed location parser negative coords not working

This commit is contained in:
ImproperIssues
2023-09-10 00:22:56 -07:00
parent f35ba0e8b0
commit 0df381d378
2 changed files with 27 additions and 11 deletions

View File

@@ -9,7 +9,7 @@ public class LocationParser {
private final double x, y, z; private final double x, y, z;
public LocationParser(String input) { public LocationParser(String input) {
String[] secs = input.replaceAll("[^0-9 ]", "").trim().split(" "); String[] secs = input.replaceAll("[^0-9 -]", "").trim().split(" ");
double x = 0.0; double x = 0.0;
double y = 0.0; double y = 0.0;
double z = 0.0; double z = 0.0;
@@ -35,7 +35,7 @@ public class LocationParser {
} }
public LocationParser(String input, Location relativeTo) { public LocationParser(String input, Location relativeTo) {
String[] secs = input.replaceAll("[^0-9 ~]", "").trim().split(" "); String[] secs = input.replaceAll("[^0-9 ~-]", "").trim().split(" ");
double x = 0.0; double x = 0.0;
double y = 0.0; double y = 0.0;
double z = 0.0; double z = 0.0;
@@ -43,21 +43,21 @@ public class LocationParser {
for (int i = 0; i < secs.length; i++) { for (int i = 0; i < secs.length; i++) {
switch (i) { switch (i) {
case 0 -> { case 0 -> {
String parsing = secs[i].replaceAll("[^0-9]", ""); String parsing = secs[i].replaceAll("[^0-9-]", "");
if (!parsing.isEmpty()) { if (!parsing.isEmpty()) {
x = Double.parseDouble(parsing); x = Double.parseDouble(parsing);
} }
x = secs[i].contains("~") ? relativeTo.getX() + x : x; x = secs[i].contains("~") ? relativeTo.getX() + x : x;
} }
case 1 -> { case 1 -> {
String parsing = secs[i].replaceAll("[^0-9]", ""); String parsing = secs[i].replaceAll("[^0-9-]", "");
if (!parsing.isEmpty()) { if (!parsing.isEmpty()) {
y = Double.parseDouble(parsing); y = Double.parseDouble(parsing);
} }
y = secs[i].contains("~") ? relativeTo.getY() + y : y; y = secs[i].contains("~") ? relativeTo.getY() + y : y;
} }
case 2 -> { case 2 -> {
String parsing = secs[i].replaceAll("[^0-9]", ""); String parsing = secs[i].replaceAll("[^0-9-]", "");
if (!parsing.isEmpty()) { if (!parsing.isEmpty()) {
z = Double.parseDouble(parsing); z = Double.parseDouble(parsing);
} }

View File

@@ -12,6 +12,7 @@ import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor; import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
@@ -53,13 +54,12 @@ public class TimerCommand implements TabExecutor {
} }
Material type = Material.valueOf(args[7].toUpperCase()); Material type = Material.valueOf(args[7].toUpperCase());
timers.put(timer, new TimerEntry(timer, tag, System.currentTimeMillis() + ticks * 50L, () -> { timers.put(timer, new TimerEntry(timer, tag, System.currentTimeMillis() + ticks * 50L, () -> parser.getBlock(world).setType(type)));
parser.getBlock(world).setType(type);
timers.remove(timer);
}));
Bukkit.getScheduler().runTaskLater(OgreDupeAlias.instance, () -> { Bukkit.getScheduler().runTaskLater(OgreDupeAlias.instance, () -> {
if (timers.containsKey(timer)) { if (timers.containsKey(timer)) {
timers.get(timer).endAction().run(); TimerEntry entry = timers.get(timer);
timers.remove(timer);
entry.endAction().run();
} }
}, ticks); }, ticks);
@@ -87,6 +87,17 @@ public class TimerCommand implements TabExecutor {
@Override @Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) { public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
List<String> l = new ArrayList<>(); List<String> l = new ArrayList<>();
World world;
if (sender instanceof Player source) {
world = source.getWorld();
}
else if (sender instanceof BlockCommandSender source) {
world = source.getBlock().getWorld();
}
else {
return l;
}
switch (args.length) { switch (args.length) {
case 1 -> l.addAll(List.of("stop", "set")); case 1 -> l.addAll(List.of("stop", "set"));
@@ -102,7 +113,12 @@ public class TimerCommand implements TabExecutor {
} }
case 3 -> { case 3 -> {
switch (args[0]) { switch (args[0]) {
case "set" -> l.add(args[1]); case "set" -> {
world.getEntities().stream().filter(e -> e instanceof Player).map(Entity::getScoreboardTags).forEach(l::addAll);
if (l.isEmpty()) {
l.add(args[1]);
}
}
} }
} }
case 4 -> { case 4 -> {