2012-01-09 11:00:13 -08:00
|
|
|
package com.gmail.nossr50.commands.party;
|
|
|
|
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandExecutor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
import com.gmail.nossr50.Users;
|
|
|
|
import com.gmail.nossr50.mcMMO;
|
2012-04-22 19:34:34 -04:00
|
|
|
import com.gmail.nossr50.commands.CommandHelper;
|
2012-04-26 07:27:57 -07:00
|
|
|
import com.gmail.nossr50.config.Config;
|
2012-01-09 11:00:13 -08:00
|
|
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
2012-03-27 15:57:37 -04:00
|
|
|
import com.gmail.nossr50.events.party.McMMOPartyTeleportEvent;
|
2012-01-09 11:00:13 -08:00
|
|
|
import com.gmail.nossr50.locale.mcLocale;
|
2012-03-08 18:23:04 -08:00
|
|
|
import com.gmail.nossr50.party.Party;
|
2012-01-09 11:00:13 -08:00
|
|
|
|
|
|
|
public class PtpCommand implements CommandExecutor {
|
2012-04-22 19:34:34 -04:00
|
|
|
private final mcMMO plugin;
|
|
|
|
|
|
|
|
public PtpCommand(mcMMO instance) {
|
|
|
|
this.plugin = instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
|
|
String usage = ChatColor.RED + "Proper usage is /ptp <player>"; //TODO: Needs more locale.
|
|
|
|
|
|
|
|
if (CommandHelper.noConsoleUsage(sender)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.ptp")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (args.length) {
|
|
|
|
case 1:
|
|
|
|
Player player = (Player) sender;
|
|
|
|
PlayerProfile PP = Users.getProfile(player);
|
|
|
|
|
|
|
|
if (!Party.getInstance().isInParty(player, PP)) {
|
|
|
|
player.sendMessage(mcLocale.getString("Commands.Party.None"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-04-26 20:58:21 -07:00
|
|
|
if (PP.getRecentlyHurt() + (Config.getInstance().getPTPCommandCooldown() * 1000) > System.currentTimeMillis()) {
|
|
|
|
player.sendMessage(mcLocale.getString("Party.Teleport.Hurt", new Object[] { Config.getInstance().getPTPCommandCooldown() }));
|
2012-04-22 19:34:34 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Player target = plugin.getServer().getPlayer(args[0]);
|
|
|
|
|
2012-04-27 02:21:25 -04:00
|
|
|
if (player.equals(target)) {
|
|
|
|
player.sendMessage("You can't teleport to yourself!"); //TODO: Use locale
|
|
|
|
}
|
|
|
|
|
2012-04-22 19:34:34 -04:00
|
|
|
if (target == null) {
|
|
|
|
player.sendMessage(mcLocale.getString("Party.Teleport.Invalid"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (target.isDead()) {
|
|
|
|
player.sendMessage(mcLocale.getString("Party.Teleport.Dead"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Party.getInstance().inSameParty(player, target)) {
|
|
|
|
McMMOPartyTeleportEvent event = new McMMOPartyTeleportEvent(player, target, PP.getParty());
|
|
|
|
plugin.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
player.teleport(target);
|
|
|
|
player.sendMessage(mcLocale.getString("Party.Teleport.Player", new Object[] { target.getName() }));
|
|
|
|
target.sendMessage(mcLocale.getString("Party.Teleport.Target", new Object[] { player.getName() }));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
player.sendMessage(mcLocale.getString("Party.NotInYourParty", new Object[] { target.getName() }));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
sender.sendMessage(usage);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2012-04-27 02:21:25 -04:00
|
|
|
}
|