I have two issues with my plugin!

Discussion in 'Plugin Development' started by HyKurtis, Aug 8, 2015.

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

    HyKurtis

    So this is a feature of my plugin for my factions server which allows you to click a certian slime block and be ascended 10 blocks into the air and then placed on a platform!

    My problem is I need it to only work if there is no blocks above the player at all and make it so that it won't replace other blocks (for example if someone clicks it next to water outside of a faction base it won't replace the water as it only replaces air.

    A very important issue that I really can't get my head around is how to stop them from doing this if they are in a world guard region!

    PLEASE HELP! Here is the code, can you please give examples of how to do it so i can understand.
    Thanks



    Code:
        @EventHandler
        public void onPlayerClickOne(PlayerInteractEvent event) {
            Player player = event.getPlayer();
            if(player.getInventory().getItemInHand().getType() == Material.SLIME_BALL){
                if(event.getPlayer().getInventory().getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("§aBouncy Ball")) {
                    World world = player.getLocation().getWorld();
                    int x = player.getLocation().getBlockX();
                    int y = player.getLocation().getBlockY();
                    int z = player.getLocation().getBlockZ();
                    float pitch = player.getLocation().getPitch();
                    float yaw = player.getLocation().getYaw();
                    int newy = (int) y + (int) 10;
                    int blocky = (int) y + (int) 9;
                    Location location = new Location(world, (float) x + 0.5, (int) newy, (float) z + 0.5);
                    location.setYaw(yaw);
                    location.setPitch(pitch);
                    Location middle = new Location(world, x, blocky, z);
                    Location right = new Location(world, x - 1, blocky, z);
                    Location left = new Location(world, x + 1, blocky, z);
                    Location front = new Location(world, x, blocky, z - 1);
                    Location back = new Location(world, x, blocky, z + 1);
                    player.teleport(location);
                    middle.getBlock().setType(Material.GLASS);
                    right.getBlock().setType(Material.GLASS);
                    left.getBlock().setType(Material.GLASS);
                    front.getBlock().setType(Material.GLASS);
                    back.getBlock().setType(Material.GLASS);
                    player.getInventory().removeItem(player.getInventory().getItemInHand());
                    player.sendMessage("§2You've ascended 10 blocks from using the §aBouncy Ball§2.");
                }
            }else {
                return;
            }
        }
     
  2. Offline

    mythbusterma

    @HyKurtis

    You would have to somehow check to see if they're in a region, and as far as I know, WorldGuard doesn't provide an API.


    Another way to go about it would be to call a BlockBreakEvent yourself and see if it gets cancelled, although some people recommend against this. This would make it so that it works with any protection system.
     
  3. Offline

    Boomer

  4. Offline

    HyKurtis

    I was able to fix this issue by using the world guard API and simply writeing if(wg.canBuild(player, event.getClickedBlock()) {

    all i need to know now is how to check if there is a block above a player AT ALL whether it is 100 blocks above them or 2. This is to stop people from going under bases and being teleported in. Thanks
     
  5. Offline

    Boomer

    The block .getLightFromSky() function can be used to determine its columnar exposure to 'sunlight' similar to ice formation conditions (the higher the value, the more directly exposed it is, even at night) .. the highest value means there are no blocks in the column above it - if it was water in an ice biome, it would freeze; water in ice biomes doesn't freeze if there is a single block of anything even 100 blocks higher...

    If there is a block above it, then you'd have to iterate through the Y coordinates until finding a non-air block to see what it is and at what level it is, starting at the player head level.
     
  6. Offline

    HyKurtis

    How does that work? I know that world edit does it in there //up command but i don't know how. First i tried something but it spammed error messages until the server crashed. Is there not a way to like find out whether Y coordinate from their location to 256 is air otherwise cancel the event?
     
  7. Offline

    Boomer

    yes - I| said there is a way to check for where-i-am to top-sky, the same way that water knows if it can freeze or not in an ice biome - the entire column must be air above it, and that only happens by measuring the light-from-sky value. at maximum value, that means there is nothing to diminish the light in the column, and it is exposed to air all above. But as for identifying what the block is in the column, if there IS one, requires iterating through the entire set of y-values above the players head. If you just want "Is there only only only only air all the way to sky above this point" the answer is "lightfromsky method gives you that ability to determine it"
     
  8. Offline

    SuperOriginal

    You can use World#getHighestBlockAt(playerLoc) to determine if there is a block above.
     
Thread Status:
Not open for further replies.

Share This Page