You are viewing our Forum Archives. To view or take place in current topics click here.
Minecraft Plugin Help!
Posted:

Minecraft Plugin Help!Posted:

--__--__--__--
  • New Member
Status: Offline
Joined: Jun 10, 201310Year Member
Posts: 31
Reputation Power: 1
Status: Offline
Joined: Jun 10, 201310Year Member
Posts: 31
Reputation Power: 1
I'm trying to get this plugin to work. It says its enabled but whenever I type the command it doesn't do anything. Could you take a look at the source code and tell me what I need to fix to make it work? Thanks!

package Flatten;
 
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
 
public class Flatten extends JavaPlugin {
        public boolean onCommand(CommandSender commandSender, Command command, String label, String[] args) {
                if(!(commandSender instanceof Player)) {
                        commandSender.sendMessage("You need to be a player to use this command!");
                        return true;
                }
                Player senderPlayer = (Player) commandSender;
                if(!(senderPlayer.isOp())) {
                        senderPlayer.sendMessage("You need to be OP to use this command!");
                        return true;
                } else if(!(senderPlayer.hasPermission("flatten.*"))) {
                        senderPlayer.sendMessage("You don't have enough permissions to use this command!");
                        return true;
                }
 
                if(command.getName().equalsIgnoreCase("flatten")) {
                        int radius = 0;
                        int height = 0;
                        Material groundBlock = null;
                        if(args.length < 3) {
                                senderPlayer.sendMessage("Not enough arguments");
                                return false;
                        }
                        if(args.length > 0)
                                radius = Integer.parseInt(args[0]);
                        if(args.length > 1)
                                height = Integer.parseInt(args[1]);
                        if(args.length > 2) {
                                if(Material.getMaterial(Integer.parseInt(args[2])) != null)
                                        groundBlock = Material.getMaterial(Integer.parseInt(args[2]));
                                else {
                                        senderPlayer.sendMessage("Error: undefined material.");
                                        return false;
                                }
                        }
 
                        for(int currentHeight = 0; currentHeight <= height; currentHeight++) {
                                for(int layer = radius; layer >= 0; layer--) {
                                        Location playerLocation = senderPlayer.getLocation();
                                        Location centerLocation = new Location(playerLocation.getWorld(), playerLocation.getBlockX(), playerLocation.getBlockY() - currentHeight, playerLocation.getBlockZ());
                                        if(currentHeight == height)
                                                changeCircleExterior(centerLocation, layer, groundBlock);
                                        else
                                                changeCircleExterior(centerLocation, layer, Material.AIR);
                                }
                        }
                }
               
                senderPlayer.sendMessage("Cleared cylinder.");
                return true;
        }
 
        // Circle tracing algorithm, taken from
        // http://fr.wikipedia.org/wiki/Algorithme_de_trac%C3%A9_de_cercle_d%27Andres
        void changeCircleExterior(Location center, int radius, Material type) {
                World targetWorld = center.getWorld();
 
                int x = 0;
                int z = radius;
                int d = radius - 1;
                int centerX = center.getBlockX();
                int centerY = center.getBlockY();
                int centerZ = center.getBlockZ();
 
                while(z >= x) {
                        targetWorld.getBlockAt(x + centerX, centerY, z + centerZ).setType(type);
                        targetWorld.getBlockAt(z + centerX, centerY, x + centerZ).setType(type);
                        targetWorld.getBlockAt(-x + centerX, centerY, z + centerZ).setType(type);
                        targetWorld.getBlockAt(-z + centerX, centerY, x + centerZ).setType(type);
                        targetWorld.getBlockAt(x + centerX, centerY, -z + centerZ).setType(type);
                        targetWorld.getBlockAt(z + centerX, centerY, -x + centerZ).setType(type);
                        targetWorld.getBlockAt(-x + centerX, centerY, -z + centerZ).setType(type);
                        targetWorld.getBlockAt(-z + centerX, centerY, -x + centerZ).setType(type);
                        if(d >= 2*x) {
                                d = d - 2*x - 1;
                                x = x+1;
                        } else if(d <= 2*(radius - z)) {
                                d = d + 2*z - 1;
                                z = z - 1;
                        } else {
                                d = d + 2*(z - x - 1);
                                z = z -1;
                                x = x+1;
                        }
                }
        }
}
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.