Added the ability to create multiple markers (#48)

Added the ability to create multiple markers

+ Player's can name markers to whatever they want
+ Internally markers are refereed by the player's `UUID NAME`
+ Markers are no longer automatically removed
+ Marker count is limited to a number set by the `qol.marker.limit.#` perm
+ Marker layer can be renamed and configured to hidden or shown by default.

Co-authored-by: Joey Hines <joey@ahines.net>
Reviewed-on: https://git.etztech.xyz/Minecraft/QoL/pulls/48
Reviewed-by: Etzelia <etzelia@hotmail.com>
1.16
Joey Hines 2020-07-02 16:40:10 +02:00
parent 2136c712f2
commit 13ce2096f8
10 changed files with 151 additions and 50 deletions

View File

@ -9,8 +9,6 @@ Additions
--------- ---------
* `Marker Command`_ - allows a player to create a marker on the dynmap at their current location. * `Marker Command`_ - allows a player to create a marker on the dynmap at their current location.
Bug Fixes Bug Fixes
--------- ---------
None None

View File

@ -45,4 +45,8 @@ Alias ``/names`` and ``/name``
``/dynmaplink [<map>] [<zoom>]`` Get a link to Dynmap with your current location. Optionally choose the map (flat, surface, etc.) and zoom level. ``/dynmaplink [<map>] [<zoom>]`` Get a link to Dynmap with your current location. Optionally choose the map (flat, surface, etc.) and zoom level.
``/marker <set|remove>`` Creates or removes a marker on the dynmap at the players current location. ``/marker <set> <name>`` Creates a marker on the dynmap at the players current location.
``/marker <remove> <name>`` Removes a marker a user has created.
``/marker <list>`` Lists all the markers a player owns.

View File

@ -63,4 +63,5 @@ Each world can have its own view distance. View distances of each world can be s
QoL Dynmap Markers 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 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.

View File

@ -31,7 +31,7 @@
<dependency> <dependency>
<groupId>com.destroystokyo.paper</groupId> <groupId>com.destroystokyo.paper</groupId>
<artifactId>paper-api</artifactId> <artifactId>paper-api</artifactId>
<version>1.14.3-R0.1-SNAPSHOT</version> <version>1.15.2-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
@ -41,8 +41,8 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.ess3</groupId> <groupId>net.ess3</groupId>
<artifactId>Essentials</artifactId> <artifactId>EssentialsX</artifactId>
<version>2.14-SNAPSHOT</version> <version>2.17.2</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>us.dynmap</groupId> <groupId>us.dynmap</groupId>
@ -72,7 +72,7 @@
</repository> </repository>
<repository> <repository>
<id>ess-repo</id> <id>ess-repo</id>
<url>http://repo.ess3.net/content/groups/essentials</url> <url>https://ci.ender.zone/plugin/repository/everything/</url>
</repository> </repository>
<repository> <repository>
<id>mvn-repo</id> <id>mvn-repo</id>

View File

@ -7,6 +7,7 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionAttachmentInfo;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStream; import java.io.InputStream;
@ -14,6 +15,7 @@ import java.io.InputStreamReader;
import java.net.URL; import java.net.URL;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
public class EtzTechUtil public class EtzTechUtil
@ -36,8 +38,6 @@ public class EtzTechUtil
paramPlayer.sendMessage(ChatColor.translateAlternateColorCodes('&', paramString)); paramPlayer.sendMessage(ChatColor.translateAlternateColorCodes('&', paramString));
} }
public static UUID asUUID(String uuid) { public static UUID asUUID(String uuid) {
try { try {
if (uuid.contains("-") && uuid.length() == 36) { if (uuid.contains("-") && uuid.length() == 36) {
@ -116,7 +116,18 @@ public class EtzTechUtil
return minutes*60*20; return minutes*60*20;
} }
public static int getPermValue(String perm, Set<PermissionAttachmentInfo> 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;
}

View File

@ -25,7 +25,6 @@ import java.util.logging.Logger;
public class QoL extends JavaPlugin { public class QoL extends JavaPlugin {
static private final String qolMarkerSetName = "qolMarkerSet"; static private final String qolMarkerSetName = "qolMarkerSet";
static private final String qolMarkerSetLabel = "QoL Markers";
private String qolMarkerIcon = null; private String qolMarkerIcon = null;
private static QoL instance; private static QoL instance;
@ -33,6 +32,8 @@ public class QoL extends JavaPlugin {
private DynmapAPI dynmap = null; private DynmapAPI dynmap = null;
private MarkerAPI markerAPI = null; private MarkerAPI markerAPI = null;
private MarkerSet playerMarkerSet = null; private MarkerSet playerMarkerSet = null;
private boolean qolMarkerLayerShow = false;
private String qolMarkerSetLabel = null;
public static FileConfiguration config; public static FileConfiguration config;
private Logger log = Logger.getLogger( "Minecraft" ); private Logger log = Logger.getLogger( "Minecraft" );
@ -78,7 +79,8 @@ public class QoL extends JavaPlugin {
log("Unable to create marker set"); log("Unable to create marker set");
} }
else { else {
playerMarkerSet.setHideByDefault(true); playerMarkerSet.setHideByDefault(!qolMarkerLayerShow);
playerMarkerSet.setMarkerSetLabel(qolMarkerSetLabel);
} }
@ -144,6 +146,7 @@ public class QoL extends JavaPlugin {
if (dynmap != null) { if (dynmap != null) {
MarkerCommand markerCommand = new MarkerCommand(this); MarkerCommand markerCommand = new MarkerCommand(this);
this.getCommand("marker").setExecutor(markerCommand); 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"); 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; return playerMarkerSet;
} }
public void createMarkerAtPlayer(Player player) { public List<Marker> getPlayerMarkers(Player player) {
ArrayList<Marker> 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(); Location location = player.getLocation();
MarkerIcon icon = markerAPI.getMarkerIcon(qolMarkerIcon); MarkerIcon icon = markerAPI.getMarkerIcon(qolMarkerIcon);
Marker playerMarker = getPlayerMarker(player); Marker playerMarker = getPlayerMarker(player, name);
if (playerMarker != null) { if (playerMarker != null) {
playerMarker.deleteMarker(); 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) { public Marker getPlayerMarker(Player player, String name) {
String uuid = EtzTechUtil.formatUUID(player.getUniqueId().toString(), false); Marker marker = playerMarkerSet.findMarker(getMarkerName(player, name));
// Find marker using old naming system
if (marker == null) {
String uuid = EtzTechUtil.formatUUID(player.getUniqueId().toString(), false);
return playerMarkerSet.findMarker(uuid); return playerMarkerSet.findMarker(uuid);
} }
else {
return marker;
}
}
} }

View File

@ -4,15 +4,22 @@ package xyz.etztech.qol.commands;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.TabExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.dynmap.markers.Marker;
import org.dynmap.markers.MarkerSet;
import xyz.etztech.qol.EtzTechUtil; import xyz.etztech.qol.EtzTechUtil;
import xyz.etztech.qol.Lang; import xyz.etztech.qol.Lang;
import xyz.etztech.qol.QoL; 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; QoL plugin;
List<String> subCommandList = Arrays.asList("set", "remove", "list");
public MarkerCommand(QoL paramQoL) public MarkerCommand(QoL paramQoL)
{ {
@ -25,29 +32,92 @@ public class MarkerCommand implements CommandExecutor {
EtzTechUtil.sms(commandSender, Lang.NO_CONSOLE.getDef()); EtzTechUtil.sms(commandSender, Lang.NO_CONSOLE.getDef());
return true; 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; return true;
} }
if (args.length < 1) { if (args.length < 1) {
EtzTechUtil.sms(commandSender, ChatColor.RED + "/marker set"); EtzTechUtil.sms(player, ChatColor.RED + "/marker set");
EtzTechUtil.sms(commandSender, ChatColor.RED + "/marker remove"); EtzTechUtil.sms(player, ChatColor.RED + "/marker remove");
return true; return true;
} }
else { else {
String action = args[0].toLowerCase(); 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")) { if (action.equals("set")) {
plugin.createMarkerAtPlayer((Player) commandSender); int marker_count = plugin.getPlayerMarkers(player).size();
EtzTechUtil.sms(commandSender, ChatColor.GREEN + "Location Marker Created!");
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")) { else if (action.equals("remove")) {
plugin.getPlayerMarker((Player)commandSender).deleteMarker(); Marker marker = plugin.getPlayerMarker(player, name);
EtzTechUtil.sms(commandSender, ChatColor.GREEN + "Location Marker Removed!"); 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; return true;
} }
@Override
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) {
for (String arg: strings) {
if (subCommandList.contains(arg)) {
return null;
}
}
return subCommandList;
}
} }

View File

@ -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); plugin.updatePlayerViewDistance(player);
CheckupCommand.join(player); CheckupCommand.join(player);

View File

@ -103,7 +103,13 @@ spec-confirm:
# Dynmap link # Dynmap link
# Leave url blank to disable # Leave url blank to disable
dynmap: dynmap:
# Dynmap marker to use
marker_icon: "blueflag" 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: "" url: ""
defaults: defaults:
map: "surface" map: "surface"

View File

@ -125,5 +125,5 @@ permissions:
qol.marker: qol.marker:
description: Ability to use the marker command description: Ability to use the marker command
default: op default: op
children:
qol.marker.limit: true