mirror of
				https://github.com/SquidDev-CC/CC-Tweaked
				synced 2025-10-26 19:37:39 +00:00 
			
		
		
		
	Merge pull request #362 from KingofGamesYami/ComputerCraft/featurecommand-event
Command Event
This commit is contained in:
		
							
								
								
									
										44
									
								
								src/main/java/dan200/computercraft/ComputerCommand.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								src/main/java/dan200/computercraft/ComputerCommand.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,44 @@ | ||||
| package dan200.computercraft; | ||||
|  | ||||
| import dan200.computercraft.shared.computer.core.ComputerFamily; | ||||
| import dan200.computercraft.shared.computer.core.ServerComputer; | ||||
| import net.minecraft.command.CommandBase; | ||||
| import net.minecraft.command.CommandException; | ||||
| import net.minecraft.command.ICommandSender; | ||||
| import net.minecraft.server.MinecraftServer; | ||||
| import org.apache.commons.lang3.ArrayUtils; | ||||
|  | ||||
| public class ComputerCommand extends CommandBase { | ||||
|  | ||||
|     @Override | ||||
|     public String getName() { | ||||
|         return "computer"; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public String getUsage(ICommandSender iCommandSender) { | ||||
|         return "computer <id> <value1> [value2]..."; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { | ||||
|         if( args.length < 2 ){ | ||||
|             throw new CommandException( "Usage: /computer <id> <value1> [value2]..." ); | ||||
|         } | ||||
|         try { | ||||
|             ServerComputer computer = ComputerCraft.serverComputerRegistry.lookup(Integer.valueOf(args[0])); | ||||
|             if( computer != null && computer.getFamily() == ComputerFamily.Command ){ | ||||
|                 computer.queueEvent( "computer_command", ArrayUtils.remove( args, 0 ) ); | ||||
|             }else{ | ||||
|                 throw new CommandException( "Computer #" + args[0] + " is not a Command Computer" ); | ||||
|             } | ||||
|         }catch( NumberFormatException e ){ | ||||
|             throw new CommandException( "Invalid ID" ); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public int getRequiredPermissionLevel(){ | ||||
|         return 0; | ||||
|     } | ||||
| } | ||||
| @@ -400,6 +400,7 @@ public class ComputerCraft | ||||
|     @Mod.EventHandler | ||||
|     public void onServerStarting( FMLServerStartingEvent event ) | ||||
|     { | ||||
|         event.registerServerCommand( new ComputerCommand() ); | ||||
|     } | ||||
|  | ||||
|     @Mod.EventHandler | ||||
|   | ||||
| @@ -39,6 +39,7 @@ public class ServerComputer extends ServerTerminal | ||||
|     private World m_world; | ||||
|     private BlockPos m_position; | ||||
|  | ||||
|     private final ComputerFamily m_family; | ||||
|     private final Computer m_computer; | ||||
|     private NBTTagCompound m_userData; | ||||
|     private boolean m_changed; | ||||
| @@ -54,6 +55,7 @@ public class ServerComputer extends ServerTerminal | ||||
|         m_world = world; | ||||
|         m_position = null; | ||||
|  | ||||
|         m_family = family; | ||||
|         m_computer = new Computer( this, getTerminal(), computerID ); | ||||
|         m_computer.setLabel( label ); | ||||
|         m_userData = null; | ||||
| @@ -63,6 +65,10 @@ public class ServerComputer extends ServerTerminal | ||||
|         m_ticksSincePing = 0; | ||||
|     } | ||||
|  | ||||
|     public ComputerFamily getFamily(){ | ||||
|         return m_family; | ||||
|     } | ||||
|  | ||||
|     public World getWorld() | ||||
|     { | ||||
|         return m_world; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Steven Dirth
					Steven Dirth