diff --git a/pom.xml b/pom.xml
index 895099d..329356f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -18,6 +18,10 @@
brokkonaut
https://www.iani.de/nexus/content/groups/public
+
+ everything
+ https://repo.citizensnpcs.co/
+
@@ -67,6 +71,18 @@
0.0.1-SNAPSHOT
provided
+
+ net.citizensnpcs
+ citizens-main
+ 2.0.29-SNAPSHOT
+ provided
+
+
+ de.iani.cubeside
+ PlayerUUIDCache
+ 2.0.0-SNAPSHOT
+ provided
+
diff --git a/src/main/java/de/fanta/challengesjoinentities/ChallengesGlobalDataHelper.java b/src/main/java/de/fanta/challengesjoinentities/ChallengesGlobalDataHelper.java
index 599587b..19f7a9f 100644
--- a/src/main/java/de/fanta/challengesjoinentities/ChallengesGlobalDataHelper.java
+++ b/src/main/java/de/fanta/challengesjoinentities/ChallengesGlobalDataHelper.java
@@ -115,12 +115,11 @@
for (Server server : plugin.getPluginConfig().getAdventureServers()) {
if (server.getName().equals(event.getServer().getName())) {
UUID uuid = Server.serverPlayers.get(server);
- if (uuid != null) {
- Player p = Bukkit.getPlayer(uuid);
- if (p != null) {
- server.spawnPiglin(p);
- GlobalApi.portOnlinePlayerToLocation(p.getName(), server.getGPLocation());
- }
+ Player p = Bukkit.getPlayer(uuid);
+ if (p != null) {
+ server.spawnPiglin(p);
+ //server.spawnNPC(p);
+ GlobalApi.portOnlinePlayerToLocation(p.getName(), server.getGPLocation());
}
break;
}
@@ -147,6 +146,7 @@
if (server.getName().equals(event.getServer().getName())) {
server.setOnline(false);
Server.serverPlayers.remove(server);
+ //server.despawnNPC();
server.despawnPiglin();
break;
}
diff --git a/src/main/java/de/fanta/challengesjoinentities/ChallengesJoinEntities.java b/src/main/java/de/fanta/challengesjoinentities/ChallengesJoinEntities.java
index dddb6d2..c00e45c 100644
--- a/src/main/java/de/fanta/challengesjoinentities/ChallengesJoinEntities.java
+++ b/src/main/java/de/fanta/challengesjoinentities/ChallengesJoinEntities.java
@@ -3,15 +3,27 @@
import de.cubeside.nmsutils.NMSUtils;
import de.fanta.challengesjoinentities.adventure.AdventureMapsConfig;
import de.fanta.challengesjoinentities.adventure.CategoriesConfig;
-import de.fanta.challengesjoinentities.commands.AdventureCommand.*;
+import de.fanta.challengesjoinentities.commands.AdventureCommand.AdventureAddCategoryCommand;
+import de.fanta.challengesjoinentities.commands.AdventureCommand.AdventureAddMapCommand;
+import de.fanta.challengesjoinentities.commands.AdventureCommand.AdventureLoadCommand;
+import de.fanta.challengesjoinentities.commands.AdventureCommand.AdventureMapsCommand;
+import de.fanta.challengesjoinentities.commands.AdventureCommand.AdventureTestMapCommand;
+import de.fanta.challengesjoinentities.commands.AdventureCommand.ChallengesRemovePlayerServer;
import de.fanta.challengesjoinentities.commands.ChallengesCommand.ChallengesloadCommand;
import de.fanta.challengesjoinentities.commands.PiglinCommand.AddEntityCommand;
+import de.fanta.challengesjoinentities.commands.PiglinCommand.Entitytphere;
+import de.fanta.challengesjoinentities.commands.PiglinCommand.ListPiglinCommand;
import de.fanta.challengesjoinentities.commands.PiglinCommand.RemoveEntityCommand;
import de.fanta.challengesjoinentities.commands.PiglinCommand.ToggleArenaCommand;
import de.fanta.challengesjoinentities.listeners.ChallengesEventListener;
import de.fanta.challengesjoinentities.listeners.EntityListener;
import de.fanta.challengesjoinentities.listeners.PlayerListener;
+import de.fanta.challengesjoinentities.loadgui.AdventureLoadGUI;
+import de.fanta.challengesjoinentities.loadgui.ChallengeLoadGUI;
import de.iani.cubesideutils.bukkit.commands.CommandRouter;
+import de.iani.playerUUIDCache.PlayerUUIDCache;
+import net.citizensnpcs.api.CitizensAPI;
+import net.citizensnpcs.api.npc.NPC;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.TextColor;
@@ -26,11 +38,17 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
-import java.util.*;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
public class ChallengesJoinEntities extends JavaPlugin {
public static final String PREFIX = ChatUtil.BLUE + "[" + ChatUtil.GREEN + "Lobby" + ChatUtil.BLUE + "]";
+ public static final String ADVENTUREGUIPREFIX = ChatColor.of("#2d8745") + "Adventure";
+ public static final String CHALLENGEGUIPREFIX = ChatColor.of("#2d8745") + "Challenge";
private static final TextColor BRACKETS = TextColor.fromHexString("#87f7ea");
@@ -45,6 +63,7 @@
private CategoriesConfig categoriesConfig;
private AdventureMapsConfig adventureMapsConfig;
public NMSUtils nmsUtils;
+ private PlayerUUIDCache playerUUIDCache;
public ChallengesJoinEntities() {
@@ -56,6 +75,7 @@
@Override
public void onEnable() {
plugin = this;
+ playerUUIDCache = (PlayerUUIDCache) getServer().getPluginManager().getPlugin("PlayerUUIDCache");
nmsUtils = getServer().getServicesManager().load(NMSUtils.class);
this.globalDataHelper = new ChallengesGlobalDataHelper(this);
this.config = new Config(this);
@@ -67,6 +87,8 @@
CommandRouter router = new CommandRouter(getCommand("piglins"));
router.addCommandMapping(new AddEntityCommand(this), "spawn");
router.addCommandMapping(new RemoveEntityCommand(this), "remove");
+ router.addCommandMapping(new Entitytphere(this), "tphere");
+ router.addCommandMapping(new ListPiglinCommand(this), "list");
router.addCommandMapping(new ToggleArenaCommand(this, true), "enable");
router.addCommandMapping(new ToggleArenaCommand(this, false), "disable");
@@ -83,6 +105,9 @@
}
Bukkit.getPluginManager().registerEvents(new EntityListener(this), this);
Bukkit.getPluginManager().registerEvents(new PlayerListener(this), this);
+ Bukkit.getPluginManager().registerEvents(new AdventureLoadGUI(), this);
+ Bukkit.getPluginManager().registerEvents(new ChallengeLoadGUI(), this);
+
Bukkit.getPluginManager().registerEvents(globalDataHelper, this);
}
@@ -125,6 +150,40 @@
}
}
+ public void spawnNPC(Location location, String serverName, String gpLocationName, String serverDisplayName, boolean saveToConfig) {
+ if (entityData.containsKey(serverName)) {
+ despawnNPC(entityData.get(serverName).getEntityUUID(), serverDisplayName);
+ }
+ if (plugin.getServer().getPluginManager().getPlugin("Citizens") == null) {
+ return;
+ }
+ NPC npc = CitizensAPI.getNPCRegistry().createNPC(EntityType.PLAYER, serverDisplayName);
+ npc.spawn(location);
+ addPiglin(npc.getUniqueId(), serverName, gpLocationName, serverDisplayName, saveToConfig);
+
+ globalDataHelper.requestInitialData(serverName);
+ }
+
+ public void despawnNPC(String serverName) {
+ if (entityData.get(serverName) != null) {
+ System.out.println("Test1");
+ despawnNPC(entityData.get(serverName).getEntityUUID(), serverName);
+ }
+ }
+
+ public void despawnNPC(UUID piglinUUID, String serverName) {
+ if (plugin.getServer().getPluginManager().getPlugin("Citizens") == null) {
+ return;
+ }
+ NPC npc = CitizensAPI.getNPCRegistry().getByUniqueId(piglinUUID);
+ System.out.println(npc);
+ if (npc != null) {
+ System.out.println("Destroy: " + piglinUUID);
+ Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "npc remove " + npc.getId());
+ removePiglin(serverName);
+ }
+ }
+
public void addPiglin(UUID piglinUUID, String serverName, String gpLocationName, String serverDisplayName, boolean saveToConfig) {
JoinEntityData entityData = new JoinEntityData(serverName, piglinUUID, gpLocationName, serverDisplayName, JoinEntityData.ServerStatus.OFFLINE, 0, 0);
this.entityData.put(serverName, entityData);
@@ -148,7 +207,6 @@
JoinEntityData data = entityData.get(serverName);
if (data != null) {
data.setServerStatus(running ? JoinEntityData.ServerStatus.RUNNING : JoinEntityData.ServerStatus.ONLINE);
-
updatePiglinCustomName(serverName);
updatePiglinBehaviour(serverName);
}
@@ -190,13 +248,28 @@
}
public void updatePiglinCustomName(String serverName) {
- Piglin piglin = getPiglinForServerName(serverName);
+ Entity entity = getPiglinForServerName(serverName);
JoinEntityData data = entityData.get(serverName);
- if (piglin != null && data != null) {
- String customName = data.createCustomEntityName();
- piglin.setCustomName(customName);
+ if (entity == null) {
+ return;
}
+
+ if (data == null) {
+ return;
+ }
+
+ String customName = data.createCustomEntityName();
+
+ NPC npc = CitizensAPI.getNPCRegistry().getByUniqueId(entity.getUniqueId());
+
+ if (npc != null) {
+ npc.setName(customName);
+ } else {
+ entity.setCustomName(customName);
+ }
+
+
}
public void updatePiglinBehaviour(String serverName) {
@@ -240,6 +313,10 @@
this.categoriesConfig.load();
}
+ public PlayerUUIDCache getPlayerUUIDCache() {
+ return playerUUIDCache;
+ }
+
public static ChallengesJoinEntities getPlugin() {
return plugin;
}
diff --git a/src/main/java/de/fanta/challengesjoinentities/Server.java b/src/main/java/de/fanta/challengesjoinentities/Server.java
index a7e324d..d4588d5 100644
--- a/src/main/java/de/fanta/challengesjoinentities/Server.java
+++ b/src/main/java/de/fanta/challengesjoinentities/Server.java
@@ -67,24 +67,42 @@
return this.gPLocation;
}
- public void loadSaved(Player p) {
+ public void loadSaved(Player p, Boolean isAutosave) {
this.online = true;
serverPlayers.put(this, p.getUniqueId());
UUID uuid = p.getUniqueId();
- File dir = new File("/home/minecraft/" + this.serverType.getDir() + "/" + uuid);
+ File dir;
+ if (isAutosave) {
+ dir = new File("/home/minecraft/" + this.serverType.getDir() + "/" + uuid + "/autosave");
+ } else {
+ dir = new File("/home/minecraft/" + this.serverType.getDir() + "/" + uuid + "/1");
+ }
if (!dir.isDirectory()) {
ChatUtil.sendErrorMessage(p, "Du hast noch keine Map gespeichert!");
this.online = false;
serverPlayers.remove(this);
return;
}
- load(p, this.serverType.getDir(), uuid.toString());
+
+ if (isAutosave) {
+ load(p, this.serverType.getDir(), uuid + "/autosave");
+ } else {
+ load(p, this.serverType.getDir(), uuid + "/1");
+ }
}
- public void loadSaved(Player p, String mapname) {
+ public void loadSaved(Player p, String mapname, Boolean isAutosave) {
this.online = true;
serverPlayers.put(this, p.getUniqueId());
- File dir = new File("/home/minecraft/" + this.serverType.getDir() + "/" + mapname);
+ File dir;
+ if (isAutosave) {
+ dir = new File("/home/minecraft/" + this.serverType.getDir() + "/" + mapname + "/autosave");
+ mapname = mapname + "/autosave";
+ } else {
+ dir = new File("/home/minecraft/" + this.serverType.getDir() + "/" + mapname + "/1");
+ mapname = mapname + "/1";
+ }
+
if (!dir.isDirectory()) {
ChatUtil.sendErrorMessage(p, "Map " + mapname + " nicht gefunden!");
this.online = false;
@@ -162,4 +180,12 @@
public void despawnPiglin() {
this.plugin.despawnPiglin(this.name);
}
+
+ public void spawnNPC(Player player) {
+ this.plugin.spawnNPC(this.piglinLocation, this.name, this.gPLocation, player.getName(), false);
+ }
+
+ public void despawnNPC() {
+ this.plugin.despawnNPC(this.name);
+ }
}
\ No newline at end of file
diff --git a/src/main/java/de/fanta/challengesjoinentities/ServerType.java b/src/main/java/de/fanta/challengesjoinentities/ServerType.java
index 9ac3ee0..a02feb9 100644
--- a/src/main/java/de/fanta/challengesjoinentities/ServerType.java
+++ b/src/main/java/de/fanta/challengesjoinentities/ServerType.java
@@ -5,7 +5,7 @@
ADVENTURE("Adventure-saves"),
CHALLENGES("saves");
- private String dir;
+ private final String dir;
ServerType(String dir) {
this.dir = dir;
diff --git a/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureLoadCommand.java b/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureLoadCommand.java
index f563c21..f8faf9e 100644
--- a/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureLoadCommand.java
+++ b/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureLoadCommand.java
@@ -3,6 +3,7 @@
import de.fanta.challengesjoinentities.ChallengesJoinEntities;
import de.fanta.challengesjoinentities.ChatUtil;
import de.fanta.challengesjoinentities.Server;
+import de.fanta.challengesjoinentities.loadgui.AdventureLoadGUI;
import de.iani.cubesideutils.bukkit.commands.SubCommand;
import de.iani.cubesideutils.commands.ArgsParser;
import org.bukkit.command.Command;
@@ -22,20 +23,18 @@
return true;
}
if (!args.hasNext()) {
- if (!Server.serverPlayers.containsValue(p.getUniqueId())) {
- plugin.getPluginConfig().getOnlineAdventureServer().ifPresentOrElse(server -> server.loadSaved(p), () -> ChatUtil.sendErrorMessage(sender, "Aktuell ist kein Server Frei!"));
- } else {
- ChatUtil.sendErrorMessage(sender, "Du kannst nur einen Server starten!");
- }
+ AdventureLoadGUI.createloadGUI(p);
return true;
}
String next = args.getNext();
- if (sender.hasPermission("challenges.load.admin"))
+ Boolean autosave = Boolean.parseBoolean(args.getNext());
+ if (sender.hasPermission("challenges.load.admin")) {
if (!Server.serverPlayers.containsValue(p.getUniqueId())) {
- this.plugin.getPluginConfig().getOnlineAdventureServer().ifPresentOrElse(server -> server.loadSaved(p, next.toLowerCase()), () -> ChatUtil.sendErrorMessage(sender, "Aktuell ist kein Server Frei!"));
+ this.plugin.getPluginConfig().getOnlineAdventureServer().ifPresentOrElse(server -> server.loadSaved(p, next.toLowerCase(), autosave), () -> ChatUtil.sendErrorMessage(sender, "Aktuell ist kein Server Frei!"));
} else {
ChatUtil.sendErrorMessage(sender, "Du kannst nur einen Server starten!");
}
+ }
return true;
}
}
diff --git a/src/main/java/de/fanta/challengesjoinentities/commands/ChallengesCommand/ChallengesloadCommand.java b/src/main/java/de/fanta/challengesjoinentities/commands/ChallengesCommand/ChallengesloadCommand.java
index f7d7020..343cf6b 100644
--- a/src/main/java/de/fanta/challengesjoinentities/commands/ChallengesCommand/ChallengesloadCommand.java
+++ b/src/main/java/de/fanta/challengesjoinentities/commands/ChallengesCommand/ChallengesloadCommand.java
@@ -3,6 +3,7 @@
import de.fanta.challengesjoinentities.ChallengesJoinEntities;
import de.fanta.challengesjoinentities.ChatUtil;
import de.fanta.challengesjoinentities.Server;
+import de.fanta.challengesjoinentities.loadgui.ChallengeLoadGUI;
import de.iani.cubesideutils.bukkit.commands.SubCommand;
import de.iani.cubesideutils.commands.ArgsParser;
import org.bukkit.command.Command;
@@ -22,20 +23,18 @@
return true;
}
if (!args.hasNext()) {
- if (!Server.serverPlayers.containsValue(p.getUniqueId())) {
- this.plugin.getPluginConfig().getOnlineChanllengeServer().ifPresentOrElse(server -> server.loadSaved(p), () -> ChatUtil.sendErrorMessage(sender, "Aktuell ist kein Server Frei!"));
- } else {
- ChatUtil.sendErrorMessage(sender, "Du kannst nur einen Server starten!");
- }
+ ChallengeLoadGUI.createloadGUI(p);
return true;
}
String next = args.getNext();
- if (sender.hasPermission("challenges.load.admin"))
+ Boolean autosave = Boolean.parseBoolean(args.getNext());
+ if (sender.hasPermission("challenges.load.admin")) {
if (!Server.serverPlayers.containsValue(p.getUniqueId())) {
- this.plugin.getPluginConfig().getOnlineChanllengeServer().ifPresentOrElse(server -> server.loadSaved(p, next.toLowerCase()), () -> ChatUtil.sendErrorMessage(sender, "Aktuell ist kein Server Frei!"));
+ this.plugin.getPluginConfig().getOnlineChanllengeServer().ifPresentOrElse(server -> server.loadSaved(p, next.toLowerCase(), autosave), () -> ChatUtil.sendErrorMessage(sender, "Aktuell ist kein Server Frei!"));
} else {
ChatUtil.sendErrorMessage(sender, "Du kannst nur einen Server starten!");
}
+ }
return true;
}
}
diff --git a/src/main/java/de/fanta/challengesjoinentities/commands/PiglinCommand/Entitytphere.java b/src/main/java/de/fanta/challengesjoinentities/commands/PiglinCommand/Entitytphere.java
new file mode 100644
index 0000000..8a34205
--- /dev/null
+++ b/src/main/java/de/fanta/challengesjoinentities/commands/PiglinCommand/Entitytphere.java
@@ -0,0 +1,68 @@
+package de.fanta.challengesjoinentities.commands.PiglinCommand;
+
+import de.fanta.challengesjoinentities.ChallengesJoinEntities;
+import de.fanta.challengesjoinentities.ChatUtil;
+import de.iani.cubesideutils.bukkit.commands.SubCommand;
+import de.iani.cubesideutils.commands.ArgsParser;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Piglin;
+import org.bukkit.entity.Player;
+
+import java.util.Collection;
+import java.util.Collections;
+
+public class Entitytphere extends SubCommand {
+
+ private final ChallengesJoinEntities plugin;
+
+ public Entitytphere(ChallengesJoinEntities plugin) {
+ this.plugin = plugin;
+ }
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) {
+ if (!(sender instanceof Player p)) {
+ ChatUtil.sendErrorMessage(sender, "Du musst ein Spieler sein!");
+ return true;
+ }
+
+ if (!sender.hasPermission("challenges.spawn.teleporter")) {
+ ChatUtil.sendErrorMessage(sender, "Keine Berechtigung!");
+ return true;
+ }
+
+ if (args.hasNext()) {
+ String serverName = args.getNext();
+ Piglin piglin = plugin.getPiglinForServerName(serverName);
+ if (piglin != null) {
+ piglin.teleport(p.getLocation());
+ ChatUtil.sendNormalMessage(sender, "Piglin wurde zu dir Teleportiert.");
+ } else {
+ ChatUtil.sendErrorMessage(sender, "Kein Piglin für diesen Server gefunden!");
+ }
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public Collection onTabComplete(CommandSender sender, Command command, String alias, ArgsParser args) {
+ args.next();
+ if (!args.hasNext()) {
+ return plugin.getEntityData().keySet();
+ }
+
+ return Collections.emptyList();
+ }
+
+ @Override
+ public String getUsage() {
+ return "";
+ }
+
+ @Override
+ public String getRequiredPermission() {
+ return "challenges.spawn.teleporter";
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/de/fanta/challengesjoinentities/commands/PiglinCommand/ListPiglinCommand.java b/src/main/java/de/fanta/challengesjoinentities/commands/PiglinCommand/ListPiglinCommand.java
new file mode 100644
index 0000000..3e81a26
--- /dev/null
+++ b/src/main/java/de/fanta/challengesjoinentities/commands/PiglinCommand/ListPiglinCommand.java
@@ -0,0 +1,35 @@
+package de.fanta.challengesjoinentities.commands.PiglinCommand;
+
+import de.fanta.challengesjoinentities.ChallengesJoinEntities;
+import de.fanta.challengesjoinentities.ChatUtil;
+import de.iani.cubesideutils.bukkit.commands.SubCommand;
+import de.iani.cubesideutils.commands.ArgsParser;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class ListPiglinCommand extends SubCommand {
+
+ private final ChallengesJoinEntities plugin;
+
+ public ListPiglinCommand(ChallengesJoinEntities plugin) {
+ this.plugin = plugin;
+ }
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) {
+ if (!(sender instanceof Player p)) {
+ ChatUtil.sendErrorMessage(sender, "Du musst ein Spieler sein!");
+ return true;
+ }
+
+ if (!sender.hasPermission("challenges.spawn.teleporter")) {
+ ChatUtil.sendErrorMessage(sender, "Keine Berechtigung!");
+ return true;
+ }
+ ChatUtil.sendNormalMessage(p, "-------------------------------");
+ plugin.getEntityData().keySet().forEach(server -> ChatUtil.sendNormalMessage(p, plugin.getPiglinForServerName(server).getName() + ": " + server));
+ ChatUtil.sendNormalMessage(p, "-------------------------------");
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/de/fanta/challengesjoinentities/listeners/EntityListener.java b/src/main/java/de/fanta/challengesjoinentities/listeners/EntityListener.java
index 3e72d36..8282e8c 100644
--- a/src/main/java/de/fanta/challengesjoinentities/listeners/EntityListener.java
+++ b/src/main/java/de/fanta/challengesjoinentities/listeners/EntityListener.java
@@ -4,6 +4,10 @@
import de.fanta.challengesjoinentities.ChatUtil;
import de.fanta.challengesjoinentities.JoinEntityData;
import de.speedy64.globalport.GlobalApi;
+import io.papermc.paper.event.entity.EntityMoveEvent;
+import net.citizensnpcs.api.event.NPCClickEvent;
+import net.citizensnpcs.api.event.NPCDamageByEntityEvent;
+import net.citizensnpcs.api.event.NPCRightClickEvent;
import org.bukkit.GameMode;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
@@ -15,6 +19,8 @@
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.inventory.EquipmentSlot;
+import java.util.UUID;
+
public class EntityListener implements Listener {
private final ChallengesJoinEntities plugin;
@@ -31,7 +37,7 @@
if (event.getPlayer().getGameMode() != GameMode.CREATIVE || !event.getPlayer().isSneaking()) {
event.setCancelled(true);
- onPlayerClickEntity(event.getPlayer(), event.getRightClicked());
+ onPlayerClickEntity(event.getPlayer(), event.getRightClicked().getUniqueId());
}
}
@@ -50,15 +56,35 @@
event.setCancelled(true);
if (event.getDamager() instanceof Player) {
- onPlayerClickEntity((Player) event.getDamager(), event.getEntity());
+ onPlayerClickEntity((Player) event.getDamager(), event.getEntity().getUniqueId());
}
}
- public void onPlayerClickEntity(Player player, Entity clicked) {
+ @EventHandler
+ public void onEntityMove(EntityMoveEvent e) {
+ if (plugin.isJoinEntity(e.getEntity())) {
+ e.setCancelled(true);
+ }
+ }
+
+ @EventHandler
+ public void onNPCClick(NPCRightClickEvent e) {
+ Player p = e.getClicker();
+ onPlayerClickEntity(p, e.getNPC().getUniqueId());
+ }
+
+ @EventHandler
+ public void onNPCRightClick(NPCDamageByEntityEvent e) {
+ if (e.getDamager() instanceof Player p) {
+ onPlayerClickEntity(p, e.getNPC().getUniqueId());
+ }
+ }
+
+ public void onPlayerClickEntity(Player player, UUID clicked) {
if (player == null || clicked == null) {
return;
}
- String serverName = plugin.getServerNameForEntity(clicked.getUniqueId());
+ String serverName = plugin.getServerNameForEntity(clicked);
if (serverName == null) {
return;
}
diff --git a/src/main/java/de/fanta/challengesjoinentities/loadgui/AdventureLoadGUI.java b/src/main/java/de/fanta/challengesjoinentities/loadgui/AdventureLoadGUI.java
new file mode 100644
index 0000000..a867933
--- /dev/null
+++ b/src/main/java/de/fanta/challengesjoinentities/loadgui/AdventureLoadGUI.java
@@ -0,0 +1,78 @@
+package de.fanta.challengesjoinentities.loadgui;
+
+import de.fanta.challengesjoinentities.ChallengesJoinEntities;
+import de.fanta.challengesjoinentities.ChatUtil;
+import de.fanta.challengesjoinentities.Server;
+import de.fanta.challengesjoinentities.utils.guiutils.GUIUtils;
+import net.md_5.bungee.api.ChatColor;
+import org.bukkit.Bukkit;
+import org.bukkit.Material;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.inventory.InventoryClickEvent;
+import org.bukkit.event.inventory.InventoryType;
+import org.bukkit.inventory.Inventory;
+import org.bukkit.inventory.ItemStack;
+
+import java.io.File;
+
+public class AdventureLoadGUI implements Listener {
+
+ private static final ChallengesJoinEntities plugin = ChallengesJoinEntities.getPlugin();
+
+ private static final int SAVE_1_INDEX = 1;
+ private static final int AUTOSAVE_INDEX = 3;
+
+ public static final int INVENTORY_SIZE = 5;
+ public static final Inventory RESET_GUI = Bukkit.createInventory(null, InventoryType.HOPPER, ChallengesJoinEntities.ADVENTUREGUIPREFIX + " >> AdventureMap laden");
+
+ public static void createloadGUI(Player p) {
+ File adventuresave = new File("/home/minecraft/Adventure-saves/" + p.getUniqueId() + "/1");
+ File adventureautosave = new File("/home/minecraft/Adventure-saves/" + p.getUniqueId() + "/autosave");
+
+ if (adventuresave.isDirectory()) {
+ RESET_GUI.setItem(SAVE_1_INDEX, GUIUtils.createGuiItem(Material.MAP, ChatColor.GREEN + "Save 1", ChatColor.GREEN + "Klicken zum laden."));
+ } else {
+ RESET_GUI.setItem(SAVE_1_INDEX, GUIUtils.createGuiItem(Material.BARRIER, ChatColor.DARK_RED + "Du hast noch keine Map gespeichert."));
+ }
+
+ if (adventureautosave.isDirectory()) {
+ RESET_GUI.setItem(AUTOSAVE_INDEX, GUIUtils.createGuiItem(Material.CLOCK, ChatUtil.GREEN + "AutoSave", ChatColor.GREEN + "Klicken zum laden."));
+ } else {
+ RESET_GUI.setItem(AUTOSAVE_INDEX, GUIUtils.createGuiItem(Material.BARRIER, ChatColor.DARK_RED + "Du hast noch keine Map gespeichert."));
+ }
+
+ for (int i = 0; i < INVENTORY_SIZE; i++) {
+ ItemStack item = RESET_GUI.getItem(i);
+ if (item == null || item.getType() == Material.AIR) {
+ RESET_GUI.setItem(i, GUIUtils.EMPTY_ICON);
+ }
+ }
+ p.openInventory(RESET_GUI);
+ }
+
+ @EventHandler
+ public void onInventoryClick(InventoryClickEvent e) {
+ int slot = e.getRawSlot();
+ Player p = (Player) e.getWhoClicked();
+ if (RESET_GUI.equals(e.getClickedInventory())) {
+ if (slot == SAVE_1_INDEX) {
+ if (!Server.serverPlayers.containsValue(p.getUniqueId())) {
+ plugin.getPluginConfig().getOnlineAdventureServer().ifPresentOrElse(server -> server.loadSaved(p, false), () -> ChatUtil.sendErrorMessage(p, "Aktuell ist kein Server Frei!"));
+ } else {
+ ChatUtil.sendErrorMessage(p, "Du kannst nur einen Server starten!");
+ }
+ }
+ if (slot == AUTOSAVE_INDEX) {
+ if (!Server.serverPlayers.containsValue(p.getUniqueId())) {
+ plugin.getPluginConfig().getOnlineAdventureServer().ifPresentOrElse(server -> server.loadSaved(p, true), () -> ChatUtil.sendErrorMessage(p, "Aktuell ist kein Server Frei!"));
+ } else {
+ ChatUtil.sendErrorMessage(p, "Du kannst nur einen Server starten!");
+ }
+ }
+ p.closeInventory();
+ e.setCancelled(true);
+ }
+ }
+}
diff --git a/src/main/java/de/fanta/challengesjoinentities/loadgui/ChallengeLoadGUI.java b/src/main/java/de/fanta/challengesjoinentities/loadgui/ChallengeLoadGUI.java
new file mode 100644
index 0000000..76246ea
--- /dev/null
+++ b/src/main/java/de/fanta/challengesjoinentities/loadgui/ChallengeLoadGUI.java
@@ -0,0 +1,78 @@
+package de.fanta.challengesjoinentities.loadgui;
+
+import de.fanta.challengesjoinentities.ChallengesJoinEntities;
+import de.fanta.challengesjoinentities.ChatUtil;
+import de.fanta.challengesjoinentities.Server;
+import de.fanta.challengesjoinentities.utils.guiutils.GUIUtils;
+import net.md_5.bungee.api.ChatColor;
+import org.bukkit.Bukkit;
+import org.bukkit.Material;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.inventory.InventoryClickEvent;
+import org.bukkit.event.inventory.InventoryType;
+import org.bukkit.inventory.Inventory;
+import org.bukkit.inventory.ItemStack;
+
+import java.io.File;
+
+public class ChallengeLoadGUI implements Listener {
+
+ private static final ChallengesJoinEntities plugin = ChallengesJoinEntities.getPlugin();
+
+ private static final int SAVE_1_INDEX = 1;
+ private static final int AUTOSAVE_INDEX = 3;
+
+ public static final int INVENTORY_SIZE = 5;
+ public static final Inventory RESET_GUI = Bukkit.createInventory(null, InventoryType.HOPPER, ChallengesJoinEntities.CHALLENGEGUIPREFIX + " >> Challenge laden");
+
+ public static void createloadGUI(Player p) {
+ File adventuresave = new File("/home/minecraft/saves/" + p.getUniqueId() + "/1");
+ File adventureautosave = new File("/home/minecraft/saves/" + p.getUniqueId() + "/autosave");
+
+ if (adventuresave.isDirectory()) {
+ RESET_GUI.setItem(SAVE_1_INDEX, GUIUtils.createGuiItem(Material.MAP, ChatColor.GREEN + "Save 1", ChatColor.GREEN + "Klicken zum laden."));
+ } else {
+ RESET_GUI.setItem(SAVE_1_INDEX, GUIUtils.createGuiItem(Material.BARRIER, ChatColor.DARK_RED + "Du hast noch keine Map gespeichert."));
+ }
+
+ if (adventureautosave.isDirectory()) {
+ RESET_GUI.setItem(AUTOSAVE_INDEX, GUIUtils.createGuiItem(Material.CLOCK, ChatUtil.GREEN + "AutoSave", ChatColor.GREEN + "Klicken zum laden."));
+ } else {
+ RESET_GUI.setItem(AUTOSAVE_INDEX, GUIUtils.createGuiItem(Material.BARRIER, ChatColor.DARK_RED + "Du hast noch keine Map gespeichert."));
+ }
+
+ for (int i = 0; i < INVENTORY_SIZE; i++) {
+ ItemStack item = RESET_GUI.getItem(i);
+ if (item == null || item.getType() == Material.AIR) {
+ RESET_GUI.setItem(i, GUIUtils.EMPTY_ICON);
+ }
+ }
+ p.openInventory(RESET_GUI);
+ }
+
+ @EventHandler
+ public void onInventoryClick(InventoryClickEvent e) {
+ int slot = e.getRawSlot();
+ Player p = (Player) e.getWhoClicked();
+ if (RESET_GUI.equals(e.getClickedInventory())) {
+ if (slot == SAVE_1_INDEX) {
+ if (!Server.serverPlayers.containsValue(p.getUniqueId())) {
+ plugin.getPluginConfig().getOnlineChanllengeServer().ifPresentOrElse(server -> server.loadSaved(p, false), () -> ChatUtil.sendErrorMessage(p, "Aktuell ist kein Server Frei!"));
+ } else {
+ ChatUtil.sendErrorMessage(p, "Du kannst nur einen Server starten!");
+ }
+ }
+ if (slot == AUTOSAVE_INDEX) {
+ if (!Server.serverPlayers.containsValue(p.getUniqueId())) {
+ plugin.getPluginConfig().getOnlineChanllengeServer().ifPresentOrElse(server -> server.loadSaved(p, true), () -> ChatUtil.sendErrorMessage(p, "Aktuell ist kein Server Frei!"));
+ } else {
+ ChatUtil.sendErrorMessage(p, "Du kannst nur einen Server starten!");
+ }
+ }
+ p.closeInventory();
+ e.setCancelled(true);
+ }
+ }
+}
diff --git a/src/main/java/de/fanta/challengesjoinentities/utils/guiutils/GUIUtils.java b/src/main/java/de/fanta/challengesjoinentities/utils/guiutils/GUIUtils.java
new file mode 100644
index 0000000..df4d900
--- /dev/null
+++ b/src/main/java/de/fanta/challengesjoinentities/utils/guiutils/GUIUtils.java
@@ -0,0 +1,51 @@
+package de.fanta.challengesjoinentities.utils.guiutils;
+
+import de.fanta.challengesjoinentities.ChallengesJoinEntities;
+import de.fanta.challengesjoinentities.ChatUtil;
+import net.md_5.bungee.api.ChatColor;
+import org.bukkit.Bukkit;
+import org.bukkit.Material;
+import org.bukkit.Sound;
+import org.bukkit.enchantments.Enchantment;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.ItemFlag;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+
+import java.util.Arrays;
+
+public class GUIUtils {
+
+ private static final ChallengesJoinEntities plugin = ChallengesJoinEntities.getPlugin();
+
+ public static final ItemStack EMPTY_ICON = createGuiItem(Material.GRAY_STAINED_GLASS_PANE, "§1", true);
+
+ public static ItemStack createGuiItem(Material material, String name, String... lore) {
+ return createGuiItem(material, name, false, lore);
+ }
+
+ public static ItemStack createGuiItem(final Material material, final String name, boolean glowing, final String... lore) {
+ final ItemStack item = new ItemStack(material, 1);
+ final ItemMeta meta = item.getItemMeta();
+ meta.setDisplayName(name);
+ meta.setLore(Arrays.asList(lore));
+ if (glowing) {
+ meta.addEnchant(Enchantment.MENDING, 1, false);
+ meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
+ }
+ item.setItemMeta(meta);
+ return item;
+ }
+
+ public static void sendTitleToAll(String headline, String text, ChatColor textColor) {
+ for (Player p : Bukkit.getOnlinePlayers()) {
+ p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 1.0F, 2.0F);
+ p.sendTitle(ChatUtil.BLUE + headline, textColor + text, 10, 60, 10);
+ }
+ }
+
+ public static void setConfig(String path, Object value) {
+ plugin.getConfig().set(path, value);
+ plugin.saveConfig();
+ }
+}
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index b8b8fd2..a7a8ee8 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -5,7 +5,7 @@
api-version: 1.17
depend: [GlobalClient, CubesideUtils, GlobalPort, CubesideNMSUtils]
-softdepend: [Challenges]
+softdepend: [Challenges, Citizens]
commands:
piglins: