/ess reset <player> - Clears stored data about a user.

This commit is contained in:
KHobbits 2012-09-14 02:30:24 +01:00
parent d988546ef3
commit cc0a65bace
2 changed files with 25 additions and 2 deletions

View File

@ -13,13 +13,14 @@ import org.bukkit.inventory.ItemStack;
public abstract class UserData extends PlayerExtension implements IConf
{
protected final transient IEssentials ess;
private final EssentialsConf config;
private EssentialsConf config;
private final File folder;
protected UserData(Player base, IEssentials ess)
{
super(base);
this.ess = ess;
File folder = new File(ess.getDataFolder(), "userdata");
folder = new File(ess.getDataFolder(), "userdata");
if (!folder.exists())
{
folder.mkdirs();
@ -27,6 +28,12 @@ public abstract class UserData extends PlayerExtension implements IConf
config = new EssentialsConf(new File(folder, Util.sanitizeFileName(base.getName()) + ".yml"));
reloadConfig();
}
public final void reset () {
config.getFile().delete();
config = new EssentialsConf(new File(folder, Util.sanitizeFileName(base.getName()) + ".yml"));
reloadConfig();
}
@Override
public final void reloadConfig()

View File

@ -1,6 +1,7 @@
package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
import com.earth2me.essentials.metrics.Metrics;
import java.io.IOException;
import java.util.HashMap;
@ -41,6 +42,10 @@ public class Commandessentials extends EssentialsCommand
{
run_moo(server, sender, commandLabel, args);
}
else if (args[0].equalsIgnoreCase("reset"))
{
run_reset(server, sender, commandLabel, args);
}
else if (args[0].equalsIgnoreCase("opt-out"))
{
run_optout(server, sender, commandLabel, args);
@ -69,6 +74,17 @@ public class Commandessentials extends EssentialsCommand
}
}
private void run_reset(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
if (args.length < 2)
{
throw new NotEnoughArgumentsException("/<command> reset <player>");
}
final User user = getPlayer(server, args, 1, true);
user.reset();
sender.sendMessage("Reset Essentials userdata for player: " + user.getDisplayName());
}
private void run_debug(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
ess.getSettings().setDebug(!ess.getSettings().isDebug());