diff --git a/src/de/steamwar/lobby/Displayable.java b/src/de/steamwar/lobby/Displayable.java index 7fd21c5..f8836a2 100644 --- a/src/de/steamwar/lobby/Displayable.java +++ b/src/de/steamwar/lobby/Displayable.java @@ -20,6 +20,7 @@ package de.steamwar.lobby; import de.steamwar.lobby.listener.BasicListener; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -46,6 +47,8 @@ public class Displayable extends BasicListener { this.chunkZ = posToChunk(location.getZ()); this.show = show; this.hide = hide; + + Bukkit.getOnlinePlayers().forEach(player -> checkLocation(player, player.getLocation())); } @EventHandler diff --git a/src/de/steamwar/lobby/command/PortalCommand.java b/src/de/steamwar/lobby/command/PortalCommand.java index 9b1e2ea..b83ced2 100644 --- a/src/de/steamwar/lobby/command/PortalCommand.java +++ b/src/de/steamwar/lobby/command/PortalCommand.java @@ -63,7 +63,7 @@ public class PortalCommand extends SWCommand { LobbySystem.MESSAGE.send("PORTAL_NO_WORLDEDIT_SELECTION", player); return; } - new Portal(portalName, tuple.k, tuple.v, portal -> new CommandPortal(portal, String.join(" ", command))); + new Portal(portalName, tuple.k, tuple.v, portal -> new CommandPortal(String.join(" ", command))); } @Register({"create", "fightserver"}) diff --git a/src/de/steamwar/lobby/portal/CommandPortal.java b/src/de/steamwar/lobby/portal/CommandPortal.java index 411c2f3..ae8563f 100644 --- a/src/de/steamwar/lobby/portal/CommandPortal.java +++ b/src/de/steamwar/lobby/portal/CommandPortal.java @@ -19,29 +19,58 @@ package de.steamwar.lobby.portal; +import de.steamwar.lobby.listener.Portals; import org.bukkit.Location; import org.bukkit.entity.Player; +import java.util.Deque; import java.util.Map; public class CommandPortal implements PortalHandler { - private final Portal portal; private final String command; public CommandPortal(Map section, Portal portal) { - this.portal = portal; this.command = (String) section.get("command"); } - public CommandPortal(Portal portal, String command) { - this.portal = portal; + public CommandPortal(String command) { this.command = command; } @Override public void handle(Player player, Location loc) { - player.sendMessage("Folgender Command wäre jetzt ausgeführt worden, könnte der Bungee das schon: " + command); + String[] parts = command.split("\\\\"); + + int[] stackIds = new int[parts.length-1]; + int maxId = 0; + for(int i = 1; i < parts.length; i++) { + stackIds[i-1] = Integer.getInteger(String.valueOf(parts[i].charAt(0))); + if(stackIds[i-1] > maxId) + maxId = stackIds[i-1]; + } + + Deque stack = Portals.getStack(player); + String[] pieces = new String[stackIds.length]; + while (maxId > 0) { + Portal portal = stack.pop(); + if(portal.type() == PortalType.STACK) { + for(int i = 0; i < stackIds.length; i++) { + if(stackIds[i] == maxId) { + pieces[i] = ((StackPortal) portal.getHandler()).getText(); + } + } + + maxId--; + } + } + + StringBuilder cmd = new StringBuilder(parts[0]); + for(int i = 0; i < pieces.length; i++) { + cmd.append(pieces[i]).append(parts[i+1]); + } + + player.sendMessage("Folgender Command wäre jetzt ausgeführt worden, könnte der Bungee das schon: " + cmd); } @Override diff --git a/src/de/steamwar/lobby/portal/Portal.java b/src/de/steamwar/lobby/portal/Portal.java index be7482c..9c9e849 100644 --- a/src/de/steamwar/lobby/portal/Portal.java +++ b/src/de/steamwar/lobby/portal/Portal.java @@ -135,4 +135,7 @@ public class Portal implements PortalHandler, ConfigurationSerializable { return id; } + PortalHandler getHandler() { + return handler; + } } diff --git a/src/de/steamwar/lobby/portal/PortalType.java b/src/de/steamwar/lobby/portal/PortalType.java index 3522c70..db56dbb 100644 --- a/src/de/steamwar/lobby/portal/PortalType.java +++ b/src/de/steamwar/lobby/portal/PortalType.java @@ -26,7 +26,8 @@ public enum PortalType { TELEPORT(TeleportPortal::new), COMMAND(CommandPortal::new), FIGHTSERVER(FightserverPortal::new), - DUMMY(DummyPortal::new); + DUMMY(DummyPortal::new), + STACK(StackPortal::new); private final BiFunction, Portal, PortalHandler> deserializer; diff --git a/src/de/steamwar/lobby/portal/StackPortal.java b/src/de/steamwar/lobby/portal/StackPortal.java new file mode 100644 index 0000000..8f71e05 --- /dev/null +++ b/src/de/steamwar/lobby/portal/StackPortal.java @@ -0,0 +1,52 @@ +/* + * 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.portal; + +import java.util.Map; + +public class StackPortal extends TeleportPortal { + + private final String text; + + public StackPortal(Map section, Portal portal) { + super(section, portal); + this.text = (String) section.get("text"); + } + + public StackPortal(Portal portal, String target, String text) { + super(portal, target); + this.text = text; + } + + @Override + public void serialize(Map map) { + super.serialize(map); + map.put("text", text); + } + + @Override + public PortalType type() { + return PortalType.STACK; + } + + public String getText() { + return text; + } +}