Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c36c0c247f | ||
|
|
6611a0f82c | ||
|
|
625b981b81 | ||
|
|
d8607917a1 | ||
|
|
30d5f54459 | ||
|
|
a59c05174f | ||
|
|
cf01abcf87 |
@@ -52,6 +52,7 @@ import java.util.stream.Collectors;
|
||||
* <b>IMPORTANT: When reloading a plugin, all runnables / tasks will
|
||||
* be cancelled.</b>
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public abstract class EcoPlugin extends JavaPlugin {
|
||||
/**
|
||||
* The spigot resource ID of the plugin.
|
||||
@@ -464,7 +465,7 @@ public abstract class EcoPlugin extends JavaPlugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* Default code to be executed on plugin reload.
|
||||
* Reload the plugin.
|
||||
*/
|
||||
public final void reload() {
|
||||
this.getConfigHandler().updateConfigs();
|
||||
@@ -476,6 +477,19 @@ public abstract class EcoPlugin extends JavaPlugin {
|
||||
this.handleReload();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload the plugin and return the time taken to reload.
|
||||
*
|
||||
* @return The time.
|
||||
*/
|
||||
public final long reloadWithTime() {
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
this.reload();
|
||||
|
||||
return System.currentTimeMillis() - startTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* The plugin-specific code to be executed on enable.
|
||||
* <p>
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
package com.willfp.eco.core.items;
|
||||
|
||||
import com.willfp.eco.core.items.builder.ItemBuilder;
|
||||
import com.willfp.eco.core.items.builder.ItemStackBuilder;
|
||||
import com.willfp.eco.core.recipe.parts.EmptyTestableItem;
|
||||
import com.willfp.eco.core.recipe.parts.MaterialTestableItem;
|
||||
import com.willfp.eco.core.recipe.parts.ModifiedTestableItem;
|
||||
import com.willfp.eco.core.recipe.parts.TestableStack;
|
||||
import com.willfp.eco.util.NamespacedKeyUtils;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
@@ -36,6 +42,15 @@ public final class Items {
|
||||
REGISTRY.put(key, part);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item.
|
||||
*
|
||||
* @param key The key of the recipe part.
|
||||
*/
|
||||
public void removeCustomItem(@NotNull final NamespacedKey key) {
|
||||
REGISTRY.remove(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup item from string.
|
||||
* <p>
|
||||
@@ -45,14 +60,21 @@ public final class Items {
|
||||
* @return The found testable item, or an empty item if not found.
|
||||
*/
|
||||
public TestableItem lookup(@NotNull final String key) {
|
||||
String[] split = key.toLowerCase().split(":");
|
||||
String[] args = key.split(" ");
|
||||
if (args.length == 0) {
|
||||
return new EmptyTestableItem();
|
||||
}
|
||||
|
||||
TestableItem item = null;
|
||||
|
||||
String[] split = args[0].toLowerCase().split(":");
|
||||
|
||||
if (split.length == 1) {
|
||||
Material material = Material.getMaterial(key.toUpperCase());
|
||||
Material material = Material.getMaterial(args[0].toUpperCase());
|
||||
if (material == null || material == Material.AIR) {
|
||||
return new EmptyTestableItem();
|
||||
}
|
||||
return new MaterialTestableItem(material);
|
||||
item = new MaterialTestableItem(material);
|
||||
}
|
||||
|
||||
if (split.length == 2) {
|
||||
@@ -63,18 +85,66 @@ public final class Items {
|
||||
if (material == null || material == Material.AIR) {
|
||||
return new EmptyTestableItem();
|
||||
}
|
||||
return new TestableStack(new MaterialTestableItem(material), Integer.parseInt(split[1]));
|
||||
item = new TestableStack(new MaterialTestableItem(material), Integer.parseInt(split[1]));
|
||||
} else {
|
||||
return part;
|
||||
item = part;
|
||||
}
|
||||
}
|
||||
|
||||
if (split.length == 3) {
|
||||
CustomItem part = REGISTRY.get(NamespacedKeyUtils.create(split[0], split[1]));
|
||||
return part == null ? new EmptyTestableItem() : new TestableStack(part, Integer.parseInt(split[2]));
|
||||
item = part == null ? new EmptyTestableItem() : new TestableStack(part, Integer.parseInt(split[2]));
|
||||
}
|
||||
|
||||
return new EmptyTestableItem();
|
||||
if (item == null || item instanceof EmptyTestableItem) {
|
||||
return new EmptyTestableItem();
|
||||
}
|
||||
|
||||
String[] enchantArgs = Arrays.copyOfRange(args, 1, args.length);
|
||||
|
||||
Map<Enchantment, Integer> requiredEnchantments = new HashMap<>();
|
||||
|
||||
for (String enchantArg : enchantArgs) {
|
||||
String[] enchantArgSplit = enchantArg.split(":");
|
||||
|
||||
Enchantment enchantment = Enchantment.getByKey(NamespacedKey.minecraft(enchantArgSplit[0].toLowerCase()));
|
||||
int level = Integer.parseInt(enchantArgSplit[1]);
|
||||
|
||||
requiredEnchantments.put(enchantment, level);
|
||||
}
|
||||
|
||||
if (requiredEnchantments.isEmpty()) {
|
||||
return item;
|
||||
}
|
||||
|
||||
ItemBuilder builder = new ItemStackBuilder(item.getItem());
|
||||
requiredEnchantments.forEach(builder::addEnchantment);
|
||||
ItemStack example = builder.build();
|
||||
|
||||
return new ModifiedTestableItem(
|
||||
item,
|
||||
itemStack -> {
|
||||
if (!itemStack.hasItemMeta()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
|
||||
assert meta != null;
|
||||
|
||||
for (Map.Entry<Enchantment, Integer> entry : requiredEnchantments.entrySet()) {
|
||||
if (!meta.hasEnchant(entry.getKey())) {
|
||||
return false;
|
||||
}
|
||||
if (meta.getEnchantLevel(entry.getKey()) < entry.getValue()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
example
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.willfp.eco.core.recipe.parts;
|
||||
|
||||
import com.willfp.eco.core.items.TestableItem;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* Existing testable items with an extra filter.
|
||||
*
|
||||
* @see com.willfp.eco.core.items.CustomItem
|
||||
*/
|
||||
public class ModifiedTestableItem implements TestableItem {
|
||||
/**
|
||||
* The item.
|
||||
*/
|
||||
private final TestableItem handle;
|
||||
|
||||
/**
|
||||
* The amount.
|
||||
*/
|
||||
@Getter
|
||||
private final Predicate<ItemStack> test;
|
||||
|
||||
/**
|
||||
* The item for the modified test.
|
||||
*/
|
||||
private final ItemStack example;
|
||||
|
||||
/**
|
||||
* Create a new modified testable item.
|
||||
*
|
||||
* @param item The item.
|
||||
* @param test The test.
|
||||
* @param example The example.
|
||||
*/
|
||||
public ModifiedTestableItem(@NotNull final TestableItem item,
|
||||
@NotNull final Predicate<ItemStack> test,
|
||||
@NotNull final ItemStack example) {
|
||||
this.handle = item;
|
||||
this.test = test;
|
||||
this.example = example;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the item matches the material.
|
||||
*
|
||||
* @param itemStack The item to test.
|
||||
* @return If the item is of the specified material.
|
||||
*/
|
||||
@Override
|
||||
public boolean matches(@Nullable final ItemStack itemStack) {
|
||||
return itemStack != null && handle.matches(itemStack) && test.test(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem() {
|
||||
return example;
|
||||
}
|
||||
}
|
||||
@@ -112,6 +112,10 @@ public class BlockUtils {
|
||||
Validate.isTrue(initialized, "Must be initialized!");
|
||||
Validate.notNull(blockBreakConsumer, "Must be initialized!");
|
||||
|
||||
if (block.getLocation().getY() < 0 || block.getLocation().getY() > 256) {
|
||||
return;
|
||||
}
|
||||
|
||||
blockBreakConsumer.accept(player, block);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.willfp.eco.internal;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.items.CustomItem;
|
||||
import com.willfp.eco.core.items.Items;
|
||||
import com.willfp.eco.core.proxy.Cleaner;
|
||||
import com.willfp.eco.internal.proxy.EcoProxyFactory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -18,6 +20,12 @@ public class EcoCleaner implements Cleaner {
|
||||
|
||||
Plugins.LOADED_ECO_PLUGINS.remove(plugin.getName().toLowerCase());
|
||||
|
||||
for (CustomItem customItem : Items.getCustomItems()) {
|
||||
if (customItem.getKey().getNamespace().equalsIgnoreCase(plugin.getName().toLowerCase())) {
|
||||
Items.removeCustomItem(customItem.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
if (plugin.getClass().getClassLoader() instanceof URLClassLoader urlClassLoader) {
|
||||
try {
|
||||
urlClassLoader.close();
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
version = 6.0.6
|
||||
version = 6.1.0
|
||||
plugin-name = eco
|
||||
Reference in New Issue
Block a user