Search in sources :

Example 36 with Region

use of br.net.fabiozumbi12.RedProtect.Sponge.Region in project RedProtect by FabioZumbi12.

the class RPPlayerListener method PlayerTrownArrow.

@EventHandler
public void PlayerTrownArrow(ProjectileLaunchEvent e) {
    if (!(e.getEntity().getShooter() instanceof Player)) {
        return;
    }
    RedProtect.get().logger.debug("Is ProjectileLaunchEvent event.");
    Location l = e.getEntity().getLocation();
    Player p = (Player) e.getEntity().getShooter();
    Region r = RedProtect.get().rm.getTopRegion(l);
    if (r != null && !r.canProtectiles(p)) {
        e.setCancelled(true);
        RPLang.sendMessage(p, "playerlistener.region.cantuse");
    }
}
Also used : Player(org.bukkit.entity.Player) PvPlayer(me.NoChance.PvPManager.PvPlayer) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 37 with Region

use of br.net.fabiozumbi12.RedProtect.Sponge.Region in project RedProtect by FabioZumbi12.

the class RPPlayerListener method onPlayerInteract.

@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerInteract(PlayerInteractEntityEvent event) {
    Entity e = event.getRightClicked();
    Player p = event.getPlayer();
    if (e == null) {
        return;
    }
    RedProtect.get().logger.debug("RPPlayerListener - Is PlayerInteractEntityEvent event: " + e.getType().name());
    Location l = e.getLocation();
    if (e instanceof ItemFrame || e instanceof Painting) {
        Region r = RedProtect.get().rm.getTopRegion(l);
        if (r != null && !r.canBuild(p)) {
            RPLang.sendMessage(p, "playerlistener.region.cantedit");
            event.setCancelled(true);
        }
    } else if ((e instanceof Minecart || e instanceof Boat)) {
        Region r = RedProtect.get().rm.getTopRegion(l);
        if (r != null && !r.canMinecart(p)) {
            RPLang.sendMessage(p, "blocklistener.region.cantenter");
            event.setCancelled(true);
        }
    } else if (RedProtect.get().MyPet && e instanceof MyPetBukkitEntity) {
        if (((MyPetBukkitEntity) e).getOwner().getPlayer().equals(p)) {
        }
    } else if (!RPUtil.isBukkitEntity(e) && (!(event.getRightClicked() instanceof Player))) {
        Region r = RedProtect.get().rm.getTopRegion(l);
        if (r != null && !r.allowMod(p)) {
            RedProtect.get().logger.debug("PlayerInteractEntityEvent - Block is " + event.getRightClicked().getType().name());
            RPLang.sendMessage(p, "playerlistener.region.cantinteract");
            event.setCancelled(true);
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) MyPetBukkitEntity(de.Keyle.MyPet.api.entity.MyPetBukkitEntity) Player(org.bukkit.entity.Player) PvPlayer(me.NoChance.PvPManager.PvPlayer) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) Minecart(org.bukkit.entity.Minecart) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) ItemFrame(org.bukkit.entity.ItemFrame) MyPetBukkitEntity(de.Keyle.MyPet.api.entity.MyPetBukkitEntity) Location(org.bukkit.Location) Painting(org.bukkit.entity.Painting) Boat(org.bukkit.entity.Boat) EventHandler(org.bukkit.event.EventHandler)

Example 38 with Region

use of br.net.fabiozumbi12.RedProtect.Sponge.Region in project RedProtect by FabioZumbi12.

the class RPPlayerListener method onEntityDamageEvent.

