forked from Minecraft/QoL
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
parent
2136c712f2
commit
13ce2096f8
|
@ -9,8 +9,6 @@ Additions
|
|||
---------
|
||||
* `Marker Command`_ - allows a player to create a marker on the dynmap at their current location.
|
||||
|
||||
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
None
|
|
@ -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.
|
||||
|
||||
``/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.
|
||||
|
|
|
@ -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
|
||||
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.
|
8
pom.xml
8
pom.xml
|
@ -31,7 +31,7 @@
|
|||
<dependency>
|
||||
<groupId>com.destroystokyo.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.14.3-R0.1-SNAPSHOT</version>
|
||||
<version>1.15.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -41,8 +41,8 @@
|
|||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ess3</groupId>
|
||||
<artifactId>Essentials</artifactId>
|
||||
<version>2.14-SNAPSHOT</version>
|
||||
<artifactId>EssentialsX</artifactId>
|
||||
<version>2.17.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>us.dynmap</groupId>
|
||||
|
@ -72,7 +72,7 @@
|
|||
</repository>
|
||||
<repository>
|
||||
<id>ess-repo</id>
|
||||
<url>http://repo.ess3.net/content/groups/essentials</url>
|
||||
<url>https://ci.ender.zone/plugin/repository/everything/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>mvn-repo</id>
|
||||
|
|
|
@ -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<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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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<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();
|
||||
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));
|
||||
|
||||
// Find marker using old naming system
|
||||
if (marker == null) {
|
||||
String uuid = EtzTechUtil.formatUUID(player.getUniqueId().toString(), false);
|
||||
return playerMarkerSet.findMarker(uuid);
|
||||
}
|
||||
else {
|
||||
return marker;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<String> 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<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) {
|
||||
for (String arg: strings) {
|
||||
if (subCommandList.contains(arg)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return subCommandList;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -125,5 +125,5 @@ permissions:
|
|||
qol.marker:
|
||||
description: Ability to use the marker command
|
||||
default: op
|
||||
|
||||
|
||||
children:
|
||||
qol.marker.limit: true
|
||||
|
|
Loading…
Reference in New Issue