13
0
Dieser Commit ist enthalten in:
Lixfel 2021-10-04 14:39:59 +02:00
Ursprung a47bb93d24
Commit 08fecc3333
6 geänderte Dateien mit 95 neuen und 7 gelöschten Zeilen

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.lobby; package de.steamwar.lobby;
import de.steamwar.lobby.listener.BasicListener; import de.steamwar.lobby.listener.BasicListener;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -46,6 +47,8 @@ public class Displayable extends BasicListener {
this.chunkZ = posToChunk(location.getZ()); this.chunkZ = posToChunk(location.getZ());
this.show = show; this.show = show;
this.hide = hide; this.hide = hide;
Bukkit.getOnlinePlayers().forEach(player -> checkLocation(player, player.getLocation()));
} }
@EventHandler @EventHandler

Datei anzeigen

@ -63,7 +63,7 @@ public class PortalCommand extends SWCommand {
LobbySystem.MESSAGE.send("PORTAL_NO_WORLDEDIT_SELECTION", player); LobbySystem.MESSAGE.send("PORTAL_NO_WORLDEDIT_SELECTION", player);
return; 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"}) @Register({"create", "fightserver"})

Datei anzeigen

@ -19,29 +19,58 @@
package de.steamwar.lobby.portal; package de.steamwar.lobby.portal;
import de.steamwar.lobby.listener.Portals;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.Deque;
import java.util.Map; import java.util.Map;
public class CommandPortal implements PortalHandler { public class CommandPortal implements PortalHandler {
private final Portal portal;
private final String command; private final String command;
public CommandPortal(Map<String, Object> section, Portal portal) { public CommandPortal(Map<String, Object> section, Portal portal) {
this.portal = portal;
this.command = (String) section.get("command"); this.command = (String) section.get("command");
} }
public CommandPortal(Portal portal, String command) { public CommandPortal(String command) {
this.portal = portal;
this.command = command; this.command = command;
} }
@Override @Override
public void handle(Player player, Location loc) { 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<Portal> 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 @Override

Datei anzeigen

@ -135,4 +135,7 @@ public class Portal implements PortalHandler, ConfigurationSerializable {
return id; return id;
} }
PortalHandler getHandler() {
return handler;
}
} }

Datei anzeigen

@ -26,7 +26,8 @@ public enum PortalType {
TELEPORT(TeleportPortal::new), TELEPORT(TeleportPortal::new),
COMMAND(CommandPortal::new), COMMAND(CommandPortal::new),
FIGHTSERVER(FightserverPortal::new), FIGHTSERVER(FightserverPortal::new),
DUMMY(DummyPortal::new); DUMMY(DummyPortal::new),
STACK(StackPortal::new);
private final BiFunction<Map<String, Object>, Portal, PortalHandler> deserializer; private final BiFunction<Map<String, Object>, Portal, PortalHandler> deserializer;

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.lobby.portal;
import java.util.Map;
public class StackPortal extends TeleportPortal {
private final String text;
public StackPortal(Map<String, Object> 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<String, Object> map) {
super.serialize(map);
map.put("text", text);
}
@Override
public PortalType type() {
return PortalType.STACK;
}
public String getText() {
return text;
}
}