Minuteman updates to include playtime clause

This commit is contained in:
Aubri Seebauer committed 2023-05-02 13:55:16 -04:00
1 parent 392ff18aaa
commit a01b7e909d
6 files changed
+119 -80

No files matched your search

@@ -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());
}
}
@@ -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) {
@@ -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;
}
}
}
@@ -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;
}
}
}
@@ -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;
}
}
}