Search in sources :

Example 6 with RPGlobalListener

use of br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPGlobalListener in project RedProtect by FabioZumbi12.

the class RPGlobalListener method onCreatureSpawn.

@EventHandler
public void onCreatureSpawn(CreatureSpawnEvent event) {
    RedProtect.get().logger.debug("RPGlobalListener - Is CreatureSpawnEvent event! Cancelled? " + event.isCancelled());
    if (event.isCancelled()) {
        return;
    }
    Entity e = event.getEntity();
    if (e == null) {
        return;
    }
    Location l = event.getLocation();
    Region r = RedProtect.get().rm.getTopRegion(l);
    if (r != null) {
        return;
    }
    if (e instanceof Wither && event.getSpawnReason().equals(SpawnReason.BUILD_WITHER) && !RPConfig.getGlobalFlagBool(e.getWorld().getName() + ".spawn-wither")) {
        event.setCancelled(true);
        return;
    }
    if (e instanceof Monster && !RPConfig.getGlobalFlagBool(e.getWorld().getName() + ".spawn-monsters")) {
        if (event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.NATURAL) || event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.SPAWNER) || event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.CHUNK_GEN) || event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.DEFAULT)) {
            event.setCancelled(true);
            return;
        }
    }
    if ((e instanceof Animals || e instanceof Villager || e instanceof Golem) && !RPConfig.getGlobalFlagBool(e.getWorld().getName() + ".spawn-passives")) {
        if (event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.NATURAL) || event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.SPAWNER) || event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.CHUNK_GEN) || event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.DEFAULT)) {
            event.setCancelled(true);
        }
    }
}
Also used : Wither(org.bukkit.entity.Wither) Golem(org.bukkit.entity.Golem) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Animals(org.bukkit.entity.Animals) Monster(org.bukkit.entity.Monster) Villager(org.bukkit.entity.Villager) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 7 with RPGlobalListener

use of br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPGlobalListener in project RedProtect by FabioZumbi12.

the class RPGlobalListener method onPlayerFrostWalk.

@EventHandler
public void onPlayerFrostWalk(EntityBlockFormEvent e) {
    Region r = RedProtect.get().rm.getTopRegion(e.getBlock().getLocation());
    if (r != null) {
        return;
    }
    RedProtect.get().logger.debug("RPGlobalListener - EntityBlockFormEvent canceled? " + e.isCancelled());
    if (e.getEntity() instanceof Player) {
        Player p = (Player) e.getEntity();
        if (!RPConfig.getGlobalFlagBool(p.getWorld().getName() + ".iceform-by.player") && !p.hasPermission("redprotect.bypass.world")) {
            e.setCancelled(true);
        }
    } else if (!RPConfig.getGlobalFlagBool(e.getEntity().getWorld().getName() + ".iceform-by.entity")) {
        e.setCancelled(true);
    }
}
Also used : Player(org.bukkit.entity.Player) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) EventHandler(org.bukkit.event.EventHandler)

Example 8 with RPGlobalListener

use of br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPGlobalListener in project RedProtect by FabioZumbi12.

the class RPGlobalListener method onPlayerInteract.

