From e11dc680dee959412ad2632cc1de1b7df539b41e Mon Sep 17 00:00:00 2001 From: TfT_02 Date: Wed, 10 Apr 2013 16:39:37 +0200 Subject: [PATCH] Add configurable warmup and cooldown timers for party teleportation Closes #348 --- .../party/teleport/PtpAcceptCommand.java | 2 +- .../commands/party/teleport/PtpCommand.java | 23 +++++++- .../java/com/gmail/nossr50/config/Config.java | 3 +- .../runnables/items/TeleportationWarmup.java | 57 +++++++++++++++++++ src/main/resources/config.yml | 3 +- 5 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/runnables/items/TeleportationWarmup.java diff --git a/src/main/java/com/gmail/nossr50/commands/party/teleport/PtpAcceptCommand.java b/src/main/java/com/gmail/nossr50/commands/party/teleport/PtpAcceptCommand.java index 677e49a62..f6784bbf8 100644 --- a/src/main/java/com/gmail/nossr50/commands/party/teleport/PtpAcceptCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/party/teleport/PtpAcceptCommand.java @@ -58,7 +58,7 @@ public class PtpAcceptCommand implements CommandExecutor { } } - PtpCommand.handlePartyTeleportEvent(target, player); + PtpCommand.handleTeleportWarmup(target, player); return true; } } diff --git a/src/main/java/com/gmail/nossr50/commands/party/teleport/PtpCommand.java b/src/main/java/com/gmail/nossr50/commands/party/teleport/PtpCommand.java index bb43311ab..831c88527 100644 --- a/src/main/java/com/gmail/nossr50/commands/party/teleport/PtpCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/party/teleport/PtpCommand.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Set; +import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -17,6 +18,7 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.events.party.McMMOPartyTeleportEvent; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.party.PartyManager; +import com.gmail.nossr50.runnables.items.TeleportationWarmup; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.commands.CommandUtils; @@ -100,7 +102,7 @@ public class PtpCommand implements TabExecutor { } if (!mcMMOTarget.getPtpConfirmRequired()) { - handlePartyTeleportEvent(player, target); + handleTeleportWarmup(player, target); return; } @@ -146,7 +148,24 @@ public class PtpCommand implements TabExecutor { return true; } - protected static void handlePartyTeleportEvent(Player teleportingPlayer, Player targetPlayer) { + protected static void handleTeleportWarmup(Player teleportingPlayer, Player targetPlayer) { + McMMOPlayer mcMMOPlayer = UserManager.getPlayer(teleportingPlayer); + mcMMOTarget = UserManager.getPlayer(targetPlayer); + + long warmup = Config.getInstance().getPTPCommandWarmup(); + + mcMMOPlayer.actualizeTeleportCommenceLocation(teleportingPlayer); + + if (warmup > 0) { + teleportingPlayer.sendMessage(ChatColor.GRAY + "Commencing teleport in " + ChatColor.GOLD + "(" + warmup + ")" + ChatColor.GRAY + " seconds, please stand still..."); //TODO Locale! + new TeleportationWarmup(mcMMOPlayer, mcMMOTarget).runTaskLater(mcMMO.p, 20 * warmup); + } + else { + handlePartyTeleportEvent(teleportingPlayer, targetPlayer); + } + } + + public static void handlePartyTeleportEvent(Player teleportingPlayer, Player targetPlayer) { McMMOPlayer mcMMOPlayer = UserManager.getPlayer(teleportingPlayer); McMMOPartyTeleportEvent event = new McMMOPartyTeleportEvent(teleportingPlayer, targetPlayer, mcMMOPlayer.getParty().getName()); diff --git a/src/main/java/com/gmail/nossr50/config/Config.java b/src/main/java/com/gmail/nossr50/config/Config.java index 59fd89285..4e21c7c51 100644 --- a/src/main/java/com/gmail/nossr50/config/Config.java +++ b/src/main/java/com/gmail/nossr50/config/Config.java @@ -142,7 +142,8 @@ public class Config extends AutoUpdateConfigLoader { public double getPartyShareRange() { return config.getDouble("Party.Sharing.Range", 75.0); } /* Party Teleport Settings */ - public int getPTPCommandCooldown() { return config.getInt("Commands.ptp.Cooldown", 30); } + public int getPTPCommandCooldown() { return config.getInt("Commands.ptp.Cooldown", 120); } + public int getPTPCommandWarmup() { return config.getInt("Commands.ptp.Warmup", 5); } public int getPTPCommandTimeout() { return config.getInt("Commands.ptp.Request_Timeout", 300); } public boolean getPTPCommandConfirmRequired() { return config.getBoolean("Commands.ptp.Confirm_Required", true); } public boolean getPTPCommandWorldPermissions() { return config.getBoolean("Commands.ptp.World_Based_Permissions", false); } diff --git a/src/main/java/com/gmail/nossr50/runnables/items/TeleportationWarmup.java b/src/main/java/com/gmail/nossr50/runnables/items/TeleportationWarmup.java new file mode 100644 index 000000000..3376200ad --- /dev/null +++ b/src/main/java/com/gmail/nossr50/runnables/items/TeleportationWarmup.java @@ -0,0 +1,57 @@ +package com.gmail.nossr50.runnables.items; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +import com.gmail.nossr50.commands.party.teleport.PtpCommand; +import com.gmail.nossr50.datatypes.player.McMMOPlayer; +import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.party.PartyManager; +import com.gmail.nossr50.util.Misc; +import com.gmail.nossr50.util.skills.SkillUtils; + +public class TeleportationWarmup extends BukkitRunnable { + private static Player teleportingPlayer; + private McMMOPlayer mcMMOPlayer; + private static Player targetPlayer; + private McMMOPlayer mcMMOTarget; + + public TeleportationWarmup(McMMOPlayer mcMMOPlayer, McMMOPlayer mcMMOTarget) { + this.mcMMOPlayer = mcMMOPlayer; + this.mcMMOTarget = mcMMOTarget; + } + + @Override + public void run() { + checkPartyTeleport(); + } + + private void checkPartyTeleport() { + teleportingPlayer = mcMMOPlayer.getPlayer(); + targetPlayer = mcMMOTarget.getPlayer(); + Location previousLocation = mcMMOPlayer.getTeleportCommenceLocation(); + Location newLocation = mcMMOPlayer.getPlayer().getLocation(); + long recentlyHurt = mcMMOPlayer.getRecentlyHurt(); + + mcMMOPlayer.setTeleportCommenceLocation(null); + + if (!PartyManager.inSameParty(teleportingPlayer, targetPlayer)) { + teleportingPlayer.sendMessage(LocaleLoader.getString("Party.NotInYourParty", targetPlayer.getName())); + return; + } + + if (newLocation.distanceSquared(previousLocation) > 1.0) { + teleportingPlayer.sendMessage(ChatColor.DARK_RED + "Teleportation canceled!"); //TODO Locale! + return; + } + + if (!SkillUtils.cooldownOver(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, 60, teleportingPlayer)) { + teleportingPlayer.sendMessage(LocaleLoader.getString("Item.Injured.Wait", SkillUtils.calculateTimeLeft(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, 60, teleportingPlayer))); + return; + } + + PtpCommand.handlePartyTeleportEvent(teleportingPlayer, targetPlayer); + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index eed497415..c21d013f2 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -355,7 +355,8 @@ Commands: mcmmo: Donate_Message: true ptp: - Cooldown: 30 + Cooldown: 120 + Warmup: 5 Confirm_Required: true Request_Timeout: 300 # If true, require players to have a mcmmo.commands.ptp.world.[WorldName] permission