package me.km.commands; import me.km.api.Utils; import me.km.api.GlobalText; import me.km.api.Module; import me.km.api.ModuleCommand; import me.km.chatmanager.ChatManager; import me.km.permissions.Permissions; import me.km.utils.SpecialBlockUtils; import net.minecraft.block.Block; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.tileentity.TileEntitySign; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class CommandSign extends ModuleCommand { public CommandSign(Module m) { super("sign", m); super.setDescription("Editiert ein Schild"); super.setUsage("/sign <1-4> [text]"); super.setPermission(Permissions.SIGN); } @Override public boolean execute(ICommandSender cs, String[] arg) { if(!(cs instanceof EntityPlayer)) { this.getModule().send(cs, GlobalText.onlyPlayer()); return true; } if(arg.length < 1) { return false; } EntityPlayer p = (EntityPlayer) cs; World w = p.getEntityWorld(); BlockPos pos = Utils.getPlayerTarget(p, 20, true); Block b = w.getBlockState(pos).getBlock(); if(b == Blocks.STANDING_SIGN || b == Blocks.WALL_SIGN) { TileEntitySign sign = (TileEntitySign) w.getTileEntity(pos); if(sign == null) { this.getModule().send(cs, GlobalText.shouldNotHappen()); return true; } int line; try { line = Integer.parseInt(arg[0]) - 1; if(line > 3 || line < 0) { throw new java.lang.NumberFormatException(); } } catch(java.lang.NumberFormatException ex) { this.getModule().send(cs, "Du musst eine Zahl von 1 bis 4 eingeben."); return true; } String newText = Utils.connectSpaces(arg, 1); newText = ChatManager.colorMessage(newText, p); SpecialBlockUtils.setSignLine(sign, line, newText); return true; } this.getModule().send(cs, "Du bist nicht auf ein Schild gerichtet."); return true; } }