From a01b7e909d7561b0e6385eaa33d22b1c3288b0bb Mon Sep 17 00:00:00 2001 From: Aubri Seebauer Date: Tue, 2 May 2023 13:55:16 -0400 Subject: [PATCH] Minuteman updates to include playtime clause --- resources/config.yml | 8 +- .../java/me/ShermansWorld/AlathraWar/War.java | 4 +- .../AlathraWar/commands/CommandHelper.java | 27 ++++++- .../AlathraWar/commands/RaidCommands.java | 75 +++++++++++-------- .../AlathraWar/commands/SiegeCommands.java | 42 ++++++----- .../AlathraWar/commands/WarCommands.java | 43 +++++------ 6 files changed, 119 insertions(+), 80 deletions(-) diff --git a/resources/config.yml b/resources/config.yml index e646db3..9c5f739 100644 --- a/resources/config.yml +++ b/resources/config.yml @@ -1,4 +1,8 @@ #Minimum time in days a player must have joined ago to join any war or event. +#Set to 0 to disable check minimumPlayerAge: 4 -#how long should a bettering ram open a door (in seconds) -batteringRamEffectiveness: 600 \ No newline at end of file +#Minimum playtime in hours a player must have in hours to join a war/siege/raid +#Set to 0 to disable check +minimumPlayTime: 12 +#How long should a bettering ram open a door (in seconds) +batteringRamEffectiveness: 10 \ No newline at end of file diff --git a/src/main/java/me/ShermansWorld/AlathraWar/War.java b/src/main/java/me/ShermansWorld/AlathraWar/War.java index 4ccec2a..09d4543 100644 --- a/src/main/java/me/ShermansWorld/AlathraWar/War.java +++ b/src/main/java/me/ShermansWorld/AlathraWar/War.java @@ -245,8 +245,8 @@ public class War { Town town = TownyAPI.getInstance().getTown(townString); if (town != null) { for (Resident res : town.getResidents()) { - //Minuteman countermeasure! - if (System.currentTimeMillis() - CommandHelper.getPlayerJoinDate(res.getName()) > 86400000L * Main.getInstance().getConfig().getInt("minimumPlayerAge") ) { + //Minuteman countermeasure! if they are they get skipped + if (CommandHelper.isPlayerMinuteman(res.getName()) == 0) { returnList.add(res.getName()); } } diff --git a/src/main/java/me/ShermansWorld/AlathraWar/commands/CommandHelper.java b/src/main/java/me/ShermansWorld/AlathraWar/commands/CommandHelper.java index a449822..eb4b14a 100644 --- a/src/main/java/me/ShermansWorld/AlathraWar/commands/CommandHelper.java +++ b/src/main/java/me/ShermansWorld/AlathraWar/commands/CommandHelper.java @@ -12,6 +12,7 @@ import me.ShermansWorld.AlathraWar.data.SiegeData; import me.ShermansWorld.AlathraWar.data.WarData; import me.ShermansWorld.AlathraWar.items.WarItems; import org.bukkit.Bukkit; +import org.bukkit.Statistic; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -194,9 +195,31 @@ public class CommandHelper { return out; } - public static long getPlayerJoinDate(String player) { + /** + * + * @param player player to check + * @return 0, 1, 2 (good to go, insufficient join, insufficient playtime) + */ + public static int isPlayerMinuteman(String player) { Resident res = TownyAPI.getInstance().getResident(player); - return res.getRegistered(); + if(res != null) { + //get registration time + long regTime = res.getRegistered(); + int playTicks = Bukkit.getPlayer(res.getUUID()).getStatistic(Statistic.PLAY_ONE_MINUTE); + int out = 0; + if(Main.getInstance().getConfig().getInt("minimumPlayerAge") > 0) { + //compare the join date, if they joined less that min age ago it is true + if ((System.currentTimeMillis() - regTime) < 86400000L * Main.getInstance().getConfig().getInt("minimumPlayerAge")) out = 1; + } + if(Main.getInstance().getConfig().getInt("minimumPlayTime") > 0) { + //check playtime, if its less than min its true + if(playTicks < (Main.getInstance().getConfig().getInt("minimumPlayTime") * (60 * 60 * 20))) out = 2; + } + + return out; + } + //if the player doesnt exist just return true + return true; } protected static boolean logCommand(CommandSender sender, String label, String[] args) { diff --git a/src/main/java/me/ShermansWorld/AlathraWar/commands/RaidCommands.java b/src/main/java/me/ShermansWorld/AlathraWar/commands/RaidCommands.java index 5efa144..13b0c17 100644 --- a/src/main/java/me/ShermansWorld/AlathraWar/commands/RaidCommands.java +++ b/src/main/java/me/ShermansWorld/AlathraWar/commands/RaidCommands.java @@ -97,24 +97,32 @@ public class RaidCommands implements CommandExecutor { return; } - //Minutemen countermeasures, 86400 * 4 time. 86400 seconds in a day, 4 days min playtime + //Minuteman countermeasures + int minuteman = CommandHelper.isPlayerMinuteman(raidOwner.getName()); + boolean override = false; if (admin) { - if (System.currentTimeMillis() - CommandHelper.getPlayerJoinDate(raidOwner.getName()) < 86400000L * Main.getInstance().getConfig().getInt("minimumPlayerAge") ) { - if(args.length >= 5) { + if (args.length >= 6) { + if (Boolean.parseBoolean(args[5])) { //player has joined to recently p.sendMessage(ChatColor.RED + "Warning! Ignoring Minuteman Countermeasure!"); - } else { - //player has joined to recently - p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining."); - raidOwner.getPlayer().sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining."); - return; + override = true; } } - } else { - if (System.currentTimeMillis() - CommandHelper.getPlayerJoinDate(raidOwner.getName()) < 86400000L * Main.getInstance().getConfig().getInt("minimumPlayerAge") ) { - //player has joined to recently - p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining."); - return; + } + //override? + if(!override) { + if (minuteman != 0) { + if (minuteman == 1) { + //player has joined to recently + if (admin) p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining."); + raidOwner.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining."); + return; + } else if (minuteman == 2) { + //player has played too little + if (admin) p.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play."); + raidOwner.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play."); + return; + } } } @@ -387,30 +395,31 @@ public class RaidCommands implements CommandExecutor { } //Minutemen countermeasures, 86400 * 4 time. 86400 seconds in a day, 4 days min playtime + //also 12 hours min platim by default + int minuteman = CommandHelper.isPlayerMinuteman(joiner.getName()); + boolean override = false; if (admin) { - if (System.currentTimeMillis() - CommandHelper.getPlayerJoinDate(args[3]) < 86400000L * Main.getInstance().getConfig().getInt("minimumPlayerAge") ) { - if(args.length >= 6) { - if (Boolean.parseBoolean(args[5])) { - //player has joined to recently - p.sendMessage(ChatColor.RED + "Warning! Ignoring Minuteman Countermeasure!"); - } else { - //player has joined to recently - p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining."); - joiner.getPlayer().sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining."); - return; - } - } else { + if (args.length >= 6) { + if (Boolean.parseBoolean(args[5])) { //player has joined to recently - p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining."); - joiner.getPlayer().sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining."); - return; + p.sendMessage(ChatColor.RED + "Warning! Ignoring Minuteman Countermeasure!"); + override = true; } } - } else { - if (System.currentTimeMillis() - CommandHelper.getPlayerJoinDate(joiner.getName()) < 86400000L * Main.getInstance().getConfig().getInt("minimumPlayerAge") ) { - //player has joined to recently - p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining."); - return; + } + if(!override) { + if (minuteman != 0) { + if (minuteman == 1) { + //player has joined to recently + if (admin) p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining."); + joiner.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining."); + return; + } else if (minuteman == 2) { + //player has played too little + if (admin) p.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play."); + joiner.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play."); + return; + } } } diff --git a/src/main/java/me/ShermansWorld/AlathraWar/commands/SiegeCommands.java b/src/main/java/me/ShermansWorld/AlathraWar/commands/SiegeCommands.java index e74f0b6..1d6e9f4 100644 --- a/src/main/java/me/ShermansWorld/AlathraWar/commands/SiegeCommands.java +++ b/src/main/java/me/ShermansWorld/AlathraWar/commands/SiegeCommands.java @@ -120,30 +120,32 @@ public class SiegeCommands implements CommandExecutor { } //Minutemen countermeasures, 86400 * 4 time. 86400 seconds in a day, 4 days min playtime + //Minuteman countermeasures + int minuteman = CommandHelper.isPlayerMinuteman(siegeOwner.getName()); + boolean override = false; if (admin) { - if (System.currentTimeMillis() - CommandHelper.getPlayerJoinDate(siegeOwner.getName()) < 86400000L * Main.getInstance().getConfig().getInt("minimumPlayerAge") ) { - if(args.length >= 5) { - if (Boolean.parseBoolean(args[4])) { - //player has joined to recently - sender.sendMessage(ChatColor.RED + "Warning! Ignoring Minuteman Countermeasure!"); - } else { - //player has joined to recently - sender.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining."); - siegeOwner.getPlayer().sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining."); - return; - } - } else { + if (args.length >= 6) { + if (Boolean.parseBoolean(args[5])) { //player has joined to recently - sender.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining."); - siegeOwner.getPlayer().sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining."); - return; + sender.sendMessage(ChatColor.RED + "Warning! Ignoring Minuteman Countermeasure!"); + override = true; } } - } else { - if (System.currentTimeMillis() - CommandHelper.getPlayerJoinDate(siegeOwner.getName()) < 86400000L * Main.getInstance().getConfig().getInt("minimumPlayerAge") ) { - //player has joined to recently - siegeOwner.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining."); - return; + } + //override? + if(!override) { + if (minuteman != 0) { + if (minuteman == 1) { + //player has joined to recently + if (admin) sender.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining."); + siegeOwner.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining."); + return; + } else if (minuteman == 2) { + //player has played too little + if (admin) sender.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play."); + siegeOwner.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play."); + return; + } } } diff --git a/src/main/java/me/ShermansWorld/AlathraWar/commands/WarCommands.java b/src/main/java/me/ShermansWorld/AlathraWar/commands/WarCommands.java index 1d4b737..321dd33 100644 --- a/src/main/java/me/ShermansWorld/AlathraWar/commands/WarCommands.java +++ b/src/main/java/me/ShermansWorld/AlathraWar/commands/WarCommands.java @@ -167,31 +167,32 @@ public class WarCommands implements CommandExecutor { return; } - //Minutemen countermeasures, 86400 * 4 time. 86400 seconds in a day, 4 days min playtime + //Minuteman countermeasures + int minuteman = CommandHelper.isPlayerMinuteman(player.getName()); + boolean override = false; if (admin) { - if (System.currentTimeMillis() - CommandHelper.getPlayerJoinDate(args[3]) < 86400000L * Main.getInstance().getConfig().getInt("minimumPlayerAge") ) { - if(args.length >= 5) { - if (Boolean.parseBoolean(args[4])) { - //player has joined to recently - p.sendMessage(ChatColor.RED + "Warning! Ignoring Minuteman Countermeasure!"); - } else { - //player has joined to recently - p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining."); - res.getPlayer().sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining."); - return; - } - } else { + if (args.length >= 6) { + if (Boolean.parseBoolean(args[5])) { //player has joined to recently - p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining."); - res.getPlayer().sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining."); - return; + p.sendMessage(ChatColor.RED + "Warning! Ignoring Minuteman Countermeasure!"); + override = true; } } - } else { - if (System.currentTimeMillis() - CommandHelper.getPlayerJoinDate(p.getName()) < 86400000L * Main.getInstance().getConfig().getInt("minimumPlayerAge") ) { - //player has joined to recently - p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining."); - return; + } + //override? + if(!override) { + if (minuteman != 0) { + if (minuteman == 1) { + //player has joined to recently + if (admin) p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining."); + player.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining."); + return; + } else if (minuteman == 2) { + //player has played too little + if (admin) p.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play."); + player.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play."); + return; + } } }