Only mayors can build

Discussion in 'Plugin Development' started by xXMaTTHDXx, Aug 12, 2014.

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

    xXMaTTHDXx

    Code:java
    1. @EventHandler
    2. public void onBlockBreak(BlockBreakEvent e){
    3. Block b = e.getBlock();
    4. Player p = e.getPlayer();
    5.  
    6. Chunk currentChunk = p.getWorld().getChunkAt(b);
    7.  
    8.  
    9.  
    10. for(String s : plugin.getTowns().getKeys(false)){
    11. List<String> residents = plugin.getConfig().getStringList(s + ".Residents");
    12. List<String> citizens = plugin.getConfig().getStringList(s + ".Citizens");
    13.  
    14.  
    15.  
    16. if(plugin.getTowns().getStringList(s + ".chunks").contains(String.format("%s, %s", currentChunk.getX(), currentChunk.getZ()))){
    17. if(!plugin.getTowns().getStringList(s + ".mayors").contains(p.getUniqueId().toString()) && !residents.contains(p.getUniqueId().toString()) && !citizens.contains(p.getUniqueId().toString())){
    18. e.setCancelled(true);
    19. return;
    20. }
    21. }
    22. }
    23. }
    24. }
    25.  

    This is supposed to allow all town members to build inside the town, while disabling building for people who do not belong to the town, but only the mayor can build, any idea?
     
  2. Offline

    mine-care

    Mabe you need block place not block break and why chunk stuff? Just if he is a major pet him build else cancel block place and break events
     
  3. Code:java
    1. if(!//Check is mayor)
    2. {
    3. if(!//Check is citizen)
    4. {
    5. e.setCancelled(true);
    6. }
    7. }
    8.  

    Give it a go.
     
Thread Status:
Not open for further replies.

Share This Page