diff --git a/docs/source/changelog/v1.9.rst b/docs/source/changelog/v1.9.rst index 83b41db..c3e8d6c 100644 --- a/docs/source/changelog/v1.9.rst +++ b/docs/source/changelog/v1.9.rst @@ -9,8 +9,6 @@ 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 4ce2631..05932f8 100644 --- a/docs/source/commands.rst +++ b/docs/source/commands.rst @@ -45,4 +45,8 @@ Alias ``/names`` and ``/name`` ``/dynmaplink [] []`` Get a link to Dynmap with your current location. Optionally choose the map (flat, surface, etc.) and zoom level. -``/marker `` Creates or removes a marker on the dynmap at the players current location. +``/marker `` Creates a marker on the dynmap at the players current location. + +``/marker `` Removes a marker a user has created. + +``/marker `` Lists all the markers a player owns. diff --git a/docs/source/misc.rst b/docs/source/misc.rst index a7c49d2..7c0a788 100644 --- a/docs/source/misc.rst +++ b/docs/source/misc.rst @@ -63,4 +63,5 @@ Each world can have its own view distance. View distances of each world can be s QoL Dynmap Markers ------------------ -QoL Markers are placed on their own layer hidden by default. A player with permission can have one marker. When a player loses the `qol.marker` permission, their marker is removed. The icon of the marker can be set in the `dynmap.marker_icon` config option \ No newline at end of file +QoL Markers are placed on their own layer which can be configured to be shown or hidden. The icon of the marker can be set in the `dynmap.marker_icon` config option. +The number of markers a player can have is set by the `qol.marker.limit.#` permission. \ No newline at end of file diff --git a/pom.xml b/pom.xml index f202732..2070ef2 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ com.destroystokyo.paper paper-api - 1.14.3-R0.1-SNAPSHOT + 1.15.2-R0.1-SNAPSHOT provided @@ -41,8 +41,8 @@ net.ess3 - Essentials - 2.14-SNAPSHOT + EssentialsX + 2.17.2 us.dynmap @@ -70,9 +70,9 @@ dynmap-repo http://repo.mikeprimm.com/ - - ess-repo - http://repo.ess3.net/content/groups/essentials + + ess-repo + https://ci.ender.zone/plugin/repository/everything/ mvn-repo diff --git a/src/main/java/xyz/etztech/qol/EtzTechUtil.java b/src/main/java/xyz/etztech/qol/EtzTechUtil.java index 0dcead6..9364da6 100644 --- a/src/main/java/xyz/etztech/qol/EtzTechUtil.java +++ b/src/main/java/xyz/etztech/qol/EtzTechUtil.java @@ -7,6 +7,7 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.permissions.PermissionAttachmentInfo; import java.io.BufferedReader; import java.io.InputStream; @@ -14,6 +15,7 @@ import java.io.InputStreamReader; import java.net.URL; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.Set; import java.util.UUID; public class EtzTechUtil @@ -36,8 +38,6 @@ public class EtzTechUtil paramPlayer.sendMessage(ChatColor.translateAlternateColorCodes('&', paramString)); } - - public static UUID asUUID(String uuid) { try { if (uuid.contains("-") && uuid.length() == 36) { @@ -116,7 +116,18 @@ public class EtzTechUtil return minutes*60*20; } - + public static int getPermValue(String perm, Set permissions) { + int limit = 0; + for (PermissionAttachmentInfo permission : permissions) { + if (permission.getPermission().startsWith(perm + ".") && permission.getValue()) { + try { + int p = Integer.parseInt(permission.getPermission().replaceFirst(perm + ".", "")); + limit = limit > p ? limit : p; + } catch (Exception ignored) {} + } + } + return limit; + } diff --git a/src/main/java/xyz/etztech/qol/QoL.java b/src/main/java/xyz/etztech/qol/QoL.java index 4dfc95e..8edbfce 100644 --- a/src/main/java/xyz/etztech/qol/QoL.java +++ b/src/main/java/xyz/etztech/qol/QoL.java @@ -25,7 +25,6 @@ import java.util.logging.Logger; public class QoL extends JavaPlugin { static private final String qolMarkerSetName = "qolMarkerSet"; - static private final String qolMarkerSetLabel = "QoL Markers"; private String qolMarkerIcon = null; private static QoL instance; @@ -33,6 +32,8 @@ public class QoL extends JavaPlugin { private DynmapAPI dynmap = null; private MarkerAPI markerAPI = null; private MarkerSet playerMarkerSet = null; + private boolean qolMarkerLayerShow = false; + private String qolMarkerSetLabel = null; public static FileConfiguration config; private Logger log = Logger.getLogger( "Minecraft" ); @@ -78,7 +79,8 @@ public class QoL extends JavaPlugin { log("Unable to create marker set"); } else { - playerMarkerSet.setHideByDefault(true); + playerMarkerSet.setHideByDefault(!qolMarkerLayerShow); + playerMarkerSet.setMarkerSetLabel(qolMarkerSetLabel); } @@ -144,6 +146,7 @@ public class QoL extends JavaPlugin { if (dynmap != null) { MarkerCommand markerCommand = new MarkerCommand(this); this.getCommand("marker").setExecutor(markerCommand); + this.getCommand("marker").setTabCompleter(markerCommand); } @@ -232,6 +235,8 @@ public class QoL extends JavaPlugin { } qolMarkerIcon = config.getString("dynmap.marker_icon", "blueflag"); + qolMarkerLayerShow = config.getBoolean("dynmap.marker_set_show", false); + qolMarkerSetLabel = config.getString("dynmap.marker_set_label", "QoL Markers"); } @@ -352,23 +357,47 @@ public class QoL extends JavaPlugin { return playerMarkerSet; } - public void createMarkerAtPlayer(Player player) { + public List getPlayerMarkers(Player player) { + ArrayList markers = new ArrayList<>(); + String player_uuid = EtzTechUtil.formatUUID(player.getUniqueId().toString(), true); + for (Marker marker: playerMarkerSet.getMarkers()) { + if (marker.getMarkerID().contains(player_uuid)) { + markers.add(marker); + } + } + + return markers; + } + + public String getMarkerName(Player player, String name) { + String uuid = EtzTechUtil.formatUUID(player.getUniqueId().toString(), true); + return uuid + " " + name; + } + + public void createMarkerAtPlayer(Player player, String name) { Location location = player.getLocation(); MarkerIcon icon = markerAPI.getMarkerIcon(qolMarkerIcon); - Marker playerMarker = getPlayerMarker(player); + Marker playerMarker = getPlayerMarker(player, name); 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); + playerMarkerSet.createMarker(getMarkerName(player, name), name, player.getWorld().getName(), location.getX(), location.getY(), location.getZ(), icon, true); } - public Marker getPlayerMarker(Player player) { - String uuid = EtzTechUtil.formatUUID(player.getUniqueId().toString(), false); + public Marker getPlayerMarker(Player player, String name) { + Marker marker = playerMarkerSet.findMarker(getMarkerName(player, name)); - return playerMarkerSet.findMarker(uuid); + // Find marker using old naming system + if (marker == null) { + String uuid = EtzTechUtil.formatUUID(player.getUniqueId().toString(), false); + return playerMarkerSet.findMarker(uuid); + } + else { + return marker; + } } } diff --git a/src/main/java/xyz/etztech/qol/commands/MarkerCommand.java b/src/main/java/xyz/etztech/qol/commands/MarkerCommand.java index 42af86d..90507a7 100644 --- a/src/main/java/xyz/etztech/qol/commands/MarkerCommand.java +++ b/src/main/java/xyz/etztech/qol/commands/MarkerCommand.java @@ -4,15 +4,22 @@ package xyz.etztech.qol.commands; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; +import org.bukkit.command.TabExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.dynmap.markers.Marker; +import org.dynmap.markers.MarkerSet; import xyz.etztech.qol.EtzTechUtil; import xyz.etztech.qol.Lang; import xyz.etztech.qol.QoL; +import java.util.Arrays; +import java.util.List; -public class MarkerCommand implements CommandExecutor { + +public class MarkerCommand implements CommandExecutor, TabExecutor{ QoL plugin; + List subCommandList = Arrays.asList("set", "remove", "list"); public MarkerCommand(QoL paramQoL) { @@ -25,29 +32,92 @@ public class MarkerCommand implements CommandExecutor { EtzTechUtil.sms(commandSender, Lang.NO_CONSOLE.getDef()); return true; } - if (!commandSender.hasPermission("qol.marker")) { - EtzTechUtil.sms(commandSender, Lang.NO_PERMISSION.getDef()); + + Player player = (Player) commandSender; + + if (!player.hasPermission("qol.marker")) { + EtzTechUtil.sms(player, Lang.NO_PERMISSION.getDef()); return true; } if (args.length < 1) { - EtzTechUtil.sms(commandSender, ChatColor.RED + "/marker set"); - EtzTechUtil.sms(commandSender, ChatColor.RED + "/marker remove"); + EtzTechUtil.sms(player, ChatColor.RED + "/marker set"); + EtzTechUtil.sms(player, ChatColor.RED + "/marker remove"); return true; } else { String action = args[0].toLowerCase(); + String name; + if (args.length > 1) { + String[] arr = Arrays.copyOfRange(args, 1, args.length); + + name = String.join(" ", arr); + } + else { + name = (player).getDisplayName(); + } + + if (name.length() > 25) { + EtzTechUtil.sms(player, ChatColor.RED + "Marker name too long, try a shorter name"); + return true; + } + if (action.equals("set")) { - plugin.createMarkerAtPlayer((Player) commandSender); - EtzTechUtil.sms(commandSender, ChatColor.GREEN + "Location Marker Created!"); + int marker_count = plugin.getPlayerMarkers(player).size(); + + if (marker_count >= EtzTechUtil.getPermValue("qol.marker.limit", player.getEffectivePermissions())) { + EtzTechUtil.sms(player, ChatColor.RED + "You can't add more markers, delete an old one first."); + return true; + } + + plugin.createMarkerAtPlayer(player, name); + EtzTechUtil.sms(player, ChatColor.GREEN + "Marker \"" + name + "\" created"); } else if (action.equals("remove")) { - plugin.getPlayerMarker((Player)commandSender).deleteMarker(); - EtzTechUtil.sms(commandSender, ChatColor.GREEN + "Location Marker Removed!"); + Marker marker = plugin.getPlayerMarker(player, name); + if (marker != null) { + marker.deleteMarker(); + EtzTechUtil.sms(player, ChatColor.GREEN + "Marker \"" + name +"\" removed."); + } + else { + EtzTechUtil.sms(player, ChatColor.RED + "You don't have a marker by that name"); + } + } + else if (action.equals("list")) { + MarkerSet markerSet = plugin.getPlayerMarkerSet(); + StringBuilder msg = new StringBuilder(); + int marker_count = 0; + + msg.append(ChatColor.GREEN); + msg.append("You have the following markers:\n"); + msg.append(ChatColor.YELLOW); + for (Marker marker: plugin.getPlayerMarkers(player)) { + msg.append(marker.getLabel()); + msg.append('\n'); + marker_count++; + } + + if (marker_count == 0) { + EtzTechUtil.sms(player, ChatColor.RED + "You don't have any markers"); + } + else { + EtzTechUtil.sms(player, msg.toString()); + } } } return true; } + + @Override + public List onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) { + for (String arg: strings) { + if (subCommandList.contains(arg)) { + return null; + } + } + + return subCommandList; + } } \ 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 c744284..b88de77 100644 --- a/src/main/java/xyz/etztech/qol/listeners/JoinListener.java +++ b/src/main/java/xyz/etztech/qol/listeners/JoinListener.java @@ -57,24 +57,6 @@ 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/config.yml b/src/main/resources/config.yml index cf2229b..6da7a24 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -103,7 +103,13 @@ spec-confirm: # Dynmap link # Leave url blank to disable dynmap: + # Dynmap marker to use marker_icon: "blueflag" + # Name of the marker layer + marker_set_label: "QoL Markers" + # Show the markers on the map by default + marker_set_show: false + # Limit to how many markers one player can have url: "" defaults: map: "surface" diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 5b558fb..c666af0 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -125,5 +125,5 @@ permissions: qol.marker: description: Ability to use the marker command default: op - - + children: + qol.marker.limit: true