Skip to content

Commit

Permalink
dynmap support
Browse files Browse the repository at this point in the history
  • Loading branch information
czQery committed Feb 13, 2023
1 parent 9e4cf97 commit d97896e
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 27 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<img src="https://github.com/czQery/ToolKit/blob/master/banner.png?raw=true" alt="Logo">
</p>

[![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

Expand All @@ -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 |
|----------|----------------|--------------------------------------------|
Expand All @@ -37,7 +39,7 @@

- Waypoints
- Disabled mods
- Automatically kick non lunar players
- Automatically kick non-lunar players

## Trolls

Expand Down Expand Up @@ -101,7 +103,6 @@ lunar:
#lunar waypoints
waypoints:
- Spawn:
name: Spawn
color: '#ba1e0d'
world: world
x: 0
Expand Down
13 changes: 11 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>cz.qery</groupId>
<artifactId>ToolKit</artifactId>
<version>3.8-SNAPSHOT</version>
<version>3.8</version>
<packaging>jar</packaging>

<name>ToolKit</name>
Expand Down Expand Up @@ -51,6 +52,7 @@
<version>3.0.0</version>
</dependency>
<dependency>
<!--Local m2-->
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.19.3-R0.1-SNAPSHOT</version>
Expand All @@ -61,6 +63,13 @@
<artifactId>BukkitAPI-NetHandler</artifactId>
<version>fab9915</version>
</dependency>
<dependency>
<!--Local m2-->
<groupId>us.dynmap</groupId>
<artifactId>DynmapCoreAPI</artifactId>
<version>3.5-beta-2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-api</artifactId>
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/cz/qery/toolkit/Dy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package cz.qery.toolkit;

import org.dynmap.DynmapCommonAPI;

public class Dy {
public static DynmapCommonAPI api;
}
7 changes: 6 additions & 1 deletion src/main/java/cz/qery/toolkit/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/cz/qery/toolkit/Vnsh.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<UUID, String> pl : players.entrySet()) {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cz/qery/toolkit/commands/Aliases.java
Original file line number Diff line number Diff line change
Expand Up @@ -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!"));
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/cz/qery/toolkit/commands/Lunar.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/cz/qery/toolkit/commands/Vanish.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <player/list>"));
return false;
if ((sender instanceof Player)) {
target = (Player) sender;
} else {
sender.sendMessage(Tools.chat(b+"["+n+"VANISH"+b+"]"+t+" Please use "+h+"/vanish <player/list>"));
return false;
}
}


Expand Down
29 changes: 29 additions & 0 deletions src/main/java/cz/qery/toolkit/events/DyListener.java
Original file line number Diff line number Diff line change
@@ -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!");
}
}
40 changes: 26 additions & 14 deletions src/main/java/cz/qery/toolkit/lunar/Waypoint.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -29,17 +31,16 @@ public static void Load() {

List<Map<?, ?>> 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<String, Object> point = (HashMap<String, Object>)entry;
HashMap<String, Object> point = (HashMap<String, Object>)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);
}
});
}
}

Expand All @@ -48,14 +49,17 @@ public static void Update() {
for (Waypoint wp : waypoints) {
HashMap<String, HashMap<String, Object>> waypoint_temp = new HashMap<String, HashMap<String, Object>>();
HashMap<String, Object> waypoint_temp2 = new HashMap<String, Object>();
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, "<span style=\"color: "+wp.color+";\">⬤ </span><span>"+wp.name+"</span>", 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);
Expand All @@ -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<Player> players = new ArrayList<>(Bukkit.getOnlinePlayers());
for (Player pp : players) {
Tools.sendLunarPacket(pp, new LCPacketWaypointRemove(name, world));
Expand Down
8 changes: 5 additions & 3 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -44,7 +46,7 @@ commands:
description: Allows the player to fly
wc:
description: Clear weather
clear:
ic:
description: Clear inventory

permissions:
Expand Down Expand Up @@ -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

0 comments on commit d97896e

Please sign in to comment.