Adding spawn prot when warping to spawn

Discussion in 'Plugin Development' started by lelguy, Oct 5, 2015.

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

    lelguy

    Hey,
    I am trying to code a plugin where when you type /spawn it gives you spawn protection...

    Heres basically the code (everything works exept that you get spawn prot by teleporting to spawn)

    Code:
     public boolean onCommand(CommandSender cmdSender, Command cmd, String paramString, String[] paramArrayOfString)
      {
        if (cmd.getName().equalsIgnoreCase("spawn"))
        {
          final Player p = (Player)cmdSender;
           
            
                    p.sendMessage(ChatColor.RED + "Teleporting to spawn in 10 seconds!");
                    Main.dontmove.add(p.getName());
                    WarpMethods.warpRunnable = Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin)JavaPlugin.getPlugin((Class)Main.class), (Runnable)new Runnable() {
                        @Override
                        public void run() {
                            if (Main.dontmove.contains(p.getName())) {
                                p.teleport(new Location(Bukkit.getWorld("s"), 0.0D, 9.0D, 0.0D));
                                 
                        
                                Main.dontmove.remove(p.getName());
                               
                               
                                Main.spawnProt.add(p.getName());
                                
                            }
                        }
                    }, 200L);
    }
        return false;
       
      }
    }
    (what doesnt work is "Main.spawnProt.add(p.getName());")
     
  2. Offline

    RoboticPlayer

    A) Don't use "Main" as your main class' name, use something unique to the plugin
    B) Returning false says that the command wasn't handled, and will return the usage from the plugin.yml
    C) Check before casting sender to player!
    D) What are you doing with Main.spawnProt (I assume it is an ArrayList)?
    E) To cancel damage, just listen for the EntityDamageEvent, check if the entity is a player, and if they are in the ArrayList cancel the event.
     
Thread Status:
Not open for further replies.

Share This Page