mirror of
https://github.com/HibiscusMC/HibiscusCommons.git
synced 2025-12-19 15:09:26 +00:00
feat: move towards easily overrideable methods in sub plugins rather than each plugin needing their own channel
This commit is contained in:
@@ -2,6 +2,7 @@ package me.lojosho.hibiscuscommons;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hooks;
|
||||
import me.lojosho.hibiscuscommons.listener.PlayerConnectionEvent;
|
||||
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
|
||||
import me.lojosho.hibiscuscommons.util.ServerUtils;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
@@ -42,6 +43,8 @@ public final class HibiscusCommonsPlugin extends HibiscusPlugin {
|
||||
return;
|
||||
}
|
||||
|
||||
getServer().getPluginManager().registerEvents(new PlayerConnectionEvent(), this);
|
||||
|
||||
// Plugin startup logic
|
||||
Hooks.setup();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,10 @@ package me.lojosho.hibiscuscommons;
|
||||
import com.jeff_media.updatechecker.UpdateCheckSource;
|
||||
import com.jeff_media.updatechecker.UpdateChecker;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.lojosho.hibiscuscommons.packets.DefaultPacketInterface;
|
||||
import me.lojosho.hibiscuscommons.packets.PacketInterface;
|
||||
import me.lojosho.hibiscuscommons.plugins.SubPlugins;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
@@ -20,6 +24,8 @@ public abstract class HibiscusPlugin extends JavaPlugin {
|
||||
private boolean onLatestVersion = true;
|
||||
@Getter
|
||||
private boolean disabled = false;
|
||||
@Getter @Setter
|
||||
private PacketInterface packetInterface = new DefaultPacketInterface();
|
||||
|
||||
protected HibiscusPlugin() {
|
||||
this(-1);
|
||||
@@ -47,6 +53,8 @@ public abstract class HibiscusPlugin extends JavaPlugin {
|
||||
return;
|
||||
}
|
||||
|
||||
SubPlugins.addSubPlugin(this);
|
||||
|
||||
if (bstats > 0) {
|
||||
Metrics metrics = new Metrics(this, bstats);
|
||||
}
|
||||
@@ -88,6 +96,7 @@ public abstract class HibiscusPlugin extends JavaPlugin {
|
||||
@Override
|
||||
public final void onDisable() {
|
||||
disabled = true;
|
||||
SubPlugins.removeSubPlugin(this);
|
||||
|
||||
onEnd();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package me.lojosho.hibiscuscommons.listener;
|
||||
|
||||
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class PlayerConnectionEvent implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = false, priority = EventPriority.LOW)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
NMSHandlers.getHandler().getUtilHandler().handleChannelOpen(event.getPlayer());
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package me.lojosho.hibiscuscommons.nms;
|
||||
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -18,4 +19,8 @@ public interface NMSUtils {
|
||||
|
||||
ItemStack setColor(@NotNull ItemStack itemStack, Color color);
|
||||
|
||||
default void handleChannelOpen(@NotNull Player player) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package me.lojosho.hibiscuscommons.packets;
|
||||
|
||||
public class DefaultPacketInterface implements PacketInterface {
|
||||
// Overrides nothing
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package me.lojosho.hibiscuscommons.packets;
|
||||
|
||||
public enum PacketAction {
|
||||
NOTHING,
|
||||
CHANGED,
|
||||
CANCELLED,
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package me.lojosho.hibiscuscommons.packets;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface PacketInterface {
|
||||
|
||||
default PacketAction writeContainerContent(@NotNull Player player, Integer windowId, @NotNull List<ItemStack> slotData) {
|
||||
return PacketAction.NOTHING;
|
||||
}
|
||||
|
||||
default PacketAction writeSlotContent(@NotNull Player player, Integer windowId, Integer slot, @NotNull ItemStack itemStack) {
|
||||
return PacketAction.NOTHING;
|
||||
}
|
||||
|
||||
default PacketAction writeEquipmentContent(@NotNull Player player, @NotNull Map<EquipmentSlot, ItemStack> armor) {
|
||||
return PacketAction.NOTHING;
|
||||
}
|
||||
|
||||
default PacketAction writePassengerContent(@NotNull Player player, Integer owner, List<Integer> passengers) {
|
||||
return PacketAction.NOTHING;
|
||||
}
|
||||
|
||||
default PacketAction readInventoryClick(@NotNull Player player, Integer clickType, Integer slotNumber) {
|
||||
return PacketAction.NOTHING;
|
||||
// Override
|
||||
}
|
||||
|
||||
default PacketAction readPlayerAction(@NotNull Player player, Integer actionType) {
|
||||
return PacketAction.NOTHING;
|
||||
// Override
|
||||
}
|
||||
|
||||
default PacketAction readPlayerArm(@NotNull Player player) {
|
||||
return PacketAction.NOTHING;
|
||||
// Override
|
||||
}
|
||||
|
||||
default PacketAction readEntityHandle(@NotNull Player player) {
|
||||
return PacketAction.NOTHING;
|
||||
// Override
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package me.lojosho.hibiscuscommons.plugins;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import me.lojosho.hibiscuscommons.HibiscusPlugin;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SubPlugins {
|
||||
|
||||
private static final List<HibiscusPlugin> SUB_PLUGINS = new ArrayList<>();
|
||||
|
||||
@NotNull
|
||||
public static List<HibiscusPlugin> getSubPlugins() {
|
||||
return ImmutableList.copyOf(SUB_PLUGINS);
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static void addSubPlugin(@NotNull HibiscusPlugin plugin) {
|
||||
SUB_PLUGINS.add(plugin);
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static void removeSubPlugin(@NotNull HibiscusPlugin plugin) {
|
||||
SUB_PLUGINS.remove(plugin);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user