2012-01-09 11:00:13 -08:00
package com.gmail.nossr50.commands.party ;
2012-03-27 15:57:37 -04:00
import org.bukkit.Bukkit ;
2012-01-09 11:00:13 -08:00
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 ;
import com.gmail.nossr50.mcPermissions ;
2012-03-09 19:54:56 -05:00
import com.gmail.nossr50.config.LoadProperties ;
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 {
private final mcMMO plugin ;
public PtpCommand ( mcMMO instance ) {
this . plugin = instance ;
}
@Override
public boolean onCommand ( CommandSender sender , Command command , String label , String [ ] args ) {
if ( ! ( sender instanceof Player ) ) {
2012-03-26 16:17:35 -04:00
sender . sendMessage ( " This command does not support console useage. " ) ; //TODO: Needs more locale.
2012-01-09 11:00:13 -08:00
return true ;
}
Player player = ( Player ) sender ;
PlayerProfile PP = Users . getProfile ( player ) ;
if ( ! mcPermissions . getInstance ( ) . partyTeleport ( player ) ) {
player . sendMessage ( ChatColor . YELLOW + " [mcMMO] " + ChatColor . DARK_RED + mcLocale . getString ( " mcPlayerListener.NoPermission " ) ) ;
return true ;
}
2012-03-08 18:00:43 -08:00
2012-03-08 18:24:16 -08:00
if ( ! Party . getInstance ( ) . isParty ( PP . getParty ( ) ) )
2012-03-08 18:00:43 -08:00
{
2012-03-26 16:17:35 -04:00
player . sendMessage ( ChatColor . RED + " You are not in a party! " ) ; //TODO: Needs more locale.
2012-03-08 18:00:43 -08:00
return true ;
}
2012-03-08 18:23:04 -08:00
2012-03-09 19:54:56 -05:00
if ( PP . getRecentlyHurt ( ) + ( LoadProperties . ptpCommandCooldown * 1000 ) > System . currentTimeMillis ( ) )
2012-03-09 16:40:39 -08:00
{
2012-03-26 16:17:35 -04:00
player . sendMessage ( ChatColor . RED + " You've been hurt in the last " + LoadProperties . ptpCommandCooldown + " seconds and cannnot teleport. " ) ; //TODO: Needs more locale.
2012-03-09 16:40:39 -08:00
return true ;
}
2012-01-09 11:00:13 -08:00
if ( args . length < 1 ) {
2012-03-26 16:17:35 -04:00
player . sendMessage ( ChatColor . RED + " Usage is /ptp <playername> " ) ; //TODO: Needs more locale.
2012-01-09 11:00:13 -08:00
return true ;
}
2012-03-08 18:00:43 -08:00
2012-01-09 11:00:13 -08:00
if ( plugin . getServer ( ) . getPlayer ( args [ 0 ] ) = = null ) {
2012-03-26 16:17:35 -04:00
player . sendMessage ( " That is not a valid player " ) ; //TODO: Needs more locale.
2012-01-09 11:00:13 -08:00
}
if ( plugin . getServer ( ) . getPlayer ( args [ 0 ] ) ! = null ) {
Player target = plugin . getServer ( ) . getPlayer ( args [ 0 ] ) ;
PlayerProfile PPt = Users . getProfile ( target ) ;
2012-03-27 15:57:37 -04:00
2012-03-27 23:04:00 -04:00
if ( target . isDead ( ) ) {
player . sendMessage ( ChatColor . RED + " You can't teleport to dead players. " ) ; //TODO: Needs more locale.
return true ;
}
2012-01-09 11:00:13 -08:00
if ( PP . getParty ( ) . equals ( PPt . getParty ( ) ) ) {
2012-03-27 15:57:37 -04:00
McMMOPartyTeleportEvent event = new McMMOPartyTeleportEvent ( player , target , PP . getParty ( ) ) ;
Bukkit . getPluginManager ( ) . callEvent ( event ) ;
if ( ! event . isCancelled ( ) ) {
player . teleport ( target ) ;
player . sendMessage ( ChatColor . GREEN + " You have teleported to " + target . getName ( ) ) ; //TODO: Needs more locale.
target . sendMessage ( ChatColor . GREEN + player . getName ( ) + " has teleported to you. " ) ; //TODO: Needs more locale.
}
2012-03-08 18:00:43 -08:00
} else {
2012-03-26 16:17:35 -04:00
player . sendMessage ( ChatColor . RED + " That player is in a different party than you. " ) ; //TODO: Needs more locale.
2012-01-09 11:00:13 -08:00
}
}
return true ;
}
2012-03-03 12:43:50 -08:00
}