Solved Check if Player can BUILD!!

Discussion in 'Plugin Development' started by mrZcr4fter, Dec 9, 2013.

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

    mrZcr4fter

    Hello! I need some help! I searched all over the internet! I want a way to check if a certain player can build in a certain area, WITHOUT him placing a block to check, if there was a way to place a block for him and check or something! HELP D: Please i'm so desperate! :(

    Come on GUYS! :(((

    Ok so, I want to place a block, based on BlockInteractEvent, but if there was towny on the server, it would bypass it's protection! I looked at towny java docs (API) but I don't understand how to do it! someone HELP! i'm a newbie to bukkit plugin making!

    Bump :(

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  2. erm, there is no way to disable building in certain regions with plain bukkit. you need to depend on other bukkit plugins
     
  3. Offline

    mrZcr4fter

    *facepalm* read the thread closely V_V I know that, I said i want to know if the player can build in a certain area, I basically want to make my plugin towny compatible!
     
  4. Offline

    SuperOmegaCow

    mrZcr4fter Louis1234567890987654321
    *facepalm* please read the Towny api again/ watch a youtube tutorial. If that is too complicated check if the event is cancelled by another plugin.
     
  5. Sorry
    Sorry I didn't read the post properly
     
  6. Offline

    SuperOmegaCow

    Louis1234567890987654321 I was talking to mrZ but a legit way to check is to see if the event is cancelled by another plugin.
     
  7. Offline

    mrZcr4fter

    if there was youtube tutorials i would've not came here.. and the API does not say how I would do this, also I don't think that towny cancels blockInteractEvent..

    How would I do that? SuperOmegaCow

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  8. Offline

    NathanWolf

    I'm not sure about Towny, I know WorldGuard has a very simple API you can call.

    That's the only one I've hooked into, personally, because they make it clean and easy. I tried to hook into Factions and got totally lost in the mess of it- not sure if it's the same with Towny or not.


    Which API are you looking at? This is not going to be in the Bukkit API, you should check the Towny docs (and ask this on their forum/comments/whatever, since this is help with a specific plugin and not with Bukkit in general). I'd think, anyway.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  9. Offline

    mrZcr4fter

    dangit towny! why so hard!
     
  10. Offline

    SuperOmegaCow

    Code:java
    1. @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
    2. public void onBlockPlace(BlockPlaceEvent event) {
    3.  
    4. if (plugin.isError()) {
    5. event.setCancelled(true);
    6. return;
    7. }
    8.  
    9. Player player = event.getPlayer();
    10. Block block = event.getBlock();
    11. WorldCoord worldCoord;
    12.  
    13. try {
    14. TownyWorld world = TownyUniverse.getDataSource().getWorld(block.getWorld().getName());
    15. worldCoord = new WorldCoord(world.getName(), Coord.parseCoord(block));
    16.  
    17. //Get build permissions (updates if none exist)
    18. boolean bBuild = PlayerCacheUtil.getCachePermission(player, block.getLocation(), block.getTypeId(), block.getData(), TownyPermission.ActionType.BUILD);
    19.  
    20. // Allow build if we are permitted
    21. if (bBuild)
    22. return;
    23.  
    24. /*
    25.   * Fetch the players cache
    26.   */
    27. PlayerCache cache = plugin.getCache(player);
    28. TownBlockStatus status = cache.getStatus();
    29.  
    30. /*
    31.   * Flag war
    32.   */
    33. if (((status == TownBlockStatus.ENEMY) && TownyWarConfig.isAllowingAttacks()) && (event.getBlock().getType() == TownyWarConfig.getFlagBaseMaterial())) {
    34.  
    35. try {
    36. if (TownyWar.callAttackCellEvent(plugin, player, block, worldCoord))
    37. return;
    38. } catch (TownyException e) {
    39. TownyMessaging.sendErrorMsg(player, e.getMessage());
    40. }
    41.  
    42. event.setBuild(false);
    43. event.setCancelled(true);
    44.  
    45. } else if (status == TownBlockStatus.WARZONE) {
    46. if (!TownyWarConfig.isEditableMaterialInWarZone(block.getType())) {
    47. event.setBuild(false);
    48. event.setCancelled(true);
    49. TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_warzone_cannot_edit_material"), "build", block.getType().toString().toLowerCase()));
    50. }
    51. return;
    52. } else {
    53. event.setBuild(false);
    54. event.setCancelled(true);
    55. }
    56.  
    57. /*
    58.   * display any error recorded for this plot
    59.   */
    60. if ((cache.hasBlockErrMsg()) && (event.isCancelled()))
    61. TownyMessaging.sendErrorMsg(player, cache.getBlockErrMsg());
    62.  
    63. } catch (NotRegisteredException e1) {
    64. TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_not_configured"));
    65. event.setCancelled(true);
    66. }
    67.  
    68. }

    Well actually they do
     
    NathanWolf likes this.
  11. Offline

    mrZcr4fter

    I did look at their API! so hard for newbie plugin makers!
     
  12. Offline

    Developing

    mrZcr4fter Thats why you shouldnt attempt to run when you just know how to walk. You should work on simplier plugins and take a step at a time instead of jumping straight to such advanced plugin developing.
     
  13. Offline

    NathanWolf

    I agree with the above, but also would like to point out that the API could be simpler. WG literally has like a "hasBuildPermission(Player, Location)" method- if everything were that simple (or, gasp, used a common API) this wouldn't require quite so much running.
     
    mrZcr4fter likes this.
  14. Offline

    mrZcr4fter

    im just that ambitious :3 Thanks @SuperaOmegaCow ! that seems like it would work!
     
  15. Offline

    MrInspector

    don't bump within 24 hours :)

    But make a BlockBreakEvent, and if(p.hasPermission("perm.perm");
     
  16. Offline

    mrZcr4fter

    I like shooting for the stars.. i seriously can work on 1 plugin as simple as sending messages for 2 days.. I like researching and making it as perfect as possible.

    nah I do not want it that way , i got my fix anyway, thanks!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
    NathanWolf likes this.
  17. Offline

    MrInspector

    Ah okay ;)

    Good luck. :D
     
    mrZcr4fter likes this.
Thread Status:
Not open for further replies.

Share This Page