From e75d8efdfcf744d6683bcaa3b48be38c0966ec2f Mon Sep 17 00:00:00 2001 From: ZeroHD Date: Wed, 9 Oct 2019 18:30:54 +0200 Subject: [PATCH] Dynmap Marker Command (#42) --- docs/source/changelog/index.rst | 3 +- docs/source/changelog/v1.9.rst | 16 +++++ docs/source/commands.rst | 2 + docs/source/permissions.rst | 4 +- pom.xml | 2 +- src/main/java/xyz/etztech/qol/QoL.java | 60 +++++++++++++++++++ .../etztech/qol/commands/MarkerCommand.java | 38 ++++++++++++ .../etztech/qol/listeners/JoinListener.java | 19 ++++++ src/main/resources/plugin.yml | 6 ++ 9 files changed, 147 insertions(+), 3 deletions(-) create mode 100644 docs/source/changelog/v1.9.rst create mode 100644 src/main/java/xyz/etztech/qol/commands/MarkerCommand.java diff --git a/docs/source/changelog/index.rst b/docs/source/changelog/index.rst index b5b0006..2b34c62 100644 --- a/docs/source/changelog/index.rst +++ b/docs/source/changelog/index.rst @@ -13,4 +13,5 @@ Changelogs v1.5 v1.6 v1.7 - v1.8 \ No newline at end of file + v1.8 + v1.9 <1.9> \ No newline at end of file diff --git a/docs/source/changelog/v1.9.rst b/docs/source/changelog/v1.9.rst new file mode 100644 index 0000000..83b41db --- /dev/null +++ b/docs/source/changelog/v1.9.rst @@ -0,0 +1,16 @@ +.. include:: ../common.rst + +.. _qol_v1.9: + +QoL v1.9 +======== + +Additions +--------- +* `Marker Command`_ - allows a player to create a marker on the dynmap at their current location. + + + +Bug Fixes +--------- +None \ No newline at end of file diff --git a/docs/source/commands.rst b/docs/source/commands.rst index 9267bf1..a7e8c34 100644 --- a/docs/source/commands.rst +++ b/docs/source/commands.rst @@ -44,3 +44,5 @@ Alias ``/names`` and ``/name`` ``/checkup `` Start a checkup, teleporting to all online players. ``/dynmaplink [] []`` Get a link to Dynmap with your current location. Optionally choose the map (flat, surface, etc.) and zoom level. + +``/marker`` Creates a marker on the dynmap at the players current location. diff --git a/docs/source/permissions.rst b/docs/source/permissions.rst index 6137788..6c5e8f1 100644 --- a/docs/source/permissions.rst +++ b/docs/source/permissions.rst @@ -48,4 +48,6 @@ Permissions ``qol.checkup`` - Ability to use the Checkup command -``qol.discord`` - Use Discord (markdown) syntax for chat formatting \ No newline at end of file +``qol.discord`` - Use Discord (markdown) syntax for chat formatting + +``qol.marker`` - Ability to use the Marker command \ No newline at end of file diff --git a/pom.xml b/pom.xml index 6af587b..f202732 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ xyz.etztech QoL - 1.8 + 1.9 jar diff --git a/src/main/java/xyz/etztech/qol/QoL.java b/src/main/java/xyz/etztech/qol/QoL.java index a580e4e..4f6b5bc 100644 --- a/src/main/java/xyz/etztech/qol/QoL.java +++ b/src/main/java/xyz/etztech/qol/QoL.java @@ -3,11 +3,16 @@ package xyz.etztech.qol; import net.ess3.api.IEssentials; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.Location; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import org.dynmap.DynmapAPI; +import org.dynmap.markers.Marker; +import org.dynmap.markers.MarkerAPI; +import org.dynmap.markers.MarkerIcon; +import org.dynmap.markers.MarkerSet; import xyz.etztech.qol.commands.*; import xyz.etztech.qol.listeners.*; import xyz.etztech.qol.other.GriefAlert; @@ -19,9 +24,15 @@ import java.util.logging.Logger; public class QoL extends JavaPlugin { + static private final String qolMarkerSetName = "qolMarkerSet"; + static private final String qolMarkerSetLabel = "QoL Markers"; + static private final String qolMarkerIcon = "blueflag"; + private static QoL instance; private IEssentials essentials = null; private DynmapAPI dynmap = null; + private MarkerAPI markerAPI = null; + private MarkerSet playerMarkerSet = null; public static FileConfiguration config; private Logger log = Logger.getLogger( "Minecraft" ); @@ -52,6 +63,26 @@ public class QoL extends JavaPlugin { if (Bukkit.getPluginManager().isPluginEnabled("dynmap")) { log("Hooked into Dynmap."); dynmap = (DynmapAPI) Bukkit.getPluginManager().getPlugin("dynmap"); + + // Marker setup + if (dynmap != null) { + markerAPI = dynmap.getMarkerAPI(); + + playerMarkerSet = markerAPI.getMarkerSet(qolMarkerSetName); + + if (playerMarkerSet == null) { + playerMarkerSet = markerAPI.createMarkerSet(qolMarkerSetName, qolMarkerSetLabel, null, true); + } + + if (playerMarkerSet == null) { + log("Unable to create marker set"); + } + else { + playerMarkerSet.setHideByDefault(true); + } + + + } } if( isEnabled() ) { @@ -110,6 +141,12 @@ public class QoL extends JavaPlugin { DynmapLinkCommand dynmapLinkCommand = new DynmapLinkCommand(this); this.getCommand("dynmaplink").setExecutor(dynmapLinkCommand); + if (dynmap != null) { + MarkerCommand markerCommand = new MarkerCommand(this); + this.getCommand("marker").setExecutor(markerCommand); + } + + if (getConfig().getStringList("list").size() > 0) { ListCommand listCommand = new ListCommand(this); this.getCommand("list").setExecutor(listCommand); @@ -308,5 +345,28 @@ public class QoL extends JavaPlugin { public void updatePlayerViewDistance(Player player) { //player.setViewDistance(viewDistances.getOrDefault(player.getWorld().getName().toLowerCase(), getServer().getViewDistance())); } + + public MarkerSet getPlayerMarkerSet() { + return playerMarkerSet; + } + + public void createMarkerAtPlayer(Player player) { + Location location = player.getLocation(); + MarkerIcon icon = markerAPI.getMarkerIcon(qolMarkerIcon); + + Marker playerMarker = getPlayerMarker(player); + + if (playerMarker != null) { + playerMarker.deleteMarker(); + } + + playerMarkerSet.createMarker(EtzTechUtil.formatUUID(player.getUniqueId().toString(), false), player.getName(), player.getWorld().getName(), location.getX(), location.getY(), location.getZ(), icon, true); + } + + public Marker getPlayerMarker(Player player) { + String uuid = EtzTechUtil.formatUUID(player.getUniqueId().toString(), false); + + return playerMarkerSet.findMarker(uuid); + } } diff --git a/src/main/java/xyz/etztech/qol/commands/MarkerCommand.java b/src/main/java/xyz/etztech/qol/commands/MarkerCommand.java new file mode 100644 index 0000000..34bfd9d --- /dev/null +++ b/src/main/java/xyz/etztech/qol/commands/MarkerCommand.java @@ -0,0 +1,38 @@ + +package xyz.etztech.qol.commands; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import xyz.etztech.qol.EtzTechUtil; +import xyz.etztech.qol.Lang; +import xyz.etztech.qol.QoL; + + +public class MarkerCommand implements CommandExecutor { + QoL plugin; + + public MarkerCommand(QoL paramQoL) + { + this.plugin = paramQoL; + } + + @Override + public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) { + if (!( commandSender instanceof Player)) { + EtzTechUtil.sms(commandSender, Lang.NO_CONSOLE.getDef()); + return true; + } + if (!commandSender.hasPermission("qol.marker")) { + EtzTechUtil.sms(commandSender, Lang.NO_PERMISSION.getDef()); + return true; + } + + plugin.createMarkerAtPlayer((Player) commandSender); + + EtzTechUtil.sms(commandSender, "Location Marker Created!"); + + return true; + } +} \ No newline at end of file diff --git a/src/main/java/xyz/etztech/qol/listeners/JoinListener.java b/src/main/java/xyz/etztech/qol/listeners/JoinListener.java index 1af0ade..c744284 100644 --- a/src/main/java/xyz/etztech/qol/listeners/JoinListener.java +++ b/src/main/java/xyz/etztech/qol/listeners/JoinListener.java @@ -8,6 +8,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerLoginEvent; +import org.dynmap.markers.Marker; import xyz.etztech.qol.QoL; import xyz.etztech.qol.commands.CheckupCommand; @@ -56,6 +57,24 @@ public class JoinListener implements Listener { } } + // Remove player marker + if (!player.hasPermission("qol.marker") && (plugin.getPlayerMarkerSet() != null)) { + Marker playerMarker = plugin.getPlayerMarker(player); + + if (playerMarker != null) { + playerMarker.deleteMarker(); + } + } + // Update marker name + else if (player.hasPermission("qol.marker")) { + Marker playerMarker = plugin.getPlayerMarker(player); + + if (playerMarker != null) { + playerMarker.setLabel(player.getName()); + } + } + + plugin.updatePlayerViewDistance(player); CheckupCommand.join(player); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 3e54995..5b558fb 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -48,6 +48,9 @@ commands: dynmaplink: description: Dynmap Link command aliases: [dlink] + marker: + description: Dynmap marker command + aliases: [mark] permissions: qol.admin: description: Ability to reload the plugin @@ -119,5 +122,8 @@ permissions: default: op children: qol.timeout.bypass: true + qol.marker: + description: Ability to use the marker command + default: op