diff --git a/Lobby/src/main/java/de/fanta/lobby/Config.java b/Lobby/src/main/java/de/fanta/lobby/Config.java index d4f7bce..d6f9262 100644 --- a/Lobby/src/main/java/de/fanta/lobby/Config.java +++ b/Lobby/src/main/java/de/fanta/lobby/Config.java @@ -42,7 +42,16 @@ if (piglinsSection != null) { for (String serverName : piglinsSection.getKeys(false)) { ConfigurationSection piglin = piglinsSection.getConfigurationSection(serverName); - plugin.addPiglin(UUID.fromString(piglin.getString("uuid")), serverName, piglin.getString("gpLocation"), piglin.getString("displayName"), false); + ConfigurationSection hangableSection = piglin.getConfigurationSection("hangableData"); + HangableData hangableData = null; + if (hangableSection != null) { + boolean hangable = hangableSection.getBoolean("hangable"); + Location fenceLocation = hangableSection.getLocation("fenceLocation"); + Location onlineBlockLocation = hangableSection.getLocation("onlineBlockLocation"); + Location offlineBlockLocation = hangableSection.getLocation("offlineBlockLocation"); + hangableData = new HangableData(hangable, fenceLocation, null, onlineBlockLocation, null, offlineBlockLocation); + } + plugin.addPiglin(UUID.fromString(piglin.getString("uuid")), serverName, piglin.getString("gpLocation"), piglin.getString("displayName"), hangableData, false); plugin.getGlobalDataHelper().requestInitialData(serverName); } } @@ -98,7 +107,6 @@ public void savePiglin(JoinEntityData data) { FileConfiguration config = plugin.getConfig(); ConfigurationSection piglinsSection = config.getConfigurationSection("piglins"); - if (piglinsSection == null) { config.createSection("piglins"); piglinsSection = config.getConfigurationSection("piglins"); @@ -108,7 +116,15 @@ piglin.set("uuid", data.getEntityUUID().toString()); piglin.set("gpLocation", data.getGlobalPortLocationName()); piglin.set("displayName", data.getServerDisplayName()); - piglin.set("hangable", data.isHangable()); + + HangableData hangableData = data.getHangableData(); + if (hangableData != null) { + ConfigurationSection hangableSection = piglin.createSection("hangableData"); + hangableSection.set("hangable", hangableData.isHangable()); + hangableSection.set("fenceLocation", hangableData.getFenceLocation()); + hangableSection.set("onlineBlockLocation", hangableData.getOnlineBlockLocation()); + hangableSection.set("offlineBlockLocation", hangableData.getOfflineBlockLocation()); + } plugin.saveConfig(); } diff --git a/Lobby/src/main/java/de/fanta/lobby/HangableData.java b/Lobby/src/main/java/de/fanta/lobby/HangableData.java new file mode 100644 index 0000000..8cdc616 --- /dev/null +++ b/Lobby/src/main/java/de/fanta/lobby/HangableData.java @@ -0,0 +1,81 @@ +package de.fanta.lobby; + + +import org.bukkit.Location; +import org.jetbrains.annotations.Nullable; + +public class HangableData { + + private boolean isHangable; + + private Location fenceLocation; + + private String onlineBlock; + private Location onlineBlockLocation; + + private String offlineBlock; + private Location offlineBlockLocation; + + public HangableData(boolean isHangable, @Nullable Location fenceLocation, @Nullable String onlineBlock, @Nullable Location onlineBlockLocation, @Nullable String offlineBlock, @Nullable Location offlineBlockLocation) { + this.isHangable = isHangable; + this.fenceLocation = fenceLocation; + this.onlineBlock = onlineBlock; + this.onlineBlockLocation = onlineBlockLocation; + this.offlineBlock = offlineBlock; + this.offlineBlockLocation = offlineBlockLocation; + } + + public boolean isHangable() { + return isHangable; + } + + public void setHangable(boolean hangable) { + isHangable = hangable; + } + + @Nullable + public Location getFenceLocation() { + return fenceLocation; + } + + + public void setFenceLocation(Location fenceLocation) { + this.fenceLocation = fenceLocation; + } + + @Nullable + public String getOnlineBlock() { + return onlineBlock; + } + + public void setOnlineBlock(String onlineBlock) { + this.onlineBlock = onlineBlock; + } + + @Nullable + public Location getOnlineBlockLocation() { + return onlineBlockLocation; + } + + public void setOnlineBlockLocation(Location onlineBlockLocation) { + this.onlineBlockLocation = onlineBlockLocation; + } + + @Nullable + public String getOfflineBlock() { + return offlineBlock; + } + + public void setOfflineBlock(String offlineBlock) { + this.offlineBlock = offlineBlock; + } + + @Nullable + public Location getOfflineBlockLocation() { + return offlineBlockLocation; + } + + public void setOfflineBlockLocation(Location offlineBlockLocation) { + this.offlineBlockLocation = offlineBlockLocation; + } +} diff --git a/Lobby/src/main/java/de/fanta/lobby/JoinEntityData.java b/Lobby/src/main/java/de/fanta/lobby/JoinEntityData.java index 3fb6e3d..ea1da97 100644 --- a/Lobby/src/main/java/de/fanta/lobby/JoinEntityData.java +++ b/Lobby/src/main/java/de/fanta/lobby/JoinEntityData.java @@ -17,11 +17,11 @@ private EventStatus eventStatus; private int playerCount; private int maxPlayers; - private boolean isHangable; + private HangableData hangableData; private final int mapVersion; - public JoinEntityData(String serverName, @Nullable Integer mapVersion, UUID entityUUID, String globalPortLocationName, String serverDisplayName, ServerStatus serverStatus, EventStatus eventStatus, int playerCount, int maxPlayers, boolean isHangable) { + public JoinEntityData(String serverName, @Nullable Integer mapVersion, UUID entityUUID, String globalPortLocationName, String serverDisplayName, ServerStatus serverStatus, EventStatus eventStatus, int playerCount, int maxPlayers) { this.serverName = serverName; this.mapVersion = mapVersion == null ? 0 : mapVersion; this.entityUUID = entityUUID; @@ -32,7 +32,6 @@ this.eventStatus = eventStatus; this.playerCount = playerCount; this.maxPlayers = maxPlayers; - this.isHangable = isHangable; } public String getServerName() { @@ -87,9 +86,14 @@ return mapVersion; } - public boolean isHangable() {return isHangable;} + @Nullable + public HangableData getHangableData() { + return hangableData; + } - public void setHangable(boolean isHangable) {this.isHangable = isHangable;} + public void setHangableData(HangableData hangableData) { + this.hangableData = hangableData; + } public Component createCustomEntityName() { Component statusComponent = serverStatus == ServerStatus.ONLINE ? Component.text(" ONLINE ", Color.GREEN) : serverStatus == ServerStatus.OFFLINE ? Component.text(" OFFLINE ", Color.RED) : serverStatus == ServerStatus.RUNNING ? Component.text(" RUNNING ", Color.ORANGE) : Component.text(" "); diff --git a/Lobby/src/main/java/de/fanta/lobby/Lobby.java b/Lobby/src/main/java/de/fanta/lobby/Lobby.java index 117a496..66be41c 100644 --- a/Lobby/src/main/java/de/fanta/lobby/Lobby.java +++ b/Lobby/src/main/java/de/fanta/lobby/Lobby.java @@ -28,7 +28,7 @@ import de.fanta.lobby.commands.PiglinCommand.ListPiglinCommand; import de.fanta.lobby.commands.PiglinCommand.RemoveEntityCommand; import de.fanta.lobby.commands.PiglinCommand.SetEntitySpawnLocationCommand; -import de.fanta.lobby.commands.PiglinCommand.SetHangablePiglinCommand; +import de.fanta.lobby.commands.PiglinCommand.HangableDataPiglinCommand; import de.fanta.lobby.commands.PiglinCommand.ToggleArenaCommand; import de.fanta.lobby.listeners.AnvilGuiListener; import de.fanta.lobby.listeners.ChallengesEventListener; @@ -160,7 +160,7 @@ router.addCommandMapping(new Entitytphere(this), "tphere"); router.addCommandMapping(new ListPiglinCommand(this), "list"); router.addCommandMapping(new InfoPiglinCommand(this), "info"); - router.addCommandMapping(new SetHangablePiglinCommand(this), "sethangable"); + router.addCommandMapping(new HangableDataPiglinCommand(this), "hangabledata"); router.addCommandMapping(new SetEntitySpawnLocationCommand(this), "setlocation"); router.addCommandMapping(new ToggleArenaCommand(this, true), "enable"); router.addCommandMapping(new ToggleArenaCommand(this, false), "disable"); @@ -214,7 +214,7 @@ piglin.setRemoveWhenFarAway(false); piglin.setPersistent(true); piglin.setCustomNameVisible(true); - addPiglin(piglin.getUniqueId(), serverName, serverVersion, gpLocationName, serverDisplayName, saveToConfig); + addPiglin(piglin.getUniqueId(), serverName, serverVersion, gpLocationName, serverDisplayName, null, saveToConfig); globalDataHelper.requestInitialData(serverName); } @@ -259,12 +259,15 @@ removePiglin(serverName); } - public void addPiglin(UUID piglinUUID, String serverName, String gpLocationName, String serverDisplayName, boolean saveToConfig) { - addPiglin(piglinUUID, serverName, null, gpLocationName, serverDisplayName, saveToConfig); + public void addPiglin(UUID piglinUUID, String serverName, String gpLocationName, String serverDisplayName, @Nullable HangableData hangableData, boolean saveToConfig) { + addPiglin(piglinUUID, serverName, null, gpLocationName, serverDisplayName, hangableData, saveToConfig); } - public void addPiglin(UUID piglinUUID, String serverName, @Nullable Integer mapVersion, String gpLocationName, String serverDisplayName, boolean saveToConfig) { - JoinEntityData entityData = new JoinEntityData(serverName, mapVersion, piglinUUID, gpLocationName, serverDisplayName, JoinEntityData.ServerStatus.OFFLINE, JoinEntityData.EventStatus.NORMAL, 0, 0, false); + public void addPiglin(UUID piglinUUID, String serverName, @Nullable Integer mapVersion, String gpLocationName, String serverDisplayName, @Nullable HangableData hangableData, boolean saveToConfig) { + JoinEntityData entityData = new JoinEntityData(serverName, mapVersion, piglinUUID, gpLocationName, serverDisplayName, JoinEntityData.ServerStatus.OFFLINE, JoinEntityData.EventStatus.NORMAL, 0, 0); + if (hangableData != null) { + entityData.setHangableData(hangableData); + } this.entityData.put(serverName, entityData); this.entityServerMapping.put(piglinUUID, serverName); @@ -358,7 +361,14 @@ switch (data.getServerStatus()) { case ONLINE -> { piglin.getEquipment().clear(); - if (data.isHangable()) { + HangableData hangableData = data.getHangableData(); + boolean isHangable; + if (hangableData == null) { + isHangable = false; + } else { + isHangable = hangableData.isHangable(); + } + if (isHangable) { Location location = piglin.getLocation().clone(); location.setPitch(0); piglin.teleport(location); @@ -371,7 +381,14 @@ if (nmsUtils != null) { nmsUtils.getEntityUtils().setPiglinDancing(piglin, false); } - if (data.isHangable()) { + HangableData hangableData = data.getHangableData(); + boolean isHangable; + if (hangableData == null) { + isHangable = false; + } else { + isHangable = hangableData.isHangable(); + } + if (isHangable) { Location location = piglin.getLocation().clone(); location.setPitch(45); piglin.teleport(location); diff --git a/Lobby/src/main/java/de/fanta/lobby/commands/PiglinCommand/HangableDataPiglinCommand.java b/Lobby/src/main/java/de/fanta/lobby/commands/PiglinCommand/HangableDataPiglinCommand.java new file mode 100644 index 0000000..47580f1 --- /dev/null +++ b/Lobby/src/main/java/de/fanta/lobby/commands/PiglinCommand/HangableDataPiglinCommand.java @@ -0,0 +1,136 @@ +package de.fanta.lobby.commands.PiglinCommand; + +import de.fanta.lobby.HangableData; +import de.fanta.lobby.JoinEntityData; +import de.fanta.lobby.Lobby; +import de.iani.cubesideutils.bukkit.commands.SubCommand; +import de.iani.cubesideutils.commands.ArgsParser; +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.block.data.type.Fence; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.util.RayTraceResult; + +import java.util.Collection; +import java.util.List; + +public class HangableDataPiglinCommand extends SubCommand { + + private final Lobby plugin; + + public HangableDataPiglinCommand(Lobby plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) { + if (!(sender instanceof Player player)) { + plugin.getComponentUtil().sendErrorMessage(sender, "Du musst ein Spieler sein!"); + return true; + } + + if (!args.hasNext()) { + return false; + } + + + String serverName = args.getNext(); + if (serverName == null) { + return true; + } + JoinEntityData data = plugin.getEntityData(serverName); + if (data == null) { + return true; + } + + String argsNext = args.getNext(); + HangableData hangableData = data.getHangableData(); + + switch (argsNext) { + case "enabled" -> { + Boolean isHangable = args.getNext(false); + if (isHangable == null) { + return false; + } + if (hangableData == null) { + hangableData = new HangableData(isHangable, null, null, null, null, null); + } + hangableData.setHangable(isHangable); + data.setHangableData(hangableData); + plugin.getComponentUtil().sendNormalMessage(player, "Das Join Entity von " + serverName + (isHangable ? " ist nun hangable." : " ist nun nicht mehr hangable.")); + } + case "fenceLocation" -> { + Block block = getTargetBlock(player); + if (!(block.getBlockData() instanceof Fence)) { + plugin.getComponentUtil().sendWarningMessage(player, "Du musst einen Zaun anschauen."); + return true; + } + Location fenceLocation = block.getLocation(); + if (hangableData == null) { + hangableData = new HangableData(false, fenceLocation, null, null, null, null); + } + hangableData.setFenceLocation(fenceLocation); + data.setHangableData(hangableData); + plugin.getComponentUtil().sendNormalMessage(player, "Die Fence Location von " + serverName + " wurde erfolgreich gesetzt."); + } + case "onlineBlockLocation" -> { + Block block = getTargetBlock(player); + if (block == null) { + plugin.getComponentUtil().sendWarningMessage(player, "Du musst einen Block anschauen."); + return true; + } + Location blockLaction = block.getLocation(); + if (hangableData == null) { + hangableData = new HangableData(false, null, null, blockLaction, null, null); + } + hangableData.setOnlineBlockLocation(blockLaction); + data.setHangableData(hangableData); + plugin.getComponentUtil().sendNormalMessage(player, "Die Onlineblock Location von " + serverName + " wurde erfolgreich gesetzt."); + } + case "offlineBlockLocation" -> { + Block block = getTargetBlock(player); + if (block == null) { + plugin.getComponentUtil().sendWarningMessage(player, "Du musst einen Block anschauen."); + return true; + } + Location blockLaction = block.getLocation(); + if (hangableData == null) { + hangableData = new HangableData(false, null, null, null, null, blockLaction); + } + hangableData.setOfflineBlockLocation(blockLaction); + data.setHangableData(hangableData); + plugin.getComponentUtil().sendNormalMessage(player, "Die Offlineblock von " + serverName + " wurde erfolgreich gesetzt."); + } + default -> { + return false; + } + } + plugin.getPluginConfig().savePiglin(data); + return true; + } + + public Block getTargetBlock(Player player) { + RayTraceResult rayTraceBlocks = player.rayTraceBlocks(10); + if (rayTraceBlocks == null) { + return null; + } + return rayTraceBlocks.getHitBlock(); + } + + @Override + public Collection onTabComplete(CommandSender sender, Command command, String alias, ArgsParser args) { + return List.of("true", "false"); + } + + @Override + public String getRequiredPermission() { + return "lobby.piglin.hangabledata"; + } + + @Override + public String getUsage() { + return " | fenceLocation | onlineBlockLocation | offlineBlockLocation>"; + } +} diff --git a/Lobby/src/main/java/de/fanta/lobby/commands/PiglinCommand/InfoPiglinCommand.java b/Lobby/src/main/java/de/fanta/lobby/commands/PiglinCommand/InfoPiglinCommand.java index bd12667..08b55fb 100644 --- a/Lobby/src/main/java/de/fanta/lobby/commands/PiglinCommand/InfoPiglinCommand.java +++ b/Lobby/src/main/java/de/fanta/lobby/commands/PiglinCommand/InfoPiglinCommand.java @@ -2,6 +2,7 @@ import de.cubeside.connection.GlobalPlayer; import de.cubeside.connection.GlobalServer; +import de.fanta.lobby.HangableData; import de.fanta.lobby.JoinEntityData; import de.fanta.lobby.Lobby; import de.iani.cubesideutils.StringUtil; @@ -41,7 +42,10 @@ plugin.getComponentUtil().sendNormalMessage(player, "GlobalServer Name: " + server); plugin.getComponentUtil().sendNormalMessage(player, "Port Punkt: " + entityData.getGlobalPortLocationName()); plugin.getComponentUtil().sendNormalMessage(player, "Spielerzahl: " + entityData.getPlayerCount() + "/" + entityData.getMaxPlayers()); - plugin.getComponentUtil().sendNormalMessage(player, "Piglin hangable: " + (entityData.isHangable()? "true" : "false")); + HangableData hangableData = entityData.getHangableData(); + if (hangableData != null) { + plugin.getComponentUtil().sendNormalMessage(player, "Piglin hangable: " + (entityData.getHangableData().isHangable()? "true" : "false")); + } GlobalServer globalServer = plugin.getGlobalDataHelper().getServer(server); if (globalServer != null) { Collection globalPlayers = globalServer.getPlayers(); diff --git a/Lobby/src/main/java/de/fanta/lobby/commands/PiglinCommand/SetHangablePiglinCommand.java b/Lobby/src/main/java/de/fanta/lobby/commands/PiglinCommand/SetHangablePiglinCommand.java deleted file mode 100644 index 571fe16..0000000 --- a/Lobby/src/main/java/de/fanta/lobby/commands/PiglinCommand/SetHangablePiglinCommand.java +++ /dev/null @@ -1,81 +0,0 @@ -package de.fanta.lobby.commands.PiglinCommand; - -import de.fanta.lobby.JoinEntityData; -import de.fanta.lobby.Lobby; -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.Entity; -import org.bukkit.entity.Player; - -import java.util.Collection; -import java.util.List; - -public class SetHangablePiglinCommand extends SubCommand { - - private final Lobby plugin; - - public SetHangablePiglinCommand(Lobby plugin) {this.plugin = plugin;} - - @Override - public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) { - if (!(sender instanceof Player player)) { - plugin.getComponentUtil().sendErrorMessage(sender, "Du musst ein Spieler sein!"); - return true; - } - - if (!args.hasNext()) { - return false; - } - - if (player.getTargetEntity(10) == null) { - plugin.getComponentUtil().sendWarningMessage(player, "Du musst ein Entity anschauen."); - return true; - } - - Entity entity = player.getTargetEntity(10); - if (!plugin.isJoinEntity(entity)) { - plugin.getComponentUtil().sendErrorMessage(player, "Nur Join Entities können hangable sein."); - return true; - } - - String serverName = plugin.getServerNameForEntity(entity.getUniqueId()); - if (serverName == null) { - return true; - } - JoinEntityData data = plugin.getEntityData(serverName); - if (data == null) { - return true; - } - - String argsNext = args.getNext(); - if (argsNext.equalsIgnoreCase("true")) { - data.setHangable(true); - plugin.getPluginConfig().savePiglin(data); - plugin.getComponentUtil().sendNormalMessage(player, "Das Join Entity von " + serverName + " ist nun hangable."); - } else if (argsNext.equalsIgnoreCase("false")) { - data.setHangable(false); - plugin.getPluginConfig().savePiglin(data); - plugin.getComponentUtil().sendNormalMessage(player, "Das Join Entity von " + serverName + " ist nun nicht mehr hangable."); - } else { - return false; - } - return true; - } - - @Override - public Collection onTabComplete(CommandSender sender, Command command, String alias, ArgsParser args) { - return List.of("true", "false"); - } - - @Override - public String getRequiredPermission() { - return "lobby.piglin.hangable"; - } - - @Override - public String getUsage() { - return ""; - } -}