Skip to content

Instantly share code, notes, and snippets.

@Goblom
Created August 14, 2014 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Goblom/77c70f39dea4a972f0f1 to your computer and use it in GitHub Desktop.
Save Goblom/77c70f39dea4a972f0f1 to your computer and use it in GitHub Desktop.
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
/**
*
* @author Goblom
*/
public class Example {
private static final Map<UUID, List<String>> allowedCommands = new HashMap();
static {
//lets pretend this is my uuid
allowedCommands.put(UUID.randomUUID(), Arrays.asList("help", "msg", "tell", "pm", "tp"));
}
public boolean isAllowedToUse(Player player, String command) {
List<String> commands = allowedCommands.get(player.getUniqueId());
boolean canUse = false;
for (String cmd : commands) {
if (cmd.equalsIgnoreCase(command)) {
canUse = true;
break;
}
}
return canUse;
}
@EventHandler
public void onCommandPreprocess(PlayerCommandPreprocessEvent event) {
//should return "help" instead of "/help"
String command = event.getMessage().split(" ")[0].replace("/", "");
if (!isAllowedToUse(event.getPlayer(), command)) {
//This stoppes the command from being sent to the plugin that handles the command
event.setCancelled(true);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment