Skip to content

Commit

Permalink
Merge pull request #1380 from Dans-Plugins/introducing-randomness-to-…
Browse files Browse the repository at this point in the history
…scheduled-teleport

Introduced an element of randomness to the scheduleTeleport() method.
  • Loading branch information
dmccoystephenson authored Mar 7, 2022
2 parents 6bb2d0e + 195e8ff commit d4e4e75
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,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 + Locale.get("IntegerSet"));
} else if (option.equalsIgnoreCase("mobsSpawnInFactionTerritory")
Expand All @@ -235,8 +236,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 + Locale.get("BooleanSet"));
} else if (option.equalsIgnoreCase("factionOwnerMultiplier")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package dansplugins.factionsystem.utils.extended;

import java.util.Random;
import java.util.concurrent.TimeUnit;

import org.bukkit.Bukkit;
Expand Down Expand Up @@ -100,8 +101,15 @@ 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 * 20);
delayedTeleportTask.runTaskLater(MedievalFactions.getInstance(), (long) (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 {
Expand Down

0 comments on commit d4e4e75

Please sign in to comment.