Skip to content

Commit

Permalink
chore: merge pull request #3 from ryderbelserion/main
Browse files Browse the repository at this point in the history
Switches from ansi to minimessage support with updated configuration handling
  • Loading branch information
NotGeri authored Apr 5, 2024
2 parents fdc1a4a + 5a05f52 commit 68d6552
Show file tree
Hide file tree
Showing 33 changed files with 816 additions and 323 deletions.
17 changes: 13 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ java {

ext {
pluginName = 'BloomAB'
pluginVersion = '1.5.3'
pluginVersion = '1.5.4'
pluginDescription = 'Anti bot protection for Bloom servers'
pluginAuthor = 'Bloom'
pluginWebsite = 'https://bloom.host'
Expand Down Expand Up @@ -44,8 +44,14 @@ subprojects {
}

dependencies {
// Use repackaged SnakeYAML for configs
implementation 'dev.geri:Konfig:1.7'
// Include minimessage api
implementation 'net.kyori:adventure-text-serializer-gson:4.16.0'
implementation 'net.kyori:adventure-text-minimessage:4.16.0'
implementation 'net.kyori:adventure-platform-bukkit:4.3.2'

implementation 'ch.jalu:configme:1.4.1'
// This is needed for older versions of Minecraft.
implementation 'org.yaml:snakeyaml:2.2'

// Use GSON for JSON processing
implementation group: 'com.google.code.gson', name: 'gson', version: '2.10.1'
Expand All @@ -56,9 +62,12 @@ subprojects {
task uberJar(type: ShadowJar) {

// Relocate important dependencies to avoid any collisions at runtime
relocate 'org.yaml.snakeyaml', 'host.bloom.ab.dependencies.snakeyml'
relocate 'org.yaml', 'host.bloom.ab.dependencies.snakeyaml'
relocate 'ch.jalu', 'host.bloom.ab.dependencies.configme'
relocate 'com.google.gson', 'host.bloom.ab.dependencies.gson'
relocate 'org.apache.commons', 'host.bloom.ab.dependencies.apache.commons'
// do not relocate, Kyori does not like being relocated, it will scream about "no class found"
//relocate 'net.kyori', 'host.bloom.ab.dependencies.kyori'

// Set the output file name and location
archiveFileName = "${project.ext.pluginName}-${project.ext.pluginVersion}.jar"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.TabExecutor;

import java.util.Arrays;
import java.util.List;

public class BukkitCommandHandler implements TabExecutor {

private final BukkitPlugin plugin;
private final Handler handler;

public BukkitCommandHandler(BukkitPlugin plugin) {
this.plugin = plugin;
this.handler = new Handler(plugin);

PluginCommand command = plugin.getCommand(Handler.getCommandName());
Expand All @@ -27,13 +28,13 @@ public BukkitCommandHandler(BukkitPlugin plugin) {

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
this.handler.execute(new BukkitSender(sender), args);
this.handler.execute(new BukkitSender(this.plugin, sender), args);
return true;
}

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
return this.handler.onTabComplete(new BukkitSender(sender), args);
return this.handler.onTabComplete(new BukkitSender(this.plugin, sender), args);
}

}
13 changes: 13 additions & 0 deletions bukkit/src/main/java/host/bloom/ab/bukkit/BukkitLoginListener.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package host.bloom.ab.bukkit;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.server.ServerListPingEvent;

public class BukkitLoginListener implements Listener {
Expand All @@ -16,11 +18,22 @@ public BukkitLoginListener(BukkitPlugin plugin) {
@EventHandler
public void onPlayerJoinEvent(PlayerJoinEvent e) {
plugin.getManager().incrementConnectionCount();

Player player = e.getPlayer();

if (player.hasPermission("bab.admin.actionbar.onjoin")) {
this.plugin.getManager().addSeer(player.getUniqueId());
}
}

@EventHandler
public void onServerListPingEvent(ServerListPingEvent e) {
plugin.getManager().incrementConnectionCount();
}

@EventHandler
public void onPlayerQuitEvent(PlayerQuitEvent event) {
// Always remove it just in case as they might not have the permission.
this.plugin.getManager().removeSeer(event.getPlayer().getUniqueId());
}
}
63 changes: 47 additions & 16 deletions bukkit/src/main/java/host/bloom/ab/bukkit/BukkitPlugin.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
package host.bloom.ab.bukkit;

import dev.geri.konfig.util.InvalidConfigurationException;
import host.bloom.ab.common.AbstractPlugin;
import host.bloom.ab.common.config.Config;
import host.bloom.ab.common.managers.ConfigManager;
import host.bloom.ab.common.managers.CounterManager;
import host.bloom.ab.common.utils.Logger;
import host.bloom.ab.common.utils.Scheduler;
import host.bloom.ab.common.utils.Utils;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.IOException;
import java.util.UUID;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import org.jetbrains.annotations.NotNull;
import java.io.File;

public class BukkitPlugin extends JavaPlugin implements AbstractPlugin {

private BukkitAudiences adventure;

private BukkitLogger logger;
private Config config;
private CounterManager manager;

@Override
public void onEnable() {
// Initialize the logger
this.logger = new BukkitLogger(super.getLogger());

// Load the config
try {
this.config = Config.load(this, this.getDataFolder().getAbsolutePath());
} catch (IOException | InvalidConfigurationException exception) {
this.getABLogger().error("Unable to load config, shutting down: " + exception.getMessage());
return;
}
// Load the configuration files.
ConfigManager.load(this);

// Initialize an audiences instance for the plugin
this.adventure = BukkitAudiences.create(this);

// Initialize the manager
this.manager = new CounterManager(this);
Expand All @@ -42,6 +44,14 @@ public void onEnable() {
this.afterStartup();
}

@Override
public void onDisable() {
if (this.adventure != null) {
this.adventure.close();
this.adventure = null;
}
}

@Override
public CounterManager getManager() {
return this.manager;
Expand All @@ -63,18 +73,39 @@ public Logger getABLogger() {
}

@Override
public Config getABConfig() {
return this.config;
public Platform getPlatform() {
return Platform.BUKKIT;
}

@Override
public Platform getPlatform() {
return Platform.BUKKIT;
public File getFolder() {
return getDataFolder();
}

@Override
public void actionbar(UUID uuid, String message) {
Player player = getPlayer(uuid);

if (player != null) {
this.adventure.sender(player).sendActionBar(Utils.color(message));
}
}

@Override
public Player getPlayer(UUID uuid) {
return getServer().getPlayer(uuid);
}

@Override
public int getPort() {
return this.getServer().getPort();
}

public @NotNull BukkitAudiences adventure() {
if (this.adventure == null) {
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
}

return this.adventure;
}
}
33 changes: 30 additions & 3 deletions bukkit/src/main/java/host/bloom/ab/bukkit/BukkitSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,50 @@

import host.bloom.ab.common.commands.Sender;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.UUID;
import host.bloom.ab.common.utils.Utils;

public class BukkitSender implements Sender {

private final BukkitPlugin plugin;
private final CommandSender sender;

public BukkitSender(CommandSender sender) {
public BukkitSender(BukkitPlugin plugin, CommandSender sender) {
this.plugin = plugin;
this.sender = sender;
}

@Override
public void sendMessage(String message) {
this.sender.sendMessage(message);
this.plugin.adventure().sender(this.sender).sendMessage(Utils.color(message));
}

@Override
public boolean hasPermission(String permission) {
return this.sender.hasPermission(permission);
}

}
@Override
public void actionbar(String message) {
if (!isPlayer()) return;

Player player = (Player) sender;

this.plugin.adventure().sender(player).sendActionBar(Utils.color(message));
}

@Override
public boolean isPlayer() {
return this.sender instanceof Player;
}

@Override
public UUID getUUID() {
if (!isPlayer()) return null;

Player player = (Player) sender;

return player.getUniqueId();
}
}
23 changes: 16 additions & 7 deletions common/src/main/java/host/bloom/ab/common/AbstractPlugin.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package host.bloom.ab.common;

import host.bloom.ab.common.config.Config;
import ch.jalu.configme.SettingsManager;
import host.bloom.ab.common.config.ConfigKeys;
import host.bloom.ab.common.managers.ConfigManager;
import host.bloom.ab.common.managers.CounterManager;
import host.bloom.ab.common.utils.Logger;
import host.bloom.ab.common.utils.Scheduler;
import host.bloom.ab.common.utils.UpdateChecker;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

public interface AbstractPlugin {
Expand All @@ -26,10 +29,14 @@ enum Platform {

Logger getABLogger();

Config getABConfig();

Platform getPlatform();

void actionbar(UUID uuid, String message);

<P> P getPlayer(UUID uuid);

File getFolder();

int getPort();

default void afterStartup() {
Expand All @@ -40,16 +47,18 @@ default void afterStartup() {
throw new RuntimeException("The server is not using a supported port! Please ensure it's using one of the following ports, and restart: " + supportedPorts.stream().map(String::valueOf).collect(Collectors.joining(", ")));
}

this.getABLogger().info("Successfully loaded version: v" + this.getVersion() + ", location: " + this.getABConfig().location.getDisplayName() + "!");
SettingsManager config = ConfigManager.getConfig();

this.getABLogger().info("Successfully loaded version: v" + this.getVersion() + ", location: " + config.getProperty(ConfigKeys.locations) + "!");

// Check for new updates in the background
UpdateChecker.handle(this);

if (this.getPlatform() == Platform.BUKKIT && this.getABConfig().catchRawConnections) {
if (this.getPlatform() == Platform.BUKKIT && config.getProperty(ConfigKeys.catch_raw_connections)) {
this.getABLogger().warning("The plugin does not support using raw connections for this platform, defaulting to using built in APIs!");
}

if (this.getPlatform() == Platform.WATERFALL && !this.getABConfig().catchRawConnections) {
if (this.getPlatform() == Platform.WATERFALL && !config.getProperty(ConfigKeys.catch_raw_connections)) {
this.getABLogger().warning("The plugin does not support using internal APIs for connections for this platform, defaulting to catching raw connections!");
}
}
Expand Down
Loading

0 comments on commit 68d6552

Please sign in to comment.