Compare commits
32 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb42505d66 | ||
|
|
b4d59077e3 | ||
|
|
104d55c11b | ||
|
|
b5af17cf08 | ||
|
|
78ae662ced | ||
|
|
32e48db3ce | ||
|
|
8a27e75c02 | ||
|
|
bf55e9b189 | ||
|
|
bfbaa3d033 | ||
|
|
64f87d5741 | ||
|
|
cb3441286c | ||
|
|
5e97a0f894 | ||
|
|
de2166dfdb | ||
|
|
abd361f4b5 | ||
|
|
422f8ead23 | ||
|
|
7c05dd7457 | ||
|
|
3ef7622c6f | ||
|
|
8207d62b1f | ||
|
|
75a0b1dd0d | ||
|
|
d1307e35db | ||
|
|
0a6b197a97 | ||
|
|
8d6512886c | ||
|
|
5c0c0f3e2a | ||
|
|
e2c2fc776a | ||
|
|
576050b31e | ||
|
|
f9a43bd336 | ||
|
|
203f2f599a | ||
|
|
baa5d37744 | ||
|
|
17f6af2a70 | ||
|
|
eae213f58e | ||
|
|
3a6a133560 | ||
|
|
57cf144c57 |
@@ -0,0 +1,16 @@
|
||||
package com.willfp.eco.proxy.v1_15_R1;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.BlockBreakProxy;
|
||||
import net.minecraft.server.v1_15_R1.BlockPosition;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class BlockBreak implements BlockBreakProxy {
|
||||
@Override
|
||||
public void breakBlock(@NotNull final Player player,
|
||||
@NotNull final Block block) {
|
||||
((CraftPlayer) player).getHandle().playerInteractManager.breakBlock(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.willfp.eco.proxy.v1_15_R1;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.CooldownProxy;
|
||||
import net.minecraft.server.v1_15_R1.EntityHuman;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class Cooldown implements CooldownProxy {
|
||||
@Override
|
||||
public double getAttackCooldown(@NotNull final Player player) {
|
||||
EntityHuman entityHuman = ((CraftPlayer) player).getHandle();
|
||||
return entityHuman.s(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.willfp.eco.proxy.v1_15_R1;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.willfp.eco.proxy.proxies.SkullProxy;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class Skull implements SkullProxy {
|
||||
/**
|
||||
* Cached method to set the gameProfile.
|
||||
*/
|
||||
private Method setProfile = null;
|
||||
|
||||
@Override
|
||||
public void setSkullTexture(@NotNull final SkullMeta meta,
|
||||
@NotNull final String base64) {
|
||||
try {
|
||||
if (setProfile == null) {
|
||||
setProfile = meta.getClass().getDeclaredMethod("setProfile", GameProfile.class);
|
||||
setProfile.setAccessible(true);
|
||||
}
|
||||
|
||||
UUID uuid = new UUID(
|
||||
base64.substring(base64.length() - 20).hashCode(),
|
||||
base64.substring(base64.length() - 10).hashCode()
|
||||
);
|
||||
|
||||
GameProfile profile = new GameProfile(uuid, "talismans");
|
||||
profile.getProperties().put("textures", new Property("textures", base64));
|
||||
|
||||
setProfile.invoke(meta, profile);
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.willfp.eco.proxy.v1_15_R1;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.TridentStackProxy;
|
||||
import net.minecraft.server.v1_15_R1.EntityThrownTrident;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftTrident;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Trident;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class TridentStack implements TridentStackProxy {
|
||||
@Override
|
||||
public ItemStack getTridentStack(@NotNull final Trident trident) {
|
||||
EntityThrownTrident t = ((CraftTrident) trident).getHandle();
|
||||
return CraftItemStack.asBukkitCopy(t.trident);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.willfp.eco.proxy.v1_16_R1;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.BlockBreakProxy;
|
||||
import net.minecraft.server.v1_16_R1.BlockPosition;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class BlockBreak implements BlockBreakProxy {
|
||||
@Override
|
||||
public void breakBlock(@NotNull final Player player,
|
||||
@NotNull final Block block) {
|
||||
((CraftPlayer) player).getHandle().playerInteractManager.breakBlock(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.willfp.eco.proxy.v1_16_R1;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.willfp.eco.proxy.proxies.SkullProxy;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class Skull implements SkullProxy {
|
||||
/**
|
||||
* Cached method to set the gameProfile.
|
||||
*/
|
||||
private Method setProfile = null;
|
||||
|
||||
@Override
|
||||
public void setSkullTexture(@NotNull final SkullMeta meta,
|
||||
@NotNull final String base64) {
|
||||
try {
|
||||
if (setProfile == null) {
|
||||
setProfile = meta.getClass().getDeclaredMethod("setProfile", GameProfile.class);
|
||||
setProfile.setAccessible(true);
|
||||
}
|
||||
|
||||
UUID uuid = new UUID(
|
||||
base64.substring(base64.length() - 20).hashCode(),
|
||||
base64.substring(base64.length() - 10).hashCode()
|
||||
);
|
||||
|
||||
GameProfile profile = new GameProfile(uuid, "talismans");
|
||||
profile.getProperties().put("textures", new Property("textures", base64));
|
||||
|
||||
setProfile.invoke(meta, profile);
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.willfp.eco.proxy.v1_16_R1;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.TridentStackProxy;
|
||||
import net.minecraft.server.v1_16_R1.EntityThrownTrident;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.entity.CraftTrident;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Trident;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class TridentStack implements TridentStackProxy {
|
||||
@Override
|
||||
public ItemStack getTridentStack(@NotNull final Trident trident) {
|
||||
EntityThrownTrident t = ((CraftTrident) trident).getHandle();
|
||||
return CraftItemStack.asBukkitCopy(t.trident);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.willfp.eco.proxy.v1_16_R2;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.BlockBreakProxy;
|
||||
import net.minecraft.server.v1_16_R2.BlockPosition;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class BlockBreak implements BlockBreakProxy {
|
||||
@Override
|
||||
public void breakBlock(@NotNull final Player player,
|
||||
@NotNull final Block block) {
|
||||
((CraftPlayer) player).getHandle().playerInteractManager.breakBlock(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.willfp.eco.proxy.v1_16_R2;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.willfp.eco.proxy.proxies.SkullProxy;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class Skull implements SkullProxy {
|
||||
/**
|
||||
* Cached method to set the gameProfile.
|
||||
*/
|
||||
private Method setProfile = null;
|
||||
|
||||
@Override
|
||||
public void setSkullTexture(@NotNull final SkullMeta meta,
|
||||
@NotNull final String base64) {
|
||||
try {
|
||||
if (setProfile == null) {
|
||||
setProfile = meta.getClass().getDeclaredMethod("setProfile", GameProfile.class);
|
||||
setProfile.setAccessible(true);
|
||||
}
|
||||
|
||||
UUID uuid = new UUID(
|
||||
base64.substring(base64.length() - 20).hashCode(),
|
||||
base64.substring(base64.length() - 10).hashCode()
|
||||
);
|
||||
|
||||
GameProfile profile = new GameProfile(uuid, "talismans");
|
||||
profile.getProperties().put("textures", new Property("textures", base64));
|
||||
|
||||
setProfile.invoke(meta, profile);
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.willfp.eco.proxy.v1_16_R2;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.TridentStackProxy;
|
||||
import net.minecraft.server.v1_16_R2.EntityThrownTrident;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.entity.CraftTrident;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Trident;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class TridentStack implements TridentStackProxy {
|
||||
@Override
|
||||
public ItemStack getTridentStack(@NotNull final Trident trident) {
|
||||
EntityThrownTrident t = ((CraftTrident) trident).getHandle();
|
||||
return CraftItemStack.asBukkitCopy(t.trident);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.willfp.eco.proxy.v1_16_R3;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.BlockBreakProxy;
|
||||
import net.minecraft.server.v1_16_R3.BlockPosition;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class BlockBreak implements BlockBreakProxy {
|
||||
@Override
|
||||
public void breakBlock(@NotNull final Player player,
|
||||
@NotNull final Block block) {
|
||||
((CraftPlayer) player).getHandle().playerInteractManager.breakBlock(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.willfp.eco.proxy.v1_16_R3;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.willfp.eco.proxy.proxies.SkullProxy;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class Skull implements SkullProxy {
|
||||
/**
|
||||
* Cached method to set the gameProfile.
|
||||
*/
|
||||
private Method setProfile = null;
|
||||
|
||||
@Override
|
||||
public void setSkullTexture(@NotNull final SkullMeta meta,
|
||||
@NotNull final String base64) {
|
||||
try {
|
||||
if (setProfile == null) {
|
||||
setProfile = meta.getClass().getDeclaredMethod("setProfile", GameProfile.class);
|
||||
setProfile.setAccessible(true);
|
||||
}
|
||||
|
||||
UUID uuid = new UUID(
|
||||
base64.substring(base64.length() - 20).hashCode(),
|
||||
base64.substring(base64.length() - 10).hashCode()
|
||||
);
|
||||
|
||||
GameProfile profile = new GameProfile(uuid, "talismans");
|
||||
profile.getProperties().put("textures", new Property("textures", base64));
|
||||
|
||||
setProfile.invoke(meta, profile);
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.willfp.eco.proxy.v1_16_R3;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.TridentStackProxy;
|
||||
import net.minecraft.server.v1_16_R3.EntityThrownTrident;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftTrident;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Trident;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class TridentStack implements TridentStackProxy {
|
||||
@Override
|
||||
public ItemStack getTridentStack(@NotNull final Trident trident) {
|
||||
EntityThrownTrident t = ((CraftTrident) trident).getHandle();
|
||||
return CraftItemStack.asBukkitCopy(t.trident);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,18 @@
|
||||
package com.willfp.eco.spigot;
|
||||
|
||||
import com.willfp.eco.spigot.display.packets.PacketAutoRecipe;
|
||||
import com.willfp.eco.spigot.display.packets.PacketChat;
|
||||
import com.willfp.eco.spigot.display.packets.PacketOpenWindowMerchant;
|
||||
import com.willfp.eco.spigot.display.packets.PacketSetCreativeSlot;
|
||||
import com.willfp.eco.spigot.display.packets.PacketSetSlot;
|
||||
import com.willfp.eco.spigot.display.packets.PacketWindowItems;
|
||||
import com.willfp.eco.proxy.proxies.BlockBreakProxy;
|
||||
import com.willfp.eco.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.eco.proxy.proxies.SkullProxy;
|
||||
import com.willfp.eco.proxy.proxies.TridentStackProxy;
|
||||
import com.willfp.eco.spigot.display.PacketAutoRecipe;
|
||||
import com.willfp.eco.spigot.display.PacketChat;
|
||||
import com.willfp.eco.spigot.display.PacketOpenWindowMerchant;
|
||||
import com.willfp.eco.spigot.display.PacketSetCreativeSlot;
|
||||
import com.willfp.eco.spigot.display.PacketSetSlot;
|
||||
import com.willfp.eco.spigot.display.PacketWindowItems;
|
||||
import com.willfp.eco.spigot.drops.CollatedRunnable;
|
||||
import com.willfp.eco.spigot.eventlisteners.EntityDeathByEntityListeners;
|
||||
import com.willfp.eco.spigot.eventlisteners.NaturalExpGainListeners;
|
||||
import com.willfp.eco.spigot.integrations.anticheat.AnticheatAAC;
|
||||
import com.willfp.eco.spigot.integrations.anticheat.AnticheatMatrix;
|
||||
import com.willfp.eco.spigot.integrations.anticheat.AnticheatNCP;
|
||||
@@ -16,13 +23,16 @@ import com.willfp.eco.spigot.integrations.antigrief.AntigriefLands;
|
||||
import com.willfp.eco.spigot.integrations.antigrief.AntigriefTowny;
|
||||
import com.willfp.eco.spigot.integrations.antigrief.AntigriefWorldGuard;
|
||||
import com.willfp.eco.spigot.integrations.mcmmo.McmmoIntegrationImpl;
|
||||
import com.willfp.eco.spigot.recipes.RecipeListener;
|
||||
import com.willfp.eco.util.BlockUtils;
|
||||
import com.willfp.eco.util.PlayerUtils;
|
||||
import com.willfp.eco.util.SkullUtils;
|
||||
import com.willfp.eco.util.TridentUtils;
|
||||
import com.willfp.eco.util.command.AbstractCommand;
|
||||
import com.willfp.eco.util.display.Display;
|
||||
import com.willfp.eco.util.drops.internal.FastCollatedDropQueue;
|
||||
import com.willfp.eco.util.display.DisplayModule;
|
||||
import com.willfp.eco.util.events.armorequip.ArmorListener;
|
||||
import com.willfp.eco.util.events.armorequip.DispenserArmorListener;
|
||||
import com.willfp.eco.util.events.entitydeathbyentity.EntityDeathByEntityListeners;
|
||||
import com.willfp.eco.util.events.naturalexpgainevent.NaturalExpGainListeners;
|
||||
import com.willfp.eco.util.integrations.IntegrationLoader;
|
||||
import com.willfp.eco.util.integrations.anticheat.AnticheatManager;
|
||||
import com.willfp.eco.util.integrations.antigrief.AntigriefManager;
|
||||
@@ -31,6 +41,7 @@ import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -50,15 +61,20 @@ public class EcoPlugin extends AbstractEcoPlugin {
|
||||
super("eco", 87955, 10043, "com.willfp.eco.proxy", "&a");
|
||||
instance = this;
|
||||
Display.setFinalizeKey(this.getNamespacedKeyFactory().create("finalized"));
|
||||
SkullUtils.initialize((skullMeta, base64) -> InternalProxyUtils.getProxy(SkullProxy.class).setSkullTexture(skullMeta, base64));
|
||||
BlockUtils.initialize(((player, block) -> InternalProxyUtils.getProxy(BlockBreakProxy.class).breakBlock(player, block)));
|
||||
PlayerUtils.initialize(((player) -> InternalProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown(player)));
|
||||
TridentUtils.initialize(((trident) -> InternalProxyUtils.getProxy(TridentStackProxy.class).getTridentStack(trident)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
new FastCollatedDropQueue.CollatedRunnable(this);
|
||||
new CollatedRunnable(this);
|
||||
this.getEventManager().registerListener(new NaturalExpGainListeners());
|
||||
this.getEventManager().registerListener(new ArmorListener());
|
||||
this.getEventManager().registerListener(new DispenserArmorListener());
|
||||
this.getEventManager().registerListener(new EntityDeathByEntityListeners(this));
|
||||
this.getEventManager().registerListener(new RecipeListener());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,7 +89,7 @@ public class EcoPlugin extends AbstractEcoPlugin {
|
||||
|
||||
@Override
|
||||
public void onReload() {
|
||||
new FastCollatedDropQueue.CollatedRunnable(this);
|
||||
new CollatedRunnable(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -128,4 +144,10 @@ public class EcoPlugin extends AbstractEcoPlugin {
|
||||
public List<Class<?>> getUpdatableClasses() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected DisplayModule createDisplayModule() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.spigot.display.packets;
|
||||
package com.willfp.eco.spigot.display;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.spigot.display.packets;
|
||||
package com.willfp.eco.spigot.display;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.spigot.display.packets;
|
||||
package com.willfp.eco.spigot.display;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.spigot.display.packets;
|
||||
package com.willfp.eco.spigot.display;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.spigot.display.packets;
|
||||
package com.willfp.eco.spigot.display;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.spigot.display.packets;
|
||||
package com.willfp.eco.spigot.display;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.willfp.eco.spigot.drops;
|
||||
|
||||
|
||||
import com.willfp.eco.internal.drops.impl.FastCollatedDropQueue;
|
||||
import com.willfp.eco.internal.drops.impl.InternalDropQueue;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class CollatedRunnable {
|
||||
/**
|
||||
* The {@link BukkitTask} that the runnable represents.
|
||||
*/
|
||||
@Getter
|
||||
private final BukkitTask runnableTask;
|
||||
|
||||
/**
|
||||
* Create and run a new runnable to process collated drops.
|
||||
*
|
||||
* @param plugin The {@link AbstractEcoPlugin} that manages the processing.
|
||||
*/
|
||||
public CollatedRunnable(@NotNull final AbstractEcoPlugin plugin) {
|
||||
runnableTask = plugin.getScheduler().runTimer(() -> {
|
||||
for (Map.Entry<Player, FastCollatedDropQueue.CollatedDrops> entry : FastCollatedDropQueue.COLLATED_MAP.entrySet()) {
|
||||
new InternalDropQueue(entry.getKey())
|
||||
.setLocation(entry.getValue().getLocation())
|
||||
.addItems(entry.getValue().getDrops())
|
||||
.addXP(entry.getValue().getXp())
|
||||
.push();
|
||||
FastCollatedDropQueue.COLLATED_MAP.remove(entry.getKey());
|
||||
}
|
||||
FastCollatedDropQueue.COLLATED_MAP.clear();
|
||||
}, 0, 1);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.willfp.eco.util.events.entitydeathbyentity;
|
||||
package com.willfp.eco.spigot.eventlisteners;
|
||||
|
||||
import com.willfp.eco.util.events.entitydeathbyentity.EntityDeathByEntityEvent;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.lang.Validate;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.events.entitydeathbyentity;
|
||||
package com.willfp.eco.spigot.eventlisteners;
|
||||
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.willfp.eco.util.events.naturalexpgainevent;
|
||||
package com.willfp.eco.spigot.eventlisteners;
|
||||
|
||||
import com.willfp.eco.util.events.naturalexpgainevent.NaturalExpGainEvent;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.lang.Validate;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.events.naturalexpgainevent;
|
||||
package com.willfp.eco.spigot.eventlisteners;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -7,6 +7,7 @@ import org.bukkit.event.player.PlayerExpChangeEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public class NaturalExpGainListeners implements Listener {
|
||||
@@ -28,9 +29,10 @@ public class NaturalExpGainListeners implements Listener {
|
||||
|
||||
NaturalExpGainBuilder toRemove = null;
|
||||
for (NaturalExpGainBuilder searchBuilder : events) {
|
||||
if (!searchBuilder.getLocation().getWorld().equals(event.getPlayer().getLocation().getWorld())) {
|
||||
if (!Objects.equals(searchBuilder.getLocation().getWorld(), event.getPlayer().getLocation().getWorld())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (searchBuilder.getReason().equals(NaturalExpGainBuilder.BuildReason.BOTTLE) && searchBuilder.getLocation().distanceSquared(event.getPlayer().getLocation()) > 52) {
|
||||
toRemove = searchBuilder;
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
package com.willfp.eco.spigot.recipes;
|
||||
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.util.recipe.RecipeParts;
|
||||
import com.willfp.eco.util.recipe.Recipes;
|
||||
import com.willfp.eco.util.recipe.parts.RecipePart;
|
||||
import com.willfp.eco.util.recipe.parts.SimpleRecipePart;
|
||||
import com.willfp.eco.util.recipe.recipes.EcoShapedRecipe;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.CraftItemEvent;
|
||||
import org.bukkit.event.inventory.PrepareItemCraftEvent;
|
||||
import org.bukkit.event.player.PlayerRecipeDiscoverEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class RecipeListener implements Listener {
|
||||
/**
|
||||
* Called on item craft.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
public void complexRecipeListener(@NotNull final PrepareItemCraftEvent event) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
||||
|
||||
if (!AbstractEcoPlugin.LOADED_ECO_PLUGINS.contains(recipe.getKey().getNamespace())) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack[] matrix = event.getInventory().getMatrix();
|
||||
EcoShapedRecipe matched = Recipes.getMatch(matrix);
|
||||
|
||||
if (matched == null) {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
return;
|
||||
}
|
||||
|
||||
if (matched.test(matrix)) {
|
||||
event.getInventory().setResult(matched.getOutput());
|
||||
} else {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on item craft.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
public void complexRecipeListener(@NotNull final CraftItemEvent event) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
||||
|
||||
if (!AbstractEcoPlugin.LOADED_ECO_PLUGINS.contains(recipe.getKey().getNamespace())) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack[] matrix = event.getInventory().getMatrix();
|
||||
EcoShapedRecipe matched = Recipes.getMatch(matrix);
|
||||
|
||||
if (matched == null) {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
event.setResult(Event.Result.DENY);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (matched.test(matrix)) {
|
||||
event.getInventory().setResult(matched.getOutput());
|
||||
} else {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
event.setResult(Event.Result.DENY);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on item craft.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
public void preventUsingComplexPartInEcoRecipe(@NotNull final PrepareItemCraftEvent event) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
||||
|
||||
EcoShapedRecipe ecoShapedRecipe = Recipes.getShapedRecipe(recipe.getKey());
|
||||
|
||||
if (ecoShapedRecipe == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
ItemStack itemStack = event.getInventory().getMatrix()[i];
|
||||
RecipePart part = ecoShapedRecipe.getParts()[i];
|
||||
if (part instanceof SimpleRecipePart) {
|
||||
if (RecipeParts.isRecipePart(itemStack)) {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on item craft.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
public void preventUsingComplexPartInEcoRecipe(@NotNull final CraftItemEvent event) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
||||
|
||||
EcoShapedRecipe ecoShapedRecipe = Recipes.getShapedRecipe(recipe.getKey());
|
||||
|
||||
if (ecoShapedRecipe == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
ItemStack itemStack = event.getInventory().getMatrix()[i];
|
||||
RecipePart part = ecoShapedRecipe.getParts()[i];
|
||||
if (part instanceof SimpleRecipePart) {
|
||||
if (RecipeParts.isRecipePart(itemStack)) {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
event.setResult(Event.Result.DENY);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents using talismans in recipes.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
public void preventUsingComplexPartInVanillaRecipe(@NotNull final PrepareItemCraftEvent event) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
||||
|
||||
if (AbstractEcoPlugin.LOADED_ECO_PLUGINS.contains(recipe.getKey().getNamespace())) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (ItemStack itemStack : event.getInventory().getMatrix()) {
|
||||
if (RecipeParts.isRecipePart(itemStack)) {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents using talismans in recipes.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
public void preventUsingComplexPartInVanillaRecipe(@NotNull final CraftItemEvent event) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
||||
|
||||
if (AbstractEcoPlugin.LOADED_ECO_PLUGINS.contains(recipe.getKey().getNamespace())) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (ItemStack itemStack : event.getInventory().getMatrix()) {
|
||||
if (RecipeParts.isRecipePart(itemStack)) {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
event.setResult(Event.Result.DENY);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents learning displayed recipes.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
public void preventLearningDisplayedRecipes(@NotNull final PlayerRecipeDiscoverEvent event) {
|
||||
if (!AbstractEcoPlugin.LOADED_ECO_PLUGINS.contains(event.getRecipe().getNamespace())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getRecipe().getKey().contains("_displayed")) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.willfp.eco.proxy.proxies;
|
||||
|
||||
import com.willfp.eco.util.proxy.AbstractProxy;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface BlockBreakProxy extends AbstractProxy {
|
||||
/**
|
||||
* Break the block as if the player had done it manually.
|
||||
*
|
||||
* @param player The player to break the block as.
|
||||
* @param block The block to break.
|
||||
*/
|
||||
void breakBlock(@NotNull Player player,
|
||||
@NotNull Block block);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.willfp.eco.proxy.proxies;
|
||||
|
||||
import com.willfp.eco.util.proxy.AbstractProxy;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface CooldownProxy extends AbstractProxy {
|
||||
/**
|
||||
* Get the attack cooldown for a player.
|
||||
*
|
||||
* @param player The player's attack cooldown.
|
||||
* @return A value between 0 and 1, with 1 representing full power.
|
||||
*/
|
||||
double getAttackCooldown(@NotNull Player player);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.willfp.eco.proxy.proxies;
|
||||
|
||||
import com.willfp.eco.util.proxy.AbstractProxy;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface SkullProxy extends AbstractProxy {
|
||||
/**
|
||||
* Set the texture of a skull from base64.
|
||||
*
|
||||
* @param meta The meta to modify.
|
||||
* @param base64 The base64 texture.
|
||||
*/
|
||||
void setSkullTexture(@NotNull SkullMeta meta,
|
||||
@NotNull String base64);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.willfp.eco.proxy.proxies;
|
||||
|
||||
import com.willfp.eco.util.proxy.AbstractProxy;
|
||||
import org.bukkit.entity.Trident;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface TridentStackProxy extends AbstractProxy {
|
||||
/**
|
||||
* Get a trident's ItemStack.
|
||||
*
|
||||
* @param trident The trident to query.
|
||||
* @return The trident's ItemStack.
|
||||
*/
|
||||
ItemStack getTridentStack(@NotNull Trident trident);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.arrows;
|
||||
package com.willfp.eco.internal.arrows;
|
||||
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.willfp.eco.util.bukkit.events;
|
||||
package com.willfp.eco.internal.bukkit.events;
|
||||
|
||||
import com.willfp.eco.util.bukkit.events.EventManager;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.willfp.eco.util.bukkit.logging;
|
||||
package com.willfp.eco.internal.bukkit.logging;
|
||||
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import com.willfp.eco.util.bukkit.logging.Logger;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.willfp.eco.util.bukkit.scheduling;
|
||||
package com.willfp.eco.internal.bukkit.scheduling;
|
||||
|
||||
import com.willfp.eco.util.bukkit.scheduling.Scheduler;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.config.internal;
|
||||
package com.willfp.eco.internal.config;
|
||||
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
@@ -19,9 +19,12 @@ import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public abstract class AbstractConfig extends PluginDependent {
|
||||
/**
|
||||
* The linked {@link YamlConfiguration} where values are physically stored.
|
||||
@@ -53,6 +56,11 @@ public abstract class AbstractConfig extends PluginDependent {
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private final Class<?> source;
|
||||
|
||||
/**
|
||||
* Cached values for faster reading.
|
||||
*/
|
||||
private final Map<String, Object> cache = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Abstract config.
|
||||
*
|
||||
@@ -151,6 +159,13 @@ public abstract class AbstractConfig extends PluginDependent {
|
||||
return newConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears cache.
|
||||
*/
|
||||
public final void clearCache() {
|
||||
cache.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if the config contains a key.
|
||||
*
|
||||
@@ -185,7 +200,12 @@ public abstract class AbstractConfig extends PluginDependent {
|
||||
*/
|
||||
@Nullable
|
||||
public ConfigurationSection getSectionOrNull(@NotNull final String path) {
|
||||
return config.getConfigurationSection(path);
|
||||
if (cache.containsKey(path)) {
|
||||
return (ConfigurationSection) cache.get(path);
|
||||
} else {
|
||||
cache.put(path, config.getConfigurationSection(path));
|
||||
return getSectionOrNull(path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -195,7 +215,12 @@ public abstract class AbstractConfig extends PluginDependent {
|
||||
* @return The found value, or 0 if not found.
|
||||
*/
|
||||
public int getInt(@NotNull final String path) {
|
||||
return config.getInt(path, 0);
|
||||
if (cache.containsKey(path)) {
|
||||
return (int) cache.get(path);
|
||||
} else {
|
||||
cache.put(path, config.getInt(path, 0));
|
||||
return getInt(path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -222,7 +247,12 @@ public abstract class AbstractConfig extends PluginDependent {
|
||||
*/
|
||||
public int getInt(@NotNull final String path,
|
||||
final int def) {
|
||||
return config.getInt(path, def);
|
||||
if (cache.containsKey(path)) {
|
||||
return (int) cache.get(path);
|
||||
} else {
|
||||
cache.put(path, config.getInt(path, def));
|
||||
return getInt(path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -233,7 +263,12 @@ public abstract class AbstractConfig extends PluginDependent {
|
||||
*/
|
||||
@NotNull
|
||||
public List<Integer> getInts(@NotNull final String path) {
|
||||
return config.getIntegerList(path);
|
||||
if (cache.containsKey(path)) {
|
||||
return (List<Integer>) cache.get(path);
|
||||
} else {
|
||||
cache.put(path, config.getIntegerList(path));
|
||||
return getInts(path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -258,7 +293,12 @@ public abstract class AbstractConfig extends PluginDependent {
|
||||
* @return The found value, or false if not found.
|
||||
*/
|
||||
public boolean getBool(@NotNull final String path) {
|
||||
return config.getBoolean(path, false);
|
||||
if (cache.containsKey(path)) {
|
||||
return (boolean) cache.get(path);
|
||||
} else {
|
||||
cache.put(path, config.getBoolean(path));
|
||||
return getBool(path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -284,7 +324,12 @@ public abstract class AbstractConfig extends PluginDependent {
|
||||
*/
|
||||
@NotNull
|
||||
public List<Boolean> getBools(@NotNull final String path) {
|
||||
return config.getBooleanList(path);
|
||||
if (cache.containsKey(path)) {
|
||||
return (List<Boolean>) cache.get(path);
|
||||
} else {
|
||||
cache.put(path, config.getBooleanList(path));
|
||||
return getBools(path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -310,7 +355,12 @@ public abstract class AbstractConfig extends PluginDependent {
|
||||
*/
|
||||
@NotNull
|
||||
public String getString(@NotNull final String path) {
|
||||
return StringUtils.translate(Objects.requireNonNull(config.getString(path, "")));
|
||||
if (cache.containsKey(path)) {
|
||||
return (String) cache.get(path);
|
||||
} else {
|
||||
cache.put(path, StringUtils.translate(Objects.requireNonNull(config.getString(path, ""))));
|
||||
return getString(path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -336,7 +386,12 @@ public abstract class AbstractConfig extends PluginDependent {
|
||||
*/
|
||||
@NotNull
|
||||
public List<String> getStrings(@NotNull final String path) {
|
||||
return config.getStringList(path);
|
||||
if (cache.containsKey(path)) {
|
||||
return (List<String>) cache.get(path);
|
||||
} else {
|
||||
cache.put(path, config.getStringList(path));
|
||||
return getStrings(path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -361,7 +416,12 @@ public abstract class AbstractConfig extends PluginDependent {
|
||||
* @return The found value, or 0 if not found.
|
||||
*/
|
||||
public double getDouble(@NotNull final String path) {
|
||||
return config.getDouble(path, 0);
|
||||
if (cache.containsKey(path)) {
|
||||
return (double) cache.get(path);
|
||||
} else {
|
||||
cache.put(path, config.getDouble(path));
|
||||
return getDouble(path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -387,7 +447,12 @@ public abstract class AbstractConfig extends PluginDependent {
|
||||
*/
|
||||
@NotNull
|
||||
public List<Double> getDoubles(@NotNull final String path) {
|
||||
return config.getDoubleList(path);
|
||||
if (cache.containsKey(path)) {
|
||||
return (List<Double>) cache.get(path);
|
||||
} else {
|
||||
cache.put(path, config.getDoubleList(path));
|
||||
return getDoubles(path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.config.internal;
|
||||
package com.willfp.eco.internal.config;
|
||||
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
@@ -51,6 +51,7 @@ public abstract class AbstractUpdatableConfig extends AbstractConfig {
|
||||
* Writes missing values, however removes comments due to how configs are stored internally in bukkit.
|
||||
*/
|
||||
public void update() {
|
||||
super.clearCache();
|
||||
try {
|
||||
config.load(this.getConfigFile());
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.drops.internal;
|
||||
package com.willfp.eco.internal.drops;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.drops.internal;
|
||||
package com.willfp.eco.internal.drops;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.UtilityClass;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.drops.internal;
|
||||
package com.willfp.eco.internal.drops;
|
||||
|
||||
public enum DropQueueType {
|
||||
/**
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.willfp.eco.util.drops.internal;
|
||||
package com.willfp.eco.internal.drops.impl;
|
||||
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.internal.drops.AbstractDropQueue;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
@@ -8,8 +8,6 @@ import lombok.experimental.Accessors;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
@@ -22,7 +20,7 @@ public class FastCollatedDropQueue extends InternalDropQueue {
|
||||
* <p>
|
||||
* Cleared and updated every tick.
|
||||
*/
|
||||
private static final Map<Player, CollatedDrops> COLLATED_MAP = new ConcurrentHashMap<>();
|
||||
public static final Map<Player, CollatedDrops> COLLATED_MAP = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* Backend implementation of {@link AbstractDropQueue}
|
||||
@@ -37,7 +35,7 @@ public class FastCollatedDropQueue extends InternalDropQueue {
|
||||
}
|
||||
|
||||
/**
|
||||
* Queues the drops to be managed by the {@link CollatedRunnable}.
|
||||
* Queues the drops to be managed by the runnable.
|
||||
*/
|
||||
@Override
|
||||
public void push() {
|
||||
@@ -50,7 +48,7 @@ public class FastCollatedDropQueue extends InternalDropQueue {
|
||||
* The items, location, and xp linked to a player's drops.
|
||||
*/
|
||||
@ToString
|
||||
private static final class CollatedDrops {
|
||||
public static final class CollatedDrops {
|
||||
/**
|
||||
* A collection of all ItemStacks to be dropped at the end of the tick.
|
||||
*/
|
||||
@@ -101,32 +99,4 @@ public class FastCollatedDropQueue extends InternalDropQueue {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public static class CollatedRunnable {
|
||||
/**
|
||||
* The {@link BukkitTask} that the runnable represents.
|
||||
*/
|
||||
@Getter
|
||||
private final BukkitTask runnableTask;
|
||||
|
||||
/**
|
||||
* Create and run a new runnable to process collated drops.
|
||||
*
|
||||
* @param plugin The {@link AbstractEcoPlugin} that manages the processing.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public CollatedRunnable(@NotNull final AbstractEcoPlugin plugin) {
|
||||
runnableTask = plugin.getScheduler().runTimer(() -> {
|
||||
for (Map.Entry<Player, CollatedDrops> entry : COLLATED_MAP.entrySet()) {
|
||||
new InternalDropQueue(entry.getKey())
|
||||
.setLocation(entry.getValue().getLocation())
|
||||
.addItems(entry.getValue().getDrops())
|
||||
.addXP(entry.getValue().getXp())
|
||||
.push();
|
||||
COLLATED_MAP.remove(entry.getKey());
|
||||
}
|
||||
COLLATED_MAP.clear();
|
||||
}, 0, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.willfp.eco.util.drops.internal;
|
||||
package com.willfp.eco.internal.drops.impl;
|
||||
|
||||
import com.willfp.eco.internal.drops.AbstractDropQueue;
|
||||
import com.willfp.eco.util.drops.telekinesis.TelekinesisUtils;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.willfp.eco.util.extensions.loader;
|
||||
package com.willfp.eco.internal.extensions;
|
||||
|
||||
|
||||
import com.willfp.eco.util.extensions.Extension;
|
||||
import com.willfp.eco.util.extensions.MalformedExtensionException;
|
||||
import com.willfp.eco.util.extensions.loader.ExtensionLoader;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -94,6 +96,9 @@ public class EcoExtensionLoader extends PluginDependent implements ExtensionLoad
|
||||
String mainClass = extensionYml.getString("main");
|
||||
String name = extensionYml.getString("name");
|
||||
String version = extensionYml.getString("version");
|
||||
Validate.notNull(name, "Name is missing!");
|
||||
Validate.notNull(version, "Version is missing!");
|
||||
|
||||
Extension.ExtensionMetadata metadata = new Extension.ExtensionMetadata(version, name);
|
||||
|
||||
Class<?> cls;
|
||||
@@ -1,20 +1,34 @@
|
||||
package com.willfp.eco.util;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
@UtilityClass
|
||||
public class BlockUtils {
|
||||
public class BlockUtils {
|
||||
/**
|
||||
* If the meta set function has been set.
|
||||
*/
|
||||
private boolean initialized = false;
|
||||
|
||||
/**
|
||||
* The block break function.
|
||||
*/
|
||||
private BiConsumer<Player, Block> blockBreakConsumer = null;
|
||||
|
||||
private Set<Block> getNearbyBlocks(@NotNull final Block start,
|
||||
@NotNull final List<Material> allowedMaterials,
|
||||
@NotNull final HashSet<Block> blocks,
|
||||
@NotNull final Set<Block> blocks,
|
||||
final int limit) {
|
||||
for (BlockFace face : BlockFace.values()) {
|
||||
Block block = start.getRelative(face);
|
||||
@@ -29,7 +43,6 @@ public class BlockUtils {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a set of all blocks in contact with each other of a specific type.
|
||||
*
|
||||
@@ -44,4 +57,32 @@ public class BlockUtils {
|
||||
final int limit) {
|
||||
return getNearbyBlocks(start, allowedMaterials, new HashSet<>(), limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Break the block as if the player had done it manually.
|
||||
*
|
||||
* @param player The player to break the block as.
|
||||
* @param block The block to break.
|
||||
*/
|
||||
public void breakBlock(@NotNull final Player player,
|
||||
@NotNull final Block block) {
|
||||
Validate.isTrue(initialized, "Must be initialized!");
|
||||
Validate.notNull(blockBreakConsumer, "Must be initialized!");
|
||||
|
||||
blockBreakConsumer.accept(player, block);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the block break function.
|
||||
*
|
||||
* @param function The function.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public void initialize(@NotNull final BiConsumer<Player, Block> function) {
|
||||
Validate.isTrue(!initialized, "Already initialized!");
|
||||
|
||||
blockBreakConsumer = function;
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
54
eco-util/src/main/java/com/willfp/eco/util/PlayerUtils.java
Normal file
54
eco-util/src/main/java/com/willfp/eco/util/PlayerUtils.java
Normal file
@@ -0,0 +1,54 @@
|
||||
package com.willfp.eco.util;
|
||||
|
||||
import com.willfp.eco.util.optional.Prerequisite;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@UtilityClass
|
||||
public class PlayerUtils {
|
||||
/**
|
||||
* If the meta set function has been set.
|
||||
*/
|
||||
private boolean initialized = false;
|
||||
|
||||
/**
|
||||
* The cooldown function.
|
||||
*/
|
||||
private Function<Player, Double> cooldownFunction = null;
|
||||
|
||||
/**
|
||||
* Get the attack cooldown for a player.
|
||||
*
|
||||
* @param player The player's attack cooldown.
|
||||
* @return A value between 0 and 1, with 1 representing full power.
|
||||
*/
|
||||
public double getAttackCooldown(@NotNull final Player player) {
|
||||
Validate.isTrue(initialized, "Must be initialized!");
|
||||
Validate.notNull(cooldownFunction, "Must be initialized!");
|
||||
|
||||
if (Prerequisite.MINIMUM_1_16.isMet()) {
|
||||
return player.getAttackCooldown();
|
||||
}
|
||||
|
||||
return cooldownFunction.apply(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the cooldown function.
|
||||
*
|
||||
* @param function The function.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public void initialize(@NotNull final Function<Player, Double> function) {
|
||||
Validate.isTrue(!initialized, "Already initialized!");
|
||||
|
||||
cooldownFunction = function;
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
49
eco-util/src/main/java/com/willfp/eco/util/SkullUtils.java
Normal file
49
eco-util/src/main/java/com/willfp/eco/util/SkullUtils.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package com.willfp.eco.util;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
@UtilityClass
|
||||
public class SkullUtils {
|
||||
/**
|
||||
* If the meta set function has been set.
|
||||
*/
|
||||
private boolean initialized = false;
|
||||
|
||||
/**
|
||||
* The meta set function.
|
||||
*/
|
||||
private BiConsumer<SkullMeta, String> metaSetConsumer = null;
|
||||
|
||||
/**
|
||||
* Set the texture of a skull from base64.
|
||||
*
|
||||
* @param meta The meta to modify.
|
||||
* @param base64 The base64 texture.
|
||||
*/
|
||||
public void setSkullTexture(@NotNull final SkullMeta meta,
|
||||
@NotNull final String base64) {
|
||||
Validate.isTrue(initialized, "Must be initialized!");
|
||||
Validate.notNull(metaSetConsumer, "Must be initialized!");
|
||||
|
||||
metaSetConsumer.accept(meta, base64);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the skull texture function.
|
||||
*
|
||||
* @param function The function.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public void initialize(@NotNull final BiConsumer<SkullMeta, String> function) {
|
||||
Validate.isTrue(!initialized, "Already initialized!");
|
||||
|
||||
metaSetConsumer = function;
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
49
eco-util/src/main/java/com/willfp/eco/util/TridentUtils.java
Normal file
49
eco-util/src/main/java/com/willfp/eco/util/TridentUtils.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package com.willfp.eco.util;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.entity.Trident;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@UtilityClass
|
||||
public class TridentUtils {
|
||||
/**
|
||||
* If the meta set function has been set.
|
||||
*/
|
||||
private boolean initialized = false;
|
||||
|
||||
/**
|
||||
* The meta set function.
|
||||
*/
|
||||
private Function<Trident, ItemStack> tridentFunction = null;
|
||||
|
||||
/**
|
||||
* Get a trident's ItemStack.
|
||||
*
|
||||
* @param trident The trident to query.
|
||||
* @return The trident's ItemStack.
|
||||
*/
|
||||
public ItemStack getItemStack(@NotNull final Trident trident) {
|
||||
Validate.isTrue(initialized, "Must be initialized!");
|
||||
Validate.notNull(tridentFunction, "Must be initialized!");
|
||||
|
||||
return tridentFunction.apply(trident);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the trident function.
|
||||
*
|
||||
* @param function The function.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public void initialize(@NotNull final Function<Trident, ItemStack> function) {
|
||||
Validate.isTrue(!initialized, "Already initialized!");
|
||||
|
||||
tridentFunction = function;
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.willfp.eco.util.bukkit.keys;
|
||||
|
||||
import com.willfp.eco.util.internal.PluginDependentFactory;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class NamespacedKeyFactory extends PluginDependentFactory {
|
||||
public class NamespacedKeyFactory extends PluginDependent {
|
||||
/**
|
||||
* Factory class to produce {@link NamespacedKey}s associated with an {@link AbstractEcoPlugin}.
|
||||
*
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.willfp.eco.util.bukkit.meta;
|
||||
|
||||
import com.willfp.eco.util.internal.PluginDependentFactory;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MetadataValueFactory extends PluginDependentFactory {
|
||||
public class MetadataValueFactory extends PluginDependent {
|
||||
/**
|
||||
* Factory class to produce {@link FixedMetadataValue}s associated with an {@link AbstractEcoPlugin}.
|
||||
*
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package com.willfp.eco.util.bukkit.scheduling;
|
||||
|
||||
import com.willfp.eco.util.internal.PluginDependentFactory;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class RunnableFactory extends PluginDependentFactory {
|
||||
public class RunnableFactory extends PluginDependent {
|
||||
/**
|
||||
* Factory class to produce {@link EcoBukkitRunnable}s associated with an {@link AbstractEcoPlugin}.
|
||||
*
|
||||
|
||||
@@ -12,7 +12,8 @@ public interface Scheduler {
|
||||
* @param ticksLater The amount of ticks to wait before execution.
|
||||
* @return The created {@link BukkitTask}.
|
||||
*/
|
||||
BukkitTask runLater(@NotNull Runnable runnable, long ticksLater);
|
||||
BukkitTask runLater(@NotNull Runnable runnable,
|
||||
long ticksLater);
|
||||
|
||||
/**
|
||||
* Run the task repeatedly on a timer.
|
||||
@@ -22,7 +23,9 @@ public interface Scheduler {
|
||||
* @param repeat The amount of ticks to wait between executions.
|
||||
* @return The created {@link BukkitTask}.
|
||||
*/
|
||||
BukkitTask runTimer(@NotNull Runnable runnable, long delay, long repeat);
|
||||
BukkitTask runTimer(@NotNull Runnable runnable,
|
||||
long delay,
|
||||
long repeat);
|
||||
|
||||
/**
|
||||
* Run the task repeatedly and asynchronously on a timer.
|
||||
@@ -32,7 +35,9 @@ public interface Scheduler {
|
||||
* @param repeat The amount of ticks to wait between executions.
|
||||
* @return The created {@link BukkitTask}.
|
||||
*/
|
||||
BukkitTask runAsyncTimer(@NotNull Runnable runnable, long delay, long repeat);
|
||||
BukkitTask runAsyncTimer(@NotNull Runnable runnable,
|
||||
long delay,
|
||||
long repeat);
|
||||
|
||||
/**
|
||||
* Run the task.
|
||||
@@ -58,7 +63,9 @@ public interface Scheduler {
|
||||
* @param repeat The amount of ticks to wait between executions.
|
||||
* @return The id of the task.
|
||||
*/
|
||||
int syncRepeating(@NotNull Runnable runnable, long delay, long repeat);
|
||||
int syncRepeating(@NotNull Runnable runnable,
|
||||
long delay,
|
||||
long repeat);
|
||||
|
||||
/**
|
||||
* Cancel all running tasks from the linked {@link AbstractEcoPlugin}.
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.willfp.eco.util.bukkit.scheduling;
|
||||
|
||||
public interface TimedRunnable extends Runnable {
|
||||
/**
|
||||
* The TimedRunnable interface is generally used for repeating tasks.
|
||||
* This method is to retrieve the ticks between repetitions.
|
||||
*
|
||||
* @return The ticks between repetitions.
|
||||
*/
|
||||
long getTime();
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.willfp.eco.util.command;
|
||||
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.interfaces.Registerable;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
@@ -15,7 +14,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractCommand extends PluginDependent implements CommandExecutor, Registerable {
|
||||
public abstract class AbstractCommand extends PluginDependent implements CommandExecutor {
|
||||
/**
|
||||
* The name of the command
|
||||
* <p>
|
||||
@@ -130,7 +129,6 @@ public abstract class AbstractCommand extends PluginDependent implements Command
|
||||
* <p>
|
||||
* Requires the command name to exist, defined in plugin.yml.
|
||||
*/
|
||||
@Override
|
||||
public final void register() {
|
||||
PluginCommand command = Bukkit.getPluginCommand(name);
|
||||
assert command != null;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.willfp.eco.util.config;
|
||||
|
||||
import com.willfp.eco.util.config.internal.AbstractUpdatableConfig;
|
||||
import com.willfp.eco.internal.config.AbstractUpdatableConfig;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.willfp.eco.util.config;
|
||||
|
||||
import com.willfp.eco.util.config.internal.AbstractUpdatableConfig;
|
||||
import com.willfp.eco.internal.config.AbstractUpdatableConfig;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.willfp.eco.util.config;
|
||||
|
||||
import com.willfp.eco.util.config.internal.AbstractConfig;
|
||||
import com.willfp.eco.internal.config.AbstractConfig;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package com.willfp.eco.util.config;
|
||||
|
||||
@Deprecated
|
||||
public interface ValueGetter {
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.willfp.eco.util.config.configs;
|
||||
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import com.willfp.eco.util.config.BaseConfig;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -21,7 +20,7 @@ public class Lang extends BaseConfig {
|
||||
* @return The prefix.
|
||||
*/
|
||||
public String getPrefix() {
|
||||
return StringUtils.translate(this.getConfig().getString("messages.prefix"));
|
||||
return this.getString("messages.prefix");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -30,7 +29,7 @@ public class Lang extends BaseConfig {
|
||||
* @return The message.
|
||||
*/
|
||||
public String getNoPermission() {
|
||||
return getPrefix() + StringUtils.translate(this.getConfig().getString("messages.no-permission"));
|
||||
return getPrefix() + this.getString("messages.no-permission");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,6 +39,6 @@ public class Lang extends BaseConfig {
|
||||
* @return The message with a prefix appended.
|
||||
*/
|
||||
public String getMessage(@NotNull final String message) {
|
||||
return getPrefix() + StringUtils.translate(this.getConfig().getString("messages." + message));
|
||||
return getPrefix() + this.getString("messages." + message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,25 +14,23 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@UtilityClass
|
||||
public class Display {
|
||||
/**
|
||||
* Registered display functions.
|
||||
* The prefix for lore lines.
|
||||
*/
|
||||
private static final List<Map<String, Function<ItemStack, ItemStack>>> DISPLAY_FUNCTIONS = new ArrayList<>(10000);
|
||||
public static final String PREFIX = "§z";
|
||||
|
||||
/**
|
||||
* Registered revert functions.
|
||||
* All registered display modules.
|
||||
*/
|
||||
private static final List<Function<ItemStack, ItemStack>> REVERT_FUNCTIONS = new ArrayList<>();
|
||||
private static final Map<DisplayPriority, List<DisplayModule>> MODULES = new HashMap<>();
|
||||
|
||||
/**
|
||||
* NamespacedKey for finalizing.
|
||||
*/
|
||||
private static NamespacedKey finalizeKey;
|
||||
private static NamespacedKey finalizeKey = null;
|
||||
|
||||
/**
|
||||
* Register display module.
|
||||
@@ -40,30 +38,11 @@ public class Display {
|
||||
* @param module The module.
|
||||
*/
|
||||
public void registerDisplayModule(@NotNull final DisplayModule module) {
|
||||
int priority = module.getPriority();
|
||||
if (priority > 9999) {
|
||||
priority = 9999;
|
||||
}
|
||||
Function<ItemStack, ItemStack> function = module.getFunction();
|
||||
List<DisplayModule> modules = MODULES.get(module.getPriority());
|
||||
|
||||
Map<String, Function<ItemStack, ItemStack>> functions = DISPLAY_FUNCTIONS.get(priority);
|
||||
if (functions == null) {
|
||||
functions = new HashMap<>();
|
||||
}
|
||||
modules.add(module);
|
||||
|
||||
functions.remove(module.getId());
|
||||
functions.put(module.getId(), function);
|
||||
|
||||
DISPLAY_FUNCTIONS.set(priority, functions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register revert function.
|
||||
*
|
||||
* @param function The function.
|
||||
*/
|
||||
public void registerRevertModule(@NotNull final Function<ItemStack, ItemStack> function) {
|
||||
REVERT_FUNCTIONS.add(function);
|
||||
MODULES.put(module.getPriority(), modules);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,13 +59,20 @@ public class Display {
|
||||
|
||||
revert(itemStack);
|
||||
|
||||
for (Map<String, Function<ItemStack, ItemStack>> displayFunctions : DISPLAY_FUNCTIONS) {
|
||||
if (displayFunctions == null) {
|
||||
continue;
|
||||
}
|
||||
if (!itemStack.hasItemMeta()) {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
for (Function<ItemStack, ItemStack> displayFunction : displayFunctions.values()) {
|
||||
displayFunction.apply(itemStack);
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
|
||||
if (meta == null) {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
for (DisplayPriority priority : DisplayPriority.values()) {
|
||||
List<DisplayModule> modules = MODULES.get(priority);
|
||||
for (DisplayModule module : modules) {
|
||||
module.display(itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,8 +101,33 @@ public class Display {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
for (Function<ItemStack, ItemStack> displayFunction : REVERT_FUNCTIONS) {
|
||||
displayFunction.apply(itemStack);
|
||||
if (!itemStack.hasItemMeta()) {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
|
||||
if (meta == null) {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
List<String> lore = meta.getLore();
|
||||
|
||||
if (lore == null) {
|
||||
lore = new ArrayList<>();
|
||||
}
|
||||
|
||||
lore.removeIf(line -> line.startsWith(Display.PREFIX));
|
||||
|
||||
meta.setLore(lore);
|
||||
|
||||
itemStack.setItemMeta(meta);
|
||||
|
||||
for (DisplayPriority priority : DisplayPriority.values()) {
|
||||
List<DisplayModule> modules = MODULES.get(priority);
|
||||
for (DisplayModule module : modules) {
|
||||
module.revert(itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
return itemStack;
|
||||
@@ -130,13 +141,16 @@ public class Display {
|
||||
*/
|
||||
public ItemStack finalize(@NotNull final ItemStack itemStack) {
|
||||
Validate.notNull(finalizeKey, "Key cannot be null!");
|
||||
|
||||
if (itemStack.getType().getMaxStackSize() > 1) {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
if (meta == null) {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
container.set(finalizeKey, PersistentDataType.INTEGER, 1);
|
||||
itemStack.setItemMeta(meta);
|
||||
@@ -151,10 +165,13 @@ public class Display {
|
||||
*/
|
||||
public ItemStack unfinalize(@NotNull final ItemStack itemStack) {
|
||||
Validate.notNull(finalizeKey, "Key cannot be null!");
|
||||
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
|
||||
if (meta == null) {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
container.remove(finalizeKey);
|
||||
itemStack.setItemMeta(meta);
|
||||
@@ -169,37 +186,17 @@ public class Display {
|
||||
*/
|
||||
public boolean isFinalized(@NotNull final ItemStack itemStack) {
|
||||
Validate.notNull(finalizeKey, "Key cannot be null!");
|
||||
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
|
||||
if (meta == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
return container.has(finalizeKey, PersistentDataType.INTEGER);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Register finalize function.
|
||||
*
|
||||
* @param function The function.
|
||||
* @deprecated Not needed.
|
||||
*/
|
||||
@Deprecated
|
||||
public void registerFinalizeModule(@NotNull final Function<ItemStack, ItemStack> function) {
|
||||
// This function is not needed.
|
||||
}
|
||||
|
||||
/**
|
||||
* Register finalize test function.
|
||||
*
|
||||
* @param function The function.
|
||||
* @deprecated Not needed.
|
||||
*/
|
||||
@Deprecated
|
||||
public void registerFinalizeTestModule(@NotNull final Predicate<ItemStack> function) {
|
||||
// This isn't needed.
|
||||
}
|
||||
|
||||
/**
|
||||
* Set key to be used for finalization.
|
||||
*
|
||||
@@ -211,8 +208,8 @@ public class Display {
|
||||
}
|
||||
|
||||
static {
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
DISPLAY_FUNCTIONS.add(null);
|
||||
for (DisplayPriority priority : DisplayPriority.values()) {
|
||||
MODULES.put(priority, new ArrayList<>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,42 +1,41 @@
|
||||
package com.willfp.eco.util.display;
|
||||
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public class DisplayModule {
|
||||
public abstract class DisplayModule extends PluginDependent {
|
||||
/**
|
||||
* Priority of the display module, where lower numbers are executed sooner.
|
||||
* The priority of the module.
|
||||
*/
|
||||
@Getter
|
||||
private final int priority;
|
||||
private final DisplayPriority priority;
|
||||
|
||||
/**
|
||||
* The function executed on display.
|
||||
*/
|
||||
@Getter
|
||||
private final Function<ItemStack, ItemStack> function;
|
||||
|
||||
/**
|
||||
* Function id for unregistration.
|
||||
*/
|
||||
@Getter
|
||||
private final String id;
|
||||
|
||||
/**
|
||||
* Create new display module.
|
||||
* Create a new display module.
|
||||
*
|
||||
* @param function The function.
|
||||
* @param priority The priority.
|
||||
* @param id The id.
|
||||
* @param plugin The plugin that the display is for.
|
||||
* @param priority The priority of the module.
|
||||
*/
|
||||
public DisplayModule(@NotNull final Function<ItemStack, ItemStack> function,
|
||||
final int priority,
|
||||
@NotNull final String id) {
|
||||
this.function = function;
|
||||
protected DisplayModule(@NotNull final AbstractEcoPlugin plugin,
|
||||
@NotNull final DisplayPriority priority) {
|
||||
super(plugin);
|
||||
this.priority = priority;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display an item.
|
||||
*
|
||||
* @param itemStack The item.
|
||||
*/
|
||||
protected abstract void display(@NotNull ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* Revert an item.
|
||||
*
|
||||
* @param itemStack The item.
|
||||
*/
|
||||
protected abstract void revert(@NotNull ItemStack itemStack);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.willfp.eco.util.display;
|
||||
|
||||
public enum DisplayPriority {
|
||||
/**
|
||||
* Ran first.
|
||||
*/
|
||||
LOWEST,
|
||||
|
||||
/**
|
||||
* Ran second.
|
||||
*/
|
||||
LOW,
|
||||
|
||||
/**
|
||||
* Ran third.
|
||||
*/
|
||||
HIGH,
|
||||
|
||||
/**
|
||||
* Ran last.
|
||||
*/
|
||||
HIGHEST
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.willfp.eco.util.drops;
|
||||
|
||||
import com.willfp.eco.util.drops.internal.AbstractDropQueue;
|
||||
import com.willfp.eco.util.drops.internal.DropManager;
|
||||
import com.willfp.eco.util.drops.internal.DropQueueType;
|
||||
import com.willfp.eco.util.drops.internal.FastCollatedDropQueue;
|
||||
import com.willfp.eco.util.drops.internal.InternalDropQueue;
|
||||
import com.willfp.eco.internal.drops.AbstractDropQueue;
|
||||
import com.willfp.eco.internal.drops.DropManager;
|
||||
import com.willfp.eco.internal.drops.DropQueueType;
|
||||
import com.willfp.eco.internal.drops.impl.FastCollatedDropQueue;
|
||||
import com.willfp.eco.internal.drops.impl.InternalDropQueue;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@@ -122,6 +122,6 @@ public class ArmorEquipEvent extends PlayerEvent implements Cancellable {
|
||||
/**
|
||||
* When you die causing all armor to unequip
|
||||
*/
|
||||
DEATH;
|
||||
DEATH
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
package com.willfp.eco.util.interfaces;
|
||||
|
||||
public interface EcoRunnable extends Runnable {
|
||||
/**
|
||||
* The EcoRunnable interface is generally used for repeating tasks.
|
||||
* This method is to retrieve the ticks between repetitions.
|
||||
*
|
||||
* @return The ticks between repetitions.
|
||||
*/
|
||||
long getTime();
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package com.willfp.eco.util.interfaces;
|
||||
|
||||
public interface Registerable {
|
||||
/**
|
||||
* Register an object with its respective registry.
|
||||
*/
|
||||
void register();
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.willfp.eco.util.internal;
|
||||
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public abstract class PluginDependentFactory extends PluginDependent {
|
||||
protected PluginDependentFactory(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.willfp.eco.util.optional;
|
||||
|
||||
import com.willfp.eco.util.ClassUtils;
|
||||
import com.willfp.eco.util.proxy.ProxyConstants;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -20,7 +20,7 @@ public class Prerequisite {
|
||||
* Requires the server to be running minecraft version 1.16 or higher.
|
||||
*/
|
||||
public static final Prerequisite MINIMUM_1_16 = new Prerequisite(
|
||||
() -> !Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3].contains("15"),
|
||||
() -> !ProxyConstants.NMS_VERSION.contains("15"),
|
||||
"Requires minimum server version of 1.16"
|
||||
);
|
||||
|
||||
|
||||
@@ -1,29 +1,28 @@
|
||||
package com.willfp.eco.util.plugin;
|
||||
|
||||
import com.willfp.eco.util.ClassUtils;
|
||||
import com.willfp.eco.util.arrows.ArrowDataListener;
|
||||
import com.willfp.eco.util.bukkit.events.EcoEventManager;
|
||||
import com.willfp.eco.internal.arrows.ArrowDataListener;
|
||||
import com.willfp.eco.internal.bukkit.events.EcoEventManager;
|
||||
import com.willfp.eco.internal.bukkit.logging.EcoLogger;
|
||||
import com.willfp.eco.internal.bukkit.scheduling.EcoScheduler;
|
||||
import com.willfp.eco.internal.extensions.EcoExtensionLoader;
|
||||
import com.willfp.eco.util.bukkit.events.EventManager;
|
||||
import com.willfp.eco.util.bukkit.keys.NamespacedKeyFactory;
|
||||
import com.willfp.eco.util.bukkit.logging.EcoLogger;
|
||||
import com.willfp.eco.util.bukkit.logging.Logger;
|
||||
import com.willfp.eco.util.bukkit.meta.MetadataValueFactory;
|
||||
import com.willfp.eco.util.bukkit.scheduling.EcoScheduler;
|
||||
import com.willfp.eco.util.bukkit.scheduling.RunnableFactory;
|
||||
import com.willfp.eco.util.bukkit.scheduling.Scheduler;
|
||||
import com.willfp.eco.util.command.AbstractCommand;
|
||||
import com.willfp.eco.util.config.configs.Config;
|
||||
import com.willfp.eco.util.config.configs.Lang;
|
||||
import com.willfp.eco.util.config.updating.ConfigHandler;
|
||||
import com.willfp.eco.util.extensions.loader.EcoExtensionLoader;
|
||||
import com.willfp.eco.util.display.Display;
|
||||
import com.willfp.eco.util.display.DisplayModule;
|
||||
import com.willfp.eco.util.extensions.loader.ExtensionLoader;
|
||||
import com.willfp.eco.util.integrations.IntegrationLoader;
|
||||
import com.willfp.eco.util.integrations.placeholder.PlaceholderManager;
|
||||
import com.willfp.eco.util.integrations.placeholder.plugins.PlaceholderIntegrationPAPI;
|
||||
import com.willfp.eco.util.optional.Prerequisite;
|
||||
import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
|
||||
import com.willfp.eco.util.recipe.RecipeListener;
|
||||
import com.willfp.eco.util.recipe.RecipeManager;
|
||||
import com.willfp.eco.util.updater.UpdateChecker;
|
||||
import lombok.Getter;
|
||||
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
||||
@@ -33,6 +32,7 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -41,7 +41,6 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
/**
|
||||
* Loaded eco plugins.
|
||||
@@ -142,12 +141,6 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
@Getter
|
||||
private final RunnableFactory runnableFactory;
|
||||
|
||||
/**
|
||||
* Recipe handler for crafting recipes.
|
||||
*/
|
||||
@Getter
|
||||
private final RecipeManager recipeManager;
|
||||
|
||||
/**
|
||||
* The loader for all plugin extensions.
|
||||
*
|
||||
@@ -162,6 +155,12 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
@Getter
|
||||
private final ConfigHandler configHandler;
|
||||
|
||||
/**
|
||||
* The display module for the plugin.
|
||||
*/
|
||||
@Getter
|
||||
private DisplayModule displayModule;
|
||||
|
||||
/**
|
||||
* If the server is running an outdated version of the plugin.
|
||||
*/
|
||||
@@ -196,7 +195,6 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
this.runnableFactory = new RunnableFactory(this);
|
||||
this.extensionLoader = new EcoExtensionLoader(this);
|
||||
this.configHandler = new ConfigHandler(this);
|
||||
this.recipeManager = new RecipeManager(this);
|
||||
|
||||
this.langYml = new Lang(this);
|
||||
this.configYml = new Config(this);
|
||||
@@ -215,7 +213,6 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
this.getLog().info("Loading " + this.color + this.pluginName);
|
||||
|
||||
this.getEventManager().registerListener(new ArrowDataListener(this));
|
||||
this.getEventManager().registerListener(new RecipeListener(this));
|
||||
|
||||
new UpdateChecker(this).getVersion(version -> {
|
||||
DefaultArtifactVersion currentVersion = new DefaultArtifactVersion(this.getDescription().getVersion());
|
||||
@@ -298,14 +295,18 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
* Default code to be executed after the server is up.
|
||||
*/
|
||||
public final void afterLoad() {
|
||||
if (ClassUtils.exists("com.comphenix.protocol.events.PacketAdapter")) {
|
||||
this.getPacketAdapters().forEach(abstractPacketAdapter -> {
|
||||
if (abstractPacketAdapter.isPostLoad()) {
|
||||
abstractPacketAdapter.register();
|
||||
}
|
||||
});
|
||||
this.displayModule = createDisplayModule();
|
||||
|
||||
if (this.getDisplayModule() != null) {
|
||||
Display.registerDisplayModule(this.getDisplayModule());
|
||||
}
|
||||
|
||||
this.getPacketAdapters().forEach(abstractPacketAdapter -> {
|
||||
if (abstractPacketAdapter.isPostLoad()) {
|
||||
abstractPacketAdapter.register();
|
||||
}
|
||||
});
|
||||
|
||||
if (!Prerequisite.HAS_PAPER.isMet()) {
|
||||
this.getLog().error("");
|
||||
this.getLog().error("----------------------------");
|
||||
@@ -401,4 +402,12 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
* @return A list of all updatable classes.
|
||||
*/
|
||||
public abstract List<Class<?>> getUpdatableClasses();
|
||||
|
||||
/**
|
||||
* Create the display module for the plugin.
|
||||
*
|
||||
* @return The display module, or null.
|
||||
*/
|
||||
@Nullable
|
||||
protected abstract DisplayModule createDisplayModule();
|
||||
}
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
package com.willfp.eco.util.recipe;
|
||||
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.CraftItemEvent;
|
||||
import org.bukkit.event.inventory.PrepareItemCraftEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class RecipeListener extends PluginDependent implements Listener {
|
||||
/**
|
||||
* Pass an {@link AbstractEcoPlugin} in order to interface with it.
|
||||
*
|
||||
* @param plugin The plugin to manage.
|
||||
*/
|
||||
public RecipeListener(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on item craft.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
public void prepareCraftListener(@NotNull final PrepareItemCraftEvent event) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
||||
|
||||
if (!recipe.getKey().getNamespace().equals(this.getPlugin().getPluginName().toLowerCase())) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack[] matrix = event.getInventory().getMatrix();
|
||||
EcoShapedRecipe matched = this.getPlugin().getRecipeManager().getMatch(matrix);
|
||||
|
||||
if (matched == null) {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
return;
|
||||
}
|
||||
|
||||
if (matched.test(matrix)) {
|
||||
event.getInventory().setResult(matched.getOutput());
|
||||
} else {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on item craft.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
public void craftListener(@NotNull final CraftItemEvent event) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
||||
|
||||
if (!recipe.getKey().getNamespace().equals(this.getPlugin().getPluginName().toLowerCase())) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack[] matrix = event.getInventory().getMatrix();
|
||||
EcoShapedRecipe matched = this.getPlugin().getRecipeManager().getMatch(matrix);
|
||||
|
||||
if (matched == null) {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (matched.test(matrix)) {
|
||||
event.getInventory().setResult(matched.getOutput());
|
||||
} else {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.willfp.eco.util.recipe;
|
||||
|
||||
import com.willfp.eco.util.recipe.parts.EmptyRecipePart;
|
||||
import com.willfp.eco.util.recipe.parts.RecipePart;
|
||||
import com.willfp.eco.util.recipe.parts.SimpleRecipePart;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@UtilityClass
|
||||
@SuppressWarnings("deprecation")
|
||||
public final class RecipeParts {
|
||||
/**
|
||||
* All recipe parts.
|
||||
*/
|
||||
private static final Map<NamespacedKey, RecipePart> PARTS = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Register a new recipe part.
|
||||
*
|
||||
* @param key The key of the recipe part.
|
||||
* @param part The recipe part.
|
||||
*/
|
||||
public void registerRecipePart(@NotNull final NamespacedKey key,
|
||||
@NotNull final RecipePart part) {
|
||||
PARTS.put(key, part);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup recipe part from string.
|
||||
*
|
||||
* @param key The string to test.
|
||||
* @return The found recipe part, or null if not found.
|
||||
*/
|
||||
public RecipePart lookup(@NotNull final String key) {
|
||||
String[] split = key.toLowerCase().split(":");
|
||||
if (split.length == 1) {
|
||||
Material material = Material.getMaterial(key.toUpperCase());
|
||||
if (material == null || material == Material.AIR) {
|
||||
return new EmptyRecipePart();
|
||||
}
|
||||
return new SimpleRecipePart(material);
|
||||
}
|
||||
|
||||
RecipePart part = PARTS.get(new NamespacedKey(split[0], split[1]));
|
||||
return part == null ? new EmptyRecipePart() : part;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if itemStack is a recipe part (used to check for custom items).
|
||||
*
|
||||
* @param itemStack The itemStack to check.
|
||||
* @return If is recipe.
|
||||
*/
|
||||
public boolean isRecipePart(@NotNull final ItemStack itemStack) {
|
||||
return PARTS.values().stream().anyMatch(recipePart -> recipePart.matches(itemStack));
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,8 @@ package com.willfp.eco.util.recipe;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.util.recipe.recipes.EcoShapedRecipe;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -12,40 +12,34 @@ import org.bukkit.inventory.ShapedRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@UtilityClass
|
||||
@SuppressWarnings("deprecation")
|
||||
public class RecipeManager extends PluginDependent {
|
||||
public class Recipes {
|
||||
/**
|
||||
* Registry of all recipes.
|
||||
*/
|
||||
private final BiMap<String, EcoShapedRecipe> registry = HashBiMap.create();
|
||||
private static final BiMap<NamespacedKey, EcoShapedRecipe> RECIPES = HashBiMap.create();
|
||||
|
||||
|
||||
/**
|
||||
* Pass an {@link AbstractEcoPlugin} in order to interface with it.
|
||||
* Register a recipe.
|
||||
*
|
||||
* @param plugin The plugin to manage.
|
||||
* @param recipe The recipe.
|
||||
*/
|
||||
public RecipeManager(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
public void register(@NotNull final EcoShapedRecipe recipe) {
|
||||
RECIPES.forcePut(recipe.getKey(), recipe);
|
||||
|
||||
void register(@NotNull final EcoShapedRecipe recipe) {
|
||||
String key = recipe.getKey();
|
||||
registry.forcePut(key, recipe);
|
||||
Bukkit.getServer().removeRecipe(recipe.getKey());
|
||||
Bukkit.getServer().removeRecipe(recipe.getDisplayedKey());
|
||||
|
||||
NamespacedKey baseKey = this.getPlugin().getNamespacedKeyFactory().create(key);
|
||||
Bukkit.getServer().removeRecipe(baseKey);
|
||||
|
||||
NamespacedKey displayedKey = this.getPlugin().getNamespacedKeyFactory().create(key + "_displayed");
|
||||
Bukkit.getServer().removeRecipe(displayedKey);
|
||||
|
||||
ShapedRecipe shapedRecipe = new ShapedRecipe(baseKey, recipe.getOutput());
|
||||
ShapedRecipe shapedRecipe = new ShapedRecipe(recipe.getKey(), recipe.getOutput());
|
||||
shapedRecipe.shape("012", "345", "678");
|
||||
for (int i = 0; i < 9; i++) {
|
||||
char character = String.valueOf(i).toCharArray()[0];
|
||||
shapedRecipe.setIngredient(character, recipe.getMaterialAtIndex(i));
|
||||
}
|
||||
|
||||
ShapedRecipe displayedRecipe = new ShapedRecipe(displayedKey, recipe.getOutput());
|
||||
ShapedRecipe displayedRecipe = new ShapedRecipe(recipe.getDisplayedKey(), recipe.getOutput());
|
||||
displayedRecipe.shape("012", "345", "678");
|
||||
for (int i = 0; i < 9; i++) {
|
||||
char character = String.valueOf(i).toCharArray()[0];
|
||||
@@ -64,7 +58,7 @@ public class RecipeManager extends PluginDependent {
|
||||
*/
|
||||
@Nullable
|
||||
public EcoShapedRecipe getMatch(@NotNull final ItemStack[] matrix) {
|
||||
return registry.values().stream().filter(recipe -> recipe.test(matrix)).findFirst().orElse(null);
|
||||
return RECIPES.values().stream().filter(recipe -> recipe.test(matrix)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,7 +68,18 @@ public class RecipeManager extends PluginDependent {
|
||||
* @return The shaped recipe, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
public EcoShapedRecipe getShapedRecipe(@NotNull final String key) {
|
||||
return registry.get(key);
|
||||
public EcoShapedRecipe getShapedRecipe(@NotNull final NamespacedKey key) {
|
||||
EcoShapedRecipe recipe = RECIPES.get(key);
|
||||
if (recipe != null) {
|
||||
return recipe;
|
||||
}
|
||||
|
||||
if (key.getKey().contains("_displayed")) {
|
||||
NamespacedKey otherKey = new NamespacedKey(key.getNamespace(), key.getKey().replace("_displayed", ""));
|
||||
|
||||
return RECIPES.get(otherKey);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package com.willfp.eco.util.recipe.lookup;
|
||||
|
||||
import com.willfp.eco.util.recipe.parts.EmptyRecipePart;
|
||||
import com.willfp.eco.util.recipe.parts.RecipePart;
|
||||
import com.willfp.eco.util.recipe.parts.SimpleRecipePart;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Material;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
@UtilityClass
|
||||
public final class RecipePartUtils {
|
||||
/**
|
||||
* All recipes.
|
||||
*/
|
||||
private static final Map<String, Function<String, RecipePart>> TESTS = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Register a new lookup.
|
||||
*
|
||||
* @param key The key of the lookup.
|
||||
* @param lookupFunction The lookup to register, where the output is the recipe part generated.
|
||||
*/
|
||||
public void registerLookup(@NotNull final String key,
|
||||
@NotNull final Function<String, RecipePart> lookupFunction) {
|
||||
TESTS.put(key, lookupFunction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup recipe part from string.
|
||||
*
|
||||
* @param key The string to test.
|
||||
* @return The generated recipe part, or null if invalid.
|
||||
*/
|
||||
public RecipePart lookup(@NotNull final String key) {
|
||||
Function<String, RecipePart> lookup = TESTS.get(key);
|
||||
|
||||
if (lookup == null) {
|
||||
Material material = Material.getMaterial(key.toUpperCase());
|
||||
if (material == null || material == Material.AIR) {
|
||||
return new EmptyRecipePart();
|
||||
}
|
||||
return new SimpleRecipePart(material);
|
||||
}
|
||||
|
||||
return lookup.apply(key);
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,19 @@
|
||||
package com.willfp.eco.util.recipe;
|
||||
package com.willfp.eco.util.recipe.recipes;
|
||||
|
||||
import com.willfp.eco.util.interfaces.Registerable;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.util.recipe.Recipes;
|
||||
import com.willfp.eco.util.recipe.parts.EmptyRecipePart;
|
||||
import com.willfp.eco.util.recipe.parts.RecipePart;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public final class EcoShapedRecipe extends PluginDependent implements Registerable {
|
||||
public final class EcoShapedRecipe extends PluginDependent {
|
||||
/**
|
||||
* Recipe parts.
|
||||
*/
|
||||
@@ -23,7 +24,13 @@ public final class EcoShapedRecipe extends PluginDependent implements Registerab
|
||||
* The key of the recipe.
|
||||
*/
|
||||
@Getter
|
||||
private final String key;
|
||||
private final NamespacedKey key;
|
||||
|
||||
/**
|
||||
* The key of the displayed recipe.
|
||||
*/
|
||||
@Getter
|
||||
private final NamespacedKey displayedKey;
|
||||
|
||||
/**
|
||||
* The recipe's output.
|
||||
@@ -38,7 +45,8 @@ public final class EcoShapedRecipe extends PluginDependent implements Registerab
|
||||
super(plugin);
|
||||
|
||||
this.parts = parts;
|
||||
this.key = key;
|
||||
this.key = plugin.getNamespacedKeyFactory().create(key);
|
||||
this.displayedKey = plugin.getNamespacedKeyFactory().create(key + "_displayed");
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
@@ -82,9 +90,8 @@ public final class EcoShapedRecipe extends PluginDependent implements Registerab
|
||||
/**
|
||||
* Register the recipe.
|
||||
*/
|
||||
@Override
|
||||
public void register() {
|
||||
this.getPlugin().getRecipeManager().register(this);
|
||||
Recipes.register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -193,66 +200,4 @@ public final class EcoShapedRecipe extends PluginDependent implements Registerab
|
||||
return new EcoShapedRecipe(plugin, key.toLowerCase(), recipeParts, output);
|
||||
}
|
||||
}
|
||||
|
||||
public enum RecipePosition {
|
||||
/**
|
||||
* Top left of matrix.
|
||||
*/
|
||||
TOP_LEFT(0),
|
||||
|
||||
/**
|
||||
* Top middle of matrix.
|
||||
*/
|
||||
TOP_MIDDLE(1),
|
||||
|
||||
/**
|
||||
* Top right of matrix.
|
||||
*/
|
||||
TOP_RIGHT(2),
|
||||
|
||||
/**
|
||||
* Middle left of matrix.
|
||||
*/
|
||||
MIDDLE_LEFT(3),
|
||||
|
||||
/**
|
||||
* Middle of matrix.
|
||||
*/
|
||||
MIDDLE(4),
|
||||
|
||||
/**
|
||||
* Middle right of matrix.
|
||||
*/
|
||||
MIDDLE_RIGHT(5),
|
||||
|
||||
/**
|
||||
* Bottom left of matrix.
|
||||
*/
|
||||
BOTTOM_LEFT(6),
|
||||
|
||||
/**
|
||||
* Bottom middle of matrix.
|
||||
*/
|
||||
BOTTOM_MIDDLE(7),
|
||||
|
||||
/**
|
||||
* Bottom right of matrix.
|
||||
*/
|
||||
BOTTOM_RIGHT(8);
|
||||
|
||||
/**
|
||||
* The index within a crafting table matrix.
|
||||
*/
|
||||
@Getter
|
||||
private final int index;
|
||||
|
||||
/**
|
||||
* Recipe position with crafting table index.
|
||||
*
|
||||
* @param index The index.
|
||||
*/
|
||||
RecipePosition(final int index) {
|
||||
this.index = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.willfp.eco.util.recipe.recipes;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
public enum RecipePosition {
|
||||
/**
|
||||
* Top left of matrix.
|
||||
*/
|
||||
TOP_LEFT(0),
|
||||
|
||||
/**
|
||||
* Top middle of matrix.
|
||||
*/
|
||||
TOP_MIDDLE(1),
|
||||
|
||||
/**
|
||||
* Top right of matrix.
|
||||
*/
|
||||
TOP_RIGHT(2),
|
||||
|
||||
/**
|
||||
* Middle left of matrix.
|
||||
*/
|
||||
MIDDLE_LEFT(3),
|
||||
|
||||
/**
|
||||
* Middle of matrix.
|
||||
*/
|
||||
MIDDLE(4),
|
||||
|
||||
/**
|
||||
* Middle right of matrix.
|
||||
*/
|
||||
MIDDLE_RIGHT(5),
|
||||
|
||||
/**
|
||||
* Bottom left of matrix.
|
||||
*/
|
||||
BOTTOM_LEFT(6),
|
||||
|
||||
/**
|
||||
* Bottom middle of matrix.
|
||||
*/
|
||||
BOTTOM_MIDDLE(7),
|
||||
|
||||
/**
|
||||
* Bottom right of matrix.
|
||||
*/
|
||||
BOTTOM_RIGHT(8);
|
||||
|
||||
/**
|
||||
* The index within a crafting table matrix.
|
||||
*/
|
||||
@Getter
|
||||
private final int index;
|
||||
|
||||
/**
|
||||
* Recipe position with crafting table index.
|
||||
*
|
||||
* @param index The index.
|
||||
*/
|
||||
RecipePosition(final int index) {
|
||||
this.index = index;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,12 @@
|
||||
package com.willfp.eco.util.tuplets;
|
||||
package com.willfp.eco.util.tuples;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ToString
|
||||
public class Pair<A, B> {
|
||||
/**
|
||||
* The first value in the pair.
|
||||
* The first item in the tuple.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@@ -16,7 +14,7 @@ public class Pair<A, B> {
|
||||
private A first;
|
||||
|
||||
/**
|
||||
* The second value in the pair.
|
||||
* The second item in the tuple.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.willfp.eco.util.tuples;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class Triplet<A, B, C> extends Pair<A, B> {
|
||||
/**
|
||||
* The third item in the tuple.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Nullable
|
||||
private C third;
|
||||
|
||||
/**
|
||||
* Create a triple of values.
|
||||
*
|
||||
* @param first The first item in the pair.
|
||||
* @param second The second item in the pair.
|
||||
* @param third The third item in the pair.
|
||||
*/
|
||||
public Triplet(@Nullable final A first,
|
||||
@Nullable final B second,
|
||||
@Nullable final C third) {
|
||||
super(first, second);
|
||||
|
||||
this.third = third;
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package com.willfp.eco.util.tuplets;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ToString
|
||||
public class Triplet<A, B, C> {
|
||||
/**
|
||||
* The first item in the triplet.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Nullable
|
||||
private A first;
|
||||
|
||||
/**
|
||||
* The second item in the triplet.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Nullable
|
||||
private B second;
|
||||
|
||||
/**
|
||||
* The third item in the triplet.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Nullable
|
||||
private C third;
|
||||
|
||||
/**
|
||||
* Create a triplet.
|
||||
*
|
||||
* @param first The first item in the triplet.
|
||||
* @param second The second item in the triplet.
|
||||
* @param third The third item in the triplet.
|
||||
*/
|
||||
public Triplet(@Nullable final A first,
|
||||
@Nullable final B second,
|
||||
@Nullable final C third) {
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
this.third = third;
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
version = 3.7.0
|
||||
version = 4.0.0
|
||||
plugin-name = eco
|
||||
Reference in New Issue
Block a user