Created
August 14, 2014 11:51
-
-
Save Goblom/77c70f39dea4a972f0f1 to your computer and use it in GitHub Desktop.
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
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