Skip to content

Commit

Permalink
Merge branch 'HelpChat:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Euphillya authored Dec 16, 2024
2 parents 193af7a + abd23c9 commit 9935b48
Show file tree
Hide file tree
Showing 21 changed files with 700 additions and 213 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies {
compileOnly(libs.headdb)
compileOnly(libs.itemsadder)
compileOnly(libs.oraxen)
compileOnly(libs.mythiclib)
compileOnly(libs.mmoitems)
compileOnly(libs.score)

Expand Down
8 changes: 5 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
[versions]
# Compile only
spigot = "1.21-R0.1-SNAPSHOT"
spigot = "1.21.3-R0.1-SNAPSHOT"
vault = "1.7.1"
authlib = "1.5.25"
headdb = "1.3.1"
itemsadder = "3.2.5"
oraxen = "1.159.0"
mmoitems = "6.9.4-SNAPSHOT"
mythiclib = "1.6.2-SNAPSHOT"
mmoitems = "6.9.5-SNAPSHOT"
papi = "2.11.6"
score = "4.23.10.8"

# Implementation
nashorn = "15.4"
adventure-platform = "4.3.3"
adventure-platform = "4.3.4"
adventure-minimessage = "4.17.0"

[libraries]
Expand All @@ -23,6 +24,7 @@ authlib = { module = "com.mojang:authlib", version.ref = "authlib" }
headdb = { module = "com.arcaniax:HeadDatabase-API", version.ref = "headdb" }
itemsadder = { module = "com.github.LoneDev6:api-itemsadder", version.ref = "itemsadder" }
oraxen = { module = "com.github.oraxen:oraxen", version.ref = "oraxen" }
mythiclib = { module = "io.lumine:MythicLib-dist", version.ref = "mythiclib"}
mmoitems = { module = "net.Indyuce:MMOItems-API", version.ref = "mmoitems" }
papi = { module = "me.clip:placeholderapi", version.ref = "papi" }
score = { module = "com.github.Ssomar-Developement:SCore", version.ref = "score" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,10 +759,19 @@ private Map<Integer, TreeMap<Integer, MenuItem>> loadMenuItems(FileConfiguration
.hideUnbreakable(c.getBoolean(currentPath + "hide_unbreakable", false))
.hideEnchants(c.getBoolean(currentPath + "hide_enchantments", false))
.nbtString(c.getString(currentPath + "nbt_string", null))
.nbtByte(c.getString(currentPath + "nbt_byte", null))
.nbtShort(c.getString(currentPath + "nbt_short", null))
.nbtInt(c.getString(currentPath + "nbt_int", null))
.nbtStrings(c.getStringList(currentPath + "nbt_strings"))
.nbtBytes(c.getStringList(currentPath + "nbt_bytes"))
.nbtShorts(c.getStringList(currentPath + "nbt_shorts"))
.nbtInts(c.getStringList(currentPath + "nbt_ints"))
.priority(c.getInt(currentPath + "priority", 1));
.priority(c.getInt(currentPath + "priority", 1))
.hideTooltip(c.getString(currentPath + "hide_tooltip", null))
.enchantmentGlintOverride(c.getString(currentPath + "enchantment_glint_override", null))
.rarity(c.getString(currentPath + "rarity", null))
.tooltipStyle(c.getString(currentPath + "tooltip_style", null))
.itemModel(c.getString(currentPath + "item_model", null));

// Lore Append Mode
if (c.contains(currentPath + "lore_append_mode")) {
Expand Down Expand Up @@ -1056,9 +1065,14 @@ private RequirementList getRequirements(FileConfiguration c, String path) {
case DOES_NOT_HAVE_ITEM:
ItemWrapper wrapper = new ItemWrapper();
if (c.contains(rPath + ".material")) {
String materialName = c.getString(rPath + ".material");
try {
if (!containsPlaceholders(c.getString(rPath + ".material")))
Material.valueOf(c.getString(rPath + ".material").toUpperCase());
if (!containsPlaceholders(materialName) && plugin.getItemHooks().values()
.stream()
.filter(x -> materialName.toLowerCase().startsWith(x.getPrefix()))
.findFirst()
.orElse(null) == null)
Material.valueOf(materialName.toUpperCase());
} catch (Exception ex) {
DeluxeMenus.debug(
DebugLevel.HIGHEST,
Expand All @@ -1067,7 +1081,7 @@ private RequirementList getRequirements(FileConfiguration c, String path) {
);
break;
}
wrapper.setMaterial(c.getString(rPath + ".material"));
wrapper.setMaterial(materialName);
} else {
DeluxeMenus.debug(
DebugLevel.HIGHEST,
Expand Down Expand Up @@ -1142,6 +1156,44 @@ private RequirementList getRequirements(FileConfiguration c, String path) {
);
}
break;
case HAS_PERMISSIONS:
case DOES_NOT_HAVE_PERMISSIONS:
if (c.contains(rPath + ".permissions")) {
invert = type == RequirementType.DOES_NOT_HAVE_PERMISSIONS;
int minimum = -1;
if (c.contains(rPath + ".minimum") && (minimum = c.getInt(rPath + ".minimum")) < 1) {
DeluxeMenus.debug(
DebugLevel.HIGHEST,
Level.WARNING,
"Has Permissions requirement at path: " + rPath + " has a minimum lower than 1. All permissions will be checked"
);
minimum = -1;
}
List<String> permissions = c.getStringList(rPath + ".permissions");
if (permissions.isEmpty()) {
DeluxeMenus.debug(
DebugLevel.HIGHEST,
Level.WARNING,
"Has Permissions requirement at path: " + rPath + " has no permissions to check. Ignoring..."
);
break;
} else if (minimum > permissions.size()) {
DeluxeMenus.debug(
DebugLevel.HIGHEST,
Level.WARNING,
"Has Permissions requirement at path: " + rPath + " has a minimum higher than the amount of permissions. Using "+permissions.size()+" instead"
);
minimum = permissions.size();
}
req = new HasPermissionsRequirement(permissions, minimum, invert);
} else {
DeluxeMenus.debug(
DebugLevel.HIGHEST,
Level.WARNING,
"Has Permissions requirement at path: " + rPath + " does not contain permissions: entry"
);
}
break;
case JAVASCRIPT:
if (c.contains(rPath + ".expression")) {
req = new JavascriptRequirement(c.getString(rPath + ".expression"));
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/extendedclip/deluxemenus/hooks/BaseHeadHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ public ItemStack getItem(@NotNull final String... arguments) {
return DeluxeMenus.getInstance().getHead().clone();
}

@Override
public boolean itemMatchesIdentifiers(@NotNull ItemStack item, @NotNull String... arguments) {
if (arguments.length == 0) {
return false;
}
String itemTexture = SkullUtils.getTextureFromSkull(item);
String texture = SkullUtils.decodeSkinUrl(arguments[0]);
if (itemTexture == null || texture == null) return false;

texture = texture.substring("https://textures.minecraft.net/texture/".length()-1);
return texture.equals(itemTexture);
}

@Override
public String getPrefix() {
return "basehead-";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public ItemStack getItem(@NotNull String... arguments) {
return (item == null) ? new ItemStack(Material.STONE) : item.clone();
}

@Override
public boolean itemMatchesIdentifiers(@NotNull ItemStack item, @NotNull String... arguments) {
return false;
}

@Override
public String getPrefix() {
return "executableblocks-";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;

import com.ssomar.score.api.executableitems.config.ExecutableItemInterface;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
Expand All @@ -31,6 +33,16 @@ public ItemStack getItem(@NotNull String... arguments) {
return (item == null) ? new ItemStack(Material.STONE) : item.clone();
}

@Override
public boolean itemMatchesIdentifiers(@NotNull ItemStack item, @NotNull String... arguments) {
if (arguments.length == 0) {
return false;
}
ExecutableItemInterface fromId = ExecutableItemsAPI.getExecutableItemsManager().getExecutableItem(arguments[0]).orElse(null);
ExecutableItemInterface fromItem = ExecutableItemsAPI.getExecutableItemsManager().getExecutableItem(item).orElse(null);
return fromItem != null && fromItem.equals(fromId);
}

@Override
public String getPrefix() {
return "executableitems-";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ public ItemStack getItem(@NotNull final String... arguments) {
return DeluxeMenus.getInstance().getHead().clone();
}

@Override
public boolean itemMatchesIdentifiers(@NotNull ItemStack item, @NotNull String... arguments) {
if (arguments.length == 0) {
return false;
}
return arguments[0].equalsIgnoreCase(api.getItemID(item));
}

@Override
public String getPrefix() {
return "hdb-";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public interface ItemHook {

ItemStack getItem(@NotNull final String... arguments);

boolean itemMatchesIdentifiers(@NotNull ItemStack item, @NotNull final String... arguments);

String getPrefix();

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ public ItemStack getItem(@NotNull final String... arguments) {
return item.clone();
}

@Override
public boolean itemMatchesIdentifiers(@NotNull ItemStack item, @NotNull String... arguments) {
if (arguments.length == 0) {
return false;
}
CustomStack stack = CustomStack.byItemStack(item);
return stack != null && stack.getId().equalsIgnoreCase(arguments[0]);
}

@Override
public String getPrefix() {
return "itemsadder-";
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/extendedclip/deluxemenus/hooks/MMOItemsHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ public ItemStack getItem(@NotNull final String... arguments) {
return mmoItem == null ? new ItemStack(Material.STONE, 1) : mmoItem;
}

@Override
public boolean itemMatchesIdentifiers(@NotNull ItemStack item, @NotNull String... arguments) {
if (arguments.length == 0) {
return false;
}
String[] splitArgs = arguments[0].split(":");
if (splitArgs.length != 2) return false;
return splitArgs[0].equalsIgnoreCase(MMOItems.getTypeName(item)) && splitArgs[1].equalsIgnoreCase(MMOItems.getID(item));
}

@Override
public String getPrefix() {
return "mmoitems-";
Expand Down
124 changes: 68 additions & 56 deletions src/main/java/com/extendedclip/deluxemenus/hooks/NamedHeadHook.java
Original file line number Diff line number Diff line change
@@ -1,56 +1,68 @@
package com.extendedclip.deluxemenus.hooks;

import com.extendedclip.deluxemenus.DeluxeMenus;
import com.extendedclip.deluxemenus.cache.SimpleCache;
import com.extendedclip.deluxemenus.utils.SkullUtils;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

public class NamedHeadHook implements ItemHook, Listener, SimpleCache {

private final Map<String, ItemStack> cache = new ConcurrentHashMap<>();

public NamedHeadHook(@NotNull final DeluxeMenus plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}

@Override
public ItemStack getItem(@NotNull final String... arguments) {
if (arguments.length == 0) {
return DeluxeMenus.getInstance().getHead().clone();
}

try {
return cache.computeIfAbsent(arguments[0], SkullUtils::getSkullByName).clone();
} catch (Exception exception) {
DeluxeMenus.printStacktrace(
"Something went wrong while trying to get a head by name" +
": " + arguments[0],
exception
);
}

return DeluxeMenus.getInstance().getHead().clone();
}

@EventHandler(ignoreCancelled = true)
public void onPlayerQuit(final PlayerQuitEvent event) {
cache.remove(event.getPlayer().getName());
}

@Override
public String getPrefix() {
return "head-";
}

@Override
public void clearCache() {
cache.clear();
}
}
package com.extendedclip.deluxemenus.hooks;

import com.extendedclip.deluxemenus.DeluxeMenus;
import com.extendedclip.deluxemenus.cache.SimpleCache;
import com.extendedclip.deluxemenus.utils.SkullUtils;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.extendedclip.deluxemenus.utils.VersionHelper;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import org.jetbrains.annotations.NotNull;

public class NamedHeadHook implements ItemHook, Listener, SimpleCache {

private final Map<String, ItemStack> cache = new ConcurrentHashMap<>();

public NamedHeadHook(@NotNull final DeluxeMenus plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}

@Override
public ItemStack getItem(@NotNull final String... arguments) {
if (arguments.length == 0) {
return DeluxeMenus.getInstance().getHead().clone();
}

try {
return cache.computeIfAbsent(arguments[0], SkullUtils::getSkullByName).clone();
} catch (Exception exception) {
DeluxeMenus.printStacktrace(
"Something went wrong while trying to get a head by name" +
": " + arguments[0],
exception
);
}

return DeluxeMenus.getInstance().getHead().clone();
}

@Override
public boolean itemMatchesIdentifiers(@NotNull ItemStack item, @NotNull String... arguments) {
if (arguments.length == 0) {
return false;
}
return arguments[0].equalsIgnoreCase(SkullUtils.getSkullOwner(item));
}

@EventHandler(ignoreCancelled = true)
public void onPlayerQuit(final PlayerQuitEvent event) {
cache.remove(event.getPlayer().getName());
}

@Override
public String getPrefix() {
return "head-";
}

@Override
public void clearCache() {
cache.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ public ItemStack getItem(@NotNull String... arguments) {
return (item == null) ? new ItemStack(Material.STONE) : item.clone();
}

@Override
public boolean itemMatchesIdentifiers(@NotNull ItemStack item, @NotNull String... arguments) {
if (arguments.length == 0) {
return false;
}
return arguments[0].equalsIgnoreCase(OraxenItems.getIdByItem(item));
}

@Override
public String getPrefix() {
return "oraxen-";
Expand Down
Loading

0 comments on commit 9935b48

Please sign in to comment.