Portal refactoring
Dieser Commit ist enthalten in:
Ursprung
074119c1de
Commit
200e283a50
56
src/de/steamwar/lobby/portal/DummyPortal.java
Normale Datei
56
src/de/steamwar/lobby/portal/DummyPortal.java
Normale Datei
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class DummyPortal implements PortalHandler {
|
||||||
|
|
||||||
|
public DummyPortal() {
|
||||||
|
// Inits nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
public DummyPortal(Map<String, Object> section, Portal portal) {
|
||||||
|
// Deserializes nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(Player player, Location from) {
|
||||||
|
// Does nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialize(Map<String, Object> map) {
|
||||||
|
// Serializes nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PortalType type() {
|
||||||
|
return PortalType.DUMMY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete() {
|
||||||
|
// Delets nothing
|
||||||
|
}
|
||||||
|
}
|
@ -27,19 +27,45 @@ import java.util.Map;
|
|||||||
public class FightserverPortal implements PortalHandler {
|
public class FightserverPortal implements PortalHandler {
|
||||||
|
|
||||||
private final Portal portal;
|
private final Portal portal;
|
||||||
|
private final String group;
|
||||||
|
private final String target;
|
||||||
|
|
||||||
|
private PortalHandler handler = new DummyPortal();
|
||||||
|
|
||||||
public FightserverPortal(Map<String, Object> section, Portal portal) {
|
public FightserverPortal(Map<String, Object> section, Portal portal) {
|
||||||
this.portal = portal;
|
this.portal = portal;
|
||||||
|
this.group = (String) section.get("group");
|
||||||
|
this.target = (String) section.get("target");
|
||||||
|
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public FightserverPortal(Portal portal, String group, String target) {
|
||||||
|
this.portal = portal;
|
||||||
|
this.group = group;
|
||||||
|
this.target = target;
|
||||||
|
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init() {
|
||||||
|
setHandler(new TeleportPortal(portal, target));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setHandler(PortalHandler handler) {
|
||||||
|
handler.delete();
|
||||||
|
this.handler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(Player player, Location from) {
|
public void handle(Player player, Location from) {
|
||||||
|
handler.handle(player, from);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serialize(Map<String, Object> map) {
|
public void serialize(Map<String, Object> map) {
|
||||||
|
map.put("group", group);
|
||||||
|
map.put("target", target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -49,6 +75,6 @@ public class FightserverPortal implements PortalHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delete() {
|
public void delete() {
|
||||||
|
handler.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package de.steamwar.lobby.portal;
|
package de.steamwar.lobby.portal;
|
||||||
|
|
||||||
|
import de.steamwar.lobby.LobbySystem;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -71,6 +72,7 @@ public class Portal implements PortalHandler, ConfigurationSerializable {
|
|||||||
this.type = handler.type();
|
this.type = handler.type();
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
LobbySystem.config().save();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
@ -107,8 +109,10 @@ public class Portal implements PortalHandler, ConfigurationSerializable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delete() {
|
public void delete() {
|
||||||
|
handler.delete();
|
||||||
portals.remove("id");
|
portals.remove("id");
|
||||||
posMap.values().removeIf(this::equals);
|
posMap.values().removeIf(this::equals);
|
||||||
|
LobbySystem.config().save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,7 +25,8 @@ import java.util.function.BiFunction;
|
|||||||
public enum PortalType {
|
public enum PortalType {
|
||||||
TELEPORT(TeleportPortal::new),
|
TELEPORT(TeleportPortal::new),
|
||||||
COMMAND(CommandPortal::new),
|
COMMAND(CommandPortal::new),
|
||||||
FIGHTSERVER(FightserverPortal::new);
|
FIGHTSERVER(FightserverPortal::new),
|
||||||
|
DUMMY(DummyPortal::new);
|
||||||
|
|
||||||
private final BiFunction<Map<String, Object>, Portal, PortalHandler> deserializer;
|
private final BiFunction<Map<String, Object>, Portal, PortalHandler> deserializer;
|
||||||
|
|
||||||
|
@ -34,13 +34,13 @@ public class TeleportPortal implements PortalHandler {
|
|||||||
|
|
||||||
private final Set<TeleportPortal> sources = new HashSet<>();
|
private final Set<TeleportPortal> sources = new HashSet<>();
|
||||||
|
|
||||||
protected TeleportPortal(Map<String, Object> section, Portal portal) {
|
public TeleportPortal(Map<String, Object> section, Portal portal) {
|
||||||
this.portal = portal;
|
this.portal = portal;
|
||||||
this.target = (String) section.get("target");
|
this.target = (String) section.get("target");
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TeleportPortal(Portal portal, String target) {
|
public TeleportPortal(Portal portal, String target) {
|
||||||
this.portal = portal;
|
this.portal = portal;
|
||||||
this.target = target;
|
this.target = target;
|
||||||
init();
|
init();
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren