From d97896eee741b5dd1ee04e0a50ba0e928efe0e21 Mon Sep 17 00:00:00 2001 From: czQery Date: Mon, 13 Feb 2023 17:27:49 +0100 Subject: [PATCH] dynmap support --- README.md | 9 +++-- pom.xml | 13 +++++- src/main/java/cz/qery/toolkit/Dy.java | 7 ++++ src/main/java/cz/qery/toolkit/Main.java | 7 +++- src/main/java/cz/qery/toolkit/Vnsh.java | 8 ++++ .../cz/qery/toolkit/commands/Aliases.java | 2 +- .../java/cz/qery/toolkit/commands/Lunar.java | 1 + .../java/cz/qery/toolkit/commands/Vanish.java | 8 +++- .../cz/qery/toolkit/events/DyListener.java | 29 ++++++++++++++ .../java/cz/qery/toolkit/lunar/Waypoint.java | 40 ++++++++++++------- src/main/resources/plugin.yml | 8 ++-- 11 files changed, 105 insertions(+), 27 deletions(-) create mode 100644 src/main/java/cz/qery/toolkit/Dy.java create mode 100644 src/main/java/cz/qery/toolkit/events/DyListener.java diff --git a/README.md b/README.md index bd4830d..a4247b5 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ Logo

-[![Version](https://img.shields.io/badge/version-v3.7-informational.svg)](https://github.com/czQery/ToolKit/releases) -[![Releases](https://img.shields.io/badge/download-1.19-brightgreen.svg)](https://github.com/czQery/ToolKit/releases/latest/download/ToolKit-3.7.jar) +[![Version](https://img.shields.io/badge/version-v3.8-informational.svg)](https://github.com/czQery/ToolKit/releases) +[![Releases](https://img.shields.io/badge/download-1.19-brightgreen.svg)](https://github.com/czQery/ToolKit/releases/latest/download/ToolKit-3.8.jar) ## Commands @@ -24,6 +24,8 @@ | /gmsp | toolkit.gmsp | toolkit.gmsp.other | Switch player's gamemode to SPECTATOR | | /spawn | toolkit.spawn | toolkit.spawn.other | Teleports player to spawn | | /fly | toolkit.fly | toolkit.fly.other | Allows the player to fly | +| /wc | toolkit.wc | toolkit.wc.other | Clear weather | +| /ic | toolkit.ic | toolkit.ic.other | Clear inventory | | Command | Permission | Description | |----------|----------------|--------------------------------------------| @@ -37,7 +39,7 @@ - Waypoints - Disabled mods -- Automatically kick non lunar players +- Automatically kick non-lunar players ## Trolls @@ -101,7 +103,6 @@ lunar: #lunar waypoints waypoints: - Spawn: - name: Spawn color: '#ba1e0d' world: world x: 0 diff --git a/pom.xml b/pom.xml index 56f7289..0ca62d8 100644 --- a/pom.xml +++ b/pom.xml @@ -1,10 +1,11 @@ - + 4.0.0 cz.qery ToolKit - 3.8-SNAPSHOT + 3.8 jar ToolKit @@ -51,6 +52,7 @@ 3.0.0 + org.spigotmc spigot 1.19.3-R0.1-SNAPSHOT @@ -61,6 +63,13 @@ BukkitAPI-NetHandler fab9915 + + + us.dynmap + DynmapCoreAPI + 3.5-beta-2 + provided + net.kyori adventure-api diff --git a/src/main/java/cz/qery/toolkit/Dy.java b/src/main/java/cz/qery/toolkit/Dy.java new file mode 100644 index 0000000..f471797 --- /dev/null +++ b/src/main/java/cz/qery/toolkit/Dy.java @@ -0,0 +1,7 @@ +package cz.qery.toolkit; + +import org.dynmap.DynmapCommonAPI; + +public class Dy { + public static DynmapCommonAPI api; +} diff --git a/src/main/java/cz/qery/toolkit/Main.java b/src/main/java/cz/qery/toolkit/Main.java index 85c9342..91d890a 100644 --- a/src/main/java/cz/qery/toolkit/Main.java +++ b/src/main/java/cz/qery/toolkit/Main.java @@ -54,7 +54,7 @@ public void onEnable() { Objects.requireNonNull(getCommand("spawn")).setExecutor(new Aliases()); Objects.requireNonNull(getCommand("fly")).setExecutor(new Aliases()); Objects.requireNonNull(getCommand("wc")).setExecutor(new Aliases()); - Objects.requireNonNull(getCommand("clear")).setExecutor(new Aliases()); + Objects.requireNonNull(getCommand("ic")).setExecutor(new Aliases()); new Interact(this); new Join(this); @@ -86,6 +86,11 @@ public void onEnable() { //bStats new Metrics(this, 11896); + //Dynmap + if(getServer().getPluginManager().getPlugin("dynmap") != null) { + new DyListener(); + } + Waypoint.Load(); Mod.Load(); CommandBlock.Load(); diff --git a/src/main/java/cz/qery/toolkit/Vnsh.java b/src/main/java/cz/qery/toolkit/Vnsh.java index e5f805d..1fe6ac3 100644 --- a/src/main/java/cz/qery/toolkit/Vnsh.java +++ b/src/main/java/cz/qery/toolkit/Vnsh.java @@ -44,6 +44,10 @@ public static void Show(Player p, boolean init) { } else { plugin.getServer().broadcastMessage(Tools.chat(plugin.getConfig().getString("join.message")).replace("%player%",p.getName())); } + + if (Dy.api != null) { + Dy.api.setPlayerVisiblity(p.getName(), true); + } } for (Map.Entry pl : players.entrySet()) { @@ -74,6 +78,10 @@ public static void Hide(Player p, boolean init) { } else { plugin.getServer().broadcastMessage(Tools.chat(plugin.getConfig().getString("leave.message")).replace("%player%",p.getName())); } + + if (Dy.api != null) { + Dy.api.setPlayerVisiblity(p.getName(), false); + } } p.setSleepingIgnored(true); p.setAllowFlight(true); diff --git a/src/main/java/cz/qery/toolkit/commands/Aliases.java b/src/main/java/cz/qery/toolkit/commands/Aliases.java index b3a3231..db41550 100644 --- a/src/main/java/cz/qery/toolkit/commands/Aliases.java +++ b/src/main/java/cz/qery/toolkit/commands/Aliases.java @@ -102,7 +102,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N target.getWorld().setTime(1000); sender.sendMessage(Tools.chat(b + "[" + n + "SERVER" + b + "]" + t + " Weather cleared!")); } - case "clear" -> { + case "ic" -> { target.getInventory().setContents(new ItemStack[]{}); sender.sendMessage(Tools.chat(b + "[" + n + "SERVER" + b + "]" + t + " Inventory cleared!")); } diff --git a/src/main/java/cz/qery/toolkit/commands/Lunar.java b/src/main/java/cz/qery/toolkit/commands/Lunar.java index 9de7b78..ca45d4c 100644 --- a/src/main/java/cz/qery/toolkit/commands/Lunar.java +++ b/src/main/java/cz/qery/toolkit/commands/Lunar.java @@ -1,5 +1,6 @@ package cz.qery.toolkit.commands; +import cz.qery.toolkit.Dy; import cz.qery.toolkit.Main; import cz.qery.toolkit.Tools; import cz.qery.toolkit.lunar.Waypoint; diff --git a/src/main/java/cz/qery/toolkit/commands/Vanish.java b/src/main/java/cz/qery/toolkit/commands/Vanish.java index 11a1bd7..03dd0d3 100644 --- a/src/main/java/cz/qery/toolkit/commands/Vanish.java +++ b/src/main/java/cz/qery/toolkit/commands/Vanish.java @@ -50,8 +50,12 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N return false; } } else { - sender.sendMessage(Tools.chat(b+"["+n+"VANISH"+b+"]"+t+" Please use "+h+"/vanish ")); - return false; + if ((sender instanceof Player)) { + target = (Player) sender; + } else { + sender.sendMessage(Tools.chat(b+"["+n+"VANISH"+b+"]"+t+" Please use "+h+"/vanish ")); + return false; + } } diff --git a/src/main/java/cz/qery/toolkit/events/DyListener.java b/src/main/java/cz/qery/toolkit/events/DyListener.java new file mode 100644 index 0000000..9245727 --- /dev/null +++ b/src/main/java/cz/qery/toolkit/events/DyListener.java @@ -0,0 +1,29 @@ +package cz.qery.toolkit.events; + +import cz.qery.toolkit.Dy; +import cz.qery.toolkit.Main; +import cz.qery.toolkit.Tools; +import cz.qery.toolkit.lunar.Waypoint; +import org.bukkit.Bukkit; +import org.dynmap.DynmapCommonAPI; +import org.dynmap.DynmapCommonAPIListener; + +public class DyListener extends DynmapCommonAPIListener { + static Main plugin = Main.getPlugin(Main.class); + static String b = plugin.getConfig().getString("color.bracket"); + static String n = plugin.getConfig().getString("color.name"); + static String t = plugin.getConfig().getString("color.text"); + static String h = plugin.getConfig().getString("color.highlight"); + + public DyListener() { + DynmapCommonAPIListener.register(this); + } + + @Override + public void apiEnabled(DynmapCommonAPI api) { + Dy.api = api; + api.getMarkerAPI().createMarkerSet("toolkit.lunar", "Lunar", null, false); + Bukkit.getScheduler().runTaskAsynchronously(plugin, Waypoint::Update); + Tools.log(b+"["+n+"ToolKit"+b+"] &aDynmapAPI loaded!"); + } +} diff --git a/src/main/java/cz/qery/toolkit/lunar/Waypoint.java b/src/main/java/cz/qery/toolkit/lunar/Waypoint.java index 1a2057d..5c6246a 100644 --- a/src/main/java/cz/qery/toolkit/lunar/Waypoint.java +++ b/src/main/java/cz/qery/toolkit/lunar/Waypoint.java @@ -1,11 +1,13 @@ package cz.qery.toolkit.lunar; import com.lunarclient.bukkitapi.nethandler.shared.LCPacketWaypointRemove; +import cz.qery.toolkit.Dy; import cz.qery.toolkit.Main; import cz.qery.toolkit.Scripts; import cz.qery.toolkit.Tools; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.dynmap.markers.Marker; import java.util.ArrayList; import java.util.HashMap; @@ -29,17 +31,16 @@ public static void Load() { List> maps = plugin.getConfig().getMapList("lunar.waypoints"); for (Map map : maps) { - for (Object entry : map.values()) { - - if (!(entry instanceof HashMap)) { - continue; + map.forEach((k,v) -> { + if (!(v instanceof HashMap)) { + return; } - HashMap point = (HashMap)entry; + HashMap point = (HashMap)v; - Waypoint waypoint = new Waypoint(point.get("name").toString(), (int) point.get("x"), (int) point.get("y"), (int) point.get("z"), point.get("world").toString(), point.get("color").toString()); + Waypoint waypoint = new Waypoint(k.toString(), (int) point.get("x"), (int) point.get("y"), (int) point.get("z"), point.get("world").toString(), point.get("color").toString()); waypoints.add(waypoint); - } + }); } } @@ -48,14 +49,17 @@ public static void Update() { for (Waypoint wp : waypoints) { HashMap> waypoint_temp = new HashMap>(); HashMap waypoint_temp2 = new HashMap(); - waypoint_temp2.put("name", wp.name()); - waypoint_temp2.put("color", wp.color()); - waypoint_temp2.put("world", wp.world()); - waypoint_temp2.put("x", wp.x()); - waypoint_temp2.put("y", wp.y()); - waypoint_temp2.put("z", wp.z()); - waypoint_temp.put(wp.name(), waypoint_temp2); + waypoint_temp2.put("color", wp.color); + waypoint_temp2.put("world", wp.world); + waypoint_temp2.put("x", wp.x); + waypoint_temp2.put("y", wp.y); + waypoint_temp2.put("z", wp.z); + waypoint_temp.put(wp.name, waypoint_temp2); l.add(waypoint_temp); + + if (Dy.api != null && Dy.api.getMarkerAPI().getMarkerSet("toolkit.lunar").findMarkerByLabel(wp.name) == null) { + Dy.api.getMarkerAPI().getMarkerSet("toolkit.lunar").createMarker(wp.name, ""+wp.name+"", true, wp.world, wp.x, wp.y, wp.z, Dy.api.getMarkerAPI().getMarkerIcon("pin"), false); + } } plugin.getConfig().set("lunar.waypoints", null); plugin.getConfig().set("lunar.waypoints", l); @@ -76,6 +80,14 @@ public static void SendOne(Player p) { } public static void Remove(String name, String world) { + if (Dy.api != null) { + Marker dyMarker = Dy.api.getMarkerAPI().getMarkerSet("toolkit.lunar").findMarkerByLabel(name); + + if (dyMarker != null) { + dyMarker.deleteMarker(); + } + } + List players = new ArrayList<>(Bukkit.getOnlinePlayers()); for (Player pp : players) { Tools.sendLunarPacket(pp, new LCPacketWaypointRemove(name, world)); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 7c73170..0e2a6a9 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -6,6 +6,8 @@ authors: [ czQery ] description: Set of useful tools website: github.com/czQery/ToolKit +softdepend: [ dynmap ] + commands: crash: description: Lag/Crash players game @@ -44,7 +46,7 @@ commands: description: Allows the player to fly wc: description: Clear weather - clear: + ic: description: Clear inventory permissions: @@ -109,7 +111,7 @@ permissions: description: Wc command toolkit.wc.other: description: Wc command - toolkit.clear: + toolkit.ic: description: Clear command - toolkit.clear.other: + toolkit.ic.other: description: CLear command \ No newline at end of file