Solved Code executing twice

Discussion in 'Plugin Development' started by MinecraftMart, Jun 21, 2014.

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

    MinecraftMart

    I have this code:
    Code:java
    1. if(p.getInventory().getItemInHand().getItemMeta().getDisplayName().contains("Speed Wand")){
    2. if(wizardry.players.contains("class.spellcaster." + p.getName())){
    3. p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 10*20, 0));
    4. p.getWorld().playSound(p.getLocation(), Sound.LEVEL_UP, 1, 1);
    5. int oldNumber = wizardry.getLevelCustomConfig().getInt("player." + p.getName() + ".xp");
    6. int newNumber = oldNumber + 15;
    7. wizardry.level.set("player." + p.getName() + ".xp", newNumber);
    8. wizardry.saveLevelCustomConfig();
    9. }
    10. else{
    11. p.sendMessage("You are not a Spell Caster!");
    12. }
    13. }


    But instead of adding 15 it adds 30 to the config file
     
  2. Offline

    Drew1080

    MinecraftMart
    Is the value in the config file already 15? Is so your just adding 15 to that number which makes it thirty.
     
  3. Offline

    MinecraftMart

    Drew1080

    No it starts of at 0, then it becomes 30, then it becomes 60
     
  4. Offline

    Gater12

  5. Offline

    xTigerRebornx

    MinecraftMart Can you paste the full code so that we may be able to tell what the cause is easier?
     
  6. Is it some event that could be triggered multiple times in a sec? --> just send a MSG to the player after the config and if you receice the mrssage twice then you have to work on the event listener - if not then well code looks fine so...
     
  7. Offline

    MinecraftMart

    Code:java
    1. @EventHandler
    2. public void onWandClick(PlayerInteractEvent e){
    3. final Player p = (Player) e.getPlayer();
    4. if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK){
    5. ItemStack hand = p.getItemInHand();
    6. if(hand != null && hand.hasItemMeta() && hand.getItemMeta().hasDisplayName()){
    7. if(p.getInventory().getItemInHand().getItemMeta().getDisplayName().contains("Speed Wand")){
    8. if(wizardry.players.contains("class.spellcaster." + p.getName())){
    9. p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 10*20, 0));
    10. p.getWorld().playSound(p.getLocation(), Sound.LEVEL_UP, 1, 1);
    11. int oldNumber = wizardry.getLevelCustomConfig().getInt("player." + p.getName() + ".xp");
    12. int newNumber = oldNumber + 15;
    13. wizardry.level.set("player." + p.getName() + ".xp", newNumber);
    14. wizardry.saveLevelCustomConfig();
    15. }


    Better?

    Heres the onEnable()
    Code:java
    1.  
    2. WandEvents wandevents = new WandEvents(this);
    3. @Override
    4. public void onEnable(){
    5. Bukkit.getLogger().info("Wizardry is enabled! Deb u suck!");
    6. PluginManager pm = getServer().getPluginManager();
    7. pm.registerEvents(wandevents, this);
    8. this.getCommand("join").setExecutor(new joincommand(this));
    9. this.getCommand("bind").setExecutor(new Bind(this));
    10. this.getCustomConfig();
    11. this.getLevelCustomConfig();
    12.  
    13.  
    14.  
    15. }


    EDIT: i think i was registering my events twice.... ill check it now

    EDIT2: yes i was indeed doing that.. Im such a smart man lol, well thx guyz!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page