Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
e903880
Add fallback to APIReference
WolfyScript Oct 6, 2023
2eab447
Implement fallback into APIReferenceSerialization
WolfyScript Oct 6, 2023
e0bba87
Implement fallback into CustomItem#getReferenceByItemStack
WolfyScript Oct 6, 2023
5df50fb
Apply fallback when creating VanillaRef
WolfyScript Oct 6, 2023
f4d6d7a
Only try to deserialize APIReference fallback if json node available
WolfyScript Oct 6, 2023
5573de2
Merge branch 'master' into feature/api-ref-stack-fallback
WolfyScript Oct 12, 2023
2d0e175
Start reworking APIReference system
WolfyScript Oct 12, 2023
448a3d3
Add Bukkit and WolfyUtils stack identifiers
WolfyScript Oct 12, 2023
770357c
Start migrating from APIReferences to StackReferences
WolfyScript Oct 12, 2023
b1fd53a
Remove fallback from APIReference
WolfyScript Oct 13, 2023
33b1b28
Deprecate APIReference
WolfyScript Oct 13, 2023
c894875
Add convert method to StackIdentifier
WolfyScript Oct 13, 2023
0fcce7d
Add convert method to StackReference
WolfyScript Oct 13, 2023
dc8d075
Add convert methods to APIReference
WolfyScript Oct 13, 2023
882f5e0
Use APIReference convert method when deserializing StackReference fro…
WolfyScript Oct 13, 2023
4e24998
Add a few more constructors to StackReference
WolfyScript Oct 13, 2023
744b145
Implement convert method in VanillaRef and WolfyUtilitiesRef
WolfyScript Oct 13, 2023
a78f460
Add WolfyUtilsStackIdentifier#customItem to get the referenced Custom…
WolfyScript Oct 13, 2023
b9c98ab
Use the customItem method in WolfyUtilsStackIdentifier#item method
WolfyScript Oct 13, 2023
845964b
Remove parser from WolfyUtilsStackIdentifier
WolfyScript Oct 13, 2023
254b7dc
Update CustomItem to the new StackReference system
WolfyScript Oct 13, 2023
fa746b7
Bump version to 4.16.15-beta.1-SNAPSHOT
WolfyScript Oct 13, 2023
5c99e6b
Make StackIdentifierParser Comparable
WolfyScript Oct 13, 2023
98b69d1
Fix StackReference.Deserializer constructor
WolfyScript Oct 13, 2023
34e1f34
Register StackIdentifierParsers inside WolfyUtilCore constructor
WolfyScript Oct 13, 2023
1494a68
Make craftRemain method in CustomItem static
WolfyScript Oct 14, 2023
32233f1
Deprecate PluginIntegration#isAPIReferenceIncluded
WolfyScript Oct 14, 2023
5558251
Add remove/shrink methods from CustomItem to StackReference
WolfyScript Oct 14, 2023
0092d3b
Add CustomItem#convertToReference to convert it to a StackReference
WolfyScript Oct 18, 2023
49f5f45
Add matches and shrink methods to StackIdentifier
WolfyScript Oct 18, 2023
7b1a72f
Add matches methods to StackReference
WolfyScript Oct 18, 2023
06e7796
Add StackReference#of to easily create ItemStack references
WolfyScript Oct 18, 2023
35f47ce
Add disclaimer to StackReference#stack
WolfyScript Oct 18, 2023
bec613d
No longer get parser from StackIdentifier
WolfyScript Oct 18, 2023
affc947
Redirect StackReference#shrink methods to identifier
WolfyScript Oct 18, 2023
4524797
Implement new matches method in Bukkit and WU StackIdentifiers
WolfyScript Oct 18, 2023
246543a
Add RegistryStackIdentifierParsers#parseFrom
WolfyScript Oct 18, 2023
614640a
Add RegistryStackIdentifierParsers#matchingParsers
WolfyScript Oct 19, 2023
c136dc7
Add StackIdentifier#permission to get permissions of stack
WolfyScript Oct 19, 2023
9a93f2b
Allow to swap parser of StackReference
WolfyScript Oct 19, 2023
589ac6e
Add ItemCreateContext to provide context when creating external stacks
WolfyScript Oct 21, 2023
58be02d
Add OraxenStackIdentifier
WolfyScript Oct 21, 2023
c90a0d7
Add MythicMobsStackIdentifier
WolfyScript Oct 21, 2023
b5a2685
Add MMOItemsStackIdentifier
WolfyScript Oct 21, 2023
51b0306
Add MagicStackIdentifier
WolfyScript Oct 21, 2023
574a4f7
Add ItemsAdderStackIdentifier
WolfyScript Oct 21, 2023
9b06e72
Add FancyBagsStackIdentifier
WolfyScript Oct 21, 2023
89e716c
Add ExecutableItemsStackIdentifier
WolfyScript Oct 21, 2023
cfffcc8
Add ExecutableBlocksStackIdentifier
WolfyScript Oct 21, 2023
f5f43ef
Add EcoStackIdentifier
WolfyScript Oct 21, 2023
f0c566a
Update Bukkit & WolfyUtilsStackIdentifiers to the new ItemCreateContext
WolfyScript Oct 21, 2023
e986154
Rename StackIdentifier#item to #stack
WolfyScript Oct 25, 2023
3a71a86
Add display options StackIdentifierParser
WolfyScript Oct 25, 2023
3614626
Add display option for BukkitStackIdentifier
WolfyScript Oct 25, 2023
c37b82d
Add display option for EcoStackIdentifier
WolfyScript Oct 25, 2023
3ce7066
Add display option for ItemsAdderStackIdentifier
WolfyScript Oct 25, 2023
d5c43d9
Add display option for MMOItemsStackIdentifier
WolfyScript Oct 25, 2023
8675f02
Add display option for MythicMobsStackIdentifier
WolfyScript Oct 25, 2023
17ae494
Add display option for OraxenStackIdentifier
WolfyScript Oct 25, 2023
a457add
Add display option for WolfyUtilsStackIdentifier
WolfyScript Oct 25, 2023
1a47570
Use natural ordering in RegistryStackIdentifierParsers#reIndexParsers
WolfyScript Oct 25, 2023
47ec81a
Register all plugin specific StackIdentifiers in their corresponding …
WolfyScript Oct 25, 2023
eb1137b
Add JavaDocs to StackIdentifier & StackReference
WolfyScript Oct 29, 2023
ecb6a3f
Fix reference json property
WolfyScript Oct 29, 2023
927f348
Fix StackReference.Deserializer not detecting new StackReferences
WolfyScript Oct 29, 2023
6c135db
Bump version to 4.16.15-beta.2
WolfyScript Oct 29, 2023
3b71b49
Merge branch 'master' into feature/api-ref-stack-fallback
WolfyScript Oct 29, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ java {
}

