StackPortals!
Dieser Commit ist enthalten in:
Ursprung
a47bb93d24
Commit
08fecc3333
@ -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
|
||||
|
@ -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"})
|
||||
|
@ -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<String, Object> 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<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
|
||||
|
@ -135,4 +135,7 @@ public class Portal implements PortalHandler, ConfigurationSerializable {
|
||||
return id;
|
||||
}
|
||||
|
||||
PortalHandler getHandler() {
|
||||
return handler;
|
||||
}
|
||||
}
|
||||
|
@ -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<Map<String, Object>, Portal, PortalHandler> deserializer;
|
||||
|
||||
|
52
src/de/steamwar/lobby/portal/StackPortal.java
Normale Datei
52
src/de/steamwar/lobby/portal/StackPortal.java
Normale Datei
@ -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;
|
||||
}
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren