Search in sources :

Example 1 with RPEntityListener

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

the class RPEntityListener method onEntityDamage.

@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityDamage(EntityDamageEvent e) {
    if (e.isCancelled()) {
        return;
    }
    Entity ent = e.getEntity();
    Region r = RedProtect.get().rm.getTopRegion(ent.getLocation());
    if (ent instanceof LivingEntity && !(ent instanceof Monster)) {
        if (r != null && r.flagExists("invincible")) {
            if (r.getFlagBool("invincible")) {
                if (ent instanceof Animals) {
                    ((Animals) ent).setTarget(null);
                }
                e.setCancelled(true);
            }
        }
    }
    if (e instanceof EntityDamageByEntityEvent) {
        EntityDamageByEntityEvent de = (EntityDamageByEntityEvent) e;
        Entity e1 = de.getEntity();
        Entity e2 = de.getDamager();
        if (e2 == null) {
            return;
        }
        RedProtect.get().logger.debug("RPEntityListener - Is EntityDamageByEntityEvent event. Damager: " + e2.getType().name());
        if (e2 instanceof Projectile) {
            Projectile a = (Projectile) e2;
            if (a.getShooter() instanceof Entity) {
                e2 = (Entity) a.getShooter();
            }
            a = null;
            if (e2 == null) {
                return;
            }
        }
        RedProtect.get().logger.debug("EntityDamageByEntityEvent event. Damager Player: " + e2.getType().name());
        RedProtect.get().logger.debug("Cause: " + de.getCause().name());
        Region r1 = RedProtect.get().rm.getTopRegion(e1.getLocation());
        Region r2 = RedProtect.get().rm.getTopRegion(e2.getLocation());
        if (de.getCause().equals(DamageCause.LIGHTNING) || de.getCause().equals(DamageCause.BLOCK_EXPLOSION) || de.getCause().equals(DamageCause.FIRE) || de.getCause().equals(DamageCause.WITHER) || de.getCause().equals(DamageCause.CUSTOM) || de.getCause().equals(DamageCause.ENTITY_EXPLOSION)) {
            if (r1 != null && !r1.canFire() && !(e2 instanceof Player)) {
                e.setCancelled(true);
                return;
            }
        }
        if (e1 instanceof Player) {
            if (e2 instanceof Player && !e1.equals(e2)) {
                Player p2 = (Player) e2;
                if (r1 != null) {
                    Material mp2 = p2.getItemInHand().getType();
                    if (RedProtect.get().version >= 190) {
                        if (p2.getInventory().getItemInMainHand() != null) {
                            mp2 = p2.getInventory().getItemInMainHand().getType();
                        } else {
                            mp2 = p2.getInventory().getItemInOffHand().getType();
                        }
                    }
                    if (mp2.equals(Material.EGG) && !r1.canProtectiles(p2)) {
                        e.setCancelled(true);
                        RPLang.sendMessage(p2, "playerlistener.region.cantuse");
                        return;
                    }
                    if (r2 != null) {
                        if (mp2.equals(Material.EGG) && !r2.canProtectiles(p2)) {
                            e.setCancelled(true);
                            RPLang.sendMessage(p2, "playerlistener.region.cantuse");
                            return;
                        }
                        if ((r1.flagExists("pvp") && !r1.canPVP((Player) e1, p2)) || (r1.flagExists("pvp") && !r2.canPVP((Player) e1, p2))) {
                            e.setCancelled(true);
                            RPLang.sendMessage(p2, "entitylistener.region.cantpvp");
                        }
                    } else if (r1.flagExists("pvp") && !r1.canPVP((Player) e1, p2)) {
                        e.setCancelled(true);
                        RPLang.sendMessage(p2, "entitylistener.region.cantpvp");
                    }
                } else if (r2 != null && r2.flagExists("pvp") && !r2.canPVP((Player) e1, p2)) {
                    e.setCancelled(true);
                    RPLang.sendMessage(p2, "entitylistener.region.cantpvp");
                }
            }
        } else if (e1 instanceof Animals || e1 instanceof Villager || e1 instanceof Golem) {
            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) && !r1.canBreak(e1.getType())) {
                e.setCancelled(true);
                RPLang.sendMessage(p2, "playerlistener.region.cantuse");
                return;
            }
            if (r2 != null && !r2.canBuild(p2) && !r2.canBreak(e1.getType())) {
                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("Cancelled ItemFrame drop Item");
                e.setCancelled(true);
            }
        } else if (e2 instanceof Explosive) {
            if ((r1 != null && !r1.canFire()) || (r2 != null && !r2.canFire())) {
                e.setCancelled(true);
            }
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Material(org.bukkit.Material) Projectile(org.bukkit.entity.Projectile) LivingEntity(org.bukkit.entity.LivingEntity) Golem(org.bukkit.entity.Golem) Animals(org.bukkit.entity.Animals) Explosive(org.bukkit.entity.Explosive) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) Hanging(org.bukkit.entity.Hanging) Monster(org.bukkit.entity.Monster) Villager(org.bukkit.entity.Villager) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) EventHandler(org.bukkit.event.EventHandler)

