Dynmap Link

Signed-off-by: Etzelia <etzelia@hotmail.com>
dynmap_link
Etzelia 2019-10-04 10:52:33 -05:00
parent 8d0e30cfa3
commit b8e5e6e11b
No known key found for this signature in database
GPG Key ID: 3CAEB74806C4ADE5
4 changed files with 77 additions and 0 deletions

View File

@ -107,6 +107,8 @@ public class QoL extends JavaPlugin {
this.getCommand("karattrophy").setExecutor(karatTrophyCommand);
CheckupCommand checkupCommand = new CheckupCommand(this);
this.getCommand("checkup").setExecutor(checkupCommand);
DynmapLinkCommand dynmapLinkCommand = new DynmapLinkCommand(this);
this.getCommand("dynmaplink").setExecutor(dynmapLinkCommand);
if (getConfig().getStringList("list").size() > 0) {
ListCommand listCommand = new ListCommand(this);

View File

@ -0,0 +1,61 @@
package xyz.etztech.qol.commands;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.dynmap.DynmapAPI;
import xyz.etztech.qol.EtzTechUtil;
import xyz.etztech.qol.Lang;
import xyz.etztech.qol.QoL;
import java.util.*;
public class DynmapLinkCommand implements CommandExecutor {
QoL plugin;
public DynmapLinkCommand(QoL plugin) {
this.plugin = plugin;
}
@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;
}
Player player = (Player) commandSender;
String base = plugin.getConfig().getString("dynmap.defaults.url", "");
String defaultMap = plugin.getConfig().getString("dynmap.defaults.map", "surface");
String defaultZoom = String.valueOf(plugin.getConfig().getInt("dynmap.defaults.zoom", 5));
TextComponent message;
if (base.trim().length() > 0) {
String world = player.getWorld().getName();
Location location = player.getLocation();
String x = String.valueOf(location.getX());
String y = String.valueOf(location.getY());
String z = String.valueOf(location.getZ());
String map = args.length > 0 ? args[0] : defaultMap;
String zoom = args.length > 1 ? args[1] : defaultZoom;
String url = String.format("%s?worldname=%s&mapname=%s&zoom=%s&x=%s&y=%s&z=%s", base, world, map, zoom, x, y, z);
message = new TextComponent(ChatColor.YELLOW + "Click here to see your location on Dynmap.");
message.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url));
} else {
message = new TextComponent(ChatColor.RED + "This command is currently disabled or the server has no Dynmap!");
}
player.spigot().sendMessage(message);
return true;
}
}

View File

@ -93,3 +93,11 @@ disable-fire:
# Overrides view distance per world, format is [World Name]: [View Distance]
view-distances:
world: 2
# Dynmap link
# Leave url blank to disable
dynmap:
url: ""
defaults:
map: "surface"
zoom: 5

View File

@ -45,6 +45,9 @@ commands:
aliases: [trophy]
checkup:
description: Checkup command
dynmaplink:
description: Dynmap Link command
aliases: [dlink]
permissions:
qol.admin:
description: Ability to reload the plugin
@ -85,6 +88,9 @@ permissions:
qol.checkup:
description: Ability to use the Checkup Command
default: op
qol.dynmaplink:
description: Ability to use the Dynmap Link Command
default: op
qol.auditable:
description: Audits command usage
default: op