From d3b9852d94d57c21231dd34204e2c4a4fcdc809b Mon Sep 17 00:00:00 2001 From: ProfMobius Date: Tue, 4 Feb 2014 17:45:59 +0100 Subject: [PATCH] All commands are now console compatible. --- .../commands/server/CommandAmountEntities.java | 13 +++++++++++-- .../opis/commands/server/CommandChunkList.java | 14 +++++++++++--- .../opis/commands/server/CommandFrequency.java | 3 +-- mcp/mobius/opis/commands/server/CommandHelp.java | 10 +++------- mcp/mobius/opis/commands/server/CommandKill.java | 14 ++++---------- .../opis/commands/server/CommandKillAll.java | 7 +++---- .../opis/commands/server/CommandMeanModTime.java | 14 +++++++++++++- mcp/mobius/opis/commands/server/CommandReset.java | 3 +-- mcp/mobius/opis/commands/server/CommandStart.java | 5 ++--- mcp/mobius/opis/commands/server/CommandStop.java | 5 ++++- mcp/mobius/opis/commands/server/CommandTicks.java | 5 ++--- .../commands/server/CommandTimingEntities.java | 13 +++++++++++-- .../commands/server/CommandTimingTileEntities.java | 12 ++++++++++-- mcp/mobius/opis/modOpis.java | 8 ++++---- 14 files changed, 80 insertions(+), 46 deletions(-) diff --git a/mcp/mobius/opis/commands/server/CommandAmountEntities.java b/mcp/mobius/opis/commands/server/CommandAmountEntities.java index cdccc65..ff9517a 100644 --- a/mcp/mobius/opis/commands/server/CommandAmountEntities.java +++ b/mcp/mobius/opis/commands/server/CommandAmountEntities.java @@ -7,10 +7,13 @@ import mcp.mobius.opis.data.managers.EntityManager; import mcp.mobius.opis.network.server.Packet_DataScreenAmountEntities; import net.minecraft.command.CommandBase; import net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.network.MemoryConnection; +import net.minecraft.network.rcon.RConConsoleSource; import net.minecraft.server.MinecraftServer; import net.minecraft.server.dedicated.DedicatedServer; +import net.minecraft.util.ChatMessageComponent; public class CommandAmountEntities extends CommandBase implements IOpisCommand{ @@ -27,7 +30,13 @@ public class CommandAmountEntities extends CommandBase implements IOpisCommand{ @Override public void processCommand(ICommandSender icommandsender, String[] astring) { HashMap ents = EntityManager.getCumulativeEntities(); - ((EntityPlayerMP)icommandsender).playerNetServerHandler.sendPacketToPlayer(Packet_DataScreenAmountEntities.create(ents)); + + if (icommandsender instanceof EntityPlayer) + ((EntityPlayerMP)icommandsender).playerNetServerHandler.sendPacketToPlayer(Packet_DataScreenAmountEntities.create(ents)); + else if (icommandsender instanceof DedicatedServer){ + for (String s : ents.keySet()) + icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(String.format("%s : %s", s, ents.get(s)))); + } } @@ -40,7 +49,7 @@ public class CommandAmountEntities extends CommandBase implements IOpisCommand{ @Override public boolean canCommandSenderUseCommand(ICommandSender sender) { - if (sender instanceof DedicatedServer) return false; + if (sender instanceof DedicatedServer) return true; if (((EntityPlayerMP)sender).playerNetServerHandler.netManager instanceof MemoryConnection) return true; return MinecraftServer.getServer().getConfigurationManager().isPlayerOpped(((EntityPlayerMP)sender).username); } diff --git a/mcp/mobius/opis/commands/server/CommandChunkList.java b/mcp/mobius/opis/commands/server/CommandChunkList.java index e243cea..df5ddc1 100644 --- a/mcp/mobius/opis/commands/server/CommandChunkList.java +++ b/mcp/mobius/opis/commands/server/CommandChunkList.java @@ -8,10 +8,12 @@ import mcp.mobius.opis.data.managers.ChunkManager; import mcp.mobius.opis.network.server.Packet_ChunkTopList; import net.minecraft.command.CommandBase; import net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.network.MemoryConnection; import net.minecraft.server.MinecraftServer; import net.minecraft.server.dedicated.DedicatedServer; +import net.minecraft.util.ChatMessageComponent; public class CommandChunkList extends CommandBase implements IOpisCommand { @@ -42,8 +44,14 @@ public class CommandChunkList extends CommandBase implements IOpisCommand { System.out.printf("%s\n", stat); } */ - - ((EntityPlayerMP)icommandsender).playerNetServerHandler.sendPacketToPlayer(Packet_ChunkTopList.create(chunks)); + if (icommandsender instanceof EntityPlayer) + ((EntityPlayerMP)icommandsender).playerNetServerHandler.sendPacketToPlayer(Packet_ChunkTopList.create(chunks)); + else if (icommandsender instanceof DedicatedServer){ + icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText("[DIM X Z] Time NTEs")); + for (ChunkStats stat : chunks){ + icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(stat.toString())); + } + } } @@ -56,7 +64,7 @@ public class CommandChunkList extends CommandBase implements IOpisCommand { @Override public boolean canCommandSenderUseCommand(ICommandSender sender) { - if (sender instanceof DedicatedServer) return false; + if (sender instanceof DedicatedServer) return true; if (((EntityPlayerMP)sender).playerNetServerHandler.netManager instanceof MemoryConnection) return true; return MinecraftServer.getServer().getConfigurationManager().isPlayerOpped(((EntityPlayerMP)sender).username); } diff --git a/mcp/mobius/opis/commands/server/CommandFrequency.java b/mcp/mobius/opis/commands/server/CommandFrequency.java index df3a1af..370af16 100644 --- a/mcp/mobius/opis/commands/server/CommandFrequency.java +++ b/mcp/mobius/opis/commands/server/CommandFrequency.java @@ -31,8 +31,7 @@ public class CommandFrequency extends CommandBase implements IOpisCommand { if (astring.length < 1) return; try{ modOpis.profilerDelay = Integer.valueOf(astring[0]); - if (icommandsender instanceof EntityPlayer) - PacketDispatcher.sendPacketToPlayer(new Packet3Chat(ChatMessageComponent.createFromText(String.format("\u00A7oOpis delay set to %s ticks.", astring[0]))), (Player)icommandsender); + icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(String.format("\u00A7oOpis delay set to %s ticks.", astring[0]))); } catch (Exception e){} } diff --git a/mcp/mobius/opis/commands/server/CommandHelp.java b/mcp/mobius/opis/commands/server/CommandHelp.java index 57d8906..45c671a 100644 --- a/mcp/mobius/opis/commands/server/CommandHelp.java +++ b/mcp/mobius/opis/commands/server/CommandHelp.java @@ -46,14 +46,11 @@ public class CommandHelp extends CommandBase implements IOpisCommand { new CommandKill(), new CommandKillAll(), - new CommandHandler() + //new CommandHandler() }; - - if (icommandsender instanceof EntityPlayer) - for (IOpisCommand cmd : commands) - PacketDispatcher.sendPacketToPlayer(new Packet3Chat(ChatMessageComponent.createFromText(String.format("/%s : %s", cmd.getCommandName(), cmd.getDescription()))), (Player)icommandsender); - + for (IOpisCommand cmd : commands) + icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(String.format("/%s : %s", cmd.getCommandName(), cmd.getDescription()))); } @Override @@ -65,7 +62,6 @@ public class CommandHelp extends CommandBase implements IOpisCommand { @Override public boolean canCommandSenderUseCommand(ICommandSender sender) { - if (sender instanceof DedicatedServer) return false; return true; } diff --git a/mcp/mobius/opis/commands/server/CommandKill.java b/mcp/mobius/opis/commands/server/CommandKill.java index 4814dd8..13d89da 100644 --- a/mcp/mobius/opis/commands/server/CommandKill.java +++ b/mcp/mobius/opis/commands/server/CommandKill.java @@ -35,24 +35,18 @@ public class CommandKill extends CommandBase implements IOpisCommand { 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); + icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(String.format("\u00A7oCannot find dim %d in world %d", dim))); 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); + icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(String.format("\u00A7oCannot find entity %d in dim %d", eid, dim))); return; } entity.setDead(); - PacketDispatcher.sendPacketToPlayer( - new Packet3Chat(ChatMessageComponent.createFromText(String.format("\u00A7oKilled entity %d in dim %d", eid, dim))), - (Player)icommandsender); + icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(String.format("\u00A7oKilled entity %d in dim %d", eid, dim))); return; } @@ -65,7 +59,7 @@ public class CommandKill extends CommandBase implements IOpisCommand { @Override public boolean canCommandSenderUseCommand(ICommandSender sender) { - if (sender instanceof DedicatedServer) return false; + if (sender instanceof DedicatedServer) return true; if (((EntityPlayerMP)sender).playerNetServerHandler.netManager instanceof MemoryConnection) return true; return MinecraftServer.getServer().getConfigurationManager().isPlayerOpped(((EntityPlayerMP)sender).username); } diff --git a/mcp/mobius/opis/commands/server/CommandKillAll.java b/mcp/mobius/opis/commands/server/CommandKillAll.java index 5102b8c..83dcda4 100644 --- a/mcp/mobius/opis/commands/server/CommandKillAll.java +++ b/mcp/mobius/opis/commands/server/CommandKillAll.java @@ -39,8 +39,7 @@ public class CommandKillAll extends CommandBase implements IOpisCommand { int nkilled = 0; if (searchname.equals("Player")){ - if (icommandsender instanceof EntityPlayer) - PacketDispatcher.sendPacketToPlayer(new Packet3Chat(ChatMessageComponent.createFromText(String.format("\u00A7oSeriously ? I can't, seriously, I can't. I should remove you from the OP list !"))), (Player)icommandsender); + icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(String.format("\u00A7oSeriously ? I can't, seriously, I can't. I should remove you from the OP list !"))); return; } @@ -61,7 +60,7 @@ public class CommandKillAll extends CommandBase implements IOpisCommand { } if (icommandsender instanceof EntityPlayer) - PacketDispatcher.sendPacketToPlayer(new Packet3Chat(ChatMessageComponent.createFromText(String.format("\u00A7oKilled %d entities of type %s", nkilled, searchname))), (Player)icommandsender); + icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(String.format("\u00A7oKilled %d entities of type %s", nkilled, searchname))); /* World world = DimensionManager.getWorld(dim); @@ -97,7 +96,7 @@ public class CommandKillAll extends CommandBase implements IOpisCommand { @Override public boolean canCommandSenderUseCommand(ICommandSender sender) { - if (sender instanceof DedicatedServer) return false; + if (sender instanceof DedicatedServer) return true; if (((EntityPlayerMP)sender).playerNetServerHandler.netManager instanceof MemoryConnection) return true; return MinecraftServer.getServer().getConfigurationManager().isPlayerOpped(((EntityPlayerMP)sender).username); } diff --git a/mcp/mobius/opis/commands/server/CommandMeanModTime.java b/mcp/mobius/opis/commands/server/CommandMeanModTime.java index 98d5999..ad67964 100644 --- a/mcp/mobius/opis/commands/server/CommandMeanModTime.java +++ b/mcp/mobius/opis/commands/server/CommandMeanModTime.java @@ -8,10 +8,12 @@ import mcp.mobius.opis.data.managers.TileEntityManager; import mcp.mobius.opis.network.server.Packet_ModMeanTime; import net.minecraft.command.CommandBase; import net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.network.MemoryConnection; import net.minecraft.server.MinecraftServer; import net.minecraft.server.dedicated.DedicatedServer; +import net.minecraft.util.ChatMessageComponent; public class CommandMeanModTime extends CommandBase implements IOpisCommand { @@ -28,7 +30,17 @@ public class CommandMeanModTime extends CommandBase implements IOpisCommand { @Override public void processCommand(ICommandSender icommandsender, String[] astring) { ArrayList modStats = TileEntityManager.getModStats(); - ((EntityPlayerMP)icommandsender).playerNetServerHandler.sendPacketToPlayer(Packet_ModMeanTime.create(modStats)); + + if (icommandsender instanceof EntityPlayer) + ((EntityPlayerMP)icommandsender).playerNetServerHandler.sendPacketToPlayer(Packet_ModMeanTime.create(modStats)); + else if (icommandsender instanceof DedicatedServer){ + icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText("[Name] NTEs MeanTime")); + for (ModStats stat : modStats){ + icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText( + String.format("[ %s ] %3d %.2f", stat.getModID(), stat.ntes, stat.dstat.getMean()))); + } + } + } @Override diff --git a/mcp/mobius/opis/commands/server/CommandReset.java b/mcp/mobius/opis/commands/server/CommandReset.java index 654ad0d..ecda06b 100644 --- a/mcp/mobius/opis/commands/server/CommandReset.java +++ b/mcp/mobius/opis/commands/server/CommandReset.java @@ -38,8 +38,7 @@ public class CommandReset extends CommandBase implements IOpisCommand { public void processCommand(ICommandSender icommandsender, String[] astring) { MetaManager.reset(); - if (icommandsender instanceof EntityPlayer) - PacketDispatcher.sendPacketToPlayer(new Packet3Chat(ChatMessageComponent.createFromText(String.format("\u00A7oInternal data reseted."))), (Player)icommandsender); + icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(String.format("\u00A7oInternal data reseted."))); PacketDispatcher.sendPacketToAllPlayers(Packet_ClearSelection.create()); //notifyAdmins(icommandsender, "Opis started with a tick delay %s.", new Object[] {modOpis.profilerDelay}); diff --git a/mcp/mobius/opis/commands/server/CommandStart.java b/mcp/mobius/opis/commands/server/CommandStart.java index 4e41521..42ee359 100644 --- a/mcp/mobius/opis/commands/server/CommandStart.java +++ b/mcp/mobius/opis/commands/server/CommandStart.java @@ -41,10 +41,9 @@ public class CommandStart extends CommandBase implements IOpisCommand { modOpis.profilerRun = true; ProfilerRegistrar.turnOn(); - if (icommandsender instanceof EntityPlayer){ + if (icommandsender instanceof EntityPlayer) OpisServerTickHandler.instance.players.add((EntityPlayer)icommandsender); - PacketDispatcher.sendPacketToPlayer(new Packet3Chat(ChatMessageComponent.createFromText(String.format("\u00A7oOpis started with a tick delay %s.", modOpis.profilerDelay))), (Player)icommandsender); - } + icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(String.format("\u00A7oOpis started with a tick delay %s.", modOpis.profilerDelay))); } diff --git a/mcp/mobius/opis/commands/server/CommandStop.java b/mcp/mobius/opis/commands/server/CommandStop.java index 543cedc..bea8214 100644 --- a/mcp/mobius/opis/commands/server/CommandStop.java +++ b/mcp/mobius/opis/commands/server/CommandStop.java @@ -38,7 +38,10 @@ public class CommandStop extends CommandBase implements IOpisCommand { OpisServerTickHandler.instance.players.add((EntityPlayer)icommandsender); for (EntityPlayer player : OpisServerTickHandler.instance.players) - PacketDispatcher.sendPacketToPlayer(new Packet3Chat(ChatMessageComponent.createFromText(String.format("\u00A7oOpis stopped."))), (Player)player); + PacketDispatcher.sendPacketToPlayer(new Packet3Chat(ChatMessageComponent.createFromText(String.format("\u00A7oOpis stopped."))), (Player)player); + + if (icommandsender instanceof DedicatedServer) + icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(String.format("\u00A7oOpis stopped."))); } @Override diff --git a/mcp/mobius/opis/commands/server/CommandTicks.java b/mcp/mobius/opis/commands/server/CommandTicks.java index 8d15d1d..8076647 100644 --- a/mcp/mobius/opis/commands/server/CommandTicks.java +++ b/mcp/mobius/opis/commands/server/CommandTicks.java @@ -31,9 +31,8 @@ public class CommandTicks extends CommandBase implements IOpisCommand { if (astring.length < 1) return; try{ modOpis.profilerMaxTicks = Integer.valueOf(astring[0]); - - if (icommandsender instanceof EntityPlayer) - PacketDispatcher.sendPacketToPlayer(new Packet3Chat(ChatMessageComponent.createFromText(String.format("\u00A7oOpis ticks set to %s ticks.", astring[0]))), (Player)icommandsender); + icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(String.format("\u00A7oOpis ticks set to %s ticks.", astring[0]))); + } catch (Exception e){} } diff --git a/mcp/mobius/opis/commands/server/CommandTimingEntities.java b/mcp/mobius/opis/commands/server/CommandTimingEntities.java index ebf530d..b723a90 100644 --- a/mcp/mobius/opis/commands/server/CommandTimingEntities.java +++ b/mcp/mobius/opis/commands/server/CommandTimingEntities.java @@ -10,10 +10,12 @@ import mcp.mobius.opis.data.managers.EntityManager; import mcp.mobius.opis.network.server.Packet_DataScreenTimingEntities; import net.minecraft.command.CommandBase; import net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.network.MemoryConnection; import net.minecraft.server.MinecraftServer; import net.minecraft.server.dedicated.DedicatedServer; +import net.minecraft.util.ChatMessageComponent; public class CommandTimingEntities extends CommandBase implements IOpisCommand { @@ -39,7 +41,14 @@ public class CommandTimingEntities extends CommandBase implements IOpisCommand { } catch (Exception e) {return;} } - ((EntityPlayerMP)icommandsender).playerNetServerHandler.sendPacketToPlayer(Packet_DataScreenTimingEntities.create(ents)); + if (icommandsender instanceof EntityPlayer) + ((EntityPlayerMP)icommandsender).playerNetServerHandler.sendPacketToPlayer(Packet_DataScreenTimingEntities.create(ents)); + else if (icommandsender instanceof DedicatedServer){ + icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText("[DIM X Z] Time NTEs")); + for (EntityStats stat : ents){ + icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(stat.toString())); + } + } } @@ -52,7 +61,7 @@ public class CommandTimingEntities extends CommandBase implements IOpisCommand { @Override public boolean canCommandSenderUseCommand(ICommandSender sender) { - if (sender instanceof DedicatedServer) return false; + if (sender instanceof DedicatedServer) return true; if (((EntityPlayerMP)sender).playerNetServerHandler.netManager instanceof MemoryConnection) return true; return MinecraftServer.getServer().getConfigurationManager().isPlayerOpped(((EntityPlayerMP)sender).username); } diff --git a/mcp/mobius/opis/commands/server/CommandTimingTileEntities.java b/mcp/mobius/opis/commands/server/CommandTimingTileEntities.java index 7a26315..62150df 100644 --- a/mcp/mobius/opis/commands/server/CommandTimingTileEntities.java +++ b/mcp/mobius/opis/commands/server/CommandTimingTileEntities.java @@ -8,10 +8,12 @@ import mcp.mobius.opis.data.managers.TileEntityManager; import mcp.mobius.opis.network.server.Packet_TileEntitiesTopList; import net.minecraft.command.CommandBase; import net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.network.MemoryConnection; import net.minecraft.server.MinecraftServer; import net.minecraft.server.dedicated.DedicatedServer; +import net.minecraft.util.ChatMessageComponent; public class CommandTimingTileEntities extends CommandBase implements IOpisCommand { @@ -37,7 +39,13 @@ public class CommandTimingTileEntities extends CommandBase implements IOpisComma } catch (Exception e) {return;} } - ((EntityPlayerMP)icommandsender).playerNetServerHandler.sendPacketToPlayer(Packet_TileEntitiesTopList.create(tes)); + if (icommandsender instanceof EntityPlayer) + ((EntityPlayerMP)icommandsender).playerNetServerHandler.sendPacketToPlayer(Packet_TileEntitiesTopList.create(tes)); + else if (icommandsender instanceof DedicatedServer){ + for (TileEntityStats stat : tes){ + icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(stat.toString())); + } + } } @@ -50,7 +58,7 @@ public class CommandTimingTileEntities extends CommandBase implements IOpisComma @Override public boolean canCommandSenderUseCommand(ICommandSender sender) { - if (sender instanceof DedicatedServer) return false; + if (sender instanceof DedicatedServer) return true; 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 8c59c8b..47d7fd5 100644 --- a/mcp/mobius/opis/modOpis.java +++ b/mcp/mobius/opis/modOpis.java @@ -127,11 +127,11 @@ public class modOpis { event.registerServerCommand(new CommandKill()); event.registerServerCommand(new CommandKillAll()); event.registerServerCommand(new CommandReset()); - event.registerServerCommand(new CommandHandler()); + //event.registerServerCommand(new CommandHandler()); - event.registerServerCommand(new CommandClientTest()); - event.registerServerCommand(new CommandClientStart()); - event.registerServerCommand(new CommandClientShowRenderTick()); + //event.registerServerCommand(new CommandClientTest()); + //event.registerServerCommand(new CommandClientStart()); + //event.registerServerCommand(new CommandClientShowRenderTick()); event.registerServerCommand(new CommandHelp());