Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Punishes players who are not participating in the siege with war sick… #28

Merged
merged 38 commits into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d738229
Punishes players who are not participating in the siege with war sick…
ceeedric Jan 14, 2021
3079bea
Fixes players still getting sickness even after leaving in time
ceeedric Jan 14, 2021
4b3f35d
Fixes small typo
ceeedric Jan 14, 2021
f821488
Flip checks around
ceeedric Jan 14, 2021
d8ff436
Add "" after default config values
ceeedric Jan 14, 2021
7b2923b
Moving sieges list so it is below the permission check
ceeedric Jan 14, 2021
075cc35
Merge branch 'master' of https://github.com/TownyAdvanced/SiegeWar in…
ceeedric Jan 14, 2021
99b7de8
Rebase
ceeedric Jan 14, 2021
9960216
Fixes players still getting sickness even after leaving in time
ceeedric Jan 14, 2021
e9599d7
Fixes small typo
ceeedric Jan 14, 2021
16ee433
Flip checks around
ceeedric Jan 14, 2021
9ce395b
Add "" after default config values
ceeedric Jan 14, 2021
d275014
Moving sieges list so it is below the permission check
ceeedric Jan 14, 2021
033f450
Merge remote-tracking branch 'origin/war_sickness' into war_sickness
ceeedric Jan 14, 2021
c576ff1
Merge branch 'master' of https://github.com/TownyAdvanced/SiegeWar in…
ceeedric Jan 14, 2021
b5b416b
Sickness is now disabled by default
ceeedric Jan 15, 2021
36a7267
Renamed getSiegesAt to getActiveSiegesAt and added isActive check
ceeedric Jan 16, 2021
99b1ed3
Adds military rank check
ceeedric Jan 20, 2021
1b9bf59
Merge branch 'master' into war_sickness
ceeedric Jan 20, 2021
30c7873
attempt to fix english.yml
ceeedric Jan 21, 2021
d7ee8c9
Delete english.yml
ceeedric Jan 21, 2021
19e111e
Create english.yml
ceeedric Jan 21, 2021
57bf127
Rebase
ceeedric Jan 14, 2021
004df01
Fixes players still getting sickness even after leaving in time
ceeedric Jan 14, 2021
c0de3e5
Fixes small typo
ceeedric Jan 14, 2021
0f4445c
Flip checks around
ceeedric Jan 14, 2021
255fad7
Add "" after default config values
ceeedric Jan 14, 2021
9650ab6
Moving sieges list so it is below the permission check
ceeedric Jan 14, 2021
0750f9a
rebase
ceeedric Jan 14, 2021
f7dbc06
Flip checks around
ceeedric Jan 14, 2021
9d11a9f
Merge branch 'master' of https://github.com/TownyAdvanced/SiegeWar in…
ceeedric Jan 14, 2021
c3b4210
Sickness is now disabled by default
ceeedric Jan 15, 2021
3eeac57
Renamed getSiegesAt to getActiveSiegesAt and added isActive check
ceeedric Jan 16, 2021
4d4934c
Adds military rank check
ceeedric Jan 20, 2021
3277969
attempt to fix english.yml
ceeedric Jan 21, 2021
2ec13cf
Merge remote-tracking branch 'origin/war_sickness' into war_sickness
ceeedric Jan 21, 2021
ea3af29
Delete english.yml
ceeedric Jan 21, 2021
8cb7258
Add files via upload
ceeedric Jan 21, 2021
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
11 changes: 11 additions & 0 deletions src/main/java/com/gmail/goosius/siegewar/SiegeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

import com.gmail.goosius.siegewar.utils.SiegeWarDistanceUtil;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
Expand Down Expand Up @@ -293,5 +294,15 @@ public static Set<Player> getPlayersInBannerControlSessions() {
}
return result;
}

public static List<Siege> getSiegesAt(Location location) {
ceeedric marked this conversation as resolved.
Show resolved Hide resolved
List<Siege> siegesAtLocation = new ArrayList<>();
for (Siege siege : sieges.values()) {
if (SiegeWarDistanceUtil.isInSiegeZone(location, siege)) {
siegesAtLocation.add(siege);
}
}
return siegesAtLocation;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public void onShortTime(NewShortTimeEvent event) {
SiegeWarTimerTaskController.evaluateBannerControl();
SiegeWarTimerTaskController.evaluateTacticalVisibility();
SiegeWarTimerTaskController.evaluateTimedSiegeOutcomes();
SiegeWarTimerTaskController.punishNonSiegeParticipantsInSiegeZone();
SiegeHUDManager.updateHUDs();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,38 @@ public enum ConfigNodes {
"true",
"",
"# If this value is true, then a town under occupation cannot unclaim.",
"# This setting is recommended, to avoid occupation escape exploits.");
"# This setting is recommended, to avoid occupation escape exploits."),

PUNISH_NON_SIEGE_PARTICIPANTS_IN_SIEGE_ZONE(
"punish_non_siege_participants_in_siege_zone",
"",
"############################################################",
"# +------------------------------------------------------+ #",
"# | War Sickness | #",
"# +------------------------------------------------------+ #",
"############################################################",
""),

ENABLE_SICKNESS(
"punish_non_siege_participants_in_siege_zone.enable_sickness",
"true",
ceeedric marked this conversation as resolved.
Show resolved Hide resolved
"",
"# If true, players that are not participating in a siege will receive war sickness",
ceeedric marked this conversation as resolved.
Show resolved Hide resolved
"# A non-participant is a player who does not have a military rank, is not allied to either the attacker or the defender, or is peaceful.",
"# There are two types of war sickness, full and special.",
"# Special war sickness is only given if a non-participant is at his town that happened to be in a siege zone",
"# - Effects: Weakness V",
"# Full sickness is given to all players that are not allied to either side, do not have a military rank, or is peaceful, and are not in their own town.",
"# - Effects: Nausea V, Poison V, Weakness V, Slowness III, Mining Fatigue III"
),

SECONDS_BEFORE_SICKNESS(
"punish_non_siege_participants_in_siege_zone.seconds_warning",
"5",
ceeedric marked this conversation as resolved.
Show resolved Hide resolved
"",
"# This is how many seconds a player has to leave the siege zone before he gets war sickness",
"# If this is set to 0, no warn will be given and non-participants will receive war sickness instantly, if enabled"
);

private final String Root;
private final String Default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,12 @@ public static boolean getWarCommonPeacefulTownsAllowedToTogglePVP() {
return Settings.getBoolean(ConfigNodes.PEACEFUL_TOWNS_ALLOWED_TO_TOGGLE_PVP);
}

public static boolean getPunishingNonSiegeParticipantsInSiegeZone() {
return Settings.getBoolean(ConfigNodes.ENABLE_SICKNESS);
}

public static int getSicknessWarningTimeInTicks() {
return Settings.getInt(ConfigNodes.SECONDS_BEFORE_SICKNESS) * 20;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,11 @@ public static void punishPeacefulPlayersInActiveSiegeZones() {
TownPeacefulnessUtil.punishPeacefulPlayersInActiveSiegeZones();
}
}

public static void punishNonSiegeParticipantsInSiegeZone() {
if (SiegeWarSettings.getPunishingNonSiegeParticipantsInSiegeZone()) {
SiegeWarSicknessUtil.punishNonSiegeParticipantsInSiegeZone();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
package com.gmail.goosius.siegewar.utils;

import com.gmail.goosius.siegewar.SiegeController;
import com.gmail.goosius.siegewar.enums.SiegeWarPermissionNodes;
import com.gmail.goosius.siegewar.objects.Siege;
import com.gmail.goosius.siegewar.settings.SiegeWarSettings;
import com.gmail.goosius.siegewar.settings.Translation;
import com.palmergames.bukkit.towny.Towny;
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.TownySettings;
import com.palmergames.bukkit.towny.TownyUniverse;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.util.BukkitTools;
import com.palmergames.util.TimeTools;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import java.util.ArrayList;
import java.util.List;

public class SiegeWarSicknessUtil {

public static void punishNonSiegeParticipantsInSiegeZone() {

for (Player player : BukkitTools.getOnlinePlayers()) {
Location location = player.getLocation();

// Players immune to war nausea won't be punished
if (player.hasPermission(SiegeWarPermissionNodes.SIEGEWAR_IMMUNE_TO_WAR_NAUSEA.getNode()))
continue;

List<Siege> sieges = SiegeController.getSiegesAt(location);

// not in a siege zone
if (sieges.isEmpty())
continue;

Resident resident = TownyUniverse.getInstance().getResident(player.getUniqueId());

if (resident == null)
continue;

boolean allowedInAnyOverlappingSiege = false;
try {
for (Siege siege : sieges) {
if (isSiegeParticipant(resident, siege)) {
allowedInAnyOverlappingSiege = true;
break;
}
}

if (!allowedInAnyOverlappingSiege) {
if (isInOwnClaims(resident)) {
punishWithSpecialWarSickness(player);
} else {
punishWithFullWarSickness(player);
}

}
} catch (NotRegisteredException ignored) {}

}

}

public static void punishWithFullWarSickness(Player player) {
final int effectDurationTicks = (int)(TimeTools.convertToTicks(TownySettings.getShortInterval() + 5));
if (SiegeWarSettings.getSicknessWarningTimeInTicks() / 20 >= 1) {
player.sendMessage(Translation.of("plugin_prefix") + Translation.of("msg_you_will_get_sickness",
SiegeWarSettings.getSicknessWarningTimeInTicks() / 20));
}
Towny.getPlugin().getServer().getScheduler().runTaskLater(Towny.getPlugin(), new Runnable() {
public void run() {
try {
Resident resident = TownyUniverse.getInstance().getResident(player.getUniqueId());
List<Siege> sieges = SiegeController.getSiegesAt(player.getLocation());
boolean allowedInAnyOverlappingSiege = false;
for (Siege siege : sieges) {
if (isSiegeParticipant(resident, siege)) {
allowedInAnyOverlappingSiege = true;
break;
}
}

if (!allowedInAnyOverlappingSiege && SiegeWarDistanceUtil.isLocationInActiveSiegeZone(player.getLocation())) {
// still in siege zone
List<PotionEffect> potionEffects = new ArrayList<>();
potionEffects.add(new PotionEffect(PotionEffectType.CONFUSION, effectDurationTicks, 4));
potionEffects.add(new PotionEffect(PotionEffectType.POISON, effectDurationTicks, 4));
potionEffects.add(new PotionEffect(PotionEffectType.WEAKNESS, effectDurationTicks, 4));
potionEffects.add(new PotionEffect(PotionEffectType.SLOW, effectDurationTicks, 2));
potionEffects.add(new PotionEffect(PotionEffectType.SLOW_DIGGING, effectDurationTicks, 2));
player.addPotionEffects(potionEffects);
player.sendMessage(Translation.of("plugin_prefix") + Translation.of("msg_you_received_war_sickness"));
}
} catch (NotRegisteredException ignored) {}
}
}, SiegeWarSettings.getSicknessWarningTimeInTicks());
}

public static void punishWithSpecialWarSickness(Player player) {
final int effectDurationTicks = (int)(TimeTools.convertToTicks(TownySettings.getShortInterval() + 5));
Towny.getPlugin().getServer().getScheduler().runTask(Towny.getPlugin(), new Runnable() {
public void run() {
player.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, effectDurationTicks, 4));
}
});
}

public static boolean isSiegeParticipant(Resident resident, Siege siege) throws NotRegisteredException {

if (!resident.hasTown())
return false;

TownyUniverse universe = TownyUniverse.getInstance();
Town defendingTown = siege.getDefendingTown();
Town residentTown = resident.getTown();
Nation attackingNation = siege.getAttackingNation();

if (residentTown == defendingTown && universe.getPermissionSource().testPermission(resident.getPlayer(),
SiegeWarPermissionNodes.SIEGEWAR_TOWN_SIEGE_POINTS.getNode())) {
// Player is defending their own town
return true;
}

if (residentTown.hasNation() &&
(attackingNation == residentTown.getNation() || attackingNation.hasMutualAlly(residentTown.getNation()))) {
// Player is attacking
return true;

}

if (defendingTown.hasNation()
&& (defendingTown.getNation() == residentTown.getNation()
|| defendingTown.getNation().hasMutualAlly(residentTown.getNation()))) {
// Player is defending another town in the nation
return true;
}

return false;
}

private static boolean isInOwnClaims(Resident resident) throws NotRegisteredException {
Location location = resident.getPlayer().getLocation();
if (!resident.hasTown())
return false;

if (TownyAPI.getInstance().isWilderness(location))
return false;

return TownyAPI.getInstance().getTownBlock(location).getTown().equals(resident.getTown());
}

}
23 changes: 3 additions & 20 deletions src/main/resources/english.yml
Original file line number Diff line number Diff line change
Expand Up @@ -227,23 +227,6 @@ msg_swa_resident_doesnt_have_control: "&cResident %s doesn't have control."
msg_swa_set_plunder_success: '&bSet plundered to %s for %s.'
msg_swa_set_captured_success: '&bSet captured to %s for %s.'

siege_status_in_progress: 'In Progress'
siege_status_attacker_win: 'Attacker Win'
siege_status_defender_win: 'Defender Win'
siege_status_attacker_abandon: 'Attacker Abandon'
siege_status_defender_surrender: 'Defender Surrender'
siege_status_pending_attacker_abandon: 'Pending Attacker Abandon'
siege_status_pending_defender_surrender: 'Pending Defender Surrender'
siege_status_unknown: 'Unknown'

dynmap_siege_title: 'Siege: %s'
dynmap_siege_attacker: 'Attacker: %s'
dynmap_siege_defender: 'Defender: %s'
dynmap_siege_points: 'Points: %d'
dynmap_siege_banner_control: 'Banner Control: %s'
dynmap_siege_status: 'Status: %s'
dynmap_siege_status_in_progress: 'In Progress'
dynmap_siege_status_pending_surrender: 'Pending Surrender'
dynmap_siege_status_pending_abandon: 'Pending Abandon'
dynmap_siege_time_left: 'Time Left: %s'
dynmap_siege_war_chest: 'War Chest: %s'
#War sickness
msg_you_received_war_sickness: '&cYou are not a participant of this siege and cannot be in the Siege Zone. Please leave to remove the war sickness. Common causes of war sickness: being in a peaceful town, not having a military rank or not being allied to either side.'
msg_you_will_get_sickness: '&c&cYou are not a participant of this siege and cannot be in the Siege Zone. Please leave or you will receive war sickness in %s seconds.'