Example 2 with RPEntityListener

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

the class RPEntityListener method onInteractEvent.

@EventHandler
public void onInteractEvent(PlayerInteractEntityEvent e) {
    RedProtect.get().logger.debug("RPEntityListener - Is PlayerInteractEntityEvent");
    if (e.isCancelled()) {
        return;
    }
    Player p = e.getPlayer();
    if (p == null) {
        return;
    }
    Location l = e.getRightClicked().getLocation();
    Region r = RedProtect.get().rm.getTopRegion(l);
    Entity et = e.getRightClicked();
    if (r != null && !r.canInteractPassives(p) && (et instanceof Animals || et instanceof Villager || et instanceof Golem)) {
        if (et instanceof Tameable) {
            Tameable tam = (Tameable) et;
            if (tam.isTamed() && tam.getOwner() != null && tam.getOwner().getName().equals(p.getName())) {
                return;
            }
        }
        e.setCancelled(true);
        RPLang.sendMessage(p, "entitylistener.region.cantinteract");
    }
}
Also used : Golem(org.bukkit.entity.Golem) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Animals(org.bukkit.entity.Animals) Tameable(org.bukkit.entity.Tameable) Villager(org.bukkit.entity.Villager) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 3 with RPEntityListener

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

the class RPEntityListener method onPotionSplash.

