-
Notifications
You must be signed in to change notification settings - Fork 419
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
4 changed files
with
106 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/main/java/cn/nukkit/command/defaults/ClearCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package cn.nukkit.command.defaults; | ||
|
||
import cn.nukkit.Player; | ||
import cn.nukkit.Server; | ||
import cn.nukkit.command.Command; | ||
import cn.nukkit.command.CommandSender; | ||
import cn.nukkit.command.data.CommandEnum; | ||
import cn.nukkit.command.data.CommandParamType; | ||
import cn.nukkit.command.data.CommandParameter; | ||
import cn.nukkit.item.Item; | ||
import cn.nukkit.lang.TranslationContainer; | ||
import cn.nukkit.utils.TextFormat; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Created on 2024/26/2 by Sherko231. | ||
* Package cn.nukkit.command.defaults in project Nukkit . | ||
*/ | ||
public class ClearCommand extends VanillaCommand { | ||
public ClearCommand(String name) { | ||
super(name, "%nukkit.command.clear.description", "%nukkit.command.clear.usage"); | ||
this.setPermission("nukkit.command.clear"); | ||
this.commandParameters.clear(); | ||
this.commandParameters.put("default", new CommandParameter[]{}); | ||
this.commandParameters.put("target", new CommandParameter[]{ | ||
CommandParameter.newType("player", CommandParamType.TARGET), | ||
}); | ||
} | ||
|
||
@Override | ||
public boolean execute(CommandSender sender, String commandLabel, String[] args) { | ||
if (!this.testPermission(sender)) { | ||
return false; | ||
} | ||
|
||
if (args.length > 1 || (!(sender instanceof Player) && args.length < 1)) { | ||
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage)); | ||
return false; | ||
} | ||
|
||
if (args.length == 0) { | ||
Player player = (Player) sender; | ||
player.getInventory().clearAll(); | ||
return false; | ||
} | ||
|
||
List<Player> targets = new ArrayList<>(); | ||
if (args[0].equals("@a")) { | ||
targets.addAll(Server.getInstance().getOnlinePlayers().values()); | ||
} | ||
else { | ||
Player target = sender.getServer().getPlayer(args[0].replace("@s", sender.getName())); | ||
if (target != null) { | ||
targets.add(target); | ||
} | ||
else { | ||
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.player.notFound")); | ||
return false; | ||
} | ||
} | ||
|
||
for (Player player : targets) { | ||
player.getInventory().clearAll(); | ||
Command.broadcastCommandMessage(sender, new TranslationContainer("%commands.clear.success", player.getName())); | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters