Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
310485402f | ||
|
|
727dc25083 | ||
|
|
364f36d502 | ||
|
|
b6086bc4bd | ||
|
|
dd3beaa548 | ||
|
|
c36c0c247f | ||
|
|
6611a0f82c | ||
|
|
625b981b81 | ||
|
|
d8607917a1 | ||
|
|
30d5f54459 | ||
|
|
a59c05174f | ||
|
|
cf01abcf87 | ||
|
|
70a4a06d4f | ||
|
|
bbee18fd8a | ||
|
|
26ab9a327d | ||
|
|
0676f5fa33 | ||
|
|
051b95ad88 | ||
|
|
d786014cbc | ||
|
|
b62bb48bb6 | ||
|
|
b238a10209 | ||
|
|
251049f1f1 | ||
|
|
16d146dba0 |
@@ -52,6 +52,7 @@ import java.util.stream.Collectors;
|
|||||||
* <b>IMPORTANT: When reloading a plugin, all runnables / tasks will
|
* <b>IMPORTANT: When reloading a plugin, all runnables / tasks will
|
||||||
* be cancelled.</b>
|
* be cancelled.</b>
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public abstract class EcoPlugin extends JavaPlugin {
|
public abstract class EcoPlugin extends JavaPlugin {
|
||||||
/**
|
/**
|
||||||
* The spigot resource ID of the plugin.
|
* 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() {
|
public final void reload() {
|
||||||
this.getConfigHandler().updateConfigs();
|
this.getConfigHandler().updateConfigs();
|
||||||
@@ -476,6 +477,19 @@ public abstract class EcoPlugin extends JavaPlugin {
|
|||||||
this.handleReload();
|
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.
|
* The plugin-specific code to be executed on enable.
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@@ -42,10 +42,24 @@ public interface CommandBase {
|
|||||||
*/
|
*/
|
||||||
CommandHandler getHandler();
|
CommandHandler getHandler();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the handler.
|
||||||
|
*
|
||||||
|
* @param handler The handler.
|
||||||
|
*/
|
||||||
|
void setHandler(@NotNull CommandHandler handler);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the tab completer.
|
* Get the tab completer.
|
||||||
*
|
*
|
||||||
* @return The tab completer.
|
* @return The tab completer.
|
||||||
*/
|
*/
|
||||||
TabCompleteHandler getTabCompleter();
|
TabCompleteHandler getTabCompleter();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the tab completer.
|
||||||
|
*
|
||||||
|
* @param handler The handler.
|
||||||
|
*/
|
||||||
|
void setTabCompleter(@NotNull TabCompleteHandler handler);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import com.willfp.eco.core.command.CommandHandler;
|
|||||||
import com.willfp.eco.core.command.TabCompleteHandler;
|
import com.willfp.eco.core.command.TabCompleteHandler;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.StringUtil;
|
import org.bukkit.util.StringUtil;
|
||||||
@@ -48,6 +49,20 @@ abstract class HandledCommand extends PluginDependent<EcoPlugin> implements Comm
|
|||||||
@Getter
|
@Getter
|
||||||
private final boolean playersOnly;
|
private final boolean playersOnly;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The actual code to be executed in the command.
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private CommandHandler handler = (sender, args) -> { };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The tab completion code to be executed in the command.
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private TabCompleteHandler tabCompleter = (sender, args) -> new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All subcommands for the command.
|
* All subcommands for the command.
|
||||||
*/
|
*/
|
||||||
@@ -164,14 +179,6 @@ abstract class HandledCommand extends PluginDependent<EcoPlugin> implements Comm
|
|||||||
return this.getTabCompleter().tabComplete(sender, Arrays.asList(args));
|
return this.getTabCompleter().tabComplete(sender, Arrays.asList(args));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public abstract CommandHandler getHandler();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TabCompleteHandler getTabCompleter() {
|
|
||||||
return (sender, args) -> new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If a sender can execute the command.
|
* If a sender can execute the command.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -29,6 +29,27 @@ public interface JSONConfig extends Config {
|
|||||||
@Nullable
|
@Nullable
|
||||||
List<JSONConfig> getSubsectionsOrNull(@NotNull String path);
|
List<JSONConfig> getSubsectionsOrNull(@NotNull String path);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get subsection from config.
|
||||||
|
*
|
||||||
|
* @param path The key to check.
|
||||||
|
* @return The subsection. Throws NPE if not found.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
JSONConfig getSubsection(@NotNull String path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get subsection from config.
|
||||||
|
*
|
||||||
|
* @param path The key to check.
|
||||||
|
* @return The subsection, or null if not found.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
JSONConfig getSubsectionOrNull(@NotNull String path);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
JSONConfig clone();
|
JSONConfig clone();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,16 @@ public abstract class JSONConfigWrapper extends ConfigWrapper<JSONConfig> implem
|
|||||||
return this.getHandle().getSubsectionsOrNull(path);
|
return this.getHandle().getSubsectionsOrNull(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull JSONConfig getSubsection(@NotNull final String path) {
|
||||||
|
return this.getHandle().getSubsection(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable JSONConfig getSubsectionOrNull(@NotNull final String path) {
|
||||||
|
return this.getHandle().getSubsectionOrNull(path);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONConfig clone() {
|
public JSONConfig clone() {
|
||||||
return this.getHandle().clone();
|
return this.getHandle().clone();
|
||||||
|
|||||||
@@ -3,12 +3,14 @@ package com.willfp.eco.core.display;
|
|||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.persistence.PersistentDataContainer;
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -57,6 +59,18 @@ public class Display {
|
|||||||
* @return The ItemStack.
|
* @return The ItemStack.
|
||||||
*/
|
*/
|
||||||
public ItemStack display(@NotNull final ItemStack itemStack) {
|
public ItemStack display(@NotNull final ItemStack itemStack) {
|
||||||
|
return display(itemStack, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display on ItemStacks.
|
||||||
|
*
|
||||||
|
* @param itemStack The item.
|
||||||
|
* @param player The player.
|
||||||
|
* @return The ItemStack.
|
||||||
|
*/
|
||||||
|
public ItemStack display(@NotNull final ItemStack itemStack,
|
||||||
|
@Nullable final Player player) {
|
||||||
if (!itemStack.hasItemMeta()) {
|
if (!itemStack.hasItemMeta()) {
|
||||||
return itemStack; // return early if there's no customization of the item
|
return itemStack; // return early if there's no customization of the item
|
||||||
}
|
}
|
||||||
@@ -83,6 +97,9 @@ public class Display {
|
|||||||
for (DisplayModule module : modules) {
|
for (DisplayModule module : modules) {
|
||||||
Object[] varargs = pluginVarArgs.get(module.getPluginName());
|
Object[] varargs = pluginVarArgs.get(module.getPluginName());
|
||||||
module.display(itemStack, varargs);
|
module.display(itemStack, varargs);
|
||||||
|
if (player != null) {
|
||||||
|
module.display(itemStack, player, varargs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +113,19 @@ public class Display {
|
|||||||
* @return The ItemStack.
|
* @return The ItemStack.
|
||||||
*/
|
*/
|
||||||
public ItemStack displayAndFinalize(@NotNull final ItemStack itemStack) {
|
public ItemStack displayAndFinalize(@NotNull final ItemStack itemStack) {
|
||||||
return finalize(display(itemStack));
|
return finalize(display(itemStack, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display on ItemStacks and then finalize.
|
||||||
|
*
|
||||||
|
* @param itemStack The item.
|
||||||
|
* @param player The player.
|
||||||
|
* @return The ItemStack.
|
||||||
|
*/
|
||||||
|
public ItemStack displayAndFinalize(@NotNull final ItemStack itemStack,
|
||||||
|
@Nullable final Player player) {
|
||||||
|
return finalize(display(itemStack, player));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.willfp.eco.core.display;
|
|||||||
import com.willfp.eco.core.EcoPlugin;
|
import com.willfp.eco.core.EcoPlugin;
|
||||||
import com.willfp.eco.core.PluginDependent;
|
import com.willfp.eco.core.PluginDependent;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@@ -39,6 +40,19 @@ public abstract class DisplayModule extends PluginDependent<EcoPlugin> {
|
|||||||
// Technically optional.
|
// Technically optional.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display an item.
|
||||||
|
*
|
||||||
|
* @param itemStack The item.
|
||||||
|
* @param player The player.
|
||||||
|
* @param args Optional args for display.
|
||||||
|
*/
|
||||||
|
protected void display(@NotNull final ItemStack itemStack,
|
||||||
|
@NotNull final Player player,
|
||||||
|
@NotNull final Object... args) {
|
||||||
|
// Technically optional.
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Revert an item.
|
* Revert an item.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package com.willfp.eco.core.events;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.bukkit.event.player.PlayerEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The armor change event <b>does</> contain information about the event.</b>
|
||||||
|
* <p>
|
||||||
|
* Unlike {@link ArmorEquipEvent}, it is called the next tick and contains previous and current armor contents.
|
||||||
|
*/
|
||||||
|
public class ArmorChangeEvent extends PlayerEvent {
|
||||||
|
/**
|
||||||
|
* Bukkit parity.
|
||||||
|
*/
|
||||||
|
private static final HandlerList HANDLERS = new HandlerList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The armor contents before. 0 is helmet, 3 is boots.
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
private final List<ItemStack> before;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The armor contents after. 0 is helmet, 3 is boots.
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
private final List<ItemStack> after;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new ArmorChangeEvent.
|
||||||
|
*
|
||||||
|
* @param player The player.
|
||||||
|
* @param before The armor contents before.
|
||||||
|
* @param after The armor contents after.
|
||||||
|
*/
|
||||||
|
public ArmorChangeEvent(@NotNull final Player player,
|
||||||
|
@NotNull final List<ItemStack> before,
|
||||||
|
@NotNull final List<ItemStack> after) {
|
||||||
|
super(player);
|
||||||
|
this.before = before;
|
||||||
|
this.after = after;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a list of handlers handling this event.
|
||||||
|
*
|
||||||
|
* @return A list of handlers handling this event.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bukkit parity.
|
||||||
|
*
|
||||||
|
* @return The handler list.
|
||||||
|
*/
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,9 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
* so you can check a tick later to see the new contents.
|
* so you can check a tick later to see the new contents.
|
||||||
*/
|
*/
|
||||||
public class ArmorEquipEvent extends PlayerEvent {
|
public class ArmorEquipEvent extends PlayerEvent {
|
||||||
|
/**
|
||||||
|
* Bukkit parity.
|
||||||
|
*/
|
||||||
private static final HandlerList HANDLERS = new HandlerList();
|
private static final HandlerList HANDLERS = new HandlerList();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,15 +1,21 @@
|
|||||||
package com.willfp.eco.core.items;
|
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.EmptyTestableItem;
|
||||||
import com.willfp.eco.core.recipe.parts.MaterialTestableItem;
|
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.core.recipe.parts.TestableStack;
|
||||||
import com.willfp.eco.util.NamespacedKeyUtils;
|
import com.willfp.eco.util.NamespacedKeyUtils;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -36,6 +42,15 @@ public final class Items {
|
|||||||
REGISTRY.put(key, part);
|
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.
|
* Lookup item from string.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -45,14 +60,21 @@ public final class Items {
|
|||||||
* @return The found testable item, or an empty item if not found.
|
* @return The found testable item, or an empty item if not found.
|
||||||
*/
|
*/
|
||||||
public TestableItem lookup(@NotNull final String key) {
|
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) {
|
if (split.length == 1) {
|
||||||
Material material = Material.getMaterial(key.toUpperCase());
|
Material material = Material.getMaterial(args[0].toUpperCase());
|
||||||
if (material == null || material == Material.AIR) {
|
if (material == null || material == Material.AIR) {
|
||||||
return new EmptyTestableItem();
|
return new EmptyTestableItem();
|
||||||
}
|
}
|
||||||
return new MaterialTestableItem(material);
|
item = new MaterialTestableItem(material);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (split.length == 2) {
|
if (split.length == 2) {
|
||||||
@@ -63,18 +85,66 @@ public final class Items {
|
|||||||
if (material == null || material == Material.AIR) {
|
if (material == null || material == Material.AIR) {
|
||||||
return new EmptyTestableItem();
|
return new EmptyTestableItem();
|
||||||
}
|
}
|
||||||
return new TestableStack(new MaterialTestableItem(material), Integer.parseInt(split[1]));
|
item = new TestableStack(new MaterialTestableItem(material), Integer.parseInt(split[1]));
|
||||||
} else {
|
} else {
|
||||||
return part;
|
item = part;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (split.length == 3) {
|
if (split.length == 3) {
|
||||||
CustomItem part = REGISTRY.get(NamespacedKeyUtils.create(split[0], split[1]));
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,10 +29,10 @@ public class ArrowUtils {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(values.get(0) instanceof ItemStack)) {
|
if (!(values.get(0).value() instanceof ItemStack)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (ItemStack) values.get(0);
|
return (ItemStack) values.get(0).value();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ package com.willfp.eco.util;
|
|||||||
import com.willfp.eco.core.tuples.Pair;
|
import com.willfp.eco.core.tuples.Pair;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -112,6 +114,14 @@ public class BlockUtils {
|
|||||||
Validate.isTrue(initialized, "Must be initialized!");
|
Validate.isTrue(initialized, "Must be initialized!");
|
||||||
Validate.notNull(blockBreakConsumer, "Must be initialized!");
|
Validate.notNull(blockBreakConsumer, "Must be initialized!");
|
||||||
|
|
||||||
|
Location location = block.getLocation();
|
||||||
|
World world = location.getWorld();
|
||||||
|
assert world != null;
|
||||||
|
|
||||||
|
if (location.getY() < world.getMinHeight() || location.getY() > world.getMaxHeight()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
blockBreakConsumer.accept(player, block);
|
blockBreakConsumer.accept(player, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.willfp.eco.internal;
|
package com.willfp.eco.internal;
|
||||||
|
|
||||||
import com.willfp.eco.core.EcoPlugin;
|
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.core.proxy.Cleaner;
|
||||||
import com.willfp.eco.internal.proxy.EcoProxyFactory;
|
import com.willfp.eco.internal.proxy.EcoProxyFactory;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -18,6 +20,12 @@ public class EcoCleaner implements Cleaner {
|
|||||||
|
|
||||||
Plugins.LOADED_ECO_PLUGINS.remove(plugin.getName().toLowerCase());
|
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) {
|
if (plugin.getClass().getClassLoader() instanceof URLClassLoader urlClassLoader) {
|
||||||
try {
|
try {
|
||||||
urlClassLoader.close();
|
urlClassLoader.close();
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package com.willfp.eco.internal.config.json;
|
|||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.willfp.eco.core.config.interfaces.Config;
|
|
||||||
import com.willfp.eco.core.config.interfaces.JSONConfig;
|
import com.willfp.eco.core.config.interfaces.JSONConfig;
|
||||||
import com.willfp.eco.util.StringUtils;
|
import com.willfp.eco.util.StringUtils;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -150,15 +149,15 @@ public class EcoJSONConfigWrapper implements JSONConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public Config getSubsection(@NotNull final String path) {
|
public JSONConfig getSubsection(@NotNull final String path) {
|
||||||
Config subsection = getSubsectionOrNull(path);
|
JSONConfig subsection = getSubsectionOrNull(path);
|
||||||
Validate.notNull(subsection);
|
Validate.notNull(subsection);
|
||||||
return subsection;
|
return subsection;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public Config getSubsectionOrNull(@NotNull final String path) {
|
public JSONConfig getSubsectionOrNull(@NotNull final String path) {
|
||||||
if (values.containsKey(path)) {
|
if (values.containsKey(path)) {
|
||||||
Map<String, Object> subsection = (Map<String, Object>) values.get(path);
|
Map<String, Object> subsection = (Map<String, Object>) values.get(path);
|
||||||
return new EcoJSONConfigSection(subsection);
|
return new EcoJSONConfigSection(subsection);
|
||||||
@@ -171,8 +170,7 @@ public class EcoJSONConfigWrapper implements JSONConfig {
|
|||||||
@NotNull
|
@NotNull
|
||||||
public List<JSONConfig> getSubsections(@NotNull final String path) {
|
public List<JSONConfig> getSubsections(@NotNull final String path) {
|
||||||
List<JSONConfig> subsections = getSubsectionsOrNull(path);
|
List<JSONConfig> subsections = getSubsectionsOrNull(path);
|
||||||
Validate.notNull(subsections);
|
return subsections == null ? new ArrayList<>() : subsections;
|
||||||
return subsections;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -63,6 +63,14 @@ public class EcoLoadableJSONConfig extends EcoJSONConfigWrapper implements Loada
|
|||||||
plugin.getConfigHandler().addConfig(this);
|
plugin.getConfigHandler().addConfig(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void reloadFromFile() {
|
||||||
|
try {
|
||||||
|
init(this.configFile);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createFile() {
|
public void createFile() {
|
||||||
String resourcePath = getResourcePath();
|
String resourcePath = getResourcePath();
|
||||||
@@ -108,8 +116,9 @@ public class EcoLoadableJSONConfig extends EcoJSONConfigWrapper implements Loada
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save() throws IOException {
|
public void save() throws IOException {
|
||||||
configFile.delete();
|
if (configFile.delete()) {
|
||||||
Files.write(configFile.toPath(), this.toPlaintext().getBytes(), StandardOpenOption.CREATE, StandardOpenOption.WRITE);
|
Files.write(configFile.toPath(), this.toPlaintext().getBytes(), StandardOpenOption.CREATE, StandardOpenOption.WRITE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ import com.willfp.eco.core.PluginDependent;
|
|||||||
import com.willfp.eco.core.config.interfaces.LoadableConfig;
|
import com.willfp.eco.core.config.interfaces.LoadableConfig;
|
||||||
import com.willfp.eco.core.config.updating.ConfigHandler;
|
import com.willfp.eco.core.config.updating.ConfigHandler;
|
||||||
import com.willfp.eco.core.config.updating.ConfigUpdater;
|
import com.willfp.eco.core.config.updating.ConfigUpdater;
|
||||||
|
import com.willfp.eco.internal.config.json.EcoLoadableJSONConfig;
|
||||||
import com.willfp.eco.internal.config.updating.exceptions.InvalidUpdateMethodException;
|
import com.willfp.eco.internal.config.updating.exceptions.InvalidUpdateMethodException;
|
||||||
|
import com.willfp.eco.internal.config.yaml.EcoLoadableYamlConfig;
|
||||||
import com.willfp.eco.internal.config.yaml.EcoUpdatableYamlConfig;
|
import com.willfp.eco.internal.config.yaml.EcoUpdatableYamlConfig;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.reflections.Reflections;
|
import org.reflections.Reflections;
|
||||||
@@ -76,6 +78,12 @@ public class EcoConfigHandler extends PluginDependent<EcoPlugin> implements Conf
|
|||||||
if (config instanceof EcoUpdatableYamlConfig updatableYamlConfig) {
|
if (config instanceof EcoUpdatableYamlConfig updatableYamlConfig) {
|
||||||
updatableYamlConfig.update();
|
updatableYamlConfig.update();
|
||||||
}
|
}
|
||||||
|
if (config instanceof EcoLoadableYamlConfig ecoLoadableYamlConfig) {
|
||||||
|
ecoLoadableYamlConfig.reloadFromFile();
|
||||||
|
}
|
||||||
|
if (config instanceof EcoLoadableJSONConfig ecoLoadableJSONConfig) {
|
||||||
|
ecoLoadableJSONConfig.reloadFromFile();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.willfp.eco.core.config.interfaces.LoadableConfig;
|
|||||||
import com.willfp.eco.core.config.interfaces.WrappedYamlConfiguration;
|
import com.willfp.eco.core.config.interfaces.WrappedYamlConfiguration;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@@ -49,9 +50,19 @@ public class EcoLoadableYamlConfig extends EcoYamlConfigWrapper<YamlConfiguratio
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.configFile = new File(directory, this.name);
|
this.configFile = new File(directory, this.name);
|
||||||
|
|
||||||
|
this.getPlugin().getConfigHandler().addConfig(this);
|
||||||
init(YamlConfiguration.loadConfiguration(configFile));
|
init(YamlConfiguration.loadConfiguration(configFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void reloadFromFile() {
|
||||||
|
try {
|
||||||
|
this.getHandle().load(this.getConfigFile());
|
||||||
|
} catch (IOException | InvalidConfigurationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createFile() {
|
public void createFile() {
|
||||||
String resourcePath = getResourcePath();
|
String resourcePath = getResourcePath();
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ public class EcoUpdatableYamlConfig extends EcoLoadableYamlConfig {
|
|||||||
this.updateBlacklist = new ArrayList<>(Arrays.asList(updateBlacklist));
|
this.updateBlacklist = new ArrayList<>(Arrays.asList(updateBlacklist));
|
||||||
this.updateBlacklist.removeIf(String::isEmpty);
|
this.updateBlacklist.removeIf(String::isEmpty);
|
||||||
|
|
||||||
|
plugin.getConfigHandler().addConfig(this);
|
||||||
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,12 @@ package com.willfp.eco.internal.extensions;
|
|||||||
|
|
||||||
import com.willfp.eco.core.EcoPlugin;
|
import com.willfp.eco.core.EcoPlugin;
|
||||||
import com.willfp.eco.core.PluginDependent;
|
import com.willfp.eco.core.PluginDependent;
|
||||||
|
import com.willfp.eco.core.config.interfaces.Config;
|
||||||
|
import com.willfp.eco.core.config.yaml.YamlTransientConfig;
|
||||||
import com.willfp.eco.core.extensions.Extension;
|
import com.willfp.eco.core.extensions.Extension;
|
||||||
import com.willfp.eco.core.extensions.ExtensionLoader;
|
import com.willfp.eco.core.extensions.ExtensionLoader;
|
||||||
import com.willfp.eco.core.extensions.ExtensionMetadata;
|
import com.willfp.eco.core.extensions.ExtensionMetadata;
|
||||||
import com.willfp.eco.core.extensions.MalformedExtensionException;
|
import com.willfp.eco.core.extensions.MalformedExtensionException;
|
||||||
import org.apache.commons.lang.Validate;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@@ -17,8 +18,6 @@ import java.io.InputStreamReader;
|
|||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -50,12 +49,12 @@ public class EcoExtensionLoader extends PluginDependent<EcoPlugin> implements Ex
|
|||||||
try {
|
try {
|
||||||
loadExtension(extensionJar);
|
loadExtension(extensionJar);
|
||||||
} catch (MalformedExtensionException e) {
|
} catch (MalformedExtensionException e) {
|
||||||
this.getPlugin().getLogger().severe(extensionJar.getName() + " caused MalformedExtensionException: " + e.getMessage());
|
this.getPlugin().getLogger().warning(extensionJar.getName() + " caused an error!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadExtension(@NotNull final File extensionJar) {
|
private void loadExtension(@NotNull final File extensionJar) throws MalformedExtensionException {
|
||||||
URL url = null;
|
URL url = null;
|
||||||
try {
|
try {
|
||||||
url = extensionJar.toURI().toURL();
|
url = extensionJar.toURI().toURL();
|
||||||
@@ -71,22 +70,31 @@ public class EcoExtensionLoader extends PluginDependent<EcoPlugin> implements Ex
|
|||||||
throw new MalformedExtensionException("No extension.yml found in " + extensionJar.getName());
|
throw new MalformedExtensionException("No extension.yml found in " + extensionJar.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
YamlConfiguration extensionYml = YamlConfiguration.loadConfiguration(new InputStreamReader(ymlIn));
|
Config extensionYml = new YamlTransientConfig(YamlConfiguration.loadConfiguration(new InputStreamReader(ymlIn)));
|
||||||
|
|
||||||
Set<String> keys = extensionYml.getKeys(false);
|
String mainClass = extensionYml.getStringOrNull("main");
|
||||||
ArrayList<String> required = new ArrayList<>(Arrays.asList("main", "name", "version"));
|
String name = extensionYml.getStringOrNull("name");
|
||||||
required.removeAll(keys);
|
String version = extensionYml.getStringOrNull("version");
|
||||||
if (!required.isEmpty()) {
|
String author = extensionYml.getStringOrNull("author");
|
||||||
throw new MalformedExtensionException("Invalid extension.yml found in " + extensionJar.getName() + " - Missing: " + String.join(", ", required));
|
|
||||||
|
if (mainClass == null) {
|
||||||
|
throw new MalformedExtensionException("Invalid extension.yml found in " + extensionJar.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
String mainClass = extensionYml.getString("main");
|
if (name == null) {
|
||||||
String name = extensionYml.getString("name");
|
this.getPlugin().getLogger().warning(extensionJar.getName() + " doesn't have a name!");
|
||||||
String version = extensionYml.getString("version");
|
name = "Unnamed Extension " + extensionJar.getName();
|
||||||
String author = extensionYml.getString("author");
|
}
|
||||||
Validate.notNull(name, "Name is missing!");
|
|
||||||
Validate.notNull(version, "Version is missing!");
|
if (version == null) {
|
||||||
Validate.notNull(author, "Author is missing!");
|
this.getPlugin().getLogger().warning(extensionJar.getName() + " doesn't have a version!");
|
||||||
|
version = "1.0.0";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (author == null) {
|
||||||
|
this.getPlugin().getLogger().warning(extensionJar.getName() + " doesn't have an author!");
|
||||||
|
author = "Unnamed Author";
|
||||||
|
}
|
||||||
|
|
||||||
ExtensionMetadata metadata = new ExtensionMetadata(version, name, author);
|
ExtensionMetadata metadata = new ExtensionMetadata(version, name, author);
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import net.minecraft.server.v1_16_R3.IChatBaseComponent;
|
|||||||
import net.minecraft.server.v1_16_R3.MojangsonParser;
|
import net.minecraft.server.v1_16_R3.MojangsonParser;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack;
|
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@@ -21,7 +22,8 @@ import java.util.Arrays;
|
|||||||
|
|
||||||
public final class ChatComponent implements ChatComponentProxy {
|
public final class ChatComponent implements ChatComponentProxy {
|
||||||
@Override
|
@Override
|
||||||
public Object modifyComponent(@NotNull final Object object) {
|
public Object modifyComponent(@NotNull final Object object,
|
||||||
|
@NotNull final Player player) {
|
||||||
if (!(object instanceof IChatBaseComponent chatComponent)) {
|
if (!(object instanceof IChatBaseComponent chatComponent)) {
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
@@ -31,25 +33,26 @@ public final class ChatComponent implements ChatComponentProxy {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
modifyBaseComponent(iChatBaseComponent);
|
modifyBaseComponent(iChatBaseComponent, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
return chatComponent;
|
return chatComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void modifyBaseComponent(@NotNull final IChatBaseComponent component) {
|
private void modifyBaseComponent(@NotNull final IChatBaseComponent component,
|
||||||
|
@NotNull final Player player) {
|
||||||
for (IChatBaseComponent sibling : component.getSiblings()) {
|
for (IChatBaseComponent sibling : component.getSiblings()) {
|
||||||
if (sibling == null) {
|
if (sibling == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
modifyBaseComponent(sibling);
|
modifyBaseComponent(sibling, player);
|
||||||
}
|
}
|
||||||
if (component instanceof ChatMessage) {
|
if (component instanceof ChatMessage) {
|
||||||
Arrays.stream(((ChatMessage) component).getArgs())
|
Arrays.stream(((ChatMessage) component).getArgs())
|
||||||
.filter(o -> o instanceof IChatBaseComponent)
|
.filter(o -> o instanceof IChatBaseComponent)
|
||||||
.map(o -> (IChatBaseComponent) o)
|
.map(o -> (IChatBaseComponent) o)
|
||||||
.forEach(this::modifyBaseComponent);
|
.forEach(o -> this.modifyBaseComponent(o, player));
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatHoverable hoverable = component.getChatModifier().getHoverEvent();
|
ChatHoverable hoverable = component.getChatModifier().getHoverEvent();
|
||||||
@@ -70,7 +73,7 @@ public final class ChatComponent implements ChatComponentProxy {
|
|||||||
String tag = json.getAsJsonObject().get("tag").toString();
|
String tag = json.getAsJsonObject().get("tag").toString();
|
||||||
ItemStack itemStack = getFromTag(tag, id);
|
ItemStack itemStack = getFromTag(tag, id);
|
||||||
|
|
||||||
Display.displayAndFinalize(itemStack);
|
Display.displayAndFinalize(itemStack, player);
|
||||||
|
|
||||||
json.getAsJsonObject().remove("tag");
|
json.getAsJsonObject().remove("tag");
|
||||||
String newTag = toJson(itemStack);
|
String newTag = toJson(itemStack);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.willfp.eco.proxy.v1_16_R3;
|
|||||||
import com.willfp.eco.core.display.Display;
|
import com.willfp.eco.core.display.Display;
|
||||||
import com.willfp.eco.proxy.VillagerTradeProxy;
|
import com.willfp.eco.proxy.VillagerTradeProxy;
|
||||||
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftMerchantRecipe;
|
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftMerchantRecipe;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.MerchantRecipe;
|
import org.bukkit.inventory.MerchantRecipe;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -25,7 +26,8 @@ public final class VillagerTrade implements VillagerTradeProxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MerchantRecipe displayTrade(@NotNull final MerchantRecipe recipe) {
|
public MerchantRecipe displayTrade(@NotNull final MerchantRecipe recipe,
|
||||||
|
@NotNull final Player player) {
|
||||||
CraftMerchantRecipe oldRecipe = (CraftMerchantRecipe) recipe;
|
CraftMerchantRecipe oldRecipe = (CraftMerchantRecipe) recipe;
|
||||||
|
|
||||||
CraftMerchantRecipe newRecipe = new CraftMerchantRecipe(
|
CraftMerchantRecipe newRecipe = new CraftMerchantRecipe(
|
||||||
@@ -38,7 +40,7 @@ public final class VillagerTrade implements VillagerTradeProxy {
|
|||||||
);
|
);
|
||||||
|
|
||||||
for (ItemStack ingredient : recipe.getIngredients()) {
|
for (ItemStack ingredient : recipe.getIngredients()) {
|
||||||
newRecipe.addIngredient(Display.display(ingredient.clone()));
|
newRecipe.addIngredient(Display.display(ingredient.clone(), player));
|
||||||
}
|
}
|
||||||
|
|
||||||
getHandle(newRecipe).setSpecialPrice(getHandle(oldRecipe).getSpecialPrice());
|
getHandle(newRecipe).setSpecialPrice(getHandle(oldRecipe).getSpecialPrice());
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import net.minecraft.network.chat.ChatModifier;
|
|||||||
import net.minecraft.network.chat.IChatBaseComponent;
|
import net.minecraft.network.chat.IChatBaseComponent;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack;
|
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@@ -21,7 +22,8 @@ import java.util.Arrays;
|
|||||||
|
|
||||||
public final class ChatComponent implements ChatComponentProxy {
|
public final class ChatComponent implements ChatComponentProxy {
|
||||||
@Override
|
@Override
|
||||||
public Object modifyComponent(@NotNull final Object object) {
|
public Object modifyComponent(@NotNull final Object object,
|
||||||
|
@NotNull final Player player) {
|
||||||
if (!(object instanceof IChatBaseComponent chatComponent)) {
|
if (!(object instanceof IChatBaseComponent chatComponent)) {
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
@@ -31,25 +33,26 @@ public final class ChatComponent implements ChatComponentProxy {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
modifyBaseComponent(iChatBaseComponent);
|
modifyBaseComponent(iChatBaseComponent, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
return chatComponent;
|
return chatComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void modifyBaseComponent(@NotNull final IChatBaseComponent component) {
|
private void modifyBaseComponent(@NotNull final IChatBaseComponent component,
|
||||||
|
@NotNull final Player player) {
|
||||||
for (IChatBaseComponent sibling : component.getSiblings()) {
|
for (IChatBaseComponent sibling : component.getSiblings()) {
|
||||||
if (sibling == null) {
|
if (sibling == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
modifyBaseComponent(sibling);
|
modifyBaseComponent(sibling, player);
|
||||||
}
|
}
|
||||||
if (component instanceof ChatMessage) {
|
if (component instanceof ChatMessage) {
|
||||||
Arrays.stream(((ChatMessage) component).getArgs())
|
Arrays.stream(((ChatMessage) component).getArgs())
|
||||||
.filter(o -> o instanceof IChatBaseComponent)
|
.filter(o -> o instanceof IChatBaseComponent)
|
||||||
.map(o -> (IChatBaseComponent) o)
|
.map(o -> (IChatBaseComponent) o)
|
||||||
.forEach(this::modifyBaseComponent);
|
.forEach(o -> modifyBaseComponent(o, player));
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatHoverable hoverable = component.getChatModifier().getHoverEvent();
|
ChatHoverable hoverable = component.getChatModifier().getHoverEvent();
|
||||||
@@ -70,7 +73,7 @@ public final class ChatComponent implements ChatComponentProxy {
|
|||||||
String tag = json.getAsJsonObject().get("tag").toString();
|
String tag = json.getAsJsonObject().get("tag").toString();
|
||||||
ItemStack itemStack = getFromTag(tag, id);
|
ItemStack itemStack = getFromTag(tag, id);
|
||||||
|
|
||||||
Display.displayAndFinalize(itemStack);
|
Display.displayAndFinalize(itemStack, player);
|
||||||
|
|
||||||
json.getAsJsonObject().remove("tag");
|
json.getAsJsonObject().remove("tag");
|
||||||
String newTag = toJson(itemStack);
|
String newTag = toJson(itemStack);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.willfp.eco.proxy.v1_17_R1;
|
|||||||
import com.willfp.eco.core.display.Display;
|
import com.willfp.eco.core.display.Display;
|
||||||
import com.willfp.eco.proxy.VillagerTradeProxy;
|
import com.willfp.eco.proxy.VillagerTradeProxy;
|
||||||
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftMerchantRecipe;
|
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftMerchantRecipe;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.MerchantRecipe;
|
import org.bukkit.inventory.MerchantRecipe;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -25,7 +26,8 @@ public final class VillagerTrade implements VillagerTradeProxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MerchantRecipe displayTrade(@NotNull final MerchantRecipe recipe) {
|
public MerchantRecipe displayTrade(@NotNull final MerchantRecipe recipe,
|
||||||
|
@NotNull final Player player) {
|
||||||
CraftMerchantRecipe oldRecipe = (CraftMerchantRecipe) recipe;
|
CraftMerchantRecipe oldRecipe = (CraftMerchantRecipe) recipe;
|
||||||
|
|
||||||
CraftMerchantRecipe newRecipe = new CraftMerchantRecipe(
|
CraftMerchantRecipe newRecipe = new CraftMerchantRecipe(
|
||||||
@@ -38,7 +40,7 @@ public final class VillagerTrade implements VillagerTradeProxy {
|
|||||||
);
|
);
|
||||||
|
|
||||||
for (ItemStack ingredient : recipe.getIngredients()) {
|
for (ItemStack ingredient : recipe.getIngredients()) {
|
||||||
newRecipe.addIngredient(Display.display(ingredient.clone()));
|
newRecipe.addIngredient(Display.display(ingredient.clone(), player));
|
||||||
}
|
}
|
||||||
|
|
||||||
getHandle(newRecipe).setSpecialPrice(getHandle(oldRecipe).getSpecialPrice());
|
getHandle(newRecipe).setSpecialPrice(getHandle(oldRecipe).getSpecialPrice());
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import com.willfp.eco.spigot.display.PacketSetCreativeSlot;
|
|||||||
import com.willfp.eco.spigot.display.PacketSetSlot;
|
import com.willfp.eco.spigot.display.PacketSetSlot;
|
||||||
import com.willfp.eco.spigot.display.PacketWindowItems;
|
import com.willfp.eco.spigot.display.PacketWindowItems;
|
||||||
import com.willfp.eco.spigot.drops.CollatedRunnable;
|
import com.willfp.eco.spigot.drops.CollatedRunnable;
|
||||||
|
import com.willfp.eco.spigot.eventlisteners.ArmorChangeEventListeners;
|
||||||
import com.willfp.eco.spigot.eventlisteners.ArmorListener;
|
import com.willfp.eco.spigot.eventlisteners.ArmorListener;
|
||||||
import com.willfp.eco.spigot.eventlisteners.DispenserArmorListener;
|
import com.willfp.eco.spigot.eventlisteners.DispenserArmorListener;
|
||||||
import com.willfp.eco.spigot.eventlisteners.EntityDeathByEntityListeners;
|
import com.willfp.eco.spigot.eventlisteners.EntityDeathByEntityListeners;
|
||||||
@@ -55,7 +56,7 @@ import java.util.List;
|
|||||||
public abstract class EcoSpigotPlugin extends EcoPlugin {
|
public abstract class EcoSpigotPlugin extends EcoPlugin {
|
||||||
@Getter
|
@Getter
|
||||||
private static EcoSpigotPlugin instance;
|
private static EcoSpigotPlugin instance;
|
||||||
|
|
||||||
public EcoSpigotPlugin() {
|
public EcoSpigotPlugin() {
|
||||||
super(87955, 10043, "com.willfp.eco.proxy", "&a");
|
super(87955, 10043, "com.willfp.eco.proxy", "&a");
|
||||||
instance = this;
|
instance = this;
|
||||||
@@ -153,7 +154,8 @@ public abstract class EcoSpigotPlugin extends EcoPlugin {
|
|||||||
new ShapedRecipeListener(this),
|
new ShapedRecipeListener(this),
|
||||||
new PlayerJumpListeners(),
|
new PlayerJumpListeners(),
|
||||||
new GUIListener(this),
|
new GUIListener(this),
|
||||||
new ArrowDataListener(this)
|
new ArrowDataListener(this),
|
||||||
|
new ArmorChangeEventListeners(this)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public class PacketChat extends AbstractPacketAdapter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
WrappedChatComponent newComponent = WrappedChatComponent.fromHandle(this.getPlugin().getProxy(ChatComponentProxy.class).modifyComponent(component.getHandle()));
|
WrappedChatComponent newComponent = WrappedChatComponent.fromHandle(this.getPlugin().getProxy(ChatComponentProxy.class).modifyComponent(component.getHandle(), player));
|
||||||
packet.getChatComponents().write(i, newComponent);
|
packet.getChatComponents().write(i, newComponent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public class PacketOpenWindowMerchant extends AbstractPacketAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (MerchantRecipe recipe : packet.getMerchantRecipeLists().read(0)) {
|
for (MerchantRecipe recipe : packet.getMerchantRecipeLists().read(0)) {
|
||||||
MerchantRecipe newRecipe = this.getPlugin().getProxy(VillagerTradeProxy.class).displayTrade(recipe);
|
MerchantRecipe newRecipe = this.getPlugin().getProxy(VillagerTradeProxy.class).displayTrade(recipe, player);
|
||||||
recipes.add(newRecipe);
|
recipes.add(newRecipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,6 @@ public class PacketSetSlot extends AbstractPacketAdapter {
|
|||||||
public void onSend(@NotNull final PacketContainer packet,
|
public void onSend(@NotNull final PacketContainer packet,
|
||||||
@NotNull final Player player,
|
@NotNull final Player player,
|
||||||
@NotNull final PacketEvent event) {
|
@NotNull final PacketEvent event) {
|
||||||
packet.getItemModifier().modify(0, Display::display);
|
packet.getItemModifier().modify(0, item -> Display.display(item, player));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public class PacketWindowItems extends AbstractPacketAdapter {
|
|||||||
if (itemStacks == null) {
|
if (itemStacks == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
itemStacks.forEach(Display::display);
|
itemStacks.forEach(item -> Display.display(item, player));
|
||||||
return itemStacks;
|
return itemStacks;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.willfp.eco.spigot.eventlisteners;
|
||||||
|
|
||||||
|
import com.willfp.eco.core.EcoPlugin;
|
||||||
|
import com.willfp.eco.core.PluginDependent;
|
||||||
|
import com.willfp.eco.core.events.ArmorChangeEvent;
|
||||||
|
import com.willfp.eco.core.events.ArmorEquipEvent;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ArmorChangeEventListeners extends PluginDependent<EcoPlugin> implements Listener {
|
||||||
|
/**
|
||||||
|
* Pass an {@link EcoPlugin} in order to interface with it.
|
||||||
|
*
|
||||||
|
* @param plugin The plugin to manage.
|
||||||
|
*/
|
||||||
|
public ArmorChangeEventListeners(@NotNull final EcoPlugin plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onArmorChange(@NotNull final ArmorEquipEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
|
List<ItemStack> before = new ArrayList<>(Arrays.asList(player.getInventory().getArmorContents()));
|
||||||
|
|
||||||
|
this.getPlugin().getScheduler().runLater(() -> {
|
||||||
|
List<ItemStack> after = new ArrayList<>(Arrays.asList(player.getInventory().getArmorContents()));
|
||||||
|
|
||||||
|
ArmorChangeEvent armorChangeEvent = new ArmorChangeEvent(player, before, after);
|
||||||
|
Bukkit.getPluginManager().callEvent(armorChangeEvent);
|
||||||
|
}, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,13 +2,17 @@ package com.willfp.eco.proxy;
|
|||||||
|
|
||||||
|
|
||||||
import com.willfp.eco.core.proxy.AbstractProxy;
|
import com.willfp.eco.core.proxy.AbstractProxy;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public interface ChatComponentProxy extends AbstractProxy {
|
public interface ChatComponentProxy extends AbstractProxy {
|
||||||
/**
|
/**
|
||||||
* Modify hover {@link org.bukkit.inventory.ItemStack}s using EnchantDisplay#displayEnchantments.
|
* Modify hover {@link org.bukkit.inventory.ItemStack}s using EnchantDisplay#displayEnchantments.
|
||||||
|
*
|
||||||
* @param object The NMS ChatComponent to modify.
|
* @param object The NMS ChatComponent to modify.
|
||||||
|
* @param player The player.
|
||||||
* @return The modified ChatComponent.
|
* @return The modified ChatComponent.
|
||||||
*/
|
*/
|
||||||
Object modifyComponent(@NotNull Object object);
|
Object modifyComponent(@NotNull Object object,
|
||||||
|
@NotNull Player player);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.willfp.eco.proxy;
|
package com.willfp.eco.proxy;
|
||||||
|
|
||||||
import com.willfp.eco.core.proxy.AbstractProxy;
|
import com.willfp.eco.core.proxy.AbstractProxy;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.MerchantRecipe;
|
import org.bukkit.inventory.MerchantRecipe;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@@ -9,7 +10,9 @@ public interface VillagerTradeProxy extends AbstractProxy {
|
|||||||
* Display a MerchantRecipe.
|
* Display a MerchantRecipe.
|
||||||
*
|
*
|
||||||
* @param recipe The recipe.
|
* @param recipe The recipe.
|
||||||
|
* @param player The player.
|
||||||
* @return The new recipe.
|
* @return The new recipe.
|
||||||
*/
|
*/
|
||||||
MerchantRecipe displayTrade(@NotNull MerchantRecipe recipe);
|
MerchantRecipe displayTrade(@NotNull MerchantRecipe recipe,
|
||||||
|
@NotNull Player player);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
version = 6.0.2
|
version = 6.2.0
|
||||||
plugin-name = eco
|
plugin-name = eco
|
||||||
Reference in New Issue
Block a user