-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
152 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package gg.quartzdev.qxpboosts.commands; | ||
|
||
import gg.quartzdev.qxpboosts.qXpBoosts; | ||
import gg.quartzdev.qxpboosts.util.Language; | ||
import gg.quartzdev.qxpboosts.util.qUtil; | ||
import org.bukkit.command.CommandSender; | ||
|
||
public class CMD extends qCMD { | ||
|
||
public CMD(String name, String label) { | ||
super(name, label); | ||
this.permissionGroup = "qxpboosts.admin"; | ||
this.permissionNode = "qxpboosts.command.info"; | ||
} | ||
|
||
@Override | ||
public boolean logic(CommandSender sender, String[] args) { | ||
qUtil.sendMessage(sender, Language.PLUGIN_INFO.parse("version", qXpBoosts.getInstance().getPluginMeta().getVersion())); | ||
return true; | ||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/gg/quartzdev/qxpboosts/commands/CMDdisable.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,4 @@ | ||
package gg.quartzdev.qxpboosts.commands; | ||
|
||
public class CMDdisable { | ||
} |
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,4 @@ | ||
package gg.quartzdev.qxpboosts.commands; | ||
|
||
public class CMDenable { | ||
} |
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,4 @@ | ||
package gg.quartzdev.qxpboosts.commands; | ||
|
||
public class CMDlist { | ||
} |
21 changes: 20 additions & 1 deletion
21
src/main/java/gg/quartzdev/qxpboosts/commands/CMDreload.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 |
---|---|---|
@@ -1,4 +1,23 @@ | ||
package gg.quartzdev.qxpboosts.commands; | ||
|
||
public class CMDreload { | ||
import gg.quartzdev.qxpboosts.qXpBoosts; | ||
import gg.quartzdev.qxpboosts.util.Language; | ||
import gg.quartzdev.qxpboosts.util.qUtil; | ||
import org.bukkit.command.CommandSender; | ||
|
||
public class CMDreload extends qCMD { | ||
|
||
public CMDreload(String name, String label) { | ||
super(name, label); | ||
this.permissionGroup = "qxpboosts.admin"; | ||
this.permissionNode = "qxpboosts.command.reload"; | ||
} | ||
|
||
@Override | ||
public boolean logic(CommandSender sender, String[] args) { | ||
qXpBoosts.getInstance().config.reload(); | ||
qUtil.sendMessage(sender, Language.RELOAD_COMPLETE); | ||
return true; | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
src/main/java/gg/quartzdev/qxpboosts/commands/CommandManager.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,55 @@ | ||
package gg.quartzdev.qxpboosts.commands; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.util.StringUtil; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class CommandManager extends Command { | ||
|
||
List<String> aliases = new ArrayList<>(); | ||
List<String> commandsList = new ArrayList<>(); | ||
|
||
public CommandManager(String name){ | ||
super(name); | ||
aliases.add("xpboosts"); | ||
super.setPermission("qxpboosts.command"); | ||
super.setAliases(aliases); | ||
commandsList.add("reload"); | ||
commandsList.add("list"); | ||
commandsList.add("enable"); | ||
commandsList.add("disable"); | ||
Bukkit.getCommandMap().register(name, this); | ||
} | ||
|
||
@Override | ||
public boolean execute(@NotNull CommandSender sender, @NotNull String labelOrAlias, @NotNull String[] args) { | ||
|
||
if(args.length >= 1) | ||
if(args[0].equalsIgnoreCase("reload")) | ||
return (new CMDreload(args[0], labelOrAlias)).run(sender, args); | ||
|
||
return (new CMD(null, labelOrAlias)).run(sender, args); | ||
|
||
} | ||
|
||
@Override | ||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String labelOrAlias, String[] args) throws IllegalArgumentException { | ||
List<String> completions = new ArrayList<>(); | ||
|
||
if(args.length == 0) return completions; | ||
|
||
if(args.length == 1){ | ||
StringUtil.copyPartialMatches(args[0], commandsList, completions); | ||
} | ||
Collections.sort(completions); | ||
return completions; | ||
} | ||
|
||
|
||
} |
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 |
---|---|---|
@@ -1,4 +1,43 @@ | ||
package gg.quartzdev.qxpboosts.commands; | ||
|
||
public class qCMD { | ||
import gg.quartzdev.qxpboosts.util.Language; | ||
import gg.quartzdev.qxpboosts.util.qUtil; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
|
||
public abstract class qCMD { | ||
|
||
String label; | ||
String name; | ||
String permissionGroup; | ||
String permissionNode; | ||
String commandSyntax; | ||
|
||
public qCMD(String name, String label){ | ||
this.name = name; | ||
this.label = label; | ||
} | ||
public boolean run(CommandSender sender, String[] args){ | ||
// checks permission | ||
if(!this.hasPermission(sender)){ | ||
qUtil.sendMessage(sender, Language.ERROR_NO_PERMISSION); | ||
return false; | ||
} | ||
// runs command | ||
return logic(sender, args); | ||
} | ||
public abstract boolean logic(CommandSender sender, String[] args); | ||
public boolean hasPermission(CommandSender sender){ | ||
// If sender is console | ||
if(!(sender instanceof Player)) return true; | ||
// If sender is op | ||
if(sender.isOp()) return true; | ||
// If sender has permission group | ||
if(sender.hasPermission(this.permissionGroup)) return true; | ||
// If sender has permission node | ||
if(sender.hasPermission(this.permissionNode)) return true; | ||
// else | ||
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