Possible to protect air?

Discussion in 'Plugin Development' started by recon88, Sep 23, 2011.

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

    recon88

    Hi there,

    i have rewritten a protection plugin and i got a question:
    Is it possible to protect Air from pushing blocks inside (with pistons) in a protected area?

    e.g:
    Player 1 ownes Region 1
    Player 2 wanna push a block in Region 1 with a Piston or Sticky Piston
     
  2. Offline

    Jogy34

    You could either try to
    1. cancel the piston event if it is within X blocks of a region or
    2. extend the region out one more block than the farthest block out
     
  3. Offline

    recon88

    The first point sounds great. Maybe you or some1 else can give me a little example for this?
     
  4. Offline

    Jogy34

    I think you have to make a block or piston listener or something then check to see if the piston is activated within a certain amount of blocks around the region then if that is true it is something like
    Code:
    block.BlockPistonEvent.setCancelled(true);//replace "block" with the name of the variable that you have the piston set to
    
     
  5. Offline

    recon88

    This 2 i already got to pretend block moving in a protected area.
    But i can't get it where i have to to set the air protection now. Maybe i should take some coffee :D

    Code:
    //Piston Extend block
    public void onBlockPistonExtend(BlockPistonExtendEvent event) {
            //gather info on where the block was placed and who placed it
            Chunk piston_chunk = event.getBlock().getChunk();
            String piston_owner=plugin.RegionHandler.ClaimCheck(piston_chunk);
            List<Block> moved_blocks = event.getBlocks();
            for (Block block : moved_blocks) {
                if(piston_chunk.equals(block.getChunk())==false){
                    String target_owner =plugin.RegionHandler.ClaimCheck(block.getChunk());
                    if(target_owner!=""){
                        ConfigChunk conf_chunk = new ConfigChunk(new OwnedChunk(block.getChunk()));
                        if (conf_chunk.pitstone==1){
                            if(target_owner.equalsIgnoreCase(piston_owner)==false && plugin.FriendHandler.isafriend(piston_owner, target_owner,conf_chunk.access)==false){
                                event.setCancelled(true);
    
    //Piston retract block
        public void onBlockPistonRetract(BlockPistonRetractEvent event) {
            Chunk pistonblock = event.getBlock().getChunk();
            Chunk rett=event.getRetractLocation().getBlock().getChunk();
            if(event.isSticky()==true){
                if(pistonblock.equals(rett)==false){
                    String piston_owner =plugin.RegionHandler.ClaimCheck(pistonblock);
                    String target_owner =plugin.RegionHandler.ClaimCheck(rett);
                    if(target_owner!=""){
                        if (new ConfigChunk(new OwnedChunk(rett)).pitstone==1){
                            if(target_owner.equalsIgnoreCase(piston_owner)==false && plugin.FriendHandler.isafriend(piston_owner, target_owner)==false){
                                event.setCancelled(true);
    
    
     
  6. Offline

    Jogy34

    I don't know I've never actually worked with canceling pistons or with protecting areas sorry
     
  7. Offline

    MuisYa

    There is a plugin which protects worldguard areas from blocks being pushed in.
    If that is the thing you wanna make?
     
  8. Offline

    oyasunadev

    I would just increase the area by 1 (without protection), and then block only pistons from being placed in that special area, if it was not placed by the owner of the area.
     
  9. Offline

    MuisYa

    Maybe do it like this: Get the area around it (15 blocks)
    And if a player places a piston in it. Request which direction its heading to.
    If its heading to the protected area: event.setCancelled(true);
     
  10. Offline

    recon88

    Yea that's the thing i wana know.
    Just stucking at the code
     
  11. Offline

    MuisYa

    Well, on a block place you can listen for only pistons.
    Than get the location of it.
    You know how to do that?

    Here: this might be useful.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 19, 2016
  12. Offline

    recon88

    Would be useful if there would be a Source :/

    Not really
     
  13. Offline

    MuisYa

    Search Java Decompiler (google)
    It is illegal, but if you won't COPY it they cant get you.
     
  14. Offline

    sddddgjd

    Dude,get on skype...:|

    On-topic!
    You need to listen to the BLOCK_PLACE event!
    If you don't know how to do that,go watch some plugin developing tutorials!
     
  15. Offline

    recon88

    That really really helps.. Big thx
    [/irony off]
     
  16. What I should do is, block the event when the piston modifies the protected area. But when it happens and the piston is inside the protected area, you allow it.
     
  17. Offline

    sddddgjd

    What do you want me to do? Just give you the code? You don't even know the basic stuff... you could learn all the stuff you asked by watching tutorials,not just by coming here demanding code...
     
  18. Offline

    recon88

    I did not asked "YOU" for helping me to find help on youtube or something else.. That's the point.
    And i did not asked "YOU" for the code. I asked "others" for an example and i got some so why u r posting pointless things here?
    thx bb
     
  19. Offline

    sddddgjd

    /facepalm
    The original question of the thread (if it's possible to protect air) is perfectly normal,i don't have any problem with that...but then you said you don't know how to do a block listener,which is the most basic thing in bukkit plugin development...nobody will start to explain everything to you from scratch, believe me...

    And since you don't seem to have the IQ to go to youtube, this is how you do it:
    Code:
    PluginManager pm = getServer().getPluginManager();
    pm.registerEvent(Event.Type.BLOCK_PLACE, new blockListener(this),Priority.Normal, this);
    
    and in the blocklistener
    Code:
    public class blockListener extends BlockListener {
    public void onBlockPlace(BlockPlaceEvent event){
    Location loc=event.getLocation();
    if(loc is near the protected area){
    event.setCancelled(true);
    }
    
     
Thread Status:
Not open for further replies.

Share This Page