mirror of
https://github.com/HibiscusMC/HibiscusCommons.git
synced 2025-12-21 07:59:20 +00:00
feat: Initial Commit
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package me.lojosho.hibiscuscommons;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hooks;
|
||||
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
|
||||
import me.lojosho.hibiscuscommons.util.ServerUtils;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class HibiscusCommonsPlugin extends HibiscusPlugin {
|
||||
|
||||
@Getter
|
||||
private static HibiscusCommonsPlugin instance;
|
||||
@Getter
|
||||
private static boolean onPaper = false;
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
instance = this;
|
||||
|
||||
// Detects if a user is running a paper server
|
||||
if (ServerUtils.hasClass("com.destroystokyo.paper.PaperConfig") || ServerUtils.hasClass("io.papermc.paper.configuration.Configuration")) {
|
||||
onPaper = true;
|
||||
getLogger().info("Detected Paper! Enabling Paper support...");
|
||||
//getServer().getPluginManager().registerEvents(new PaperPlayerGameListener(), this);
|
||||
}
|
||||
|
||||
if (!NMSHandlers.isVersionSupported()) {
|
||||
getLogger().severe("This version is not supported! Consider switching versions?");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
// Plugin startup logic
|
||||
Hooks.setup();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package me.lojosho.hibiscuscommons;
|
||||
|
||||
import com.jeff_media.updatechecker.UpdateCheckSource;
|
||||
import com.jeff_media.updatechecker.UpdateChecker;
|
||||
import lombok.Getter;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public abstract class HibiscusPlugin extends JavaPlugin {
|
||||
|
||||
@Getter
|
||||
private final int bstats;
|
||||
@Getter
|
||||
private final int resourceID;
|
||||
@Getter
|
||||
private String latestVersion = "";
|
||||
@Getter
|
||||
private boolean onLatestVersion = true;
|
||||
@Getter
|
||||
private boolean disabled = false;
|
||||
|
||||
protected HibiscusPlugin() {
|
||||
this(-1);
|
||||
}
|
||||
|
||||
protected HibiscusPlugin(int bstats) {
|
||||
this(bstats, -1);
|
||||
}
|
||||
|
||||
protected HibiscusPlugin(int bstats, int resourceID) {
|
||||
this.bstats = bstats;
|
||||
this.resourceID = resourceID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onEnable() {
|
||||
super.onEnable();
|
||||
|
||||
if (bstats > 0) {
|
||||
Metrics metrics = new Metrics(this, bstats);
|
||||
}
|
||||
if (resourceID > 0) {
|
||||
// Update Checker
|
||||
UpdateChecker checker = new UpdateChecker(this, UpdateCheckSource.POLYMART, String.valueOf(resourceID))
|
||||
.onSuccess((commandSenders, latestVersion) -> {
|
||||
this.latestVersion = (String) latestVersion;
|
||||
String pluginName = getDescription().getName();
|
||||
|
||||
if (!this.latestVersion.equalsIgnoreCase(getDescription().getVersion())) {
|
||||
getLogger().info("+++++++++++++++++++++++++++++++++++");
|
||||
getLogger().info("There is a new update for " + pluginName + "!");
|
||||
getLogger().info("Please download it as soon as possible for possible fixes and new features.");
|
||||
getLogger().info("Current Version " + getDescription().getVersion() + " | Latest Version " + latestVersion);
|
||||
//getLogger().info("Spigot: https://www.spigotmc.org/resources/100107/");
|
||||
getLogger().info("Polymart: https://polymart.org/resource/" + resourceID);
|
||||
getLogger().info("+++++++++++++++++++++++++++++++++++");
|
||||
} else {
|
||||
getLogger().info("You are running the latest version of " + pluginName + "!");
|
||||
}
|
||||
})
|
||||
.setNotifyRequesters(false)
|
||||
.setNotifyOpsOnJoin(false)
|
||||
.checkEveryXHours(24)
|
||||
.checkNow();
|
||||
onLatestVersion = checker.isUsingLatestVersion();
|
||||
}
|
||||
|
||||
onStart();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final void onDisable() {
|
||||
disabled = true;
|
||||
|
||||
onEnd();
|
||||
}
|
||||
|
||||
|
||||
public void onStart() {
|
||||
// Override
|
||||
}
|
||||
|
||||
public void onReload() {
|
||||
// Override
|
||||
}
|
||||
|
||||
public void onEnd() {
|
||||
// Override
|
||||
}
|
||||
|
||||
public HibiscusPlugin get() {
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package me.lojosho.hibiscuscommons.api;
|
||||
|
||||
import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class HibiscusCommonsAPI {
|
||||
|
||||
/**
|
||||
* Returns the version of HibiscusCommons
|
||||
* @return
|
||||
*/
|
||||
@NotNull
|
||||
public static String getHibiscusVersion() {
|
||||
return HibiscusCommonsPlugin.getInstance().getDescription().getVersion();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package me.lojosho.hibiscuscommons.api.events;
|
||||
|
||||
import me.lojosho.hibiscuscommons.hooks.Hook;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* This is called when a hook is reloaded from a plugin. This is useful for plugins like ItemsAdder, which loads items async from the main thread.
|
||||
*/
|
||||
public class HibiscusHookReload extends Event {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private final Hook hook;
|
||||
|
||||
public HibiscusHookReload(Hook hook) {
|
||||
this.hook = hook;
|
||||
}
|
||||
|
||||
public Hook getHook() {
|
||||
return hook;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package me.lojosho.hibiscuscommons.api.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class HibiscusPlayerUnVanishEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private boolean cancel = false;
|
||||
|
||||
public HibiscusPlayerUnVanishEvent(Player player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancel = cancel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package me.lojosho.hibiscuscommons.api.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class HibiscusPlayerVanishEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private boolean cancel = false;
|
||||
|
||||
public HibiscusPlayerVanishEvent(Player player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancel = cancel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package me.lojosho.hibiscuscommons.config;
|
||||
|
||||
public class GlobalSettings {
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
package me.lojosho.hibiscuscommons.config.serializer;
|
||||
|
||||
import me.lojosho.hibiscuscommons.hooks.Hooks;
|
||||
import me.lojosho.hibiscuscommons.util.ColorBuilder;
|
||||
import me.lojosho.hibiscuscommons.util.InventoryUtils;
|
||||
import me.lojosho.hibiscuscommons.util.ServerUtils;
|
||||
import me.lojosho.hibiscuscommons.util.StringUtils;
|
||||
import org.apache.commons.lang3.EnumUtils;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
import org.spongepowered.configurate.serialize.TypeSerializer;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ItemSerializer implements TypeSerializer<ItemStack> {
|
||||
|
||||
public static final ItemSerializer INSTANCE = new ItemSerializer();
|
||||
private static final String MATERIAL = "material";
|
||||
private static final String AMOUNT = "amount";
|
||||
private static final String NAME = "name";
|
||||
private static final String UNBREAKABLE = "unbreakable";
|
||||
private static final String GLOWING = "glowing";
|
||||
private static final String LORE = "lore";
|
||||
private static final String MODEL_DATA = "model-data";
|
||||
private static final String NBT_TAGS = "nbt-tag";
|
||||
private static final String ENCHANTS = "enchants";
|
||||
private static final String ITEM_FLAGS = "item-flags";
|
||||
private static final String TEXTURE = "texture";
|
||||
private static final String OWNER = "owner";
|
||||
private static final String COLOR = "color";
|
||||
private static final String RED = "red";
|
||||
private static final String GREEN = "green";
|
||||
private static final String BLUE = "blue";
|
||||
|
||||
private ItemSerializer() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack deserialize(final Type type, final ConfigurationNode source)
|
||||
throws SerializationException {
|
||||
final ConfigurationNode materialNode = source.node(MATERIAL);
|
||||
final ConfigurationNode amountNode = source.node(AMOUNT);
|
||||
final ConfigurationNode nameNode = source.node(NAME);
|
||||
final ConfigurationNode unbreakableNode = source.node(UNBREAKABLE);
|
||||
final ConfigurationNode glowingNode = source.node(GLOWING);
|
||||
final ConfigurationNode loreNode = source.node(LORE);
|
||||
final ConfigurationNode modelDataNode = source.node(MODEL_DATA);
|
||||
final ConfigurationNode nbtNode = source.node(NBT_TAGS);
|
||||
final ConfigurationNode enchantsNode = source.node(ENCHANTS);
|
||||
final ConfigurationNode itemFlagsNode = source.node(ITEM_FLAGS);
|
||||
final ConfigurationNode textureNode = source.node(TEXTURE);
|
||||
final ConfigurationNode ownerNode = source.node(OWNER);
|
||||
final ConfigurationNode colorNode = source.node(COLOR);
|
||||
final ConfigurationNode redNode = colorNode.node(RED);
|
||||
final ConfigurationNode greenNode = colorNode.node(GREEN);
|
||||
final ConfigurationNode blueNode = colorNode.node(BLUE);
|
||||
|
||||
if (materialNode.virtual()) return null;
|
||||
|
||||
String material = materialNode.getString();
|
||||
|
||||
ItemStack item = Hooks.getItem(material);
|
||||
if (item == null) {
|
||||
//HMCCosmeticsPlugin.getInstance().getLogger().severe("Invalid Material -> " + material);
|
||||
return new ItemStack(Material.AIR);
|
||||
}
|
||||
item.setAmount(amountNode.getInt(1));
|
||||
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
if (itemMeta == null) return item;
|
||||
if (!nameNode.virtual())
|
||||
itemMeta.setDisplayName(StringUtils.parseStringToString((nameNode.getString(""))));
|
||||
if (!unbreakableNode.virtual()) itemMeta.setUnbreakable(unbreakableNode.getBoolean());
|
||||
if (!glowingNode.virtual()) {
|
||||
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
itemMeta.addEnchant(Enchantment.LUCK, 1, true);
|
||||
}
|
||||
if (!loreNode.virtual()) itemMeta.setLore(loreNode.getList(String.class, new ArrayList<String>()).
|
||||
stream().map(StringUtils::parseStringToString).collect(Collectors.toList()));
|
||||
if (!modelDataNode.virtual()) itemMeta.setCustomModelData(modelDataNode.getInt());
|
||||
|
||||
if (!nbtNode.virtual()) {
|
||||
for (ConfigurationNode nbtNodes : nbtNode.childrenMap().values()) {
|
||||
itemMeta.getPersistentDataContainer().set(NamespacedKey.minecraft(nbtNodes.key().toString()), PersistentDataType.STRING, nbtNodes.getString());
|
||||
}
|
||||
}
|
||||
|
||||
if (!enchantsNode.virtual()) {
|
||||
for (ConfigurationNode enchantNode : enchantsNode.childrenMap().values()) {
|
||||
if (Enchantment.getByKey(NamespacedKey.minecraft(enchantNode.key().toString())) == null) continue;
|
||||
itemMeta.addEnchant(Enchantment.getByKey(NamespacedKey.minecraft(enchantNode.key().toString())), enchantNode.getInt(1), true);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (!itemFlagsNode.virtual()) {
|
||||
for (String itemFlag : itemFlagsNode.getList(String.class)) {
|
||||
if (!EnumUtils.isValidEnum(ItemFlag.class, itemFlag)) continue;
|
||||
//MessagesUtil.sendDebugMessages("Added " + itemFlag + " to the item!");
|
||||
itemMeta.addItemFlags(ItemFlag.valueOf(itemFlag));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (item.getType() == Material.PLAYER_HEAD) {
|
||||
SkullMeta skullMeta = (SkullMeta) itemMeta;
|
||||
if (!ownerNode.virtual()) {
|
||||
String ownerString = ownerNode.getString();
|
||||
if (ownerString.contains("%")) {
|
||||
// This means it has PAPI placeholders in it
|
||||
skullMeta.getPersistentDataContainer().set(InventoryUtils.getSkullOwner(), PersistentDataType.STRING, ownerString);
|
||||
}
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(ownerString);
|
||||
skullMeta.setOwningPlayer(player);
|
||||
}
|
||||
|
||||
if (!textureNode.virtual()) {
|
||||
String textureString = textureNode.getString();
|
||||
if (textureString.contains("%")) {
|
||||
// This means it has PAPI placeholders in it
|
||||
skullMeta.getPersistentDataContainer().set(InventoryUtils.getSkullTexture(), PersistentDataType.STRING, textureString);
|
||||
}
|
||||
Bukkit.getUnsafe().modifyItemStack(item, "{SkullOwner:{Id:[I;0,0,0,0],Properties:{textures:[{Value:\""
|
||||
+ textureString + "\"}]}}}");
|
||||
|
||||
|
||||
itemMeta = skullMeta;
|
||||
}
|
||||
}
|
||||
|
||||
if (!colorNode.virtual()) {
|
||||
if (ColorBuilder.canBeColored(item.getType())) {
|
||||
if (!redNode.virtual()) {
|
||||
itemMeta = ColorBuilder.color(itemMeta, Color.fromRGB(redNode.getInt(0), greenNode.getInt(0), blueNode.getInt(0)));
|
||||
} else {
|
||||
itemMeta = ColorBuilder.color(itemMeta, ServerUtils.hex2Rgb(colorNode.getString("#FFFFFF")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
item.setItemMeta(itemMeta);
|
||||
return item;
|
||||
}
|
||||
@Override
|
||||
public void serialize(final Type type, @Nullable final ItemStack obj, final ConfigurationNode node) throws SerializationException {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package me.lojosho.hibiscuscommons.config.serializer;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
import org.spongepowered.configurate.serialize.TypeSerializer;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class LocationSerializer implements TypeSerializer<Location> {
|
||||
public static final LocationSerializer INSTANCE = new LocationSerializer();
|
||||
|
||||
private static final String WORLD = "world";
|
||||
private static final String X = "x";
|
||||
private static final String Y = "y";
|
||||
private static final String Z = "z";
|
||||
private static final String PITCH = "pitch";
|
||||
private static final String YAW = "yaw";
|
||||
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Location deserialize(final Type type, final ConfigurationNode source) throws SerializationException {
|
||||
final World world = Bukkit.getWorld(source.node(WORLD).getString());
|
||||
if (world == null) return null;
|
||||
return new Location(
|
||||
world,
|
||||
source.node(X).getDouble(),
|
||||
source.node(Y).getDouble(),
|
||||
source.node(Z).getDouble(),
|
||||
source.node(YAW).getFloat(),
|
||||
source.node(PITCH).getFloat()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(final Type type, @Nullable final Location loc, final ConfigurationNode source) throws SerializationException {
|
||||
// Empty
|
||||
}
|
||||
}
|
||||
100
common/src/main/java/me/lojosho/hibiscuscommons/hooks/Hook.java
Normal file
100
common/src/main/java/me/lojosho/hibiscuscommons/hooks/Hook.java
Normal file
@@ -0,0 +1,100 @@
|
||||
package me.lojosho.hibiscuscommons.hooks;
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Represents a hook into other minecraft plugins
|
||||
*/
|
||||
public abstract class Hook implements Listener {
|
||||
private final String id;
|
||||
private boolean active = false;
|
||||
private boolean itemHook = false;
|
||||
|
||||
public Hook(@NotNull String id, HookFlag... flags) {
|
||||
this.id = id;
|
||||
for (HookFlag flag : flags) {
|
||||
switch (flag) {
|
||||
case ITEM_SUPPORT:
|
||||
setEnabledItemHook(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
Hooks.addHook(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads this hook
|
||||
*
|
||||
* @implNote By default, this method does nothing. It should be overridden by child classes to implement any necessary loading logic
|
||||
*/
|
||||
public void load() { }
|
||||
|
||||
/**
|
||||
* Gets an {@link ItemStack} that is associated with the provided id from the hooked plugin
|
||||
* @param itemId The id of the {@link ItemStack}
|
||||
* @return The {@link ItemStack} with the id provided. If an invalid id was provided or if the hook doesn't have any related {@link ItemStack}s then this will return null
|
||||
* @implNote By default, this method returns null. It should be overridden by child classes if you will to have your hook return a related {@link ItemStack}
|
||||
*/
|
||||
@Nullable
|
||||
public ItemStack getItem(@NotNull String itemId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the id of this hook
|
||||
*
|
||||
* @return The unique id for this hook
|
||||
*/
|
||||
@NotNull
|
||||
public final String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether this hook has been activated
|
||||
* @return true if this hook is active, false otherwise
|
||||
* @deprecated As of release 2.2.5+, replaced by {@link #isActive()}
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean getActive() {
|
||||
return this.active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether this hook has been activated
|
||||
* @return true if this hook is active, false otherwise
|
||||
* @since 2.2.5
|
||||
*/
|
||||
public final boolean isActive() {
|
||||
return this.active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this hook is active
|
||||
* @param active true to activate the hook, false otherwise
|
||||
*/
|
||||
public final void setActive(boolean active) {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the method {@link #getItem(String)} should return a non-null value
|
||||
* @return true if {@link #getItem(String)} should return a non-null value, false otherwise
|
||||
*
|
||||
* @apiNote Even though this method returns true does not mean that {@link #getItem(String)} won't return null, rather if this returns false then {@link #getItem(String)} should return false everytime
|
||||
*/
|
||||
public final boolean hasEnabledItemHook() {
|
||||
return itemHook;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the method {@link #getItem(String)} should return a non-null value
|
||||
* @param enabled true if {@link #getItem(String)} should return a non-null value, false otherwise
|
||||
*/
|
||||
public final void setEnabledItemHook(boolean enabled) {
|
||||
itemHook = enabled;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package me.lojosho.hibiscuscommons.hooks;
|
||||
|
||||
public enum HookFlag {
|
||||
ITEM_SUPPORT
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package me.lojosho.hibiscuscommons.hooks;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin;
|
||||
import me.lojosho.hibiscuscommons.hooks.items.*;
|
||||
import me.lojosho.hibiscuscommons.hooks.misc.*;
|
||||
import me.lojosho.hibiscuscommons.hooks.placeholders.HookPlaceholderAPI;
|
||||
import me.lojosho.hibiscuscommons.util.MessagesUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Hooks {
|
||||
|
||||
private static final HashMap<String, Hook> hooks = new HashMap<>();
|
||||
private static final HookOraxen ORAXEN_HOOK = new HookOraxen();
|
||||
private static final HookItemAdder ITEMADDER_HOOK = new HookItemAdder();
|
||||
private static final HookGeary GEARY_HOOK = new HookGeary();
|
||||
private static final HookMythic MYTHIC_HOOK = new HookMythic();
|
||||
private static final HookDenizen DENIZEN_HOOK = new HookDenizen();
|
||||
private static final HookPremiumVanish PREMIUM_VANISH_HOOK = new HookPremiumVanish();
|
||||
private static final HookSuperVanish SUPER_VANISH_HOOK = new HookSuperVanish();
|
||||
private static final HookHMCColor HMC_COLOR_HOOK = new HookHMCColor();
|
||||
private static final HookCMI CMI_HOOK = new HookCMI();
|
||||
private static final HookLibsDisguises LIBS_DISGUISES_HOOK = new HookLibsDisguises();
|
||||
private static final HookModelEngine MODEL_ENGINE_HOOK = new HookModelEngine();
|
||||
private static final HookMMOItems MMO_ITEMS_HOOK = new HookMMOItems();
|
||||
private static final HookEco ECO_ITEMS_HOOK = new HookEco();
|
||||
private static final HookPlaceholderAPI PAPI_HOOK = new HookPlaceholderAPI();
|
||||
|
||||
public static Hook getHook(@NotNull String id) {
|
||||
return hooks.get(id.toLowerCase());
|
||||
}
|
||||
|
||||
public static boolean isItemHook(@NotNull String id) {
|
||||
return hooks.containsKey(id.toLowerCase());
|
||||
}
|
||||
|
||||
public static void addHook(Hook hook) {
|
||||
hooks.put(hook.getId().toLowerCase(), hook);
|
||||
}
|
||||
|
||||
public static void addPlaceholderAPI(PlaceholderExpansion expansion) {
|
||||
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
HookPlaceholderAPI hook = (HookPlaceholderAPI) getHook("PlaceholderAPI");
|
||||
hook.registerPlaceholder(expansion);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String processPlaceholders(OfflinePlayer player, String raw) {
|
||||
if (isActiveHook("PlaceholderAPI")) return PlaceholderAPI.setPlaceholders(player, raw);
|
||||
return raw;
|
||||
}
|
||||
|
||||
public static void setup() {
|
||||
for (Hook hook : hooks.values()) {
|
||||
HibiscusCommonsPlugin.getInstance().getLogger().info("Attempting to hook into " + hook.getId());
|
||||
if (Bukkit.getPluginManager().getPlugin(hook.getId()) != null) {
|
||||
HibiscusCommonsPlugin.getInstance().getServer().getPluginManager().registerEvents(hook, HibiscusCommonsPlugin.getInstance());
|
||||
hook.setActive(true);
|
||||
hook.load();
|
||||
HibiscusCommonsPlugin.getInstance().getLogger().info("Successfully hooked into " + hook.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ItemStack getItem(@NotNull String raw) {
|
||||
if (!raw.contains(":")) {
|
||||
Material mat = Material.getMaterial(raw.toUpperCase());
|
||||
if (mat == null) return null;
|
||||
return new ItemStack(mat);
|
||||
}
|
||||
// Ex. Oraxen:BigSword
|
||||
// split[0] is the plugin name
|
||||
// split[1] is the item name
|
||||
String[] split = raw.split(":", 2);
|
||||
|
||||
if (!isItemHook(split[0])) return null;
|
||||
Hook hook = getHook(split[0]);
|
||||
if (!hook.hasEnabledItemHook()) return null;
|
||||
if (!hook.isActive()) return null;
|
||||
return hook.getItem(split[1]);
|
||||
}
|
||||
|
||||
public static boolean isActiveHook(String id) {
|
||||
Hook hook = getHook(id);
|
||||
if (hook == null) return false;
|
||||
return hook.isActive();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package me.lojosho.hibiscuscommons.hooks.items;
|
||||
|
||||
import com.denizenscript.denizen.objects.ItemTag;
|
||||
import com.denizenscript.denizencore.utilities.CoreUtilities;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hook;
|
||||
import me.lojosho.hibiscuscommons.hooks.HookFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A hook that integrates the plugin {@link com.denizenscript.denizen.Denizen Denizen} to provide custom items
|
||||
*/
|
||||
@SuppressWarnings("SpellCheckingInspection")
|
||||
public class HookDenizen extends Hook {
|
||||
public HookDenizen() {
|
||||
super("denizen", HookFlag.ITEM_SUPPORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a cosmetic {@link ItemStack} that is associated with the provided id from the plugin {@link com.denizenscript.denizen.Denizen Denizen}
|
||||
*/
|
||||
@Override
|
||||
public ItemStack getItem(@NotNull String itemId) {
|
||||
ItemTag item = ItemTag.valueOf(itemId, CoreUtilities.noDebugContext);
|
||||
return item == null ? null : item.getItemStack();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package me.lojosho.hibiscuscommons.hooks.items;
|
||||
|
||||
import com.willfp.eco.core.items.Items;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hook;
|
||||
import me.lojosho.hibiscuscommons.hooks.HookFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class HookEco extends Hook {
|
||||
public HookEco() {
|
||||
super("Eco", HookFlag.ITEM_SUPPORT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(@NotNull String itemId) {
|
||||
return Items.lookup(itemId).getItem();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package me.lojosho.hibiscuscommons.hooks.items;
|
||||
|
||||
import com.mineinabyss.geary.papermc.tracking.items.ItemTrackingKt;
|
||||
import com.mineinabyss.geary.prefabs.PrefabKey;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hook;
|
||||
import me.lojosho.hibiscuscommons.hooks.HookFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A hook that integrates the plugin {@link com.mineinabyss.geary.papermc.GearyPlugin Geary} to provide custom items
|
||||
*/
|
||||
public class HookGeary extends Hook {
|
||||
|
||||
public HookGeary() {
|
||||
super("geary", HookFlag.ITEM_SUPPORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a cosmetic {@link ItemStack} that is associated with the provided id from the plugin {@link com.mineinabyss.geary.papermc.GearyPlugin Geary}
|
||||
*/
|
||||
@Override
|
||||
public ItemStack getItem(@NotNull String itemId) {
|
||||
PrefabKey prefabKey = PrefabKey.Companion.ofOrNull(itemId);
|
||||
if (prefabKey == null) return null;
|
||||
return ItemTrackingKt.getGearyItems().createItem(prefabKey, null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package me.lojosho.hibiscuscommons.hooks.items;
|
||||
|
||||
import dev.lone.itemsadder.api.CustomStack;
|
||||
import dev.lone.itemsadder.api.Events.ItemsAdderLoadDataEvent;
|
||||
import me.lojosho.hibiscuscommons.api.events.HibiscusHookReload;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hook;
|
||||
import me.lojosho.hibiscuscommons.hooks.HookFlag;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A hook that integrates the plugin {@link dev.lone.itemsadder.api.ItemsAdder ItemsAdder} to provide custom items
|
||||
*/
|
||||
@SuppressWarnings("SpellCheckingInspection")
|
||||
public class HookItemAdder extends Hook {
|
||||
private boolean enabled = false;
|
||||
|
||||
public HookItemAdder() {
|
||||
super("itemsadder", HookFlag.ITEM_SUPPORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a cosmetic {@link ItemStack} that is associated with the provided id from the plugin {@link dev.lone.itemsadder.api.ItemsAdder ItemsAdder}
|
||||
*/
|
||||
@Override
|
||||
public ItemStack getItem(@NotNull String itemId) {
|
||||
if (enabled) {
|
||||
CustomStack stack = CustomStack.getInstance(itemId);
|
||||
if (stack == null) return null;
|
||||
return stack.getItemStack();
|
||||
} else {
|
||||
return new ItemStack(Material.AIR);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onItemAdderDataLoad(ItemsAdderLoadDataEvent event) {
|
||||
HibiscusHookReload newEvent = new HibiscusHookReload(this);
|
||||
Bukkit.getPluginManager().callEvent(newEvent);
|
||||
//if (enabled && !Settings.isItemsAdderChangeReload()) return;
|
||||
this.enabled = true;
|
||||
//HMCCosmeticsPlugin.setup();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package me.lojosho.hibiscuscommons.hooks.items;
|
||||
|
||||
import me.lojosho.hibiscuscommons.hooks.Hook;
|
||||
import me.lojosho.hibiscuscommons.hooks.HookFlag;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class HookMMOItems extends Hook {
|
||||
public HookMMOItems() {
|
||||
super("MMOItems", HookFlag.ITEM_SUPPORT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(@NotNull String itemId) {
|
||||
String[] split = itemId.split(":", 2);
|
||||
if (split.length == 2) {
|
||||
return MMOItems.plugin.getItem(split[0], split[1]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package me.lojosho.hibiscuscommons.hooks.items;
|
||||
|
||||
import io.lumine.mythic.bukkit.MythicBukkit;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hook;
|
||||
import me.lojosho.hibiscuscommons.hooks.HookFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A hook that integrates the plugin {@link io.lumine.mythic.bukkit.MythicBukkit MythicBukkit} to provide custom items
|
||||
*/
|
||||
@SuppressWarnings("SpellCheckingInspection")
|
||||
public class HookMythic extends Hook {
|
||||
public HookMythic() {
|
||||
super("mythicmobs", HookFlag.ITEM_SUPPORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a cosmetic {@link ItemStack} that is associated with the provided id from the plugin {@link io.lumine.mythic.bukkit.MythicBukkit MythicBukkit}
|
||||
*/
|
||||
@Override
|
||||
public ItemStack getItem(@NotNull String itemId) {
|
||||
return MythicBukkit.inst().getItemManager().getItemStack(itemId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package me.lojosho.hibiscuscommons.hooks.items;
|
||||
|
||||
import io.th0rgal.oraxen.api.OraxenItems;
|
||||
import io.th0rgal.oraxen.items.ItemBuilder;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hook;
|
||||
import me.lojosho.hibiscuscommons.hooks.HookFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A hook that integrates the plugin {@link io.th0rgal.oraxen.OraxenPlugin OraxenPlugin} to provide custom items
|
||||
*/
|
||||
@SuppressWarnings("SpellCheckingInspection")
|
||||
public class HookOraxen extends Hook {
|
||||
public HookOraxen() {
|
||||
super("oraxen", HookFlag.ITEM_SUPPORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a cosmetic {@link ItemStack} that is associated with the provided id from the plugin {@link io.th0rgal.oraxen.OraxenPlugin OraxenPlugin}
|
||||
*/
|
||||
@Override
|
||||
public ItemStack getItem(@NotNull String itemId) {
|
||||
ItemBuilder builder = OraxenItems.getItemById(itemId);
|
||||
if (builder == null) return null;
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package me.lojosho.hibiscuscommons.hooks.misc;
|
||||
|
||||
import com.Zrips.CMI.events.CMIPlayerUnVanishEvent;
|
||||
import com.Zrips.CMI.events.CMIPlayerVanishEvent;
|
||||
import me.lojosho.hibiscuscommons.api.events.HibiscusPlayerUnVanishEvent;
|
||||
import me.lojosho.hibiscuscommons.api.events.HibiscusPlayerVanishEvent;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hook;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A hook that integrates the plugin {@link com.Zrips.CMI.CMI CMI}
|
||||
*/
|
||||
public class HookCMI extends Hook {
|
||||
public HookCMI() {
|
||||
super("CMI");
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerVanish(@NotNull CMIPlayerVanishEvent event) {
|
||||
HibiscusPlayerVanishEvent newEvent = new HibiscusPlayerVanishEvent(event.getPlayer());
|
||||
Bukkit.getPluginManager().callEvent(newEvent);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerShow(@NotNull CMIPlayerUnVanishEvent event) {
|
||||
HibiscusPlayerUnVanishEvent newEvent = new HibiscusPlayerUnVanishEvent(event.getPlayer());
|
||||
Bukkit.getPluginManager().callEvent(newEvent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package me.lojosho.hibiscuscommons.hooks.misc;
|
||||
|
||||
|
||||
import me.lojosho.hibiscuscommons.hooks.Hook;
|
||||
|
||||
public class HookHMCColor extends Hook {
|
||||
public HookHMCColor() {
|
||||
super("HMCColor");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package me.lojosho.hibiscuscommons.hooks.misc;
|
||||
|
||||
import me.libraryaddict.disguise.events.DisguiseEvent;
|
||||
import me.libraryaddict.disguise.events.UndisguiseEvent;
|
||||
import me.lojosho.hibiscuscommons.api.events.HibiscusPlayerVanishEvent;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hook;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class HookLibsDisguises extends Hook {
|
||||
public HookLibsDisguises() {
|
||||
super("LibsDisguises");
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerVanish(@NotNull DisguiseEvent event) {
|
||||
if (!(event.getEntity() instanceof Player player)) return;
|
||||
HibiscusPlayerVanishEvent newEvent = new HibiscusPlayerVanishEvent(player);
|
||||
Bukkit.getPluginManager().callEvent(newEvent);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerShow(@NotNull UndisguiseEvent event) {
|
||||
if (!(event.getEntity() instanceof Player player)) return;
|
||||
HibiscusPlayerVanishEvent newEvent = new HibiscusPlayerVanishEvent(player);
|
||||
Bukkit.getPluginManager().callEvent(newEvent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package me.lojosho.hibiscuscommons.hooks.misc;
|
||||
|
||||
import me.lojosho.hibiscuscommons.hooks.Hook;
|
||||
|
||||
public class HookModelEngine extends Hook {
|
||||
|
||||
public HookModelEngine() {
|
||||
super("ModelEngine");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package me.lojosho.hibiscuscommons.hooks.misc;
|
||||
|
||||
import de.myzelyam.api.vanish.PlayerHideEvent;
|
||||
import de.myzelyam.api.vanish.PlayerShowEvent;
|
||||
import me.lojosho.hibiscuscommons.api.events.HibiscusPlayerUnVanishEvent;
|
||||
import me.lojosho.hibiscuscommons.api.events.HibiscusPlayerVanishEvent;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hook;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A hook that integrates the plugin {@link de.myzelyam.api.vanish.VanishAPI Supervanish}
|
||||
*
|
||||
* @implSpec Supervanish and Premium Vanish both use the same api
|
||||
*/
|
||||
public class HookPremiumVanish extends Hook {
|
||||
public HookPremiumVanish() {
|
||||
super("PremiumVanish");
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onPlayerVanish(@NotNull PlayerHideEvent event) {
|
||||
HibiscusPlayerVanishEvent newEvent = new HibiscusPlayerVanishEvent(event.getPlayer());
|
||||
Bukkit.getPluginManager().callEvent(newEvent);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onPlayerShow(@NotNull PlayerShowEvent event) {
|
||||
HibiscusPlayerUnVanishEvent newEvent = new HibiscusPlayerUnVanishEvent(event.getPlayer());
|
||||
Bukkit.getPluginManager().callEvent(newEvent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package me.lojosho.hibiscuscommons.hooks.misc;
|
||||
|
||||
import de.myzelyam.api.vanish.PlayerHideEvent;
|
||||
import de.myzelyam.api.vanish.PlayerShowEvent;
|
||||
import me.lojosho.hibiscuscommons.api.events.HibiscusPlayerUnVanishEvent;
|
||||
import me.lojosho.hibiscuscommons.api.events.HibiscusPlayerVanishEvent;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hook;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A hook that integrates the plugin {@link de.myzelyam.api.vanish.VanishAPI Supervanish}
|
||||
*
|
||||
* @implSpec Supervanish and Premium Vanish both use the same api
|
||||
*/
|
||||
public class HookSuperVanish extends Hook {
|
||||
public HookSuperVanish() {
|
||||
super("SuperVanish");
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerVanish(@NotNull PlayerHideEvent event) {
|
||||
HibiscusPlayerVanishEvent newEvent = new HibiscusPlayerVanishEvent(event.getPlayer());
|
||||
Bukkit.getPluginManager().callEvent(newEvent);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerShow(@NotNull PlayerShowEvent event) {
|
||||
HibiscusPlayerUnVanishEvent newEvent = new HibiscusPlayerUnVanishEvent(event.getPlayer());
|
||||
Bukkit.getPluginManager().callEvent(newEvent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package me.lojosho.hibiscuscommons.hooks.placeholders;
|
||||
|
||||
import me.lojosho.hibiscuscommons.hooks.Hook;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class HookPlaceholderAPI extends Hook {
|
||||
|
||||
private ArrayList<PlaceholderExpansion> placeHolders = new ArrayList<>();
|
||||
|
||||
public HookPlaceholderAPI() {
|
||||
super("PlaceholderAPI");
|
||||
}
|
||||
|
||||
public void registerPlaceholder(PlaceholderExpansion placeholderExpansion) {
|
||||
placeHolders.add(placeholderExpansion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
for (PlaceholderExpansion placeholderExpansion : placeHolders) {
|
||||
placeholderExpansion.register();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package me.lojosho.hibiscuscommons.nms;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
public interface NMSHandler {
|
||||
|
||||
int getNextEntityId();
|
||||
|
||||
Entity getEntity(int entityId);
|
||||
|
||||
default boolean getSupported () {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package me.lojosho.hibiscuscommons.nms;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class NMSHandlers {
|
||||
|
||||
private static final String[] SUPPORTED_VERSION = new String[]{"v1_18_R2", "v1_19_R1", "v1_19_R2", "v1_19_R3", "v1_20_R1", "v1_20_R2", "v1_20_R3"};
|
||||
private static NMSHandler handler;
|
||||
@Getter
|
||||
private static String version;
|
||||
|
||||
@Nullable
|
||||
public static NMSHandler getHandler() {
|
||||
if (handler != null) {
|
||||
return handler;
|
||||
} else {
|
||||
setup();
|
||||
}
|
||||
return handler;
|
||||
}
|
||||
|
||||
public static boolean isVersionSupported() {
|
||||
if (getHandler() == null) return false;
|
||||
return getHandler().getSupported();
|
||||
}
|
||||
|
||||
public static void setup() {
|
||||
if (handler != null) return;
|
||||
final String packageName = HibiscusCommonsPlugin.getInstance().getServer().getClass().getPackage().getName();
|
||||
String packageVersion = packageName.substring(packageName.lastIndexOf('.') + 1);
|
||||
|
||||
for (String selectedVersion : SUPPORTED_VERSION) {
|
||||
if (!selectedVersion.contains(packageVersion)) {
|
||||
continue;
|
||||
}
|
||||
//MessagesUtil.sendDebugMessages(packageVersion + " has been detected.", Level.INFO);
|
||||
version = packageVersion;
|
||||
try {
|
||||
handler = (NMSHandler) Class.forName("me.lojosho.hibiscuscommons.nms." + packageVersion + ".NMSHandler").getConstructor().newInstance();
|
||||
return;
|
||||
} catch (ClassNotFoundException | InvocationTargetException | InstantiationException |
|
||||
IllegalAccessException | NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package me.lojosho.hibiscuscommons.util;
|
||||
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
|
||||
public class Adventure {
|
||||
|
||||
public static final LegacyComponentSerializer SERIALIZER = LegacyComponentSerializer.builder()
|
||||
.hexColors()
|
||||
.useUnusualXRepeatedCharacterHexFormat()
|
||||
.build();
|
||||
|
||||
public static final MiniMessage MINI_MESSAGE = MiniMessage.builder().tags(
|
||||
StandardTags.defaults()
|
||||
).
|
||||
build();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package me.lojosho.hibiscuscommons.util;
|
||||
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ColorBuilder {
|
||||
|
||||
public static boolean canBeColored(final Material material) {
|
||||
return canBeColored(new ItemStack(material));
|
||||
}
|
||||
|
||||
public static boolean canBeColored(final @NotNull ItemStack itemStack) {
|
||||
final ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
|
||||
return (itemMeta instanceof LeatherArmorMeta ||
|
||||
itemMeta instanceof PotionMeta);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param color armor color
|
||||
* @return this
|
||||
*/
|
||||
|
||||
public static ItemMeta color(ItemMeta itemMeta, final Color color) {
|
||||
if (itemMeta instanceof final PotionMeta meta) {
|
||||
meta.setColor(color);
|
||||
}
|
||||
if (itemMeta instanceof final LeatherArmorMeta meta) {
|
||||
meta.setColor(color);
|
||||
}
|
||||
return itemMeta;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package me.lojosho.hibiscuscommons.util;
|
||||
|
||||
import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin;
|
||||
import org.bukkit.NamespacedKey;
|
||||
|
||||
public class InventoryUtils {
|
||||
|
||||
|
||||
public static NamespacedKey getOwnerKey() {
|
||||
return new NamespacedKey(HibiscusCommonsPlugin.getInstance(), "owner");
|
||||
}
|
||||
|
||||
public static NamespacedKey getSkullOwner() {
|
||||
return new NamespacedKey(HibiscusCommonsPlugin.getInstance(), "skullowner");
|
||||
}
|
||||
|
||||
public static NamespacedKey getSkullTexture() {
|
||||
return new NamespacedKey(HibiscusCommonsPlugin.getInstance(), "skulltexture");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package me.lojosho.hibiscuscommons.util;
|
||||
|
||||
import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class MessagesUtil {
|
||||
|
||||
private static boolean debug = false;
|
||||
|
||||
|
||||
public static void sendDebugMessages(String message) {
|
||||
sendDebugMessages(message, Level.INFO);
|
||||
}
|
||||
|
||||
public static void sendDebugMessages(String message, Level level) {
|
||||
if (!debug) return;
|
||||
HibiscusCommonsPlugin.getInstance().getLogger().log(level, message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package me.lojosho.hibiscuscommons.util;
|
||||
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
import com.comphenix.protocol.wrappers.WrappedSignedProperty;
|
||||
import me.lojosho.hibiscuscommons.nms.NMSHandler;
|
||||
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ServerUtils {
|
||||
|
||||
public static int getNextEntityId() {
|
||||
return NMSHandlers.getHandler().getNextEntityId();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static WrappedSignedProperty getSkin(Player player) {
|
||||
WrappedSignedProperty skinData = WrappedGameProfile.fromPlayer(player).getProperties()
|
||||
.get("textures").stream().findAny().orElse(null);
|
||||
|
||||
if (skinData == null) {
|
||||
return null;
|
||||
}
|
||||
return new WrappedSignedProperty("textures", skinData.getValue(), skinData.getSignature());
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a color from a string.
|
||||
* Formats: #RRGGBB; R,G,B
|
||||
*
|
||||
* @param color The string
|
||||
* @return The color, if the string can't be parsed, null is returned
|
||||
*/
|
||||
public static Color colorFromString(@Nullable String color) {
|
||||
if (color == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
var decodedColor = java.awt.Color.decode(color.startsWith("#") ? color : "#" + color);
|
||||
return Color.fromRGB(decodedColor.getRed(), decodedColor.getGreen(), decodedColor.getBlue());
|
||||
} catch (NumberFormatException invalidHex) {
|
||||
try {
|
||||
var rgbValues = Arrays.stream(color.split(",")).map(Integer::parseInt).toArray(Integer[]::new);
|
||||
return Color.fromRGB(rgbValues[0], rgbValues[1], rgbValues[2]);
|
||||
} catch (Exception invalidRgb) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This takes in a string like #FFFFFF to convert it into a Bukkit color
|
||||
* @param colorStr
|
||||
* @return
|
||||
*/
|
||||
public static Color hex2Rgb(String colorStr) {
|
||||
if (colorStr.startsWith("#")) return Color.fromRGB(Integer.valueOf(colorStr.substring(1), 16));
|
||||
if (colorStr.startsWith("0x")) return Color.fromRGB(Integer.valueOf(colorStr.substring(2), 16));
|
||||
if (colorStr.contains(",")) {
|
||||
String[] colorString = colorStr.replace(" ", "").split(",");
|
||||
for (String color : colorString) if (Integer.valueOf(color) == null) return Color.WHITE;
|
||||
Color.fromRGB(Integer.valueOf(colorString[0]), Integer.valueOf(colorString[1]), Integer.valueOf(colorString[2]));
|
||||
}
|
||||
|
||||
return Color.WHITE;
|
||||
}
|
||||
|
||||
/**
|
||||
* This takes in a string like 55,49,181 to convert it into a Bukkit Color
|
||||
* @param colorStr
|
||||
* @return
|
||||
*/
|
||||
public static Color rgbToRgb(String colorStr) {
|
||||
if (colorStr.contains(",")) {
|
||||
String[] colors = colorStr.split(",", 3);
|
||||
if (colors.length == 3) {
|
||||
return Color.fromRGB(Integer.parseInt(colors[0]), Integer.parseInt(colors[1]), Integer.parseInt(colors[2]));
|
||||
}
|
||||
}
|
||||
|
||||
return Color.WHITE;
|
||||
}
|
||||
|
||||
public static int getNextYaw(final int current, final int rotationSpeed) {
|
||||
int nextYaw = current + rotationSpeed;
|
||||
if (nextYaw > 179) {
|
||||
nextYaw = (current + rotationSpeed) - 358;
|
||||
return nextYaw;
|
||||
}
|
||||
return nextYaw;
|
||||
}
|
||||
|
||||
public static boolean hasClass(String className) {
|
||||
try {
|
||||
Class.forName(className);
|
||||
return true;
|
||||
} catch (ClassNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package me.lojosho.hibiscuscommons.util;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class StringUtils {
|
||||
|
||||
@NotNull
|
||||
public static String parseStringToString(final String parsed) {
|
||||
return Adventure.SERIALIZER.serialize(Adventure.MINI_MESSAGE.deserialize(parsed));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,233 @@
|
||||
package me.lojosho.hibiscuscommons.util.packets;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import me.lojosho.hibiscuscommons.util.MessagesUtil;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PacketManager {
|
||||
|
||||
public static void sendEntitySpawnPacket(
|
||||
final @NotNull Location location,
|
||||
final int entityId,
|
||||
final EntityType entityType,
|
||||
final UUID uuid,
|
||||
final @NotNull List<Player> sendTo
|
||||
) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY);
|
||||
packet.getModifier().writeDefaults();
|
||||
packet.getUUIDs().write(0, uuid);
|
||||
packet.getIntegers().write(0, entityId);
|
||||
packet.getEntityTypeModifier().write(0, entityType);
|
||||
packet.getDoubles().
|
||||
write(0, location.getX()).
|
||||
write(1, location.getY()).
|
||||
write(2, location.getZ());
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
}
|
||||
|
||||
public static void gamemodeChangePacket(
|
||||
Player player,
|
||||
int gamemode
|
||||
) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.GAME_STATE_CHANGE);
|
||||
packet.getGameStateIDs().write(0, 3);
|
||||
// Tells what event this is. This is a change gamemode event.
|
||||
packet.getFloat().write(0, (float) gamemode);
|
||||
sendPacket(player, packet);
|
||||
MessagesUtil.sendDebugMessages("Gamemode Change sent to " + player + " to be " + gamemode);
|
||||
}
|
||||
|
||||
public static void ridingMountPacket(
|
||||
int mountId,
|
||||
int passengerId,
|
||||
@NotNull List<Player> sendTo
|
||||
) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.MOUNT);
|
||||
packet.getIntegers().write(0, mountId);
|
||||
packet.getIntegerArrays().write(0, new int[]{passengerId});
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
}
|
||||
|
||||
public static void sendLookPacket(
|
||||
int entityId,
|
||||
@NotNull Location location,
|
||||
@NotNull List<Player> sendTo
|
||||
) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_HEAD_ROTATION);
|
||||
packet.getIntegers().write(0, entityId);
|
||||
packet.getBytes().write(0, (byte) (location.getYaw() * 256.0F / 360.0F));
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
}
|
||||
|
||||
public static void sendRotationPacket(
|
||||
int entityId,
|
||||
@NotNull Location location,
|
||||
boolean onGround,
|
||||
@NotNull List<Player> sendTo
|
||||
) {
|
||||
float ROTATION_FACTOR = 256.0F / 360.0F;
|
||||
float yaw = location.getYaw() * ROTATION_FACTOR;
|
||||
float pitch = location.getPitch() * ROTATION_FACTOR;
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_LOOK);
|
||||
packet.getIntegers().write(0, entityId);
|
||||
packet.getBytes().write(0, (byte) yaw);
|
||||
packet.getBytes().write(1, (byte) pitch);
|
||||
|
||||
//Bukkit.getLogger().info("DEBUG: Yaw: " + (location.getYaw() * ROTATION_FACTOR) + " | Original Yaw: " + location.getYaw());
|
||||
packet.getBooleans().write(0, onGround);
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
}
|
||||
|
||||
public static void sendRotationPacket(
|
||||
int entityId,
|
||||
int yaw,
|
||||
boolean onGround,
|
||||
@NotNull List<Player> sendTo
|
||||
) {
|
||||
float ROTATION_FACTOR = 256.0F / 360.0F;
|
||||
float yaw2 = yaw * ROTATION_FACTOR;
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_LOOK);
|
||||
packet.getIntegers().write(0, entityId);
|
||||
packet.getBytes().write(0, (byte) yaw2);
|
||||
packet.getBytes().write(1, (byte) 0);
|
||||
|
||||
//Bukkit.getLogger().info("DEBUG: Yaw: " + (location.getYaw() * ROTATION_FACTOR) + " | Original Yaw: " + location.getYaw());
|
||||
packet.getBooleans().write(0, onGround);
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
}
|
||||
|
||||
public static void sendRidingPacket(
|
||||
final int mountId,
|
||||
final int passengerId,
|
||||
final @NotNull List<Player> sendTo
|
||||
) {
|
||||
sendRidingPacket(mountId, new int[] {passengerId}, sendTo);
|
||||
}
|
||||
|
||||
public static void sendRidingPacket(
|
||||
final int mountId,
|
||||
final int[] passengerIds,
|
||||
final @NotNull List<Player> sendTo
|
||||
) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.MOUNT);
|
||||
packet.getIntegers().write(0, mountId);
|
||||
packet.getIntegerArrays().write(0, passengerIds);
|
||||
for (final Player p : sendTo) {
|
||||
sendPacket(p, packet);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys an entity from a player
|
||||
* @param entityId The entity to delete for a player
|
||||
* @param sendTo The players the packet should be sent to
|
||||
*/
|
||||
public static void sendEntityDestroyPacket(final int entityId, @NotNull List<Player> sendTo) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
|
||||
packet.getModifier().write(0, new IntArrayList(new int[]{entityId}));
|
||||
for (final Player p : sendTo) sendPacket(p, packet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys an entity from a player
|
||||
* @param sendTo The players the packet should be sent to
|
||||
*/
|
||||
public static void sendEntityDestroyPacket(final List<Integer> ids, @NotNull List<Player> sendTo) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
|
||||
IntArrayList entities = new IntArrayList(new int[]{});
|
||||
for (int id : ids) entities.add(id);
|
||||
packet.getModifier().write(0, entities);
|
||||
for (final Player p : sendTo) sendPacket(p, packet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a camera packet
|
||||
* @param entityId The Entity ID that camera will go towards
|
||||
* @param sendTo The players that will be sent this packet
|
||||
*/
|
||||
public static void sendCameraPacket(final int entityId, @NotNull List<Player> sendTo) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.CAMERA);
|
||||
packet.getIntegers().write(0, entityId);
|
||||
for (final Player p : sendTo) sendPacket(p, packet);
|
||||
MessagesUtil.sendDebugMessages(sendTo + " | " + entityId + " has had a camera packet on them!");
|
||||
}
|
||||
|
||||
public static void sendLeashPacket(
|
||||
final int leashedEntity,
|
||||
final int entityId,
|
||||
final @NotNull List<Player> sendTo
|
||||
) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ATTACH_ENTITY);
|
||||
packet.getIntegers().write(0, leashedEntity);
|
||||
packet.getIntegers().write(1, entityId);
|
||||
for (final Player p : sendTo) {
|
||||
sendPacket(p, packet);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used when a player is sent 8+ blocks.
|
||||
* @param entityId Entity this affects
|
||||
* @param location Location a player is being teleported to
|
||||
* @param onGround If the packet is on the ground
|
||||
* @param sendTo Whom to send the packet to
|
||||
*/
|
||||
public static void sendTeleportPacket(
|
||||
final int entityId,
|
||||
final @NotNull Location location,
|
||||
boolean onGround,
|
||||
final @NotNull List<Player> sendTo
|
||||
) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_TELEPORT);
|
||||
packet.getIntegers().write(0, entityId);
|
||||
packet.getDoubles().write(0, location.getX());
|
||||
packet.getDoubles().write(1, location.getY());
|
||||
packet.getDoubles().write(2, location.getZ());
|
||||
packet.getBytes().write(0, (byte) (location.getYaw() * 256.0F / 360.0F));
|
||||
packet.getBytes().write(1, (byte) (location.getPitch() * 256.0F / 360.0F));
|
||||
packet.getBooleans().write(0, onGround);
|
||||
for (final Player p : sendTo) {
|
||||
sendPacket(p, packet);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@NotNull
|
||||
public static List<Player> getViewers(Location location, int distance) {
|
||||
ArrayList<Player> viewers = new ArrayList<>();
|
||||
if (distance <= 0) {
|
||||
viewers.addAll(location.getWorld().getPlayers());
|
||||
} else {
|
||||
viewers.addAll(getNearbyPlayers(location, distance));
|
||||
}
|
||||
return viewers;
|
||||
}
|
||||
|
||||
private static List<Player> getNearbyPlayers(Location location, int distance) {
|
||||
List<Player> players = new ArrayList<>();
|
||||
for (Entity entity : location.getWorld().getNearbyEntities(location, distance, distance, distance)) {
|
||||
if (entity instanceof Player) {
|
||||
players.add((Player) entity);
|
||||
}
|
||||
}
|
||||
return players;
|
||||
}
|
||||
|
||||
public static void sendPacket(Player player, PacketContainer packet) {
|
||||
if (player == null) return;
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, null,false);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user