Trouble replacing destroyed block with original block

Discussion in 'Plugin Development' started by supersonicsauce, Feb 5, 2014.

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

    supersonicsauce

    Hey guys,
    I'm trying to fix this bug wherein a player breaks a wool block in an area, and the plugin is supposed to replace it if he doesn't have the required permission. Problem is, the plugin does what it's supposed to right up until its supposed to replace the block.
    Here's the code:
    (it's those last 3 lines or so, it DOES send the message "you cannot unclaim your own village" to the player, so I know that the code is actually getting that far).

    Code:java
    1. @EventHandler
    2. public void onBlockBreak(BlockBreakEvent event){
    3. Player player = (Player) event.getPlayer();
    4. if (player.isOp() != true){
    5. World world = Bukkit.getServer().getWorld("world");
    6. Location fishing1 = new Location(world, 280, 74, 959);
    7.  
    8. if (event.getBlock().getType()==Material.WOOL){
    9. if (player.getLocation().getWorld() == world && player.getLocation().distanceSquared(fishing1) <= 8){
    10.  
    11. if(player.hasPermission("claim.vikings")){
    12. String bc = "broadcast "+player.getName()+" has made fishing1 a neutral zone!";
    13. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), bc);
    14. String permadd = "mangaddp rebels claim.rebels.fishing1";
    15. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), permadd);
    16.  
    17. }
    18. else if(player.hasPermission("claim.empire")){
    19. String bc = "broadcast "+player.getName()+" has made fishing1 a neutral zone!";
    20. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), bc);
    21. String permadd = "mangaddp rebels claim.rebels.fishing1";
    22. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), permadd);
    23. }
    24. else if(player.hasPermission("claim.natives")){
    25. String bc = "broadcast "+player.getName()+" has made fishing1 a neutral zone!";
    26. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), bc);
    27. String permadd = "mangaddp rebels claim.rebels.fishing1";
    28. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), permadd);
    29. }else{
    30. player.sendMessage("You cannot unclaim your own village!");
    31. event.getBlock().setType(Material.WOOL);
    32.  
    33. }
    34.  
    35.  
    36.  
    37. }
    38. }
    39.  
    40. }
    41. }
     
  2. Offline

    mazentheamazin

    supersonicsauce
    1. Bukkit.broadcastMessage("message") (If you want to broadcast a message)
    2. I recommend using Vault if modifying permissions
    3. Are their any errors on console?
     
  3. Offline

    supersonicsauce


    No errors in the console, no. How do I use vault to edit permissions, and what difference does it make? And thanks for the broadcast tip.
     
  4. Offline

    mazentheamazin

    supersonicsauce
    1. You're welcome ;)
    2. I personally like vault since its easy when you want to switch permissions plugins. Don't have to hassle changing all the commands. Its like the universal permissions handler in this case.
    3. Syntax is broken when you edited the post
    4. Try doing this:
    Code:java
    1. event.getBlock().setTypeId(idofBlock);
     
  5. Offline

    xTrollxDudex

    mazentheamazin
    Material IDs will most likely be removed in the future, hence the deprecation, don't use them.
     
  6. Offline

    supersonicsauce

    Well, what should I use then?
     
  7. Offline

    mattrick

  8. Offline

    supersonicsauce

    Well that is what I've been using, the problem is that it doesn't reset the block back to wool once it's been broken :(
     
  9. Offline

    mattrick

  10. Offline

    Jugglernaught

    The block is wool in the first place though, right? So why can't you just do a event.set canceled(true)? That wouldn't allow them to break it and you could still send the message.
     
  11. Offline

    supersonicsauce

    Worked beautifully, thanks man!
     
Thread Status:
Not open for further replies.

Share This Page