Added Adminchat

Conflicts:
	src/me/StevenLawson/TotalFreedomMod/TFM_Util.java
This commit is contained in:
Jerom van der Sar 2012-11-28 19:31:01 +01:00 committed by Steven Lawson
parent f7393a85c4
commit 11347c2327
5 changed files with 80 additions and 3 deletions

View File

@ -0,0 +1,38 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
import me.StevenLawson.TotalFreedomMod.TFM_UserInfo;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = ADMIN_LEVEL.SUPER, source = SOURCE_TYPE_ALLOWED.BOTH, ignore_permissions = false)
public class Command_o extends TFM_Command
{
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if(senderIsConsole && args.length == 0)
{
TFM_Util.playerMsg(sender, "Only in-game players can toggle AdminChat.");
return true;
}
if(args.length == 0)
{
TFM_UserInfo userinfo = TFM_UserInfo.getPlayerData(sender_p);
userinfo.setAdminChat(!userinfo.inAdminChat());
TFM_Util.playerMsg(sender, "Toggled Admin Chat " + (userinfo.inAdminChat() ? "on" : "off")+".");
}
else
{
// very complicated magic stuff
TFM_Util.AdminChatMessage(sender, StringUtils.join(args, " "), senderIsConsole);
}
return true;
}
}

View File

@ -358,8 +358,17 @@ public class TFM_PlayerListener implements Listener
} }
} }
// finally, set message // check for adminchat
event.setMessage(message); if(playerdata.inAdminChat())
{
TFM_Util.AdminChatMessage(p, message, false);
event.setCancelled(true);
}
else
{
// finally, set message
event.setMessage(message);
}
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -46,6 +46,7 @@ public class TFM_UserInfo
private boolean mp44_firing = false; private boolean mp44_firing = false;
private int lockup_schedule_id = -1; private int lockup_schedule_id = -1;
private String last_message = ""; private String last_message = "";
private boolean in_adminchat = false;
public TFM_UserInfo(Player player) public TFM_UserInfo(Player player)
{ {
@ -417,4 +418,14 @@ public class TFM_UserInfo
{ {
return this.last_message; return this.last_message;
} }
public void setAdminChat(boolean in_adminchat)
{
this.in_adminchat = in_adminchat;
}
public boolean inAdminChat()
{
return this.in_adminchat;
}
} }

View File

@ -998,4 +998,20 @@ public class TFM_Util
fos.getChannel().transferFrom(rbc, 0, 1 << 24); fos.getChannel().transferFrom(rbc, 0, 1 << 24);
fos.close(); fos.close();
} }
public static void AdminChatMessage(CommandSender sender, String message, boolean senderIsConsole)
{
// complicated magic
String name = sender.getName()+
(senderIsConsole ? ChatColor.DARK_PURPLE+" (Console)" :
(TFM_SuperadminList.isSeniorAdmin(sender) ? ChatColor.LIGHT_PURPLE+ " (SrA)" : ChatColor.GOLD+" (SA)"));
TFM_Log.info("[ADMIN] " + name + ": " + message);
for(Player p : Bukkit.getOnlinePlayers())
{
if(TFM_SuperadminList.isUserSuperadmin(p))
{
p.sendMessage("[" + ChatColor.AQUA + "ADMIN" + ChatColor.WHITE + "] " + ChatColor.DARK_RED + name + ChatColor.WHITE + ": " + ChatColor.AQUA + message);
}
}
}
} }

View File

@ -119,6 +119,9 @@ commands:
nonuke: nonuke:
description: Superadmin command - Attempt to detect "invisible griefers" and "nukers". description: Superadmin command - Attempt to detect "invisible griefers" and "nukers".
usage: /<command> <on | off> [range] [blockrate] usage: /<command> <on | off> [range] [blockrate]
o:
description: Superadmin command - Talk privately with other admins
usage: /<command> [message]
onlinemode: onlinemode:
description: Console command - Switch server online-mode on and off. description: Console command - Switch server online-mode on and off.
usage: /<command> <on | off> usage: /<command> <on | off>
@ -130,7 +133,7 @@ commands:
usage: /<command> [-c | -s] usage: /<command> [-c | -s]
ops: ops:
description: Superadmin command - Manage operators description: Superadmin command - Manage operators
usage: /<command> [count | list | purge] usage: /<command> <count | list | purge>
opme: opme:
description: Superadmin command - Automatically ops user. description: Superadmin command - Automatically ops user.
usage: /<command> usage: /<command>