13
0

Add ETP Command

Dieser Commit ist enthalten in:
Chaoscaot 2021-04-13 11:46:08 +02:00
Ursprung 47036f0ba2
Commit cc9e1d15a9
3 geänderte Dateien mit 59 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -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) {

Datei anzeigen

@ -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<REntity> entityTypeMapper() {
return SWCommandUtils.createMapper(s -> {
Collection<REntity> 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<REntity> 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());
});
}
}

Datei anzeigen

@ -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<REntity> 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;
}
}