Solved Protect some blocks...

Discussion in 'Plugin Development' started by vasil7112, Oct 9, 2013.

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

    vasil7112

    Dear Bukkit,
    I have created a plugin http://dev.bukkit.org/bukkit-plugins/portabletent , and i am trying to protect the blocks of the tents from breaking.
    I was thinking of checking for each block placed if it is inlucded in the config, and if it is, then cancel the break event. But then i realised, What if there are 50+ Tents? Would that lagg the server? So i'd like to ask if you have another way that i can protect the blocks:)

    Kind regards
     
  2. Offline

    Mathias Eklund

    Use worldguard or any other area protection plugin. perhaps implement it into your plugin.
     
  3. Offline

    vasil7112

    Hmm, i saw the worldguard api, but i can't find anything there about to create regions :/
     
  4. maybe:
    Get the location of the blocks,
    Assign them to the player whose tent is

    (BlockBreakEvent)
    check if the player who tries to break the blocks, contains the blocks of the location.
    if not, cancel the event, otherwise break it.

    Or maybe you can use WorldGuard regions.

    Regards, Greaperc4
     
  5. Offline

    vasil7112

    Hello there, sorry for late response! As i said, the first thing you suggested would cause a massive lag if the tents are many. It would have to process many locations. For example if each tent was 5x5x5, then it would have to scan 125 locations, per tent. If there were 100 tents, it would be 12500 locations! Which i believe would cause lagg ;P
    As for worldguard, i am trying to find how to make regions. This is how far i've come, but i can't yet make the region assigned!

    Code:java
    1. Location l1 = new Location(player.getWorld(), bloc.getBlockX(), bloc.getBlockY() - 1, bloc.getBlockZ());
    2. Location l2 = new Location(player.getWorld(), bloc.getBlockX() + y, bloc.getBlockY() + TentsConf.getCustomConfig().getConfigurationSection(Building+".Schema").getKeys(false).size(), bloc.getBlockZ() + x);
    3. player.sendMessage(l1 + " |||||| " + l2);
    4. ProtectedCuboidRegion pr = new ProtectedCuboidRegion(size+"_"+player.getName() , PortableTent.convertToSk89qBV(l1), PortableTent.convertToSk89qBV(l2));
    5. pr.setFlag(new StateFlag("build", false), State.DENY);

    The locations that are shown in the player.message are correct to create a Region for protection, The flags are good too i believe, but for some reason, worldguard doesn't add the new region to its config.
    Edit: I recieve no errors in the console or ingame if you are wondering:)
     
  6. Offline

    vasil7112

    I've been searching also a little bit of my own, and i found this PortableTent.worldguardPlugin.getRegionManager(player.getWorld()).addRegion(pr);
    I am not sure if it works, i am now trying it out, if it doesn't though, i will use yours. Thanks alot for the help!
     

  7. That should work, I think.
    Let me know if that worked,

    Regards, Greaperc4
     
  8. Offline

    vasil7112

    It didn't worked alone. It was working good, until i realised it didn't saved the config.
    So i just did
    Code:java
    1. PortableTent.worldguardPlugin.getRegionManager(player.getWorld()).addRegion(pr);
    2. PortableTent.worldguardPlugin.saveConfig();
    3. try {
    4. PortableTent.worldguardPlugin.getRegionManager(player.getWorld()).save();
    5. } catch (ProtectionDatabaseException e) {
    6. // TODO Auto-generated catch block
    7. e.printStackTrace();
    8. }

    And now it works <3
    Thanks alot:)
     
  9. Offline

    Goblom

    You also set custom data inside the blocks and listen on BlockBreakEvent then check if the block has the custom data and if so cancel the event.

    That would eliminate the use of worldguard and also require less plugin downloads in order to use your plugin.
     
  10. Offline

    vasil7112

    What do you mean inster custom data?
     
  11. Offline

    Goblom

    vasil7112 I do know it is possible to store data in blocks. So, maybe setMetaData(data, data);

    Not entirely sure how to do it because ive never tried it before
     
  12. Offline

    vasil7112

    Alright, thanks for letting me know
     
  13. Offline

    Fozie

    Just wanna help. You can use Block.setMetaData("protected",new FixedMetadata(1,this);
    then on the Event just do. If(Block.hasMetadata("protected") event.setCancelled(true);
    That will give you minimum lag. BUT remember that all MetaData resets after restart.
    So it is not perfect
     
  14. Offline

    vasil7112

    I've actually done it with metadata, but i didn't know that they werent saved on restart! Thats a problem i need to solve now :/
     
  15. Offline

    Fozie

    Yes, i haved the same problem when i made my Door locking plugin. But i solved it by makeing a ArrayList. But if you gonna protect many blocks it will maybe lagg a lot. :/ If you have a answer please post it here so everyone knows how to fix it
     
  16. Offline

    vasil7112

    Well, Probably what i will do is isntead of lagging while playing, i will make it load all the blocks on the plugin enable. So for example it might take some time to load, but atleast they won't require external plugins for protection. Still though, i will offer an option between WorldGuard Protection And MetaData
     
  17. Offline

    Goblom

    Add the blocks to a config or a sqlite db
     
  18. Offline

    vasil7112

    Well, i will stick with worldguard for now, and see how the users handle it. Later, i will also add the Metadata option(which will be saved on a config)
     
Thread Status:
Not open for further replies.

Share This Page