mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-10-31 07:39:42 +01:00
Implemented lastlogin command
This commit is contained in:
parent
a2e33402f9
commit
39d6fdd05d
@ -123,6 +123,19 @@ public class CommandManager {
|
||||
dungeonMazeCommand);
|
||||
listWorldCommand.setCommandPermissions("dungeonmaze.command.listworlds", CommandPermissions.DefaultPermission.OP_ONLY);*/
|
||||
|
||||
// Register the purge command
|
||||
CommandDescription lastLoginCommand = new CommandDescription(
|
||||
new LastLoginCommand(),
|
||||
new ArrayList<String>() {{
|
||||
add("lastlogin");
|
||||
add("ll");
|
||||
}},
|
||||
"Player's last login",
|
||||
"View the date of the specified players last login",
|
||||
authMeCommand);
|
||||
lastLoginCommand.setCommandPermissions("authme.admin.lastlogin", CommandPermissions.DefaultPermission.OP_ONLY);
|
||||
lastLoginCommand.addArgument(new CommandArgumentDescription("player", "Player name", true));
|
||||
|
||||
// Register the purge command
|
||||
CommandDescription purgeCommand = new CommandDescription(
|
||||
new PurgeCommand(),
|
||||
|
@ -0,0 +1,74 @@
|
||||
package fr.xephi.authme.command.executable;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.settings.Messages;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.util.Profiler;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
//import org.bukkit.ChatColor;
|
||||
import java.util.Date;
|
||||
|
||||
public class LastLoginCommand extends ExecutableCommand {
|
||||
|
||||
/**
|
||||
* Execute the command.
|
||||
*
|
||||
* @param sender The command sender.
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// Profile the reload process
|
||||
Profiler p = new Profiler(true);
|
||||
|
||||
// AuthMe plugin instance
|
||||
AuthMe plugin = AuthMe.getInstance();
|
||||
// Messages instance
|
||||
Messages m = Messages.getInstance();
|
||||
|
||||
// Get the player
|
||||
String playerName = sender.getName();
|
||||
if(commandArguments.getCount() >= 1)
|
||||
playerName = commandArguments.get(0);
|
||||
|
||||
// Validate the player
|
||||
PlayerAuth auth;
|
||||
try {
|
||||
auth = plugin.database.getAuth(args[1].toLowerCase());
|
||||
} catch (NullPointerException e) {
|
||||
m.send(sender, "unknown_user");
|
||||
return true;
|
||||
}
|
||||
if (auth == null) {
|
||||
m.send(sender, "user_unknown");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get the last login date
|
||||
long lastLogin = auth.getLastLogin();
|
||||
Date date = new Date(lastLogin);
|
||||
|
||||
// Get the difference
|
||||
final long diff = System.currentTimeMillis() - lastLogin;
|
||||
|
||||
// Build the message
|
||||
final String msg = (int) (diff / 86400000) + " days " + (int) (diff / 3600000 % 24) + " hours " + (int) (diff / 60000 % 60) + " mins " + (int) (diff / 1000 % 60) + " secs.";
|
||||
|
||||
// Get the player's last IP
|
||||
String lastIP = auth.getIp();
|
||||
|
||||
// Show the player status
|
||||
sender.sendMessage("[AuthMe] " + args[1] + " last login : " + date.toString());
|
||||
sender.sendMessage("[AuthMe] The player " + auth.getNickname() + " is unlogged since " + msg);
|
||||
sender.sendMessage("[AuthMe] Last Player's IP: " + lastIP);
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user