use of br.net.fabiozumbi12.RedProtect.Sponge.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);
}
}
}
use of br.net.fabiozumbi12.RedProtect.Sponge.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);
}
}
use of br.net.fabiozumbi12.RedProtect.Sponge.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);
}
}
use of br.net.fabiozumbi12.RedProtect.Sponge.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);
}
}
use of br.net.fabiozumbi12.RedProtect.Sponge.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);
}
}
Aggregations