@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerInteract(PlayerInteractEvent e) {
    RedProtect.get().logger.debug("RPGlobalListener - Is PlayerInteractEvent event! Cancelled? " + e.isCancelled());
    if (e.isCancelled()) {
        return;
    }
    Player p = e.getPlayer();
    Block b = e.getClickedBlock();
    ItemStack itemInHand = e.getItem();
    Location l = null;
    if (b != null) {
        l = b.getLocation();
        RedProtect.get().logger.debug("RPGlobalListener - Is PlayerInteractEvent event. The block is " + b.getType().name());
    } else {
        l = p.getLocation();
    }
    if (b != null && b.getState() instanceof Sign) {
        Sign s = (Sign) b.getState();
        if (ChatColor.stripColor(s.getLine(1)).equals(ChatColor.stripColor(RPLang.get("_redprotect.prefix")))) {
            b.setType(Material.AIR);
            e.setUseInteractedBlock(Result.DENY);
            e.setUseItemInHand(Result.DENY);
            e.setCancelled(true);
            return;
        }
    }
    Region r = RedProtect.get().rm.getTopRegion(l);
    // deny item usage
    List<String> items = RPConfig.getGlobalFlagList(p.getWorld().getName() + ".deny-item-usage.items");
    if (e.getItem() != null && items.contains(e.getItem().getType().name())) {
        if (r != null && ((!RPConfig.getGlobalFlagBool(p.getWorld().getName() + ".deny-item-usage.allow-on-claimed-rps") && r.canBuild(p)) || (RPConfig.getGlobalFlagBool(p.getWorld().getName() + ".deny-item-usage.allow-on-claimed-rps") && !r.canBuild(p)))) {
            RPLang.sendMessage(p, "playerlistener.region.cantuse");
            e.setUseInteractedBlock(Event.Result.DENY);
            e.setUseItemInHand(Event.Result.DENY);
            e.setCancelled(true);
            return;
        }
        if (r == null && !RPConfig.getGlobalFlagBool(p.getWorld().getName() + ".deny-item-usage.allow-on-wilderness") && !RedProtect.get().ph.hasPerm(p, "redprotect.bypass.world")) {
            RPLang.sendMessage(p, "playerlistener.region.cantuse");
            e.setUseInteractedBlock(Event.Result.DENY);
            e.setUseItemInHand(Event.Result.DENY);
            e.setCancelled(true);
            return;
        }
    }
    if (b == null || r != null) {
        return;
    }
    if ((b instanceof Crops || b.getType().equals(Material.PUMPKIN_STEM) || b.getType().equals(Material.MELON_STEM) || b.getType().toString().contains("CROPS") || b.getType().toString().contains("SOIL") || b.getType().toString().contains("CHORUS_") || b.getType().toString().contains("BEETROOT_") || b.getType().toString().contains("SUGAR_CANE")) && !RPConfig.getGlobalFlagBool(p.getWorld().getName() + ".allow-crops-trample") && !p.hasPermission("redprotect.bypass.world")) {
        e.setCancelled(true);
        return;
    }
    if (b.getType().equals(Material.DRAGON_EGG) || b.getType().name().equalsIgnoreCase("BED") || b.getType().name().contains("NOTE_BLOCK") || b.getType().name().contains("CAKE")) {
        if ((!RPConfig.getGlobalFlagList(p.getWorld().getName() + ".if-build-false.break-blocks").contains(b.getType().name()) || !RPConfig.getGlobalFlagList(p.getWorld().getName() + ".if-interact-false.allow-blocks").contains(b.getType().name())) && !bypassBuild(p, null, 0)) {
            RPLang.sendMessage(p, "playerlistener.region.cantinteract");
            e.setCancelled(true);
            return;
        }
    }
    if (itemInHand != null) {
        if (itemInHand.getType().name().startsWith("BOAT") || itemInHand.getType().name().contains("MINECART")) {
            if (!RPConfig.getGlobalFlagBool(p.getWorld().getName() + ".use-minecart") && !p.hasPermission("redprotect.bypass.world")) {
                e.setUseItemInHand(Event.Result.DENY);
                e.setCancelled(true);
                return;
            }
        }
        if (itemInHand.getType().equals(Material.PAINTING) || itemInHand.getType().equals(Material.ITEM_FRAME) || itemInHand.getType().equals(Material.ARMOR_STAND)) {
            if (!RPConfig.getGlobalFlagList(p.getWorld().getName() + ".if-build-false.place-blocks").contains(itemInHand.getType().name()) && !bypassBuild(p, null, 0)) {
                e.setUseItemInHand(Event.Result.DENY);
                e.setCancelled(true);
                return;
            }
        }
    }
    if (!RPConfig.getGlobalFlagBool(p.getWorld().getName() + ".interact") && !p.hasPermission("redprotect.bypass.world")) {
        if (RPConfig.getGlobalFlagList(p.getWorld().getName() + ".if-interact-false.allow-blocks").contains(b.getType().name())) {
            return;
        }
        e.setUseItemInHand(Event.Result.DENY);
        e.setCancelled(true);
    }
}
Also used : Player(org.bukkit.entity.Player) Crops(org.bukkit.material.Crops) Block(org.bukkit.block.Block) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) Sign(org.bukkit.block.Sign) ItemStack(org.bukkit.inventory.ItemStack) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 9 with RPGlobalListener

use of br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPGlobalListener in project RedProtect by FabioZumbi12.

the class RPGlobalListener method onFlow.

@EventHandler
public void onFlow(BlockFromToEvent e) {
    RedProtect.get().logger.debug("RPGlobalListener - Is BlockFromToEvent event");
    if (e.isCancelled()) {
        return;
    }
    Block b = e.getToBlock();
    Block bfrom = e.getBlock();
    RedProtect.get().logger.debug("RPGlobalListener - Is BlockFromToEvent event is to " + b.getType().name() + " from " + bfrom.getType().name());
    Region r = RedProtect.get().rm.getTopRegion(b.getLocation());
    if (r != null) {
        return;
    }
    if (bfrom.isLiquid() && !RPConfig.getGlobalFlagBool(b.getWorld().getName() + ".liquid-flow")) {
        e.setCancelled(true);
        return;
    }
    if ((bfrom.getType().equals(Material.WATER) || (bfrom.getType().name().contains("WATER") && (bfrom.getType().name().contains("STATIONARY") || bfrom.getType().name().contains("FLOWING")))) && !RPConfig.getGlobalFlagBool(b.getWorld().getName() + ".allow-changes-of.water-flow")) {
        e.setCancelled(true);
        return;
    }
    if ((bfrom.getType().equals(Material.LAVA) || (bfrom.getType().name().contains("LAVA") && (bfrom.getType().name().contains("STATIONARY") || bfrom.getType().name().contains("FLOWING")))) && !RPConfig.getGlobalFlagBool(b.getWorld().getName() + ".allow-changes-of.lava-flow")) {
        e.setCancelled(true);
        return;
    }
    if (!b.isEmpty() && !RPConfig.getGlobalFlagBool(b.getWorld().getName() + ".allow-changes-of.flow-damage")) {
        e.setCancelled(true);
    }
}
Also used : Block(org.bukkit.block.Block) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) EventHandler(org.bukkit.event.EventHandler)

Example 10 with RPGlobalListener

use of br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPGlobalListener in project RedProtect by FabioZumbi12.

the class RPGlobalListener method onBlockBreakGlobal.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockBreakGlobal(ChangeBlockEvent.Break e, @Root Player p) {
    RedProtect.get().logger.debug("default", "RPGlobalListener - Is BlockBreakEvent event! Cancelled? " + e.isCancelled());
    BlockSnapshot bt = e.getTransactions().get(0).getOriginal();
    BlockState b = bt.getState();
    World w = bt.getLocation().get().getExtent();
    Region r = RedProtect.get().rm.getTopRegion(bt.getLocation().get());
    if (r != null) {
        return;
    }
    if (!RPUtil.canBuildNear(p, bt.getLocation().get())) {
        e.setCancelled(true);
        return;
    }
    if (!bypassBuild(p, bt, 2)) {
        e.setCancelled(true);
    }
}
Also used : BlockState(org.spongepowered.api.block.BlockState) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) World(org.spongepowered.api.world.World) Listener(org.spongepowered.api.event.Listener)

Aggregations

Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)7 EventHandler (org.bukkit.event.EventHandler)7 Block (org.bukkit.block.Block)5 Player (org.bukkit.entity.Player)5 Listener (org.spongepowered.api.event.Listener)5 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)4 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)3 World (org.spongepowered.api.world.World)3 Location (org.bukkit.Location)2 Entity (org.bukkit.entity.Entity)2 LivingEntity (org.bukkit.entity.LivingEntity)2 Monster (org.bukkit.entity.Monster)2 RedProtectAPI (br.net.fabiozumbi12.RedProtect.Bukkit.API.RedProtectAPI)1 MPListener (br.net.fabiozumbi12.RedProtect.Bukkit.hooks.MPListener)1 McMMoListener (br.net.fabiozumbi12.RedProtect.Bukkit.hooks.McMMoListener)1 RPDynmap (br.net.fabiozumbi12.RedProtect.Bukkit.hooks.RPDynmap)1 RPFactions (br.net.fabiozumbi12.RedProtect.Bukkit.hooks.RPFactions)1 RPPlaceHoldersAPI (br.net.fabiozumbi12.RedProtect.Bukkit.hooks.RPPlaceHoldersAPI)1 SkillAPIListener (br.net.fabiozumbi12.RedProtect.Bukkit.hooks.SkillAPIListener)1 RPAddProtection (br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPAddProtection)1