Claiming land based on claim power?

Discussion in 'Plugin Development' started by Chrusty45, Jul 25, 2014.

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

    Chrusty45

    So far in my plugin I have it so player's can use a feather to select point 1 and point 2. When players do /claim it creates a cuboid region dedicated to them. Right now I want to make a limit to the claiming based on their claim-power (cp). The player's CP is stored in a config file and it increases when the player kills and does the opposite when they die.

    Anyways, I'm currently stuck on limiting the size of cuboid they can claim based on their CP.

    This is what I have for /claim.
    Code:java
    1. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    2. Player player = (Player) sender;
    3.  
    4. if(!player.hasPermission("hh.claim")) {
    5. player.sendMessage(ChatColor.RED + "You don't have the permission to use this command.");
    6. } else {
    7. if(command.getLabel().equalsIgnoreCase("claim")) {
    8. Cuboid cuboid = new Cuboid(ClaimManager.l1, ClaimManager.l2);
    9. for(Block b : cuboid) {
    10. Methods.storedRegions.put(player.getName(), cuboid);
    11. }
    12. }
    13. }
    14. return false;
    15. }


    Listeners for the whole claiming process:
    Code:java
    1.  
    2. @EventHandler
    3. public void onBlockInteraction(PlayerInteractEvent event) {
    4. Player player = event.getPlayer();
    5. Block block = event.getClickedBlock();
    6.  
    7. if(block != null) {
    8. if(player.getItemInHand().getType() == Material.FEATHER) {
    9. Action action = event.getAction();
    10. if(!Methods.warzone.contains(player.getName())) {
    11. player.sendMessage(ChatColor.YELLOW + "You can't claim territory in the safezone!");
    12. } else {
    13. if(action == Action.LEFT_CLICK_BLOCK) {
    14. l1 = block.getLocation();
    15. player.sendMessage(ChatColor.AQUA + "Point a set.");
    16. event.setCancelled(true);
    17. } else if(action == Action.RIGHT_CLICK_BLOCK) {
    18. l2 = block.getLocation();
    19. player.sendMessage(ChatColor.AQUA + "Point b set.");
    20. event.setCancelled(true);
    21. }
    22. }
    23. }
    24. }
    25. }
    26.  
    27. @EventHandler
    28. public void onPlayerMove(PlayerMoveEvent event) {
    29. Player player = event.getPlayer();
    30. for(Cuboid region : Methods.storedRegions.values()) {
    31. if(region.contains(event.getTo()) && !region.contains(event.getFrom())) {
    32. if(Methods.storedRegions.containsKey(player.getName())) {
    33. player.sendMessage(ChatColor.YELLOW + "Entered your region.");
    34. } else {
    35. player.sendMessage(ChatColor.YELLOW + "Entered a claimed region.");
    36. }
    37. } else if(!region.contains(event.getTo()) && region.contains(event.getFrom())) {
    38. player.sendMessage(ChatColor.YELLOW + "Left the region.");
    39. }
    40. }
    41. }
    42.  
    43. @EventHandler
    44. public void onBlockBreak(BlockBreakEvent event) {
    45. Player player = event.getPlayer();
    46. Block block = event.getBlock();
    47. for(Cuboid region : Methods.storedRegions.values()) {
    48. if(region.contains(block) && !Methods.storedRegions.containsKey(player.getName())) {
    49. player.sendMessage(ChatColor.RED + "You can't break blocks in a claimed region!");
    50. event.setCancelled(true);
    51. }
    52. }
    53. }


    To make cuboids I use this code: https://forums.bukkit.org/threads/protection-region-cuboid-creation.164161/
     
  2. Offline

    _Filip

    What have you tried so far?
     
  3. Offline

    Chrusty45

    TheSpherret I haven't tried anything so far because I have no idea how I would do this.

    Bump :\

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

    fireblast709

    Chrusty45 store the locations, calculate the volume by width*height*depth
     
  5. Offline

    Chrusty45

    fireblast709 Alright, I got that idea now, but how can I check the claim power to make sure that they can claim that size? For example, if they have a claim power of 15 they can claim a size of 20. Any idea on how I can do that?
     
  6. Offline

    fireblast709

    Chrusty45 that is just a basic int comparison, isn't it?
     
  7. Offline

    Chrusty45

    fireblast709 Could you show me an example of what you mean?
     
  8. Offline

    fireblast709

    Chrusty45 we just arrived at the point where I suggest you to learn any programming language (preferably Java) because this is a very basic concept :3
     
  9. Offline

    Chrusty45

    fireblast709 I'm a truly offended by this. I have been coding Java since Christmas 2013, I know the language. I just don't understand what you mean by a "basic int comparision". I'll google it and see if I remember what that is. Anyways, it would be helpful if you put an example of the function here. Thanks.

    fireblast709 This just came to me, by "basic int comparision" you mean this? if(num < num2). If so it would've been helpful if you explained it a bit more so I would know.

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

    Dragonphase

    Chrusty45

    It's situations like these where people won't spoonfeed you. It's better to let the person solve their problems themselves by pointing them in the right direction, which is what fireblast709 has done.

    You could use cp^3 to determine the size of a cuboid a player can claim. One kill would be 1^3 which would be a maximum volume of 1. Two kills would be 2^3 which would be a maximum volume of 8.

    It would probably be better to do this based off of the 2D area of a cuboid than the volume, if you want to allow players to claim the entire Y axe.
     
  11. Offline

    Chrusty45

    Dragonphase I honestly didn't know what he meant by that. I wasn't trying to get him to spoonfeed me, I just didn't understand what he said and I wanted an example. :\

    Anyways, I'm going to test and try out your idea, thanks. :)
     
  12. Offline

    fireblast709

    Chrusty45 is the player's claim power greater or equal to the cuboid size? This should already tell you that this would require the >= operator. That is why I assumed you didn't know enough Java, since this should be pretty basic (in probably every language that exists).
     
Thread Status:
Not open for further replies.

Share This Page