Skip to content

Commit

Permalink
added list boosts command
Browse files Browse the repository at this point in the history
  • Loading branch information
QarthO committed Dec 17, 2023
1 parent 4530185 commit 2a61498
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 6 deletions.
32 changes: 30 additions & 2 deletions src/main/java/gg/quartzdev/qxpboosts/boost/BoostManager.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package gg.quartzdev.qxpboosts.boost;

import gg.quartzdev.qxpboosts.qConfig;
import gg.quartzdev.qxpboosts.qPermission;
import gg.quartzdev.qxpboosts.qXpBoosts;
import gg.quartzdev.qxpboosts.util.Language;
import gg.quartzdev.qxpboosts.util.qLogger;
import org.apache.commons.lang3.text.WordUtils;
import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.jetbrains.annotations.NotNull;

import java.util.HashMap;
Expand All @@ -31,6 +31,7 @@ public BoostManager(){

this.boosts = new HashMap<>();
this.playerTracker = new HashMap<>();
this.boostTracker = new HashMap<>();
this.defaultBoost = new Boost("default", 1.25);
}

Expand Down Expand Up @@ -60,4 +61,31 @@ public void loadBoosts(){

}

public Set<String> listBoosts(){
Set<String> boostList = new HashSet<>();

boostList.add(this.getBoostInfo(this.defaultBoost));

for(Boost boost : boosts.values())
boostList.add(this.getBoostInfo(boost));

return boostList;
}

public String getBoostInfo(Boost boost){

String boostStatus = Language.BOOST_STATUS_ERROR.toString();

if(boostTracker.get(boost) != null)
boostStatus = (boostTracker.get(boost)) ? Language.BOOST_STATUS_ACTIVE.toString() : Language.BOOST_STATUS_DISABLED.toString();

String bootInfo = Language.BOOST_INFO.toString()
.replaceAll("<boost-name>", WordUtils.capitalizeFully(boost.getName()))
.replaceAll("<boost-multiplier>", String.valueOf(defaultBoost.getMultiplier()))
.replaceAll("<boost-status>", boostStatus)
.replaceAll("<prefix>", Language.CHAT_PREFIX.name());

return bootInfo;
}

}
31 changes: 30 additions & 1 deletion src/main/java/gg/quartzdev/qxpboosts/commands/CMDlist.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
package gg.quartzdev.qxpboosts.commands;

public class CMDlist {
import gg.quartzdev.qxpboosts.qXpBoosts;
import gg.quartzdev.qxpboosts.util.Language;
import gg.quartzdev.qxpboosts.util.qUtil;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.command.CommandSender;

import java.util.Set;

public class CMDlist extends qCMD{

public CMDlist(String name, String label) {
super(name, label);
this.permissionGroup = "qmbde.admin";
this.permissionNode = "qmbde.command.reload";
}

@Override
public boolean logic(CommandSender sender, String[] args) {

Set<String> boostList = qXpBoosts.getInstance().boostManager.listBoosts();

String message = String.join("<new-line>", boostList);
MiniMessage mm = MiniMessage.miniMessage();
Component component = mm.deserialize(message);
sender.sendMessage(component);

return false;
}

}
12 changes: 10 additions & 2 deletions src/main/java/gg/quartzdev/qxpboosts/commands/CommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,17 @@ public CommandManager(String name){
@Override
public boolean execute(@NotNull CommandSender sender, @NotNull String labelOrAlias, @NotNull String[] args) {

if(args.length >= 1)
if(args[0].equalsIgnoreCase("reload"))
if(args.length >= 1) {
if (args[0].equalsIgnoreCase("reload")) {
return (new CMDreload(args[0], labelOrAlias)).run(sender, args);
}
if (args[0].equalsIgnoreCase("list")) {
return (new CMDlist(args[0], labelOrAlias)).run(sender, args);
}
// if (args[0].equalsIgnoreCase("enable")) {
// return (new CMDreload(args[0], labelOrAlias)).run(sender, args);
// }
}

return (new CMD(null, labelOrAlias)).run(sender, args);

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/gg/quartzdev/qxpboosts/util/Language.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public enum Language {
XP_CHAT_GAIN("<prefix> <green>Gained <blue><boost-multiplier>x <green>XP"),

// Boost
BOOST_INFO("<purple> <boost-name> - <boost-status>"),
BOOST_INFO("<purple> <boost-name> - <boost-multiplier> - <boost-status>"),
BOOST_STATUS_ERROR("<red>Error"),
BOOST_STATUS_ACTIVE("<green>Active"),
BOOST_STATUS_DISABLED("<red>Disabled");

Expand Down

0 comments on commit 2a61498

Please sign in to comment.