@EventHandler
public void onEntityDamageEvent(EntityDamageEvent e) {
    if (!(e.getEntity() instanceof Player)) {
        return;
    }
    Player play = (Player) e.getEntity();
    if (RedProtect.get().tpWait.contains(play.getName())) {
        RedProtect.get().tpWait.remove(play.getName());
        RPLang.sendMessage((Player) e.getEntity(), RPLang.get("cmdmanager.region.tpcancelled"));
    }
    // deny damagecauses
    List<String> Causes = RPConfig.getStringList("server-protection.deny-playerdeath-by");
    if (Causes.size() > 0) {
        for (String cause : Causes) {
            cause = cause.toUpperCase();
            try {
                if (e.getCause().equals(DamageCause.valueOf(cause))) {
                    e.setCancelled(true);
                }
            } catch (IllegalArgumentException ex) {
                RedProtect.get().logger.severe("The config 'deny-playerdeath-by' have an unknow damage cause type. Change to a valid damage cause type.");
            }
        }
    }
    Region r = RedProtect.get().rm.getTopRegion(play.getLocation());
    if (r != null) {
        if (!r.canPlayerDamage()) {
            e.setCancelled(true);
        }
        // execute on health
        if (r.cmdOnHealth(play)) {
            RedProtect.get().logger.debug("Cmd on healt: true");
        }
        if (!r.canDeath() && play.getHealth() <= 1) {
            e.setCancelled(true);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) PvPlayer(me.NoChance.PvPManager.PvPlayer) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) EventHandler(org.bukkit.event.EventHandler)

Example 39 with Region

use of br.net.fabiozumbi12.RedProtect.Sponge.Region in project RedProtect by FabioZumbi12.

the class RPPlayerListener method PlayerDropItem.

@EventHandler
public void PlayerDropItem(PlayerDropItemEvent e) {
    RedProtect.get().logger.debug("Is PlayerDropItemEvent event.");
    Location l = e.getItemDrop().getLocation();
    Player p = e.getPlayer();
    Region r = RedProtect.get().rm.getTopRegion(l);
    if (r != null && !r.canDrop(p)) {
        e.setCancelled(true);
        RPLang.sendMessage(p, "playerlistener.region.cantdrop");
    }
}
Also used : Player(org.bukkit.entity.Player) PvPlayer(me.NoChance.PvPManager.PvPlayer) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 40 with Region

use of br.net.fabiozumbi12.RedProtect.Sponge.Region in project RedProtect by FabioZumbi12.

the class RPPlayerListener method onPlayerInteract.

@EventHandler(priority = EventPriority.LOW)
public void onPlayerInteract(PlayerInteractEvent event) {
    RedProtect.get().logger.debug("RPPlayerListener - PlayerInteractEvent canceled? " + event.isCancelled());
    final Player p = event.getPlayer();
    Block b = event.getClickedBlock();
    ItemStack itemInHand = event.getItem();
    Location l;
    if (RedProtect.get().tpWait.contains(p.getName())) {
        RedProtect.get().tpWait.remove(p.getName());
        RPLang.sendMessage(p, "cmdmanager.region.tpcancelled");
    }
    if (b != null) {
        l = b.getLocation();
        RedProtect.get().logger.debug("RPPlayerListener - Is PlayerInteractEvent event. The block is " + b.getType().name());
    } else {
        l = p.getLocation();
    }
    if (itemInHand != null && !itemInHand.getType().equals(Material.AIR)) {
        String claimmode = RPConfig.getWorldClaimType(p.getWorld().getName());
        if (itemInHand.getType().name().equalsIgnoreCase(RPConfig.getString("wands.adminWandID")) && ((claimmode.equalsIgnoreCase("WAND") || claimmode.equalsIgnoreCase("BOTH")) || p.hasPermission("redprotect.admin.claim"))) {
            if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK) || event.getAction().equals(Action.RIGHT_CLICK_AIR)) {
                if (!RPUtil.canBuildNear(p, l)) {
                    event.setCancelled(true);
                    return;
                }
                RedProtect.get().secondLocationSelections.put(p, l);
                p.sendMessage(RPLang.get("playerlistener.wand2") + RPLang.get("general.color") + " (" + ChatColor.GOLD + l.getBlockX() + RPLang.get("general.color") + ", " + ChatColor.GOLD + l.getBlockY() + RPLang.get("general.color") + ", " + ChatColor.GOLD + l.getBlockZ() + RPLang.get("general.color") + ").");
                event.setCancelled(true);
            } else if (event.getAction().equals(Action.LEFT_CLICK_BLOCK) || event.getAction().equals(Action.LEFT_CLICK_AIR)) {
                if (!RPUtil.canBuildNear(p, l)) {
                    event.setCancelled(true);
                    return;
                }
                RedProtect.get().firstLocationSelections.put(p, l);
                p.sendMessage(RPLang.get("playerlistener.wand1") + RPLang.get("general.color") + " (" + ChatColor.GOLD + l.getBlockX() + RPLang.get("general.color") + ", " + ChatColor.GOLD + l.getBlockY() + RPLang.get("general.color") + ", " + ChatColor.GOLD + l.getBlockZ() + RPLang.get("general.color") + ").");
                event.setCancelled(true);
            }
            // show preview border
            if (RedProtect.get().firstLocationSelections.containsKey(p) && RedProtect.get().secondLocationSelections.containsKey(p)) {
                Location loc1 = RedProtect.get().firstLocationSelections.get(p);
                Location loc2 = RedProtect.get().secondLocationSelections.get(p);
                if (loc1.getWorld().equals(loc2.getWorld()) && loc1.distanceSquared(loc2) > RPConfig.getInt("region-settings.define-max-distance") && !RedProtect.get().ph.hasPerm(p, "redprotect.bypass.define-max-distance")) {
                    Double dist = loc1.distanceSquared(loc2);
                    RPLang.sendMessage(p, String.format(RPLang.get("regionbuilder.selection.maxdefine"), RPConfig.getInt("region-settings.define-max-distance"), dist.intValue()));
                } else {
                    RPUtil.addBorder(p, RPUtil.get4Points(loc1, loc2, p.getLocation().getBlockY()));
                }
            }
            return;
        }
        if (itemInHand.getType().name().equalsIgnoreCase(RPConfig.getString("wands.infoWandID"))) {
            Region r = RedProtect.get().rm.getTopRegion(l);
            if (p.hasPermission("redprotect.infowand")) {
                if (r == null) {
                    RPLang.sendMessage(p, "playerlistener.noregion.atblock");
                } else if (r.canBuild(p)) {
                    p.sendMessage(RPLang.get("general.color") + "--------------- [" + ChatColor.GOLD + r.getName() + RPLang.get("general.color") + "] ---------------");
                    p.sendMessage(r.info());
                    p.sendMessage(RPLang.get("general.color") + "-----------------------------------------");
                } else {
                    p.sendMessage(RPLang.get("playerlistener.region.entered").replace("{region}", r.getName()).replace("{leaders}", r.getLeadersDesc()));
                }
                event.setCancelled(true);
                return;
            }
        }
    }
    if (event.isCancelled()) {
        return;
    }
    Region r = RedProtect.get().rm.getTopRegion(l);
    // start player checks
    if (r == null) {
        if (b != null && (b.getType().equals(Material.ANVIL) || b.getState() instanceof InventoryHolder || RPConfig.getStringList("private.allowed-blocks").contains(b.getType().name()))) {
            Boolean out = RPConfig.getBool("private.allow-outside");
            if (out && !cont.canOpen(b, p)) {
                RPLang.sendMessage(p, "playerlistener.region.cantopen");
                event.setCancelled(true);
            }
        }
    } else {
        // other blocks and interactions
        if (itemInHand != null && (event.getAction().name().equals("RIGHT_CLICK_BLOCK") || b == null)) {
            Material hand = itemInHand.getType();
            if (hand.equals(Material.ENDER_PEARL) && !r.canTeleport(p)) {
                RPLang.sendMessage(p, "playerlistener.region.cantuse");
                event.setCancelled(true);
                event.setUseItemInHand(Event.Result.DENY);
                return;
            } else if ((hand.equals(Material.BOW) || (hand.name().contains("SNOW") && hand.name().contains("BALL")) || hand.name().contains("FIREWORK") || hand.equals(Material.EGG)) && !r.canProtectiles(p)) {
                RPLang.sendMessage(p, "playerlistener.region.cantuse");
                event.setCancelled(true);
                event.setUseItemInHand(Event.Result.DENY);
                return;
            } else if (hand.equals(Material.POTION) && !r.usePotions(p)) {
                RPLang.sendMessage(p, "playerlistener.region.cantuse");
                event.setCancelled(true);
                event.setUseItemInHand(Event.Result.DENY);
                return;
            } else if (hand.name().contains("_EGG") && !r.canInteractPassives(p)) {
                RPLang.sendMessage(p, "playerlistener.region.cantuse");
                event.setCancelled(true);
                event.setUseItemInHand(Event.Result.DENY);
                return;
            }
        }
        // if (r != null) && (b != null) >>
        if (b != null) {
            if (b.getType().equals(Material.DRAGON_EGG) || b.getType().name().equalsIgnoreCase("BED") || b.getType().name().contains("NOTE_BLOCK") || b.getType().name().contains("CAKE")) {
                if (!r.canBuild(p)) {
                    RPLang.sendMessage(p, "playerlistener.region.cantinteract");
                    event.setCancelled(true);
                }
            } else if (b.getState() instanceof Sign && RPConfig.getBool("region-settings.enable-flag-sign")) {
                Sign s = (Sign) b.getState();
                String[] lines = s.getLines();
                if (lines[0].equalsIgnoreCase("[flag]") && r.flags.containsKey(lines[1])) {
                    String flag = lines[1];
                    if (!(r.flags.get(flag) instanceof Boolean)) {
                        RPLang.sendMessage(p, RPLang.get("playerlistener.region.sign.cantflag"));
                        return;
                    }
                    if (RedProtect.get().ph.hasPerm(p, "redprotect.flag." + flag)) {
                        if (r.isAdmin(p) || r.isLeader(p) || RedProtect.get().ph.hasPerm(p, "redprotect.admin.flag." + flag)) {
                            if (RPConfig.getBool("flags-configuration.change-flag-delay.enable")) {
                                if (RPConfig.getStringList("flags-configuration.change-flag-delay.flags").contains(flag)) {
                                    if (!RedProtect.get().changeWait.contains(r.getName() + flag)) {
                                        RPUtil.startFlagChanger(r.getName(), flag, p);
                                        changeFlag(r, flag, p, s);
                                        return;
                                    } else {
                                        RPLang.sendMessage(p, RPLang.get("gui.needwait.tochange").replace("{seconds}", RPConfig.getString("flags-configuration.change-flag-delay.seconds")));
                                        return;
                                    }
                                }
                            }
                            changeFlag(r, flag, p, s);
                            return;
                        }
                    }
                    RPLang.sendMessage(p, "cmdmanager.region.flag.nopermregion");
                }
            } else if (b.getType().equals(Material.ENDER_CHEST)) {
                if (!r.canEnderChest(p)) {
                    RPLang.sendMessage(p, "playerlistener.region.cantopen");
                    event.setCancelled(true);
                }
            } else if (!b.getType().equals(Material.ENDER_CHEST) && (b.getType().equals(Material.ANVIL) || b.getState() instanceof InventoryHolder || RPConfig.getStringList("private.allowed-blocks").contains(b.getType().name()))) {
                if ((r.canChest(p) && !cont.canOpen(b, p) || (!r.canChest(p) && cont.canOpen(b, p)) || (!r.canChest(p) && !cont.canOpen(b, p)))) {
                    RPLang.sendMessage(p, "playerlistener.region.cantopen");
                    event.setCancelled(true);
                }
            } else if (b.getType().name().contains("LEVER") || (b.getType().name().contains("REDSTONE") && !b.getType().equals(Material.REDSTONE_ORE))) {
                if (!r.canLever(p)) {
                    RPLang.sendMessage(p, "playerlistener.region.cantlever");
                    event.setCancelled(true);
                }
            } else if (b.getType().name().contains("BUTTON")) {
                if (!r.canButton(p)) {
                    RPLang.sendMessage(p, "playerlistener.region.cantbutton");
                    event.setCancelled(true);
                }
            } else if (RPDoor.isOpenable(b) && event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
                if (!r.canDoor(p)) /* || (r.canDoor(p) && !cont.canOpen(b, p))*/
                {
                    RPLang.sendMessage(p, "playerlistener.region.cantdoor");
                    event.setCancelled(true);
                } else {
                    RPDoor.ChangeDoor(b, r);
                }
            } else if (itemInHand != null && (itemInHand.getType().name().startsWith("BOAT") || itemInHand.getType().name().contains("MINECART"))) {
                if (!r.canMinecart(p)) {
                    RPLang.sendMessage(p, "blocklistener.region.cantplace");
                    event.setUseItemInHand(Event.Result.DENY);
                    event.setCancelled(true);
                }
            } else if ((event.getAction().equals(Action.LEFT_CLICK_BLOCK) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) && b.getType().name().contains("SIGN") && !r.canSign(p)) {
                Sign sign = (Sign) b.getState();
                for (String tag : RPConfig.getStringList("region-settings.allow-sign-interact-tags")) {
                    // check first rule
                    if (sign != null && tag.equalsIgnoreCase(sign.getLine(0))) {
                        return;
                    }
                    // check if tag is owners or members names
                    if (tag.equalsIgnoreCase("{membername}")) {
                        for (String leader : r.getLeaders()) {
                            if (sign.getLine(0).equalsIgnoreCase(RPUtil.UUIDtoPlayer(leader))) {
                                return;
                            }
                        }
                        for (String admin : r.getAdmins()) {
                            if (sign.getLine(0).equalsIgnoreCase(RPUtil.UUIDtoPlayer(admin))) {
                                return;
                            }
                        }
                        for (String member : r.getMembers()) {
                            if (sign.getLine(0).equalsIgnoreCase(RPUtil.UUIDtoPlayer(member))) {
                                return;
                            }
                        }
                    }
                    // check if tag is player name
                    if (tag.equalsIgnoreCase("{playername}")) {
                        if (sign.getLine(0).equalsIgnoreCase(RPUtil.UUIDtoPlayer(p.getName()))) {
                            return;
                        }
                    }
                }
                RPLang.sendMessage(p, "playerlistener.region.cantinteract.signs");
                event.setUseItemInHand(Event.Result.DENY);
                event.setCancelled(true);
            } else if ((itemInHand != null && !itemInHand.getType().equals(Material.AIR)) && !r.canBuild(p) && !r.canPlace(itemInHand.getType()) && (itemInHand.getType().equals(Material.FLINT_AND_STEEL) || itemInHand.getType().equals(Material.WATER_BUCKET) || itemInHand.getType().equals(Material.BUCKET) || itemInHand.getType().equals(Material.LAVA_BUCKET) || itemInHand.getType().equals(Material.ITEM_FRAME) || itemInHand.getType().equals(Material.PAINTING))) {
                RPLang.sendMessage(p, "playerlistener.region.cantuse");
                event.setCancelled(true);
                event.setUseItemInHand(Event.Result.DENY);
                event.setUseInteractedBlock(Event.Result.DENY);
            } else if (!r.allowMod(p) && !RPUtil.isBukkitBlock(b)) {
                RPLang.sendMessage(p, "playerlistener.region.cantinteract");
                event.setCancelled(true);
                event.setUseInteractedBlock(Event.Result.DENY);
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) PvPlayer(me.NoChance.PvPManager.PvPlayer) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) Block(org.bukkit.block.Block) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) Material(org.bukkit.Material) Sign(org.bukkit.block.Sign) ItemStack(org.bukkit.inventory.ItemStack) InventoryHolder(org.bukkit.inventory.InventoryHolder) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)113 EventHandler (org.bukkit.event.EventHandler)92 Player (org.bukkit.entity.Player)69 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)47 Listener (org.spongepowered.api.event.Listener)46 Location (org.bukkit.Location)43 World (org.spongepowered.api.world.World)30 Block (org.bukkit.block.Block)26 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)20 PvPlayer (me.NoChance.PvPManager.PvPlayer)20 Entity (org.bukkit.entity.Entity)20 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)19 Entity (org.spongepowered.api.entity.Entity)19 LivingEntity (org.bukkit.entity.LivingEntity)16 Player (org.spongepowered.api.entity.living.player.Player)16 World (org.bukkit.World)10 Monster (org.bukkit.entity.Monster)10 Material (org.bukkit.Material)9 ClanPlayer (net.sacredlabyrinth.phaed.simpleclans.ClanPlayer)8 OfflinePlayer (org.bukkit.OfflinePlayer)8