use of org.spongepowered.api.entity.hanging.Hanging in project RedProtect by FabioZumbi12.
the class RPEntityListener method onEntityDamage.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityDamage(DamageEntityEvent e) {
// victim
Entity e1 = e.getTargetEntity();
RedProtect.get().logger.debug("entity", "RPEntityListener - DamageEntityEvent entity target " + e1.getType().getName());
Region r = RedProtect.get().rm.getTopRegion(e1.getLocation());
if (e1 instanceof Living && !(e1 instanceof Monster)) {
if (r != null && r.flagExists("invincible")) {
if (r.getFlagBool("invincible")) {
e.setCancelled(true);
}
}
}
if (e1 instanceof Animal || e1 instanceof Villager || e1 instanceof Golem || e1 instanceof Ambient) {
if (r != null && r.flagExists("invincible")) {
if (r.getFlagBool("invincible")) {
if (e1 instanceof Animal) {
((Animal) e1).setTarget(null);
}
e.setCancelled(true);
}
}
}
// damager
if (!e.getCause().first(Living.class).isPresent()) {
return;
}
Entity e2 = e.getCause().first(Living.class).get();
RedProtect.get().logger.debug("entity", "RPEntityListener - DamageEntityEvent damager " + e2.getType().getName());
if (e2 instanceof Projectile) {
Projectile a = (Projectile) e2;
if (a.getShooter() instanceof Entity) {
e2 = (Entity) a.getShooter();
}
}
Region r1 = RedProtect.get().rm.getTopRegion(e1.getLocation());
Region r2 = RedProtect.get().rm.getTopRegion(e2.getLocation());
if (e.getCause().containsType(Lightning.class) || e.getCause().containsType(Explosive.class) || e.getCause().containsType(Fireball.class) || e.getCause().containsType(Explosion.class)) {
if (r1 != null && !r1.canFire() && !(e2 instanceof Player)) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Player) {
if (e2 instanceof Player) {
Player p2 = (Player) e2;
if (r1 != null) {
ItemType itemInHand = ItemTypes.NONE;
if (p2.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
itemInHand = p2.getItemInHand(HandTypes.MAIN_HAND).get().getItem();
} else if (p2.getItemInHand(HandTypes.OFF_HAND).isPresent()) {
itemInHand = p2.getItemInHand(HandTypes.OFF_HAND).get().getItem();
}
if (itemInHand.getType().equals(ItemTypes.EGG) && !r1.canProtectiles(p2)) {
e.setCancelled(true);
RPLang.sendMessage(p2, "playerlistener.region.cantuse");
return;
}
if (r2 != null) {
if (itemInHand.getType().equals(ItemTypes.EGG) && !r2.canProtectiles(p2)) {
e.setCancelled(true);
RPLang.sendMessage(p2, "playerlistener.region.cantuse");
return;
}
if ((r1.flagExists("pvp") && !r1.canPVP(p2)) || (r1.flagExists("pvp") && !r2.canPVP(p2))) {
e.setCancelled(true);
RPLang.sendMessage(p2, "entitylistener.region.cantpvp");
}
} else if (r1.flagExists("pvp") && !r1.canPVP(p2)) {
e.setCancelled(true);
RPLang.sendMessage(p2, "entitylistener.region.cantpvp");
}
} else if (r2 != null && r2.flagExists("pvp") && !r2.canPVP(p2)) {
e.setCancelled(true);
RPLang.sendMessage(p2, "entitylistener.region.cantpvp");
}
}
} else if (e1 instanceof Animal || e1 instanceof Villager || e1 instanceof Golem || e instanceof Ambient) {
if (r1 != null && e2 instanceof Player) {
Player p2 = (Player) e2;
if (!r1.canInteractPassives(p2)) {
e.setCancelled(true);
RPLang.sendMessage(p2, "entitylistener.region.cantpassive");
}
}
} else if ((e1 instanceof Hanging) && e2 instanceof Player) {
Player p2 = (Player) e2;
if (r1 != null && !r1.canBuild(p2)) {
e.setCancelled(true);
RPLang.sendMessage(p2, "playerlistener.region.cantuse");
return;
}
if (r2 != null && !r2.canBuild(p2)) {
e.setCancelled(true);
RPLang.sendMessage(p2, "playerlistener.region.cantuse");
}
} else if ((e1 instanceof Hanging) && e2 instanceof Monster) {
if (r1 != null || r2 != null) {
RedProtect.get().logger.debug("entity", "Cancelled ItemFrame drop Item");
e.setCancelled(true);
}
} else if ((e1 instanceof Explosive)) {
if ((r1 != null && !r1.canFire()) || (r2 != null && !r2.canFire())) {
e.setCancelled(true);
}
}
}
use of org.spongepowered.api.entity.hanging.Hanging 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.entity.hanging.Hanging in project RedProtect by FabioZumbi12.
the class RPPlayerListener method onEntityDamageEvent.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityDamageEvent(DamageEntityEvent e) {
// victim
Entity e1 = e.getTargetEntity();
// damager
Entity e2 = null;
if (e.getCause().first(IndirectEntityDamageSource.class).isPresent()) {
e2 = e.getCause().first(IndirectEntityDamageSource.class).get().getSource();
RedProtect.get().logger.debug("player", "RPLayerListener: Is DamageEntityEvent event. Damager " + e2.getType().getName());
}
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;
}
Location<World> l = e1.getLocation();
Region r = RedProtect.get().rm.getTopRegion(l);
if (r == null) {
return;
}
RedProtect.get().logger.debug("player", "RPLayerListener: Is DamageEntityEvent event. Victim " + e1.getType().getName());
if (damager instanceof Player) {
if (e1 instanceof Hanging && !r.canBuild(damager)) {
RPLang.sendMessage(damager, "entitylistener.region.cantinteract");
e.setCancelled(true);
return;
}
if (e1 instanceof Player && r.flagExists("pvp") && !r.canPVP(damager)) {
RPLang.sendMessage(damager, "entitylistener.region.cantpvp");
e.setCancelled(true);
return;
}
}
// return if not player
if (!(e1 instanceof Player)) {
return;
}
Player play = (Player) e.getTargetEntity();
if (RedProtect.get().tpWait.contains(play.getName())) {
RedProtect.get().tpWait.remove(play.getName());
RPLang.sendMessage(play, RPLang.get("cmdmanager.region.tpcancelled"));
}
if (r != null && !r.canPlayerDamage()) {
e.setCancelled(true);
}
// execute on health
if (r.cmdOnHealth(play)) {
RedProtect.get().logger.debug("player", "Cmd on healt: true");
}
if (!r.canDeath() && play.get(Keys.HEALTH).get() <= 1) {
e.setCancelled(true);
}
// deny damagecauses
List<String> Causes = RedProtect.get().cfgs.getStringList("server-protection.deny-playerdeath-by");
if (e.getCause().containsType(DamageSource.class) && Causes.size() > 0) {
DamageType damagec = e.getCause().first(DamageSource.class).get().getType();
for (String cause : Causes) {
if (damagec.getName().equalsIgnoreCase(cause)) {
e.setCancelled(true);
}
}
}
}
use of org.spongepowered.api.entity.hanging.Hanging in project RedProtect by FabioZumbi12.
the class RPPlayerListener method onPlayerInteract.
/*
@Listener(order = Order.FIRST, beforeModifications = true)
public void MoveItem(ClickInventoryEvent e, @First Player p){
Container cont = e.getTargetInventory().getProperties(Names.);
Region r = RedProtect.get().rm.getTopRegion(p.getLocation());
if (r != null && e.getInventory().getTitle() != null){
if (r.getName().length() > 16){
if (e.getInventory().getTitle().equals(RPLang.get("gui.invflag").replace("{region}", r.getName().substring(0, 16)))){
return;
}
} else {
if (e.getInventory().getTitle().equals(RPLang.get("gui.invflag").replace("{region}", r.getName())) || e.getInventory().getTitle().equals(RPLang.get("gui.editflag"))){
return;
}
}
}
if (RPUtil.RemoveGuiItem(e.getCurrentItem())){
e.setCurrentItem(new ItemStack(Material.AIR));
}
}
*/
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerInteract(InteractEntityEvent e, @First Player p) {
Entity ent = e.getTargetEntity();
RedProtect.get().logger.debug("player", "RPPlayerListener - Is InteractEntityEvent event: " + ent.getType().getName());
Location<World> l = ent.getLocation();
Region r = RedProtect.get().rm.getTopRegion(l);
if (r == null) {
return;
}
if (RedProtect.get().tpWait.contains(p.getName())) {
RedProtect.get().tpWait.remove(p.getName());
RPLang.sendMessage(p, "cmdmanager.region.tpcancelled");
}
if (ent instanceof Hanging || ent.getType().equals(EntityTypes.ARMOR_STAND)) {
if (!r.canBuild(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantedit");
e.setCancelled(true);
}
} else if ((ent.getType().getName().contains("minecart") || ent.getType().getName().contains("boat")) && !r.canMinecart(p)) {
RPLang.sendMessage(p, "blocklistener.region.cantenter");
e.setCancelled(true);
} else if (!r.allowMod(p) && !RPUtil.isBukkitEntity(ent) && (!(ent instanceof Player))) {
RedProtect.get().logger.debug("player", "PlayerInteractEntityEvent - Block is " + ent.getType().getName());
RPLang.sendMessage(p, "playerlistener.region.cantinteract");
e.setCancelled(true);
}
}
use of org.spongepowered.api.entity.hanging.Hanging in project RedProtect by FabioZumbi12.
the class RPBlockListener method onFrameAndBoatBrake.
/*
@Listener
public void onEntityExplode(ExplosionEvent.Detonate e) {
RedProtect.get().logger.debug("Is BlockListener - ExplosionEvent.Detonate event");
for (Transaction<BlockSnapshot> bl:e.getTransactions()) {
BlockSnapshot b = bl.getOriginal();
RedProtect.get().logger.debug("Blocks: "+b.getState().getType().getName());
Location<World> l = b.getLocation().get();
Region r = RedProtect.get().rm.getTopRegion(l);
if (!cont.canWorldBreak(b)){
RedProtect.get().logger.debug("canWorldBreak Called!");
bl.setValid(false);
//toRemove.add(bl);
continue;
}
if (r == null){
continue;
}
if ((b.getState().getType().getName().contains("tnt") || e.getCause().first(Lightning.class).isPresent()) && !r.canFire()){
//toRemove.add(bl);
bl.setValid(false);
continue;
}
if (e.getCause().first(Living.class).isPresent() && !r.canMobLoot()){
//toRemove.add(bl);
bl.setValid(false);
continue;
}
}
/*if (!toRemove.isEmpty()){
e.getTransactions().removeAll(toRemove);
}
}*/
@Listener(order = Order.FIRST, beforeModifications = true)
public void onFrameAndBoatBrake(DamageEntityEvent e) {
RedProtect.get().logger.debug("blocks", "Is BlockListener - DamageEntityEvent event");
Entity ent = e.getTargetEntity();
Location<World> l = e.getTargetEntity().getLocation();
Region r = RedProtect.get().rm.getTopRegion(l);
if (ent instanceof Hanging && e.getCause().first(Monster.class).isPresent()) {
if (r != null && !r.canFire()) {
e.setCancelled(true);
return;
}
}
if (ent instanceof Boat && e.getCause().first(Player.class).isPresent()) {
Player p = e.getCause().first(Player.class).get();
if (!r.canMinecart(p)) {
RPLang.sendMessage(p, "blocklistener.region.cantbreak");
e.setCancelled(true);
}
}
}
Aggregations