-
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
11 changed files
with
217 additions
and
91 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
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
131 changes: 131 additions & 0 deletions
131
src/main/java/com/artillexstudios/axrankmenu/commands/Commands.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,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", "�FF00" + group + " &fRANK"); | ||
section.set("item.lore", Arrays.asList( | ||
" ", | ||
" &7- &fPrice: �AA00$%price%", | ||
" ", | ||
"�FF00ᴘᴇʀᴍɪssɪᴏɴs", | ||
" &7- &f%permission%", | ||
" ", | ||
"�FF00&l(!) �FF00Click here to purchase!" | ||
)); | ||
section.set("item.buy-actions", Arrays.asList( | ||
"[MESSAGE] �FF00You have purchased the &f%name%�FF00! &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(); | ||
} | ||
} |
48 changes: 0 additions & 48 deletions
48
src/main/java/com/artillexstudios/axrankmenu/commands/MainCommand.java
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
src/main/java/com/artillexstudios/axrankmenu/commands/TabComplete.java
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
src/main/java/com/artillexstudios/axrankmenu/commands/annotations/Groups.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,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 { | ||
} |
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
37 changes: 37 additions & 0 deletions
37
src/main/java/com/artillexstudios/axrankmenu/hooks/currency/BeastTokensHook.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,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); | ||
} | ||
} |
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
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
Oops, something went wrong.