Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
496ace7
Added ItemReference and it's Bukkit and WolfyUtils implementation.
WolfyScript Sep 29, 2022
30d9349
Added ItemReference.Parser
WolfyScript Sep 30, 2022
13eba1b
Added ItemReferenceParser annotation that can mark a method and Parse…
WolfyScript Sep 30, 2022
01ab536
Started implementing ItemStackConfig for Bukkit
WolfyScript Oct 24, 2022
a6c5f48
Merge branch 'item_reference' into better-itemstack-config
WolfyScript Oct 24, 2022
59be659
Renamed ItemReferenceParser to ItemReferenceParserSettings
WolfyScript Nov 5, 2022
7690548
Updated built-in references to new parser annotation
WolfyScript Nov 5, 2022
67545c4
Added plugin option to ItemReferenceParserSettings
WolfyScript Nov 8, 2022
0873457
Added RegistryItemReferences to handle parsers
WolfyScript Nov 8, 2022
b2d3c16
Added id to ItemReference.Parser
WolfyScript Nov 8, 2022
2c43abc
Added BackwardsWrapperReference that wraps old APIReferences
WolfyScript Nov 8, 2022
98f5cfb
Added ItemRefCompDeserializer that converts old APIReferences to the …
WolfyScript Nov 8, 2022
48e3349
Updated CustomItem to use the new ItemReference
WolfyScript Nov 8, 2022
345e1bb
Updated ItemUtils and RegistryCustomItem to use the new ItemReference
WolfyScript Nov 8, 2022
d1c69cf
Merge branch 'master' into better-itemstack-config
WolfyScript Nov 18, 2022
b515eae
Merge branch 'v5.0.0' into better-itemstack-config
WolfyScript Nov 22, 2022
d048159
Merge branch 'v5.0.0' into better-itemstack-config
WolfyScript Nov 22, 2022
4fc59f0
Updated BukkitItemStackConfig to use ValueProviders
WolfyScript Nov 22, 2022
9315d4c
Merge branch 'v5.0.0' into better-itemstack-config
WolfyScript Dec 6, 2022
7121af7
Reimplemented ItemReferences and inject WolfyUtils across CustomItems…
WolfyScript Dec 6, 2022
00f1c59
Moved the ItemReference.AbstractParser to ItemReferenceParserSettings…
WolfyScript Dec 6, 2022
f6a69a8
Updated BukkitItemStackConfig to new API.
WolfyScript Dec 7, 2022
a1d6dc2
Started work on loading config from ItemStack
WolfyScript Dec 9, 2022
22e1621
Load all the available NBTTags into the config from the ItemStack.
WolfyScript Dec 9, 2022
2675914
Fully implemented contextual NBT construction.
WolfyScript Dec 9, 2022
b43c0ac
Merge branch 'v5.0.0' into better-itemstack-config
WolfyScript Dec 11, 2022
cc3990c
Updated NBT API to 2.11
WolfyScript Dec 13, 2022
5c45501
Fixed ItemReferenceParserSettings creating invalid parsers.
WolfyScript Dec 13, 2022
ab482f7
Added toString to ItemReferences
WolfyScript Dec 13, 2022
8fb324c
Fixed ItemReference type id
WolfyScript Dec 13, 2022
8641790
Make SimpleBukkitItemReference take priority over the BukkitItemRefer…
WolfyScript Dec 13, 2022
6d434b9
Ignore SimpleBukkitItemReference#getItem on serialization
WolfyScript Dec 13, 2022
8972ef7
Fixed reversed priority of ItemReferences
WolfyScript Dec 13, 2022
9b683e0
Ignore WolfyUtils in json
WolfyScript Dec 13, 2022
55b21d2
Reorder ItemReference properties in json
WolfyScript Dec 13, 2022
9ea37c8
Added DebugSimpleStackConfigCommand and renamed DebugNBTQueryCommand
WolfyScript Dec 13, 2022
f35c8e9
Removed unnecessary imports in nms 1.16
WolfyScript Dec 13, 2022
96bd94b
Cleaned up imports
WolfyScript Dec 13, 2022
8a4ae90
Register NBTTagConfigs
WolfyScript Dec 13, 2022
1e62a7c
Added NBTTagsRegistry to KeyedTypeResolver
WolfyScript Dec 13, 2022
051a49f
Add injectable values to global mapper
WolfyScript Dec 13, 2022
2fcc957
Init core for KeyedTypeIdResolver
WolfyScript Dec 13, 2022
89c1350
Register ItemReferences
WolfyScript Dec 13, 2022
615d85f
Removed old ItemReference registration
WolfyScript Dec 13, 2022
b1dc157
Added missing imports
WolfyScript Dec 13, 2022
d4d381b
Apply NBT first, so the specialized ItemMeta options override them.
WolfyScript Dec 13, 2022
3438bf1
Updated to latest NBT-API and WolfyUtils API
WolfyScript Dec 13, 2022
cbe1a4f
Changed Spigot to Paper API, so that we can use paper features.
WolfyScript Dec 14, 2022
ae54363
Added CompatibilityManager#isPaper
WolfyScript Dec 14, 2022
8ddf886
Improved BukkitItemStackConfig
WolfyScript Dec 14, 2022
e926daf
Updated to relocated nbt package
WolfyScript Dec 14, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
<artifactId>worldguard-bukkit</artifactId>
<version>7.1.0-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- PlotSquared Bukkit API-->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package com.wolfyscript.utilities.bukkit;

