Skip to content

Commit

Permalink
Added /checksilktouch command to check if player has silk touch
Browse files Browse the repository at this point in the history
  • Loading branch information
5U55 committed May 29, 2021
1 parent b10c301 commit 10bcf65
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ commands:
unsilktouch:
description: removes the ability for the player to have silk touch when they destroy blocks with their hand
usage: /unsilktouch
permission: silktouchhands.silktouch
checksilktouch:
description: checks if the player has the ability to have silk touch when they destroy blocks with their hand
usage: /checksilktouch
permission: silktouchhands.silktouch
39 changes: 39 additions & 0 deletions src/net/ejs/silktouchhands/CheckSilkTouchCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package net.ejs.silktouchhands;

import java.util.Arrays;

import org.bukkit.NamespacedKey;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;

import net.md_5.bungee.api.ChatColor;

public class CheckSilkTouchCommand implements CommandExecutor{
@Override
public boolean onCommand(CommandSender sender, Command arg1, String arg2, String[] arguments) {
if (sender instanceof Player) {
Player player = (Player) sender;
if (arguments.length == 1) {
player = sender.getServer().getPlayerExact(arguments[0]);
}
if (player == null) {
sender.sendMessage(ChatColor.AQUA + arguments[0] + " is offline");
}
else if (arguments.length > 1) {
player.sendMessage(ChatColor.RED + Arrays.toString(arguments) + " is not valid input, only list 0-1 players");
} else {
PersistentDataContainer data = player.getPersistentDataContainer();
if(data.get(new NamespacedKey(SilkTouchHands.getPlugin(), "cansilktouch"), PersistentDataType.STRING).equals("silktouch")) {
player.sendMessage(ChatColor.GOLD + player.getName()+" has silk touch hands");
} else {
player.sendMessage(ChatColor.GOLD + player.getName()+" does not have silk touch hands");
}
}
}
return true;
}
}
1 change: 1 addition & 0 deletions src/net/ejs/silktouchhands/SilkTouchHands.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class SilkTouchHands extends JavaPlugin implements Listener {
public void onEnable() {
this.getCommand("silktouch").setExecutor(new SilkTouchCommand());
this.getCommand("unsilktouch").setExecutor(new UnsilkTouchCommand());
this.getCommand("checksilktouch").setExecutor(new CheckSilkTouchCommand());
Bukkit.getPluginManager().registerEvents(this, this);
plugin = this;
}
Expand Down
Binary file modified target/SilkTouch.jar
Binary file not shown.

0 comments on commit 10bcf65

Please sign in to comment.