[trunk] new socialspy command. if toggled will show the output of /msg and /mail in the chat for the toggle persons. usage /socialspy to turn on, /socialspy again to turn off

git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1338 e251c2fe-e539-e718-e476-b85c1f46cddb
This commit is contained in:
ementalo 2011-05-04 10:39:56 +00:00
parent 21601e34d2
commit d0dc96542b
5 changed files with 68 additions and 1 deletions

View File

@ -23,7 +23,7 @@ import org.bukkit.plugin.java.*;
public class Essentials extends JavaPlugin
{
public static final String AUTHORS = "Zenexer, ementalo, Aelux, Brettflan, KimKandor, snowleo and ceulemans.";
public static final int minBukkitBuildVersion = 733;
public static final int minBukkitBuildVersion = 740;
private static final Logger logger = Logger.getLogger("Minecraft");
private Settings settings;
private EssentialsPlayerListener playerListener;
@ -304,6 +304,22 @@ public class Essentials extends JavaPlugin
@Override
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args)
{
if ("msg".equals(commandLabel.toLowerCase()) || "mail".equals(commandLabel.toLowerCase()) & sender instanceof Player)
{
StringBuilder str = new StringBuilder();
for (String a : args)
{
str.append(a + " ");
}
for (Player player : getServer().getOnlinePlayers())
{
if (getUser(player).isSocialSpyEnabled())
{
player.sendMessage(getUser(sender).getDisplayName() + " : " + str);
}
}
}
// Allow plugins to override the command via onCommand
if (!getSettings().isCommandOverridden(command.getName()) && !commandLabel.startsWith("e"))
{

View File

@ -55,6 +55,7 @@ public abstract class UserData extends PlayerExtension implements IConf
lastLogout = _getLastLogout();
afk = getAfk();
geolocation = _getGeoLocation();
isSocialSpyEnabled = _isSocialSpyEnabled();
}
public double getMoney()
@ -391,6 +392,12 @@ public abstract class UserData extends PlayerExtension implements IConf
setTeleportEnabled(ret);
return ret;
}
public boolean toggleSocialSpy()
{
boolean ret = !isSocialSpyEnabled();
setSocialSpyEnabled(ret);
return ret;
}
private List<String> ignoredPlayers;
public List<String> getIgnoredPlayers()
@ -670,4 +677,22 @@ public abstract class UserData extends PlayerExtension implements IConf
}
config.save();
}
private boolean isSocialSpyEnabled;
private boolean _isSocialSpyEnabled()
{
return config.getBoolean("socialspy", false);
}
public boolean isSocialSpyEnabled()
{
return isSocialSpyEnabled;
}
public void setSocialSpyEnabled(Boolean status)
{
config.setProperty("socialspy", status);
config.save();
}
}

View File

@ -1,5 +1,6 @@
package com.earth2me.essentials.commands;
import com.earth2me.essentials.commands.EssentialsCommand;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;

View File

@ -0,0 +1,22 @@
package com.earth2me.essentials.commands;
import com.earth2me.essentials.User;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
public class Commandsocialspy extends EssentialsCommand
{
public Commandsocialspy()
{
super("socialspy");
}
@Override
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
{
charge(user);
user.sendMessage("§7SocialSpy " + (user.toggleSocialSpy() ? "enabled." : "disabled."));
}
}

View File

@ -226,6 +226,9 @@ commands:
description: Set the value of an item for sale, will add item if doesn't exist
usage: /<command> [itemname|id] [price]
aliases: [esetworth]
socialspy:
description: Toggles if you can see /msg and /mail commands in chat.
usage: /<command>
spawnmob:
description: Spawns a mob.
usage: /<command> [mob]<:data><,mount<:data>> <amount>