Breaking Blocks Error

Discussion in 'Plugin Development' started by AlexHH251997, Aug 15, 2013.

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

    AlexHH251997

    Hey guys,

    I am trying to make a plugin that allows you to break, leaves and brown/red mushrooms but with the current code you can not break anything and I would like to know why this is happening. I have tried many things and have still not came out successful, this is the current code:
    Code:java
    1. public void onBlockBreak(BlockBreakEvent e){
    2. Player p = e.getPlayer();
    3. Material m = e.getBlock().getType();
    4. if(Main.inGamePlayers.containsKey(p)){
    5. if(m != Material.LONG_GRASS || m != Material.BROWN_MUSHROOM || m != Material.RED_MUSHROOM || m != Material.LEAVES){
    6. e.setCancelled(false);
    7. }
    8. }else{
    9. e.setCancelled(true);
    10. }
    11. }

    If you have a solution or idea's please let me know.

    Regards, Alex
     
  2. Offline

    Loogeh

    AlexHH251997 You have a } just above the else statement, try removing it and putting it under e.setCancelled(true);
     
  3. Offline

    AlexHH251997

    Loogeh that connects to "if(Main.inGamePlayers.containsKey(p)){" so you can not remove it.

    Regards, Alex
     
  4. Offline

    Arche

    What is the check on line 4 supposed to do? Because it likely evaluates to false each time.
     
  5. Offline

    Loogeh

    AlexHH251997 Can I see where you add people to that map? By the looks of it it's cancelling everything because that doesn't contain you.

    EDIT: What type of data is stored in the key of the map? You're testing for a player object but you should really be storing the player's name as a string to avoid memory leaks.
     
  6. Offline

    AlexHH251997

    It checks that in the Main.java all of the InGamePlayers are actually players (p) not entities.
    By this you mean teleporting people to the map?

    Regards, Alex
     
  7. Offline

    Loogeh

    AlexHH251997 why do you need to test if they're players? Doing Bukkit.getOnlinePlayers() returns an array of the online players.
     
  8. Offline

    AlexHH251997

    It is the way I have been doing it for a while and its the way I have done it now. I did not think to use Bukkit.getOnlinePlayers() but I may do in the future.

    Regards, Alex
     
Thread Status:
Not open for further replies.

Share This Page