import com.fasterxml.jackson.databind.InjectableValues;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.wolfyscript.jackson.dataformat.hocon.HoconMapper;
import com.wolfyscript.utilities.bukkit.chat.BukkitChat;
import com.wolfyscript.utilities.bukkit.commands.ChatActionCommand;
import com.wolfyscript.utilities.bukkit.commands.InfoCommand;
import com.wolfyscript.utilities.bukkit.commands.InputCommand;
import com.wolfyscript.utilities.bukkit.commands.QueryDebugCommand;
import com.wolfyscript.utilities.bukkit.commands.DebugNBTQueryCommand;
import com.wolfyscript.utilities.bukkit.commands.SpawnParticleAnimationCommand;
import com.wolfyscript.utilities.bukkit.commands.SpawnParticleEffectCommand;
import com.wolfyscript.utilities.bukkit.commands.DebugSimpleStackConfigCommand;
import com.wolfyscript.utilities.bukkit.compatibility.CompatibilityManager;
import com.wolfyscript.utilities.bukkit.compatibility.CompatibilityManagerBukkit;
import com.wolfyscript.utilities.bukkit.config.WUConfig;
Expand Down Expand Up @@ -47,6 +49,8 @@
import com.wolfyscript.utilities.bukkit.world.items.meta.PotionMeta;
import com.wolfyscript.utilities.bukkit.world.items.meta.RepairCostMeta;
import com.wolfyscript.utilities.bukkit.world.items.meta.UnbreakableMeta;
import com.wolfyscript.utilities.bukkit.world.items.reference.ItemReference;
import com.wolfyscript.utilities.bukkit.world.items.reference.SimpleBukkitItemReference;
import com.wolfyscript.utilities.bukkit.world.items.references.APIReference;
import com.wolfyscript.utilities.bukkit.world.items.references.VanillaRef;
import com.wolfyscript.utilities.bukkit.world.items.references.WolfyUtilitiesRef;
Expand Down Expand Up @@ -81,7 +85,27 @@
import com.wolfyscript.utilities.bukkit.persistent.player.CustomPlayerData;
import com.wolfyscript.utilities.bukkit.persistent.player.PlayerParticleEffectData;
import com.wolfyscript.utilities.bukkit.persistent.world.CustomBlockData;
import com.wolfyscript.utilities.bukkit.world.items.reference.BukkitItemReference;
import com.wolfyscript.utilities.bukkit.world.items.reference.WolfyUtilsItemReference;
import com.wolfyscript.utilities.common.WolfyUtils;
import com.wolfyscript.utilities.nbt.NBTTagConfig;
import com.wolfyscript.utilities.nbt.NBTTagConfigBoolean;
import com.wolfyscript.utilities.nbt.NBTTagConfigByte;
import com.wolfyscript.utilities.nbt.NBTTagConfigByteArray;
import com.wolfyscript.utilities.nbt.NBTTagConfigDouble;
import com.wolfyscript.utilities.nbt.NBTTagConfigFloat;
import com.wolfyscript.utilities.nbt.NBTTagConfigInt;
import com.wolfyscript.utilities.nbt.NBTTagConfigIntArray;
import com.wolfyscript.utilities.nbt.NBTTagConfigListCompound;
import com.wolfyscript.utilities.nbt.NBTTagConfigListDouble;
import com.wolfyscript.utilities.nbt.NBTTagConfigListFloat;
import com.wolfyscript.utilities.nbt.NBTTagConfigListInt;
import com.wolfyscript.utilities.nbt.NBTTagConfigListIntArray;
import com.wolfyscript.utilities.nbt.NBTTagConfigListLong;
import com.wolfyscript.utilities.nbt.NBTTagConfigListString;
import com.wolfyscript.utilities.nbt.NBTTagConfigLong;
import com.wolfyscript.utilities.nbt.NBTTagConfigShort;
import com.wolfyscript.utilities.nbt.NBTTagConfigString;
import com.wolfyscript.utilities.eval.operator.BoolOperatorConst;
import com.wolfyscript.utilities.eval.operator.ComparisonOperatorEqual;
import com.wolfyscript.utilities.eval.operator.ComparisonOperatorGreater;
Expand Down Expand Up @@ -235,6 +259,7 @@ public void onLoad() {

// Jackson Serializer
getLogger().info("Register JSON de-/serializers");
KeyedTypeIdResolver.setCore(this);
var module = new SimpleModule();
ItemStackSerialization.create(module);
ColorSerialization.create(module);
Expand Down Expand Up @@ -267,9 +292,17 @@ public void onLoad() {
JacksonUtil.registerModule(valueReferenceModule);

// Create Global WUCore Mapper and apply modules
api.getJacksonMapperUtil().setGlobalMapper(applyWolfyUtilsJsonMapperModules(new HoconMapper()));
HoconMapper mapper = applyWolfyUtilsJsonMapperModules(new HoconMapper());
api.getJacksonMapperUtil().applyWolfyUtilsInjectableValues(mapper, new InjectableValues.Std());
api.getJacksonMapperUtil().setGlobalMapper(mapper);

// Initialise all the Registers
console.info("Register Item references");
var itemReferences = getRegistries().getItemReferences();
itemReferences.register(BukkitItemReference.class);
itemReferences.register(SimpleBukkitItemReference.class);
itemReferences.register(WolfyUtilsItemReference.class);

getLogger().info("Register JSON Operators");
var operators = getRegistries().getOperators();
operators.register(BoolOperatorConst.class);
Expand Down Expand Up @@ -373,6 +406,29 @@ public void onLoad() {
var customPlayerDataReg = getRegistries().getCustomPlayerData();
customPlayerDataReg.register(PlayerParticleEffectData.class);

getLogger().info("Register NBT Tag Configs");
var nbtTagConfigs = getRegistries().getNbtTagConfigs();
// Primitives
nbtTagConfigs.register(NBTTagConfigBoolean.class);
nbtTagConfigs.register(NBTTagConfigString.class);
// Primitive Numerals
nbtTagConfigs.register(NBTTagConfigByte.class);
nbtTagConfigs.register(NBTTagConfigByteArray.class);
nbtTagConfigs.register(NBTTagConfigShort.class);
nbtTagConfigs.register(NBTTagConfigInt.class);
nbtTagConfigs.register(NBTTagConfigIntArray.class);
nbtTagConfigs.register(NBTTagConfigLong.class);
nbtTagConfigs.register(NBTTagConfigFloat.class);
nbtTagConfigs.register(NBTTagConfigDouble.class);
// Lists
nbtTagConfigs.register(NBTTagConfigListCompound.class);
nbtTagConfigs.register(NBTTagConfigListInt.class);
nbtTagConfigs.register(NBTTagConfigListIntArray.class);
nbtTagConfigs.register(NBTTagConfigListLong.class);
nbtTagConfigs.register(NBTTagConfigListFloat.class);
nbtTagConfigs.register(NBTTagConfigListDouble.class);
nbtTagConfigs.register(NBTTagConfigListString.class);

getLogger().info("Register NBT Query Nodes");
var nbtQueryNodes = getRegistries().getNbtQueryNodes();
nbtQueryNodes.register(QueryNodeCompound.class);
Expand All @@ -398,6 +454,7 @@ public void onLoad() {

// Register the Registries to resolve type references in JSON
KeyedTypeIdResolver.registerTypeRegistry(CustomItemData.class, registries.getCustomItemDataTypeRegistry());
KeyedTypeIdResolver.registerTypeRegistry(ItemReference.class, itemReferences);
KeyedTypeIdResolver.registerTypeRegistry(Meta.class, nbtChecks);
KeyedTypeIdResolver.registerTypeRegistry(Animator.class, particleAnimators);
KeyedTypeIdResolver.registerTypeRegistry(Shape.class, particleShapes);
Expand All @@ -409,6 +466,7 @@ public void onLoad() {
KeyedTypeIdResolver.registerTypeRegistry((Class<QueryNode<?>>) (Object)QueryNode.class, nbtQueryNodes);
KeyedTypeIdResolver.registerTypeRegistry(CustomBlockData.class, customBlockData);
KeyedTypeIdResolver.registerTypeRegistry(CustomPlayerData.class, registries.getCustomPlayerData());
KeyedTypeIdResolver.registerTypeRegistry(NBTTagConfig.class, nbtTagConfigs);
}

@Override
Expand All @@ -421,8 +479,7 @@ public void onEnable() {
this.config = new WUConfig(api.getConfigAPI(), this);
compatibilityManager.init();

// Register ReferenceParser
console.info("Register API references");
// Register ItemReferences
registerAPIReference(new VanillaRef.Parser());
registerAPIReference(new WolfyUtilitiesRef.Parser());

Expand Down Expand Up @@ -488,7 +545,8 @@ private void registerCommands() {
Bukkit.getServer().getPluginCommand("wui").setTabCompleter(new InputCommand(this));
Bukkit.getServer().getPluginCommand("wua").setExecutor(new ChatActionCommand());

Bukkit.getServer().getPluginCommand("query_item").setExecutor(new QueryDebugCommand(this));
Bukkit.getServer().getPluginCommand("query_item").setExecutor(new DebugNBTQueryCommand(this));
Bukkit.getServer().getPluginCommand("simple_bukkit_stack").setExecutor(new DebugSimpleStackConfigCommand(this));
}

public MessageHandler getMessageHandler() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class QueryDebugCommand implements TabExecutor {
public class DebugNBTQueryCommand implements TabExecutor {

private final WolfyCoreBukkit plugin;

public QueryDebugCommand(WolfyCoreBukkit plugin) {
public DebugNBTQueryCommand(WolfyCoreBukkit plugin) {
this.plugin = plugin;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* WolfyUtilities, APIs and Utilities for Minecraft Spigot plugins
* Copyright (C) 2021 WolfyScript
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.wolfyscript.utilities.bukkit.commands;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.wolfyscript.utilities.bukkit.WolfyCoreBukkit;
import com.wolfyscript.utilities.bukkit.world.inventory.ItemUtils;
import com.wolfyscript.utilities.bukkit.world.items.reference.ItemReference;
import com.wolfyscript.utilities.bukkit.world.items.reference.SimpleBukkitItemReference;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class DebugSimpleStackConfigCommand implements TabExecutor {

private final WolfyCoreBukkit plugin;

public DebugSimpleStackConfigCommand(WolfyCoreBukkit plugin) {
this.plugin = plugin;
}

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (!(sender instanceof Player player)) return true;
if (!player.hasPermission("wolfyutilities.command.simple_bukkit_stack_debug")) return true;
if (!ItemUtils.isAirOrNull(player.getEquipment().getItemInMainHand())) {
ItemReference reference = plugin.getRegistries().getItemReferences().parse(player.getEquipment().getItemInMainHand());
System.out.println("Found Reference: " + reference);
System.out.println(reference.getItem());
if (reference instanceof SimpleBukkitItemReference itemReference) {
System.out.println(itemReference.getConfig());
try {
System.out.println(plugin.getWolfyUtils().getJacksonMapperUtil().getGlobalMapper().writeValueAsString(itemReference));
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
return true;
}
File file = new File(plugin.getDataFolder(), "simple_bukkit_stack_debug.conf");
if (file.exists()) {
try {
ItemReference reference = plugin.getWolfyUtils().getJacksonMapperUtil().getGlobalMapper().readValue(file, ItemReference.class);
System.out.println("Reference: " + reference.toString());
System.out.println(reference.getItem());
ItemStack stack = reference.getItem();
if (stack != null) {
player.getInventory().addItem(stack);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return true;
}

@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ public interface CompatibilityManager {
void init();

Plugins getPlugins();

boolean isPaper();
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,21 @@
package com.wolfyscript.utilities.bukkit.compatibility;

import com.wolfyscript.utilities.bukkit.WolfyUtilCore;
import java.util.HashMap;
import java.util.Map;

public final class CompatibilityManagerBukkit implements CompatibilityManager {


private static final Map<String, Boolean> classes = new HashMap<>();
private final WolfyUtilCore core;
private final PluginsBukkit pluginsBukkit;
private final boolean isPaper;

public CompatibilityManagerBukkit(WolfyUtilCore core) {
this.core = core;
this.pluginsBukkit = new PluginsBukkit(core);
this.isPaper = hasClass("com.destroystokyo.paper.utils.PaperPluginLogger");
}

public void init() {
Expand All @@ -37,4 +43,29 @@ public void init() {
public Plugins getPlugins() {
return pluginsBukkit;
}

@Override
public boolean isPaper() {
return isPaper;
}

/**
* Check if the specific class exists.
*
* @param path The path to the class to check for.
* @return If the class exists.
*/
public static boolean hasClass(String path) {
if (classes.containsKey(path)) {
return classes.get(path);
}
try {
Class.forName(path);
classes.put(path, true);
return true;
} catch (Exception e) {
classes.put(path, false);
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public class BukkitRegistries extends Registries {
private final TypeRegistry<CustomBlockData> customBlockData;
private final TypeRegistry<CustomPlayerData> customPlayerData;
private final TypeRegistry<CustomItemData> customItemDataTypeRegistry;
private final RegistryItemReferences itemReferences;

private final TypeRegistry<QueryNode<?>> nbtQueryNodes;

Expand All @@ -95,6 +96,7 @@ public BukkitRegistries(WolfyUtilCore core) {

customItems = new RegistryCustomItem(this);
customItemData = new RegistrySimple<>(new BukkitNamespacedKey(core, "custom_item_data"), this);
itemReferences = new RegistryItemReferences(this);
particleEffects = new RegistryParticleEffect(this);
particleAnimations = new RegistryParticleAnimation(this);
customItemActionValues = new RegistrySimple<>(ITEM_ACTION_VALUES, this, (Class<Action<?>>)(Object) Action.class);
Expand Down Expand Up @@ -228,4 +230,8 @@ public TypeRegistry<CustomBlockData> getCustomBlockData() {
public TypeRegistry<QueryNode<?>> getNbtQueryNodes() {
return nbtQueryNodes;
}

public RegistryItemReferences getItemReferences() {
return itemReferences;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package com.wolfyscript.utilities.bukkit.registry;

import com.wolfyscript.utilities.bukkit.world.items.reference.WolfyUtilsItemReference;
import com.wolfyscript.utilities.NamespacedKey;
import com.wolfyscript.utilities.bukkit.BukkitNamespacedKey;
import com.wolfyscript.utilities.bukkit.world.items.CustomItem;
Expand Down Expand Up @@ -115,7 +116,7 @@ public void remove(NamespacedKey namespacedKey) {
*/
@Override
public void register(NamespacedKey namespacedKey, CustomItem item) {
if (item == null || (item.getApiReference() instanceof WolfyUtilitiesRef && ((WolfyUtilitiesRef) item.getApiReference()).getNamespacedKey().equals(namespacedKey))) {
if (item == null || (item.getReference() instanceof WolfyUtilsItemReference wuRef && wuRef.getNamespacedKey().equals(namespacedKey))) {
return;
}
this.map.put(namespacedKey, item);
Expand Down
Loading