P tags

Discussion in 'Plugin Development' started by NoSpanMan, Apr 5, 2015.

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

    NoSpanMan

    How can i add p.teleport tag in here?
    Code:
    public class Countdown extends JavaPlugin implements Listener {
    
       public int number = 5;
      
       public void onEnable() {
        
       }
      
       public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
         if(cmd.getName().equalsIgnoreCase("timer")) {
           new BukkitRunnable() {
            
           public void run() {
             if (number != -1) {
               if(number != 0) {
                 Bukkit.broadcastMessage("" + number);
                 number--;
               } else {
                 Bukkit.broadcastMessage("EIND!");
                 number = 5;
                 cancel();
                 }
               }
             }
           }.runTaskTimer(this, 0, 20); // 20L = 1sec
           }
         return false;
         }
       }
    
    
     
  2. Code:
    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    if(cmd.getName().equalsIgnoreCase("timer")) {
        if(!(sender instanceof Player)) { return false; }
    
        final Player player = (Player) sender;
            new BukkitRunnable() {
                int number = 5;
                @Override
                public void run() {
                    if(number >= 1) {
                        Bukkit.broadcastMessage("" + number);
                        number--;
                    } else {
                        if(player != null) {
                            player.teleport(player.getLocation());
                        }
                        Bukkit.broadcastMessage("END!");
                        this.cancel();
                    }
                }
            }.runTaskTimer(this, 0, 20);
        return true;
    }
    return false;
    }
    }
     
    Last edited: Apr 5, 2015
  3. Offline

    VortexGmer

    Why is there nothing in the onEnable(){
    }?????????????????
     
  4. Offline

    NoSpanMan

    @VortexGmer Thats not the problem you don't need things in the config only for commands.
     
  5. Why store an UUID and then get the Player from the UUID?
    And not just:
    Code:java
    1.  
    2. final Player player = (Player) sender;
    3. new BukkitRunnable() {
    4. public void run() {
    5. //code
    6. player.doStuff()
    7. }
    8. }
     
  6. Cuz the player can be offline ^^
     
  7. then do:
    Code:java
    1. if(player == null) cancel();
     
    Last edited: Apr 5, 2015
  8. Edit too op,i didn't think about that, i wrote it when just woke up

    pd: Can you close syntax?
     
Thread Status:
Not open for further replies.

Share This Page