From 481b2c4004aa436becdfa059505e9afa86e9dab1 Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 11 May 2020 22:21:17 +0200 Subject: [PATCH] feat: add/coords command --- .../main/java/de/cliffbreak/varo/Varo.java | 6 +++ .../varo/commands/CoordsCommand.java | 49 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 varo/src/main/java/de/cliffbreak/varo/commands/CoordsCommand.java diff --git a/varo/src/main/java/de/cliffbreak/varo/Varo.java b/varo/src/main/java/de/cliffbreak/varo/Varo.java index b05c745..c788fd3 100644 --- a/varo/src/main/java/de/cliffbreak/varo/Varo.java +++ b/varo/src/main/java/de/cliffbreak/varo/Varo.java @@ -8,6 +8,7 @@ import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.configuration.file.YamlConfiguration; +import de.cliffbreak.varo.commands.CoordsCommand; import de.cliffbreak.varo.commands.VaroCommand; import de.cliffbreak.varo.commands.VaroTabCompleter; import de.cliffbreak.varo.listeners.BannedActionListener; @@ -68,6 +69,7 @@ public class Varo extends JavaPlugin { this.getCommand("varo").setExecutor(new VaroCommand(this)); this.getCommand("varo").setTabCompleter(new VaroTabCompleter(this)); + this.getCommand("coords").setExecutor(new CoordsCommand(this)); this.varoUtils.init(); } @@ -105,6 +107,10 @@ public class Varo extends JavaPlugin { return this.banUtils; } + public TeamManager getTeamManager() { + return teamManager; + } + public boolean canCreatePortal() { return this.canCreatePortal; } diff --git a/varo/src/main/java/de/cliffbreak/varo/commands/CoordsCommand.java b/varo/src/main/java/de/cliffbreak/varo/commands/CoordsCommand.java new file mode 100644 index 0000000..3c126d1 --- /dev/null +++ b/varo/src/main/java/de/cliffbreak/varo/commands/CoordsCommand.java @@ -0,0 +1,49 @@ +package de.cliffbreak.varo.commands; + +import java.util.HashMap; +import java.util.UUID; + +import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; + +import de.cliffbreak.varo.Varo; + +public class CoordsCommand implements CommandExecutor { + + private final Varo plugin; + private final HashMap playerCoords; + + public CoordsCommand(final Varo plugin) { + this.plugin = plugin; + this.playerCoords = new HashMap(); + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (sender instanceof Player) { + Player p = (Player) sender; + if (playerCoords.keySet().contains(p.getUniqueId())) { + playerCoords.get(p.getUniqueId()).cancel(); + playerCoords.remove(p.getUniqueId()); + } else { + playerCoords.put(p.getUniqueId(), new BukkitRunnable() { + @Override + public void run() { + final Location loc = p.getLocation(); + p.sendActionBar(String.format("§6§l%d / %d / %d", (int) Math.floor(loc.getX()), + (int) Math.floor(loc.getY()), (int) Math.floor(loc.getZ()))); + } + }.runTaskTimerAsynchronously(this.plugin, 0, 20)); + } + } else { + sender.sendMessage("§c§lFehler:§r§c Dieses Kommando kann nur durch einen Spieler ausgeführt werden."); + } + return true; + } + +} \ No newline at end of file