diff --git a/pom.xml b/pom.xml
index 7decdca..1b9e391 100644
--- a/pom.xml
+++ b/pom.xml
@@ -61,5 +61,11 @@
system
${main.basedir}/lib/SpigotCore.jar
+
+ org.projectlombok
+ lombok
+ 1.18.20
+ provided
+
diff --git a/src/de/steamwar/lobby/LobbySystem.java b/src/de/steamwar/lobby/LobbySystem.java
index 680b9ec..06e7149 100644
--- a/src/de/steamwar/lobby/LobbySystem.java
+++ b/src/de/steamwar/lobby/LobbySystem.java
@@ -19,6 +19,7 @@
package de.steamwar.lobby;
+import de.steamwar.lobby.command.PortalCommand;
import de.steamwar.lobby.listener.Fightservers;
import de.steamwar.lobby.listener.Join;
import de.steamwar.lobby.listener.Portals;
@@ -45,6 +46,8 @@ public class LobbySystem extends JavaPlugin {
new Fightservers();
new Portals();
config = new Config(getConfig());
+
+ new PortalCommand();
}
public static LobbySystem getPlugin() {
diff --git a/src/de/steamwar/lobby/LobbySystem.properties b/src/de/steamwar/lobby/LobbySystem.properties
index b6d346e..9300f86 100644
--- a/src/de/steamwar/lobby/LobbySystem.properties
+++ b/src/de/steamwar/lobby/LobbySystem.properties
@@ -6,4 +6,7 @@ COMMAND_HELP_HEAD=§7---=== (§e{0}§7) ===---
# Portal Command
PORTAL_COMMAND_LIST_HELP = §8/§7portal §elist §8- §7Listet alle Portale auf
PORTAL_COMMAND_ADD_HELP = §8/§7portal §ecreate §8[§7PortalType§8] §8[§7PortalName§8] §8- §7Fügt ein Portal hinzu
-PORTAL_COMMAND_REMOVE_HELP = §8/§7portal §eremove §8[§7PortalName§8] §8- §7Entfernt ein Portal
\ No newline at end of file
+PORTAL_COMMAND_REMOVE_HELP = §8/§7portal §eremove §8[§7PortalName§8] §8- §7Entfernt ein Portal
+
+PORTAL_COMMAND_LIST_SHORT_INFO = §e{0} §8- §7{1} §7Pos1§8(§7{2}§8) §7Pos2§8(§7{2}§8)
+PORTAL_NO_WORLDEDIT_SELECTION = §cKeine WorldEdit Selection
\ No newline at end of file
diff --git a/src/de/steamwar/lobby/command/PortalCommand.java b/src/de/steamwar/lobby/command/PortalCommand.java
index e678aea..b9e06dc 100644
--- a/src/de/steamwar/lobby/command/PortalCommand.java
+++ b/src/de/steamwar/lobby/command/PortalCommand.java
@@ -1,14 +1,33 @@
package de.steamwar.lobby.command;
+import com.sk89q.worldedit.IncompleteRegionException;
+import com.sk89q.worldedit.WorldEdit;
+import com.sk89q.worldedit.bukkit.BukkitAdapter;
+import com.sk89q.worldedit.bukkit.WorldEditPlugin;
+import com.sk89q.worldedit.math.BlockVector3;
+import com.sk89q.worldedit.regions.RegionSelector;
import de.steamwar.command.SWCommand;
+import de.steamwar.command.TypeMapper;
import de.steamwar.lobby.LobbySystem;
-import de.steamwar.lobby.listener.Portals;
+import de.steamwar.lobby.portal.CommandPortal;
+import de.steamwar.lobby.portal.Portal;
+import de.steamwar.lobby.portal.TeleportPortal;
import de.steamwar.sql.SteamwarUser;
+import lombok.Data;
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.World;
+import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
+import java.util.ArrayList;
+import java.util.List;
+
public class PortalCommand extends SWCommand {
- protected PortalCommand(String command) {
+ private static final WorldEditPlugin worldEditPlugin = (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit");
+
+ public PortalCommand() {
super("portal");
}
@@ -28,26 +47,90 @@ public class PortalCommand extends SWCommand {
@Register("list")
public void portalList(Player player) {
- // TODO: implement
+ if (noPermissions(player)) return;
+ LobbySystem.MESSAGE.sendPrefixless("COMMAND_HELP_HEAD", player, "portal list");
+ Portal.getPortals().forEach(portal -> {
+ LobbySystem.MESSAGE.sendPrefixless("PORTAL_COMMAND_LIST_SHORT_INFO", player, portal.type().name(), portal.getId(), portal.getPos1().toVector().toString(), portal.getPos1().toVector().toString());
+ });
}
@Register({"create", "command"})
- public void portalAddCommand(Player player, String... command) {
-
+ public void portalAddCommand(Player player, String portalName, String... command) {
+ if (noPermissions(player)) return;
+ Tuple tuple = getSelection(player);
+ if (tuple == null) {
+ LobbySystem.MESSAGE.send("PORTAL_NO_WORLDEDIT_SELECTION", player);
+ return;
+ }
+ new Portal(portalName, tuple.k, tuple.v, portal -> new CommandPortal(portal, String.join(" ", command)));
}
@Register({"create", "fightserver"})
- public void portalAddFightserver(Player player) {
-
+ public void portalAddFightserver(Player player, String portalName) {
+ if (noPermissions(player)) return;
+ Tuple tuple = getSelection(player);
+ if (tuple == null) {
+ LobbySystem.MESSAGE.send("PORTAL_NO_WORLDEDIT_SELECTION", player);
+ return;
+ }
+ // TODO: implement FightserverPortal
+ // new Portal(portalName, tuple.k, tuple.v, portal -> new CommandPortal(portal, String.join(" ", command)));
}
@Register({"create", "teleport"})
- public void portalAddTeleport(Player player, String portalName) {
-
+ public void portalAddTeleport(Player player, String portalName, String portalDestination) {
+ if (noPermissions(player)) return;
+ Tuple tuple = getSelection(player);
+ if (tuple == null) {
+ LobbySystem.MESSAGE.send("PORTAL_NO_WORLDEDIT_SELECTION", player);
+ return;
+ }
+ new Portal(portalName, tuple.k, tuple.v, portal -> new TeleportPortal(portal, portalDestination));
}
@Register("remove")
- public void portalRemove(Player player, String portalName) {
+ public void portalRemove(Player player, Portal portal) {
+ if (noPermissions(player)) return;
+ portal.delete();
+ }
+ @ClassMapper(value = Portal.class, local = true)
+ public TypeMapper portalTypeMapper() {
+ return new TypeMapper() {
+ @Override
+ public List tabCompletes(CommandSender commandSender, String[] strings, String s) {
+ return new ArrayList<>(Portal.getPortalNames());
+ }
+
+ @Override
+ public Portal map(CommandSender commandSender, String[] previousArguments, String s) {
+ return Portal.getPortal(s);
+ }
+ };
+ }
+
+ @Data
+ private static class Tuple {
+ private final K k;
+ private final V v;
+ }
+
+ private Tuple getSelection(Player player) {
+ RegionSelector regionSelector = WorldEdit.getInstance()
+ .getSessionManager()
+ .get(BukkitAdapter.adapt(player))
+ .getRegionSelector(BukkitAdapter.adapt(player.getWorld()));
+
+ try {
+ BlockVector3 min = regionSelector.getRegion().getMinimumPoint();
+ BlockVector3 max = regionSelector.getRegion().getMaximumPoint();
+ return new Tuple<>(adapt(player.getWorld(), min), adapt(player.getWorld(), max));
+ } catch (IncompleteRegionException e) {
+ return null;
+ }
+ }
+
+ private Location adapt(World world, BlockVector3 blockVector3) {
+ return new Location(world, blockVector3.getBlockX(), blockVector3.getBlockY(), blockVector3.getBlockZ());
}
}
diff --git a/src/de/steamwar/lobby/portal/Portal.java b/src/de/steamwar/lobby/portal/Portal.java
index 91e763c..be7482c 100644
--- a/src/de/steamwar/lobby/portal/Portal.java
+++ b/src/de/steamwar/lobby/portal/Portal.java
@@ -25,10 +25,7 @@ import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import java.util.function.Function;
public class Portal implements PortalHandler, ConfigurationSerializable {
@@ -40,6 +37,10 @@ public class Portal implements PortalHandler, ConfigurationSerializable {
return new ArrayList<>(portals.values());
}
+ public static Set getPortalNames() {
+ return portals.keySet();
+ }
+
public static Portal getPortal(Location loc) {
return posMap.get(new Vector(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
}