Repackage and rename for clarity

This commit is contained in:
Jikoo committed 2021-11-27 13:56:31 -05:00
1 parent 18c3dbaee0
commit 5f1a613b48
16 files changed
+63 -47

No files matched your search

@@ -22,12 +22,12 @@ import com.lishid.openinv.commands.search.ChunkSearchOption;
import com.lishid.openinv.commands.search.CompletableOption;
import com.lishid.openinv.commands.search.PlayerSearchOption;
import com.lishid.openinv.commands.search.PseudoOption;
import com.lishid.openinv.search.ItemMatcher;
import com.lishid.openinv.search.MatchMetaOption;
import com.lishid.openinv.search.MatchOption;
import com.lishid.openinv.search.MatchOptions;
import com.lishid.openinv.search.match.ItemMatcher;
import com.lishid.openinv.search.match.MatchableMeta;
import com.lishid.openinv.search.match.MatchableItem;
import com.lishid.openinv.search.match.ItemMatchables;
import com.lishid.openinv.search.Search;
import com.lishid.openinv.search.SearchBucket;
import com.lishid.openinv.search.bucket.SearchBucket;
import com.lishid.openinv.util.PseudoJson;
import java.util.ArrayList;
import java.util.Collection;
@@ -52,8 +52,8 @@ public class SearchCommand implements TabExecutor {
private final Collection<String> activeSearches = Collections.newSetFromMap(new ConcurrentHashMap<>());
private final Collection<CompletableOption<? extends SearchBucket>> completableSearchBuckets = new HashSet<>();
private final Collection<CompletableOption<MatchOption>> completableMatchOptions = new HashSet<>();
private final Collection<CompletableOption<MatchMetaOption>> completableMatchMetaOptions = new HashSet<>();
private final Collection<CompletableOption<MatchableItem>> completableMatchOptions = new HashSet<>();
private final Collection<CompletableOption<MatchableMeta>> completableMatchMetaOptions = new HashSet<>();
public SearchCommand(OpenInv plugin) {
this.plugin = plugin;
@@ -107,7 +107,7 @@ public class SearchCommand implements TabExecutor {
}
private @Nullable ItemMatcher getMatcher(Collection<PseudoJson> args) {
List<MatchMetaOption> matchMetaOptions = new ArrayList<>();
List<MatchableMeta> matchMetaOptions = new ArrayList<>();
Material type = null;
Integer minAmount = null;
@@ -159,25 +159,25 @@ public class SearchCommand implements TabExecutor {
}
}
matchMetaOptions.add(MatchOptions.hasEnchant(enchantment, enchantLevel));
matchMetaOptions.add(ItemMatchables.hasEnchant(enchantment, enchantLevel));
}
}
List<MatchOption> matchOptions = new ArrayList<>();
List<MatchableItem> matchableItems = new ArrayList<>();
if (type != null) {
matchOptions.add(MatchOptions.isType(type));
matchableItems.add(ItemMatchables.isType(type));
}
if (minAmount != null) {
matchOptions.add(MatchOptions.hasAmount(minAmount));
matchableItems.add(ItemMatchables.hasAmount(minAmount));
}
if (matchOptions.isEmpty()) {
if (matchableItems.isEmpty()) {
return null;
}
return new ItemMatcher(matchOptions, matchMetaOptions);
return new ItemMatcher(matchableItems, matchMetaOptions);
}
private Collection<SearchBucket> getSearchBuckets(CommandSender sender, Collection<PseudoJson> args) {
@@ -16,7 +16,7 @@
package com.lishid.openinv.commands.search;
import com.lishid.openinv.search.ChunkBucket;
import com.lishid.openinv.search.bucket.ChunkBucket;
import com.lishid.openinv.util.Permissions;
import com.lishid.openinv.util.PseudoJson;
import java.util.Collection;
@@ -17,7 +17,7 @@
package com.lishid.openinv.commands.search;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.search.PlayerBucket;
import com.lishid.openinv.search.bucket.PlayerBucket;
import com.lishid.openinv.util.Permissions;
import com.lishid.openinv.util.PseudoJson;
import java.util.Collection;
@@ -17,6 +17,10 @@
package com.lishid.openinv.search;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.search.bucket.SearchBucket;
import com.lishid.openinv.search.match.ItemMatcher;
import com.lishid.openinv.search.match.MatchResult;
import com.lishid.openinv.search.match.Matchable;
import com.lishid.openinv.util.MessagePart;
import java.text.DecimalFormat;
import java.util.ArrayList;
@@ -14,9 +14,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.search;
package com.lishid.openinv.search.bucket;
import com.github.jikoo.planarwrappers.tuple.Pair;
import com.lishid.openinv.search.match.MatchResult;
import com.lishid.openinv.search.match.Matchable;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@@ -14,8 +14,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.search;
package com.lishid.openinv.search.bucket;
import com.lishid.openinv.search.match.ItemMatcher;
import com.lishid.openinv.search.match.MatchResult;
import com.lishid.openinv.search.match.Matchable;
import com.lishid.openinv.util.MessagePart;
import java.util.ArrayList;
import java.util.List;
@@ -57,7 +60,7 @@ class MatchableChunk implements Matchable {
}
@Override
public @NotNull MatchResult match(ItemMatcher matcher) {
public @NotNull MatchResult match(@NotNull ItemMatcher matcher) {
List<BlockState> blocks = new ArrayList<>();
for (BlockState tileEntity : getChunk().getTileEntities()) {
@@ -14,9 +14,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.search;
package com.lishid.openinv.search.bucket;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.search.match.ItemMatcher;
import com.lishid.openinv.search.match.MatchResult;
import com.lishid.openinv.search.match.Matchable;
import com.lishid.openinv.util.MessagePart;
import java.util.UUID;
import java.util.function.Supplier;
@@ -44,7 +47,7 @@ public class MatchablePlayer implements Matchable {
}
@Override
public @NotNull MatchResult match(ItemMatcher matcher) {
public @NotNull MatchResult match(@NotNull ItemMatcher matcher) {
Player player;
if (offlinePlayer instanceof Player) {
@@ -14,9 +14,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.search;
package com.lishid.openinv.search.bucket;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.search.match.Matchable;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
@@ -14,8 +14,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.search;
package com.lishid.openinv.search.bucket;
import com.lishid.openinv.search.match.Matchable;
import org.jetbrains.annotations.NotNull;
public interface SearchBucket {
@@ -14,24 +14,24 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.search;
package com.lishid.openinv.search.match;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class MatchOptions {
public class ItemMatchables {
public static MatchOption isType(@NotNull Material material) {
public static MatchableItem isType(@NotNull Material material) {
return itemStack -> itemStack.getType() == material;
}
public static MatchOption hasAmount(int minAmount) {
public static MatchableItem hasAmount(int minAmount) {
return itemStack -> itemStack.getAmount() >= minAmount;
}
public static MatchMetaOption hasEnchant(@Nullable Enchantment enchantment, @Nullable Integer minLevel) {
public static MatchableMeta hasEnchant(@Nullable Enchantment enchantment, @Nullable Integer minLevel) {
return itemMeta -> {
if (minLevel == null) {
if (enchantment == null) {
@@ -59,6 +59,6 @@ public class MatchOptions {
};
}
private MatchOptions() {}
private ItemMatchables() {}
}
@@ -14,7 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.search;
package com.lishid.openinv.search.match;
import java.util.Collection;
import java.util.HashSet;
@@ -28,12 +28,12 @@ import org.jetbrains.annotations.Nullable;
*/
public class ItemMatcher {
private final Collection<MatchOption> baseOptions;
private final Collection<MatchMetaOption> metaOptions;
private final Collection<MatchableItem> baseOptions;
private final Collection<MatchableMeta> metaOptions;
public ItemMatcher(
Collection<MatchOption> baseOptions,
Collection<MatchMetaOption> metaOptions) {
Collection<MatchableItem> baseOptions,
Collection<MatchableMeta> metaOptions) {
this.baseOptions = new HashSet<>(baseOptions);
this.metaOptions = new HashSet<>(metaOptions);
}
@@ -45,7 +45,7 @@ public class ItemMatcher {
}
// Match options against base item.
for (MatchOption baseOption : baseOptions) {
for (MatchableItem baseOption : baseOptions) {
if (!baseOption.matches(other)) {
return false;
}
@@ -63,7 +63,7 @@ public class ItemMatcher {
}
// Match meta-based options.
for (MatchMetaOption metaOption : metaOptions) {
for (MatchableMeta metaOption : metaOptions) {
if (!metaOption.matches(meta)) {
return false;
}
@@ -14,7 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.search;
package com.lishid.openinv.search.match;
import com.lishid.openinv.util.MessagePart;
import org.jetbrains.annotations.NotNull;
@@ -14,7 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.search;
package com.lishid.openinv.search.match;
import org.jetbrains.annotations.NotNull;
@@ -22,6 +22,6 @@ public interface Matchable {
Matchable EMPTY = matcher -> MatchResult.NO_MATCH;
@NotNull MatchResult match(ItemMatcher matcher);
@NotNull MatchResult match(@NotNull ItemMatcher matcher);
}
@@ -14,12 +14,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.search;
package com.lishid.openinv.search.match;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public interface MatchOption {
public interface MatchableItem {
boolean matches(ItemStack itemStack);
boolean matches(@NotNull ItemStack itemStack);
}
@@ -14,12 +14,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.search;
package com.lishid.openinv.search.match;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
public interface MatchMetaOption {
public interface MatchableMeta {
boolean matches(ItemMeta itemMeta);
boolean matches(@NotNull ItemMeta itemMeta);
}
@@ -30,8 +30,8 @@ import org.jetbrains.annotations.NotNull;
*
* <p>Ex: A ChunkBucket can be expressed <code>chunks{world:world_name,x:0,z:0,radius:10,load:true}</code>. The
* starting "chunks" identifies it as a ChunkBucket and the content in braces contains the construction detail.
* However, a simpler detail, such as a MatchOption, may be specified <code>type:IRON_SWORD</code> where "type"
* is both the identifier of the MatchOption and the key of the sole value.
* However, a simpler detail, such as a MatchableItem, may be specified <code>type:IRON_SWORD</code> where "type"
* is both the identifier of the MatchableItem and the key of the sole value.
*
* <p>A best-effort will be made to match other start and finish demarcation techniques.
*/