mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 06:36:45 +01:00
Static Abuse Removal - PTP Commands
This commit is contained in:
parent
4c4732695b
commit
5fd93cea19
@ -1,6 +1,7 @@
|
||||
package com.gmail.nossr50.commands.party.teleport;
|
||||
|
||||
import com.gmail.nossr50.datatypes.party.PartyTeleportRecord;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import org.bukkit.command.Command;
|
||||
@ -8,6 +9,12 @@ import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class PtpAcceptAnyCommand implements CommandExecutor {
|
||||
private mcMMO pluginRef;
|
||||
|
||||
public PtpAcceptAnyCommand(mcMMO pluginRef) {
|
||||
this.pluginRef = pluginRef;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!Permissions.partyTeleportAcceptAll(sender)) {
|
||||
|
@ -28,75 +28,21 @@ import java.util.List;
|
||||
public class PtpCommand implements TabExecutor {
|
||||
|
||||
private mcMMO pluginRef;
|
||||
private CommandExecutor ptpToggleCommand;
|
||||
private CommandExecutor ptpAcceptAnyCommand;
|
||||
private CommandExecutor ptpAcceptCommand;
|
||||
|
||||
public PtpCommand(mcMMO pluginRef) {
|
||||
this.pluginRef = pluginRef;
|
||||
|
||||
//Init SubCommands
|
||||
ptpToggleCommand = new PtpToggleCommand(pluginRef);
|
||||
ptpAcceptAnyCommand = new PtpAcceptAnyCommand(pluginRef);
|
||||
ptpAcceptCommand = new PtpAcceptCommand(pluginRef);
|
||||
}
|
||||
|
||||
public final List<String> TELEPORT_SUBCOMMANDS = ImmutableList.of("toggle", "accept", "acceptany", "acceptall");
|
||||
|
||||
private CommandExecutor ptpToggleCommand = new PtpToggleCommand();
|
||||
private CommandExecutor ptpAcceptAnyCommand = new PtpAcceptAnyCommand();
|
||||
private CommandExecutor ptpAcceptCommand = new PtpAcceptCommand();
|
||||
|
||||
protected boolean canTeleport(CommandSender sender, Player player, String targetName) {
|
||||
McMMOPlayer mcMMOTarget = UserManager.getPlayer(targetName);
|
||||
|
||||
if (!CommandUtils.checkPlayerExistence(sender, targetName, mcMMOTarget)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Player target = mcMMOTarget.getPlayer();
|
||||
|
||||
if (player.equals(target)) {
|
||||
player.sendMessage(pluginRef.getLocaleManager().getString("Party.Teleport.Self"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!pluginRef.getPartyManager().inSameParty(player, target)) {
|
||||
player.sendMessage(pluginRef.getLocaleManager().getString("Party.NotInYourParty", targetName));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!mcMMOTarget.getPartyTeleportRecord().isEnabled()) {
|
||||
player.sendMessage(pluginRef.getLocaleManager().getString("Party.Teleport.Disabled", targetName));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!target.isValid()) {
|
||||
player.sendMessage(pluginRef.getLocaleManager().getString("Party.Teleport.Dead"));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void handleTeleportWarmup(Player teleportingPlayer, Player targetPlayer) {
|
||||
if (UserManager.getPlayer(targetPlayer) == null) {
|
||||
targetPlayer.sendMessage(pluginRef.getLocaleManager().getString("Profile.PendingLoad"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (UserManager.getPlayer(teleportingPlayer) == null) {
|
||||
teleportingPlayer.sendMessage(pluginRef.getLocaleManager().getString("Profile.PendingLoad"));
|
||||
return;
|
||||
}
|
||||
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(teleportingPlayer);
|
||||
McMMOPlayer mcMMOTarget = UserManager.getPlayer(targetPlayer);
|
||||
|
||||
long warmup = pluginRef.getConfigManager().getConfigParty().getPTP().getPtpWarmup();
|
||||
|
||||
mcMMOPlayer.actualizeTeleportCommenceLocation(teleportingPlayer);
|
||||
|
||||
if (warmup > 0) {
|
||||
teleportingPlayer.sendMessage(pluginRef.getLocaleManager().getString("Teleport.Commencing", warmup));
|
||||
new TeleportationWarmup(mcMMOPlayer, mcMMOTarget).runTaskLater(pluginRef, 20 * warmup);
|
||||
} else {
|
||||
pluginRef.getEventManager().handlePartyTeleportEvent(teleportingPlayer, targetPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (CommandUtils.noConsoleUsage(sender)) {
|
||||
@ -216,7 +162,7 @@ public class PtpCommand implements TabExecutor {
|
||||
}
|
||||
|
||||
private void sendTeleportRequest(CommandSender sender, Player player, String targetName) {
|
||||
if (!canTeleport(sender, player, targetName)) {
|
||||
if (!pluginRef.getPartyManager().canTeleport(sender, player, targetName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -226,7 +172,7 @@ public class PtpCommand implements TabExecutor {
|
||||
PartyTeleportRecord ptpRecord = mcMMOTarget.getPartyTeleportRecord();
|
||||
|
||||
if (!ptpRecord.isConfirmRequired()) {
|
||||
handleTeleportWarmup(player, target);
|
||||
pluginRef.getPartyManager().handleTeleportWarmup(player, target);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.gmail.nossr50.commands.party.teleport;
|
||||
|
||||
import com.gmail.nossr50.datatypes.party.PartyTeleportRecord;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import org.bukkit.command.Command;
|
||||
@ -8,6 +9,13 @@ import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class PtpToggleCommand implements CommandExecutor {
|
||||
|
||||
private mcMMO pluginRef;
|
||||
|
||||
public PtpToggleCommand(mcMMO pluginRef) {
|
||||
this.pluginRef = pluginRef;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!Permissions.partyTeleportToggle(sender)) {
|
||||
|
@ -8,12 +8,15 @@ import com.gmail.nossr50.events.party.McMMOPartyAllianceChangeEvent;
|
||||
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent;
|
||||
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
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;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import com.gmail.nossr50.util.sounds.SoundManager;
|
||||
import com.gmail.nossr50.util.sounds.SoundType;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -35,6 +38,64 @@ public final class PartyManager {
|
||||
partyFile = new File(pluginRef.getFlatFileDirectory() + "parties.yml");
|
||||
}
|
||||
|
||||
public boolean canTeleport(CommandSender sender, Player player, String targetName) {
|
||||
McMMOPlayer mcMMOTarget = UserManager.getPlayer(targetName);
|
||||
|
||||
if (!CommandUtils.checkPlayerExistence(sender, targetName, mcMMOTarget)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Player target = mcMMOTarget.getPlayer();
|
||||
|
||||
if (player.equals(target)) {
|
||||
player.sendMessage(pluginRef.getLocaleManager().getString("Party.Teleport.Self"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!pluginRef.getPartyManager().inSameParty(player, target)) {
|
||||
player.sendMessage(pluginRef.getLocaleManager().getString("Party.NotInYourParty", targetName));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!mcMMOTarget.getPartyTeleportRecord().isEnabled()) {
|
||||
player.sendMessage(pluginRef.getLocaleManager().getString("Party.Teleport.Disabled", targetName));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!target.isValid()) {
|
||||
player.sendMessage(pluginRef.getLocaleManager().getString("Party.Teleport.Dead"));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void handleTeleportWarmup(Player teleportingPlayer, Player targetPlayer) {
|
||||
if (UserManager.getPlayer(targetPlayer) == null) {
|
||||
targetPlayer.sendMessage(pluginRef.getLocaleManager().getString("Profile.PendingLoad"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (UserManager.getPlayer(teleportingPlayer) == null) {
|
||||
teleportingPlayer.sendMessage(pluginRef.getLocaleManager().getString("Profile.PendingLoad"));
|
||||
return;
|
||||
}
|
||||
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(teleportingPlayer);
|
||||
McMMOPlayer mcMMOTarget = UserManager.getPlayer(targetPlayer);
|
||||
|
||||
long warmup = pluginRef.getConfigManager().getConfigParty().getPTP().getPtpWarmup();
|
||||
|
||||
mcMMOPlayer.actualizeTeleportCommenceLocation(teleportingPlayer);
|
||||
|
||||
if (warmup > 0) {
|
||||
teleportingPlayer.sendMessage(pluginRef.getLocaleManager().getString("Teleport.Commencing", warmup));
|
||||
new TeleportationWarmup(mcMMOPlayer, mcMMOTarget).runTaskLater(pluginRef, 20 * warmup);
|
||||
} else {
|
||||
pluginRef.getEventManager().handlePartyTeleportEvent(teleportingPlayer, targetPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Grab the appropriate unlock level for a party feature
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user