Add reset player command

This commit is contained in:
Business Goose 2022-03-28 23:04:21 +01:00
parent 804f846e73
commit 5df6d4cfed
No known key found for this signature in database
GPG key ID: 77DCA801362E9645
3 changed files with 58 additions and 1 deletions

View file

@ -0,0 +1,52 @@
package me.StevenLawson.TotalFreedomMod.commands;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.nio.file.Files;
import java.nio.file.Paths;
@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.BOTH)
public class Command_resetplayer extends FreedomCommand {
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
OfflinePlayer target = null;
String searchString = args[0];
for (OfflinePlayer offlinePlayer : Bukkit.getOfflinePlayers()) {
if(offlinePlayer.getName().equalsIgnoreCase(searchString)) {
target = offlinePlayer;
break;
} else if (offlinePlayer.getName().startsWith(searchString.toLowerCase())) {
target = offlinePlayer;
break;
}
}
if(target == null) {
playerMsg(sender, FreedomCommand.PLAYER_NOT_FOUND);
return true;
}
if(target.isOnline()) {
target.getPlayer().kickPlayer(ChatColor.RED + "YOU ARE BEING RESET.");
}
playerMsg(sender, String.format("Resetting %s's user data (excluding TFM)...", target.getName()));
try {
String uuid = target.getUniqueId().toString();
Files.deleteIfExists(Paths.get(".", "world", "playerdata", uuid + ".dat"));
Files.deleteIfExists(Paths.get(".", "plugins", "Essentials", "userdata", uuid + ".yml"));
playerMsg(sender, "Done.");
} catch (Exception e) {
e.printStackTrace();
playerMsg(sender, "Oops");
}
return true;
}
}

View file

@ -108,5 +108,6 @@ public class Commands {
plugin.getCommand("wipeuserdata").setExecutor(new Command_wipeuserdata()); plugin.getCommand("wipeuserdata").setExecutor(new Command_wipeuserdata());
plugin.getCommand("whoami").setExecutor(new Command_whoami()); plugin.getCommand("whoami").setExecutor(new Command_whoami());
plugin.getCommand("offlinetp").setExecutor(new Command_offlinetp()); plugin.getCommand("offlinetp").setExecutor(new Command_offlinetp());
plugin.getCommand("resetplayer").setExecutor(new Command_resetplayer());
} }
} }

View file

@ -337,4 +337,8 @@ commands:
offlinetp: offlinetp:
aliases: ["otp"] aliases: ["otp"]
description: 'Teleport to an offline player''s last known location.' description: 'Teleport to an offline player''s last known location.'
usage: '/<command> <partialName>' usage: '/<command> <partialName>'
resetplayer:
aliases: ["resetplayerdata"]
description: 'Reset a player''s data.'
usage: '/command <partialName>'