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 package me.Ian.Duel; import org.bukkit.block.Block;import org.bukkit.command.CommandSender;import org.bukkit.entity.Entity;import org.bukkit.entity.Player;import org.bukkit.event.Listener;import org.bukkit.event.EventHandler;import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.event.player.PlayerInteractEntityEvent; public class Duel extends JavaPlugin implements Listener { public int test = 1; public void onEnable(){ getLogger().info("Curse-Blocker Has Been Enabled!"); getServer().getPluginManager().registerEvents(this, this); } public void onDisable(){ getLogger().info("Curse-Blocker Has Been Disabled!"); } int play1 = 0;int play2 = 0; Player player; Entity entity; @EventHandler public void onPlayerInteract(PlayerInteractEntityEvent event1){ if (play1 == 0){ player = event1.getPlayer(); entity = event1.getRightClicked(); if(entity instanceof Player == true){ Entity y = event1.getRightClicked(); if (play1 == 2){ player.sendMessage("You're already dueling, wait for the countdown"); play1 = 0; } player.sendMessage("You sent " + y + " a duel request!"); ((CommandSender) y).sendMessage("Player " + player + " Wants to duel you, right click " + y + " to accept"); event1.isCancelled(); play1 = 1; }else{ player.sendMessage("You cant duel this"); if(entity instanceof Block == true){ } } } } @EventHandler public void onPlayerInteract1(PlayerInteractEntityEvent event2){ player = event2.getPlayer(); entity = event2.getRightClicked(); if(entity instanceof Player == true){ if (play1 == 2){ player.sendMessage("You're already dueling this person, wait for the countdown"); play1 = 0; } if (play1 == 1){ player.sendMessage(" you accepted his duel request!"); ((CommandSender) entity).sendMessage("the player you requested to duel with accepted!"); play1 = 2; } } } } 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.
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.
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.
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
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.
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 if(entity instanceof Player == true){ N Never use == true or == false after if.