Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.github.fer22f.commandBlockColor;
- import net.minecraft.server.v1_4_5.*;
- import org.bukkit.block.Block;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.craftbukkit.v1_4_5.CraftWorld;
- import org.bukkit.entity.Player;
- import org.bukkit.plugin.java.JavaPlugin;
- public class CommandBlockColor extends JavaPlugin {
- @Override
- public void onEnable(){
- getLogger().info("onEnable has been invoked!");
- }
- @Override
- public void onDisable() {
- getLogger().info("onDisable has been invoked!");
- }
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
- if(cmd.getName().equalsIgnoreCase("colorCommandBlock")){ // If the player typed /basic then do the following...
- if (!(sender instanceof Player)) {
- sender.sendMessage("This command can only be run by a player.");
- } else {
- String res = "";
- for (int x = 0; x < args.length; x++)
- {
- if (x == 0)
- {
- res = args[0];
- } else {
- res = res + " " + args[x];
- }
- }
- res = res.replace("&", "ยง");
- res = res.replace("&&", "&");
- Player player = (Player)sender;
- CraftWorld cw = (CraftWorld)player.getWorld();
- Block b = player.getTargetBlock(null, 10);
- if (b.getTypeId() != 137)
- {
- getLogger().info("This isn't a Command Block");
- }
- b.setTypeId(137);
- cw.getHandle().setTileEntity(b.getX(), b.getY(), b.getZ(), null);
- TileEntityCommand c = new TileEntityCommand();
- NBTTagCompound com = new NBTTagCompound();
- com.setString("Command", res);
- c.a(com);
- cw.getHandle().setTileEntity(b.getX(), b.getY(), b.getZ(), c);
- c.update();
- getLogger().info("Successful process, command block now has the command:");
- getLogger().info(res);
- }
- return true;
- } //If this has happened the function will return true.
- // If this hasn't happened the a value of false will be returned.
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement