one player acts like two players? :O

Discussion in 'Plugin Development' started by Asgernohns, Aug 31, 2013.

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

    Asgernohns

    Hello all java programmers! :)

    When i use my new plugin called GodWand, it acts like two players.
    when i press rightclick i will get this message twice:
    Lightning mode
    Lightning mode

    or

    Fireball mode
    Fireball mode
    :/

    And if i fire the fireball it sends two! :O
    Can't figure out whats wrong :(

    Please help if you can :)

    here is the code for the plugin:
    Code:java
    1. package me.AsgerNohns.magicwand;
    2.  
    3. import java.util.HashMap;
    4. import java.util.Map;
    5. import java.util.logging.Logger;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Location;
    8. import org.bukkit.Server;
    9. import org.bukkit.World;
    10. import org.bukkit.block.Block;
    11. import org.bukkit.configuration.file.FileConfiguration;
    12. import org.bukkit.configuration.file.FileConfigurationOptions;
    13. import org.bukkit.entity.Fireball;
    14. import org.bukkit.entity.Player;
    15. import org.bukkit.event.EventHandler;
    16. import org.bukkit.event.Listener;
    17. import org.bukkit.event.block.Action;
    18. import org.bukkit.event.player.PlayerInteractEvent;
    19. import org.bukkit.inventory.ItemStack;
    20. import org.bukkit.plugin.PluginDescriptionFile;
    21. import org.bukkit.plugin.PluginManager;
    22. import org.bukkit.plugin.java.JavaPlugin;
    23.  
    24. public class magicwand extends JavaPlugin
    25. implements Listener
    26. {
    27. public final Logger Logger = Logger.getLogger("Minecraft");
    28. public static magicwand plugin;
    29. Map<String, Integer> wandmodes = new HashMap();
    30.  
    31. public void loadConfiguration()
    32. {
    33. FileConfiguration config = getConfig();
    34. config.addDefault("Explosion_power", Integer.valueOf(5));
    35. config.addDefault("Wand_range", Integer.valueOf(500));
    36. config.addDefault("Magic_wand_itemId", Integer.valueOf(369));
    37. getConfig().options().copyDefaults(true);
    38. saveConfig();
    39. }
    40.  
    41. public void onEnable() {
    42. loadConfiguration();
    43. PluginDescriptionFile pdfFile = getDescription();
    44. this.Logger.info(pdfFile.getName() + " v" + pdfFile.getVersion() + " Has Been Enabled!");
    45. getServer().getPluginManager().registerEvents(this, this);
    46. }
    47.  
    48. @EventHandler
    49. public void onPlayerInteract(PlayerInteractEvent e)
    50. {
    51. Player p = e.getPlayer();
    52. int wandmode = this.wandmodes.containsKey(p.getName()) ? ((Integer)this.wandmodes.get(p.getName())).intValue() : 1;
    53. if (p.getItemInHand().getTypeId() == getConfig().getInt("Magic_wand_itemId")) {
    54. if ((e.getAction() == Action.RIGHT_CLICK_AIR) || (e.getAction() == Action.RIGHT_CLICK_BLOCK)) {
    55. if (wandmode < 4) {
    56. if (wandmode == 1)
    57. p.sendMessage(ChatColor.GOLD + "Lightning mode");
    58. else if (wandmode == 2)
    59. p.sendMessage(ChatColor.GOLD + "Teleport mode");
    60. else if (wandmode == 3)
    61. p.sendMessage(ChatColor.GOLD + "Explosion mode");
    62. else if (wandmode == 0) {
    63. p.sendMessage(ChatColor.GOLD + "Fireball mode");
    64. }
    65.  
    66. wandmode++;
    67. }
    68. else if (wandmode == 4) {
    69. wandmode -= 4;
    70. }
    71. else {
    72. wandmode = 0;
    73. }
    74. this.wandmodes.put(p.getName(), Integer.valueOf(wandmode));
    75. }
    76. if ((e.getAction() == Action.LEFT_CLICK_AIR) || (e.getAction() == Action.LEFT_CLICK_BLOCK))
    77. if (wandmode == 1)
    78. {
    79. p.launchProjectile(Fireball.class);
    80. }
    81. else if (wandmode == 2)
    82. {
    83. Location loc = p.getTargetBlock(null, getConfig().getInt("Wand_range")).getLocation();
    84. p.getWorld().strikeLightning(loc);
    85. }
    86. else if (wandmode == 3)
    87. {
    88. Location loc = p.getTargetBlock(null, getConfig().getInt("Wand_range")).getLocation();
    89. p.teleport(loc);
    90. }
    91. else if (wandmode == 4)
    92. {
    93. Location loc = p.getTargetBlock(null, getConfig().getInt("Wand_range")).getLocation();
    94. p.getWorld().createExplosion(loc, getConfig().getInt("Explosion_power"));
    95. }
    96. }
    97. }
    98. }
     
  2. Offline

    Asgernohns

    CaptainBern i dont think it help me :(. and i don't like the copy and paste method, because i am not the creator of your code
     
  3. Online

    timtower Administrator Administrator Moderator

    Asgernohns I can try to fix it for you, just shifting some things around, will do in an hour or 1.5 if it is still needed
     
Thread Status:
Not open for further replies.

Share This Page