mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 15:16:45 +01:00
Add configurable warmup and cooldown timers for party teleportation
Closes #348
This commit is contained in:
parent
71249334c3
commit
e11dc680de
@ -58,7 +58,7 @@ public class PtpAcceptCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PtpCommand.handlePartyTeleportEvent(target, player);
|
PtpCommand.handleTeleportWarmup(target, player);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
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.events.party.McMMOPartyTeleportEvent;
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
import com.gmail.nossr50.party.PartyManager;
|
import com.gmail.nossr50.party.PartyManager;
|
||||||
|
import com.gmail.nossr50.runnables.items.TeleportationWarmup;
|
||||||
import com.gmail.nossr50.util.Misc;
|
import com.gmail.nossr50.util.Misc;
|
||||||
import com.gmail.nossr50.util.Permissions;
|
import com.gmail.nossr50.util.Permissions;
|
||||||
import com.gmail.nossr50.util.commands.CommandUtils;
|
import com.gmail.nossr50.util.commands.CommandUtils;
|
||||||
@ -100,7 +102,7 @@ public class PtpCommand implements TabExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!mcMMOTarget.getPtpConfirmRequired()) {
|
if (!mcMMOTarget.getPtpConfirmRequired()) {
|
||||||
handlePartyTeleportEvent(player, target);
|
handleTeleportWarmup(player, target);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,7 +148,24 @@ public class PtpCommand implements TabExecutor {
|
|||||||
return true;
|
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);
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(teleportingPlayer);
|
||||||
McMMOPartyTeleportEvent event = new McMMOPartyTeleportEvent(teleportingPlayer, targetPlayer, mcMMOPlayer.getParty().getName());
|
McMMOPartyTeleportEvent event = new McMMOPartyTeleportEvent(teleportingPlayer, targetPlayer, mcMMOPlayer.getParty().getName());
|
||||||
|
|
||||||
|
@ -142,7 +142,8 @@ public class Config extends AutoUpdateConfigLoader {
|
|||||||
public double getPartyShareRange() { return config.getDouble("Party.Sharing.Range", 75.0); }
|
public double getPartyShareRange() { return config.getDouble("Party.Sharing.Range", 75.0); }
|
||||||
|
|
||||||
/* Party Teleport Settings */
|
/* 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 int getPTPCommandTimeout() { return config.getInt("Commands.ptp.Request_Timeout", 300); }
|
||||||
public boolean getPTPCommandConfirmRequired() { return config.getBoolean("Commands.ptp.Confirm_Required", true); }
|
public boolean getPTPCommandConfirmRequired() { return config.getBoolean("Commands.ptp.Confirm_Required", true); }
|
||||||
public boolean getPTPCommandWorldPermissions() { return config.getBoolean("Commands.ptp.World_Based_Permissions", false); }
|
public boolean getPTPCommandWorldPermissions() { return config.getBoolean("Commands.ptp.World_Based_Permissions", false); }
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -355,7 +355,8 @@ Commands:
|
|||||||
mcmmo:
|
mcmmo:
|
||||||
Donate_Message: true
|
Donate_Message: true
|
||||||
ptp:
|
ptp:
|
||||||
Cooldown: 30
|
Cooldown: 120
|
||||||
|
Warmup: 5
|
||||||
Confirm_Required: true
|
Confirm_Required: true
|
||||||
Request_Timeout: 300
|
Request_Timeout: 300
|
||||||
# If true, require players to have a mcmmo.commands.ptp.world.[WorldName] permission
|
# If true, require players to have a mcmmo.commands.ptp.world.[WorldName] permission
|
||||||
|
Loading…
Reference in New Issue
Block a user