Skip to content

Commit

Permalink
feat: 1.21(.1) support + CommandAPI
Browse files Browse the repository at this point in the history
Moved to CommandAPI from ACF as CommandAPI offers much more easier creating of commands and follow best practices.
  • Loading branch information
ArikSquad committed Sep 3, 2024
1 parent aec45c8 commit b74bcde
Show file tree
Hide file tree
Showing 12 changed files with 178 additions and 189 deletions.
18 changes: 8 additions & 10 deletions common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>

<repository>
<id>maven_central</id>
<name>Maven Central</name>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
</repositories>

<dependencies>
Expand All @@ -47,15 +53,15 @@
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-api</artifactId>
<version>4.14.0</version>
<version>4.17.0</version>
<scope>compile</scope>
</dependency>

<!-- Adventure Platform API -->
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-platform-api</artifactId>
<version>4.3.2</version>
<version>4.3.3</version>
<scope>compile</scope>
</dependency>

Expand All @@ -66,14 +72,6 @@
<version>4.5.0</version>
</dependency>

<!-- Guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>32.1.3-jre</version>
<scope>compile</scope>
</dependency>

<!-- Adventure Text - MiniMessage -->
<dependency>
<groupId>net.kyori</groupId>
Expand Down
12 changes: 11 additions & 1 deletion common/src/main/java/eu/mikart/animvanish/IAnimVanish.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,15 @@ default void reload() {
loadConfig();
}

default void loadExtra() {}
/**
* Load per platform code, such as registering commands or effects
* @since 1.1.0
*/
default void loadPlatform() {}

/**
* Unload per platform code, such as unregistering a command handler
* @since 1.1.1
*/
default void unloadPlatform() {}
}
4 changes: 2 additions & 2 deletions common/src/main/java/eu/mikart/animvanish/config/Locales.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package eu.mikart.animvanish.config;

import com.google.common.collect.Maps;
import de.exlll.configlib.Configuration;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
Expand All @@ -13,6 +12,7 @@
import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;

