Add ETP Command
Dieser Commit ist enthalten in:
Ursprung
47036f0ba2
Commit
cc9e1d15a9
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package de.steamwar.spectatesystem;
|
package de.steamwar.spectatesystem;
|
||||||
|
|
||||||
|
import de.steamwar.spectatesystem.commands.ETPCommand;
|
||||||
import de.steamwar.spectatesystem.commands.InspectCommand;
|
import de.steamwar.spectatesystem.commands.InspectCommand;
|
||||||
import de.steamwar.spectatesystem.commands.ReplayCommand;
|
import de.steamwar.spectatesystem.commands.ReplayCommand;
|
||||||
import de.steamwar.spectatesystem.commands.TPSLimitCommand;
|
import de.steamwar.spectatesystem.commands.TPSLimitCommand;
|
||||||
@ -54,6 +55,7 @@ public class SpectateSystem extends JavaPlugin {
|
|||||||
new PlayerListener();
|
new PlayerListener();
|
||||||
new CancelListener();
|
new CancelListener();
|
||||||
new PlayerSeatListener();
|
new PlayerSeatListener();
|
||||||
|
new ETPCommand();
|
||||||
try {
|
try {
|
||||||
acceptor = new ConnectionAcceptor();
|
acceptor = new ConnectionAcceptor();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
47
src/de/steamwar/spectatesystem/commands/ETPCommand.java
Normale Datei
47
src/de/steamwar/spectatesystem/commands/ETPCommand.java
Normale Datei
@ -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());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -26,7 +26,9 @@ import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
|
|||||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public abstract class REntity {
|
public abstract class REntity {
|
||||||
@ -67,6 +69,10 @@ public abstract class REntity {
|
|||||||
return entities.get(internalId);
|
return entities.get(internalId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Collection<REntity> getEntities(){
|
||||||
|
return entities.values();
|
||||||
|
}
|
||||||
|
|
||||||
public static void removeAll(){
|
public static void removeAll(){
|
||||||
int entity_counter = 0;
|
int entity_counter = 0;
|
||||||
synchronized (entities){
|
synchronized (entities){
|
||||||
@ -145,4 +151,8 @@ public abstract class REntity {
|
|||||||
protected void spawnEntity(PlayerConnection connection){
|
protected void spawnEntity(PlayerConnection connection){
|
||||||
connection.sendPacket(new PacketPlayOutSpawnEntity(entity));
|
connection.sendPacket(new PacketPlayOutSpawnEntity(entity));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Entity getEntity() {
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren