diff --git a/src/de/steamwar/lobby/portal/DummyPortal.java b/src/de/steamwar/lobby/portal/DummyPortal.java new file mode 100644 index 0000000..291ee8c --- /dev/null +++ b/src/de/steamwar/lobby/portal/DummyPortal.java @@ -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 . + */ + +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 section, Portal portal) { + // Deserializes nothing + } + + @Override + public void handle(Player player, Location from) { + // Does nothing + } + + @Override + public void serialize(Map map) { + // Serializes nothing + } + + @Override + public PortalType type() { + return PortalType.DUMMY; + } + + @Override + public void delete() { + // Delets nothing + } +} diff --git a/src/de/steamwar/lobby/portal/FightserverPortal.java b/src/de/steamwar/lobby/portal/FightserverPortal.java index 56f5515..fba1459 100644 --- a/src/de/steamwar/lobby/portal/FightserverPortal.java +++ b/src/de/steamwar/lobby/portal/FightserverPortal.java @@ -27,19 +27,45 @@ import java.util.Map; public class FightserverPortal implements PortalHandler { private final Portal portal; + private final String group; + private final String target; + + private PortalHandler handler = new DummyPortal(); public FightserverPortal(Map section, 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 public void handle(Player player, Location from) { - + handler.handle(player, from); } @Override public void serialize(Map map) { - + map.put("group", group); + map.put("target", target); } @Override @@ -49,6 +75,6 @@ public class FightserverPortal implements PortalHandler { @Override public void delete() { - + handler.delete(); } } diff --git a/src/de/steamwar/lobby/portal/Portal.java b/src/de/steamwar/lobby/portal/Portal.java index a3c4eb5..91e763c 100644 --- a/src/de/steamwar/lobby/portal/Portal.java +++ b/src/de/steamwar/lobby/portal/Portal.java @@ -19,6 +19,7 @@ package de.steamwar.lobby.portal; +import de.steamwar.lobby.LobbySystem; import org.bukkit.Location; import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.entity.Player; @@ -71,6 +72,7 @@ public class Portal implements PortalHandler, ConfigurationSerializable { this.type = handler.type(); init(); + LobbySystem.config().save(); } private void init() { @@ -107,8 +109,10 @@ public class Portal implements PortalHandler, ConfigurationSerializable { @Override public void delete() { + handler.delete(); portals.remove("id"); posMap.values().removeIf(this::equals); + LobbySystem.config().save(); } @Override diff --git a/src/de/steamwar/lobby/portal/PortalType.java b/src/de/steamwar/lobby/portal/PortalType.java index f27a8f9..3522c70 100644 --- a/src/de/steamwar/lobby/portal/PortalType.java +++ b/src/de/steamwar/lobby/portal/PortalType.java @@ -25,7 +25,8 @@ import java.util.function.BiFunction; public enum PortalType { TELEPORT(TeleportPortal::new), COMMAND(CommandPortal::new), - FIGHTSERVER(FightserverPortal::new); + FIGHTSERVER(FightserverPortal::new), + DUMMY(DummyPortal::new); private final BiFunction, Portal, PortalHandler> deserializer; diff --git a/src/de/steamwar/lobby/portal/TeleportPortal.java b/src/de/steamwar/lobby/portal/TeleportPortal.java index a8018bb..0f2b4af 100644 --- a/src/de/steamwar/lobby/portal/TeleportPortal.java +++ b/src/de/steamwar/lobby/portal/TeleportPortal.java @@ -34,13 +34,13 @@ public class TeleportPortal implements PortalHandler { private final Set sources = new HashSet<>(); - protected TeleportPortal(Map section, Portal portal) { + public TeleportPortal(Map section, Portal portal) { this.portal = portal; this.target = (String) section.get("target"); init(); } - protected TeleportPortal(Portal portal, String target) { + public TeleportPortal(Portal portal, String target) { this.portal = portal; this.target = target; init();