use of org.spongepowered.api.event.Listener in project RedProtect by FabioZumbi12.
the class RPGlobalListener method onPlayerInteract.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerInteract(InteractEntityEvent e, @Root Player p) {
Entity ent = e.getTargetEntity();
Location<World> l = ent.getLocation();
Region r = RedProtect.get().rm.getTopRegion(l);
if (!canInteract(p, r)) {
e.setCancelled(true);
}
if (r != null) {
return;
}
if (ent instanceof Minecart || ent instanceof Boat) {
if (!RedProtect.get().cfgs.getGlobalFlag(ent.getWorld().getName(), "use-minecart") && !p.hasPermission("redprotect.world.bypass")) {
e.setCancelled(true);
return;
}
}
if (ent instanceof Hanging || ent instanceof ArmorStand) {
if (!RedProtect.get().cfgs.getGlobalFlag(ent.getWorld().getName(), "build") && !p.hasPermission("redprotect.world.bypass")) {
e.setCancelled(true);
return;
}
}
if (!RedProtect.get().cfgs.getGlobalFlag(ent.getWorld().getName(), "interact") && !p.hasPermission("redprotect.world.bypass") && (!(ent instanceof Player))) {
e.setCancelled(true);
}
}
use of org.spongepowered.api.event.Listener in project RedProtect by FabioZumbi12.
the class RPGlobalListener method onFireSpread.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onFireSpread(NotifyNeighborBlockEvent e, @Root BlockSnapshot source) {
Map<Direction, BlockState> dirs = e.getNeighbors();
for (Direction dir : dirs.keySet()) {
BlockSnapshot b = source.getLocation().get().getRelative(dir).createSnapshot();
BlockState bstate = source.getState();
Region r = RedProtect.get().rm.getTopRegion(b.getLocation().get());
if (r != null) {
return;
}
if ((bstate.getType().equals(BlockTypes.FIRE) || bstate.getType().getName().contains("lava")) && !RedProtect.get().cfgs.getGlobalFlag(b.getLocation().get().getExtent().getName(), "fire-spread")) {
e.setCancelled(true);
return;
}
}
}
use of org.spongepowered.api.event.Listener in project RedProtect by FabioZumbi12.
the class RPGlobalListener method onBlockPlace.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockPlace(ChangeBlockEvent.Place e, @Root Player p) {
RedProtect.get().logger.debug("default", "RPGlobalListener - Is ChangeBlockEvent event! Cancelled? " + e.isCancelled());
BlockSnapshot b = e.getTransactions().get(0).getFinal();
ItemType item = ItemTypes.NONE;
if (p.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
item = p.getItemInHand(HandTypes.MAIN_HAND).get().getItem();
} else if (p.getItemInHand(HandTypes.OFF_HAND).isPresent()) {
item = p.getItemInHand(HandTypes.OFF_HAND).get().getItem();
}
Region r = RedProtect.get().rm.getTopRegion(e.getTransactions().get(0).getOriginal().getLocation().get());
if (r != null) {
return;
}
if (!RPUtil.canBuildNear(p, b.getLocation().get())) {
e.setCancelled(true);
return;
}
if (item.getName().contains("minecart") || item.getName().contains("boat")) {
if (!RedProtect.get().cfgs.getGlobalFlag(p.getWorld().getName(), "use-minecart") && !p.hasPermission("redprotect.world.bypass")) {
e.setCancelled(true);
RedProtect.get().logger.debug("default", "RPGlobalListener - Can't place minecart/boat!");
}
} else {
if (!bypassBuild(p, b, 1)) {
e.setCancelled(true);
RedProtect.get().logger.debug("default", "RPGlobalListener - Can't Build!");
}
}
}
use of org.spongepowered.api.event.Listener in project RedProtect by FabioZumbi12.
the class RPMine18 method onAttemptInteractAS.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onAttemptInteractAS(InteractEntityEvent e, @First Player p) {
Entity ent = e.getTargetEntity();
Location<World> l = ent.getLocation();
Region r = RedProtect.get().rm.getTopRegion(l);
if (r == null) {
// global flags
if (ent.getType().equals(EntityTypes.ARMOR_STAND)) {
if (!RedProtect.get().cfgs.getGlobalFlag(l.getExtent().getName(), "build")) {
e.setCancelled(true);
return;
}
}
return;
}
ItemType itemInHand = ItemTypes.NONE;
if (p.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
itemInHand = p.getItemInHand(HandTypes.MAIN_HAND).get().getItem();
} else if (p.getItemInHand(HandTypes.OFF_HAND).isPresent()) {
itemInHand = p.getItemInHand(HandTypes.OFF_HAND).get().getItem();
}
if (!itemInHand.equals(ItemTypes.NONE) && itemInHand.getType().equals(ItemTypes.ARMOR_STAND)) {
if (r != null && !r.canBuild(p)) {
e.setCancelled(true);
RPLang.sendMessage(p, "blocklistener.region.cantbuild");
return;
}
}
// TODO Not working!
if (ent.getType().equals(EntityTypes.ARMOR_STAND)) {
if (r != null && !r.canBuild(p)) {
if (!RedProtect.get().ph.hasPerm(p, "redprotect.bypass")) {
RPLang.sendMessage(p, "playerlistener.region.cantedit");
e.setCancelled(true);
}
}
}
}
use of org.spongepowered.api.event.Listener in project RedProtect by FabioZumbi12.
the class RPMine18 method onEntityDamage.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityDamage(DamageEntityEvent e, @First Entity e2) {
Entity e1 = e.getTargetEntity();
Location<World> loc = e1.getLocation();
Player damager = null;
if (e2 instanceof Projectile) {
Projectile proj = (Projectile) e2;
if (proj.getShooter() instanceof Player) {
damager = (Player) proj.getShooter();
}
} else if (e2 instanceof Player) {
damager = (Player) e2;
}
Region r1 = RedProtect.get().rm.getTopRegion(loc);
if (r1 == null) {
// global flags
if (e1 instanceof ArmorStand) {
if (e2 instanceof Player) {
if (!RedProtect.get().cfgs.getGlobalFlag(loc.getExtent().getName(), "build")) {
e.setCancelled(true);
return;
}
}
}
return;
}
if (e1 instanceof ArmorStand) {
if (r1 != null && !r1.canBuild(damager)) {
e.setCancelled(true);
RPLang.sendMessage(damager, "blocklistener.region.cantbreak");
}
}
}
Aggregations