diff --git a/src/main/java/fun/ogre/ogredupealias/commands/LocationParser.java b/src/main/java/fun/ogre/ogredupealias/commands/LocationParser.java index 7fd7cf1..8d371a8 100644 --- a/src/main/java/fun/ogre/ogredupealias/commands/LocationParser.java +++ b/src/main/java/fun/ogre/ogredupealias/commands/LocationParser.java @@ -9,7 +9,7 @@ public class LocationParser { private final double x, y, z; 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 y = 0.0; double z = 0.0; @@ -35,7 +35,7 @@ public class LocationParser { } 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 y = 0.0; double z = 0.0; @@ -43,21 +43,21 @@ public class LocationParser { for (int i = 0; i < secs.length; i++) { switch (i) { case 0 -> { - String parsing = secs[i].replaceAll("[^0-9]", ""); + String parsing = secs[i].replaceAll("[^0-9-]", ""); if (!parsing.isEmpty()) { x = Double.parseDouble(parsing); } x = secs[i].contains("~") ? relativeTo.getX() + x : x; } case 1 -> { - String parsing = secs[i].replaceAll("[^0-9]", ""); + String parsing = secs[i].replaceAll("[^0-9-]", ""); if (!parsing.isEmpty()) { y = Double.parseDouble(parsing); } y = secs[i].contains("~") ? relativeTo.getY() + y : y; } case 2 -> { - String parsing = secs[i].replaceAll("[^0-9]", ""); + String parsing = secs[i].replaceAll("[^0-9-]", ""); if (!parsing.isEmpty()) { z = Double.parseDouble(parsing); } diff --git a/src/main/java/fun/ogre/ogredupealias/commands/commands/TimerCommand.java b/src/main/java/fun/ogre/ogredupealias/commands/commands/TimerCommand.java index 871f1bf..b09ba27 100644 --- a/src/main/java/fun/ogre/ogredupealias/commands/commands/TimerCommand.java +++ b/src/main/java/fun/ogre/ogredupealias/commands/commands/TimerCommand.java @@ -12,6 +12,7 @@ import org.bukkit.command.BlockCommandSender; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import java.util.ArrayList; @@ -53,13 +54,12 @@ public class TimerCommand implements TabExecutor { } Material type = Material.valueOf(args[7].toUpperCase()); - timers.put(timer, new TimerEntry(timer, tag, System.currentTimeMillis() + ticks * 50L, () -> { - parser.getBlock(world).setType(type); - timers.remove(timer); - })); + timers.put(timer, new TimerEntry(timer, tag, System.currentTimeMillis() + ticks * 50L, () -> parser.getBlock(world).setType(type))); Bukkit.getScheduler().runTaskLater(OgreDupeAlias.instance, () -> { if (timers.containsKey(timer)) { - timers.get(timer).endAction().run(); + TimerEntry entry = timers.get(timer); + timers.remove(timer); + entry.endAction().run(); } }, ticks); @@ -87,6 +87,17 @@ public class TimerCommand implements TabExecutor { @Override public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { List 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) { case 1 -> l.addAll(List.of("stop", "set")); @@ -102,7 +113,12 @@ public class TimerCommand implements TabExecutor { } case 3 -> { 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 -> {