I don't even know what is wrong...

Discussion in 'Plugin Development' started by Lupus, Jul 15, 2012.

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

    Lupus

    Code:
    package us.lupusbikkit.Freeze;
     
    import java.util.ArrayList;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.event.player.PlayerTeleportEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Freeze extends JavaPlugin implements Listener {
        public void onDisable(){
           
            System.out.println(this + " is now disabled!");
        }
        static ArrayList<Player> frozen = new ArrayList<Player>();
        @Override
            public void onEnable(){
            getServer().getPluginManager().registerEvents(this, this);
        }
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
                if (command.getName().equalsIgnoreCase("freeze") && sender.hasPermission("freeze.freeze")) {
                    Player target = getServer().getPlayer(args[0]); 
                    if (!target.hasPermission("freeze.exempt"))       
                        frozen.add(target);
                        sender.sendMessage(ChatColor.GREEN + target.getName() + " has been frozen.");
                        target.sendMessage(ChatColor.RED + sender.getName() + "has frozen you!");
                        return true;
                    }
                       
                        else sender.sendMessage(ChatColor.RED + "Cannot freeze that player!");
                        return false;
        }
                                     
                if (command.getName().equalsIgnoreCase("unfreeze") && sender.hasPermission("freeze.unfreeze")) {
                    if (args.length != 0) {
                        Player target = getServer().getPlayer(args[0]);
                        frozen.remove(target);
                        sender.sendMessage(ChatColor.GREEN + target.getName() + " has been unfrozen.");
                        target.sendMessage(ChatColor.GREEN + sender.getName() + " has unfrozen you!");
                        return true;
                    }
                    return false; // This should send the usage message automatically
                }
                return false;
        }
        @EventHandler
        public void onBlockPlace(BlockPlaceEvent event) {
        Player player = event.getPlayer();
        if (frozen.contains(player)) {
            event.setCancelled(true);
        }
        }
        @EventHandler
        public void onBlockBreak(BlockBreakEvent event) {
            Player player = event.getPlayer();
            if (frozen.contains(player)) {
                event.setCancelled(true);
            }
        }
        @EventHandler
        public void onPlayerMove(PlayerMoveEvent event) {
            Player player = event.getPlayer();
            if (frozen.contains(player)) {
                event.setTo(event.getFrom());
            }
           
        }
    }

    I am getting numerous errors in the if statement for the unfreeze command. Help?
     
  2. Offline

    Kodfod

    What You put:
    Code:JAVA
    1.  
    2. if (!target.hasPermission("freeze.exempt"))
    3. frozen.add(target);
    4. sender.sendMessage(ChatColor.GREEN + target.getName() + " has been frozen.");
    5. target.sendMessage(ChatColor.RED + sender.getName() + "has frozen you!");
    6. return true;
    7. }
    8.  


    Should be:
    Code:JAVA
    1.  
    2. if (!target.hasPermission("freeze.exempt"))
    3. frozen.put(target);
    4. sender.sendMessage(ChatColor.GREEN + target.getName() + " has been frozen.");
    5. target.sendMessage(ChatColor.RED + sender.getName() + "has frozen you!");
    6. return true;
    7. }
    8.  
     
  3. Offline

    VeryBIgCorp

    It's an ArrayList, not a Map
     
  4. Offline

    Kodfod

    *should learn to read* XD
     
  5. Offline

    gjossep

    What are your errors? Can we see them?
     
  6. Offline

    Firefly

    Code:
    if (!target.hasPermission("freeze.exempt"))     
                        frozen.add(target);
                        sender.sendMessage(ChatColor.GREEN + target.getName() + " has been frozen.");
                        target.sendMessage(ChatColor.RED + sender.getName() + "has frozen you!");
                        return true;
                    }
                     
                        else sender.sendMessage(ChatColor.RED + "Cannot freeze that player!");
                        return false;
    I think you're missing some brackets.
     
    ferrybig likes this.
Thread Status:
Not open for further replies.

Share This Page