Skip to content

Commit

Permalink
added reload config command
Browse files Browse the repository at this point in the history
  • Loading branch information
QarthO committed Dec 17, 2023
1 parent 7d2f944 commit 4530185
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 2 deletions.
22 changes: 22 additions & 0 deletions src/main/java/gg/quartzdev/qxpboosts/commands/CMD.java
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 src/main/java/gg/quartzdev/qxpboosts/commands/CMDdisable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package gg.quartzdev.qxpboosts.commands;

public class CMDdisable {
}
4 changes: 4 additions & 0 deletions src/main/java/gg/quartzdev/qxpboosts/commands/CMDenable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package gg.quartzdev.qxpboosts.commands;

public class CMDenable {
}
4 changes: 4 additions & 0 deletions src/main/java/gg/quartzdev/qxpboosts/commands/CMDlist.java
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 src/main/java/gg/quartzdev/qxpboosts/commands/CMDreload.java
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 src/main/java/gg/quartzdev/qxpboosts/commands/CommandManager.java
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;
}


}
41 changes: 40 additions & 1 deletion src/main/java/gg/quartzdev/qxpboosts/commands/qCMD.java
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;
}

}
3 changes: 3 additions & 0 deletions src/main/java/gg/quartzdev/qxpboosts/qXpBoosts.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gg.quartzdev.qxpboosts;

import gg.quartzdev.qxpboosts.boost.BoostManager;
import gg.quartzdev.qxpboosts.commands.CommandManager;
import gg.quartzdev.qxpboosts.listeners.PlayerPickupExpListener;
import gg.quartzdev.qxpboosts.util.qLogger;
import org.bstats.bukkit.Metrics;
Expand Down Expand Up @@ -32,6 +33,8 @@ public void onEnable() {
this.boostManager = new BoostManager();

registerHandlers();

new CommandManager(this.getPluginMeta().getName().toLowerCase());
}

@Override
Expand Down

0 comments on commit 4530185

Please sign in to comment.