diff --git a/src/de/steamwar/spectatesystem/SpectateSystem.java b/src/de/steamwar/spectatesystem/SpectateSystem.java index 354800f..237e779 100644 --- a/src/de/steamwar/spectatesystem/SpectateSystem.java +++ b/src/de/steamwar/spectatesystem/SpectateSystem.java @@ -19,6 +19,7 @@ package de.steamwar.spectatesystem; +import de.steamwar.spectatesystem.commands.ETPCommand; import de.steamwar.spectatesystem.commands.InspectCommand; import de.steamwar.spectatesystem.commands.ReplayCommand; import de.steamwar.spectatesystem.commands.TPSLimitCommand; @@ -54,6 +55,7 @@ public class SpectateSystem extends JavaPlugin { new PlayerListener(); new CancelListener(); new PlayerSeatListener(); + new ETPCommand(); try { acceptor = new ConnectionAcceptor(); } catch (IOException e) { diff --git a/src/de/steamwar/spectatesystem/commands/ETPCommand.java b/src/de/steamwar/spectatesystem/commands/ETPCommand.java new file mode 100644 index 0000000..6114660 --- /dev/null +++ b/src/de/steamwar/spectatesystem/commands/ETPCommand.java @@ -0,0 +1,47 @@ +package de.steamwar.spectatesystem.commands; + +import de.steamwar.command.SWCommand; +import de.steamwar.command.SWCommandUtils; +import de.steamwar.command.TypeMapper; +import de.steamwar.spectatesystem.elements.REntity; +import org.bukkit.entity.Player; + +import java.util.*; +import java.util.stream.Collectors; + +public class ETPCommand extends SWCommand { + + public ETPCommand() { + super("etp"); + } + + @Register + public void genericCommand(Player p, REntity entity) { + if(entity == null) { + p.sendMessage("Mehr als Zwei oder keine Entity gefunden!"); + return; + } + if(!InspectCommand.inspecting) { + p.sendMessage("Der Inspect Mode ist nicht an!"); + return; + } + p.teleport(entity.getEntity().getBukkitEntity()); + } + + @ClassMapper(local = true, value = REntity.class) + public TypeMapper entityTypeMapper() { + return SWCommandUtils.createMapper(s -> { + Collection entities = REntity.getEntities(); + entities.removeIf(entity -> !entity.getEntity().getName().equalsIgnoreCase(s)); + if(entities.size() != 1) + return null; + return new ArrayList<>(entities).get(0); + }, (commandSender, s) -> { + if(!InspectCommand.inspecting) + return Collections.emptyList(); + Collection entities = REntity.getEntities(); + entities.removeIf(entity -> !entity.getEntity().getName().toLowerCase().startsWith(s.toLowerCase())); + return new LinkedList<>(entities).stream().map(entity -> entity.getEntity().getName()).collect(Collectors.toList()); + }); + } +} diff --git a/src/de/steamwar/spectatesystem/elements/REntity.java b/src/de/steamwar/spectatesystem/elements/REntity.java index fc11e99..5286d4d 100644 --- a/src/de/steamwar/spectatesystem/elements/REntity.java +++ b/src/de/steamwar/spectatesystem/elements/REntity.java @@ -26,7 +26,9 @@ import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; public abstract class REntity { @@ -67,6 +69,10 @@ public abstract class REntity { return entities.get(internalId); } + public static Collection getEntities(){ + return entities.values(); + } + public static void removeAll(){ int entity_counter = 0; synchronized (entities){ @@ -145,4 +151,8 @@ public abstract class REntity { protected void spawnEntity(PlayerConnection connection){ connection.sendPacket(new PacketPlayOutSpawnEntity(entity)); } + + public Entity getEntity() { + return entity; + } }