Solved Glass Barrier

Discussion in 'Plugin Development' started by shmkane, Sep 16, 2014.

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

    shmkane

    Hey, I'm trying to create a glass barrier plugin that won't allow people to enter a region. This plugin will form a glass wall in a pre determined spot. Here's what I have:


    PHP:
        @EventHandler
        
    public void onMove(PlayerMoveEvent e){
            
    Player p = (Player)e.getPlayer();//testing MoveEvent
            
    p.sendMessage("You're Moving");
            
    double spawnX 10;
            
    double spawnY 100;
            
    double spawnZ 10;
     
     
            
    double xcoord p.getLocation().getBlockX();
            
    double zcoord p.getLocation().getBlockZ();
     
            
    double distance Math.round(Math.sqrt(Math.pow(xcoord spawnX2) + Math.pow(zcoord -spawnZ 2)));//Get distance from me to the coords specified
            
    int x 10;
            while(
    distance 64 && 20){
                
    Location loc = new Location(p.getWorld(), spawnX xspawnYspawnZ);
                
    p.sendMessage("X: " x);//Just so I know ;)
                
    p.sendBlockChange(locMaterial.GLASS, (byte0);
                
    x++;
            }
        }
    This creates a small 1x high 'wall' that looks something like this.(Expanding it X high is simple)
    [​IMG]

    My question is, how would I make this so players cannot enderpearl through the glass, because currently they can.

    Edit: Enderpearls go straight through the glass, since it's a client based block.
    Update:
    Top: Actual glass.
    Bottom: Client side glass.
    [​IMG]

    Added a quick test to see what the enderpearl hits:
    PHP:
        @EventHandler
        
    public void checkPearl(ProjectileHitEvent e){
            if(
    e.getEntity() instanceof EnderPearl){
                
    Player p = (Player)e.getEntity().getShooter();
                
    Entity pearl e.getEntity();
                
    Location loc pearl.getLocation();
           
                
    Vector v pearl.getVelocity();
                
    Location loc2 = new Location(loc.getWorld(), loc.getX() + v.getX(), loc.getY() + v.getY(), loc.getZ() + v.getZ());
                
    Material check loc2.getBlock().getType();
                if(
    check == Material.GLASS){
                    
    p.sendMessage("It's glass.");
                }else{
                    
    p.sendMessage("Tis not glass");
                }
            }
        }


    When I throw the pearl at the top glass(real):
    [​IMG]

    When I throw it at the bottom one (client sided):
    [​IMG]
    ^Passes straight through and lands on the ocean floor below.
     
  2. Offline

    JordyPwner

    Check if the glass is there
    Check if player throws enderpearl enderpearl above or through the glass
    Cancel the teleport :)
     
  3. Offline

    shmkane

    Will this work since the glass is only client based, not server?
     
  4. Offline

    shmkane

    How exactly would you go about checking if it goes through the glass then? I was originally thinking check where the enderpearl LANDS, but the pearl travels through the glass.
     
  5. Offline

    JordyPwner

    check if enderpearl hits the glass...
     
  6. Offline

    shmkane

    I don't know how much more clear I can be. You cannot check if the enderpearl hits the glass, because it does not technically hit the glass. It simply passws through it. Here's an example.

    Top: Actual glass.
    Bottom: Client side glass.
    [​IMG]

    Added a quick test to see what the enderpearl hits:
    PHP:
        @EventHandler
        
    public void checkPearl(ProjectileHitEvent e){
            if(
    e.getEntity() instanceof EnderPearl){
                
    Player p = (Player)e.getEntity().getShooter();
                
    Entity pearl e.getEntity();
                
    Location loc pearl.getLocation();
             
                
    Vector v pearl.getVelocity();
                
    Location loc2 = new Location(loc.getWorld(), loc.getX() + v.getX(), loc.getY() + v.getY(), loc.getZ() + v.getZ());
                
    Material check loc2.getBlock().getType();
                if(
    check == Material.GLASS){
                    
    p.sendMessage("It's glass.");
                }else{
                    
    p.sendMessage("Tis not glass");
                }
            }
        }


    When I throw the pearl at the top glass(real):
    [​IMG]

    When I throw it at the bottom one (client sided):
    [​IMG]
    ^Passes straight through and lands on the ocean floor below.
    Could you show me how to code (or atleast give me an event)a way to test if an enderpearl passes through the glass, as you stated here.

     
  7. Offline

    JordyPwner

    Im not that smart :p I know things but not know code much. Sorry that i cant help you :/ maybe ask bwfcwalshy
     
  8. JordyPwner Thanks for just sending me in there :D
     
  9. Offline

    shmkane

    Well in his defence, you did say:

    So do you have any tips

    Would there be a way to show blocks to only one person?

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

    Jalau

    Simply store the Locations you send glass to a client in a array and test if the enderpearl is flying through one of the locations
     
  11. Offline

    shmkane

    Okay, I have aslightly buggy version if that kinda setup. How should I go about removing the blocks? Setting them to air? or is there just a way to update blocks in certain regions?
     
  12. Offline

    ChipDev

    Maybe every tick check if the ender pearl is in glass, if true, remove the entity
     
  13. Offline

    Jalau

    The blocks are client side....
     
    shmkane likes this.
  14. Offline

    fireblast709

    shmkane
    • ProjectileLaunchEvent -> schedule task
    • ProjectileHitEvent -> cancel task
    • task run() -> if enderpearl is in region, remove the enderpearl and cancel the task
     
  15. Offline

    shmkane

    Ah okay, makes sense now. One more thing, how would I remove the client sided blocks(set them to air? or somehow updating a region, or other)
     
  16. Offline

    fireblast709

    shmkane send them a block change with the old Material and data
     
  17. Offline

    shmkane

    Alright so, There's gotta be a more efficient way to make a wall of glass around specific points. Here's my current method, this causes lag to the server. Anyone help out?

    PHP:
        @EventHandler
        
    public void onMove(PlayerMoveEvent event){
            
    Player p event.getPlayer();
            
    Location loc1 = new Location(p.getWorld(), 1010010);
            
    Location loc2 = new Location(p.getWorld(), 1015029);
     
            
    Location loc3 = new Location(p.getWorld(), 1010010);
            
    Location loc4 = new Location(p.getWorld(), 2915010);
     
     
            
    Location loc5 = new Location(p.getWorld(), 2910010);
            
    Location loc6 = new Location(p.getWorld(), 2915029);
     
            
    Location loc7 = new Location(p.getWorld(), 1010029);
            
    Location loc8 = new Location(p.getWorld(), 2915029);
     
            
    wallAdd(loc1loc2loc3loc4loc5loc6loc7loc8p);
        }
        @
    SuppressWarnings("deprecation")
        public 
    void wallAdd(Location loc1Location loc2Location loc3Location loc4Location loc5Location loc6Location loc7Location loc8Player p){
            
    int topBlockX = (loc1.getBlockX() < loc2.getBlockX() ? loc2.getBlockX() : loc1.getBlockX());
            
    int bottomBlockX = (loc1.getBlockX() > loc2.getBlockX() ? loc2.getBlockX() : loc1.getBlockX());
     
            
    int topBlockY = (loc1.getBlockY() < loc2.getBlockY() ? loc2.getBlockY() : loc1.getBlockY());
            
    int bottomBlockY = (loc1.getBlockY() > loc2.getBlockY() ? loc2.getBlockY() : loc1.getBlockY());
     
            
    int topBlockZ = (loc1.getBlockZ() < loc2.getBlockZ() ? loc2.getBlockZ() : loc1.getBlockZ());
            
    int bottomBlockZ = (loc1.getBlockZ() > loc2.getBlockZ() ? loc2.getBlockZ() : loc1.getBlockZ());
     
            
    int topBlockX2 = (loc3.getBlockX() < loc4.getBlockX() ? loc4.getBlockX() : loc3.getBlockX());
            
    int bottomBlockX2 = (loc3.getBlockX() > loc4.getBlockX() ? loc4.getBlockX() : loc3.getBlockX());
     
            
    int topBlockY2 = (loc3.getBlockY() < loc4.getBlockY() ? loc4.getBlockY() : loc3.getBlockY());
            
    int bottomBlockY2 = (loc3.getBlockY() > loc4.getBlockY() ? loc4.getBlockY() : loc3.getBlockY());
     
            
    int topBlockZ2 = (loc3.getBlockZ() < loc4.getBlockZ() ? loc4.getBlockZ() : loc3.getBlockZ());
            
    int bottomBlockZ2 = (loc3.getBlockZ() > loc4.getBlockZ() ? loc4.getBlockZ() : loc3.getBlockZ());
     
            
    int topBlockX3 = (loc5.getBlockX() < loc6.getBlockX() ? loc6.getBlockX() : loc5.getBlockX());
            
    int bottomBlockX3 = (loc5.getBlockX() > loc6.getBlockX() ? loc6.getBlockX() : loc5.getBlockX());
     
            
    int topBlockY3 = (loc5.getBlockY() < loc6.getBlockY() ? loc6.getBlockY() : loc5.getBlockY());
            
    int bottomBlockY3 = (loc5.getBlockY() > loc6.getBlockY() ? loc6.getBlockY() : loc5.getBlockY());
     
            
    int topBlockZ3 = (loc5.getBlockZ() < loc6.getBlockZ() ? loc6.getBlockZ() : loc5.getBlockZ());
            
    int bottomBlockZ3 = (loc5.getBlockZ() > loc6.getBlockZ() ? loc6.getBlockZ() : loc5.getBlockZ());
     
            
    int topBlockX4 = (loc7.getBlockX() < loc8.getBlockX() ? loc8.getBlockX() : loc7.getBlockX());
            
    int bottomBlockX4 = (loc7.getBlockX() > loc8.getBlockX() ? loc8.getBlockX() : loc7.getBlockX());
     
            
    int topBlockY4 = (loc7.getBlockY() < loc8.getBlockY() ? loc8.getBlockY() : loc7.getBlockY());
            
    int bottomBlockY4 = (loc7.getBlockY() > loc8.getBlockY() ? loc8.getBlockY() : loc7.getBlockY());
     
            
    int topBlockZ4 = (loc7.getBlockZ() < loc8.getBlockZ() ? loc8.getBlockZ() : loc7.getBlockZ());
            
    int bottomBlockZ4 = (loc7.getBlockZ() > loc8.getBlockZ() ? loc8.getBlockZ() : loc7.getBlockZ());
     
            for(
    int x bottomBlockX<= topBlockXx++)
            {
                for(
    int z bottomBlockZ<= topBlockZz++)
                {
                    for(
    int y bottomBlockY<= topBlockYy++)
                    {
                        
    Location finalLoc = new Location(p.getWorld(), xyz);
                        
    p.sendBlockChange(finalLocMaterial.GLASS, (byte)0);
                    }
                }
            }
     
            for(
    int x bottomBlockX2<= topBlockX2x++)
            {
                for(
    int z bottomBlockZ2<= topBlockZ2z++)
                {
                    for(
    int y bottomBlockY2<= topBlockY2y++)
                    {
                        
    Location finalLoc = new Location(p.getWorld(), xyz);
                        
    p.sendBlockChange(finalLocMaterial.GLASS, (byte)0);
                    }
                }
            }
     
            for(
    int x bottomBlockX3<= topBlockX3x++)
            {
                for(
    int z bottomBlockZ3<= topBlockZ3z++)
                {
                    for(
    int y bottomBlockY3<= topBlockY3y++)
                    {
                        
    Location finalLoc = new Location(p.getWorld(), xyz);
                        
    p.sendBlockChange(finalLocMaterial.GLASS, (byte)0);
                    }
                }
            }
     
            for(
    int x bottomBlockX4<= topBlockX4x++)
            {
                for(
    int z bottomBlockZ4<= topBlockZ4z++)
                {
                    for(
    int y bottomBlockY4<= topBlockY4y++)
                    {
                        
    Location finalLoc = new Location(p.getWorld(), xyz);
                        
    p.sendBlockChange(finalLocMaterial.GLASS, (byte)0);
                    }
                }
            }
        }
    This works, but again, its laggy.
    Edit: It creates the exact shape to what I want([​IMG])
    Just lags the server ;)

    Might need to mention this: There's no console errors or errors in the code. All the commands take 5-10 seconds longer to work, except /tps for whatever reason, and /tps still shows 20 instantly.

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

    shmkane

  19. Offline

    MasterDoctor

    shmkane World Edit API?

    shmkane or checking on a specific command

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
    shmkane likes this.
  20. Offline

    shmkane

    Feel stupid for not thinking of this earlier xD

    The point for this is so that people don't walk into a specific area, so I need this "constantly" updating

    MasterDoctor
    I can set an area with whatever block I want, but how would I do the outline (//walls) of it?

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

    MasterDoctor

    Do the area, and subtract the blocks in the middle.

    Wait, Could you explain fully what you want to achieve? :)

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

    shmkane

    MasterDoctor
    I managed to figure everything out, thanks to everyone who contributed

    Here's my final code(needs some touching up :p)

    PHP:
    package me.shmkane.border;
    import java.util.HashMap;
    import java.util.Map;
     
    import org.bukkit.Chunk;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    import com.sk89q.worldedit.BlockVector;
    import com.sk89q.worldedit.Vector;
    import com.sk89q.worldguard.protection.flags.DefaultFlag;
    import com.sk89q.worldguard.protection.flags.StateFlag.State;
    import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
     
    public class 
    Main extends JavaPlugin implements Listener{
     
        public 
    Map<StringIntegertaskID = new HashMap<StringInteger>();
        
    FileConfiguration config;//might make a config later
     
        
    public void onEnable(){
            
    //register yo events
        
    }
     
        public 
    void scheduleRepeatingTask(final Player plong ticks){
            final 
    int tid getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
                @
    SuppressWarnings("deprecation")//p.sendBlockChange is deprecated
                
    public void run(){
                    
    taskID.put(p.getName(), taskID.get(p.getName()));
                    for(
    int x min.getBlockX();<= max.getBlockX(); x++){
                        for(
    int y min.getBlockY();<= max.getBlockY(); y++){
                            for(
    int z min.getBlockZ();<= max.getBlockZ(); z++){
                                if(
    == min.getBlockZ() || == min.getBlockX() || == max.getBlockX() || == max.getBlockZ()){//only the walls are formed, so not the entire region.(same as //walls on world edit)
                                        //p.send block change to that location                 
                                
    }
                            }
                        }
                    }
                }
            },
    ticksticks);//time..
            
    taskID.put(p.getName(), tid);
        }
     
     
        @
    EventHandler
        
    public void onMove(PlayerMoveEvent e){
                    if(!
    taskID.containsKey(p.getName())){
                        
    //call the task
                    
    }
            }
        }
    }
     
  23. Offline

    FabeGabeMC

  24. Offline

    shmkane

    I decided since either way the region I'm working with will be region'd with world guard, so I just added a no enderpearl flag to it(if you're referring to the ender pearl concept)
     
Thread Status:
Not open for further replies.

Share This Page