mcMMO/src/main/java/com/gmail/nossr50/chat/commands/AdminChatCommand.java

88 lines
2.9 KiB
Java
Raw Normal View History

2013-02-02 06:09:47 +01:00
package com.gmail.nossr50.chat.commands;
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;
import com.gmail.nossr50.mcMMO;
2013-02-02 06:09:47 +01:00
import com.gmail.nossr50.chat.ChatManager;
import com.gmail.nossr50.datatypes.McMMOPlayer;
2012-04-27 11:47:11 +02:00
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Users;
2012-01-09 20:00:13 +01:00
public class AdminChatCommand implements CommandExecutor {
2012-04-21 00:09:50 +02:00
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
McMMOPlayer mcMMOPlayer;
2012-04-18 19:01:07 +02:00
2012-04-22 08:55:58 +02:00
switch (args.length) {
case 0:
if (!(sender instanceof Player)) {
return false;
}
2012-04-18 19:01:07 +02:00
mcMMOPlayer = Users.getPlayer((Player) sender);
2012-01-09 20:00:13 +01:00
// Can't have both party & admin chat at the same time.
if (mcMMOPlayer.getPartyChatMode()) {
mcMMOPlayer.togglePartyChat();
}
2012-01-09 20:00:13 +01:00
mcMMOPlayer.toggleAdminChat();
if (mcMMOPlayer.getAdminChatMode()) {
sender.sendMessage(LocaleLoader.getString("Commands.AdminChat.On"));
2012-04-21 00:09:50 +02:00
}
2012-04-22 08:55:58 +02:00
else {
sender.sendMessage(LocaleLoader.getString("Commands.AdminChat.Off"));
2012-04-22 08:55:58 +02:00
}
2012-04-21 00:09:50 +02:00
return true;
2012-01-09 20:00:13 +01:00
2012-04-22 08:55:58 +02:00
default:
if (args.length == 1) {
if (!(sender instanceof Player)) {
return false;
}
mcMMOPlayer = Users.getPlayer((Player) sender);
if (args[0].equalsIgnoreCase("on")) {
mcMMOPlayer.setPartyChat(false);
mcMMOPlayer.setAdminChat(true);
sender.sendMessage(LocaleLoader.getString("Commands.AdminChat.On"));
return true;
}
if (args[0].equalsIgnoreCase("off")) {
mcMMOPlayer.setAdminChat(false);
sender.sendMessage(LocaleLoader.getString("Commands.AdminChat.Off"));
return true;
}
}
2013-01-31 00:58:31 +01:00
StringBuilder builder = new StringBuilder();
builder.append(args[0]);
2012-01-09 20:00:13 +01:00
2012-04-22 08:55:58 +02:00
for (int i = 1; i < args.length; i++) {
2013-01-31 00:58:31 +01:00
builder.append(" ");
builder.append(args[i]);
2012-04-22 08:55:58 +02:00
}
2012-01-09 20:00:13 +01:00
2013-01-31 00:58:31 +01:00
String message = builder.toString();
2012-04-22 08:55:58 +02:00
if (sender instanceof Player) {
Player player = (Player) sender;
ChatManager.handleAdminChat(mcMMO.p, player.getName(), player.getDisplayName(), message);
2012-04-21 00:09:50 +02:00
}
2012-04-22 08:55:58 +02:00
else {
String ssender = LocaleLoader.getString("Commands.Chat.Console");
ChatManager.handleAdminChat(mcMMO.p, ssender, ssender, message);
2012-04-21 00:09:50 +02:00
}
2012-04-22 08:55:58 +02:00
return true;
2012-04-21 00:09:50 +02:00
}
}
2012-01-09 20:00:13 +01:00
}