diff --git a/src/de/steamwar/lobby/LobbySystem.java b/src/de/steamwar/lobby/LobbySystem.java index 06e7149..56d4c27 100644 --- a/src/de/steamwar/lobby/LobbySystem.java +++ b/src/de/steamwar/lobby/LobbySystem.java @@ -19,6 +19,7 @@ package de.steamwar.lobby; +import de.steamwar.lobby.command.HologramCommand; import de.steamwar.lobby.command.PortalCommand; import de.steamwar.lobby.listener.Fightservers; import de.steamwar.lobby.listener.Join; @@ -28,8 +29,7 @@ import org.bukkit.plugin.java.JavaPlugin; public class LobbySystem extends JavaPlugin { - // This should be treated as final! - public static Message MESSAGE; + private static Message message; private static LobbySystem plugin; private static Config config; @@ -40,14 +40,15 @@ public class LobbySystem extends JavaPlugin { @Override public void onEnable() { - MESSAGE = new Message("de.steamwar.lobby.LobbySystem", getClassLoader()); + message = new Message("de.steamwar.lobby.LobbySystem", getClassLoader()); new Join(); new Fightservers(); new Portals(); - config = new Config(getConfig()); - new PortalCommand(); + new HologramCommand(); + + config = new Config(getConfig()); } public static LobbySystem getPlugin() { @@ -57,4 +58,8 @@ public class LobbySystem extends JavaPlugin { public static Config config() { return config; } + + public static Message getMessage() { + return message; + } } diff --git a/src/de/steamwar/lobby/command/HologramCommand.java b/src/de/steamwar/lobby/command/HologramCommand.java new file mode 100644 index 0000000..fb38db4 --- /dev/null +++ b/src/de/steamwar/lobby/command/HologramCommand.java @@ -0,0 +1,63 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.lobby.command; + +import de.steamwar.command.SWCommand; +import de.steamwar.lobby.LobbySystem; +import de.steamwar.lobby.display.Hologram; +import org.bukkit.entity.Player; + +public class HologramCommand extends SWCommand { + + public HologramCommand() { + super("hologram"); + } + + @Register(help = true) + public void genericHelp(Player player, String... args) { + if (PortalCommand.noPermissions(player)) return; + + player.sendMessage("/hologram create "); + player.sendMessage("/hologram list"); + player.sendMessage("/hologram delete "); + } + + @Register("create") + public void portalCreate(Player player, String id, String... text) { + if (PortalCommand.noPermissions(player)) return; + + new Hologram(id, player.getLocation(), String.join(" ", text)); + LobbySystem.config().save(); + } + + @Register("list") + public void portalList(Player player) { + if (PortalCommand.noPermissions(player)) return; + Hologram.getHolograms().forEach(hologram -> player.sendMessage(hologram.toString())); + } + + @Register("delete") + public void portalDelete(Player player, String id) { + if (PortalCommand.noPermissions(player)) return; + + Hologram.getHologram(id).delete(); + LobbySystem.config().save(); + } +} diff --git a/src/de/steamwar/lobby/command/PortalCommand.java b/src/de/steamwar/lobby/command/PortalCommand.java index 053a601..efb9eb4 100644 --- a/src/de/steamwar/lobby/command/PortalCommand.java +++ b/src/de/steamwar/lobby/command/PortalCommand.java @@ -25,7 +25,7 @@ public class PortalCommand extends SWCommand { super("portal"); } - private boolean noPermissions(Player player) { + public static boolean noPermissions(Player player) { SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId()); return !steamwarUser.getUserGroup().isTeamGroup(); } @@ -33,18 +33,18 @@ public class PortalCommand extends SWCommand { @Register(help = true) public void genericHelp(Player player, String... args) { if (noPermissions(player)) return; - LobbySystem.MESSAGE.sendPrefixless("COMMAND_HELP_HEAD", player, "portal"); - LobbySystem.MESSAGE.sendPrefixless("PORTAL_COMMAND_LIST_HELP", player); - LobbySystem.MESSAGE.sendPrefixless("PORTAL_COMMAND_ADD_HELP", player); - LobbySystem.MESSAGE.sendPrefixless("PORTAL_COMMAND_REMOVE_HELP", player); + LobbySystem.getMessage().sendPrefixless("COMMAND_HELP_HEAD", player, "portal"); + LobbySystem.getMessage().sendPrefixless("PORTAL_COMMAND_LIST_HELP", player); + LobbySystem.getMessage().sendPrefixless("PORTAL_COMMAND_ADD_HELP", player); + LobbySystem.getMessage().sendPrefixless("PORTAL_COMMAND_REMOVE_HELP", player); } @Register("list") public void portalList(Player player) { if (noPermissions(player)) return; - LobbySystem.MESSAGE.sendPrefixless("COMMAND_HELP_HEAD", player, "portal list"); + LobbySystem.getMessage().sendPrefixless("COMMAND_HELP_HEAD", player, "portal list"); Portal.getPortals().forEach(portal -> { - LobbySystem.MESSAGE.sendPrefixless("PORTAL_COMMAND_LIST_SHORT_INFO", player, portal.type().name(), portal.getId(), portal.getPos1().toVector().toString(), portal.getPos1().toVector().toString()); + LobbySystem.getMessage().sendPrefixless("PORTAL_COMMAND_LIST_SHORT_INFO", player, portal.type().name(), portal.getId(), portal.getPos1().toVector().toString(), portal.getPos1().toVector().toString()); }); } @@ -53,7 +53,7 @@ public class PortalCommand extends SWCommand { if (noPermissions(player)) return; Tuple tuple = getSelection(player); if (tuple == null) { - LobbySystem.MESSAGE.send("PORTAL_NO_WORLDEDIT_SELECTION", player); + LobbySystem.getMessage().send("PORTAL_NO_WORLDEDIT_SELECTION", player); return; } new Portal(portalName, tuple.k, tuple.v, portal -> new CommandPortal(String.join(" ", command))); @@ -64,7 +64,7 @@ public class PortalCommand extends SWCommand { if (noPermissions(player)) return; Tuple tuple = getSelection(player); if (tuple == null) { - LobbySystem.MESSAGE.send("PORTAL_NO_WORLDEDIT_SELECTION", player); + LobbySystem.getMessage().send("PORTAL_NO_WORLDEDIT_SELECTION", player); return; } new Portal(portalName, tuple.k, tuple.v, portal -> new FightserverPortal(portal, group, target)); @@ -75,7 +75,7 @@ public class PortalCommand extends SWCommand { if (noPermissions(player)) return; Tuple tuple = getSelection(player); if (tuple == null) { - LobbySystem.MESSAGE.send("PORTAL_NO_WORLDEDIT_SELECTION", player); + LobbySystem.getMessage().send("PORTAL_NO_WORLDEDIT_SELECTION", player); return; } new Portal(portalName, tuple.k, tuple.v, portal -> new TeleportPortal(portal, portalDestination)); @@ -86,7 +86,7 @@ public class PortalCommand extends SWCommand { if (noPermissions(player)) return; Tuple tuple = getSelection(player); if (tuple == null) { - LobbySystem.MESSAGE.send("PORTAL_NO_WORLDEDIT_SELECTION", player); + LobbySystem.getMessage().send("PORTAL_NO_WORLDEDIT_SELECTION", player); return; } new Portal(portalName, tuple.k, tuple.v, portal -> new StackPortal(portal, portalDestination, String.join(" ", command))); diff --git a/src/de/steamwar/lobby/display/Hologram.java b/src/de/steamwar/lobby/display/Hologram.java index ab4662b..259887f 100644 --- a/src/de/steamwar/lobby/display/Hologram.java +++ b/src/de/steamwar/lobby/display/Hologram.java @@ -74,12 +74,15 @@ public class Hologram implements ConfigurationSerializable { private static final Reflection.ConstructorInvoker destoryPacketConstructor = Reflection.getConstructor(destroyPacket); private static final Reflection.FieldAccessor destroyIds = Reflection.getField(destroyPacket, int[].class, 0); - private static final List holograms = new ArrayList<>(); + private static final Map holograms = new HashMap<>(); private static int entityIds = -1; private static final Random random = new Random(); public static List getHolograms() { - return holograms; + return new ArrayList<>(holograms.values()); + } + public static Hologram getHologram(String id) { + return holograms.get(id); } private final Displayable display; @@ -114,7 +117,7 @@ public class Hologram implements ConfigurationSerializable { display = new Displayable(location, this::show, this::hide); if(id != null) - holograms.add(this); + holograms.put(id, this); } private void show(Player player) { @@ -151,4 +154,9 @@ public class Hologram implements ConfigurationSerializable { if(id != null) holograms.remove(this); } + + @Override + public String toString() { + return id + " " + location + " " + text; + } }