forked from Minecraft/QoL
60 lines
2.3 KiB
Java
60 lines
2.3 KiB
Java
package xyz.etztech.qol.commands;
|
|
|
|
import net.md_5.bungee.api.ChatColor;
|
|
import net.md_5.bungee.api.chat.ClickEvent;
|
|
import net.md_5.bungee.api.chat.TextComponent;
|
|
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 xyz.etztech.qol.EtzTechUtil;
|
|
import xyz.etztech.qol.Lang;
|
|
import xyz.etztech.qol.QoL;
|
|
|
|
public class DynmapLinkCommand implements CommandExecutor {
|
|
|
|
QoL plugin;
|
|
|
|
public DynmapLinkCommand(QoL plugin) {
|
|
this.plugin = plugin;
|
|
plugin.getCommand("dynmaplink").setExecutor(this);
|
|
}
|
|
|
|
@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.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("Click here to see your location on Dynmap.");
|
|
message.setColor(ChatColor.YELLOW);
|
|
message.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url));
|
|
} else {
|
|
message = new TextComponent("This command is currently disabled or the server has no Dynmap!");
|
|
message.setColor(ChatColor.RED);
|
|
}
|
|
player.spigot().sendMessage(message);
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|