Skip to content

Commit

Permalink
Merge pull request #152 from HibiscusMC/development
Browse files Browse the repository at this point in the history
HMCWraps 1.5.1
  • Loading branch information
Skyslycer authored Dec 13, 2024
2 parents bff444c + 9fcf191 commit b9eee09
Show file tree
Hide file tree
Showing 36 changed files with 554 additions and 240 deletions.
6 changes: 4 additions & 2 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
java
`maven-publish`
kotlin("jvm") version "2.0.0"
kotlin("jvm") version "2.0.20"
id("org.jetbrains.dokka") version ("1.9.20")
}

Expand All @@ -11,14 +11,16 @@ version = rootProject.version
repositories {
mavenCentral()
maven("https://repo.skyslycer.de/jitpack")
maven("https://repo.skyslycer.de/mirrors")
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
maven("https://oss.sonatype.org/content/repositories/snapshots/")
maven("https://oss.sonatype.org/content/groups/public")
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
maven("https://repo.dmulloy2.net/repository/public/")
maven("https://repo.codemc.io/repository/maven-snapshots/")
maven("https://repo.codemc.io/repository/maven-public/")
maven("https://nexuslite.gcnt.net/repos/other/")
maven("https://repo.triumphteam.dev/snapshots")
maven("https://repo.nexomc.com/snapshots/")
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;

public class DefaultItemHook implements ItemHook {
public class DefaultItemHook extends ItemHook {

@Override
@Nullable
Expand Down Expand Up @@ -45,4 +47,16 @@ public String getTrimMaterial(String id) {
return null;
}

@Override
@Nullable
public EquipmentSlot getEquippableSlot(String id) {
return null;
}

@Override
@Nullable
public NamespacedKey getEquippableModel(String id) {
return null;
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package de.skyslycer.hmcwraps.itemhook;

import org.bukkit.Color;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;

import java.util.Set;

public class HookAccessor {

private final DefaultItemHook defaultHook = new DefaultItemHook();
private final Set<ItemHook> hooks;

public HookAccessor(Set<ItemHook> hooks) {
Expand All @@ -24,7 +27,7 @@ public HookAccessor(Set<ItemHook> hooks) {
public ItemStack getItemFromHook(String id) {
var possible = hooks.stream().filter(it -> id.startsWith(it.getPrefix())).findFirst();
if (possible.isEmpty()) {
return ItemHook.defaultHook.get(id);
return this.defaultHook.get(id);
} else {
return possible.get().get(id.replace(possible.get().getPrefix(), ""));
}
Expand Down Expand Up @@ -69,4 +72,16 @@ public String getTrimMaterialFromHook(String id) {
return possible.map(itemHook -> itemHook.getTrimMaterial(id.replace(possible.get().getPrefix(), ""))).orElse(null);
}

@Nullable
public EquipmentSlot getEquippableSlotFromHook(String id) {
var possible = hooks.stream().filter(it -> id.startsWith(it.getPrefix())).findFirst();
return possible.map(itemHook -> itemHook.getEquippableSlot(id.replace(possible.get().getPrefix(), ""))).orElse(null);
}

@Nullable
public NamespacedKey getEquippableModelFromHook(String id) {
var possible = hooks.stream().filter(it -> id.startsWith(it.getPrefix())).findFirst();
return possible.map(itemHook -> itemHook.getEquippableModel(id.replace(possible.get().getPrefix(), ""))).orElse(null);
}

}
76 changes: 66 additions & 10 deletions api/src/main/java/de/skyslycer/hmcwraps/itemhook/ItemHook.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package de.skyslycer.hmcwraps.itemhook;

import de.skyslycer.hmcwraps.util.VersionUtil;
import org.bukkit.Color;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ArmorMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.jetbrains.annotations.Nullable;

public interface ItemHook {


DefaultItemHook defaultHook = new DefaultItemHook();
public abstract class ItemHook {

/**
* Get the hook prefix.
*
* @return The hook prefix
*/
String getPrefix();
abstract String getPrefix();

/**
* Get an item stack based on the input.
Expand All @@ -23,15 +25,21 @@ public interface ItemHook {
* @return The item stack
*/
@Nullable
ItemStack get(String id);
abstract ItemStack get(String id);

/**
* Get the model id corresponding to the input.
*
* @param id The input
* @return The model id
*/
int getModelId(String id);
public int getModelId(String id) {
var stack = get(id);
if (stack != null && stack.getItemMeta().hasCustomModelData()) {
return stack.getItemMeta().getCustomModelData();
}
return -1;
}

/**
* Get the color corresponding to the input.
Expand All @@ -40,7 +48,13 @@ public interface ItemHook {
* @return The color
*/
@Nullable
Color getColor(String id);
public Color getColor(String id) {
var stack = get(id);
if (stack != null && stack.getItemMeta() instanceof LeatherArmorMeta meta) {
return meta.getColor();
}
return null;
}

/**
* Get the trim pattern corresponding to the input.
Expand All @@ -49,7 +63,13 @@ public interface ItemHook {
* @return The trim pattern
*/
@Nullable
String getTrimPattern(String id);
public String getTrimPattern(String id) {
var stack = get(id);
if (VersionUtil.trimsSupported() && stack != null && stack.getItemMeta() instanceof ArmorMeta meta && meta.getTrim() != null) {
return meta.getTrim().getPattern().getKey().toString();
}
return null;
}

/**
* Get the trim material corresponding to the input.
Expand All @@ -58,6 +78,42 @@ public interface ItemHook {
* @return The trim material
*/
@Nullable
String getTrimMaterial(String id);
public String getTrimMaterial(String id) {
var stack = get(id);
if (VersionUtil.trimsSupported() && stack != null && stack.getItemMeta() instanceof ArmorMeta meta && meta.getTrim() != null) {
return meta.getTrim().getMaterial().getKey().toString();
}
return null;
}

/**
* Get the equippable slot corresponding to the input.
*
* @param id The input
* @return The equippable slot
*/
@Nullable
public EquipmentSlot getEquippableSlot(String id) {
var stack = get(id);
if (VersionUtil.equippableSupported() && stack != null && stack.getItemMeta().hasEquippable()) {
return stack.getItemMeta().getEquippable().getSlot();
}
return null;
}

/**
* Get the equippable key corresponding to the input.
*
* @param id The input
* @return The equippable key
*/
@Nullable
public NamespacedKey getEquippableModel(String id) {
var stack = get(id);
if (VersionUtil.equippableSupported() && stack != null && stack.getItemMeta().hasEquippable()) {
return stack.getItemMeta().getEquippable().getModel();
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public void preview() {
sendTeleportPacket();
sendEquipPacket();

task = plugin.getFoliaLib().getImpl().runTimerAsync(new RotateRunnable(player, entityId, plugin), 3, 1);
task = plugin.getFoliaLib().getScheduler().runTimerAsync(new RotateRunnable(player, entityId, plugin), 3, 1);

cancelTask = plugin.getFoliaLib().getImpl().runAtEntityLater(player, () -> plugin.getPreviewManager().remove(player.getUniqueId(), true),
cancelTask = plugin.getFoliaLib().getScheduler().runAtEntityLater(player, () -> plugin.getPreviewManager().remove(player.getUniqueId(), true),
plugin.getConfiguration().getPreview().getDuration() * 20L);
}

Expand All @@ -64,10 +64,10 @@ public void cancel(boolean open) {
if (open && onClose != null) {
onClose.accept(player);
}
plugin.getFoliaLib().getImpl().runAtEntityLater(player, () -> {
plugin.getFoliaLib().getScheduler().runAtEntityLater(player, () -> {
PacketEvents.getAPI().getPlayerManager().sendPacket(player, new WrapperPlayServerDestroyEntities(entityId));
if (plugin.getConfiguration().getPreview().getSneakCancel().isActionBar()) {
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(" "));
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacy(" "));
}
}, 1L);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ public void preview() {
slot = 36 + player.getInventory().getHeldItemSlot();
sendFakeItem(item);

task = plugin.getFoliaLib().getImpl().runTimerAsync(() -> {
task = plugin.getFoliaLib().getScheduler().runTimerAsync(() -> {
if (plugin.getConfiguration().getPreview().getSneakCancel().isActionBar() && plugin.getConfiguration().getPreview().getSneakCancel().isEnabled()) {
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, StringUtil.parse(player, plugin.getMessageHandler().get(Messages.PREVIEW_BAR)));
}
}, 3, 1);
cancelTask = plugin.getFoliaLib().getImpl().runAtEntityLater(player, () -> plugin.getPreviewManager().remove(player.getUniqueId(), true),
cancelTask = plugin.getFoliaLib().getScheduler().runAtEntityLater(player, () -> plugin.getPreviewManager().remove(player.getUniqueId(), true),
plugin.getConfiguration().getPreview().getDuration() * 20L);
}

Expand All @@ -56,10 +56,10 @@ public void cancel(boolean open) {
if (open && onClose != null) {
onClose.accept(player);
}
plugin.getFoliaLib().getImpl().runAtEntityLater(player, () -> {
plugin.getFoliaLib().getScheduler().runAtEntityLater(player, () -> {
sendFakeItem(oldItem);
if (plugin.getConfiguration().getPreview().getSneakCancel().isActionBar()) {
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(" "));
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacy(" "));
}
}, 1L);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class GlobalDisable {
private List<String> oraxen;
private List<String> itemsadder;
private List<String> mythic;
private List<String> nexo;

public List<Integer> getModelId() {
return modelId;
Expand All @@ -33,4 +34,8 @@ public List<String> getMythicId() {
return mythic;
}

public List<String> getNexoId() {
return nexo;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class Inventory {
private int targetItemSlot;
private Map<String, InventoryItem> items;
private @Nullable HashMap<String, HashMap<String, List<String>>> actions;
private @Nullable HashMap<String, HashMap<String, List<String>>> lockedActions;

public String getTitle() {
return title;
Expand Down Expand Up @@ -51,6 +52,11 @@ public HashMap<String, HashMap<String, List<String>>> getActions() {
return actions;
}

@Nullable
public HashMap<String, HashMap<String, List<String>>> getLockedActions() {
return lockedActions;
}

public boolean isItemChangeEnabled() {
return itemChangeEnabled;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class InventoryItem extends SerializableItem {
public InventoryItem(String id, String name, @Nullable Boolean glow, @Nullable List<String> lore, @Nullable List<String> flags,
@Nullable Integer modelId, @Nullable Map<String, Integer> enchantments, @Nullable Integer amount,
@Nullable String color, @Nullable String nbt, @Nullable Integer durability, @Nullable String skullOwner, @Nullable String skullTexture,
@Nullable String trim, @Nullable String trimMaterial) {
super(id, name, glow, lore, flags, modelId, enchantments, amount, color, nbt, durability, skullOwner, skullTexture, trim, trimMaterial);
@Nullable String trim, @Nullable String trimMaterial, @Nullable String equippableSlot, @Nullable String equippableModel) {
super(id, name, glow, lore, flags, modelId, enchantments, amount, color, nbt, durability, skullOwner, skullTexture, trim, trimMaterial, equippableSlot, equippableModel);
}

public InventoryItem() {
Expand Down
Loading

0 comments on commit b9eee09

Please sign in to comment.