2013-02-01 19:41:26 +01:00
|
|
|
package com.gmail.nossr50.commands.admin;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandExecutor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2013-02-01 23:01:11 +01:00
|
|
|
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
2012-04-05 06:44:12 +02:00
|
|
|
import com.gmail.nossr50.commands.CommandHelper;
|
2012-01-09 20:00:13 +01:00
|
|
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
2013-02-01 23:01:11 +01:00
|
|
|
import com.gmail.nossr50.util.Permissions;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.util.Users;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
|
|
|
public class McgodCommand implements CommandExecutor {
|
2012-04-05 06:44:12 +02:00
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
2013-02-01 23:01:11 +01:00
|
|
|
PlayerProfile profile;
|
2012-04-05 06:44:12 +02:00
|
|
|
|
2013-02-01 23:01:11 +01:00
|
|
|
switch (args.length) {
|
|
|
|
case 0:
|
|
|
|
if (CommandHelper.noConsoleUsage(sender)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Permissions.mcgodCommand(sender)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
profile = Users.getProfile((Player) sender);
|
|
|
|
|
|
|
|
if (profile == null) {
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
|
|
|
|
return true;
|
|
|
|
}
|
2012-04-05 06:44:12 +02:00
|
|
|
|
2013-02-01 23:01:11 +01:00
|
|
|
if (profile.getGodMode()) {
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.GodMode.Disabled"));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.GodMode.Enabled"));
|
|
|
|
}
|
2012-04-05 06:44:12 +02:00
|
|
|
|
2013-02-01 23:01:11 +01:00
|
|
|
profile.toggleGodMode();
|
2012-10-31 01:59:58 +01:00
|
|
|
return true;
|
2013-02-01 23:01:11 +01:00
|
|
|
case 1:
|
|
|
|
if (!Permissions.hasPermission(sender, "mcmmo.commands.mcgod.others")) {
|
|
|
|
sender.sendMessage(command.getPermissionMessage());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
McMMOPlayer mcMMOPlayer = Users.getPlayer(args[0]);
|
2012-10-31 01:59:58 +01:00
|
|
|
|
2013-02-01 23:01:11 +01:00
|
|
|
// If the mcMMOPlayer doesn't exist, create a temporary profile and
|
|
|
|
// check if it's present in the database. If it's not, abort the process.
|
|
|
|
if (mcMMOPlayer == null) {
|
|
|
|
profile = new PlayerProfile(args[0], false);
|
2012-04-05 06:44:12 +02:00
|
|
|
|
2013-02-01 23:01:11 +01:00
|
|
|
if (!profile.isLoaded()) {
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
profile = mcMMOPlayer.getProfile();
|
|
|
|
Player player = mcMMOPlayer.getPlayer();
|
2012-04-05 06:44:12 +02:00
|
|
|
|
2013-02-01 23:01:11 +01:00
|
|
|
// Check if the player is online before we try to send them a message.
|
|
|
|
if (player.isOnline()) {
|
|
|
|
if (profile.getGodMode()) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.GodMode.Disabled"));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.GodMode.Enabled"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
profile.toggleGodMode();
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2012-04-05 06:44:12 +02:00
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|