Advertisement
Fer22f

CommandBlockColor

Nov 15th, 2013
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.16 KB | None | 0 0
  1. package com.github.fer22f.commandBlockColor;
  2.  
  3. import net.minecraft.server.v1_4_5.*;
  4.  
  5. import org.bukkit.block.Block;
  6. import org.bukkit.command.Command;
  7. import org.bukkit.command.CommandSender;
  8. import org.bukkit.craftbukkit.v1_4_5.CraftWorld;
  9. import org.bukkit.entity.Player;
  10. import org.bukkit.plugin.java.JavaPlugin;
  11.  
  12. public class CommandBlockColor extends JavaPlugin {
  13.  
  14.     @Override
  15.     public void onEnable(){
  16.         getLogger().info("onEnable has been invoked!");
  17.     }
  18.  
  19.     @Override
  20.     public void onDisable() {
  21.         getLogger().info("onDisable has been invoked!");
  22.     }
  23.    
  24.     public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
  25.         if(cmd.getName().equalsIgnoreCase("colorCommandBlock")){ // If the player typed /basic then do the following...
  26.             if (!(sender instanceof Player)) {
  27.                 sender.sendMessage("This command can only be run by a player.");
  28.             } else {
  29.                 String res = "";
  30.                 for (int x = 0; x < args.length; x++)
  31.                 {
  32.                   if (x == 0)
  33.                   {
  34.                      res = args[0];
  35.                   } else {
  36.                       res = res + " " + args[x];
  37.                   }
  38.                  
  39.                 }
  40.                 res = res.replace("&", "ยง");
  41.                 res = res.replace("&&", "&");
  42.                 Player player = (Player)sender;
  43.                 CraftWorld cw = (CraftWorld)player.getWorld();
  44.                 Block b = player.getTargetBlock(null, 10);
  45.                 if (b.getTypeId() != 137)
  46.                 {
  47.                  getLogger().info("This isn't a Command Block");
  48.                  
  49.                 }
  50.                
  51.                 b.setTypeId(137);
  52.                 cw.getHandle().setTileEntity(b.getX(), b.getY(), b.getZ(), null);
  53.                 TileEntityCommand c = new TileEntityCommand();
  54.                 NBTTagCompound com = new NBTTagCompound();
  55.                 com.setString("Command", res);
  56.                 c.a(com);
  57.                 cw.getHandle().setTileEntity(b.getX(), b.getY(), b.getZ(), c);
  58.                 c.update();
  59.                 getLogger().info("Successful process, command block now has the command:");
  60.                 getLogger().info(res);
  61.             }
  62.             return true;
  63.         } //If this has happened the function will return true.
  64.             // If this hasn't happened the a value of false will be returned.
  65.         return false;
  66.     }
  67.    
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement