Compare commits

...

13 Commits
3.7.0 ... 3.8.0

Author SHA1 Message Date
Auxilor
d1307e35db Minor code issues 2021-02-16 19:48:20 +00:00
Auxilor
0a6b197a97 Cleaned various internals 2021-02-16 19:44:34 +00:00
Auxilor
8d6512886c Removed redundant PluginDependentFactory.java 2021-02-16 19:37:55 +00:00
Auxilor
5c0c0f3e2a Refactored Scheduler.java 2021-02-16 19:35:55 +00:00
Auxilor
e2c2fc776a Moved break blocks into block utils 2021-02-16 19:34:26 +00:00
Auxilor
576050b31e Updated to 3.8.0 2021-02-16 19:22:20 +00:00
Auxilor
f9a43bd336 Added trident util initializatoin 2021-02-16 19:17:59 +00:00
Auxilor
203f2f599a Added trident utils 2021-02-16 19:16:48 +00:00
Auxilor
baa5d37744 Added PlayerUtils 2021-02-16 19:11:02 +00:00
Auxilor
17f6af2a70 Added Skull texture setter 2021-02-16 18:07:47 +00:00
Auxilor
eae213f58e More refactoring, splitting api and internal 2021-02-14 16:31:16 +00:00
Auxilor
3a6a133560 Added caching to AbstractConfig 2021-02-14 15:32:10 +00:00
Auxilor
57cf144c57 Refactoring to remove internal components from API 2021-02-14 15:23:42 +00:00
59 changed files with 815 additions and 118 deletions

View File

@@ -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()));
}
}

View File

@@ -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);
}
}

View File

@@ -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();
}
}
}

View File

@@ -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);
}
}

View File

@@ -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()));
}
}

View File

@@ -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();
}
}
}

View File

@@ -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);
}
}

View File

@@ -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()));
}
}

View File

@@ -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();
}
}
}

View File

@@ -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);
}
}

View File

@@ -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()));
}
}

View File

@@ -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();
}
}
}

View File

@@ -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);
}
}

View File

@@ -1,11 +1,18 @@
package com.willfp.eco.spigot; package com.willfp.eco.spigot;
import com.willfp.eco.spigot.display.packets.PacketAutoRecipe; import com.willfp.eco.proxy.proxies.BlockBreakProxy;
import com.willfp.eco.spigot.display.packets.PacketChat; import com.willfp.eco.proxy.proxies.CooldownProxy;
import com.willfp.eco.spigot.display.packets.PacketOpenWindowMerchant; import com.willfp.eco.proxy.proxies.SkullProxy;
import com.willfp.eco.spigot.display.packets.PacketSetCreativeSlot; import com.willfp.eco.proxy.proxies.TridentStackProxy;
import com.willfp.eco.spigot.display.packets.PacketSetSlot; import com.willfp.eco.spigot.display.PacketAutoRecipe;
import com.willfp.eco.spigot.display.packets.PacketWindowItems; 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.AnticheatAAC;
import com.willfp.eco.spigot.integrations.anticheat.AnticheatMatrix; import com.willfp.eco.spigot.integrations.anticheat.AnticheatMatrix;
import com.willfp.eco.spigot.integrations.anticheat.AnticheatNCP; import com.willfp.eco.spigot.integrations.anticheat.AnticheatNCP;
@@ -16,13 +23,14 @@ import com.willfp.eco.spigot.integrations.antigrief.AntigriefLands;
import com.willfp.eco.spigot.integrations.antigrief.AntigriefTowny; import com.willfp.eco.spigot.integrations.antigrief.AntigriefTowny;
import com.willfp.eco.spigot.integrations.antigrief.AntigriefWorldGuard; import com.willfp.eco.spigot.integrations.antigrief.AntigriefWorldGuard;
import com.willfp.eco.spigot.integrations.mcmmo.McmmoIntegrationImpl; import com.willfp.eco.spigot.integrations.mcmmo.McmmoIntegrationImpl;
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.command.AbstractCommand;
import com.willfp.eco.util.display.Display; import com.willfp.eco.util.display.Display;
import com.willfp.eco.util.drops.internal.FastCollatedDropQueue;
import com.willfp.eco.util.events.armorequip.ArmorListener; import com.willfp.eco.util.events.armorequip.ArmorListener;
import com.willfp.eco.util.events.armorequip.DispenserArmorListener; 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.IntegrationLoader;
import com.willfp.eco.util.integrations.anticheat.AnticheatManager; import com.willfp.eco.util.integrations.anticheat.AnticheatManager;
import com.willfp.eco.util.integrations.antigrief.AntigriefManager; import com.willfp.eco.util.integrations.antigrief.AntigriefManager;
@@ -50,11 +58,15 @@ public class EcoPlugin extends AbstractEcoPlugin {
super("eco", 87955, 10043, "com.willfp.eco.proxy", "&a"); super("eco", 87955, 10043, "com.willfp.eco.proxy", "&a");
instance = this; instance = this;
Display.setFinalizeKey(this.getNamespacedKeyFactory().create("finalized")); 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 @Override
public void enable() { public void enable() {
new FastCollatedDropQueue.CollatedRunnable(this); new CollatedRunnable(this);
this.getEventManager().registerListener(new NaturalExpGainListeners()); this.getEventManager().registerListener(new NaturalExpGainListeners());
this.getEventManager().registerListener(new ArmorListener()); this.getEventManager().registerListener(new ArmorListener());
this.getEventManager().registerListener(new DispenserArmorListener()); this.getEventManager().registerListener(new DispenserArmorListener());
@@ -73,7 +85,7 @@ public class EcoPlugin extends AbstractEcoPlugin {
@Override @Override
public void onReload() { public void onReload() {
new FastCollatedDropQueue.CollatedRunnable(this); new CollatedRunnable(this);
} }
@Override @Override

View File

@@ -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.PacketType;
import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolLibrary;

View File

@@ -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.PacketType;
import com.comphenix.protocol.events.ListenerPriority; import com.comphenix.protocol.events.ListenerPriority;

View File

@@ -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.PacketType;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;

View File

@@ -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.PacketType;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;

View File

@@ -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.PacketType;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;

View File

@@ -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.PacketType;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;

View File

@@ -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);
}
}

View File

@@ -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.Getter;
import lombok.Setter; import lombok.Setter;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;

View File

@@ -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.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.eco.util.plugin.AbstractEcoPlugin;

View File

@@ -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.Getter;
import lombok.Setter; import lombok.Setter;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;

View File

@@ -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.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@@ -7,6 +7,7 @@ import org.bukkit.event.player.PlayerExpChangeEvent;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.HashSet; import java.util.HashSet;
import java.util.Objects;
import java.util.Set; import java.util.Set;
public class NaturalExpGainListeners implements Listener { public class NaturalExpGainListeners implements Listener {
@@ -28,9 +29,10 @@ public class NaturalExpGainListeners implements Listener {
NaturalExpGainBuilder toRemove = null; NaturalExpGainBuilder toRemove = null;
for (NaturalExpGainBuilder searchBuilder : events) { for (NaturalExpGainBuilder searchBuilder : events) {
if (!searchBuilder.getLocation().getWorld().equals(event.getPlayer().getLocation().getWorld())) { if (!Objects.equals(searchBuilder.getLocation().getWorld(), event.getPlayer().getLocation().getWorld())) {
continue; continue;
} }
if (searchBuilder.getReason().equals(NaturalExpGainBuilder.BuildReason.BOTTLE) && searchBuilder.getLocation().distanceSquared(event.getPlayer().getLocation()) > 52) { if (searchBuilder.getReason().equals(NaturalExpGainBuilder.BuildReason.BOTTLE) && searchBuilder.getLocation().distanceSquared(event.getPlayer().getLocation()) > 52) {
toRemove = searchBuilder; toRemove = searchBuilder;
} }

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;

View File

@@ -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.StringUtils;
import com.willfp.eco.util.bukkit.logging.Logger;
import com.willfp.eco.util.internal.PluginDependent; import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;

View File

@@ -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.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.drops.internal; package com.willfp.eco.internal.drops;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.drops.internal; package com.willfp.eco.internal.drops;
import lombok.Getter; import lombok.Getter;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.drops.internal; package com.willfp.eco.internal.drops;
public enum DropQueueType { public enum DropQueueType {
/** /**

View File

@@ -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.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.ToString; import lombok.ToString;
@@ -8,8 +8,6 @@ import lombok.experimental.Accessors;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.List; import java.util.List;
@@ -22,7 +20,7 @@ public class FastCollatedDropQueue extends InternalDropQueue {
* <p> * <p>
* Cleared and updated every tick. * 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} * 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 @Override
public void push() { public void push() {
@@ -50,7 +48,7 @@ public class FastCollatedDropQueue extends InternalDropQueue {
* The items, location, and xp linked to a player's drops. * The items, location, and xp linked to a player's drops.
*/ */
@ToString @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. * 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; 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);
}
}
} }

View File

@@ -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 com.willfp.eco.util.drops.telekinesis.TelekinesisUtils;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;

View File

@@ -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.Extension;
import com.willfp.eco.util.extensions.MalformedExtensionException; 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.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import org.apache.commons.lang.Validate;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -94,6 +96,9 @@ public class EcoExtensionLoader extends PluginDependent implements ExtensionLoad
String mainClass = extensionYml.getString("main"); String mainClass = extensionYml.getString("main");
String name = extensionYml.getString("name"); String name = extensionYml.getString("name");
String version = extensionYml.getString("version"); 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); Extension.ExtensionMetadata metadata = new Extension.ExtensionMetadata(version, name);
Class<?> cls; Class<?> cls;

View File

@@ -1,20 +1,33 @@
package com.willfp.eco.util; package com.willfp.eco.util;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import org.apache.commons.lang.Validate;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.function.BiConsumer;
@UtilityClass @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, private Set<Block> getNearbyBlocks(@NotNull final Block start,
@NotNull final List<Material> allowedMaterials, @NotNull final List<Material> allowedMaterials,
@NotNull final HashSet<Block> blocks, @NotNull final Set<Block> blocks,
final int limit) { final int limit) {
for (BlockFace face : BlockFace.values()) { for (BlockFace face : BlockFace.values()) {
Block block = start.getRelative(face); Block block = start.getRelative(face);
@@ -29,7 +42,6 @@ public class BlockUtils {
return blocks; return blocks;
} }
/** /**
* Get a set of all blocks in contact with each other of a specific type. * Get a set of all blocks in contact with each other of a specific type.
* *
@@ -44,4 +56,31 @@ public class BlockUtils {
final int limit) { final int limit) {
return getNearbyBlocks(start, allowedMaterials, new HashSet<>(), 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.
*/
public void initialize(@NotNull final BiConsumer<Player, Block> function) {
Validate.isTrue(!initialized, "Already initialized!");
blockBreakConsumer = function;
initialized = true;
}
} }

View File

@@ -0,0 +1,52 @@
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.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.
*/
public void initialize(@NotNull final Function<Player, Double> function) {
Validate.isTrue(!initialized, "Already initialized!");
cooldownFunction = function;
initialized = true;
}
}

View File

@@ -0,0 +1,47 @@
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.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.
*/
public void initialize(@NotNull final BiConsumer<SkullMeta, String> function) {
Validate.isTrue(!initialized, "Already initialized!");
metaSetConsumer = function;
initialized = true;
}
}

View File

@@ -0,0 +1,47 @@
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.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.
*/
public void initialize(@NotNull final Function<Trident, ItemStack> function) {
Validate.isTrue(!initialized, "Already initialized!");
tridentFunction = function;
initialized = true;
}
}

View File

@@ -1,11 +1,11 @@
package com.willfp.eco.util.bukkit.keys; 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 com.willfp.eco.util.plugin.AbstractEcoPlugin;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.jetbrains.annotations.NotNull; 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}. * Factory class to produce {@link NamespacedKey}s associated with an {@link AbstractEcoPlugin}.
* *

View File

@@ -1,11 +1,11 @@
package com.willfp.eco.util.bukkit.meta; 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 com.willfp.eco.util.plugin.AbstractEcoPlugin;
import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.FixedMetadataValue;
import org.jetbrains.annotations.NotNull; 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}. * Factory class to produce {@link FixedMetadataValue}s associated with an {@link AbstractEcoPlugin}.
* *

View File

@@ -1,12 +1,12 @@
package com.willfp.eco.util.bukkit.scheduling; 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 com.willfp.eco.util.plugin.AbstractEcoPlugin;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer; 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}. * Factory class to produce {@link EcoBukkitRunnable}s associated with an {@link AbstractEcoPlugin}.
* *

View File

@@ -12,7 +12,8 @@ public interface Scheduler {
* @param ticksLater The amount of ticks to wait before execution. * @param ticksLater The amount of ticks to wait before execution.
* @return The created {@link BukkitTask}. * @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. * Run the task repeatedly on a timer.
@@ -22,7 +23,9 @@ public interface Scheduler {
* @param repeat The amount of ticks to wait between executions. * @param repeat The amount of ticks to wait between executions.
* @return The created {@link BukkitTask}. * @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. * 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. * @param repeat The amount of ticks to wait between executions.
* @return The created {@link BukkitTask}. * @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. * Run the task.
@@ -58,7 +63,9 @@ public interface Scheduler {
* @param repeat The amount of ticks to wait between executions. * @param repeat The amount of ticks to wait between executions.
* @return The id of the task. * @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}. * Cancel all running tasks from the linked {@link AbstractEcoPlugin}.

View File

@@ -1,6 +1,5 @@
package com.willfp.eco.util.config.configs; 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.config.BaseConfig;
import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -21,7 +20,7 @@ public class Lang extends BaseConfig {
* @return The prefix. * @return The prefix.
*/ */
public String getPrefix() { 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. * @return The message.
*/ */
public String getNoPermission() { 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. * @return The message with a prefix appended.
*/ */
public String getMessage(@NotNull final String message) { public String getMessage(@NotNull final String message) {
return getPrefix() + StringUtils.translate(this.getConfig().getString("messages." + message)); return getPrefix() + this.getString("messages." + message);
} }
} }

View File

@@ -19,9 +19,12 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
@SuppressWarnings("unchecked")
public abstract class AbstractConfig extends PluginDependent { public abstract class AbstractConfig extends PluginDependent {
/** /**
* The linked {@link YamlConfiguration} where values are physically stored. * The linked {@link YamlConfiguration} where values are physically stored.
@@ -53,6 +56,11 @@ public abstract class AbstractConfig extends PluginDependent {
@Getter(AccessLevel.PROTECTED) @Getter(AccessLevel.PROTECTED)
private final Class<?> source; private final Class<?> source;
/**
* Cached values for faster reading.
*/
private final Map<String, Object> cache = new HashMap<>();
/** /**
* Abstract config. * Abstract config.
* *
@@ -151,6 +159,13 @@ public abstract class AbstractConfig extends PluginDependent {
return newConfig; return newConfig;
} }
/**
* Clears cache.
*/
public final void clearCache() {
cache.clear();
}
/** /**
* Get if the config contains a key. * Get if the config contains a key.
* *
@@ -185,7 +200,12 @@ public abstract class AbstractConfig extends PluginDependent {
*/ */
@Nullable @Nullable
public ConfigurationSection getSectionOrNull(@NotNull final String path) { 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. * @return The found value, or 0 if not found.
*/ */
public int getInt(@NotNull final String path) { 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, public int getInt(@NotNull final String path,
final int def) { 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 @NotNull
public List<Integer> getInts(@NotNull final String path) { 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. * @return The found value, or false if not found.
*/ */
public boolean getBool(@NotNull final String path) { 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 @NotNull
public List<Boolean> getBools(@NotNull final String path) { 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 @NotNull
public String getString(@NotNull final String path) { 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 @NotNull
public List<String> getStrings(@NotNull final String path) { 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. * @return The found value, or 0 if not found.
*/ */
public double getDouble(@NotNull final String path) { 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 @NotNull
public List<Double> getDoubles(@NotNull final String path) { 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);
}
} }
/** /**

View File

@@ -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. * Writes missing values, however removes comments due to how configs are stored internally in bukkit.
*/ */
public void update() { public void update() {
super.clearCache();
try { try {
config.load(this.getConfigFile()); config.load(this.getConfigFile());

View File

@@ -1,10 +1,10 @@
package com.willfp.eco.util.drops; package com.willfp.eco.util.drops;
import com.willfp.eco.util.drops.internal.AbstractDropQueue; import com.willfp.eco.internal.drops.AbstractDropQueue;
import com.willfp.eco.util.drops.internal.DropManager; import com.willfp.eco.internal.drops.DropManager;
import com.willfp.eco.util.drops.internal.DropQueueType; import com.willfp.eco.internal.drops.DropQueueType;
import com.willfp.eco.util.drops.internal.FastCollatedDropQueue; import com.willfp.eco.internal.drops.impl.FastCollatedDropQueue;
import com.willfp.eco.util.drops.internal.InternalDropQueue; import com.willfp.eco.internal.drops.impl.InternalDropQueue;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;

View File

@@ -122,6 +122,6 @@ public class ArmorEquipEvent extends PlayerEvent implements Cancellable {
/** /**
* When you die causing all armor to unequip * When you die causing all armor to unequip
*/ */
DEATH; DEATH
} }
} }

View File

@@ -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);
}
}

View File

@@ -1,8 +1,8 @@
package com.willfp.eco.util.optional; package com.willfp.eco.util.optional;
import com.willfp.eco.util.ClassUtils; import com.willfp.eco.util.ClassUtils;
import com.willfp.eco.util.proxy.ProxyConstants;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
@@ -20,7 +20,7 @@ public class Prerequisite {
* Requires the server to be running minecraft version 1.16 or higher. * Requires the server to be running minecraft version 1.16 or higher.
*/ */
public static final Prerequisite MINIMUM_1_16 = new Prerequisite( 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" "Requires minimum server version of 1.16"
); );

View File

@@ -1,21 +1,21 @@
package com.willfp.eco.util.plugin; package com.willfp.eco.util.plugin;
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.util.ClassUtils; import com.willfp.eco.util.ClassUtils;
import com.willfp.eco.util.arrows.ArrowDataListener; import com.willfp.eco.util.arrows.ArrowDataListener;
import com.willfp.eco.util.bukkit.events.EcoEventManager;
import com.willfp.eco.util.bukkit.events.EventManager; import com.willfp.eco.util.bukkit.events.EventManager;
import com.willfp.eco.util.bukkit.keys.NamespacedKeyFactory; 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.logging.Logger;
import com.willfp.eco.util.bukkit.meta.MetadataValueFactory; 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.RunnableFactory;
import com.willfp.eco.util.bukkit.scheduling.Scheduler; import com.willfp.eco.util.bukkit.scheduling.Scheduler;
import com.willfp.eco.util.command.AbstractCommand; import com.willfp.eco.util.command.AbstractCommand;
import com.willfp.eco.util.config.configs.Config; import com.willfp.eco.util.config.configs.Config;
import com.willfp.eco.util.config.configs.Lang; import com.willfp.eco.util.config.configs.Lang;
import com.willfp.eco.util.config.updating.ConfigHandler; import com.willfp.eco.util.config.updating.ConfigHandler;
import com.willfp.eco.util.extensions.loader.EcoExtensionLoader; import com.willfp.eco.internal.extensions.EcoExtensionLoader;
import com.willfp.eco.util.extensions.loader.ExtensionLoader; import com.willfp.eco.util.extensions.loader.ExtensionLoader;
import com.willfp.eco.util.integrations.IntegrationLoader; import com.willfp.eco.util.integrations.IntegrationLoader;
import com.willfp.eco.util.integrations.placeholder.PlaceholderManager; import com.willfp.eco.util.integrations.placeholder.PlaceholderManager;
@@ -41,7 +41,6 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@SuppressWarnings("unchecked")
public abstract class AbstractEcoPlugin extends JavaPlugin { public abstract class AbstractEcoPlugin extends JavaPlugin {
/** /**
* Loaded eco plugins. * Loaded eco plugins.

View File

@@ -0,0 +1,17 @@
package com.willfp.eco.util.tuples;
import org.jetbrains.annotations.Nullable;
@SuppressWarnings("deprecation")
public class Pair<A, B> extends com.willfp.eco.util.tuplets.Pair<A, B> {
/**
* Create a pair of values.
*
* @param first The first item in the pair.
* @param second The second item in the pair.
*/
public Pair(@Nullable final A first,
@Nullable final B second) {
super(first, second);
}
}

View File

@@ -0,0 +1,19 @@
package com.willfp.eco.util.tuples;
import org.jetbrains.annotations.Nullable;
@SuppressWarnings("deprecation")
public class Triplet<A, B, C> extends com.willfp.eco.util.tuplets.Triplet<A, B, C> {
/**
* 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, third);
}
}

View File

@@ -5,7 +5,9 @@ import lombok.Setter;
import lombok.ToString; import lombok.ToString;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@SuppressWarnings("DeprecatedIsStillUsed")
@ToString @ToString
@Deprecated
public class Pair<A, B> { public class Pair<A, B> {
/** /**
* The first value in the pair. * The first value in the pair.
@@ -25,6 +27,8 @@ public class Pair<A, B> {
/** /**
* Create a pair of values. * Create a pair of values.
* <p>
* This is deprecated because I forgot how to spell Tuples before putting this into production.
* *
* @param first The first item in the pair. * @param first The first item in the pair.
* @param second The second item in the pair. * @param second The second item in the pair.

View File

@@ -5,7 +5,9 @@ import lombok.Setter;
import lombok.ToString; import lombok.ToString;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@SuppressWarnings("DeprecatedIsStillUsed")
@ToString @ToString
@Deprecated
public class Triplet<A, B, C> { public class Triplet<A, B, C> {
/** /**
* The first item in the triplet. * The first item in the triplet.
@@ -33,6 +35,8 @@ public class Triplet<A, B, C> {
/** /**
* Create a triplet. * Create a triplet.
* <p>
* This is deprecated because I forgot how to spell Tuples before putting this into production.
* *
* @param first The first item in the triplet. * @param first The first item in the triplet.
* @param second The second item in the triplet. * @param second The second item in the triplet.

View File

@@ -1,2 +1,2 @@
version = 3.7.0 version = 3.8.0
plugin-name = eco plugin-name = eco