Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
30cb6f4
Add the first framework for an ItemExpression API
Feb 2, 2019
cb3df58
Add material matching to ItemExpression
Feb 2, 2019
58b4e5a
Redo material parsing
Feb 2, 2019
e0cd367
Add amount matching
Feb 2, 2019
108dc3c
Add intelij files to .gitignore
Feb 2, 2019
2e28aa0
Remove unused function from development
Feb 2, 2019
91b015a
Refactor material parsing again
Feb 2, 2019
e1c485d
Remove unused exports
Feb 2, 2019
e35fd85
Add @author Ameliorate to ItemExpression and related classes
Feb 2, 2019
256be15
Add lore matching
Feb 2, 2019
d5fcc89
Add a getMaterial like all the other matchers
Feb 2, 2019
6bfc0d6
Add the new matchers to ItemExpression.matches()
Feb 2, 2019
a5110a2
Add name matching
Feb 2, 2019
21336db
Fix typo of AnyLore -> AnyName in the gross part of ItemExpression.ma…
Feb 2, 2019
cfd99f6
Add ItemExpression.getItemExpression()
Feb 3, 2019
e5e4133
Make the private parse*() functions in ItemExpression take a path arg…
Feb 3, 2019
0e7223c
Add enchantment matching
Feb 3, 2019
f7b43c8
Add durability matching
Feb 3, 2019
d0b9bbe
Add null checking to enchantment matching
Feb 3, 2019
e103471
Remove minor double empty line
Feb 3, 2019
25e6114
Add matching if an item is unbreakable
Feb 3, 2019
ae8249a
Add negative matching enchantments
Feb 3, 2019
fdf5c96
Fix matches none with no itemmeta
Feb 3, 2019
615780c
Parse enchantmentsNone from config
Feb 3, 2019
2148980
Fix variable name getEnchantmentMatcherNone -> enchantmentMatcherNone
Feb 4, 2019
0195288
Fix getGetEnchantmentNone -> getEnchantmentNone
Feb 5, 2019
41ba002
Add matching EnchantmentStorageMeta
Feb 5, 2019
c352c9f
Fix unbreakable parsing from config
Feb 5, 2019
b9c71e5
Fix all the NPEs and wrong logic
Feb 5, 2019
026bf2c
Make lore regexes just one regex
Feb 5, 2019
80c4d8a
Remove debug println
Feb 5, 2019
9b5d6ed
Fix the whole thing instanceof AnyName stuff
Feb 5, 2019
e1e06cf
Remove the "material: any" and sorts part of the config parser
Feb 5, 2019
e3a5952
Optimize imports
Feb 5, 2019
7f90826
Fix nothing being matched
Feb 6, 2019
168d77b
Add a function to remove an amount of matching items from an inventory
Feb 9, 2019
37aaf67
Use vanilla enchantment keys instead of the bukkit enchantment names
Feb 9, 2019
9b39851
Add basic matching on player heads
Feb 19, 2019
ed0bf5e
Bump version
Feb 24, 2019
fbd9e5a
Add a constructor for ItemExpression to match exactly an ItemStack
Feb 24, 2019
db12a76
Remove minor debug statement
Feb 24, 2019
4f4d397
Refactor ItemExpression to use less boilerplate
Feb 25, 2019
6e42ffb
Add some documentation to stuff I guess
Feb 26, 2019
2e465f0
Fix a NPE in ExactlyLore when creating an exact ItemExpression
Feb 26, 2019
a998749
Fix a class of errors with implementors of ItemMatcher
Feb 26, 2019
36528a3
Add a function to remove from the main hand or off hand
Feb 28, 2019
c4ae41c
Revert changes to pom.xml
Feb 28, 2019
0d96b17
s/amound/amount in ItemExpression config parsing
Feb 28, 2019
dbb1ba9
Add regex player skulls
Feb 28, 2019
538c97a
Add a few forgotten @author tags
Feb 28, 2019
e955865
Fix ItemExactlyEnchantmentsMatcher ignoring held enchantments
Feb 28, 2019
c37a088
Add ItemFlag to the things that can be matched by ItemExpression
Feb 28, 2019
74fed79
Add matching on unbreakable to the config
Feb 28, 2019
7729058
Document private ItemStack.removeFromItemArray(ItemStack[], int)
Feb 28, 2019
9e72d64
Add matching over ItemMaps to ItemExpression
Mar 1, 2019
359dd83
Add a function to parse a List<ItemExpression> from a config
Mar 1, 2019
935349b
Add matching by any enchantment of a specific level
Mar 1, 2019
8a16e3e
Better document getMatchesItemMapPredicate.
Mar 2, 2019
a2c0456
Add matching over item held inventories
Mar 2, 2019
eb12f92
Remove useless null check in RegexLore
Mar 2, 2019
6454e5c
Add matching over a book's metadata
Mar 3, 2019
7858744
Refractor exact ItemExpressions
Mar 3, 2019
a8d11a7
Refactor book generation matching
Mar 3, 2019
fabd4c1
Continue removing unused classes after exactly ItemExpression refactor
Mar 3, 2019
ebdaf15
Remove some code that was only used by exactly ItemExpressions
Mar 5, 2019
873a765
Fix bug in ItemUnbreakableMatcher
Mar 5, 2019
5e40eba
Add matching over the pages of a book
Mar 5, 2019
96c30db
Add matching over the color of a shulkerbox
Mar 5, 2019
856901d
Add matching over knowlege books
Mar 5, 2019
807c2b9
Add matching over the custom effects of a potion
Mar 6, 2019
fc28fe9
Add matching over the base effect of a potion
Mar 6, 2019
504f36d
Add matching over item attributes
Mar 8, 2019
529b512
Add matching over buckets of tropical fish
Mar 9, 2019
e33a8dd
Further abstract parseEnumListMatcher to match any/none as well
Mar 9, 2019
677600f
Refactor the way enums are matched
Mar 10, 2019
1408066
Use EnumMatcher for matching on base potion effects
Mar 10, 2019
928de8b
Add case insensitivity to ExactlyName and RegexName
Mar 11, 2019
e198b76
Add matching over the number of pages in a book
Mar 11, 2019
ed6c569
Add matching over the number of enchantments in an item
Mar 12, 2019
cce2510
Add forgotten @author javadoc in ItemBookPageCountMatcher
Mar 12, 2019
1ecbb91
Add basic color matching support
Mar 13, 2019
4533670
Add another forgotten @author in ItemMapMatcher
Mar 13, 2019
cef1b06
Add matching over the color of leather armour
Mar 13, 2019
36e313c
Add matching over the properties of a map
Mar 13, 2019
6cfd848
Add ItemExpression.addMatcher(Collection<ItemMatcher>)
Mar 13, 2019
9d4ef03
Sort ItemExpression.parseConfig() and add comments
Mar 13, 2019
61b0fb5
Fix multiple ItemMatchers being initalized with null values
Mar 13, 2019
d08517c
Add matching over monster spawners
Mar 13, 2019
d538eed
Add a null check to ItemExpression.addMatcher(Collection<ItemMatcher>)
Mar 13, 2019
6f77cc9
Remove unused import in ExactlyColour
Mar 13, 2019
7deef0c
Greately improve ListMatchingMode
Mar 14, 2019
b027455
Refactor GenericMatcher into a generic class for all matchers
Mar 14, 2019
eed6880
Add matching fireworks
Mar 16, 2019
bf9c70c
Refactor all of config parsing to use Optional instead of null
Mar 16, 2019
3af21dd
Add better defaults for range
Mar 16, 2019
bd9b777
Implement Matcher<ItemStack> for ItemExpression
Mar 16, 2019
0b8bdaa
Add solving
May 19, 2019
e5a548b
Rename some config options
May 19, 2019
029433a
Document a few of the solve methods
May 20, 2019
f82efa4
Replace the MaterialMatcher stuff with EnumMatcher<Material>
May 20, 2019
7fc6963
Add a utility function to parse a map of ItemExpressions from a config
May 20, 2019
21b1dde
Use crc32 instead of md5 in getFireworkEffectWithIndex
May 20, 2019
234c211
Add some commands to debug ItemExpressions
May 22, 2019
7c71ec6
Fix a bunch of bugs
May 25, 2019
79a4824
Improve the TestItemSolving and TestItemMatching commands
May 25, 2019
89ad1ca
Actually reload the config
May 25, 2019
3625d55
Remove shulkerbox.inventory.
Aug 11, 2019
77f4b65
Add a base check to solve that checks if the generated item matches
Aug 12, 2019
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@
.classpath
.project
.settings/**

/.idea/
/*.iml
/*.ipr
/*.iws
18 changes: 0 additions & 18 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<configuration>
<configLocation>https://build.devotedmc.com/job/Style-guide-master/lastSuccessfulBuild/artifact/src/main/resources/devoted_checks.xml</configLocation>
<consoleOutput>true</consoleOutput>
</configuration>
<executions>
<execution>
<id>checkstyle</id>
<goals>
<goal>checkstyle</goal>
</goals>
<phase>prepare-package</phase>
</execution>
</executions>
</plugin>
</plugins>

<resources>
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/vg/civcraft/mc/civmodcore/CivModCorePlugin.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package vg.civcraft.mc.civmodcore;

import vg.civcraft.mc.civmodcore.itemHandling.itemExpression.TestItemSolvingCommand;
import vg.civcraft.mc.civmodcore.itemHandling.itemExpression.TestMatchingCommand;

/**
* The sole purpose of this class is to make Spigot recognize this library as a plugin and automatically load the
* classes onto the classpath for us.
Expand All @@ -15,6 +18,9 @@ public void onEnable() {
super.onEnable();
// needed for some of the apis
instance = this;

getCommand("testitemsolving").setExecutor(new TestItemSolvingCommand());
getCommand("testitemmatching").setExecutor(new TestMatchingCommand());
}

public static CivModCorePlugin getInstance() {
Expand Down
53 changes: 47 additions & 6 deletions src/main/java/vg/civcraft/mc/civmodcore/itemHandling/ItemMap.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package vg.civcraft.mc.civmodcore.itemHandling;

import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.Map.Entry;
import java.util.Set;
import java.util.function.Predicate;
import java.util.logging.Logger;

import com.google.common.collect.Lists;
import net.minecraft.server.v1_13_R2.NBTTagCompound;
import net.minecraft.server.v1_13_R2.NBTTagList;
import org.bukkit.Bukkit;
Expand All @@ -18,6 +16,7 @@
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import vg.civcraft.mc.civmodcore.itemHandling.itemExpression.ItemExpression;

/**
* Allows the storage and comparison of itemstacks while ignoring their maximum possible stack sizes. This offers
Expand Down Expand Up @@ -562,6 +561,48 @@ public boolean removeSafelyFrom(Inventory i) {
return true;
}

/**
* Matches a number of ItemExpression on this ItemMap, trying to match each ItemExpression to a ItemStack 1:1.
*
* This works similar to, but not exactly like ItemMap.getEntries().steam().allMatch().
*
* For example, if this is an ItemMap of a diamond sword and a stack of dirt, passing this function a
* ItemExpression that matches any sword will return true, but passing it a collection of
* ItemExpressions [Matches diamond sword, Matches any sword] will return false, because it can't match each
* ItemExpression to an ItemStack.
* @param itemExpressions The collection of ItemExpression that will match over this ItemMap.
* @return true if all if all of the ItemExpressions matched an item in this ItemMap in a 1:1 fashion, otherwise false.
*/
public boolean itemExpressionsMatchItems(Collection<ItemExpression> itemExpressions) {
// clone so we can remove elements as needed.
ArrayList<ItemExpression> itemExpressions1 = new ArrayList<>(itemExpressions);
ItemMap clone = clone();

// The list is reversed so we can remove the current ItemExpression without shifting over the list.
for (ItemExpression e : Lists.reverse(itemExpressions1)) {
Predicate<Entry<ItemStack, Integer>> iePredicate = e.getMatchesItemMapPredicate(clone);
boolean matched = false;

for (Entry<ItemStack, Integer> entry : clone.getEntrySet()) {
if (iePredicate.test(entry)) {
// Make sure that each ItemExpression can match one ItemStack,
// and that each ItemStack can only be matched by one ItemExpression
clone.removeItemStack(entry.getKey());
itemExpressions1.remove(e);
matched = true;
break;
}
}

if (!matched) {
// slight optimization to return early instead of needing to check every single ItemExpression
return false;
}
}

return itemExpressions1.isEmpty();
}

@Override
public boolean equals(Object o) {
if (o instanceof ItemMap) {
Expand Down
Loading