Dynmap Marker Command (#42)

1.16
Joey Hines 2019-10-09 18:30:54 +02:00 committed by Gitea
parent d55fb1112a
commit e75d8efdfc
9 changed files with 147 additions and 3 deletions

View File

@ -14,3 +14,4 @@ Changelogs
v1.6 <v1.6> v1.6 <v1.6>
v1.7 <v1.7> v1.7 <v1.7>
v1.8 <v1.8> v1.8 <v1.8>
v1.9 <1.9>

View File

@ -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

View File

@ -44,3 +44,5 @@ Alias ``/names`` and ``/name``
``/checkup <start|next|stop>`` Start a checkup, teleporting to all online players. ``/checkup <start|next|stop>`` Start a checkup, teleporting to all online players.
``/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`` Creates a marker on the dynmap at the players current location.

View File

@ -49,3 +49,5 @@ Permissions
``qol.checkup`` - Ability to use the Checkup command ``qol.checkup`` - Ability to use the Checkup command
``qol.discord`` - Use Discord (markdown) syntax for chat formatting ``qol.discord`` - Use Discord (markdown) syntax for chat formatting
``qol.marker`` - Ability to use the Marker command

View File

@ -3,7 +3,7 @@
<groupId>xyz.etztech</groupId> <groupId>xyz.etztech</groupId>
<artifactId>QoL</artifactId> <artifactId>QoL</artifactId>
<!-- Version is used in plugin.yml --> <!-- Version is used in plugin.yml -->
<version>1.8</version> <version>1.9</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<!-- Plugin Information --> <!-- Plugin Information -->

View File

@ -3,11 +3,16 @@ package xyz.etztech.qol;
import net.ess3.api.IEssentials; import net.ess3.api.IEssentials;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.dynmap.DynmapAPI; 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.commands.*;
import xyz.etztech.qol.listeners.*; import xyz.etztech.qol.listeners.*;
import xyz.etztech.qol.other.GriefAlert; import xyz.etztech.qol.other.GriefAlert;
@ -19,9 +24,15 @@ 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 qolMarkerSetLabel = "QoL Markers";
static private final String qolMarkerIcon = "blueflag";
private static QoL instance; private static QoL instance;
private IEssentials essentials = null; private IEssentials essentials = null;
private DynmapAPI dynmap = null; private DynmapAPI dynmap = null;
private MarkerAPI markerAPI = null;
private MarkerSet playerMarkerSet = null;
public static FileConfiguration config; public static FileConfiguration config;
private Logger log = Logger.getLogger( "Minecraft" ); private Logger log = Logger.getLogger( "Minecraft" );
@ -52,6 +63,26 @@ public class QoL extends JavaPlugin {
if (Bukkit.getPluginManager().isPluginEnabled("dynmap")) { if (Bukkit.getPluginManager().isPluginEnabled("dynmap")) {
log("Hooked into Dynmap."); log("Hooked into Dynmap.");
dynmap = (DynmapAPI) Bukkit.getPluginManager().getPlugin("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() ) { if( isEnabled() ) {
@ -110,6 +141,12 @@ public class QoL extends JavaPlugin {
DynmapLinkCommand dynmapLinkCommand = new DynmapLinkCommand(this); DynmapLinkCommand dynmapLinkCommand = new DynmapLinkCommand(this);
this.getCommand("dynmaplink").setExecutor(dynmapLinkCommand); this.getCommand("dynmaplink").setExecutor(dynmapLinkCommand);
if (dynmap != null) {
MarkerCommand markerCommand = new MarkerCommand(this);
this.getCommand("marker").setExecutor(markerCommand);
}
if (getConfig().getStringList("list").size() > 0) { if (getConfig().getStringList("list").size() > 0) {
ListCommand listCommand = new ListCommand(this); ListCommand listCommand = new ListCommand(this);
this.getCommand("list").setExecutor(listCommand); this.getCommand("list").setExecutor(listCommand);
@ -308,5 +345,28 @@ public class QoL extends JavaPlugin {
public void updatePlayerViewDistance(Player player) { public void updatePlayerViewDistance(Player player) {
//player.setViewDistance(viewDistances.getOrDefault(player.getWorld().getName().toLowerCase(), getServer().getViewDistance())); //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);
}
} }

View File

@ -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;
}
}

View File

@ -8,6 +8,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerLoginEvent;
import org.dynmap.markers.Marker;
import xyz.etztech.qol.QoL; import xyz.etztech.qol.QoL;
import xyz.etztech.qol.commands.CheckupCommand; 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); plugin.updatePlayerViewDistance(player);
CheckupCommand.join(player); CheckupCommand.join(player);

View File

@ -48,6 +48,9 @@ commands:
dynmaplink: dynmaplink:
description: Dynmap Link command description: Dynmap Link command
aliases: [dlink] aliases: [dlink]
marker:
description: Dynmap marker command
aliases: [mark]
permissions: permissions:
qol.admin: qol.admin:
description: Ability to reload the plugin description: Ability to reload the plugin
@ -119,5 +122,8 @@ permissions:
default: op default: op
children: children:
qol.timeout.bypass: true qol.timeout.bypass: true
qol.marker:
description: Ability to use the marker command
default: op