mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 22:17:17 +00:00
Add fabric builds for older MC versions & add checkstyle (#449)
* Remove instance getters, improve command logic, register APi * Publish multiple fabric builds, enforce checkstyle * Bump guava * Bump to 4.4.2
This commit is contained in:
1 parent
51baf196b3
commit
c9f5262292
219 files changed
+8032
-1392
No files matched your search
@@ -22,9 +22,9 @@ package net.william278.huskhomes;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.william278.annotaml.Annotaml;
|
||||
import net.william278.desertwell.util.Version;
|
||||
import net.william278.huskhomes.api.HuskHomesAPI;
|
||||
import net.william278.huskhomes.command.BukkitCommand;
|
||||
import net.william278.huskhomes.command.Command;
|
||||
import net.william278.huskhomes.command.DisabledCommand;
|
||||
import net.william278.huskhomes.config.Locales;
|
||||
import net.william278.huskhomes.config.Server;
|
||||
import net.william278.huskhomes.config.Settings;
|
||||
@@ -62,6 +62,7 @@ import org.bukkit.plugin.java.JavaPluginLoader;
|
||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
import space.arim.morepaperlib.MorePaperLib;
|
||||
import space.arim.morepaperlib.scheduling.GracefulScheduling;
|
||||
|
||||
@@ -79,6 +80,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
||||
* Metrics ID for <a href="https://bstats.org/plugin/bukkit/HuskHomes/8430">HuskHomes on Bukkit</a>.
|
||||
*/
|
||||
private static final int METRICS_ID = 8430;
|
||||
|
||||
private Set<SavedUser> savedUsers;
|
||||
private Settings settings;
|
||||
private Locales locales;
|
||||
@@ -94,34 +96,23 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
||||
private Map<String, List<String>> globalPlayerList;
|
||||
private Set<UUID> currentlyOnWarmup;
|
||||
private Server server;
|
||||
@Nullable
|
||||
private Broker broker;
|
||||
private BukkitAudiences audiences;
|
||||
private MorePaperLib paperLib;
|
||||
|
||||
private static BukkitHuskHomes instance;
|
||||
|
||||
public static BukkitHuskHomes getInstance() {
|
||||
return instance;
|
||||
}
|
||||
@Nullable
|
||||
private Broker broker;
|
||||
|
||||
// Default public constructor
|
||||
@SuppressWarnings("unused")
|
||||
public BukkitHuskHomes() {
|
||||
super();
|
||||
}
|
||||
|
||||
// Super constructor for unit testing
|
||||
@SuppressWarnings("unused")
|
||||
protected BukkitHuskHomes(@NotNull JavaPluginLoader loader, @NotNull PluginDescriptionFile description, @NotNull File dataFolder, @NotNull File file) {
|
||||
@TestOnly
|
||||
protected BukkitHuskHomes(@NotNull JavaPluginLoader loader, @NotNull PluginDescriptionFile description,
|
||||
@NotNull File dataFolder, @NotNull File file) {
|
||||
super(loader, description, dataFolder, file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Create adventure audience
|
||||
@@ -142,7 +133,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
||||
// Initialize the database
|
||||
initialize(getSettings().getDatabaseType().getDisplayName() + " database connection", (plugin) -> {
|
||||
this.database = switch (getSettings().getDatabaseType()) {
|
||||
case MYSQL -> new MySqlDatabase(this);
|
||||
case MYSQL, MARIADB -> new MySqlDatabase(this);
|
||||
case SQLITE -> new SqLiteDatabase(this);
|
||||
};
|
||||
|
||||
@@ -190,6 +181,9 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
||||
// Register commands
|
||||
initialize("commands", (plugin) -> this.commands = registerCommands());
|
||||
|
||||
// Initialize the API
|
||||
initialize("API", (plugin) -> HuskHomesAPI.register(this));
|
||||
|
||||
// Hook into bStats and check for updates
|
||||
initialize("metrics", (plugin) -> this.registerMetrics(METRICS_ID));
|
||||
this.checkForUpdates();
|
||||
@@ -197,19 +191,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
||||
|
||||
@NotNull
|
||||
public List<Command> registerCommands() {
|
||||
return Arrays.stream(BukkitCommand.Type.values())
|
||||
.map(type -> {
|
||||
final Command command = type.getCommand();
|
||||
if (settings.isCommandDisabled(command)) {
|
||||
new BukkitCommand(new DisabledCommand(command.getName(), this), this).register();
|
||||
return null;
|
||||
} else {
|
||||
new BukkitCommand(command, this).register();
|
||||
return command;
|
||||
}
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
return BukkitCommand.Type.getCommands(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -259,7 +241,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the adventure Bukkit audiences
|
||||
* Returns the adventure Bukkit audiences.
|
||||
*
|
||||
* @return The adventure Bukkit audiences
|
||||
*/
|
||||
@@ -277,7 +259,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
||||
@Override
|
||||
public List<OnlineUser> getOnlineUsers() {
|
||||
return Bukkit.getOnlinePlayers().stream()
|
||||
.map(player -> (OnlineUser) BukkitUser.adapt(player))
|
||||
.map(player -> (OnlineUser) BukkitUser.adapt(player, this))
|
||||
.toList();
|
||||
}
|
||||
|
||||
@@ -369,7 +351,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
||||
|
||||
// Update the world spawn location, too
|
||||
BukkitAdapter.adaptLocation(location).ifPresent(bukkitLocation -> {
|
||||
assert bukkitLocation.getWorld() != null;
|
||||
assert bukkitLocation.getWorld() != null : "World was null when setting server spawn";
|
||||
bukkitLocation.getWorld().setSpawnLocation(bukkitLocation);
|
||||
});
|
||||
} catch (IOException | InvocationTargetException | InstantiationException | IllegalAccessException e) {
|
||||
@@ -451,14 +433,23 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
||||
|
||||
try {
|
||||
final Metrics metrics = new Metrics(this, metricsId);
|
||||
metrics.addCustomChart(new SimplePie("bungee_mode", () -> Boolean.toString(getSettings().doCrossServer())));
|
||||
metrics.addCustomChart(new SimplePie("bungee_mode",
|
||||
() -> Boolean.toString(getSettings().doCrossServer())));
|
||||
|
||||
if (getSettings().doCrossServer()) {
|
||||
metrics.addCustomChart(new SimplePie("messenger_type", () -> getSettings().getBrokerType().getDisplayName()));
|
||||
metrics.addCustomChart(new SimplePie("messenger_type",
|
||||
() -> getSettings().getBrokerType().getDisplayName()));
|
||||
}
|
||||
metrics.addCustomChart(new SimplePie("language", () -> getSettings().getLanguage().toLowerCase()));
|
||||
metrics.addCustomChart(new SimplePie("database_type", () -> getSettings().getDatabaseType().getDisplayName()));
|
||||
metrics.addCustomChart(new SimplePie("using_economy", () -> Boolean.toString(getSettings().doEconomy())));
|
||||
metrics.addCustomChart(new SimplePie("using_map", () -> Boolean.toString(getSettings().doMapHook())));
|
||||
|
||||
metrics.addCustomChart(new SimplePie("language",
|
||||
() -> getSettings().getLanguage().toLowerCase()));
|
||||
metrics.addCustomChart(new SimplePie("database_type",
|
||||
() -> getSettings().getDatabaseType().getDisplayName()));
|
||||
metrics.addCustomChart(new SimplePie("using_economy",
|
||||
() -> Boolean.toString(getSettings().doEconomy())));
|
||||
metrics.addCustomChart(new SimplePie("using_map",
|
||||
() -> Boolean.toString(getSettings().doMapHook())));
|
||||
|
||||
getMapHook().ifPresent(hook -> metrics.addCustomChart(new SimplePie("map_type", hook::getName)));
|
||||
} catch (Throwable e) {
|
||||
log(Level.WARNING, "Failed to register bStats metrics (" + e.getMessage() + ")");
|
||||
@@ -467,8 +458,9 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
||||
|
||||
@Override
|
||||
public void initializePluginChannels() {
|
||||
Bukkit.getMessenger().registerIncomingPluginChannel(this, PluginMessageBroker.BUNGEE_CHANNEL_ID, this);
|
||||
Bukkit.getMessenger().registerOutgoingPluginChannel(this, PluginMessageBroker.BUNGEE_CHANNEL_ID);
|
||||
final String channelId = PluginMessageBroker.BUNGEE_CHANNEL_ID;
|
||||
Bukkit.getMessenger().registerIncomingPluginChannel(this, channelId, this);
|
||||
Bukkit.getMessenger().registerOutgoingPluginChannel(this, channelId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -483,8 +475,8 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
||||
@Override
|
||||
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, byte[] message) {
|
||||
if (broker != null && broker instanceof PluginMessageBroker pluginMessenger
|
||||
&& getSettings().getBrokerType() == Broker.Type.PLUGIN_MESSAGE) {
|
||||
pluginMessenger.onReceive(channel, BukkitUser.adapt(player), message);
|
||||
&& getSettings().getBrokerType() == Broker.Type.PLUGIN_MESSAGE) {
|
||||
pluginMessenger.onReceive(channel, BukkitUser.adapt(player, this), message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -498,4 +490,5 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
||||
public HuskHomes getPlugin() {
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user