Really annoying errors.

Discussion in 'Plugin Development' started by spankynutbean, Apr 21, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    spankynutbean

    So here's my code:
    Code:
    package me.spankynutbean.cuboid;
     
    import java.util.HashMap;
    import org.bukkit.Location;
    import org.bukkit.event.Event.*;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.*;
    import org.bukkit.plugin.java.JavaPlugin;
     
     
    public class Cuboid extends JavaPlugin {
        private HashMap<String, BlockStorage> startedCuboids = new HashMap<String, BlockStorage>();
        public void onDisable() {}
        public void onEnable() {
            getServer().getPluginManager().registerEvent(Type.PLAYER_INTERACT, new Listener(), Priority.Normal, this);
            System.out.println("[Cuboid] Enabled.");
        }
        private class Listener extends PlayerListener{
            public void onPlayerInteract(PlayerInteractEvent event) {
                if(!(event.getPlayer().getItemInHand().getTypeId() ==  280) && !(event.getAction().equals(Action.RIGHT_CLICK_BLOCK)))  return;
                if(startedCuboids.containsKey(event.getPlayer().getName())){
                    BlockStorage bs = startedCuboids.get(event.getPlayer().getName());
                    bs.loc2 = event.getClickedBlock().getLocation();
                    int start_x = Math.min(bs.loc1.getBlockX(), bs.loc2.getBlockX());
                    int start_y = Math.min(bs.loc1.getBlockY(), bs.loc2.getBlockY());
                    int start_z = Math.min(bs.loc1.getBlockZ(), bs.loc2.getBlockZ());
                    int end_x    = Math.max(bs.loc1.getBlockX(), bs.loc2.getBlockX());
                    int end_y    = Math.max(bs.loc1.getBlockY(), bs.loc2.getBlockY());
                    int end_z    = Math.max(bs.loc1.getBlockZ(), bs.loc2.getBlockZ());
                    for (int x = start_x; x <= end_x; x++) {
                        for (int y = start_y; y <= end_y; y++) {
                            for (int z = start_z; z <= end_z; z++) {
                                bs.loc1.getWorld().getBlockAt(x, y,  z).setTypeIdAndData(bs.loc1.getBlock().getTypeId(),  bs.loc1.getBlock().getData(), false);
                            }
                        }
                    }
                    startedCuboids.remove(event.getPlayer().getName());
                    event.getPlayer().sendMessage("Cuboid builded.  "+"start: ["+start_x+"|"+start_y+"|"+start_z+"] end:  ["+end_x+"|"+end_y+"|"+end_z+"]");
                }
                else {
                    BlockStorage newCubeoid = new BlockStorage();
                    newCubeoid.loc1 = event.getClickedBlock().getLocation();
                    startedCuboids.put(event.getPlayer().getName(), newCubeoid);
                    event.getPlayer().sendMessage("Got Block 1. Now Rightclick Block 2");
                }
            }
        }
        private class BlockStorage{
            public Location loc1, loc2;
        }
    }
    I've got errors on 'PlayerListenerEvent' and 'Type', i cant seem to find a way to get rid of these errors, please help!
     
  2. Offline

    Tirelessly

    spankynutbean You are using the old event system. Please refer to the wiki to find the newer syntax.
     
  3. Offline

    spankynutbean

    Can you help me put it in the new version? I've tried but every time i just get more errors
     
  4. Offline

    devilquak

    spankynutbean

    Don't try to replace your old code here, make a new plugin and just start over.
     
  5. Offline

    spankynutbean

    devilquak Don't worry, already done :) But now i'm having a problem with the HashMap:
    Code:
    private HashMap<String, BlockStorage> startedCuboids = new HashMap<String, BlockStorage>();
        ItemStack itemstack = new ItemStack(Material.STICK, 1);
       
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            if(cmd.getName().equalsIgnoreCase("Cuboid")&&(sender instanceof Player)){ // If the player typed /TownCraft then do the following...
                    Player player = (Player)sender;
                    player.getInventory().addItem(itemstack);
                    player.sendMessage(ChatColor.DARK_PURPLE + "<TownCraft>" + ChatColor.BLUE + "Here's your tool, now get to work!");
                    startedCuboids.add(player.getName(),?);
            }
            return false;
        }
    The question mark there is because i have no idea what to put there, can anyone tell me what to put there if i just want to add the player's name.
     
  6. Offline

    Austy

    You can use a set if You want to store only players' names.
     
  7. Offline

    MadArkael

    like austy said. Set<String> startedCuboids;

    startedCuboids.add(player.getName());
     
  8. Offline

    spankynutbean

    Austy MadArkael Ok here's my code
    Code:
    public class Cuboid extends JavaPlugin {
        public void onDisable() {}
        public void onEnable() {
            System.out.println("[Cuboid] Enabled.");
        }
       
        Set<String> names;
        ItemStack itemstack = new ItemStack(Material.STICK, 1);
       
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            if(cmd.getName().equalsIgnoreCase("Cuboid")&&(sender instanceof Player)){ // If the player typed /TownCraft then do the following...
                    Player player = (Player)sender;
                    player.getInventory().addItem(itemstack);
                    player.sendMessage(ChatColor.DARK_PURPLE + "<TownCraft>" + ChatColor.BLUE + "Here's your tool, now get to work!");
                    names.add(player.getName());
            }
            return false;
        }
       
     
            public void onPlayerInteract(PlayerInteractEvent event) {
                if(!(event.getPlayer().getItemInHand().getTypeId() ==  280) && !(event.getAction().equals(Action.RIGHT_CLICK_BLOCK))){
                if(names.contains(event.getPlayer().getName())){
                    BlockStorage bs = names.get(event.getPlayer().getName());
                    bs.loc2 = event.getClickedBlock().getLocation();
                    int start_x = Math.min(bs.loc1.getBlockX(), bs.loc2.getBlockX());
                    int start_y = Math.min(bs.loc1.getBlockY(), bs.loc2.getBlockY());
                    int start_z = Math.min(bs.loc1.getBlockZ(), bs.loc2.getBlockZ());
                    int end_x = Math.max(bs.loc1.getBlockX(), bs.loc2.getBlockX());
                    int end_y = Math.max(bs.loc1.getBlockY(), bs.loc2.getBlockY());
                    int end_z = Math.max(bs.loc1.getBlockZ(), bs.loc2.getBlockZ());
                    for (int x = start_x; x <= end_x; x++) {
                        for (int y = start_y; y <= end_y; y++) {
                            for (int z = start_z; z <= end_z; z++) {
                                bs.loc1.getWorld().getBlockAt(x, y,  z).setTypeIdAndData(bs.loc1.getBlock().getTypeId(),  bs.loc1.getBlock().getData(), false);
                            }
                        }
                    }
                    names.remove(event.getPlayer().getName());
                    event.getPlayer().sendMessage("Cuboid builded.  "+"start: ["+start_x+"|"+start_y+"|"+start_z+"] end:  ["+end_x+"|"+end_y+"|"+end_z+"]");
                }
                else {
                    BlockStorage newCubeoid = new BlockStorage();
                    newCubeoid.loc1 = event.getClickedBlock().getLocation();
                    names.add(event.getPlayer().getName());
                    event.getPlayer().sendMessage("Got Block 1. Now Rightclick Block 2");
                }
            }
        }
        class BlockStorage{
            public Location loc1, loc2;
        }
    }
    but the 'get' is an error
     
  9. Offline

    Hoolean

    Are you attempting to update an old plugin?
     
  10. Offline

    spankynutbean

    MrBluebear3 No, i'm just trying to create regions, with entry/exit messages without having to go through hours of code with worldguard.
     
Thread Status:
Not open for further replies.

Share This Page