Basic guide on obsidianDestroy plugin

Discussion in 'Plugin Development' started by BeastCraft3, Dec 29, 2014.

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

    BeastCraft3

    Hello, I would basicly want a simple guide on how to create an obsidianDestroy plugin with config.
    Like the config is:
    TntHits: "1"
    CreeperHits: "5"

    Please help me, I'm stuck. I dont know where to begin or end.
     
  2. Offline

    Sm0oth_kriminal

    I haven't seen this plugin, can you provide a link?
     
  3. Offline

    BeastCraft3

    @Sm0oth_kriminal
    no I want to know how to make it. like ObsidianDestoryer but less complicated
     
  4. Offline

    InkzzzMC

    I suggest making a plugin request.
     
  5. Offline

    BeastCraft3

    @InkzzzMC
    no no no, I want to code it my self. I just need some help to start cause I dont know where to start.
     
  6. Offline

    woutwoot

    Start here
    You'll need "EntityExplodeEvent"
     
  7. Offline

    BeastCraft3

    @woutwoot
    Yeah, I've figured that out. I'm wondering how i check if the block is obsidian + how to check how many tnt hits it got.
     
  8. Offline

    Sm0oth_kriminal

    Tnt hits at once?
    I would suggest making it a total number of explosions.
    I have never used entityexplodeevent, but I assume you can get the x y and z, then look for all blocks (in a for loop) and you can test for a block there (I believe getBlock (x, y, z) but correct me if I am wrong) and have some shape you can define with a set of relative points defined by the shape. I believe that most of these plugins have source code available.
     
  9. Offline

    BeastCraft3

  10. Offline

    Totom3

    First of all you'll probably need the following to keep track of how much times the blocks were hit: Map<Location OR Block, Integer> --> the keys point to a certain block, and the values represent how much times it was hit.

    Secondly what's the problem with @Sm0oth_kriminal 's solution? Listen to EntityExplodeEvent, get the Location of the explosion and iterate over the nearby blocks. If their type (or Material) is obsidian, increment the value in the Map and if it goes over the limit which was set in the config, destroy them.
     
  11. Offline

    Skionz

    @BeastCraft3 Please don't copy ObsidianDestroyer and distribute it for free.
     
  12. Offline

    BeastCraft3

    @Totom3 @Sm0oth_kriminal
    sorry smooth, for some reason I couldn't didn't see your reply.
    And how do I make it so it will drop naturaly after 3 tnt hits? I just don't get it.
     
  13. Offline

    Skionz

  14. Offline

    BeastCraft3

    @Skionz
    e.dropNaturlly. I know that part but I'm wondering how to check if its hit 2 times? I can't figure it out..
     
  15. Offline

    Skionz

    @BeastCraft3 EntityExplodeEvent. Iterate through the blocks and save the hits in a Map.
     
    xTrollxDudex likes this.
  16. Offline

    BeastCraft3

    But how do I check if the Obsidian is hit???

    @Skionz
     
  17. Offline

    Skionz

    @BeastCraft3 Get the Block's type. Check if it is obsidian. Increment it's value in the Map.
     
    xTrollxDudex likes this.
  18. Offline

    Sm0oth_kriminal

    @BeastCraft3
    onentityexplodeevent, just locate your map, and test if the durability is greater than config option! (Sidenote: I would use a custom event for checking durability and dropping, just so no duplicate code when it comes to different types of explosions

    @BeastCraft3
    Are you working on this?

    @Skionz @BeastCraft3 @Totom3
    what you'll want is a HashMap<block, durability> and when it explodes, go to the map, set event.getBlock () (aka key) to durabilitymap.get (event.getblock()) + 1


    Now what I am not sure about is editing the specific x y and z coords to set all of the areas of the explosions durability
    @Skionz probably knows more java! Skionz how do you edit the x y independently ?
    (P.s. I am 13, so my knowledge and time are a little limited)
     
    Last edited by a moderator: Jan 8, 2015
  19. Offline

    Skionz

    He would have to iterate through the 'exploded' blocks with EntityExplodeEvent#blockList()
     
  20. Offline

    Sm0oth_kriminal

    @Skionz
    What makes up a var of type 'location' and could I alter them? Could I combine say e.getLocX() and pass that to 'location'? In the config, could you have a list of points in a matrix that are relative(offsets) to the centerpoint! (e.g. 0, 0, 0; 1, 0, 0; 0, 1, 0; 0, 0, 1; -1, 0, 0; 0, -1, 0; 0, 0, -1)?

    (would produce a 1 radius circle)

    And what I was talking about with the setting just X Y and Z coords is that by doing so, you could simply add the values from the matrix point list! So users an design their own 'exploded' obsidian range!
    Code:
    Location A = e.getBlockX(), e.getBlockX(), e.getBlockZ();
    /*Is there a way to do this? And I hear that Hashmaps take up a lot of ram, so we could store it as a List<String>, but I don't know all the 'Getting' method of List<>*/
    We could do a very cheap method of serialization!
    Code:
    String skey = e.getBlockX() + ", " +  e.getBlockY()  + ", " + e.getBlockZ();
    /*Our "nice" serialization*/
    HashMap<String, Int> durmap = new HashMap();
    /*creating our hashmap (empty)*/
    if (!(durmap.get(skey) == null)) {
    /*You'll see why*/
    /*todo for-loop*/
    for (x<= #POINTSINMATRIX#, x++) {
    Int matrixoffsetx = getConfig(args...);
    Int matrixoffsety = getConfig(args...);
    Int matrixoffsetz = getConfig(args...);/*not gonna do that right now, just getting offsets*/
    Int matrixx = e.getBlockX() + matrixoffsetx;
    Int matrixy = e.getBlockY() + matrixoffsety;
    Int matrixz = e.getBlockZ() + matrixoffsetz;
    /*taking offsets and applying them to each block instanec*/
    String mkey = matrixx + ", " + matrixy + ", " + matrixz;
    /*getting a serialized key with the finished points*/
    Int currentdur = (durmap.get(mkey);
    /*getting currentdurability*/
    Int afterdur = currentdur + 1;
    /*adding one*/
    durmap.put(mkey, afterdur);
    /*setting value*/
    }
    }
    else {
    durmap.put(skey, 0);
    }
    
    And this would be your checkdurability(String skey) (it is a custom event)
    Code:
    if (durmap.get(skey) >= getConfig("path.to.durability")){
    String<string> matrix = getConfig().getStringList("path.to.matrixlist");
    List<Integer> coordlist = Arrays.asList(matrix.split(",\\s*"));/*we need some just general string parse*/
    int xcoord = coordlist.get(0);
    int ycoord = coordlist.get(1);
    int zcoord = coordlist.get(2);
    /*just getting coords from our serialized list!*/
    Block blockinquestion = world.getBlockAt(xcoord, ycoord, zcoord);
    blockinquestion.setType(Material.AIR);
    }
    **DO NOT USE e.getLocX(), use e.getBlockX()**

    EDIT: You would have to iterate it through the matrix list, but you could make a matrix list from config to iterate through! such as...
    Code:
    List<String> matrix = getConfig().getStringList("path.to.matrixlist");
    int sizeoflist = matrix.size();
    /*you can use the size and the contents to drive the function of the for loop*/
    Would I need to parseInteger?

    I might get this done, might not! a lot of annoying things going on!
    Probably won't, BUT PLEASE TELL ME WHEN
    I have a class with no actual errors...
    here at pastie

    http://pastie.org/9823129

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 31, 2016
    Skionz likes this.
Thread Status:
Not open for further replies.

Share This Page