Static Abuse Removal - PTP Commands

This commit is contained in:
nossr50 2019-07-02 18:38:22 -07:00
parent 4c4732695b
commit 5fd93cea19
4 changed files with 86 additions and 64 deletions

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.commands.party.teleport; package com.gmail.nossr50.commands.party.teleport;
import com.gmail.nossr50.datatypes.party.PartyTeleportRecord; import com.gmail.nossr50.datatypes.party.PartyTeleportRecord;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -8,6 +9,12 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
public class PtpAcceptAnyCommand implements CommandExecutor { public class PtpAcceptAnyCommand implements CommandExecutor {
private mcMMO pluginRef;
public PtpAcceptAnyCommand(mcMMO pluginRef) {
this.pluginRef = pluginRef;
}
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!Permissions.partyTeleportAcceptAll(sender)) { if (!Permissions.partyTeleportAcceptAll(sender)) {

View File

@ -28,75 +28,21 @@ import java.util.List;
public class PtpCommand implements TabExecutor { public class PtpCommand implements TabExecutor {
private mcMMO pluginRef; private mcMMO pluginRef;
private CommandExecutor ptpToggleCommand;
private CommandExecutor ptpAcceptAnyCommand;
private CommandExecutor ptpAcceptCommand;
public PtpCommand(mcMMO pluginRef) { public PtpCommand(mcMMO pluginRef) {
this.pluginRef = 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"); 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 @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (CommandUtils.noConsoleUsage(sender)) { if (CommandUtils.noConsoleUsage(sender)) {
@ -216,7 +162,7 @@ public class PtpCommand implements TabExecutor {
} }
private void sendTeleportRequest(CommandSender sender, Player player, String targetName) { private void sendTeleportRequest(CommandSender sender, Player player, String targetName) {
if (!canTeleport(sender, player, targetName)) { if (!pluginRef.getPartyManager().canTeleport(sender, player, targetName)) {
return; return;
} }
@ -226,7 +172,7 @@ public class PtpCommand implements TabExecutor {
PartyTeleportRecord ptpRecord = mcMMOTarget.getPartyTeleportRecord(); PartyTeleportRecord ptpRecord = mcMMOTarget.getPartyTeleportRecord();
if (!ptpRecord.isConfirmRequired()) { if (!ptpRecord.isConfirmRequired()) {
handleTeleportWarmup(player, target); pluginRef.getPartyManager().handleTeleportWarmup(player, target);
return; return;
} }

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.commands.party.teleport; package com.gmail.nossr50.commands.party.teleport;
import com.gmail.nossr50.datatypes.party.PartyTeleportRecord; import com.gmail.nossr50.datatypes.party.PartyTeleportRecord;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -8,6 +9,13 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
public class PtpToggleCommand implements CommandExecutor { public class PtpToggleCommand implements CommandExecutor {
private mcMMO pluginRef;
public PtpToggleCommand(mcMMO pluginRef) {
this.pluginRef = pluginRef;
}
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!Permissions.partyTeleportToggle(sender)) { if (!Permissions.partyTeleportToggle(sender)) {

View File

@ -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;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason; import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
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.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.sounds.SoundManager; import com.gmail.nossr50.util.sounds.SoundManager;
import com.gmail.nossr50.util.sounds.SoundType; import com.gmail.nossr50.util.sounds.SoundType;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -35,6 +38,64 @@ public final class PartyManager {
partyFile = new File(pluginRef.getFlatFileDirectory() + "parties.yml"); 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 * Grab the appropriate unlock level for a party feature
* *