Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions Plugin/src/main/java/dev/lrxh/neptune/game/kit/Kit.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ public Kit(String name, List<ItemStack> items, ItemStack icon) {
private HashMap<KitRule, Boolean> rules() {
HashMap<KitRule, Boolean> 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;
Expand Down Expand Up @@ -163,7 +163,15 @@ public List<String> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ public void load() {
}

HashMap<KitRule, Boolean> 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<PotionEffect> potionEffects = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down
Loading