Skip to content

Commit

Permalink
1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
BenceX100 committed Jun 23, 2024
1 parent 45a62a1 commit 87ca323
Show file tree
Hide file tree
Showing 9 changed files with 265 additions and 35 deletions.
23 changes: 12 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

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

<name>AxRankMenu</name>

<properties>
<java.version>1.8</java.version>
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand All @@ -23,8 +23,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -116,32 +116,32 @@
<dependency>
<groupId>com.artillexstudios.axapi</groupId>
<artifactId>axapi</artifactId>
<version>1.4.190</version>
<version>1.4.259</version>
<scope>compile</scope>
<classifier>all</classifier>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-platform-bukkit</artifactId>
<version>4.3.2</version>
<version>4.3.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-minimessage</artifactId>
<version>4.16.0</version>
<version>4.17.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-legacy</artifactId>
<version>4.16.0</version>
<version>4.17.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-api</artifactId>
<version>4.16.0</version>
<version>4.17.0</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand All @@ -153,7 +153,8 @@
<dependency>
<groupId>dev.triumphteam</groupId>
<artifactId>triumph-gui</artifactId>
<version>3.1.7</version>
<version>3.1.10</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.luckperms</groupId>
Expand Down Expand Up @@ -190,7 +191,7 @@
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.3</version>
<version>2.11.6</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/artillexstudios/axrankmenu/AxRankMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.artillexstudios.axapi.utils.MessageUtils;
import com.artillexstudios.axrankmenu.commands.Commands;
import com.artillexstudios.axrankmenu.hooks.HookManager;
import com.artillexstudios.axrankmenu.utils.UpdateNotifier;
import org.bstats.bukkit.Metrics;

import java.io.File;
Expand Down Expand Up @@ -46,6 +47,8 @@ public void enable() {
Commands.registerCommand();

Scheduler.get().run(task -> new HookManager().updateHooks());

if (CONFIG.getBoolean("update-notifier.enabled", true)) new UpdateNotifier(this, 5071);
}

public void disable() {
Expand Down
73 changes: 53 additions & 20 deletions src/main/java/com/artillexstudios/axrankmenu/commands/Commands.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
package com.artillexstudios.axrankmenu.commands;

import com.artillexstudios.axapi.libs.boostedyaml.boostedyaml.block.implementation.Section;
import com.artillexstudios.axapi.nms.NMSHandlers;
import com.artillexstudios.axapi.reflection.FastFieldAccessor;
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 com.artillexstudios.axrankmenu.utils.CommandMessages;
import net.luckperms.api.LuckPerms;
import net.luckperms.api.LuckPermsProvider;
import net.luckperms.api.model.group.Group;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Warning;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import revxrsal.commands.annotation.DefaultFor;
import revxrsal.commands.annotation.Subcommand;
import revxrsal.commands.bukkit.BukkitCommandActor;
import revxrsal.commands.bukkit.BukkitCommandHandler;
import revxrsal.commands.bukkit.annotation.CommandPermission;
import revxrsal.commands.bukkit.exception.InvalidPlayerException;
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.Locale;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -103,28 +113,51 @@ private int getFirstEmptySlot() {
return -1;
}

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

public static void registerCommand() {
if (handler == null) {
Warning.WarningState prevState = Bukkit.getWarningState();
FastFieldAccessor accessor = FastFieldAccessor.forClassField(Bukkit.getServer().getClass().getPackage().getName() + ".CraftServer", "warningState");
accessor.set(Bukkit.getServer(), Warning.WarningState.OFF);
handler = BukkitCommandHandler.create(AxRankMenu.getInstance());
accessor.set(Bukkit.getServer(), prevState);

handler.registerValueResolver(0, OfflinePlayer.class, context -> {
String value = context.pop();
if (value.equalsIgnoreCase("self") || value.equalsIgnoreCase("me")) return ((BukkitCommandActor) context.actor()).requirePlayer();
OfflinePlayer player = NMSHandlers.getNmsHandler().getCachedOfflinePlayer(value);
if (player == null && !(player = Bukkit.getOfflinePlayer(value)).hasPlayedBefore()) throw new InvalidPlayerException(context.parameter(), value);
return player;
});

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.getAutoCompleter().registerParameterSuggestions(OfflinePlayer.class, (args, sender, command) -> {
return Bukkit.getOnlinePlayers().stream().map(HumanEntity::getName).collect(Collectors.toSet());
});

handler.getTranslator().add(new CommandMessages());
handler.setLocale(new Locale("en", "US"));
}
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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.artillexstudios.axrankmenu.utils;

import com.artillexstudios.axapi.utils.StringUtils;
import revxrsal.commands.locales.LocaleReader;

import java.util.Locale;

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

public class CommandMessages implements LocaleReader {
@Override
public boolean containsKey(String s) {
return true;
}

@Override
public String get(String s) {
String res;
switch (s) {
case "invalid-enum", "invalid-number", "invalid-uuid", "invalid-url", "invalid-boolean": {
res = LANG.getString("commands.invalid-value")
.replace("%value%", "{0}");
break;
}
case "missing-argument": {
res = LANG.getString("commands.missing-argument")
.replace("%value%", "{0}");
break;
}
case "no-permission": {
res = LANG.getString("commands.no-permission");
break;
}
case "number-not-in-range": {
res = LANG.getString("commands.out-of-range")
.replace("%number%", "{0}")
.replace("%min%", "{1}")
.replace("%max%", "{2}");
break;
}
case "must-be-player": {
res = LANG.getString("commands.player-only");
break;
}
case "must-be-console": {
res = LANG.getString("commands.console-only");
break;
}
case "invalid-player": {
res = LANG.getString("commands.invalid-player")
.replace("%player%", "{0}");
break;
}
case "invalid-selector": {
res = LANG.getString("commands.invalid-selector");
break;
}
default: {
res = LANG.getString("commands.invalid-command");
break;
}
}
return StringUtils.formatToString(CONFIG.getString("prefix", "") + res);
}

private final Locale locale = new Locale("en", "US");

@Override
public Locale getLocale() {
return locale;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.artillexstudios.axrankmenu.utils;

import com.artillexstudios.axapi.libs.boostedyaml.boostedyaml.block.implementation.Section;
import com.artillexstudios.axapi.utils.ClassUtils;
import com.artillexstudios.axapi.reflection.ClassUtils;
import com.artillexstudios.axapi.utils.ItemBuilder;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.artillexstudios.axrankmenu.utils;

import com.artillexstudios.axapi.libs.boostedyaml.boostedyaml.block.implementation.Section;
import com.artillexstudios.axapi.utils.ClassUtils;
import com.artillexstudios.axapi.reflection.ClassUtils;
import com.artillexstudios.axapi.utils.StringUtils;
import com.artillexstudios.axrankmenu.hooks.HookManager;
import net.luckperms.api.LuckPerms;
Expand Down
Loading

0 comments on commit 87ca323

Please sign in to comment.