@EventHandler
public void onPotionSplash(PotionSplashEvent event) {
    RedProtect.get().logger.debug("RPEntityListener - Is PotionSplashEvent");
    if (event.isCancelled()) {
        return;
    }
    ProjectileSource thrower = event.getPotion().getShooter();
    for (PotionEffect e : event.getPotion().getEffects()) {
        PotionEffectType t = e.getType();
        if (!t.equals(PotionEffectType.BLINDNESS) && !t.equals(PotionEffectType.CONFUSION) && !t.equals(PotionEffectType.HARM) && !t.equals(PotionEffectType.HUNGER) && !t.equals(PotionEffectType.POISON) && !t.equals(PotionEffectType.SLOW) && !t.equals(PotionEffectType.SLOW_DIGGING) && !t.equals(PotionEffectType.WEAKNESS) && !t.equals(PotionEffectType.WITHER)) {
            return;
        }
    }
    Player shooter;
    if (thrower instanceof Player) {
        shooter = (Player) thrower;
    } else {
        return;
    }
    for (Entity e2 : event.getAffectedEntities()) {
        Region r = RedProtect.get().rm.getTopRegion(e2.getLocation());
        if (event.getEntity() instanceof Player) {
            if (r != null && r.flagExists("pvp") && !r.canPVP((Player) event.getEntity(), shooter)) {
                event.setCancelled(true);
                return;
            }
        } else {
            if (r != null && !r.canInteractPassives(shooter)) {
                event.setCancelled(true);
                return;
            }
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) ProjectileSource(org.bukkit.projectiles.ProjectileSource) EventHandler(org.bukkit.event.EventHandler)

Example 4 with RPEntityListener

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

the class RedProtect method onEnable.

public void onEnable() {
    try {
        plugin = this;
        BossBar = checkBM();
        MyChunk = checkMyChunk();
        MyPet = checkMyPet();
        McMMo = checkMcMMo();
        Mc = checkMc();
        Vault = checkVault();
        SkillAPI = checkSkillAPI();
        PvPm = checkPvPm();
        Ess = checkEss();
        GP = checkGP();
        Dyn = checkDyn();
        WE = checkWe();
        AWE = checkAWe();
        SC = checkSP();
        Fac = checkFac();
        PLib = checkPLib();
        PlaceHolderAPI = checkPHAPI();
        JarFile = this.getFile();
        initVars();
        RPConfig.init();
        RPLang.init();
        rm.loadAll();
        OnlineMode = serv.getOnlineMode();
        serv.getPluginManager().registerEvents(new RPGlobalListener(), this);
        serv.getPluginManager().registerEvents(new RPBlockListener(), this);
        serv.getPluginManager().registerEvents(new RPPlayerListener(), this);
        serv.getPluginManager().registerEvents(new RPEntityListener(), this);
        serv.getPluginManager().registerEvents(new RPWorldListener(), this);
        serv.getPluginManager().registerEvents(new RPAddProtection(), this);
        version = getBukkitVersion();
        logger.debug("Version String: " + version);
        if (version >= 180) {
            serv.getPluginManager().registerEvents(new RPMine18(), this);
        }
        if (version >= 190) {
            serv.getPluginManager().registerEvents(new RPMine19(), this);
        }
        getCommand("RedProtect").setExecutor(new RPCommands());
        if (Vault) {
            RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
            if (rsp == null) {
                logger.warning("Vault found, but for some reason cant be used with RedProtect.");
                Vault = false;
            } else {
                econ = rsp.getProvider();
                logger.info("Vault found. Hooked.");
            }
        }
        if (PLib) {
            logger.info("ProtocolLib found. Hidding Gui Flag item stats.");
        }
        if (PvPm) {
            logger.info("PvPManager found. Hooked.");
        }
        if (Ess) {
            pless = (Essentials) Bukkit.getPluginManager().getPlugin("Essentials");
            logger.info("Essentials found. Hooked.");
        }
        if (WE) {
            logger.info("WorldEdit found. Hooked.");
        }
        if (AWE) {
            logger.info("AsyncWorldEdit found. Hooked.");
        }
        if (BossBar) {
            logger.info("BossbarAPI found. Hooked.");
        }
        if (MyPet) {
            serv.getPluginManager().registerEvents(new MPListener(), this);
            logger.info("MyPet found. Hooked.");
        }
        if (McMMo) {
            serv.getPluginManager().registerEvents(new McMMoListener(), this);
            logger.info("McMMo found. Hooked.");
        }
        if (SkillAPI) {
            serv.getPluginManager().registerEvents(new SkillAPIListener(), this);
            logger.info("SkillAPI found. Hooked.");
        }
        if (MyChunk) {
            logger.sucess("MyChunk found. Ready to convert!");
            logger.warning("Use '/rp mychunkconvert' to start MyChunk conversion (This may cause lag during conversion)");
        }
        if (Mc) {
            logger.info("MagicCarpet found. Hooked.");
        }
        if (SC) {
            clanManager = SimpleClans.getInstance().getClanManager();
            logger.info("SimpleClans found. Hooked.");
        }
        if (Dyn && RPConfig.getBool("hooks.dynmap.enable")) {
            logger.info("Dynmap found. Hooked.");
            logger.info("Loading dynmap markers...");
            dynmap = new RPDynmap((DynmapAPI) Bukkit.getPluginManager().getPlugin("dynmap"));
            logger.info("Dynmap markers loaded!");
        }
        if (PlaceHolderAPI) {
            new RPPlaceHoldersAPI(this).hook();
            logger.info("PlaceHolderAPI found. Hooked and registered some chat placeholders.");
        }
        if (Fac) {
            serv.getPluginManager().registerEvents(new RPFactions(), this);
            logger.info("Factions found. Hooked.");
        }
        if (!RPConfig.getString("file-type").equalsIgnoreCase("mysql")) {
            RPUtil.ReadAllDB(rm.getAllRegions());
        } else {
            logger.info("Theres " + rm.getTotalRegionsNum() + " regions on (" + RPConfig.getString("file-type") + ") database!");
        }
        logger.info("Loading API...");
        this.rpAPI = new RedProtectAPI();
        logger.info("API Loaded!");
        logger.clear("&4 _   _  _  &c _   _   _  _ _  _  _ _ _  __");
        logger.clear("&4|_| |_ | \\ &c|_| |_| | |  |  |_ |   |    /");
        logger.clear("&4| \\ |_ |_/ &c|   | \\ |_|  |  |_ |_  |   /");
        logger.clear("&a¯ " + pdf.getFullName() + " enabled");
        logger.clear("");
        if (RPConfig.getBool("update-check.enable")) {
            logger.info("Checking for update...");
            if (CheckUpdate()) {
                logger.sucess("Update available! Use /rp update to download.");
            } else {
                logger.info("No update available.");
            }
        }
        if (RPConfig.getString("file-type").equals("yml")) {
            AutoSaveHandler();
        }
    } catch (Exception e) {
        e.printStackTrace();
        if (!RPConfig.getString("file-type").equalsIgnoreCase("mysql")) {
            logger.severe("Error enabling RedProtect, plugin will shut down.");
            this.disable();
        }
    }
}
Also used : RPPlayerListener(br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPPlayerListener) RPWorldListener(br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPWorldListener) DynmapAPI(org.dynmap.DynmapAPI) RPGlobalListener(br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPGlobalListener) RPAddProtection(br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPAddProtection) MPListener(br.net.fabiozumbi12.RedProtect.Bukkit.hooks.MPListener) RPMine19(br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPMine19) RPMine18(br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPMine18) SkillAPIListener(br.net.fabiozumbi12.RedProtect.Bukkit.hooks.SkillAPIListener) RPFactions(br.net.fabiozumbi12.RedProtect.Bukkit.hooks.RPFactions) RPBlockListener(br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPBlockListener) McMMoListener(br.net.fabiozumbi12.RedProtect.Bukkit.hooks.McMMoListener) Economy(net.milkbowl.vault.economy.Economy) RPEntityListener(br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPEntityListener) RedProtectAPI(br.net.fabiozumbi12.RedProtect.Bukkit.API.RedProtectAPI) RPPlaceHoldersAPI(br.net.fabiozumbi12.RedProtect.Bukkit.hooks.RPPlaceHoldersAPI) RPDynmap(br.net.fabiozumbi12.RedProtect.Bukkit.hooks.RPDynmap) RPCommands(br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPCommands)

Example 5 with RPEntityListener

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

the class RPEntityListener method WitherBlockBreak.

@Listener(order = Order.FIRST, beforeModifications = true)
public void WitherBlockBreak(ChangeBlockEvent.Break event, @First Entity e) {
    if (e instanceof Monster) {
        BlockSnapshot b = event.getTransactions().get(0).getOriginal();
        RedProtect.get().logger.debug("entity", "RPEntityListener - Is EntityChangeBlockEvent event! Block " + b.getState().getType().getName());
        Region r = RedProtect.get().rm.getTopRegion(b.getLocation().get());
        if (!cont.canWorldBreak(b)) {
            event.setCancelled(true);
            return;
        }
        if (r != null && !r.canMobLoot()) {
            event.setCancelled(true);
        }
    }
}
Also used : Monster(org.spongepowered.api.entity.living.monster.Monster) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) Listener(org.spongepowered.api.event.Listener)

Aggregations

Listener (org.spongepowered.api.event.Listener)6 Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)5 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)5 EventHandler (org.bukkit.event.EventHandler)5 Entity (org.bukkit.entity.Entity)4 LivingEntity (org.bukkit.entity.LivingEntity)4 Player (org.bukkit.entity.Player)4 Entity (org.spongepowered.api.entity.Entity)4 Monster (org.spongepowered.api.entity.living.monster.Monster)3 Animals (org.bukkit.entity.Animals)2 Golem (org.bukkit.entity.Golem)2 Monster (org.bukkit.entity.Monster)2 Villager (org.bukkit.entity.Villager)2 Ambient (org.spongepowered.api.entity.living.Ambient)2 Animal (org.spongepowered.api.entity.living.animal.Animal)2 Golem (org.spongepowered.api.entity.living.golem.Golem)2 Player (org.spongepowered.api.entity.living.player.Player)2 World (org.spongepowered.api.world.World)2 RedProtectAPI (br.net.fabiozumbi12.RedProtect.Bukkit.API.RedProtectAPI)1 MPListener (br.net.fabiozumbi12.RedProtect.Bukkit.hooks.MPListener)1