mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 21:26:46 +01:00
Clean up /ptp. Also fix bug where teleportation happened backwards when
accepting.
This commit is contained in:
parent
b21d5bdcc4
commit
b66c5d7023
@ -30,6 +30,7 @@ Version 1.4.00-dev
|
|||||||
+ Added Shears, Buckets, Fishing Rods, Flint & Steel, Carrot Sticks, and Bows to the list of items that can be Salvaged
|
+ Added Shears, Buckets, Fishing Rods, Flint & Steel, Carrot Sticks, and Bows to the list of items that can be Salvaged
|
||||||
+ Added the "wait" music disc to the default fishing treasures
|
+ Added the "wait" music disc to the default fishing treasures
|
||||||
+ Added "Chinese (Taiwan)" localization files (zh_TW)
|
+ Added "Chinese (Taiwan)" localization files (zh_TW)
|
||||||
|
= Fixed /ptp telporting the target to the player, rather than the other way around.
|
||||||
= Fixed Impact reducing durability of non-armor equipped blocks
|
= Fixed Impact reducing durability of non-armor equipped blocks
|
||||||
= Fixed multiple commands not working properly on offline players
|
= Fixed multiple commands not working properly on offline players
|
||||||
= Fixed /mmoedit not giving feedback when modifying another players stats
|
= Fixed /mmoedit not giving feedback when modifying another players stats
|
||||||
|
@ -20,6 +20,10 @@ import com.gmail.nossr50.util.Users;
|
|||||||
public class PtpCommand implements CommandExecutor {
|
public class PtpCommand implements CommandExecutor {
|
||||||
private Player player;
|
private Player player;
|
||||||
private McMMOPlayer mcMMOPlayer;
|
private McMMOPlayer mcMMOPlayer;
|
||||||
|
private PlayerProfile playerProfile;
|
||||||
|
|
||||||
|
private Player target;
|
||||||
|
private McMMOPlayer mcMMOTarget;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
@ -31,13 +35,23 @@ public class PtpCommand implements CommandExecutor {
|
|||||||
case 1:
|
case 1:
|
||||||
player = (Player) sender;
|
player = (Player) sender;
|
||||||
mcMMOPlayer = Users.getPlayer(player);
|
mcMMOPlayer = Users.getPlayer(player);
|
||||||
PlayerProfile playerProfile = mcMMOPlayer.getProfile();
|
playerProfile = mcMMOPlayer.getProfile();
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("toggle")) {
|
if (args[0].equalsIgnoreCase("toggle")) {
|
||||||
|
if (!Permissions.hasPermission(sender, "mcmmo.commands.ptp.toggle")) {
|
||||||
|
sender.sendMessage(command.getPermissionMessage());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return togglePartyTeleportation();
|
return togglePartyTeleportation();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("acceptany") || args[0].equalsIgnoreCase("acceptall")) {
|
if (args[0].equalsIgnoreCase("acceptany") || args[0].equalsIgnoreCase("acceptall")) {
|
||||||
|
if (!Permissions.hasPermission(sender, "mcmmo.commands.ptp.acceptall")) {
|
||||||
|
sender.sendMessage(command.getPermissionMessage());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return acceptAnyTeleportRequest();
|
return acceptAnyTeleportRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,6 +63,11 @@ public class PtpCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("accept")) {
|
if (args[0].equalsIgnoreCase("accept")) {
|
||||||
|
if (!Permissions.hasPermission(sender, "mcmmo.commands.ptp.accept")) {
|
||||||
|
sender.sendMessage(command.getPermissionMessage());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return acceptTeleportRequest();
|
return acceptTeleportRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,64 +78,22 @@ public class PtpCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean sendTeleportRequest(String playerName) {
|
private boolean sendTeleportRequest(String targetName) {
|
||||||
if (!mcMMO.p.getServer().getOfflinePlayer(playerName).isOnline()) {
|
if (!canTeleport(targetName)) {
|
||||||
player.sendMessage(LocaleLoader.getString("Party.NotOnline", playerName));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
McMMOPlayer mcMMOTarget = Users.getPlayer(playerName);
|
if (!mcMMOTarget.getPtpConfirmRequired()) {
|
||||||
|
return handlePartyTeleportEvent();
|
||||||
if (mcMMOTarget == null) {
|
|
||||||
player.sendMessage(LocaleLoader.getString("Party.Player.Invalid"));
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Player target = mcMMOTarget.getPlayer();
|
mcMMOTarget.setPtpRequest(player);
|
||||||
|
mcMMOTarget.actualizePtpTimeout();
|
||||||
|
player.sendMessage(LocaleLoader.getString("Commands.Invite.Success"));
|
||||||
|
|
||||||
if (player.equals(target)) {
|
int ptpRequestExpire = Config.getInstance().getPTPCommandTimeout();
|
||||||
player.sendMessage(LocaleLoader.getString("Party.Teleport.Self"));
|
target.sendMessage(LocaleLoader.getString("Commands.ptp.Request1", player.getName()));
|
||||||
return true;
|
target.sendMessage(LocaleLoader.getString("Commands.ptp.Request2", ptpRequestExpire));
|
||||||
}
|
|
||||||
|
|
||||||
if (target.isDead()) {
|
|
||||||
player.sendMessage(LocaleLoader.getString("Party.Teleport.Dead"));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PartyManager.inSameParty(player, target)) {
|
|
||||||
McMMOPlayer targetMcMMOPlayer = Users.getPlayer(target);
|
|
||||||
|
|
||||||
if (!targetMcMMOPlayer.getPtpEnabled()) {
|
|
||||||
player.sendMessage(LocaleLoader.getString("Party.Teleport.Disabled", target.getName()));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!targetMcMMOPlayer.getPtpConfirmRequired()) {
|
|
||||||
McMMOPartyTeleportEvent event = new McMMOPartyTeleportEvent(player, target, mcMMOPlayer.getParty().getName());
|
|
||||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
player.teleport(target);
|
|
||||||
player.sendMessage(LocaleLoader.getString("Party.Teleport.Player", player.getName()));
|
|
||||||
target.sendMessage(LocaleLoader.getString("Party.Teleport.Target", target.getName()));
|
|
||||||
mcMMOPlayer.getProfile().setRecentlyHurt(System.currentTimeMillis());
|
|
||||||
} else {
|
|
||||||
targetMcMMOPlayer.setPtpRequest(player);
|
|
||||||
targetMcMMOPlayer.actualizePtpTimeout();
|
|
||||||
player.sendMessage(LocaleLoader.getString("Commands.Invite.Success"));
|
|
||||||
|
|
||||||
int ptpRequestExpire = Config.getInstance().getPTPCommandTimeout();
|
|
||||||
target.sendMessage(LocaleLoader.getString("Commands.ptp.Request1", player.getName()));
|
|
||||||
target.sendMessage(LocaleLoader.getString("Commands.ptp.Request2", ptpRequestExpire));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
player.sendMessage(LocaleLoader.getString("Party.NotInYourParty", target.getName()));
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,10 +103,6 @@ public class PtpCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.ptp.accept")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ptpRequestExpire = Config.getInstance().getPTPCommandTimeout();
|
int ptpRequestExpire = Config.getInstance().getPTPCommandTimeout();
|
||||||
|
|
||||||
if ((mcMMOPlayer.getPtpTimeout() + ptpRequestExpire) * Misc.TIME_CONVERSION_FACTOR < System.currentTimeMillis()) {
|
if ((mcMMOPlayer.getPtpTimeout() + ptpRequestExpire) * Misc.TIME_CONVERSION_FACTOR < System.currentTimeMillis()) {
|
||||||
@ -140,48 +113,28 @@ public class PtpCommand implements CommandExecutor {
|
|||||||
|
|
||||||
Player target = mcMMOPlayer.getPtpRequest();
|
Player target = mcMMOPlayer.getPtpRequest();
|
||||||
|
|
||||||
if (target == null) {
|
if (!canTeleport(target.getName())) {
|
||||||
player.sendMessage(LocaleLoader.getString("Party.Player.Invalid"));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target.isDead()) {
|
//TODO: Someone want to clarify what's going on with these dynamic permissions?
|
||||||
player.sendMessage(LocaleLoader.getString("Party.Teleport.Dead"));
|
if (Config.getInstance().getPTPCommandWorldPermissions()) {
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Config.getInstance().getPTPCommandWorldPermissions()) {
|
|
||||||
String perm = "mcmmo.commands.ptp.world.";
|
String perm = "mcmmo.commands.ptp.world.";
|
||||||
|
|
||||||
if(!Permissions.hasDynamicPermission(target, perm + "all", "op")) {
|
if (!Permissions.hasDynamicPermission(target, perm + "all", "op")) {
|
||||||
if(!Permissions.hasDynamicPermission(target, perm + target.getWorld().getName(), "op")) {
|
if (!Permissions.hasDynamicPermission(target, perm + target.getWorld().getName(), "op")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if(target.getWorld() != player.getWorld() && !Permissions.hasDynamicPermission(target, perm + player.getWorld().getName(), "op")) {
|
else if (target.getWorld() != player.getWorld() && !Permissions.hasDynamicPermission(target, perm + player.getWorld().getName(), "op")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
McMMOPartyTeleportEvent event = new McMMOPartyTeleportEvent(target, player, mcMMOPlayer.getParty().getName());
|
return handlePartyTeleportEvent();
|
||||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
target.teleport(player);
|
|
||||||
target.sendMessage(LocaleLoader.getString("Party.Teleport.Player", player.getName()));
|
|
||||||
player.sendMessage(LocaleLoader.getString("Party.Teleport.Target", target.getName()));
|
|
||||||
mcMMOPlayer.getProfile().setRecentlyHurt(System.currentTimeMillis());
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean acceptAnyTeleportRequest() {
|
private boolean acceptAnyTeleportRequest() {
|
||||||
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.ptp.acceptall")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mcMMOPlayer.getPtpConfirmRequired()) {
|
if (mcMMOPlayer.getPtpConfirmRequired()) {
|
||||||
player.sendMessage(LocaleLoader.getString("Commands.ptp.AcceptAny.Disabled"));
|
player.sendMessage(LocaleLoader.getString("Commands.ptp.AcceptAny.Disabled"));
|
||||||
}
|
}
|
||||||
@ -194,10 +147,6 @@ public class PtpCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean togglePartyTeleportation() {
|
private boolean togglePartyTeleportation() {
|
||||||
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.ptp.toggle")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mcMMOPlayer.getPtpEnabled()) {
|
if (mcMMOPlayer.getPtpEnabled()) {
|
||||||
player.sendMessage(LocaleLoader.getString("Commands.ptp.Disabled"));
|
player.sendMessage(LocaleLoader.getString("Commands.ptp.Disabled"));
|
||||||
}
|
}
|
||||||
@ -208,4 +157,57 @@ public class PtpCommand implements CommandExecutor {
|
|||||||
mcMMOPlayer.togglePtpUse();
|
mcMMOPlayer.togglePtpUse();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean canTeleport(String targetName) {
|
||||||
|
if (!mcMMO.p.getServer().getOfflinePlayer(targetName).isOnline()) {
|
||||||
|
player.sendMessage(LocaleLoader.getString("Party.NotOnline", targetName));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
mcMMOTarget = Users.getPlayer(targetName);
|
||||||
|
|
||||||
|
if (mcMMOTarget == null) {
|
||||||
|
player.sendMessage(LocaleLoader.getString("Party.Player.Invalid"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
target = mcMMOTarget.getPlayer();
|
||||||
|
|
||||||
|
if (player.equals(target)) {
|
||||||
|
player.sendMessage(LocaleLoader.getString("Party.Teleport.Self"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!PartyManager.inSameParty(player, target)) {
|
||||||
|
player.sendMessage(LocaleLoader.getString("Party.NotInYourParty", targetName));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mcMMOTarget.getPtpEnabled()) {
|
||||||
|
player.sendMessage(LocaleLoader.getString("Party.Teleport.Disabled", target.getName()));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (target.isDead()) {
|
||||||
|
player.sendMessage(LocaleLoader.getString("Party.Teleport.Dead"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean handlePartyTeleportEvent() {
|
||||||
|
McMMOPartyTeleportEvent event = new McMMOPartyTeleportEvent(player, target, mcMMOPlayer.getParty().getName());
|
||||||
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||||
|
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
player.teleport(target);
|
||||||
|
player.sendMessage(LocaleLoader.getString("Party.Teleport.Player", player.getName()));
|
||||||
|
target.sendMessage(LocaleLoader.getString("Party.Teleport.Target", target.getName()));
|
||||||
|
playerProfile.setRecentlyHurt(System.currentTimeMillis());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user