Browse Source

added option for defining a max amount of users getting a payout per ip

Closes #46
MasterCake 4 years ago
parent
commit
43ab5a0336

+ 5 - 13
Plugin/src/main/java/de/Linus122/TimeIsMoney/Main.java

@@ -74,10 +74,6 @@ public class Main extends JavaPlugin {
 	 * The list of worlds where the payout feature will be disabled.
 	 */
 	private static List<String> disabledWorlds;
-	/**
-	 * The IPs of each UUID.
-	 */
-	private static final HashMap<String, UUID> boundIPs = new HashMap<>();
 	/**
 	 * The payouts listed in the config.
 	 */
@@ -156,10 +152,7 @@ public class Main extends JavaPlugin {
 			try {
 				for (Player p : Bukkit.getOnlinePlayers()) {
 					if (disabledWorlds.contains(p.getWorld().getName())) continue;
-
-					if (!boundIPs.containsKey(p.getAddress().getHostString())) {
-						boundIPs.put(p.getAddress().getHostString(), p.getUniqueId());
-					}
+					
 					if (onlineSeconds.containsKey(p.getUniqueId())) {
 						
 						onlineSeconds.put(p.getUniqueId(), onlineSeconds.get(p.getUniqueId()) + 1);
@@ -375,11 +368,10 @@ public class Main extends JavaPlugin {
 		}
 		
 		if (!finalconfig.getBoolean("allow-multiple-accounts")) {
-			if (boundIPs.containsKey(p.getAddress().getHostString())) {
-				if (!boundIPs.get(p.getAddress().getHostString()).equals(p.getUniqueId())) {
-					sendMessage(p, finalconfig.getString("message_multiple_ips"));
-					return;
-				}
+			int same_address_count = (int) Bukkit.getOnlinePlayers().stream().filter(player -> player.getAddress().getHostString().equals(p.getAddress().getHostString())).count();
+			if (same_address_count > finalconfig.getInt("max-multiple-accounts")) {
+				sendMessage(p, finalconfig.getString("message_multiple_ips"));
+				return;
 			}
 		}
 		

+ 2 - 0
Plugin/src/main/resources/config.yml

@@ -20,6 +20,8 @@ store-money-in-bank: false
 
 # Define if multiple accounts should get payed with the same ip-address. You may disable this if your players are using multiple accounts per ip.
 allow-multiple-accounts: true
+# Option to increase the maximal amount of players of the same IP getting a payout. Only applies when allow-multiple-accounts is set to false.
+max-multiple-accounts: 1
 
 # Payouts will be delivered by "chance" instead "permission".
 choose-payout-by-chance: false