mirror of
https://github.com/TheDeus-Group/TFM-4.3-Reloaded.git
synced 2024-12-22 22:24:56 +00:00
Add reset player command
This commit is contained in:
parent
804f846e73
commit
5df6d4cfed
3 changed files with 58 additions and 1 deletions
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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>'
|
Loading…
Reference in a new issue