From 2de4ffd1ea4d1d4943da46ef886bbc23589549b7 Mon Sep 17 00:00:00 2001 From: ProfMobius Date: Fri, 6 Dec 2013 23:48:04 +0100 Subject: [PATCH] Added kill command to kill a given entity by dim/eid. --- mcp/mobius/opis/commands/CommandKill.java | 72 +++++++++++++++++++++++ mcp/mobius/opis/modOpis.java | 4 +- 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 mcp/mobius/opis/commands/CommandKill.java diff --git a/mcp/mobius/opis/commands/CommandKill.java b/mcp/mobius/opis/commands/CommandKill.java new file mode 100644 index 0000000..9ca2894 --- /dev/null +++ b/mcp/mobius/opis/commands/CommandKill.java @@ -0,0 +1,72 @@ +package mcp.mobius.opis.commands; + +import cpw.mods.fml.common.network.PacketDispatcher; +import cpw.mods.fml.common.network.Player; +import net.minecraft.command.CommandBase; +import net.minecraft.command.ICommandSender; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.network.MemoryConnection; +import net.minecraft.network.packet.Packet3Chat; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.dedicated.DedicatedServer; +import net.minecraft.util.ChatMessageComponent; +import net.minecraft.world.World; +import net.minecraftforge.common.DimensionManager; + +public class CommandKill extends CommandBase { + + @Override + public String getCommandName() { + return "opis_kill"; + } + + @Override + public String getCommandUsage(ICommandSender icommandsender) { + return ""; + } + + @Override + public void processCommand(ICommandSender icommandsender, String[] astring) { + if (astring.length != 2) return; + int dim = Integer.valueOf(astring[0]); + int eid = Integer.valueOf(astring[1]); + + World world = DimensionManager.getWorld(dim); + if (world == null){ + PacketDispatcher.sendPacketToPlayer( + new Packet3Chat(ChatMessageComponent.createFromText(String.format("\u00A7oCannot find dim %d in world %d", dim))), + (Player)icommandsender); + return; + } + + Entity entity = world.getEntityByID(eid); + if (entity == null) { + PacketDispatcher.sendPacketToPlayer( + new Packet3Chat(ChatMessageComponent.createFromText(String.format("\u00A7oCannot find entity %d in dim %d", eid, dim))), + (Player)icommandsender); + return; + } + + entity.setDead(); + PacketDispatcher.sendPacketToPlayer( + new Packet3Chat(ChatMessageComponent.createFromText(String.format("\u00A7oKilled entity %d in dim %d", eid, dim))), + (Player)icommandsender); + return; + } + + @Override + public int getRequiredPermissionLevel() + { + return 3; + } + + @Override + public boolean canCommandSenderUseCommand(ICommandSender sender) + { + if (sender instanceof DedicatedServer) return false; + if (((EntityPlayerMP)sender).playerNetServerHandler.netManager instanceof MemoryConnection) return true; + return MinecraftServer.getServer().getConfigurationManager().isPlayerOpped(((EntityPlayerMP)sender).username); + } + +} diff --git a/mcp/mobius/opis/modOpis.java b/mcp/mobius/opis/modOpis.java index 88da3cd..f16d0c5 100644 --- a/mcp/mobius/opis/modOpis.java +++ b/mcp/mobius/opis/modOpis.java @@ -12,6 +12,7 @@ import mcp.mobius.opis.commands.CommandAmountEntities; import mcp.mobius.opis.commands.CommandChunkDump; import mcp.mobius.opis.commands.CommandChunkList; import mcp.mobius.opis.commands.CommandDataDump; +import mcp.mobius.opis.commands.CommandKill; import mcp.mobius.opis.commands.CommandTimingEntities; import mcp.mobius.opis.commands.CommandFrequency; import mcp.mobius.opis.commands.CommandMeanModTime; @@ -103,7 +104,8 @@ public class modOpis { event.registerServerCommand(new CommandDataDump()); event.registerServerCommand(new CommandTicks()); event.registerServerCommand(new CommandTimingEntities()); - event.registerServerCommand(new CommandAmountEntities()); + event.registerServerCommand(new CommandAmountEntities()); + event.registerServerCommand(new CommandKill()); //event.registerServerCommand(new CommandTPS()); GameRegistry.registerPlayerTracker(new OpisPlayerTracker());