group = "com.wolfyscript.wolfyutils.spigot"
version = "4.16.14.1"
version = "4.16.15-beta.2"
val apiVersion = "4.16.1-SNAPSHOT"

dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.wolfyscript.utilities.bukkit.registry;

import com.google.common.base.Preconditions;
import com.wolfyscript.utilities.bukkit.world.items.reference.BukkitStackIdentifier;
import com.wolfyscript.utilities.bukkit.world.items.reference.StackIdentifier;
import com.wolfyscript.utilities.bukkit.world.items.reference.StackIdentifierParser;
import com.wolfyscript.utilities.bukkit.world.items.reference.StackReference;
import me.wolfyscript.utilities.registry.Registries;
import me.wolfyscript.utilities.registry.RegistrySimple;
import me.wolfyscript.utilities.util.NamespacedKey;
import org.bukkit.inventory.ItemStack;

import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

public class RegistryStackIdentifierParsers extends RegistrySimple<StackIdentifierParser<?>> {

private List<StackIdentifierParser<?>> priorityIndexedParsers = List.of();
private final Registries registries;

public RegistryStackIdentifierParsers(Registries registries) {
super(new NamespacedKey(registries.getCore(), "stack_identifier/parsers"), registries, (Class<StackIdentifierParser<?>>)(Object) StackIdentifierParser.class);
this.registries = registries;
}

@Override
public void register(NamespacedKey namespacedKey, StackIdentifierParser<?> value) {
if (value != null) {
Preconditions.checkState(!this.map.containsKey(namespacedKey), "namespaced key '%s' already has an associated value!", namespacedKey);
map.put(namespacedKey, value);
reIndexParsers();
}
}

public List<StackIdentifierParser<?>> sortedParsers() {
return priorityIndexedParsers;
}

public StackIdentifier parseIdentifier(ItemStack stack) {
for (StackIdentifierParser<?> parser : sortedParsers()) {
Optional<? extends StackIdentifier> identifierOptional = parser.from(stack);
if (identifierOptional.isPresent()) return identifierOptional.get();
}
return new BukkitStackIdentifier(stack);
}

public List<StackIdentifierParser<?>> matchingParsers(ItemStack stack) {
return sortedParsers().stream().sorted().filter(stackIdentifierParser -> stackIdentifierParser.from(stack).isPresent()).toList();
}

/**
*
*
* @param stack
* @return
*/
public StackReference parseFrom(ItemStack stack) {
return new StackReference(registries.getCore(), parseIdentifier(stack), 1, 1, stack);
}

private void reIndexParsers() {
priorityIndexedParsers = map.values().stream().sorted(Comparator.naturalOrder()).filter(Objects::nonNull).toList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.wolfyscript.utilities.bukkit.world.items.reference;

import me.wolfyscript.utilities.util.NamespacedKey;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;

import java.util.Optional;

public class BukkitStackIdentifier implements StackIdentifier {

public static final NamespacedKey ID = NamespacedKey.wolfyutilties("bukkit");

private final ItemStack stack;

public BukkitStackIdentifier(ItemStack stack) {
this.stack = stack;
}

@Override
public ItemStack stack(ItemCreateContext context) {
ItemStack cloned = stack.clone();
cloned.setAmount(context.amount());
return cloned;
}

@Override
public boolean matches(ItemStack other, int count, boolean exact, boolean ignoreAmount) {
if (other.getType() != stack.getType()) return false;
if (!ignoreAmount && other.getAmount() < stack.getAmount() * count) return false;
if (!stack.hasItemMeta() && !exact) return false;
return stack.isSimilar(other);
}

@Override
public NamespacedKey getNamespacedKey() {
return ID;
}

public static class Parser implements StackIdentifierParser<BukkitStackIdentifier> {

@Override
public int priority() {
return -2048;
}

@Override
public Optional<BukkitStackIdentifier> from(ItemStack itemStack) {
return Optional.of(new BukkitStackIdentifier(itemStack.clone()));
}

@Override
public NamespacedKey getNamespacedKey() {
return ID;
}

@Override
public DisplayConfiguration displayConfig() {
return new DisplayConfiguration.SimpleDisplayConfig(
Component.text("Bukkit").color(NamedTextColor.WHITE).decorate(TextDecoration.BOLD),
new DisplayConfiguration.MaterialIconSettings(Material.LAVA_BUCKET)
);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package com.wolfyscript.utilities.bukkit.world.items.reference;

import org.bukkit.World;
import org.bukkit.entity.Player;

import java.util.Optional;

public interface ItemCreateContext {

int amount();

default Optional<StackReference> reference() {
return Optional.empty();
}

default Optional<Player> player() {
return Optional.empty();
}

default Optional<World> world() {
return Optional.empty();
}

/**
* An empty implementation only containing the required values.
*
* @return An empty context only containing the required values
*/
static ItemCreateContext empty(int amount) {
return () -> amount;
}

static Builder of(int amount) {
return new Builder.BuilderImpl(amount);
}

static Builder of(StackReference reference) {
return of(reference.amount()).reference(reference);
}

/**
* Builder to construct an ItemCreateContext
*
*/
interface Builder {

Builder reference(StackReference reference);

Builder player(Player player);

Builder world(World world);

ItemCreateContext build();

class BuilderImpl implements Builder {

private final int amount;
private StackReference reference;
private Player player;
private World world;

public BuilderImpl(int amount) {
this.amount = amount;
}

@Override
public Builder reference(StackReference reference) {
this.reference = reference;
return this;
}

@Override
public Builder player(Player player) {
this.player = player;
return this;
}

@Override
public Builder world(World world) {
this.world = world;
return this;
}

@Override
public ItemCreateContext build() {
return new ItemCreateContext() {
@Override
public int amount() {
return amount;
}

@Override
public Optional<StackReference> reference() {
return Optional.ofNullable(reference);
}

@Override
public Optional<Player> player() {
return Optional.ofNullable(player);
}

@Override
public Optional<World> world() {
return Optional.ofNullable(world);
}
};
}
}

}

}
Loading