mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-27 07:36:46 +01:00
Cleanup PtpCommand a bit, remove some useless argument passing and else
statements.
This commit is contained in:
parent
1549f66fd7
commit
92262d0e47
@ -17,6 +17,8 @@ import com.gmail.nossr50.util.Users;
|
|||||||
|
|
||||||
public class PtpCommand implements CommandExecutor {
|
public class PtpCommand implements CommandExecutor {
|
||||||
private final mcMMO plugin;
|
private final mcMMO plugin;
|
||||||
|
private Player player;
|
||||||
|
private PlayerProfile playerProfile;
|
||||||
|
|
||||||
public PtpCommand(mcMMO instance) {
|
public PtpCommand(mcMMO instance) {
|
||||||
this.plugin = instance;
|
this.plugin = instance;
|
||||||
@ -36,37 +38,37 @@ public class PtpCommand implements CommandExecutor {
|
|||||||
|
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 1:
|
case 1:
|
||||||
Player player = (Player) sender;
|
this.player = (Player) sender;
|
||||||
PlayerProfile profile = Users.getProfile(player);
|
this.playerProfile = Users.getProfile(player);
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("toggle")) {
|
if (args[0].equalsIgnoreCase("toggle")) {
|
||||||
return togglePartyTeleportation(sender, args);
|
return togglePartyTeleportation();
|
||||||
}
|
}
|
||||||
else if (args[0].equalsIgnoreCase("deny")) {
|
else if (args[0].equalsIgnoreCase("deny")) {
|
||||||
return denyTeleportRequest(sender, args);
|
return denyTeleportRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (profile.getRecentlyHurt() + (Config.getInstance().getPTPCommandCooldown() * Misc.TIME_CONVERSION_FACTOR) > System.currentTimeMillis()) {
|
int ptpCooldown = Config.getInstance().getPTPCommandCooldown();
|
||||||
player.sendMessage(LocaleLoader.getString("Party.Teleport.Hurt", new Object[] { Config.getInstance().getPTPCommandCooldown() }));
|
|
||||||
|
if (playerProfile.getRecentlyHurt() + (ptpCooldown * Misc.TIME_CONVERSION_FACTOR) > System.currentTimeMillis()) {
|
||||||
|
player.sendMessage(LocaleLoader.getString("Party.Teleport.Hurt", new Object[] { ptpCooldown }));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("accept")) {
|
if (args[0].equalsIgnoreCase("accept")) {
|
||||||
return acceptTeleportRequest(sender, args);
|
return acceptTeleportRequest();
|
||||||
}
|
|
||||||
else {
|
|
||||||
return sendTeleportRequest(sender, args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return sendTeleportRequest(args[0]);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
sender.sendMessage(usage);
|
sender.sendMessage(usage);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean sendTeleportRequest(CommandSender sender, String[] args) {
|
private boolean sendTeleportRequest(String targetName) {
|
||||||
Player player = (Player) sender;
|
Player target = plugin.getServer().getPlayer(targetName);
|
||||||
Player target = plugin.getServer().getPlayer(args[0]);
|
|
||||||
|
|
||||||
if (player.equals(target)) {
|
if (player.equals(target)) {
|
||||||
player.sendMessage(LocaleLoader.getString("Party.Teleport.Self"));
|
player.sendMessage(LocaleLoader.getString("Party.Teleport.Self"));
|
||||||
@ -84,26 +86,27 @@ public class PtpCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (PartyManager.inSameParty(player, target)) {
|
if (PartyManager.inSameParty(player, target)) {
|
||||||
if (Users.getProfile(target).getPtpEnabled()) {
|
PlayerProfile targetProfile = Users.getProfile(target);
|
||||||
Users.getProfile(target).setPtpRequest(player.getName());
|
|
||||||
|
if (targetProfile.getPtpEnabled()) {
|
||||||
|
String senderName = player.getName();
|
||||||
|
|
||||||
|
targetProfile.setPtpRequest(senderName);
|
||||||
player.sendMessage(LocaleLoader.getString("Commands.Invite.Success"));
|
player.sendMessage(LocaleLoader.getString("Commands.Invite.Success"));
|
||||||
target.sendMessage(LocaleLoader.getString("Commands.ptp.Request", new Object[] {player.getName()}));
|
target.sendMessage(LocaleLoader.getString("Commands.ptp.Request", new Object[] {senderName}));
|
||||||
return true;
|
}
|
||||||
}else {
|
else {
|
||||||
player.sendMessage(LocaleLoader.getString("Party.Teleport.Disabled", new Object[] { target.getName() }));
|
player.sendMessage(LocaleLoader.getString("Party.Teleport.Disabled", new Object[] { target.getName() }));
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
player.sendMessage(LocaleLoader.getString("Party.NotInYourParty", new Object[] { target.getName() }));
|
player.sendMessage(LocaleLoader.getString("Party.NotInYourParty", new Object[] { target.getName() }));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean acceptTeleportRequest(CommandSender sender, String[] args) {
|
private boolean acceptTeleportRequest() {
|
||||||
Player player = (Player) sender;
|
|
||||||
PlayerProfile playerProfile = Users.getProfile(player);
|
|
||||||
|
|
||||||
if (playerProfile.hasPtpRequest()) {
|
if (playerProfile.hasPtpRequest()) {
|
||||||
|
|
||||||
Player target = plugin.getServer().getPlayer(playerProfile.getPtpRequest());
|
Player target = plugin.getServer().getPlayer(playerProfile.getPtpRequest());
|
||||||
|
|
||||||
if (Users.getProfile(target).getPtpEnabled()) {
|
if (Users.getProfile(target).getPtpEnabled()) {
|
||||||
@ -118,7 +121,8 @@ public class PtpCommand implements CommandExecutor {
|
|||||||
target.sendMessage(LocaleLoader.getString("Party.Teleport.Player", new Object[] { player.getName() }));
|
target.sendMessage(LocaleLoader.getString("Party.Teleport.Player", new Object[] { player.getName() }));
|
||||||
player.sendMessage(LocaleLoader.getString("Party.Teleport.Target", new Object[] { target.getName() }));
|
player.sendMessage(LocaleLoader.getString("Party.Teleport.Target", new Object[] { target.getName() }));
|
||||||
playerProfile.setRecentlyHurt(System.currentTimeMillis());
|
playerProfile.setRecentlyHurt(System.currentTimeMillis());
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
player.sendMessage(LocaleLoader.getString("Party.Teleport.Disabled", new Object[] { target.getName() }));
|
player.sendMessage(LocaleLoader.getString("Party.Teleport.Disabled", new Object[] { target.getName() }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -128,10 +132,7 @@ public class PtpCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean denyTeleportRequest(CommandSender sender, String[] args) {
|
private boolean denyTeleportRequest() {
|
||||||
Player player = (Player) sender;
|
|
||||||
PlayerProfile playerProfile = Users.getProfile(player);
|
|
||||||
|
|
||||||
if (playerProfile.hasPtpRequest()) {
|
if (playerProfile.hasPtpRequest()) {
|
||||||
Player target = plugin.getServer().getPlayer(playerProfile.getPtpRequest());
|
Player target = plugin.getServer().getPlayer(playerProfile.getPtpRequest());
|
||||||
player.sendMessage(LocaleLoader.getString("Commands.ptp.Deny"));
|
player.sendMessage(LocaleLoader.getString("Commands.ptp.Deny"));
|
||||||
@ -144,18 +145,15 @@ public class PtpCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean togglePartyTeleportation(CommandSender sender, String[] args) {
|
private boolean togglePartyTeleportation() {
|
||||||
Player player = (Player) sender;
|
if (playerProfile.getPtpEnabled()) {
|
||||||
PlayerProfile profile = Users.getProfile(player);
|
player.sendMessage(LocaleLoader.getString("Commands.ptp.Disabled"));
|
||||||
|
|
||||||
if (profile.getPtpEnabled()) {
|
|
||||||
sender.sendMessage(LocaleLoader.getString("Commands.ptp.Disabled"));
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sender.sendMessage(LocaleLoader.getString("Commands.ptp.Enabled"));
|
player.sendMessage(LocaleLoader.getString("Commands.ptp.Enabled"));
|
||||||
}
|
}
|
||||||
|
|
||||||
profile.togglePtpUse();
|
playerProfile.togglePtpUse();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user