[Protection] Region/Cuboid creation

Discussion in 'Resources' started by KingFaris11, Jul 31, 2013.

Thread Status:
Not open for further replies.
  1. It's not something bad, it's because getTypeId and getId are depreciated because you should be using getType. Don't worry, ignore it.
     
  2. Offline

    desht

    The correct approach here (I will be doing this with my Cuboid class soon) is to deprecate that containsOnly(int) method, and add a new public boolean containsOnly(Material mat) method. Best to move away from working with block ID's and start using Material where it's easy to do so, like here.
     
    KingFaris11 likes this.
  3. Yeah, I was just trying to tell him his plugin will still work exactly the same if he does use the ID. :p I still prefer to use IDs as we have been using IDs since Bukkit started and so most server owners know the main block IDs by heart whereas the Material names such as FLINT_AND_STEEL are new to many server owners.
     
  4. Offline

    Plugers11

    So in our onDisable
    my hm : HashMap<String, Cuboid> hm
    Save :
    config.set("cuboids", hm);
    ?

    And on load;

    Cuboid cub = (Cuboid) config.get("path.to.cuboid");
     
  5. No:
    Code:
    for (Entry<String, Cuboid> hmEntry : hm.entrySet()) {
        config.set("Cuboids." + hmEntry.getKey(), hmEntry.serialize());
    }
    
    To load:
    Code:
    Cuboid cub = Cuboid.deserialize(config.getConfigurationSection("path.to.cuboid").getValues(false));
    UPDATED (Less methods but only necessary ones): https://gist.github.com/KingFaris10/4527fbaf8caa9fd7b800

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

    JBoss925

    Btw, if you're going to use Configuration Serializable, you're going to need to register the class.
    In my cuboid object I used it and my wiki gives a valid setup method here.
     
  7. I don't think it's necessary to be honest, or, I don't understand why it is needed. If you're just using deserialize() and serialize() methods, I've never required to use it. I only started using it for one plugin, never noticed a difference.
     
  8. Offline

    JBoss925

    Well, bukkit says to register it here.
     
  9. I wish it said why, does anyone know? :S I've been using it without registering and my plugins have been doing fine.
     
    JBoss925 likes this.
  10. Offline

    ChipDev

    WaitWut? I thought cuboid was in the bukkit API already :O
    can me make pull req.
     
  11. Offline

    Onlineids

    -_-
     
    KingFaris11 likes this.
  12. Offline

    ChipDev

    I have no idea why you gave me '-_-'
     
  13. Offline

    Onlineids

    ChipDev likes this.
  14. (facepalm) No... I don't think it needs to be in the Bukkit API. It's for developers to decide if they need it. Though... it could be of use as there's Vector and Location, so why not. Bukkit requires a lot of stuff to submit a PR so I'm not even bothered to look at their code.
     
  15. Offline

    EnchantedMiners

    KingFaris11 Onlineids ChipDev JBoss925 desht calebbfmv so i am tagging a bunch of people to see if one can give me the code to Check if a player have move into a region and to check if player is interacting inside the region so when they players enter the region it does something once not spamming like world guard does the greeding since PlayerMoveEvent check if player touch the mouse xD so could one of you help me out on this?
     
  16. Offline

    ChipDev

    Umm... Just use PlayerInteractEvent and use desht's code to test if they are in the region.
    Something weird... (open)

    desht = The shit ? :eek:
     
  17. Offline

    EnchantedMiners

    ChipDev yep ok lets say i have the Cuboid saved in a config file and i want to use Desht code how would i get the Cuboid to make the MyStoredRegions var from his code to work ?
     
  18. Offline

    JBoss925

    Well, I have a cuboid object with a method that checks if a player is in the cuboid. The link is here if you want it.

    Otherwise I'll walk you through it.

    1). Get 2 locations so we can create a cuboid region (we'll call them loc1 and loc2).

    2). Create six double variables, call them maxX, maxY, maxZ, minX, minY, and minZ

    3). Now, compare the two locations' coordinate values. For example:
    Code:java
    1. maxX = Math.max(loc1.getX(), loc2.getX());
    2. minX = Math.min(loc1.getX(), loc2.getX());

    and just do that for the y and z too.

    4). Now, just check where the player's coordinates are greater than the minX, less than the maxX, greater than the minY, less than the maxY, greater than the minZ, and less than the maxZ.

    That's how to figure out if a player is in a region.
     
  19. Offline

    EnchantedMiners

    JBoss925 ok so if i put that in the PlayerMoveEvent it will spam that shi* out of the players xD how do i do so it only send something once they are inside and then stop checking if the player is inside it ?
     
  20. Offline

    JBoss925

    Firstly, consider putting it in a runnable.

    Create an ArrayList<UUID> called playersInCuboid and then at the very beginning check if the player's uuid is in playersInCuboid, if so return.

    If not, execute the other code and add them to playersInCuboid.
     
  21. I stopped when I read:
     
  22. Offline

    EnchantedMiners

    JBoss925 ok got it thanks my friend is working on it so i am just looking info about it thanks,
    KingFaris11 there some people like me that are visual learners ;) learn faster if you show them what it is then i use to play a bit with the code so i remember it and so thanks any ways
     
    KingFaris11 likes this.
Thread Status:
Not open for further replies.

Share This Page