/**
* The configuration has been inspired by <a href="https://github.com/William278/HuskTowns">HuskTowns</a>
Expand All @@ -33,7 +33,7 @@ public class Locales {
protected static final String DEFAULT_LOCALE = "en-us";

// The raw set of locales loaded from yaml
Map<String, String> locales = Maps.newTreeMap();
Map<String, String> locales = new TreeMap<>();

/**
* Returns a raw, unformatted locale loaded from the locales file
Expand Down
19 changes: 11 additions & 8 deletions paper/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,10 @@
<shadedPattern>eu.mikart.animvanish</shadedPattern>
</relocation>

<!-- afc -->
<!-- CommandAPI -->
<relocation>
<pattern>co.aikar.commands</pattern>
<shadedPattern>eu.mikart.animvanish.acf</shadedPattern>
</relocation>

<relocation>
<pattern>co.aikar.locales</pattern>
<shadedPattern>eu.mikart.animvanish.locales</shadedPattern>
<pattern>dev.jorel.commandapi</pattern>
<shadedPattern>eu.mikart.animvanish.commandapi</shadedPattern>
</relocation>

<!-- if -->
Expand Down Expand Up @@ -116,5 +111,13 @@
<artifactId>animvanish-spigot</artifactId>
<version>1.1.1</version>
</dependency>

<!-- CommandAPI - Mojang Mapped -->
<dependency>
<groupId>dev.jorel</groupId>
<artifactId>commandapi-bukkit-shade-mojang-mapped</artifactId>
<version>9.5.3</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
16 changes: 15 additions & 1 deletion paper/src/main/java/eu/mikart/animvanish/AnimVanishPaper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package eu.mikart.animvanish;

import dev.jorel.commandapi.CommandAPI;
import dev.jorel.commandapi.CommandAPIBukkitConfig;
import eu.mikart.animvanish.effects.impl.TntEffect;
import lombok.NoArgsConstructor;
import net.kyori.adventure.audience.Audience;
Expand All @@ -11,6 +13,11 @@
@NoArgsConstructor
public class AnimVanishPaper extends AnimVanishBukkit {

@Override
public void onLoad() {
CommandAPI.onLoad(new CommandAPIBukkitConfig(this).shouldHookPaperReload(true).silentLogs(true));
}

@Override
@NotNull
public Audience getAudience(@NotNull UUID user) {
Expand All @@ -19,8 +26,15 @@ public Audience getAudience(@NotNull UUID user) {
}

@Override
public void loadExtra() {
public void loadPlatform() {
CommandAPI.onEnable();
areCommandsInitialized = true;
getEffectManager().registerEffect(new TntEffect(this));
}

@Override
public void unloadPlatform() {
CommandAPI.onDisable();
}

}
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<url>https://github.com/ArikSquad</url>
<url>https://github.com/ArikSquad/AnimVanish</url>

<build>
<plugins>
Expand Down Expand Up @@ -60,7 +60,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.32</version>
<version>1.18.34</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
33 changes: 14 additions & 19 deletions spigot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,6 @@
<shadedPattern>eu.mikart.animvanish</shadedPattern>
</relocation>

<!-- afc -->
<relocation>
<pattern>co.aikar.commands</pattern>
<shadedPattern>eu.mikart.animvanish.acf</shadedPattern>
</relocation>

<relocation>
<pattern>co.aikar.locales</pattern>
<shadedPattern>eu.mikart.animvanish.locales</shadedPattern>
</relocation>

<!-- if -->
<relocation>
<pattern>com.github.stefvanschie.inventoryframework</pattern>
Expand Down Expand Up @@ -151,6 +140,12 @@
<id>aikar</id>
<url>https://repo.aikar.co/content/groups/aikar/</url>
</repository>

<repository>
<id>maven_central</id>
<name>Maven Central</name>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
</repositories>

<dependencies>
Expand Down Expand Up @@ -196,7 +191,7 @@
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-minimessage</artifactId>
<version>4.14.0</version>
<version>4.16.0</version>
</dependency>

<!-- Citizens API - Citizen NPCs -->
Expand Down Expand Up @@ -235,16 +230,16 @@
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-key</artifactId>
<version>4.14.0</version>
<version>4.16.0</version>
<scope>compile</scope>
</dependency>

<!-- ACF -->
<!-- CommandAPI -->
<dependency>
<groupId>co.aikar</groupId>
<artifactId>acf-paper</artifactId>
<version>0.5.1-SNAPSHOT</version>
<scope>compile</scope>
<groupId>dev.jorel</groupId>
<artifactId>commandapi-bukkit-core</artifactId>
<version>9.5.3</version>
<scope>provided</scope>
</dependency>

<!-- AdvancedVanish API -->
Expand All @@ -259,7 +254,7 @@
<dependency>
<groupId>com.github.stefvanschie.inventoryframework</groupId>
<artifactId>IF</artifactId>
<version>0.10.13</version>
<version>0.10.17</version>
</dependency>
</dependencies>
</project>
56 changes: 7 additions & 49 deletions spigot/src/main/java/eu/mikart/animvanish/AnimVanishBukkit.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
package eu.mikart.animvanish;

import co.aikar.commands.BukkitCommandExecutionContext;
import co.aikar.commands.PaperCommandManager;
import co.aikar.commands.contexts.ContextResolver;
import com.google.common.collect.Sets;
import eu.mikart.animvanish.api.AnimVanishBukkitAPI;
import eu.mikart.animvanish.commands.InvisibilityCommand;
import eu.mikart.animvanish.config.Locales;
import eu.mikart.animvanish.config.Settings;
import eu.mikart.animvanish.effects.BareEffect;
import eu.mikart.animvanish.effects.EffectManager;
import eu.mikart.animvanish.effects.impl.FireworkEffect;
import eu.mikart.animvanish.hooks.Hook;
Expand All @@ -25,12 +20,12 @@
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import eu.mikart.animvanish.commands.AnimVanishCommand;
import org.jetbrains.annotations.NotNull;

import java.nio.file.Path;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Logger;

Expand All @@ -39,12 +34,11 @@
public class AnimVanishBukkit extends JavaPlugin implements IAnimVanish {

private AudienceProvider audiences;
private PaperCommandManager commandManager;
private static AnimVanishBukkit instance;
private EffectManager effectManager;
public boolean areCommandsInitialized = false;

@Setter
private Set<Hook> hooks = Sets.newHashSet();
private Set<Hook> hooks = new HashSet<>();
@Setter
private Hook currentHook;
@Setter
Expand All @@ -56,16 +50,12 @@ public class AnimVanishBukkit extends JavaPlugin implements IAnimVanish {
public void onEnable() {
audiences = BukkitAudiences.create(this);
effectManager = new EffectManager(this);
commandManager = new PaperCommandManager(this);
instance = this;


new Metrics(this, 14993);
this.loadConfig();

getServer().getPluginManager().registerEvents(new FireworkEffect(this), this);
commandSetup();
loadExtra(); // Load extra effects from paper
loadPlatform(); // Load extra effects from paper

Utilities.BETA = getDescription().getVersion().contains("BETA");
updateCheck();
Expand All @@ -74,6 +64,8 @@ public void onEnable() {
hooks.add(new PremiumVanishHook());
hooks.add(new SuperVanishHook());
hooks.add(new AdvancedVanishHook());
new AnimVanishCommand(this);
new InvisibilityCommand(this);

for (Hook hook : hooks) {
if (Bukkit.getPluginManager().isPluginEnabled(hook.getName())) {
Expand All @@ -85,19 +77,9 @@ public void onEnable() {
AnimVanishBukkitAPI.register(this);
}

public void commandSetup() {
commandManager.getCommandContexts().registerContext(BareEffect.class, getEffectContextResolver());
commandManager.getCommandCompletions().registerAsyncCompletion("effects", c -> getEffectManager().getEffects().stream().map(BareEffect::getName).toList());

// Register commands
commandManager.registerCommand(new AnimVanishCommand(this));
commandManager.registerCommand(new InvisibilityCommand(this));
}

@Override
public void onDisable() {
instance = null;
commandManager.unregisterCommands();
unloadPlatform();
}

@Override
Expand Down Expand Up @@ -141,30 +123,6 @@ public AnimVanishBukkit getPlugin() {
return this;
}

public static ContextResolver<BareEffect, BukkitCommandExecutionContext> getEffectContextResolver() {
return (context) -> {
String effectName = context.popFirstArg();
if (effectName == null || effectName.isEmpty()) {
return null; // No effect name provided
}

BareEffect effect = instance.getEffectManager().getEffect(effectName);
if (effect == null) {
instance.getLocales().getLocale("not_found").ifPresent(message -> {
if (context.getSender() instanceof Player player) {
instance.getAudience(player.getUniqueId()).sendMessage(message);
} else {
instance.getConsole().sendMessage(message);
}
});

return null;
}

return effect;
};
}

@Override
@NotNull
public Logger getLogger() {
Expand Down
Loading

0 comments on commit b74bcde

Please sign in to comment.