Duel Plugin Help

Discussion in 'Plugin Development' started by jthort, Nov 8, 2013.

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

    jthort

    Hey everyone i'm having trouble getting my plugin to work. You right click another player to send a duel request, if that other player right clicks you back, then you duel.

    I'm having trouble getting the messages together and to the right players. This is what I have:
    Code:java
    1. package me.Ian.Duel;
    2.  
    3.  
    4. import org.bukkit.block.Block;
    5. import org.bukkit.command.CommandSender;
    6. import org.bukkit.entity.Entity;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12.  
    13.  
    14. import org.bukkit.event.player.PlayerInteractEntityEvent;
    15.  
    16.  
    17.  
    18.  
    19. public class Duel extends JavaPlugin implements Listener {
    20.  
    21.  
    22.  
    23. public int test = 1;
    24.  
    25. public void onEnable(){
    26. getLogger().info("Curse-Blocker Has Been Enabled!");
    27. getServer().getPluginManager().registerEvents(this, this);
    28. }
    29.  
    30. public void onDisable(){
    31. getLogger().info("Curse-Blocker Has Been Disabled!");
    32. }
    33.  
    34. int play1 = 0;
    35. int play2 = 0;
    36.  
    37.  
    38. Player player;
    39. Entity entity;
    40.  
    41. @EventHandler
    42. public void onPlayerInteract(PlayerInteractEntityEvent event1){
    43. if (play1 == 0){
    44. player = event1.getPlayer();
    45. entity = event1.getRightClicked();
    46. if(entity instanceof Player == true){
    47.  
    48. Entity y = event1.getRightClicked();
    49.  
    50. if (play1 == 2){
    51. player.sendMessage("You're already dueling, wait for the countdown");
    52. play1 = 0;
    53. }
    54.  
    55. player.sendMessage("You sent " + y + " a duel request!");
    56. ((CommandSender) y).sendMessage("Player " + player + " Wants to duel you, right click " + y + " to accept");
    57. event1.isCancelled();
    58. play1 = 1;
    59.  
    60.  
    61.  
    62.  
    63. }else{
    64. player.sendMessage("You cant duel this");
    65.  
    66. if(entity instanceof Block == true){
    67.  
    68. }
    69. }
    70. }
    71. }
    72.  
    73.  
    74. @EventHandler
    75. public void onPlayerInteract1(PlayerInteractEntityEvent event2){
    76.  
    77. player = event2.getPlayer();
    78. entity = event2.getRightClicked();
    79. if(entity instanceof Player == true){
    80.  
    81. if (play1 == 2){
    82. player.sendMessage("You're already dueling this person, wait for the countdown");
    83. play1 = 0;
    84. }
    85. if (play1 == 1){
    86.  
    87. player.sendMessage(" you accepted his duel request!");
    88. ((CommandSender) entity).sendMessage("the player you requested to duel with accepted!");
    89. play1 = 2;
    90.  
    91.  
    92.  
    93.  
    94. }
    95. }
    96. }
    97. }
    98.  
    99.  


    It works sometimes, other times it will execute both event handlers on one right click. So for example you click that person to request a duel, it says you offered a duel, other player accepted. Even though he didn't accept yet.

    But sometimes it works perfectly, I need some help please (I'm still new to java so any help would be great) Thanks.
     
  2. This could have been a lot easier. Let me write it for you.
     
  3. Offline

    jthort

    I always make things more complicated then they are, thanks a lot. Also if you could tell me what I did wrong, that would be great.
     
  4. Offline

    Ytry

    Just a question why are you use the player interact event twice? What I think is happening is that since you are registering both of these events which are the same event it is messing things up. Also in your on enable and on disable you don't have to put
    When you register your events it will take care of it automatically, in the console atm you should actually see it saying your plugin has been enabled twice.

     
  5. Offline

    drtshock

    Uhm. I'd try learning some java before you start making a plugin like this. Start with basics like objects, when to initialize and instantiate objects, and how to do a boolean check. There are some good suggestions for tutorials on wiki.bukkit.org
     
  6. Offline

    jthort

    I used the player interaction event twice because I had to get the click event from both the entity and the player.

    I do know most of the basics, what I meant to say was new to plugin development. Although I do know a lot of techniques to code, I still tend to use noobish ways, for example if/else statements instead of something else. I started coding java around two months ago, then just came back to it recently for plugin development. But yeah, maybe a review of java would be a lot of help, thanks.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  7. Sure. Never use == true or == false. Just if(asssas) { This means if asssas is true or if(!asssas) { this means if it is false. Im almost done with the code
    1. if(entity instanceof Player == true){
    N
    Never use == true or == false after if.
     
  8. Offline

    jthort

    Is that the only problem with it, and thanks.
     
Thread Status:
Not open for further replies.

Share This Page