diff --git a/Plugin/src/main/java/dev/lrxh/neptune/game/kit/Kit.java b/Plugin/src/main/java/dev/lrxh/neptune/game/kit/Kit.java index 9b9b9213..80f644c5 100644 --- a/Plugin/src/main/java/dev/lrxh/neptune/game/kit/Kit.java +++ b/Plugin/src/main/java/dev/lrxh/neptune/game/kit/Kit.java @@ -113,8 +113,8 @@ public Kit(String name, List items, ItemStack icon) { private HashMap rules() { HashMap rules = new HashMap<>(); for (KitRule kitRule : KitRule.values()) { - if (kitRule == KitRule.DAMAGE) rules.put(kitRule, true); - rules.put(kitRule, false); + boolean defaultValue = kitRule == KitRule.DAMAGE || kitRule == KitRule.PROJECTILE_DAMAGE; + rules.put(kitRule, defaultValue); } return rules; @@ -163,7 +163,15 @@ public List getPotionsAsString() { } public boolean is(KitRule kitRule) { - return rules.get(kitRule); + Boolean value = rules.get(kitRule); + if (value == null) { + if (kitRule == KitRule.PROJECTILE_DAMAGE) { + Boolean damage = rules.get(KitRule.DAMAGE); + return damage != null && damage; + } + return false; + } + return value; } public void toggle(KitRule kitRule) { diff --git a/Plugin/src/main/java/dev/lrxh/neptune/game/kit/KitService.java b/Plugin/src/main/java/dev/lrxh/neptune/game/kit/KitService.java index 3ca3a5d6..576d05f2 100644 --- a/Plugin/src/main/java/dev/lrxh/neptune/game/kit/KitService.java +++ b/Plugin/src/main/java/dev/lrxh/neptune/game/kit/KitService.java @@ -61,8 +61,10 @@ public void load() { } HashMap rules = new HashMap<>(); + boolean damageEnabled = config.getBoolean(path + KitRule.DAMAGE.getSaveName(), false); for (KitRule kitRule : KitRule.values()) { - rules.put(kitRule, config.getBoolean(path + kitRule.getSaveName(), false)); + boolean fallback = kitRule == KitRule.PROJECTILE_DAMAGE ? damageEnabled : false; + rules.put(kitRule, config.getBoolean(path + kitRule.getSaveName(), fallback)); } List potionEffects = new ArrayList<>(); diff --git a/Plugin/src/main/java/dev/lrxh/neptune/game/kit/impl/KitRule.java b/Plugin/src/main/java/dev/lrxh/neptune/game/kit/impl/KitRule.java index c630f053..d4dbb64b 100644 --- a/Plugin/src/main/java/dev/lrxh/neptune/game/kit/impl/KitRule.java +++ b/Plugin/src/main/java/dev/lrxh/neptune/game/kit/impl/KitRule.java @@ -15,6 +15,7 @@ public enum KitRule implements IKitRule { BOXING(Material.DIAMOND_CHESTPLATE, "Allow/Deny Boxing", "Boxing", "boxing"), ALLOW_ARENA_BREAK(Material.WOODEN_AXE, "Allow Players to break blocks from the arena (They need to be whitelisted)", "Arena Break", "arenaBreak"), DAMAGE(Material.DIAMOND_SWORD, "Allow/Deny Players to take Damage", "Damage", "damage"), + PROJECTILE_DAMAGE(Material.ARROW, "Allow/Deny Players to take damage from projectiles (arrows, tridents, etc.)", "Projectile Damage", "projectileDamage"), BEST_OF_THREE(Material.GOLDEN_AXE, "If enabled Players would need to win 3 times", "Best of 3", "bestOfThree"), SATURATION_HEAL(Material.GOLDEN_APPLE, "If Players should regen from saturation", "Natural Regeneration", "saturationHeal"), SHOW_HP(Material.APPLE, "If players should see their enemies health under their name", "Show Health", "showHP"), diff --git a/Plugin/src/main/java/dev/lrxh/neptune/game/match/listener/MatchListener.java b/Plugin/src/main/java/dev/lrxh/neptune/game/match/listener/MatchListener.java index 7cc19ff1..0ce789bb 100644 --- a/Plugin/src/main/java/dev/lrxh/neptune/game/match/listener/MatchListener.java +++ b/Plugin/src/main/java/dev/lrxh/neptune/game/match/listener/MatchListener.java @@ -563,45 +563,50 @@ public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) { @EventHandler public void onEntityDamageByEntityMonitor(EntityDamageByEntityEvent event) { - if (event.getDamager() instanceof Player attacker && event.getEntity() instanceof Player player) { - Profile attackerProfile = API.getProfile(attacker.getUniqueId()); - Profile profile = API.getProfile(player); - if (profile == null || attackerProfile == null) - return; + if (!(event.getEntity() instanceof Player player)) + return; - if (profile.getState().equals(ProfileState.IN_CUSTOM)) { - return; - } + Player attacker = getResponsiblePlayer(event); + if (attacker == null || attacker.equals(player)) + return; - // Cancel if either player is not in match - if (!isPlayerInMatch(profile) || !isPlayerInMatch(attackerProfile)) { - event.setCancelled(true); - return; - } + Profile attackerProfile = API.getProfile(attacker.getUniqueId()); + Profile profile = API.getProfile(player); + if (profile == null || attackerProfile == null) + return; - Match match = profile.getMatch(); + if (profile.getState().equals(ProfileState.IN_CUSTOM)) { + return; + } - if (!attackerProfile.getMatch().getUuid().equals(match.getUuid())) { - event.setCancelled(true); - return; - } + // Cancel if either player is not in match + if (!isPlayerInMatch(profile) || !isPlayerInMatch(attackerProfile)) { + event.setCancelled(true); + return; + } - if (match.getParticipant(attacker).isDead()) { - event.setCancelled(true); - } + Match match = profile.getMatch(); - if (match instanceof TeamFightMatch teamFightMatch) { - if (teamFightMatch.onSameTeam(player.getUniqueId(), attacker.getUniqueId())) { - event.setCancelled(true); - } - } + if (!attackerProfile.getMatch().getUuid().equals(match.getUuid())) { + event.setCancelled(true); + return; + } + + if (match.getParticipant(attacker).isDead()) { + event.setCancelled(true); + } - if (!match.getState().equals(MatchState.IN_ROUND)) { + if (match instanceof TeamFightMatch teamFightMatch) { + if (teamFightMatch.onSameTeam(player.getUniqueId(), attacker.getUniqueId())) { event.setCancelled(true); } + } - match.getParticipant(player.getUniqueId()).setLastAttacker(match.getParticipant(attacker.getUniqueId())); + if (!match.getState().equals(MatchState.IN_ROUND)) { + event.setCancelled(true); } + + match.getParticipant(player.getUniqueId()).setLastAttacker(match.getParticipant(attacker.getUniqueId())); } @EventHandler(ignoreCancelled = true) @@ -785,7 +790,11 @@ public void onEntityDamage(EntityDamageEvent event) { } } - if (!kit.is(KitRule.DAMAGE)) { + boolean projectileDamage = event instanceof EntityDamageByEntityEvent damageEvent + && damageEvent.getDamager() instanceof Projectile; + KitRule damageRule = projectileDamage ? KitRule.PROJECTILE_DAMAGE : KitRule.DAMAGE; + + if (!kit.is(damageRule)) { event.setDamage(0); return; }