|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: MIT |
| 3 | + * |
| 4 | + * The MIT License (MIT) |
| 5 | + * |
| 6 | + * Copyright (c) 2015-2024 games647 and contributors |
| 7 | + * |
| 8 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | + * of this software and associated documentation files (the "Software"), to deal |
| 10 | + * in the Software without restriction, including without limitation the rights |
| 11 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | + * copies of the Software, and to permit persons to whom the Software is |
| 13 | + * furnished to do so, subject to the following conditions: |
| 14 | + * |
| 15 | + * The above copyright notice and this permission notice shall be included in all |
| 16 | + * copies or substantial portions of the Software. |
| 17 | + * |
| 18 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 24 | + * SOFTWARE. |
| 25 | + */ |
| 26 | +package com.github.games647.fastlogin.bukkit.command; |
| 27 | + |
| 28 | +import java.util.ArrayList; |
| 29 | +import java.util.List; |
| 30 | + |
| 31 | +import org.bukkit.Bukkit; |
| 32 | +import org.bukkit.command.Command; |
| 33 | +import org.bukkit.command.CommandSender; |
| 34 | +import org.bukkit.command.ConsoleCommandSender; |
| 35 | +import org.bukkit.command.TabExecutor; |
| 36 | +import org.bukkit.entity.Player; |
| 37 | + |
| 38 | +import com.github.games647.fastlogin.bukkit.FastLoginBukkit; |
| 39 | + |
| 40 | +public class DeleteCommand implements TabExecutor { |
| 41 | + private final FastLoginBukkit plugin; |
| 42 | + |
| 43 | + public DeleteCommand(FastLoginBukkit plugin) { |
| 44 | + this.plugin = plugin; |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Handles the command to delete profiles. |
| 49 | + */ |
| 50 | + @Override |
| 51 | + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { |
| 52 | + |
| 53 | + if (!sender.hasPermission(command.getPermission())) { |
| 54 | + plugin.getCore().sendLocaleMessage("no-permission", sender); |
| 55 | + return true; |
| 56 | + } |
| 57 | + |
| 58 | + if (plugin.getBungeeManager().isEnabled()) { |
| 59 | + sender.sendMessage("Error: Cannot delete profile entries when using BungeeCord!"); |
| 60 | + return false; |
| 61 | + } |
| 62 | + |
| 63 | + if (args.length < 1) { |
| 64 | + sender.sendMessage("Error: Must supply username to delete!"); |
| 65 | + return false; |
| 66 | + } |
| 67 | + |
| 68 | + Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { |
| 69 | + int count = plugin.getCore().getStorage().deleteProfile(args[0]); |
| 70 | + if (!(sender instanceof ConsoleCommandSender)) { |
| 71 | + Bukkit.getScheduler().runTask(plugin, () -> { |
| 72 | + if (count == 0) { |
| 73 | + sender.sendMessage("Error: No profile entries found!"); |
| 74 | + } else { |
| 75 | + sender.sendMessage("Deleted " + count + " matching profile entries"); |
| 76 | + } |
| 77 | + }); |
| 78 | + } |
| 79 | + }); |
| 80 | + |
| 81 | + return true; |
| 82 | + } |
| 83 | + |
| 84 | + @Override |
| 85 | + public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) { |
| 86 | + List<String> list = new ArrayList<>(); |
| 87 | + for (Player p : Bukkit.getOnlinePlayers()) { |
| 88 | + if (p.getName().toLowerCase().startsWith(args[0])) { |
| 89 | + list.add(p.getName()); |
| 90 | + } |
| 91 | + } |
| 92 | + return null; |
| 93 | + } |
| 94 | +} |
0 commit comments