Pārlūkot izejas kodu

Add configurable warmup and cooldown timers for party teleportation

Closes #348
TfT_02 12 gadi atpakaļ
vecāks
revīzija
e11dc680de

+ 1 - 1
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;
     }
 }

+ 21 - 2
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());
 

+ 2 - 1
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); }

+ 57 - 0
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);
+    }
+}

+ 2 - 1
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