TFM-4.3-Reloaded/src/main/java/me/StevenLawson/TotalFreedomMod/commands/Command_resetplayer.java

53 lines
1.8 KiB
Java
Raw Normal View History

2022-03-28 22:04:21 +00:00
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;
}
}