Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed some things, added permissions per command #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
import org.bukkit.plugin.java.JavaPlugin;

import java.util.ArrayList;
import java.util.List;

public final class CustomCommands extends JavaPlugin implements Listener {

public ArrayList<String> cmds = new ArrayList<>();
public List<String> cmds = new ArrayList<>();

@Override
public void onEnable() {
Expand All @@ -23,34 +24,46 @@ public void onEnable() {
}

public void loadCommands() {
for (String s : getConfig().getKeys(false)) {
cmds.add(s.toLowerCase());
}
getConfig().getKeys(false).forEach(s -> cmds.add(s.toLowerCase()));
}

@EventHandler
public void onCommand(PlayerCommandPreprocessEvent ev) {
String command = ev.getMessage().replace("/","");
if (cmds.contains(command)) {
if (cmds.contains(command.toLowerCase())) {
ev.setCancelled(true);
for (String s : getConfig().getStringList(command)) {
Player player = ev.getPlayer();
if (getConfig().contains(command + ".permission") &&
!player.hasPermission(getConfig().getString(command + ".permission"))) {
if (getConfig().contains(command + ".no-permission-message"))
player.sendMessage(ChatColor.translateAlternateColorCodes('&',
getConfig().getString(command + ".no-permission-message")));
else
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for that command");
return;
}

for (String s : getConfig().getStringList(command + ".commands")) {
if (s.startsWith("/") || s.startsWith("\\")) {
if (s.startsWith("/")) {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), format(s.replace("/", ""), ev.getPlayer()));
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), format(s.replace("/", ""), player));
}
if (s.startsWith("\\")) {
ev.getPlayer().performCommand(format(s.replace("\\", ""), ev.getPlayer()));
player.performCommand(format(s.replace("\\", ""), player));
}
} else {
if (s.contains("<*>")) {
String multiplier = s.split("<*>")[1];
if (StringUtils.isNumeric(multiplier)) {
for (int i = 0; i < Integer.valueOf(s.split("<*>")[1]); i++) {
ev.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', format(s.replace("<*>","").replace(multiplier, ""), ev.getPlayer())));
player.sendMessage(ChatColor.translateAlternateColorCodes('&',
format(s.replace("<*>", "").replace(multiplier, ""), player)));
}
} else {
getLogger().info("The command '" + command + "' doesn't have a valid number multiplier!");
}
} else {
ev.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', format(s, ev.getPlayer())));
player.sendMessage(ChatColor.translateAlternateColorCodes('&', format(s, player)));
}
}
}
Expand Down
129 changes: 74 additions & 55 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,84 +1,103 @@
#Please use lowercase
# Please use lowercase
# <*>100 will send the message 100x
# / will run a command from the console
# \ will make the player run the command.
# <player> <health> <hunger> will be replaced accordingly.
#
vote:
- '&a----------&f[&6Vote&f]&a----------'
- '&aPlanetMinecruft: &chttp://poweredbyhate.net/'
- '&aSwagDoritos: &chttp://poweredbyhate.net/'
- '&aSpigotVotes: &chttp://poweredbyhate.net/'
- '&a----------&f[&6Vote&f]&a----------'
commands:
- '&a----------&f[&6Vote&f]&a----------'
- '&aPlanetMinecraft: &chttp://poweredbyhate.net/'
- '&aSwagDoritos: &chttp://poweredbyhate.net/'
- '&aSpigotVotes: &chttp://poweredbyhate.net/'
- '&a----------&f[&6Vote&f]&a----------'

# The following command is an example of using permissions with your custom commands.
discord:
- "&8&m-----------------------------------&f"
- " "
- "&cYou can join our Discord here!"
- "&c&7https://discord.gg/SvFEBGW"
- " "
- "&8&m-----------------------------------&f"
commands:
- "&8&m-----------------------------------&f"
- " "
- "&cYou can join our Discord here!"
- "&c&7https://discord.gg/SvFEBGW"
- " "
- "&8&m-----------------------------------&f"
permission: "customcommands.discord"
# no-permission-message is optional, if it's not enabled it'll give a generic no permission message
no-permission-message: "&4You don't have permission to join our Discord, you first need to be rank Trusted or higher!"

motd:
- "&8&m-----------------------------------&f"
- " "
- "&aWelcome back, &f<player>"
- "&cDiscord: &fhttps://discord.gg/SvFEBGW"
- "&cTwitter: &f@LaxWasHere"
- "&cStore: &fhttps://www.paypal.me/LaxWasHere"
- "&cYoutube: &fhttps://www.youtube.com/LaxWasHere"
- " "
- "&8&m-----------------------------------&f"
commands:
- "&8&m-----------------------------------&f"
- " "
- "&aWelcome back, &f<player>"
- "&cDiscord: &fhttps://discord.gg/SvFEBGW"
- "&cTwitter: &f@LaxWasHere"
- "&cStore: &fhttps://www.paypal.me/LaxWasHere"
- "&cYoutube: &fhttps://www.youtube.com/LaxWasHere"
- " "
- "&8&m-----------------------------------&f"

twitter:
- "&8&m-----------------------------------&f"
- " "
- "&cFollow us on twitter!"
- "&7@LaxWasHere"
- " "
- "&8&m-----------------------------------&f"
commands:
- "&8&m-----------------------------------&f"
- " "
- "&cFollow us on twitter!"
- "&7@LaxWasHere"
- " "
- "&8&m-----------------------------------&f"

donate:
- "&8&m-----------------------------------&f"
- " "
- "&cDonate to our server!"
- "&chttps://www.paypal.me/LaxWasHere"
- " "
- "&8&m-----------------------------------&f"
commands:
- "&8&m-----------------------------------&f"
- " "
- "&cDonate to our server!"
- "&chttps://www.paypal.me/LaxWasHere"
- " "
- "&8&m-----------------------------------&f"

forums:
- "&8&m-----------------------------------&f"
- " "
- "&cCheck out our forums!"
- "&7https://www.spigotmc.org"
- " "
- "&8&m-----------------------------------&f"
commands:
- "&8&m-----------------------------------&f"
- " "
- "&cCheck out our forums!"
- "&7https://www.spigotmc.org"
- " "
- "&8&m-----------------------------------&f"

youtube:
- "&8&m-----------------------------------&f"
- " "
- "&cSubscribe to our youtube channel!"
- "&7https://www.youtube.com/LaxWasHere"
- " "
- "&8&m-----------------------------------&f"
commands:
- "&8&m-----------------------------------&f"
- " "
- "&cSubscribe to our youtube channel!"
- "&7https://www.youtube.com/LaxWasHere"
- " "
- "&8&m-----------------------------------&f"

pleasekickme: #/ will run the command from the console
- "/kick <player> &cYou asked for it!"
pleasekickme: # / will run the command from the console
commands:
- "/kick <player> &cYou asked for it!"

iatemycat: #\ will run the command from the player
- '\me I ate my cat <player>'
iatemycat: # \ will run the command from the player
commands:
- '\me I ate my cat <player>'

clearmychat:
- " <*>100" #This will send an empty message 100x
commands:
- " <*>100" # This will send an empty message 100x

amiawesome:
- "&cYes <*>3" #This will '&cYes' 3x
commands:
- "&cYes <*>3" # This will '&cYes' 3x

laxwashere:
- '&aLaxWasHere, yes'
commands:
- "&aLaxWasHere, yes"

electroniccat:
- '&aLast known sighting:&c http://i.giphy.com/GFHJXPCoVQEec.gif'
commands:
- "&aLast known sighting:&c http://i.giphy.com/GFHJXPCoVQEec.gif"

#opme: #THIS AS IT WILL ACTUALLY OP THE PLAYER. DO NOT UNCOMMENT!
# - "/op <player>"
#opme: # THIS WILL OP ANY PLAYER THAT DOES THIS COMMAND, DON'T UNCOMMENT UNLESS YOU KNOW WHAT YOU'RE DOING
# commands:
# - "/op <player>"
# permission: "customcommands.opme"