PvP Domination Plugin Loop Delay Help Please!

Discussion in 'Plugin Development' started by Live2Pwn, Jan 17, 2013.

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

    Live2Pwn

    Been trying to work at this plugin for a while now, still hitting a few jagged edges.

    I have managed to make this plugin so that it checks if players are within certain bounds (capturing a point), it will set the variable CapPlayerMod1 to 1+ for every player in bounds. But I need to make it so that it adds 5 to a variable every few seconds or so to represent the capturing of the objective multiplied by CapPlayerMod1, and I have no idea how to create a delay that loops and runs code without Eclipse or the server console spamming errors at me. Please forgive me for my stupidity, my brain is mush as I have been working for about 3 hours now.

    Here is the code for the class:

    Code:
    package com.rocketmail.live2pwn;
     
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerMoveEvent;
     
    public class mcdominationListener implements Listener{
        public static mcdomination plugin;
     
     
     
     
        //variable initialization
        int CapPlayerMod1;
     
     
     
        //player proximity detection
        @EventHandler
        public void onPlayerMove(PlayerMoveEvent evt) {
            Player player = evt.getPlayer();
            Location loc = evt.getPlayer().getLocation();
            World w = loc.getWorld();
            Block b = w.getBlockAt(loc);
            loc.setX(loc.getX() + 0);
            loc.setY(loc.getY() + 0);
            loc.setZ(loc.getZ() + 0);
            if(loc.getX() < -80 && loc.getX() > -90){;;
            player.sendMessage("Capturing point 1... ");
                CapPlayerMod1 =+ 1;
            }
            else{
                CapPlayerMod1 =+ 0;
            }
        }
    }





    And in case you are wondering, I am also using a primary class of:

    Code:
    package com.rocketmail.live2pwn;
     
        import java.util.logging.Logger;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    import org.bukkit.event.player.PlayerMoveEvent;
            public class mcdomination extends JavaPlugin{
            public final Logger logger = Logger.getLogger("Minecraft");
            public static mcdomination plugin;
            public final mcdominationListener bl = new mcdominationListener();
         
         
         
         
         
            @Override
            public void onDisable(){
                PluginDescriptionFile pdfFile = this.getDescription();
                this.logger.info("[MCDomination] Now Disabled.");
            }
         
            @Override
            public void onEnable(){
                PluginDescriptionFile pdfFile = this.getDescription();
                this.logger.info("[MCDomination] Now Enabled.");
             
                PluginManager pm = getServer().getPluginManager();
                pm.registerEvents(this.bl, this);
            }
         
         
            //commands
         
         
            public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
                Player player = (Player) sender;
                if(commandLabel.equalsIgnoreCase("mcd")){
                    player.sendMessage(ChatColor.GOLD + "[MCDomination] Version 1.0 by Live2Pwn(live2pwn2010)");
                }
                if(commandLabel.equalsIgnoreCase("pow")){
                    Location loc = player.getPlayer().getLocation();
                    World w = loc.getWorld();
                    loc.setY(113);
                    loc.setX(-98);
                    loc.setZ(21);
                    Block b = w.getBlockAt(loc);
                    b.setTypeId(42);
                 
                }
                return false;
            }
         
         
        }
     
    
     
  2. Offline

    CubixCoders

    Use an AsyncRepeatingTask and check what players are within the radius.
     
  3. Offline

    Live2Pwn

    Please forgive me, I am still a noob with plugins and java but could I get some code please?
     
  4. Offline

    ZeusAllMighty11

    Also, you are making it harder on your server with move event. Since it triggers literally whenever the mouse is touched, you should only check when their X Y and Z change. (not yaw and pitch)
    Use e.getTo() and e.getFrom()
     
  5. Offline

    Sagacious_Zed Bukkit Docs

    You should never call Bukkit API methods from an AsyncTask
     
  6. Offline

    H2NCH2COOH

    There are thread-safe methods in Bukkit API
     
  7. Offline

    Sagacious_Zed Bukkit Docs

    If you know enough that some are thread-safe, you probably won't get yourself into trouble.
     
  8. Offline

    Live2Pwn

    ...So does anybody have some code I could use to add to a variable every few seconds?
     
  9. Offline

    H2NCH2COOH

    Nice point

    PLUS: thread safety is kind of killing me.
     
Thread Status:
Not open for further replies.

Share This Page