Solved Bukkit not Recognizing Event

Discussion in 'Plugin Development' started by Philitup321, Mar 4, 2014.

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

    Philitup321

    Hello! I am trying to make a Hobbit Inspired Sword, where when a player moves , and a a Monster is within a certain radius, the sword will have a enchantment glow, as well as send them a message. But something doesn't appear to be working. I believe it the the detecting of the monsters, as atleast the message should send to the player, but I can't figure it out.

    Here is my code.
     
  2. Offline

    adam753

    "This is a private paste. If you created this paste, please login to view it."

    Please just paste your code here in [syntax=java][/syntax] tags. If you can't be bothered to do that, you'll find many people can't be bothered to help you.
     
  3. Offline

    Philitup321


    Wow, I feel like an idiot :p , Here is my code:
    Code:java
    1. @SuppressWarnings("deprecation")
    2. @EventHandler
    3. public void onPlayerMove(final PlayerMoveEvent e) {
    4. Player player = e.getPlayer();
    5. if (player.getName().equals("philitup321")){
    6. if (player.getName().equals("zombies24")){
    7.  
    8.  
    9. getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
    10. public void run() {
    11.  
    12. Player player = e.getPlayer();
    13. LivingEntity living = (LivingEntity) player;
    14. if(player.getNearbyEntities(10, 10, 10).equals(EntityType.SKELETON) ){
    15. if(player.getItemInHand().equals(Material.IRON_SWORD)) {
    16.  
    17. player.getInventory().setItemInHand(addGlow(player.getItemInHand()));
    18.  
    19. player.sendMessage(ChatColor.RED + " There are monsters nearby!!!");
    20. player.playSound(player.getLocation(), Sound.AMBIENCE_CAVE, 1, 1);
    21. }
    22. }
    23.  
    24.  
    25. }
    26.  
    27.  
    28.  
    29. }, 0, 1 * 20);
    30.  
    31. }
    32. }
    33. }



    I can't win -.-
     
  4. Offline

    adam753

    Why are you checking if the player's name is two different things?
     
  5. Offline

    Borlea

    You're checking if the player is philitup321 then if he is, you're checking if hes zombies24. which is impossible to be two names

    adam beat me :(
     
  6. Offline

    Alshain01

    What's with the repeating task? Your scheduling a new never-ending task in the most frequently called event in Bukkit. It's a wonder your server doesn't crash in the first few minutes.
     
  7. Offline

    fearless1333

    Are you trying to check if the player is named either philitup321 or zombies24?

    If so, you need to change your if statements to this:
    Code:java
    1.  
    2. if (player.getName().equals("philitup321") || player.getName().equals("zombies24")) {
    3.  


    Like others have said, currently the way you have it your plugin checks if the player has two different names.
     
  8. Offline

    Barinade

    "}, 0, 1 * 20);" 1*20 will always return 20, so why not just write 20?

    "LivingEntity living = (LivingEntity) player;" do you ever use this?

    "if(player.getItemInHand().equals(Material.IRON_SWORD)) {" this should be
    "if(player.getItemInHand().getType() == Material.IRON_SWORD) {"

    Done looking for now, fix those and post results
     
  9. Offline

    Philitup321

    adam753 Borlea fearless1333
    Yes, sorry, I should have made that more clear, I am checking for both those players. Silly mistake on those lines by me.

    Alshain01
    Forgot that the PlayerMoveEvent happens every time the player moves, so ya, I now see that the repeating task part is unnecessary.
     
  10. Offline

    fearless1333


    Is your code still not working after fixing that?
     
  11. Offline

    Philitup321

    fearless1333 Barinade
    This is what I have, and it still is not sending me any of the sounds, messages, etc.

    Code:java
    1. @EventHandler
    2. public void onPlayerMove(PlayerMoveEvent e) {
    3. Player player = e.getPlayer();
    4. if (player.getName().equals("philitup321") || player.getName().equals("zombies24")) {
    5. if(player.getNearbyEntities(10, 10, 10).equals(EntityType.SKELETON) ){
    6. if(player.getItemInHand().getType() == Material.IRON_SWORD) {
    7. player.getInventory().setItemInHand(addGlow(player.getItemInHand()));
    8. player.sendMessage(ChatColor.RED + " There are monsters nearby!!!");
    9. player.playSound(player.getLocation(), Sound.AMBIENCE_CAVE, 1, 1);
    10. }
    11. }
    12. }
    13. }
     
  12. Offline

    fearless1333

    Try changing this

    Code:Java
    1.  
    2. if(player.getNearbyEntities(10, 10, 10).equals(EntityType.SKELETON) ){
    3.  


    to this

    Code:java
    1.  
    2. boolean skeleFound = false;
    3. for (Entity entity : player.getNearbyEntities(10, 10, 10)) {
    4. if (entity.getType() == EntityType.Skeleton) {
    5. skeleFound = true;
    6. break;
    7. }
    8. }
    9. if (!skeleFound) {
    10. return;
    11. }
    12.  
     
  13. Offline

    Philitup321

Thread Status:
Not open for further replies.

Share This Page