From ff6ad908974830e489816abfb9994eec3bcfafc3 Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Sun, 6 Mar 2022 10:10:22 -0700 Subject: [PATCH 1/4] Introduced an element of randomness to the scheduleTeleport() method. --- .../factionsystem/utils/extended/Scheduler.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/dansplugins/factionsystem/utils/extended/Scheduler.java b/src/main/java/dansplugins/factionsystem/utils/extended/Scheduler.java index e358f8456..a7b0f2acd 100644 --- a/src/main/java/dansplugins/factionsystem/utils/extended/Scheduler.java +++ b/src/main/java/dansplugins/factionsystem/utils/extended/Scheduler.java @@ -4,6 +4,7 @@ */ package dansplugins.factionsystem.utils.extended; +import java.util.Random; import java.util.concurrent.TimeUnit; import org.bukkit.Bukkit; @@ -101,7 +102,13 @@ private boolean isFactionExceedingTheirDemesneLimit(Faction faction) { public void scheduleTeleport(Player player, Location destinationLocation) { final int teleport_delay = LocalConfigService.getInstance().getInt("teleportDelay"); DelayedTeleportTask delayedTeleportTask = new DelayedTeleportTask(teleport_delay, player, destinationLocation); - delayedTeleportTask.runTaskLater(MedievalFactions.getInstance(), teleport_delay * 20); + delayedTeleportTask.runTaskLater(MedievalFactions.getInstance(), teleport_delay * getRandomNumberBetween(15, 25)); + } + + private int getRandomNumberBetween(int num1, int num2) { + Random random = new Random(); + int span = num2 - num1; + return random.nextInt(span) + num1; } private class DelayedTeleportTask extends BukkitRunnable { From 742b79c70aada15fcc1d6d97e2bab65a4b6f7e1f Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Sun, 6 Mar 2022 17:28:40 +0000 Subject: [PATCH 2/4] Moved the teleport alert and made it reference the teleportDelay config option. --- .../java/dansplugins/factionsystem/commands/HomeCommand.java | 1 - .../java/dansplugins/factionsystem/utils/extended/Scheduler.java | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/dansplugins/factionsystem/commands/HomeCommand.java b/src/main/java/dansplugins/factionsystem/commands/HomeCommand.java index 0d30ca634..c80fb0864 100644 --- a/src/main/java/dansplugins/factionsystem/commands/HomeCommand.java +++ b/src/main/java/dansplugins/factionsystem/commands/HomeCommand.java @@ -51,7 +51,6 @@ public void execute(Player player, String[] args, String key) { player.sendMessage(translate("&c" + getText("HomeClaimedByAnotherFaction"))); return; } - player.sendMessage(translate("&a" + getText("TeleportingAlert"))); Scheduler.getInstance().scheduleTeleport(player, faction.getFactionHome()); } diff --git a/src/main/java/dansplugins/factionsystem/utils/extended/Scheduler.java b/src/main/java/dansplugins/factionsystem/utils/extended/Scheduler.java index a7b0f2acd..d7c05ff3d 100644 --- a/src/main/java/dansplugins/factionsystem/utils/extended/Scheduler.java +++ b/src/main/java/dansplugins/factionsystem/utils/extended/Scheduler.java @@ -101,6 +101,7 @@ private boolean isFactionExceedingTheirDemesneLimit(Faction faction) { public void scheduleTeleport(Player player, Location destinationLocation) { final int teleport_delay = LocalConfigService.getInstance().getInt("teleportDelay"); + player.sendMessage(ChatColor.AQUA + "Teleporting in " + teleport_delay + " seconds..."); DelayedTeleportTask delayedTeleportTask = new DelayedTeleportTask(teleport_delay, player, destinationLocation); delayedTeleportTask.runTaskLater(MedievalFactions.getInstance(), teleport_delay * getRandomNumberBetween(15, 25)); } From 92ce2de12c043979b1da96d4addc4b43b891f7a9 Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Sun, 6 Mar 2022 17:31:39 +0000 Subject: [PATCH 3/4] Fixed teleportDelay being referenced as a boolean when being set in the local config service. --- .../factionsystem/services/LocalConfigService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/dansplugins/factionsystem/services/LocalConfigService.java b/src/main/java/dansplugins/factionsystem/services/LocalConfigService.java index 5a7dfe420..5c64b4b34 100644 --- a/src/main/java/dansplugins/factionsystem/services/LocalConfigService.java +++ b/src/main/java/dansplugins/factionsystem/services/LocalConfigService.java @@ -210,7 +210,8 @@ public void setConfigOption(String option, String value, CommandSender sender) { || option.equalsIgnoreCase("factionMaxNameLength") || option.equalsIgnoreCase("factionMaxNumberGates") || option.equalsIgnoreCase("factionMaxGateArea") - || option.equalsIgnoreCase("maxClaimRadius")) { + || option.equalsIgnoreCase("maxClaimRadius") + || option.equalsIgnoreCase("teleportDelay")) { getConfig().set(option, Integer.parseInt(value)); sender.sendMessage(ChatColor.GREEN + LocalLocaleService.getInstance().getText("IntegerSet")); } else if (option.equalsIgnoreCase("mobsSpawnInFactionTerritory") @@ -234,8 +235,7 @@ public void setConfigOption(String option, String value, CommandSender sender) { || option.equalsIgnoreCase("limitLand") || option.equalsIgnoreCase("factionsCanSetPrefixColors") || option.equalsIgnoreCase("playersLosePowerOnDeath") - || option.equalsIgnoreCase("bonusPowerEnabled") - || option.equalsIgnoreCase("teleportDelay")) { + || option.equalsIgnoreCase("bonusPowerEnabled")) { getConfig().set(option, Boolean.parseBoolean(value)); sender.sendMessage(ChatColor.GREEN + LocalLocaleService.getInstance().getText("BooleanSet")); } else if (option.equalsIgnoreCase("factionOwnerMultiplier") From 195e8ff72d9d49dee20285d295e96a4030f6b5fb Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Sun, 6 Mar 2022 21:46:13 -0700 Subject: [PATCH 4/4] Added a cast for the teleport delay to a long. --- .../dansplugins/factionsystem/utils/extended/Scheduler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/dansplugins/factionsystem/utils/extended/Scheduler.java b/src/main/java/dansplugins/factionsystem/utils/extended/Scheduler.java index d7c05ff3d..6bf7f7173 100644 --- a/src/main/java/dansplugins/factionsystem/utils/extended/Scheduler.java +++ b/src/main/java/dansplugins/factionsystem/utils/extended/Scheduler.java @@ -103,7 +103,7 @@ public void scheduleTeleport(Player player, Location destinationLocation) { final int teleport_delay = LocalConfigService.getInstance().getInt("teleportDelay"); player.sendMessage(ChatColor.AQUA + "Teleporting in " + teleport_delay + " seconds..."); DelayedTeleportTask delayedTeleportTask = new DelayedTeleportTask(teleport_delay, player, destinationLocation); - delayedTeleportTask.runTaskLater(MedievalFactions.getInstance(), teleport_delay * getRandomNumberBetween(15, 25)); + delayedTeleportTask.runTaskLater(MedievalFactions.getInstance(), (long) (teleport_delay * getRandomNumberBetween(15, 25))); } private int getRandomNumberBetween(int num1, int num2) {