/** * Called by ItemBlocks after a block is set in the world, to allow post-place logic */ public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { TileEntity tileentity = worldIn.getTileEntity(pos); if (tileentity instanceof TileEntityCommandBlock) { CommandBlockLogic commandblocklogic = ((TileEntityCommandBlock)tileentity).getCommandBlockLogic(); if (stack.hasDisplayName()) { commandblocklogic.setName(stack.getDisplayName()); } if (!worldIn.isRemote) { commandblocklogic.setTrackOutput(worldIn.getGameRules().getBoolean("sendCommandFeedback")); } } }
private int handleCommandExecution(ICommandManager commandManager, CommandBlockLogic commandBlockLogic, String commandStored) { final String[] args = commandStored.split(" "); String commandName = args[0]; if (commandName.startsWith("/")) { commandName = commandName.substring(1); } CommandBlockCommandHook commandHook = (CommandBlockCommandHook) new CommandBlockCommandHook( (net.canarymod.api.CommandBlockLogic) commandBlockLogic, args).call(); if (!commandHook.isCanceled() && (Configuration.getServerConfig().isCommandBlockOpped() || ((net.canarymod.api.CommandBlockLogic) commandBlockLogic).hasPermission("canary.command." + commandName))) { int result = commandManager.executeCommand(commandBlockLogic, commandStored); if (result == 0) { // Minecraft found no command, now its our turn Canary.getServer().consoleCommand(commandStored, (net.canarymod.api.CommandBlockLogic) commandBlockLogic); } return result; } return 0; }
public static int fireCommand(ICommandSender sender, String input){ CommandSender wrapped = null; if(sender instanceof EntityPlayerMP){ wrapped = NailedPlatform.instance().getPlayer(((EntityPlayerMP) sender).getGameProfile().getId()); }else if(sender instanceof CommandBlockLogic){ wrapped = new CommandBlockCommandSender(((CommandBlockLogic) sender)); //TODO: replace this with our own api }else if(sender instanceof RConConsoleSource){ //wrapped = new RConCommandSender(((RConConsoleSource) sender)); }else if(sender instanceof MinecraftServer){ wrapped = serverCommandSender; } if(wrapped == null){ return -1; } return NailedCommandManager.fireCommand((wrapped instanceof Player) ? input.substring(1) : input, wrapped, sender); }
public static List<String> fireTabCompletion(ICommandSender sender, String input){ CommandSender wrapped = null; if(sender instanceof EntityPlayerMP){ wrapped = NailedPlatform.instance().getPlayer(((EntityPlayerMP) sender).getGameProfile().getId()); }else if(sender instanceof CommandBlockLogic){ wrapped = new CommandBlockCommandSender(((CommandBlockLogic) sender)); //TODO: replace this with our own api }else if(sender instanceof RConConsoleSource){ //wrapped = new RConCommandSender(((RConConsoleSource) sender)); }else if(sender instanceof MinecraftServer){ wrapped = serverCommandSender; } if(wrapped == null){ return null; } return NailedCommandManager.fireAutocompletion(input, wrapped, sender); }
/** * Load command data from NBT tag * @param commandBlock Target command block * @param tag tag to load * @param seed Loading seed */ private static void load(TileEntityCommandBlock commandBlock, NBTTagCompound tag, long seed) { if (tag == null) { return; } Random random = new Random(seed); CommandBlockLogic logic = commandBlock.func_145993_a(); logic.func_145759_b(tag); }
@Override public ReceiverType getReceiverType() { if (this instanceof Player) { return ReceiverType.PLAYER; } else if (this instanceof net.canarymod.api.CommandBlockLogic) { return ReceiverType.COMMANDBLOCK; } else { return ReceiverType.SERVER; } }
@Override public net.canarymod.api.CommandBlockLogic asCommandBlock() { if (this instanceof net.canarymod.api.CommandBlockLogic) { return (net.canarymod.api.CommandBlockLogic) this; } throw new InvalidInstanceException("This is not a MessageReceiver of the type: COMMANDBLOCK"); }
/** * Ticks the block if it's been scheduled */ public void updateTick(World p_149674_1_, int p_149674_2_, int p_149674_3_, int p_149674_4_, Random p_149674_5_) { TileEntity var6 = p_149674_1_.getTileEntity(p_149674_2_, p_149674_3_, p_149674_4_); if (var6 != null && var6 instanceof TileEntityCommandBlock) { CommandBlockLogic var7 = ((TileEntityCommandBlock)var6).func_145993_a(); var7.func_145755_a(p_149674_1_); p_149674_1_.func_147453_f(p_149674_2_, p_149674_3_, p_149674_4_, this); } }
/** * Sends a message to the admins of the server from a given CommandSender with the given resource string and given * extra srings. If the int par2 is even or zero, the original sender is also notified. */ public void notifyAdmins(ICommandSender par1ICommandSender, int par2, String par3Str, Object ... par4ArrayOfObj) { boolean var5 = true; if (par1ICommandSender instanceof CommandBlockLogic && !MinecraftServer.getServer().worldServers[0].getGameRules().getGameRuleBooleanValue("commandBlockOutput")) { var5 = false; } ChatComponentTranslation var6 = new ChatComponentTranslation("chat.type.admin", new Object[] {par1ICommandSender.getCommandSenderName(), new ChatComponentTranslation(par3Str, par4ArrayOfObj)}); var6.getChatStyle().setColor(EnumChatFormatting.GRAY); var6.getChatStyle().setItalic(Boolean.valueOf(true)); if (var5) { Iterator var7 = MinecraftServer.getServer().getConfigurationManager().playerEntityList.iterator(); while (var7.hasNext()) { EntityPlayerMP var8 = (EntityPlayerMP)var7.next(); if (var8 != par1ICommandSender && MinecraftServer.getServer().getConfigurationManager().isPlayerOpped(var8.getCommandSenderName())) { var8.addChatMessage(var6); } } } if (par1ICommandSender != MinecraftServer.getServer()) { MinecraftServer.getServer().addChatMessage(var6); } if ((par2 & 1) != 1) { par1ICommandSender.addChatMessage(new ChatComponentTranslation(par3Str, par4ArrayOfObj)); } }
/** * @author jamierocks - 1st September 2016 * @reason Log command feedback */ @Overwrite public void notifyOperators(ICommandSender sender, ICommand command, int flags, String msgFormat, Object... msgParams) { final MinecraftServer server = MinecraftServer.getServer(); final IChatComponent feedback = new ChatComponentTranslation("chat.type.admin", sender.getName(), new ChatComponentTranslation(msgFormat, msgParams)); feedback.getChatStyle().setColor(EnumChatFormatting.GRAY); feedback.getChatStyle().setItalic(true); if (sender.sendCommandFeedback()) { for (final EntityPlayer player : server.getConfigurationManager().getPlayerList()) { if (player != sender && server.getConfigurationManager().canSendCommands(player.getGameProfile()) && command .canCommandSenderUseCommand(sender)) { final boolean broadcastConsoleToOps = sender instanceof MinecraftServer && MinecraftServer.getServer().shouldBroadcastConsoleToOps(); final boolean broadcastRconToOps = sender instanceof RConConsoleSource && MinecraftServer.getServer().shouldBroadcastRconToOps(); if (broadcastConsoleToOps || broadcastRconToOps || !(sender instanceof RConConsoleSource) && !(sender instanceof MinecraftServer)) { player.addChatMessage(feedback); } } } } // Neptune - Always log command feedback //if (sender != server && server.worldServers[0].getGameRules().getBoolean("logAdminCommands")) { server.addChatMessage(feedback); //} // Neptune - end final boolean shouldSendCommandFeedback = sender instanceof CommandBlockLogic ? ((CommandBlockLogic) sender).shouldTrackOutput() : server.worldServers[0].getGameRules().getBoolean("sendCommandFeedback"); if ((flags & 1) != 1 && shouldSendCommandFeedback || sender instanceof MinecraftServer) { sender.addChatMessage(new ChatComponentTranslation(msgFormat, msgParams)); } }
/** * @author jamierocks - 3rd September 2016 * @reason Support Canary commands */ @Overwrite public void trigger(net.minecraft.world.World worldIn) { if (worldIn.isRemote) { this.successCount = 0; } MinecraftServer minecraftserver = MinecraftServer.getServer(); if (minecraftserver != null && minecraftserver.isAnvilFileSet() && minecraftserver.isCommandBlockEnabled()) { ICommandManager icommandmanager = minecraftserver.getCommandManager(); try { this.lastOutput = null; // Neptune - Canary commands this.successCount = this.handleCommandExecution(icommandmanager, (CommandBlockLogic) (Object) this, this.commandStored); // Neptune - end } catch (Throwable throwable) { CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Executing command block"); CrashReportCategory crashreportcategory = crashreport.makeCategory("Command to be executed"); crashreportcategory.addCrashSectionCallable("Command", this::getCommand); crashreportcategory.addCrashSectionCallable("Name", this::getName); throw new ReportedException(crashreport); } } else { this.successCount = 0; } }
@Override public void processCommand(ICommandSender sender, String[] args) { if (!(sender instanceof CommandBlockLogic) && !sender.canCommandSenderUseCommand(3, this.getCommandName())) { throw new CommandException("Could not execute command: Permission Denied"); } if (args.length < 1) { throw new CommandException("Could not execute command"); } String filename = args[0]; double x = sender.getPlayerCoordinates().posX; double y = sender.getPlayerCoordinates().posY; double z = sender.getPlayerCoordinates().posZ; if (args.length > 3) { x = func_110666_a(sender, x, args[1]); y = func_110666_a(sender, y, args[2]); z = func_110666_a(sender, z, args[3]); } SchematicLoader loader = new SchematicLoader(); if (!filename.endsWith(".schematic")) { filename += ".schematic"; } ResourceLocation schematicLocation = loader.loadSchematic(new File(TheMod.proxy.getDataDirectory(), "/Schematics/" + filename)); loader.renderSchematicInOneShot(schematicLocation, sender.getEntityWorld(), (int) x, (int) y, (int) z, ForgeDirection.NORTH, false); sender.addChatMessage(new ChatComponentText("Rendered schematic " + filename)); }
public SchematicLoader() { tileEntityLoadedEventListeners.add(new ITileEntityLoadedEvent() { @Override public boolean onTileEntityAdded(TileEntity tileEntity) { if (tileEntity instanceof TileEntityCommandBlock) { _logger.info("Activating command Block"); final GameRules gameRules = MinecraftServer.getServer().worldServers[0].getGameRules(); Boolean commandBlockOutputSetting = gameRules.getGameRuleBooleanValue("commandBlockOutput"); gameRules.setOrCreateGameRule("commandBlockOutput", "false"); final World worldObj = tileEntity.getWorldObj(); TileEntityCommandBlock commandBlock = (TileEntityCommandBlock) tileEntity; Block block = worldObj.getBlock(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord); CommandBlockLogic commandblocklogic = commandBlock.func_145993_a(); commandblocklogic.func_145755_a(worldObj); worldObj.func_147453_f(commandBlock.xCoord, commandBlock.yCoord, commandBlock.zCoord, block); if (worldObj.getTileEntity(commandBlock.xCoord, commandBlock.yCoord, commandBlock.zCoord) instanceof TileEntityCommandBlock) { worldObj.setBlock(commandBlock.xCoord, commandBlock.yCoord, commandBlock.zCoord, Blocks.air, 0, 3); } gameRules.setOrCreateGameRule("commandBlockOutput", commandBlockOutputSetting.toString()); return true; } return false; } }); }
public void updateTick(World p_149674_1_, int p_149674_2_, int p_149674_3_, int p_149674_4_, Random p_149674_5_) { TileEntity tileentity = p_149674_1_.getTileEntity(p_149674_2_, p_149674_3_, p_149674_4_); if (tileentity != null && tileentity instanceof TileEntityCommandBlock) { CommandBlockLogic commandblocklogic = ((TileEntityCommandBlock)tileentity).func_145993_a(); commandblocklogic.func_145755_a(p_149674_1_); p_149674_1_.func_147453_f(p_149674_2_, p_149674_3_, p_149674_4_, this); } }
public void func_152372_a(ICommandSender p_152372_1_, ICommand p_152372_2_, int p_152372_3_, String p_152372_4_, Object ... p_152372_5_) { boolean flag = true; if (p_152372_1_ instanceof CommandBlockLogic && !MinecraftServer.getServer().worldServers[0].getGameRules().getGameRuleBooleanValue("commandBlockOutput")) { flag = false; } ChatComponentTranslation chatcomponenttranslation = new ChatComponentTranslation("chat.type.admin", new Object[] {p_152372_1_.getCommandSenderName(), new ChatComponentTranslation(p_152372_4_, p_152372_5_)}); chatcomponenttranslation.getChatStyle().setColor(EnumChatFormatting.GRAY); chatcomponenttranslation.getChatStyle().setItalic(Boolean.valueOf(true)); if (flag) { Iterator iterator = MinecraftServer.getServer().getConfigurationManager().playerEntityList.iterator(); while (iterator.hasNext()) { EntityPlayer entityplayer = (EntityPlayer)iterator.next(); if (entityplayer != p_152372_1_ && MinecraftServer.getServer().getConfigurationManager().func_152596_g(entityplayer.getGameProfile()) && p_152372_2_.canCommandSenderUseCommand(entityplayer) && (!(p_152372_1_ instanceof RConConsoleSource) || MinecraftServer.getServer().func_152363_m())) { entityplayer.addChatMessage(chatcomponenttranslation); } } } if (p_152372_1_ != MinecraftServer.getServer()) { MinecraftServer.getServer().addChatMessage(chatcomponenttranslation); } if ((p_152372_3_ & 1) != 1) { p_152372_1_.addChatMessage(new ChatComponentTranslation(p_152372_4_, p_152372_5_)); } }
public CraftBlockCommandSender(CommandBlockLogic commandBlockListenerAbstract) { super(); this.commandBlock = commandBlockListenerAbstract; }
public void openEditCommandBlock(CommandBlockLogic cmdBlockLogic) { }
public CommandBlockLogic getCommandBlockLogic() { return this.commandBlockLogic; }
/** * Send an informative message to the server operators */ public void notifyOperators(ICommandSender sender, ICommand command, int flags, String msgFormat, Object... msgParams) { boolean flag = true; MinecraftServer minecraftserver = MinecraftServer.getServer(); if (!sender.sendCommandFeedback()) { flag = false; } IChatComponent ichatcomponent = new ChatComponentTranslation("chat.type.admin", new Object[] {sender.getName(), new ChatComponentTranslation(msgFormat, msgParams)}); ichatcomponent.getChatStyle().setColor(EnumChatFormatting.GRAY); ichatcomponent.getChatStyle().setItalic(Boolean.valueOf(true)); if (flag) { for (EntityPlayer entityplayer : minecraftserver.getConfigurationManager().func_181057_v()) { if (entityplayer != sender && minecraftserver.getConfigurationManager().canSendCommands(entityplayer.getGameProfile()) && command.canCommandSenderUseCommand(sender)) { boolean flag1 = sender instanceof MinecraftServer && MinecraftServer.getServer().func_183002_r(); boolean flag2 = sender instanceof RConConsoleSource && MinecraftServer.getServer().func_181034_q(); if (flag1 || flag2 || !(sender instanceof RConConsoleSource) && !(sender instanceof MinecraftServer)) { entityplayer.addChatMessage(ichatcomponent); } } } } if (sender != minecraftserver && minecraftserver.worldServers[0].getGameRules().getBoolean("logAdminCommands")) { minecraftserver.addChatMessage(ichatcomponent); } boolean flag3 = minecraftserver.worldServers[0].getGameRules().getBoolean("sendCommandFeedback"); if (sender instanceof CommandBlockLogic) { flag3 = ((CommandBlockLogic)sender).shouldTrackOutput(); } if ((flags & 1) != 1 && flag3 || sender instanceof MinecraftServer) { sender.addChatMessage(new ChatComponentTranslation(msgFormat, msgParams)); } }
public void openEditCommandBlock(CommandBlockLogic cmdBlockLogic) { this.mc.displayGuiScreen(new GuiCommandBlock(cmdBlockLogic)); }
public GuiCommandBlock(CommandBlockLogic p_i45032_1_) { this.localCommandBlock = p_i45032_1_; }