Skip to content

Commit

Permalink
1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
BenceX100 committed May 10, 2024
1 parent ef42232 commit 45a62a1
Show file tree
Hide file tree
Showing 11 changed files with 217 additions and 91 deletions.
15 changes: 11 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.artillexstudios</groupId>
<artifactId>AxRankMenu</artifactId>
<version>1.4.0</version>
<version>1.5.0</version>
<packaging>jar</packaging>

<name>AxRankMenu</name>
Expand All @@ -23,8 +23,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>9</source>
<target>9</target>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -116,7 +116,7 @@
<dependency>
<groupId>com.artillexstudios.axapi</groupId>
<artifactId>axapi</artifactId>
<version>1.4.186</version>
<version>1.4.190</version>
<scope>compile</scope>
<classifier>all</classifier>
</dependency>
Expand Down Expand Up @@ -199,6 +199,13 @@
<version>2.6.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.mraxetv.beasttokens</groupId>
<artifactId>BeastTokens</artifactId>
<version>3.13.3</version>
<systemPath>${project.basedir}/libs/bt-api-3.13.3.jar</systemPath>
<scope>system</scope>
</dependency>
</dependencies>

<distributionManagement>
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/com/artillexstudios/axrankmenu/AxRankMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
import com.artillexstudios.axapi.scheduler.Scheduler;
import com.artillexstudios.axapi.utils.FeatureFlags;
import com.artillexstudios.axapi.utils.MessageUtils;
import com.artillexstudios.axrankmenu.commands.MainCommand;
import com.artillexstudios.axrankmenu.commands.TabComplete;
import com.artillexstudios.axrankmenu.commands.Commands;
import com.artillexstudios.axrankmenu.hooks.HookManager;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;

import java.io.File;

Expand Down Expand Up @@ -45,9 +43,7 @@ public void enable() {

MESSAGEUTILS = new MessageUtils(LANG.getBackingDocument(), "prefix", CONFIG.getBackingDocument());

final MainCommand command = new MainCommand();
this.getCommand("axrankmenu").setExecutor(command);
Bukkit.getPluginCommand("axrankmenu").setTabCompleter(new TabComplete());
Commands.registerCommand();

Scheduler.get().run(task -> new HookManager().updateHooks());
}
Expand Down
131 changes: 131 additions & 0 deletions src/main/java/com/artillexstudios/axrankmenu/commands/Commands.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package com.artillexstudios.axrankmenu.commands;

import com.artillexstudios.axapi.libs.boostedyaml.boostedyaml.block.implementation.Section;
import com.artillexstudios.axrankmenu.AxRankMenu;
import com.artillexstudios.axrankmenu.commands.annotations.Groups;
import com.artillexstudios.axrankmenu.gui.impl.RankGui;
import com.artillexstudios.axrankmenu.hooks.HookManager;
import net.luckperms.api.LuckPerms;
import net.luckperms.api.LuckPermsProvider;
import net.luckperms.api.model.group.Group;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import revxrsal.commands.annotation.DefaultFor;
import revxrsal.commands.annotation.Subcommand;
import revxrsal.commands.bukkit.BukkitCommandHandler;
import revxrsal.commands.bukkit.annotation.CommandPermission;
import revxrsal.commands.orphan.OrphanCommand;
import revxrsal.commands.orphan.Orphans;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import static com.artillexstudios.axrankmenu.AxRankMenu.CONFIG;
import static com.artillexstudios.axrankmenu.AxRankMenu.LANG;
import static com.artillexstudios.axrankmenu.AxRankMenu.MESSAGEUTILS;
import static com.artillexstudios.axrankmenu.AxRankMenu.RANKS;

public class Commands implements OrphanCommand {

@DefaultFor({"~", "~ open"})
@CommandPermission(value = "axrankmenu.use")
public void open(@NotNull Player sender) {
new RankGui(sender).open();
}

@Subcommand({"reload"})
@CommandPermission(value = "axrankmenu.reload")
public void reload(@NotNull Player sender) {
if (!CONFIG.reload()) {
MESSAGEUTILS.sendLang(sender, "reload.failed", Collections.singletonMap("%file%", "tiers.yml"));
return;
}

if (!LANG.reload()) {
MESSAGEUTILS.sendLang(sender, "reload.failed", Collections.singletonMap("%file%", "lang.yml"));
return;
}

if (!RANKS.reload()) {
MESSAGEUTILS.sendLang(sender, "reload.failed", Collections.singletonMap("%file%", "ranks.yml"));
return;
}

new HookManager().updateHooks();
Commands.registerCommand();

MESSAGEUTILS.sendLang(sender, "reload.success");
}

@Subcommand({"addrank"})
@CommandPermission(value = "axrankmenu.addrank")
public void addRank(@NotNull Player sender, @Groups String group) {
final Section section = RANKS.getBackingDocument().createSection(group);
section.set("rank", group);
section.set("server", "");
section.set("price", -1.0);
section.set("currency", "Vault");
section.set("slot", getFirstEmptySlot());
section.set("item.type", "GRAY_BANNER");
section.set("item.name", "&#00FF00" + group + " &fRANK");
section.set("item.lore", Arrays.asList(
" ",
" &7- &fPrice: &#00AA00$%price%",
" ",
"&#00FF00ᴘᴇʀᴍɪssɪᴏɴs",
" &7- &f%permission%",
" ",
"&#00FF00&l(!) &#00FF00Click here to purchase!"
));
section.set("item.buy-actions", Arrays.asList(
"[MESSAGE] &#00FF00You have purchased the &f%name%&#00FF00! &7(%rank%)",
"[CONSOLE] lp user %player% parent set " + group,
"[CLOSE] menu"
));
RANKS.save();
MESSAGEUTILS.sendLang(sender, "add-rank", Map.of("%rank%", group));
}

private int getFirstEmptySlot() {
final ArrayList<Integer> filled = new ArrayList<>();
for (String str : RANKS.getBackingDocument().getRoutesAsStrings(false)) {
filled.add(RANKS.getInt(str + ".slot", -1));
}
for (int i = 0; i < RANKS.getInt("rows", 3) * 9; i++) {
if (filled.contains(i)) continue;
return i;
}
return -1;
}

public static void registerCommand() { // todo: fix unregister
final BukkitCommandHandler handler = BukkitCommandHandler.create(AxRankMenu.getInstance());
handler.unregisterAllCommands();

handler.getAutoCompleter().registerSuggestionFactory(parameter -> {
if (parameter.hasAnnotation(Groups.class)) {
return (args, sender, command) -> {
final LuckPerms luckPerms = LuckPermsProvider.get();
final Set<Group> groups = new HashSet<>(luckPerms.getGroupManager().getLoadedGroups());
groups.removeIf(group -> {
for (String str : RANKS.getBackingDocument().getRoutesAsStrings(false)) {
if (RANKS.getString(str + ".rank", "").equalsIgnoreCase(group.getName())) return true;
}
return false;
});

return groups.stream().map(Group::getName).collect(Collectors.toList());
};
}
return null;
});

handler.register(Orphans.path(CONFIG.getStringList("command-aliases").toArray(String[]::new)).handler(new Commands()));
handler.registerBrigadier();
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.artillexstudios.axrankmenu.commands.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface Groups {
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.artillexstudios.axrankmenu.hooks;

import com.artillexstudios.axapi.utils.StringUtils;
import com.artillexstudios.axrankmenu.hooks.currency.BeastTokensHook;
import com.artillexstudios.axrankmenu.hooks.currency.CoinsEngineHook;
import com.artillexstudios.axrankmenu.hooks.currency.CurrencyHook;
import com.artillexstudios.axrankmenu.hooks.currency.PlayerPointsHook;
Expand Down Expand Up @@ -47,6 +48,11 @@ public void updateHooks() {
currency.add(new UltraEconomyHook());
Bukkit.getConsoleSender().sendMessage(StringUtils.formatToString("&#33FF33[AxRankMenu] Hooked into UltraEconomy!"));
}

if (CONFIG.getBoolean("hooks.BeastTokens.register", true) && Bukkit.getPluginManager().getPlugin("BeastTokens") != null) {
currency.add(new BeastTokensHook());
Bukkit.getConsoleSender().sendMessage(StringUtils.formatToString("&#33FF33[AxRankMenu] Hooked into BeastTokens!"));
}

for (CurrencyHook hook : currency) hook.setup();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.artillexstudios.axrankmenu.hooks.currency;

import me.mraxetv.beasttokens.api.BeastTokensAPI;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

public class BeastTokensHook implements CurrencyHook {

@Override
public void setup() {
}

@Override
public String getName() {
return "BeastTokens";
}

@Override
public boolean isPersistent() {
return false;
}

@Override
public double getBalance(@NotNull Player p) {
return BeastTokensAPI.getTokensManager().getTokens(p);
}

@Override
public void giveBalance(@NotNull Player p, double amount) {
BeastTokensAPI.getTokensManager().addTokens(p, amount);
}

@Override
public void takeBalance(@NotNull Player p, double amount) {
BeastTokensAPI.getTokensManager().removeTokens(p, amount);
}
}
12 changes: 11 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ hooks:
UltraEconomy:
register: true
currency-name: "coins"
BeastTokens:
register: true
PlaceholderAPI:
register: true

Expand All @@ -36,5 +38,13 @@ force-buy-order:
enabled: false
track: "trackName"

# you must define at least 1
# reloading will add new commands, however a restart is recommended when editing this
command-aliases:
- "axrankmenu"
- "rankmenu"
- "rank"
- "ranks"

# do not change
version: 3
version: 5
4 changes: 3 additions & 1 deletion src/main/resources/lang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ reload:
buy:
no-currency: "&#FF3333You don't have enough money to buy this rank!"

add-rank: "&#33FF33You have added the &f%rank% &#33FF33rank to the gui! &7Now go to the plugins/AxRankMenu/ranks.yml file to edit it!"

error:
buy-order: "&#FF3333You must buy ranks in order!"
downgrade-disabled: "&#FF3333You can't downgrade your rank!"

# do not change
version: 3
version: 4
Loading

0 comments on commit 45a62a1

Please sign in to comment.