diff options
author | David Panić <david@panic.tk> | 2019-04-07 19:55:48 +0200 |
---|---|---|
committer | David Panić <david@panic.tk> | 2019-04-07 19:55:48 +0200 |
commit | e74a959d7481a4514cd91389949c68a382997706 (patch) | |
tree | 009be88d41a6a80ccb4efd76894cdd35ecb5a7a4 /src/main/java/com/redstoner/bungeeBans/commands/UnbanCommand.java | |
parent | afc5c65761cae9f52f53ae7f6ecc495600cb94c9 (diff) |
Created basic ban functionality (IP bans not yet supported)
Diffstat (limited to 'src/main/java/com/redstoner/bungeeBans/commands/UnbanCommand.java')
-rw-r--r-- | src/main/java/com/redstoner/bungeeBans/commands/UnbanCommand.java | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/main/java/com/redstoner/bungeeBans/commands/UnbanCommand.java b/src/main/java/com/redstoner/bungeeBans/commands/UnbanCommand.java new file mode 100644 index 0000000..a495dbb --- /dev/null +++ b/src/main/java/com/redstoner/bungeeBans/commands/UnbanCommand.java @@ -0,0 +1,80 @@ +package com.redstoner.bungeeBans.commands; + +import com.mojang.api.profiles.HttpProfileRepository; +import com.mojang.api.profiles.Profile; +import com.redstoner.bungeeBans.BanManager; +import com.redstoner.bungeeBans.Util; +import com.redstoner.bungeeBans.json.PlayerBan; +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.TextComponent; +import net.md_5.bungee.api.plugin.Command; + +import java.io.IOException; + +public class UnbanCommand extends Command { + HttpProfileRepository profileRepo = new HttpProfileRepository("minecraft"); + + private BanManager<PlayerBan> bm; + + public UnbanCommand(BanManager<PlayerBan> bm) { + super("unban", "bungeebans.unban", "pardon"); + + this.bm = bm; + } + + @Override + public void execute(CommandSender sender, String[] args) { + if (args.length != 1) { + sender.sendMessage( + new ComponentBuilder(ChatColor.RED + "Invalid command! ") + .append("Usage: ") + .append(ChatColor.AQUA + "/unban ") + .append(ChatColor.GOLD + "<username> ") + .create() + ); + + return; + } + + Profile[] profiles = profileRepo.findProfilesByNames(args[0]); + + if (profiles.length != 1) { + sender.sendMessage(new TextComponent(ChatColor.RED + "Invalid name!")); + return; + } + + String uuid = Util.dashUUID(profiles[0].getId()); + String name = profiles[0].getName(); + + PlayerBan ban = bm.getBan(uuid); + + if (ban == null) { + sender.sendMessage(new TextComponent(ChatColor.RED + "That player is not banned!")); + return; + } + + bm.removeBan(ban); + + try { + bm.saveBans(); + sender.sendMessage(new TextComponent(ChatColor.GREEN + "Saved bans to file!")); + } catch (IOException e) { + sender.sendMessage(new TextComponent(ChatColor.RED + "Failed to save bans to file!")); + e.printStackTrace(); + + bm.addBan(ban); + return; + } + + sender.sendMessage( + new ComponentBuilder(ChatColor.GREEN + "Unbanned player ") + .append(ChatColor.AQUA + name) + .append(ChatColor.GREEN + " with uuid ") + .append(ChatColor.AQUA + uuid) + .create() + ); + + } +} |