|
| 1 | +/* |
| 2 | + * Adapted from the Wizardry License |
| 3 | + * |
| 4 | + * Copyright (c) 2016-2020 larryTheCoder and contributors |
| 5 | + * |
| 6 | + * Permission is hereby granted to any persons and/or organizations |
| 7 | + * using this software to copy, modify, merge, publish, and distribute it. |
| 8 | + * Said persons and/or organizations are not allowed to use the software or |
| 9 | + * any derivatives of the work for commercial use or any other means to generate |
| 10 | + * income, nor are they allowed to claim this software as their own. |
| 11 | + * |
| 12 | + * The persons and/or organizations are also disallowed from sub-licensing |
| 13 | + * and/or trademarking this software without explicit permission from larryTheCoder. |
| 14 | + * |
| 15 | + * Any persons and/or organizations using this software must disclose their |
| 16 | + * source code and have it publicly available, include this license, |
| 17 | + * provide sufficient credit to the original authors of the project (IE: larryTheCoder), |
| 18 | + * as well as provide a link to the original project. |
| 19 | + * |
| 20 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
| 21 | + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR |
| 22 | + * PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 23 | + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 24 | + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 25 | + * USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 26 | + */ |
| 27 | + |
| 28 | +package com.larryTheCoder.listener.nms; |
| 29 | + |
| 30 | +import cn.nukkit.Player; |
| 31 | +import cn.nukkit.entity.Entity; |
| 32 | +import cn.nukkit.entity.mob.EntityMob; |
| 33 | +import cn.nukkit.entity.passive.EntityAnimal; |
| 34 | +import cn.nukkit.event.EventHandler; |
| 35 | +import cn.nukkit.event.EventPriority; |
| 36 | +import cn.nukkit.event.Listener; |
| 37 | +import cn.nukkit.event.entity.EntityDamageByEntityEvent; |
| 38 | +import cn.nukkit.event.entity.EntityDamageEvent; |
| 39 | +import com.larryTheCoder.ASkyBlock; |
| 40 | +import com.larryTheCoder.listener.Action; |
| 41 | +import com.larryTheCoder.utils.SettingsFlag; |
| 42 | +import lombok.extern.log4j.Log4j2; |
| 43 | +import nukkitcoders.mobplugin.entities.animal.Animal; |
| 44 | +import nukkitcoders.mobplugin.entities.monster.Monster; |
| 45 | + |
| 46 | +@Log4j2 |
| 47 | +public class MobPluginListener extends Action implements Listener { |
| 48 | + |
| 49 | + public MobPluginListener(ASkyBlock plugin) { |
| 50 | + super(plugin); |
| 51 | + |
| 52 | + log.debug("Using MobPlugin"); |
| 53 | + } |
| 54 | + |
| 55 | + @EventHandler(priority = EventPriority.LOWEST) |
| 56 | + public void onPlayerHitEvent(EntityDamageEvent e) { |
| 57 | + log.debug("DEBUG: " + e.getEventName()); |
| 58 | + log.debug("DEBUG: NMS MobPlugin notation."); |
| 59 | + |
| 60 | + Entity target = e.getEntity(); |
| 61 | + |
| 62 | + if (notInWorld(target)) return; |
| 63 | + if (e instanceof EntityDamageByEntityEvent) { |
| 64 | + // Identifier for player mobs attack. |
| 65 | + if (!(target instanceof Player)) { |
| 66 | + log.debug("Target is not a player."); |
| 67 | + |
| 68 | + if (target instanceof Animal) { |
| 69 | + log.debug("Target is not an animal."); |
| 70 | + |
| 71 | + if (actionAllowed(target.getLocation(), SettingsFlag.HURT_MOBS)) return; |
| 72 | + } else if (target instanceof Monster) { |
| 73 | + log.debug("Target is not a monster."); |
| 74 | + |
| 75 | + if (actionAllowed(target.getLocation(), SettingsFlag.HURT_MONSTERS)) return; |
| 76 | + } |
| 77 | + } else { |
| 78 | + log.debug("Target is a player"); |
| 79 | + if (actionAllowed(target.getLocation(), SettingsFlag.PVP)) return; |
| 80 | + } |
| 81 | + |
| 82 | + log.debug("Target cancelled."); |
| 83 | + |
| 84 | + e.setCancelled(); |
| 85 | + } |
| 86 | + } |
| 87 | +} |
0 commit comments