Compare commits
48 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b5c3af752c | ||
|
|
d0366b39e2 | ||
|
|
ed5390d2b5 | ||
|
|
e31857a15d | ||
|
|
32e119d187 | ||
|
|
5690eccd14 | ||
|
|
2faf3732df | ||
|
|
8670fb36e0 | ||
|
|
7c001c4809 | ||
|
|
bce1dd9fee | ||
|
|
412c2e1e3c | ||
|
|
dd7ffac974 | ||
|
|
7ad59e0166 | ||
|
|
2f2bdbb9f5 | ||
|
|
d23dc10bc5 | ||
|
|
46c2e3f90a | ||
|
|
1776b668a4 | ||
|
|
10dccd0f38 | ||
|
|
f1918eb1ec | ||
|
|
436b33fde2 | ||
|
|
cfa5cab1fa | ||
|
|
a8ba4dd812 | ||
|
|
94bf383d23 | ||
|
|
096207de82 | ||
|
|
3cb654f5df | ||
|
|
5552cc4fb0 | ||
|
|
94aacf8cca | ||
|
|
128d473b33 | ||
|
|
d5679dd58f | ||
|
|
b1e8165ecb | ||
|
|
d0a3d644f3 | ||
|
|
35b060af53 | ||
|
|
337dba23b4 | ||
|
|
433f9f53ab | ||
|
|
ba7a748efd | ||
|
|
1365fdae88 | ||
|
|
6a159bf049 | ||
|
|
31e0e93951 | ||
|
|
876343facb | ||
|
|
f0cd9ae16d | ||
|
|
b220428b8c | ||
|
|
8386aacfd8 | ||
|
|
3c54e24102 | ||
|
|
3dc0693b8c | ||
|
|
f087113ddf | ||
|
|
d5d1f5d8cc | ||
|
|
0d5bf901e2 | ||
|
|
ae0445f47b |
@@ -25,7 +25,7 @@ allprojects {
|
|||||||
// NMS (for jitpack compilation)
|
// NMS (for jitpack compilation)
|
||||||
maven { url 'https://repo.codemc.org/repository/nms/' }
|
maven { url 'https://repo.codemc.org/repository/nms/' }
|
||||||
|
|
||||||
// bStats
|
// bStats, mcMMO
|
||||||
maven { url 'https://repo.codemc.org/repository/maven-public' }
|
maven { url 'https://repo.codemc.org/repository/maven-public' }
|
||||||
|
|
||||||
// Spigot API
|
// Spigot API
|
||||||
@@ -69,6 +69,7 @@ allprojects {
|
|||||||
exclude group: "org.kitteh", module: "paste-gg-api"
|
exclude group: "org.kitteh", module: "paste-gg-api"
|
||||||
exclude group: "org.spongepowered", module: "configurate-hocon"
|
exclude group: "org.spongepowered", module: "configurate-hocon"
|
||||||
exclude group: "com.darkblade12", module: "particleeffect"
|
exclude group: "com.darkblade12", module: "particleeffect"
|
||||||
|
exclude group: "com.github.cryptomorin", module: "XSeries"
|
||||||
}
|
}
|
||||||
|
|
||||||
shadowJar {
|
shadowJar {
|
||||||
|
|||||||
@@ -115,7 +115,6 @@
|
|||||||
<!-- Checks for imports -->
|
<!-- Checks for imports -->
|
||||||
<!-- See https://checkstyle.org/config_imports.html -->
|
<!-- See https://checkstyle.org/config_imports.html -->
|
||||||
<module name="AvoidStarImport"/>
|
<module name="AvoidStarImport"/>
|
||||||
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
|
|
||||||
<module name="RedundantImport"/>
|
<module name="RedundantImport"/>
|
||||||
<module name="UnusedImports">
|
<module name="UnusedImports">
|
||||||
<property name="processJavadoc" value="true"/>
|
<property name="processJavadoc" value="true"/>
|
||||||
|
|||||||
@@ -9,16 +9,11 @@ import org.bukkit.inventory.MerchantRecipe;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
|
|
||||||
public final class VillagerTrade implements VillagerTradeProxy {
|
public final class VillagerTrade implements VillagerTradeProxy {
|
||||||
@Override
|
@Override
|
||||||
public void displayTrade(@NotNull final MerchantRecipe merchantRecipe) {
|
public void displayTrade(@NotNull final MerchantRecipe merchantRecipe) {
|
||||||
try {
|
try {
|
||||||
// Enables removing final modifier
|
|
||||||
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
|
||||||
modifiersField.setAccessible(true);
|
|
||||||
|
|
||||||
// Bukkit MerchantRecipe result
|
// Bukkit MerchantRecipe result
|
||||||
Field fResult = MerchantRecipe.class.getDeclaredField("result");
|
Field fResult = MerchantRecipe.class.getDeclaredField("result");
|
||||||
fResult.setAccessible(true);
|
fResult.setAccessible(true);
|
||||||
@@ -31,11 +26,9 @@ public final class VillagerTrade implements VillagerTradeProxy {
|
|||||||
Field fHandle = CraftMerchantRecipe.class.getDeclaredField("handle");
|
Field fHandle = CraftMerchantRecipe.class.getDeclaredField("handle");
|
||||||
fHandle.setAccessible(true);
|
fHandle.setAccessible(true);
|
||||||
net.minecraft.server.v1_15_R1.MerchantRecipe handle = (net.minecraft.server.v1_15_R1.MerchantRecipe) fHandle.get(merchantRecipe); // NMS Recipe
|
net.minecraft.server.v1_15_R1.MerchantRecipe handle = (net.minecraft.server.v1_15_R1.MerchantRecipe) fHandle.get(merchantRecipe); // NMS Recipe
|
||||||
modifiersField.setInt(fHandle, fHandle.getModifiers() & ~Modifier.FINAL); // Remove final
|
|
||||||
|
|
||||||
Field fSelling = net.minecraft.server.v1_15_R1.MerchantRecipe.class.getDeclaredField("sellingItem");
|
Field fSelling = net.minecraft.server.v1_15_R1.MerchantRecipe.class.getDeclaredField("sellingItem");
|
||||||
fSelling.setAccessible(true);
|
fSelling.setAccessible(true);
|
||||||
modifiersField.setInt(fSelling, fSelling.getModifiers() & ~Modifier.FINAL);
|
|
||||||
|
|
||||||
ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem);
|
ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem);
|
||||||
Display.displayAndFinalize(selling);
|
Display.displayAndFinalize(selling);
|
||||||
|
|||||||
@@ -9,16 +9,11 @@ import org.bukkit.inventory.MerchantRecipe;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
|
|
||||||
public final class VillagerTrade implements VillagerTradeProxy {
|
public final class VillagerTrade implements VillagerTradeProxy {
|
||||||
@Override
|
@Override
|
||||||
public void displayTrade(@NotNull final MerchantRecipe merchantRecipe) {
|
public void displayTrade(@NotNull final MerchantRecipe merchantRecipe) {
|
||||||
try {
|
try {
|
||||||
// Enables removing final modifier
|
|
||||||
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
|
||||||
modifiersField.setAccessible(true);
|
|
||||||
|
|
||||||
// Bukkit MerchantRecipe result
|
// Bukkit MerchantRecipe result
|
||||||
Field fResult = MerchantRecipe.class.getDeclaredField("result");
|
Field fResult = MerchantRecipe.class.getDeclaredField("result");
|
||||||
fResult.setAccessible(true);
|
fResult.setAccessible(true);
|
||||||
@@ -30,11 +25,9 @@ public final class VillagerTrade implements VillagerTradeProxy {
|
|||||||
Field fHandle = CraftMerchantRecipe.class.getDeclaredField("handle");
|
Field fHandle = CraftMerchantRecipe.class.getDeclaredField("handle");
|
||||||
fHandle.setAccessible(true);
|
fHandle.setAccessible(true);
|
||||||
net.minecraft.server.v1_16_R1.MerchantRecipe handle = (net.minecraft.server.v1_16_R1.MerchantRecipe) fHandle.get(merchantRecipe); // NMS Recipe
|
net.minecraft.server.v1_16_R1.MerchantRecipe handle = (net.minecraft.server.v1_16_R1.MerchantRecipe) fHandle.get(merchantRecipe); // NMS Recipe
|
||||||
modifiersField.setInt(fHandle, fHandle.getModifiers() & ~Modifier.FINAL); // Remove final
|
|
||||||
|
|
||||||
Field fSelling = net.minecraft.server.v1_16_R1.MerchantRecipe.class.getDeclaredField("sellingItem");
|
Field fSelling = net.minecraft.server.v1_16_R1.MerchantRecipe.class.getDeclaredField("sellingItem");
|
||||||
fSelling.setAccessible(true);
|
fSelling.setAccessible(true);
|
||||||
modifiersField.setInt(fSelling, fSelling.getModifiers() & ~Modifier.FINAL);
|
|
||||||
|
|
||||||
ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem);
|
ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem);
|
||||||
Display.displayAndFinalize(selling);
|
Display.displayAndFinalize(selling);
|
||||||
|
|||||||
@@ -9,16 +9,11 @@ import org.bukkit.inventory.MerchantRecipe;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
|
|
||||||
public final class VillagerTrade implements VillagerTradeProxy {
|
public final class VillagerTrade implements VillagerTradeProxy {
|
||||||
@Override
|
@Override
|
||||||
public void displayTrade(@NotNull final MerchantRecipe merchantRecipe) {
|
public void displayTrade(@NotNull final MerchantRecipe merchantRecipe) {
|
||||||
try {
|
try {
|
||||||
// Enables removing final modifier
|
|
||||||
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
|
||||||
modifiersField.setAccessible(true);
|
|
||||||
|
|
||||||
// Bukkit MerchantRecipe result
|
// Bukkit MerchantRecipe result
|
||||||
Field fResult = MerchantRecipe.class.getDeclaredField("result");
|
Field fResult = MerchantRecipe.class.getDeclaredField("result");
|
||||||
fResult.setAccessible(true);
|
fResult.setAccessible(true);
|
||||||
@@ -30,11 +25,9 @@ public final class VillagerTrade implements VillagerTradeProxy {
|
|||||||
Field fHandle = CraftMerchantRecipe.class.getDeclaredField("handle");
|
Field fHandle = CraftMerchantRecipe.class.getDeclaredField("handle");
|
||||||
fHandle.setAccessible(true);
|
fHandle.setAccessible(true);
|
||||||
net.minecraft.server.v1_16_R2.MerchantRecipe handle = (net.minecraft.server.v1_16_R2.MerchantRecipe) fHandle.get(merchantRecipe); // NMS Recipe
|
net.minecraft.server.v1_16_R2.MerchantRecipe handle = (net.minecraft.server.v1_16_R2.MerchantRecipe) fHandle.get(merchantRecipe); // NMS Recipe
|
||||||
modifiersField.setInt(fHandle, fHandle.getModifiers() & ~Modifier.FINAL); // Remove final
|
|
||||||
|
|
||||||
Field fSelling = net.minecraft.server.v1_16_R2.MerchantRecipe.class.getDeclaredField("sellingItem");
|
Field fSelling = net.minecraft.server.v1_16_R2.MerchantRecipe.class.getDeclaredField("sellingItem");
|
||||||
fSelling.setAccessible(true);
|
fSelling.setAccessible(true);
|
||||||
modifiersField.setInt(fSelling, fSelling.getModifiers() & ~Modifier.FINAL);
|
|
||||||
|
|
||||||
ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem);
|
ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem);
|
||||||
Display.displayAndFinalize(selling);
|
Display.displayAndFinalize(selling);
|
||||||
|
|||||||
@@ -9,16 +9,11 @@ import org.bukkit.inventory.MerchantRecipe;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
|
|
||||||
public final class VillagerTrade implements VillagerTradeProxy {
|
public final class VillagerTrade implements VillagerTradeProxy {
|
||||||
@Override
|
@Override
|
||||||
public void displayTrade(@NotNull final MerchantRecipe merchantRecipe) {
|
public void displayTrade(@NotNull final MerchantRecipe merchantRecipe) {
|
||||||
try {
|
try {
|
||||||
// Enables removing final modifier
|
|
||||||
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
|
||||||
modifiersField.setAccessible(true);
|
|
||||||
|
|
||||||
// Bukkit MerchantRecipe result
|
// Bukkit MerchantRecipe result
|
||||||
Field fResult = MerchantRecipe.class.getDeclaredField("result");
|
Field fResult = MerchantRecipe.class.getDeclaredField("result");
|
||||||
fResult.setAccessible(true);
|
fResult.setAccessible(true);
|
||||||
@@ -29,12 +24,10 @@ public final class VillagerTrade implements VillagerTradeProxy {
|
|||||||
// Get NMS MerchantRecipe from CraftMerchantRecipe
|
// Get NMS MerchantRecipe from CraftMerchantRecipe
|
||||||
Field fHandle = CraftMerchantRecipe.class.getDeclaredField("handle");
|
Field fHandle = CraftMerchantRecipe.class.getDeclaredField("handle");
|
||||||
fHandle.setAccessible(true);
|
fHandle.setAccessible(true);
|
||||||
net.minecraft.server.v1_16_R3.MerchantRecipe handle = (net.minecraft.server.v1_16_R3.MerchantRecipe) fHandle.get(merchantRecipe); // NMS Recipe
|
net.minecraft.server.v1_16_R3.MerchantRecipe handle = (net.minecraft.server.v1_16_R3.MerchantRecipe) fHandle.get(merchantRecipe); // NMS RecipeR
|
||||||
modifiersField.setInt(fHandle, fHandle.getModifiers() & ~Modifier.FINAL); // Remove final
|
|
||||||
|
|
||||||
Field fSelling = net.minecraft.server.v1_16_R3.MerchantRecipe.class.getDeclaredField("sellingItem");
|
Field fSelling = net.minecraft.server.v1_16_R3.MerchantRecipe.class.getDeclaredField("sellingItem");
|
||||||
fSelling.setAccessible(true);
|
fSelling.setAccessible(true);
|
||||||
modifiersField.setInt(fSelling, fSelling.getModifiers() & ~Modifier.FINAL);
|
|
||||||
|
|
||||||
ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem);
|
ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem);
|
||||||
Display.displayAndFinalize(selling);
|
Display.displayAndFinalize(selling);
|
||||||
|
|||||||
@@ -9,11 +9,12 @@ dependencies {
|
|||||||
compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.4-SNAPSHOT'
|
compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.4-SNAPSHOT'
|
||||||
compileOnly 'com.github.TechFortress:GriefPrevention:16.14.0'
|
compileOnly 'com.github.TechFortress:GriefPrevention:16.14.0'
|
||||||
compileOnly 'com.massivecraft:Factions:1.6.9.5-U0.5.10'
|
compileOnly 'com.massivecraft:Factions:1.6.9.5-U0.5.10'
|
||||||
compileOnly 'com.github.cryptomorin:kingdoms:1.10.3.1'
|
compileOnly 'com.github.cryptomorin:kingdoms:1.10.14'
|
||||||
compileOnly 'com.github.TownyAdvanced:Towny:0.96.2.0'
|
compileOnly 'com.github.TownyAdvanced:Towny:0.96.2.0'
|
||||||
compileOnly 'com.github.angeschossen:LandsAPI:4.7.3'
|
compileOnly 'com.github.angeschossen:LandsAPI:4.7.3'
|
||||||
compileOnly 'fr.neatmonster:nocheatplus:3.16.1-SNAPSHOT'
|
compileOnly 'fr.neatmonster:nocheatplus:3.16.1-SNAPSHOT'
|
||||||
compileOnly 'com.github.jiangdashao:matrix-api-repo:317d4635fd'
|
compileOnly 'com.github.jiangdashao:matrix-api-repo:317d4635fd'
|
||||||
|
compileOnly 'com.gmail.nossr50.mcMMO:mcMMO:2.1.157'
|
||||||
compileOnly fileTree(dir: '../../lib', include: ['*.jar'])
|
compileOnly fileTree(dir: '../../lib', include: ['*.jar'])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,16 +6,18 @@ import com.willfp.eco.spigot.display.packets.PacketOpenWindowMerchant;
|
|||||||
import com.willfp.eco.spigot.display.packets.PacketSetCreativeSlot;
|
import com.willfp.eco.spigot.display.packets.PacketSetCreativeSlot;
|
||||||
import com.willfp.eco.spigot.display.packets.PacketSetSlot;
|
import com.willfp.eco.spigot.display.packets.PacketSetSlot;
|
||||||
import com.willfp.eco.spigot.display.packets.PacketWindowItems;
|
import com.willfp.eco.spigot.display.packets.PacketWindowItems;
|
||||||
import com.willfp.eco.spigot.integrations.anticheat.plugins.AnticheatAAC;
|
import com.willfp.eco.spigot.integrations.anticheat.AnticheatAAC;
|
||||||
import com.willfp.eco.spigot.integrations.anticheat.plugins.AnticheatMatrix;
|
import com.willfp.eco.spigot.integrations.anticheat.AnticheatMatrix;
|
||||||
import com.willfp.eco.spigot.integrations.anticheat.plugins.AnticheatNCP;
|
import com.willfp.eco.spigot.integrations.anticheat.AnticheatNCP;
|
||||||
import com.willfp.eco.spigot.integrations.antigrief.plugins.AntigriefFactionsUUID;
|
import com.willfp.eco.spigot.integrations.antigrief.AntigriefFactionsUUID;
|
||||||
import com.willfp.eco.spigot.integrations.antigrief.plugins.AntigriefGriefPrevention;
|
import com.willfp.eco.spigot.integrations.antigrief.AntigriefGriefPrevention;
|
||||||
import com.willfp.eco.spigot.integrations.antigrief.plugins.AntigriefKingdoms;
|
import com.willfp.eco.spigot.integrations.antigrief.AntigriefKingdoms;
|
||||||
import com.willfp.eco.spigot.integrations.antigrief.plugins.AntigriefLands;
|
import com.willfp.eco.spigot.integrations.antigrief.AntigriefLands;
|
||||||
import com.willfp.eco.spigot.integrations.antigrief.plugins.AntigriefTowny;
|
import com.willfp.eco.spigot.integrations.antigrief.AntigriefTowny;
|
||||||
import com.willfp.eco.spigot.integrations.antigrief.plugins.AntigriefWorldGuard;
|
import com.willfp.eco.spigot.integrations.antigrief.AntigriefWorldGuard;
|
||||||
|
import com.willfp.eco.spigot.integrations.mcmmo.McmmoIntegrationImpl;
|
||||||
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.drops.internal.FastCollatedDropQueue;
|
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;
|
||||||
@@ -24,9 +26,9 @@ 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;
|
||||||
|
import com.willfp.eco.util.integrations.mcmmo.McmmoManager;
|
||||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||||
import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
|
import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
|
||||||
import com.willfp.eco.util.recipe.RecipeListener;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
@@ -47,6 +49,7 @@ public class EcoPlugin extends AbstractEcoPlugin {
|
|||||||
public EcoPlugin() {
|
public EcoPlugin() {
|
||||||
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"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -56,7 +59,6 @@ public class EcoPlugin extends AbstractEcoPlugin {
|
|||||||
this.getEventManager().registerListener(new ArmorListener());
|
this.getEventManager().registerListener(new ArmorListener());
|
||||||
this.getEventManager().registerListener(new DispenserArmorListener());
|
this.getEventManager().registerListener(new DispenserArmorListener());
|
||||||
this.getEventManager().registerListener(new EntityDeathByEntityListeners(this));
|
this.getEventManager().registerListener(new EntityDeathByEntityListeners(this));
|
||||||
this.getEventManager().registerListener(new RecipeListener(this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -93,7 +95,10 @@ public class EcoPlugin extends AbstractEcoPlugin {
|
|||||||
// Anticheat
|
// Anticheat
|
||||||
new IntegrationLoader("AAC5", () -> AnticheatManager.register(this, new AnticheatAAC())),
|
new IntegrationLoader("AAC5", () -> AnticheatManager.register(this, new AnticheatAAC())),
|
||||||
new IntegrationLoader("Matrix", () -> AnticheatManager.register(this, new AnticheatMatrix())),
|
new IntegrationLoader("Matrix", () -> AnticheatManager.register(this, new AnticheatMatrix())),
|
||||||
new IntegrationLoader("NoCheatPlus", () -> AnticheatManager.register(this, new AnticheatNCP()))
|
new IntegrationLoader("NoCheatPlus", () -> AnticheatManager.register(this, new AnticheatNCP())),
|
||||||
|
|
||||||
|
// Misc
|
||||||
|
new IntegrationLoader("mcMMO", () -> McmmoManager.register(new McmmoIntegrationImpl()))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.willfp.eco.spigot.integrations.anticheat.plugins;
|
package com.willfp.eco.spigot.integrations.anticheat;
|
||||||
|
|
||||||
import com.willfp.eco.util.integrations.anticheat.AnticheatWrapper;
|
import com.willfp.eco.util.integrations.anticheat.AnticheatWrapper;
|
||||||
import me.konsolas.aac.api.AACAPI;
|
import me.konsolas.aac.api.AACAPI;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.willfp.eco.spigot.integrations.anticheat.plugins;
|
package com.willfp.eco.spigot.integrations.anticheat;
|
||||||
|
|
||||||
import com.willfp.eco.util.integrations.anticheat.AnticheatWrapper;
|
import com.willfp.eco.util.integrations.anticheat.AnticheatWrapper;
|
||||||
import me.rerere.matrix.api.events.PlayerViolationEvent;
|
import me.rerere.matrix.api.events.PlayerViolationEvent;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.willfp.eco.spigot.integrations.anticheat.plugins;
|
package com.willfp.eco.spigot.integrations.anticheat;
|
||||||
|
|
||||||
import com.willfp.eco.util.integrations.anticheat.AnticheatWrapper;
|
import com.willfp.eco.util.integrations.anticheat.AnticheatWrapper;
|
||||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.willfp.eco.spigot.integrations.anticheat.plugins;
|
package com.willfp.eco.spigot.integrations.anticheat;
|
||||||
|
|
||||||
import com.willfp.eco.util.integrations.anticheat.AnticheatWrapper;
|
import com.willfp.eco.util.integrations.anticheat.AnticheatWrapper;
|
||||||
import me.vagdedes.spartan.api.PlayerViolationEvent;
|
import me.vagdedes.spartan.api.PlayerViolationEvent;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.willfp.eco.spigot.integrations.antigrief.plugins;
|
package com.willfp.eco.spigot.integrations.antigrief;
|
||||||
|
|
||||||
import com.massivecraft.factions.Board;
|
import com.massivecraft.factions.Board;
|
||||||
import com.massivecraft.factions.FLocation;
|
import com.massivecraft.factions.FLocation;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.willfp.eco.spigot.integrations.antigrief.plugins;
|
package com.willfp.eco.spigot.integrations.antigrief;
|
||||||
|
|
||||||
import com.willfp.eco.util.integrations.antigrief.AntigriefWrapper;
|
import com.willfp.eco.util.integrations.antigrief.AntigriefWrapper;
|
||||||
import me.ryanhamshire.GriefPrevention.Claim;
|
import me.ryanhamshire.GriefPrevention.Claim;
|
||||||
@@ -1,26 +1,43 @@
|
|||||||
package com.willfp.eco.spigot.integrations.antigrief.plugins;
|
package com.willfp.eco.spigot.integrations.antigrief;
|
||||||
|
|
||||||
import com.willfp.eco.util.integrations.antigrief.AntigriefWrapper;
|
import com.willfp.eco.util.integrations.antigrief.AntigriefWrapper;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
|
||||||
import org.bukkit.inventory.EquipmentSlot;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.kingdoms.constants.kingdom.Kingdom;
|
import org.kingdoms.constants.kingdom.Kingdom;
|
||||||
|
import org.kingdoms.constants.kingdom.model.KingdomRelation;
|
||||||
import org.kingdoms.constants.land.Land;
|
import org.kingdoms.constants.land.Land;
|
||||||
|
import org.kingdoms.constants.player.DefaultKingdomPermission;
|
||||||
|
import org.kingdoms.constants.player.KingdomPlayer;
|
||||||
import org.kingdoms.managers.PvPManager;
|
import org.kingdoms.managers.PvPManager;
|
||||||
import org.kingdoms.managers.land.LandManager;
|
|
||||||
|
|
||||||
public class AntigriefKingdoms implements AntigriefWrapper {
|
public class AntigriefKingdoms implements AntigriefWrapper {
|
||||||
@Override
|
@Override
|
||||||
public boolean canBreakBlock(@NotNull final Player player,
|
public boolean canBreakBlock(@NotNull final Player player,
|
||||||
@NotNull final Block block) {
|
@NotNull final Block block) {
|
||||||
BlockBreakEvent event = new BlockBreakEvent(block, player);
|
KingdomPlayer kp = KingdomPlayer.getKingdomPlayer(player);
|
||||||
LandManager.onBreak(event);
|
if (kp.isAdmin()) {
|
||||||
return !event.isCancelled();
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Kingdom kingdom = kp.getKingdom();
|
||||||
|
if (kingdom == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Land land = Land.getLand(block);
|
||||||
|
|
||||||
|
if (land == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
DefaultKingdomPermission permission = land.isNexusLand() ? DefaultKingdomPermission.NEXUS_BUILD : DefaultKingdomPermission.BUILD;
|
||||||
|
if (!kp.hasPermission(permission)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return kingdom.hasAttribute(land.getKingdom(), KingdomRelation.Attribute.BUILD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -41,10 +58,7 @@ public class AntigriefKingdoms implements AntigriefWrapper {
|
|||||||
@Override
|
@Override
|
||||||
public boolean canPlaceBlock(@NotNull final Player player,
|
public boolean canPlaceBlock(@NotNull final Player player,
|
||||||
@NotNull final Block block) {
|
@NotNull final Block block) {
|
||||||
Block placedOn = block.getRelative(0, -1, 0);
|
return canBreakBlock(player, block);
|
||||||
BlockPlaceEvent event = new BlockPlaceEvent(block, block.getState(), placedOn, player.getInventory().getItemInMainHand(), player, true, EquipmentSlot.HAND);
|
|
||||||
LandManager.onPlace(event);
|
|
||||||
return !event.isCancelled();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.willfp.eco.spigot.integrations.antigrief.plugins;
|
package com.willfp.eco.spigot.integrations.antigrief;
|
||||||
|
|
||||||
import com.willfp.eco.util.integrations.antigrief.AntigriefWrapper;
|
import com.willfp.eco.util.integrations.antigrief.AntigriefWrapper;
|
||||||
import com.willfp.eco.util.internal.PluginDependent;
|
import com.willfp.eco.util.internal.PluginDependent;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.willfp.eco.spigot.integrations.antigrief.plugins;
|
package com.willfp.eco.spigot.integrations.antigrief;
|
||||||
|
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
import com.palmergames.bukkit.towny.object.TownyPermission;
|
import com.palmergames.bukkit.towny.object.TownyPermission;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.willfp.eco.spigot.integrations.antigrief.plugins;
|
package com.willfp.eco.spigot.integrations.antigrief;
|
||||||
|
|
||||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
import com.sk89q.worldguard.LocalPlayer;
|
import com.sk89q.worldguard.LocalPlayer;
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.willfp.eco.spigot.integrations.mcmmo;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.datatypes.meta.BonusDropMeta;
|
||||||
|
import com.gmail.nossr50.events.fake.FakeEvent;
|
||||||
|
import com.gmail.nossr50.mcMMO;
|
||||||
|
import com.willfp.eco.util.integrations.mcmmo.McmmoWrapper;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class McmmoIntegrationImpl implements McmmoWrapper {
|
||||||
|
@Override
|
||||||
|
public int getBonusDropCount(@NotNull final Block block) {
|
||||||
|
if (block.getMetadata(mcMMO.BONUS_DROPS_METAKEY).size() > 0) {
|
||||||
|
BonusDropMeta bonusDropMeta = (BonusDropMeta) block.getMetadata(mcMMO.BONUS_DROPS_METAKEY).get(0);
|
||||||
|
return bonusDropMeta.asInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isFake(@NotNull final Event event) {
|
||||||
|
return event instanceof FakeEvent;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@ website: willfp.com
|
|||||||
loadbefore:
|
loadbefore:
|
||||||
- EcoEnchants
|
- EcoEnchants
|
||||||
- Talismans
|
- Talismans
|
||||||
- ItemStats
|
- StatTrackers
|
||||||
- EcoArmor
|
- EcoArmor
|
||||||
- Illusioner
|
- Illusioner
|
||||||
depend:
|
depend:
|
||||||
@@ -24,3 +24,4 @@ softdepend:
|
|||||||
- Matrix
|
- Matrix
|
||||||
- Spartan
|
- Spartan
|
||||||
- PlaceholderAPI
|
- PlaceholderAPI
|
||||||
|
- mcMMO
|
||||||
@@ -2,6 +2,7 @@ package com.willfp.eco.util;
|
|||||||
|
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.SoundCategory;
|
import org.bukkit.SoundCategory;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -37,25 +38,32 @@ public class DurabilityUtils {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(item.getItemMeta() instanceof Damageable)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Special edge case
|
||||||
|
if (item.getType() == Material.CARVED_PUMPKIN || item.getType() == Material.PLAYER_HEAD) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
PlayerItemDamageEvent event3 = new PlayerItemDamageEvent(player, item, damage);
|
PlayerItemDamageEvent event3 = new PlayerItemDamageEvent(player, item, damage);
|
||||||
Bukkit.getPluginManager().callEvent(event3);
|
Bukkit.getPluginManager().callEvent(event3);
|
||||||
|
|
||||||
if (!event3.isCancelled()) {
|
if (!event3.isCancelled()) {
|
||||||
int damage2 = event3.getDamage();
|
int damage2 = event3.getDamage();
|
||||||
if (item.getItemMeta() instanceof Damageable) {
|
Damageable meta = (Damageable) item.getItemMeta();
|
||||||
Damageable meta = (Damageable) item.getItemMeta();
|
meta.setDamage(meta.getDamage() + damage2);
|
||||||
meta.setDamage(meta.getDamage() + damage2);
|
|
||||||
|
|
||||||
if (meta.getDamage() >= item.getType().getMaxDurability()) {
|
if (meta.getDamage() >= item.getType().getMaxDurability()) {
|
||||||
meta.setDamage(item.getType().getMaxDurability());
|
meta.setDamage(item.getType().getMaxDurability());
|
||||||
item.setItemMeta((ItemMeta) meta);
|
item.setItemMeta((ItemMeta) meta);
|
||||||
PlayerItemBreakEvent event = new PlayerItemBreakEvent(player, item);
|
PlayerItemBreakEvent event = new PlayerItemBreakEvent(player, item);
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
player.getInventory().clear(slot);
|
player.getInventory().clear(slot);
|
||||||
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, SoundCategory.BLOCKS, 1, 1);
|
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, SoundCategory.BLOCKS, 1, 1);
|
||||||
} else {
|
} else {
|
||||||
item.setItemMeta((ItemMeta) meta);
|
item.setItemMeta((ItemMeta) meta);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,20 +86,22 @@ public class DurabilityUtils {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(item.getItemMeta() instanceof Damageable)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
PlayerItemDamageEvent event3 = new PlayerItemDamageEvent(player, item, damage);
|
PlayerItemDamageEvent event3 = new PlayerItemDamageEvent(player, item, damage);
|
||||||
Bukkit.getPluginManager().callEvent(event3);
|
Bukkit.getPluginManager().callEvent(event3);
|
||||||
|
|
||||||
if (!event3.isCancelled()) {
|
if (!event3.isCancelled()) {
|
||||||
int damage2 = event3.getDamage();
|
int damage2 = event3.getDamage();
|
||||||
if (item.getItemMeta() instanceof Damageable) {
|
Damageable meta = (Damageable) item.getItemMeta();
|
||||||
Damageable meta = (Damageable) item.getItemMeta();
|
meta.setDamage(meta.getDamage() + damage2);
|
||||||
meta.setDamage(meta.getDamage() + damage2);
|
|
||||||
|
|
||||||
if (meta.getDamage() >= item.getType().getMaxDurability()) {
|
if (meta.getDamage() >= item.getType().getMaxDurability()) {
|
||||||
meta.setDamage(item.getType().getMaxDurability() - 1);
|
meta.setDamage(item.getType().getMaxDurability() - 1);
|
||||||
}
|
|
||||||
item.setItemMeta((ItemMeta) meta);
|
|
||||||
}
|
}
|
||||||
|
item.setItemMeta((ItemMeta) meta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@@ -25,7 +23,12 @@ public class StringUtils {
|
|||||||
/**
|
/**
|
||||||
* Regex for gradients.
|
* Regex for gradients.
|
||||||
*/
|
*/
|
||||||
private static final String GRADIENT_REGEX = "<\\$#[A-Fa-f0-9]{6}>";
|
private static final Pattern GRADIENT_REGEX = Pattern.compile("<GRADIENT:([0-9A-Fa-f]{6})>(.*?)</GRADIENT:([0-9A-Fa-f]{6})>");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regex for hex codes.
|
||||||
|
*/
|
||||||
|
private static final Pattern HEX_PATTERN = Pattern.compile("&#" + "([A-Fa-f0-9]{6})" + "");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translate a string - converts Placeholders and Color codes.
|
* Translate a string - converts Placeholders and Color codes.
|
||||||
@@ -58,8 +61,7 @@ public class StringUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static String translateHexColorCodes(@NotNull final String message) {
|
private static String translateHexColorCodes(@NotNull final String message) {
|
||||||
Pattern hexPattern = Pattern.compile("&#" + "([A-Fa-f0-9]{6})" + "");
|
Matcher matcher = HEX_PATTERN.matcher(message);
|
||||||
Matcher matcher = hexPattern.matcher(message);
|
|
||||||
StringBuffer buffer = new StringBuffer(message.length() + 4 * 8);
|
StringBuffer buffer = new StringBuffer(message.length() + 4 * 8);
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
String group = matcher.group(1);
|
String group = matcher.group(1);
|
||||||
@@ -73,102 +75,90 @@ public class StringUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply gradients to the provided string.
|
* Colors a string with a gradient.
|
||||||
*
|
*
|
||||||
* @param message the string to parse.
|
* @param string The string to color.
|
||||||
* @return the parsed string.
|
* @param start The start color.
|
||||||
|
* @param end The end color.
|
||||||
|
* @return The string, colored.
|
||||||
*/
|
*/
|
||||||
public static String translateGradients(@NotNull final String message) {
|
private static String processGradients(@NotNull final String string,
|
||||||
List<String> hexes = new ArrayList<>();
|
@NotNull final Color start,
|
||||||
Matcher matcher = Pattern.compile(GRADIENT_REGEX).matcher(message);
|
@NotNull final Color end) {
|
||||||
while (matcher.find()) {
|
String processedString = string;
|
||||||
hexes.add(matcher.group().replace("<$", "").replace(">", ""));
|
List<ChatColor> modifiers = new ArrayList<>();
|
||||||
|
if (processedString.contains("&l")) {
|
||||||
|
modifiers.add(ChatColor.BOLD);
|
||||||
}
|
}
|
||||||
int hexIndex = 0;
|
if (processedString.contains("&o")) {
|
||||||
List<String> texts = new LinkedList<>(Arrays.asList(message.split(GRADIENT_REGEX)));
|
modifiers.add(ChatColor.ITALIC);
|
||||||
StringBuilder finalMsg = new StringBuilder();
|
|
||||||
for (String text : texts) {
|
|
||||||
if (texts.get(0).equalsIgnoreCase(text)) {
|
|
||||||
finalMsg.append(text);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (text.length() == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (hexIndex + 1 >= hexes.size()) {
|
|
||||||
if (!finalMsg.toString().contains(text)) {
|
|
||||||
finalMsg.append(text);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
String fromHex = hexes.get(hexIndex);
|
|
||||||
String toHex = hexes.get(hexIndex + 1);
|
|
||||||
finalMsg.append(insertFades(text, fromHex, toHex));
|
|
||||||
hexIndex++;
|
|
||||||
}
|
}
|
||||||
return finalMsg.toString();
|
if (processedString.contains("&n")) {
|
||||||
|
modifiers.add(ChatColor.UNDERLINE);
|
||||||
|
}
|
||||||
|
if (processedString.contains("&k")) {
|
||||||
|
modifiers.add(ChatColor.MAGIC);
|
||||||
|
}
|
||||||
|
processedString = processedString.replace("&l", "");
|
||||||
|
processedString = processedString.replace("&o", "");
|
||||||
|
processedString = processedString.replace("&n", "");
|
||||||
|
processedString = processedString.replace("&k", "");
|
||||||
|
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
ChatColor[] colors = getGradientColors(start, end, processedString.length());
|
||||||
|
String[] characters = processedString.split("");
|
||||||
|
for (int i = 0; i < processedString.length(); i++) {
|
||||||
|
stringBuilder.append(colors[i]);
|
||||||
|
modifiers.forEach(stringBuilder::append);
|
||||||
|
stringBuilder.append(characters[i]);
|
||||||
|
}
|
||||||
|
return stringBuilder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String insertFades(@NotNull final String message,
|
/**
|
||||||
@NotNull final String fromHex,
|
* Creates chatColors for gradients.
|
||||||
@NotNull final String toHex) {
|
*
|
||||||
boolean bold = message.contains("&l");
|
* @param start The start color.
|
||||||
boolean italic = message.contains("&o");
|
* @param end The end color.
|
||||||
String msg = message;
|
* @param step How many colors are returned.
|
||||||
msg = msg.replace("&l", "");
|
* @return Array of chat colors.
|
||||||
msg = msg.replace("&o", "");
|
*/
|
||||||
int length = msg.length();
|
private static ChatColor[] getGradientColors(@NotNull final Color start,
|
||||||
Color fromRGB = Color.decode(fromHex);
|
@NotNull final Color end,
|
||||||
Color toRGB = Color.decode(toHex);
|
final int step) {
|
||||||
double rStep = Math.abs((double) (fromRGB.getRed() - toRGB.getRed()) / length);
|
ChatColor[] colors = new ChatColor[step];
|
||||||
double gStep = Math.abs((double) (fromRGB.getGreen() - toRGB.getGreen()) / length);
|
int stepR = Math.abs(start.getRed() - end.getRed()) / (step - 1);
|
||||||
double bStep = Math.abs((double) (fromRGB.getBlue() - toRGB.getBlue()) / length);
|
int stepG = Math.abs(start.getGreen() - end.getGreen()) / (step - 1);
|
||||||
if (fromRGB.getRed() > toRGB.getRed()) {
|
int stepB = Math.abs(start.getBlue() - end.getBlue()) / (step - 1);
|
||||||
rStep = -rStep;
|
int[] direction = new int[]{
|
||||||
|
start.getRed() < end.getRed() ? +1 : -1,
|
||||||
|
start.getGreen() < end.getGreen() ? +1 : -1,
|
||||||
|
start.getBlue() < end.getBlue() ? +1 : -1
|
||||||
|
};
|
||||||
|
|
||||||
|
for (int i = 0; i < step; i++) {
|
||||||
|
Color color = new Color(start.getRed() + ((stepR * i) * direction[0]), start.getGreen() + ((stepG * i) * direction[1]), start.getBlue() + ((stepB * i) * direction[2]));
|
||||||
|
colors[i] = ChatColor.of(color);
|
||||||
}
|
}
|
||||||
if (fromRGB.getGreen() > toRGB.getGreen()) {
|
return colors;
|
||||||
gStep = -gStep;
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add gradients to a string.
|
||||||
|
*
|
||||||
|
* @param string The string.
|
||||||
|
* @return The string, colorized.
|
||||||
|
*/
|
||||||
|
private static String translateGradients(@NotNull final String string) {
|
||||||
|
String processedString = string;
|
||||||
|
Matcher matcher = GRADIENT_REGEX.matcher(string);
|
||||||
|
while (matcher.find()) {
|
||||||
|
String start = matcher.group(1);
|
||||||
|
String end = matcher.group(3);
|
||||||
|
String content = matcher.group(2);
|
||||||
|
processedString = processedString.replace(matcher.group(), processGradients(content, new Color(Integer.parseInt(start, 16)), new Color(Integer.parseInt(end, 16))));
|
||||||
}
|
}
|
||||||
if (fromRGB.getBlue() > toRGB.getBlue()) {
|
return processedString;
|
||||||
bStep = -bStep;
|
|
||||||
}
|
|
||||||
Color finalColor = new Color(fromRGB.getRGB());
|
|
||||||
msg = msg.replaceAll(GRADIENT_REGEX, "");
|
|
||||||
msg = msg.replace("", "<$>");
|
|
||||||
for (int index = 0; index <= length; index++) {
|
|
||||||
int red = (int) Math.round(finalColor.getRed() + rStep);
|
|
||||||
int green = (int) Math.round(finalColor.getGreen() + gStep);
|
|
||||||
int blue = (int) Math.round(finalColor.getBlue() + bStep);
|
|
||||||
if (red > 255) {
|
|
||||||
red = 255;
|
|
||||||
}
|
|
||||||
if (red < 0) {
|
|
||||||
red = 0;
|
|
||||||
}
|
|
||||||
if (green > 255) {
|
|
||||||
green = 255;
|
|
||||||
}
|
|
||||||
if (green < 0) {
|
|
||||||
green = 0;
|
|
||||||
}
|
|
||||||
if (blue > 255) {
|
|
||||||
blue = 255;
|
|
||||||
}
|
|
||||||
if (blue < 0) {
|
|
||||||
blue = 0;
|
|
||||||
}
|
|
||||||
finalColor = new Color(red, green, blue);
|
|
||||||
String hex = "#" + Integer.toHexString(finalColor.getRGB()).substring(2);
|
|
||||||
String formats = "";
|
|
||||||
if (bold) {
|
|
||||||
formats += ChatColor.BOLD;
|
|
||||||
}
|
|
||||||
if (italic) {
|
|
||||||
formats += ChatColor.ITALIC;
|
|
||||||
}
|
|
||||||
msg = msg.replaceFirst("<\\$>", ChatColor.of(hex) + formats);
|
|
||||||
}
|
|
||||||
return msg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -11,8 +11,6 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
public class EcoEventManager extends PluginDependent implements EventManager {
|
public class EcoEventManager extends PluginDependent implements EventManager {
|
||||||
/**
|
/**
|
||||||
* Manager class for event management.
|
* Manager class for event management.
|
||||||
* <p>
|
|
||||||
* Prevents calls to {@link AbstractEcoPlugin#getInstance()}.
|
|
||||||
*
|
*
|
||||||
* @param plugin The {@link AbstractEcoPlugin} that this manages the events of.
|
* @param plugin The {@link AbstractEcoPlugin} that this manages the events of.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,221 +1,40 @@
|
|||||||
package com.willfp.eco.util.config;
|
package com.willfp.eco.util.config;
|
||||||
|
|
||||||
import com.willfp.eco.util.StringUtils;
|
import com.willfp.eco.util.config.internal.AbstractUpdatableConfig;
|
||||||
import com.willfp.eco.util.internal.PluginDependent;
|
|
||||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
public abstract class BaseConfig extends AbstractUpdatableConfig {
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public abstract class BaseConfig extends PluginDependent implements ValueGetter {
|
|
||||||
/**
|
|
||||||
* The linked {@link YamlConfiguration} where values are physically stored.
|
|
||||||
*/
|
|
||||||
@Getter(AccessLevel.PUBLIC)
|
|
||||||
private final YamlConfiguration config;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The physical config file, as stored on disk.
|
|
||||||
*/
|
|
||||||
@Getter(AccessLevel.PROTECTED)
|
|
||||||
private final File configFile;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The full name of the config file (eg config.yml).
|
|
||||||
*/
|
|
||||||
private final String name;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether keys not in the base config should be removed on update.
|
|
||||||
*/
|
|
||||||
private final boolean removeUnused;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Config implementation for configs present in the plugin's base directory (eg config.yml, lang.yml).
|
* Config implementation for configs present in the plugin's base directory (eg config.yml, lang.yml).
|
||||||
* <p>
|
* <p>
|
||||||
* Automatically updates.
|
* Automatically updates.
|
||||||
*
|
*
|
||||||
* @param configName The name of the config
|
* @param configName The name of the config
|
||||||
* @param removeUnused Whether keys not present in the default config should be removed on update.
|
* @param removeUnused Whether keys not present in the default config should be removed on update.
|
||||||
* @param plugin The plugin.
|
* @param plugin The plugin.
|
||||||
|
* @param updateBlacklist Substring of keys to not add/remove keys for.
|
||||||
|
*/
|
||||||
|
protected BaseConfig(@NotNull final String configName,
|
||||||
|
final boolean removeUnused,
|
||||||
|
@NotNull final AbstractEcoPlugin plugin,
|
||||||
|
@NotNull final String... updateBlacklist) {
|
||||||
|
super(configName, plugin, "", plugin.getClass(), removeUnused, updateBlacklist);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Config implementation for configs present in the plugin's base directory (eg config.yml, lang.yml).
|
||||||
|
* <p>
|
||||||
|
* Automatically updates.
|
||||||
|
*
|
||||||
|
* @param configName The name of the config
|
||||||
|
* @param removeUnused Whether keys not present in the default config should be removed on update.
|
||||||
|
* @param plugin The plugin.
|
||||||
*/
|
*/
|
||||||
protected BaseConfig(@NotNull final String configName,
|
protected BaseConfig(@NotNull final String configName,
|
||||||
final boolean removeUnused,
|
final boolean removeUnused,
|
||||||
@NotNull final AbstractEcoPlugin plugin) {
|
@NotNull final AbstractEcoPlugin plugin) {
|
||||||
super(plugin);
|
super(configName, plugin, "", plugin.getClass(), removeUnused, "");
|
||||||
this.name = configName + ".yml";
|
|
||||||
this.removeUnused = removeUnused;
|
|
||||||
|
|
||||||
if (!new File(this.getPlugin().getDataFolder(), this.name).exists()) {
|
|
||||||
createFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.configFile = new File(this.getPlugin().getDataFolder(), this.name);
|
|
||||||
this.config = YamlConfiguration.loadConfiguration(configFile);
|
|
||||||
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createFile() {
|
|
||||||
this.getPlugin().saveResource(name, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the config.
|
|
||||||
* <p>
|
|
||||||
* Writes missing values, however removes comments due to how configs are stored internally in bukkit.
|
|
||||||
*/
|
|
||||||
public void update() {
|
|
||||||
try {
|
|
||||||
config.load(configFile);
|
|
||||||
|
|
||||||
InputStream newIn = this.getPlugin().getResource(name);
|
|
||||||
if (newIn == null) {
|
|
||||||
this.getPlugin().getLog().error(name + " is null?");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(newIn, StandardCharsets.UTF_8));
|
|
||||||
YamlConfiguration newConfig = new YamlConfiguration();
|
|
||||||
newConfig.load(reader);
|
|
||||||
|
|
||||||
if (newConfig.getKeys(true).equals(config.getKeys(true))) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
newConfig.getKeys(true).forEach((s -> {
|
|
||||||
if (!config.getKeys(true).contains(s)) {
|
|
||||||
config.set(s, newConfig.get(s));
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
if (this.removeUnused) {
|
|
||||||
config.getKeys(true).forEach((s -> {
|
|
||||||
if (!newConfig.getKeys(true).contains(s)) {
|
|
||||||
config.set(s, null);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
config.save(configFile);
|
|
||||||
} catch (IOException | InvalidConfigurationException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an integer from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or 0 if not found.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public int getInt(@NotNull final String path) {
|
|
||||||
return config.getInt(path, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an integer from config with a specified default (not found) value.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @param def The value to default to if not found.
|
|
||||||
* @return The found value, or the default.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public int getInt(@NotNull final String path,
|
|
||||||
final int def) {
|
|
||||||
return config.getInt(path, def);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of integers from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
public List<Integer> getInts(@NotNull final String path) {
|
|
||||||
return config.getIntegerList(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a boolean from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or false if not found.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean getBool(@NotNull final String path) {
|
|
||||||
return config.getBoolean(path, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of booleans from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
public List<Boolean> getBools(@NotNull final String path) {
|
|
||||||
return config.getBooleanList(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a string from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or an empty string if not found.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
public String getString(@NotNull final String path) {
|
|
||||||
return StringUtils.translate(Objects.requireNonNull(config.getString(path, "")));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of strings from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
public List<String> getStrings(@NotNull final String path) {
|
|
||||||
return config.getStringList(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a decimal from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or 0 if not found.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public double getDouble(@NotNull final String path) {
|
|
||||||
return config.getDouble(path, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of decimals from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
public List<Double> getDoubles(@NotNull final String path) {
|
|
||||||
return config.getDoubleList(path);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.willfp.eco.util.config;
|
||||||
|
|
||||||
|
import com.willfp.eco.util.config.internal.AbstractUpdatableConfig;
|
||||||
|
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public abstract class ExtendableConfig extends AbstractUpdatableConfig {
|
||||||
|
/**
|
||||||
|
* Config implementation for configs present in the plugin's base directory (eg config.yml, lang.yml).
|
||||||
|
* <p>
|
||||||
|
* Automatically updates.
|
||||||
|
*
|
||||||
|
* @param configName The name of the config
|
||||||
|
* @param removeUnused Whether keys not present in the default config should be removed on update.
|
||||||
|
* @param plugin The plugin.
|
||||||
|
* @param updateBlacklist Substring of keys to not add/remove keys for.
|
||||||
|
* @param subDirectoryPath The subdirectory path.
|
||||||
|
* @param source The class that owns the resource.
|
||||||
|
*/
|
||||||
|
protected ExtendableConfig(@NotNull final String configName,
|
||||||
|
final boolean removeUnused,
|
||||||
|
@NotNull final AbstractEcoPlugin plugin,
|
||||||
|
@NotNull final Class<?> source,
|
||||||
|
@NotNull final String subDirectoryPath,
|
||||||
|
@Nullable final String... updateBlacklist) {
|
||||||
|
super(configName, plugin, subDirectoryPath, source, removeUnused, updateBlacklist);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.willfp.eco.util.config;
|
||||||
|
|
||||||
|
import com.willfp.eco.util.config.internal.AbstractConfig;
|
||||||
|
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public abstract class StaticBaseConfig extends AbstractConfig {
|
||||||
|
/**
|
||||||
|
* Config implementation for configs present in the plugin's base directory (eg config.yml, lang.yml).
|
||||||
|
* <p>
|
||||||
|
* Does not automatically update.
|
||||||
|
*
|
||||||
|
* @param configName The name of the config
|
||||||
|
* @param plugin The plugin.
|
||||||
|
*/
|
||||||
|
protected StaticBaseConfig(@NotNull final String configName,
|
||||||
|
@NotNull final AbstractEcoPlugin plugin) {
|
||||||
|
super(configName, plugin, "", plugin.getClass());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,87 +1,5 @@
|
|||||||
package com.willfp.eco.util.config;
|
package com.willfp.eco.util.config;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
@Deprecated
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public interface ValueGetter {
|
public interface ValueGetter {
|
||||||
/**
|
|
||||||
* Get an integer from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or 0 if not found.
|
|
||||||
*/
|
|
||||||
int getInt(@NotNull String path);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an integer from config with a specified default (not found) value.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @param def The value to default to if not found.
|
|
||||||
* @return The found value, or the default.
|
|
||||||
*/
|
|
||||||
int getInt(@NotNull String path,
|
|
||||||
int def);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of integers from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
List<Integer> getInts(@NotNull String path);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a boolean from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or false if not found.
|
|
||||||
*/
|
|
||||||
boolean getBool(@NotNull String path);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of booleans from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
List<Boolean> getBools(@NotNull String path);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a string from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or an empty string if not found.
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
String getString(@NotNull String path);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of strings from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
List<String> getStrings(@NotNull String path);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a decimal from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or 0 if not found.
|
|
||||||
*/
|
|
||||||
double getDouble(@NotNull String path);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of decimals from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
List<Double> getDoubles(@NotNull String path);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,407 @@
|
|||||||
|
package com.willfp.eco.util.config.internal;
|
||||||
|
|
||||||
|
import com.willfp.eco.util.StringUtils;
|
||||||
|
import com.willfp.eco.util.internal.PluginDependent;
|
||||||
|
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public abstract class AbstractConfig extends PluginDependent {
|
||||||
|
/**
|
||||||
|
* The linked {@link YamlConfiguration} where values are physically stored.
|
||||||
|
*/
|
||||||
|
@Getter(AccessLevel.PUBLIC)
|
||||||
|
protected final YamlConfiguration config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The physical config file, as stored on disk.
|
||||||
|
*/
|
||||||
|
@Getter(AccessLevel.PROTECTED)
|
||||||
|
private final File configFile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The full name of the config file (eg config.yml).
|
||||||
|
*/
|
||||||
|
@Getter(AccessLevel.PROTECTED)
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The subdirectory path.
|
||||||
|
*/
|
||||||
|
@Getter(AccessLevel.PROTECTED)
|
||||||
|
private final String subDirectoryPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The provider of the config.
|
||||||
|
*/
|
||||||
|
@Getter(AccessLevel.PROTECTED)
|
||||||
|
private final Class<?> source;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract config.
|
||||||
|
*
|
||||||
|
* @param configName The name of the config
|
||||||
|
* @param plugin The plugin.
|
||||||
|
* @param subDirectoryPath The subdirectory path.
|
||||||
|
* @param source The class that owns the resource.
|
||||||
|
*/
|
||||||
|
protected AbstractConfig(@NotNull final String configName,
|
||||||
|
@NotNull final AbstractEcoPlugin plugin,
|
||||||
|
@NotNull final String subDirectoryPath,
|
||||||
|
@NotNull final Class<?> source) {
|
||||||
|
super(plugin);
|
||||||
|
this.source = source;
|
||||||
|
this.subDirectoryPath = subDirectoryPath;
|
||||||
|
this.name = configName + ".yml";
|
||||||
|
|
||||||
|
File directory = new File(this.getPlugin().getDataFolder(), subDirectoryPath);
|
||||||
|
if (!directory.exists()) {
|
||||||
|
directory.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!new File(directory, this.name).exists()) {
|
||||||
|
createFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.configFile = new File(directory, this.name);
|
||||||
|
this.config = YamlConfiguration.loadConfiguration(configFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createFile() {
|
||||||
|
String resourcePath = getResourcePath();
|
||||||
|
InputStream in = source.getResourceAsStream(resourcePath);
|
||||||
|
|
||||||
|
File outFile = new File(this.getPlugin().getDataFolder(), resourcePath);
|
||||||
|
int lastIndex = resourcePath.lastIndexOf('/');
|
||||||
|
File outDir = new File(this.getPlugin().getDataFolder(), resourcePath.substring(0, Math.max(lastIndex, 0)));
|
||||||
|
|
||||||
|
if (!outDir.exists()) {
|
||||||
|
outDir.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!outFile.exists()) {
|
||||||
|
OutputStream out = new FileOutputStream(outFile);
|
||||||
|
byte[] buf = new byte[1024];
|
||||||
|
int len;
|
||||||
|
while ((len = in.read(buf)) > 0) {
|
||||||
|
out.write(buf, 0, len);
|
||||||
|
}
|
||||||
|
out.close();
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get resource path as relative to base directory.
|
||||||
|
*
|
||||||
|
* @return The resource path.
|
||||||
|
*/
|
||||||
|
protected String getResourcePath() {
|
||||||
|
String resourcePath;
|
||||||
|
|
||||||
|
if (subDirectoryPath.isEmpty()) {
|
||||||
|
resourcePath = name;
|
||||||
|
} else {
|
||||||
|
resourcePath = subDirectoryPath + name;
|
||||||
|
}
|
||||||
|
|
||||||
|
return "/" + resourcePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get YamlConfiguration as found in jar.
|
||||||
|
*
|
||||||
|
* @return The YamlConfiguration.
|
||||||
|
*/
|
||||||
|
protected YamlConfiguration getConfigInJar() {
|
||||||
|
InputStream newIn = source.getResourceAsStream(getResourcePath());
|
||||||
|
|
||||||
|
if (newIn == null) {
|
||||||
|
throw new NullPointerException(this.getName() + " is null?");
|
||||||
|
}
|
||||||
|
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(newIn, StandardCharsets.UTF_8));
|
||||||
|
YamlConfiguration newConfig = new YamlConfiguration();
|
||||||
|
|
||||||
|
try {
|
||||||
|
newConfig.load(reader);
|
||||||
|
} catch (IOException | InvalidConfigurationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return newConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get if the config contains a key.
|
||||||
|
*
|
||||||
|
* @param path The key to check.
|
||||||
|
* @return If contained.
|
||||||
|
*/
|
||||||
|
public boolean has(@NotNull final String path) {
|
||||||
|
return config.contains(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get configuration section from config.
|
||||||
|
*
|
||||||
|
* @param path The key to check.
|
||||||
|
* @return The configuration section. Throws NPE if not found.
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public ConfigurationSection getSection(@NotNull final String path) {
|
||||||
|
ConfigurationSection section = getSectionOrNull(path);
|
||||||
|
if (section == null) {
|
||||||
|
throw new NullPointerException("Section cannot be null!");
|
||||||
|
} else {
|
||||||
|
return section;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get configuration section from config.
|
||||||
|
*
|
||||||
|
* @param path The key to check.
|
||||||
|
* @return The configuration section, or null if not found.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public ConfigurationSection getSectionOrNull(@NotNull final String path) {
|
||||||
|
return config.getConfigurationSection(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an integer from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or 0 if not found.
|
||||||
|
*/
|
||||||
|
public int getInt(@NotNull final String path) {
|
||||||
|
return config.getInt(path, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an integer from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or null if not found.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public Integer getIntOrNull(@NotNull final String path) {
|
||||||
|
if (has(path)) {
|
||||||
|
return getInt(path);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an integer from config with a specified default (not found) value.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @param def The value to default to if not found.
|
||||||
|
* @return The found value, or the default.
|
||||||
|
*/
|
||||||
|
public int getInt(@NotNull final String path,
|
||||||
|
final int def) {
|
||||||
|
return config.getInt(path, def);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of integers from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public List<Integer> getInts(@NotNull final String path) {
|
||||||
|
return config.getIntegerList(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of integers from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or null if not found.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public List<Integer> getIntsOrNull(@NotNull final String path) {
|
||||||
|
if (has(path)) {
|
||||||
|
return getInts(path);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a boolean from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or false if not found.
|
||||||
|
*/
|
||||||
|
public boolean getBool(@NotNull final String path) {
|
||||||
|
return config.getBoolean(path, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a boolean from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or null if not found.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public Boolean getBoolOrNull(@NotNull final String path) {
|
||||||
|
if (has(path)) {
|
||||||
|
return getBool(path);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of booleans from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public List<Boolean> getBools(@NotNull final String path) {
|
||||||
|
return config.getBooleanList(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of booleans from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or null if not found.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public List<Boolean> getBoolsOrNull(@NotNull final String path) {
|
||||||
|
if (has(path)) {
|
||||||
|
return getBools(path);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a string from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or an empty string if not found.
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public String getString(@NotNull final String path) {
|
||||||
|
return StringUtils.translate(Objects.requireNonNull(config.getString(path, "")));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a string from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or null if not found.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public String getStringOrNull(@NotNull final String path) {
|
||||||
|
if (has(path)) {
|
||||||
|
return getString(path);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of strings from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public List<String> getStrings(@NotNull final String path) {
|
||||||
|
return config.getStringList(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of strings from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or null if not found.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public List<String> getStringsOrNull(@NotNull final String path) {
|
||||||
|
if (has(path)) {
|
||||||
|
return getStrings(path);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a decimal from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or 0 if not found.
|
||||||
|
*/
|
||||||
|
public double getDouble(@NotNull final String path) {
|
||||||
|
return config.getDouble(path, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a decimal from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or null if not found.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public Double getDoubleOrNull(@NotNull final String path) {
|
||||||
|
if (has(path)) {
|
||||||
|
return getDouble(path);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of decimals from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public List<Double> getDoubles(@NotNull final String path) {
|
||||||
|
return config.getDoubleList(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of decimals from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or null if not found.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public List<Double> getDoublesOrNull(@NotNull final String path) {
|
||||||
|
if (has(path)) {
|
||||||
|
return getDoubles(path);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package com.willfp.eco.util.config.internal;
|
||||||
|
|
||||||
|
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||||
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public abstract class AbstractUpdatableConfig extends AbstractConfig {
|
||||||
|
/**
|
||||||
|
* Whether keys not in the base config should be removed on update.
|
||||||
|
*/
|
||||||
|
private final boolean removeUnused;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of blacklisted update keys.
|
||||||
|
*/
|
||||||
|
private final List<String> updateBlacklist;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updatable config.
|
||||||
|
*
|
||||||
|
* @param configName The name of the config
|
||||||
|
* @param plugin The plugin.
|
||||||
|
* @param subDirectoryPath The subdirectory path.
|
||||||
|
* @param source The class that owns the resource.
|
||||||
|
* @param removeUnused Whether keys not present in the default config should be removed on update.
|
||||||
|
* @param updateBlacklist Substring of keys to not add/remove keys for.
|
||||||
|
*/
|
||||||
|
protected AbstractUpdatableConfig(@NotNull final String configName,
|
||||||
|
@NotNull final AbstractEcoPlugin plugin,
|
||||||
|
@NotNull final String subDirectoryPath,
|
||||||
|
@NotNull final Class<?> source,
|
||||||
|
final boolean removeUnused,
|
||||||
|
@NotNull final String... updateBlacklist) {
|
||||||
|
super(configName, plugin, subDirectoryPath, source);
|
||||||
|
this.removeUnused = removeUnused;
|
||||||
|
this.updateBlacklist = new ArrayList<>(Arrays.asList(updateBlacklist));
|
||||||
|
this.updateBlacklist.removeIf(String::isEmpty);
|
||||||
|
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the config.
|
||||||
|
* <p>
|
||||||
|
* Writes missing values, however removes comments due to how configs are stored internally in bukkit.
|
||||||
|
*/
|
||||||
|
public void update() {
|
||||||
|
try {
|
||||||
|
config.load(this.getConfigFile());
|
||||||
|
|
||||||
|
YamlConfiguration newConfig = this.getConfigInJar();
|
||||||
|
|
||||||
|
if (newConfig.getKeys(true).equals(config.getKeys(true))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
newConfig.getKeys(true).forEach((s -> {
|
||||||
|
if (!config.getKeys(true).contains(s)) {
|
||||||
|
if (updateBlacklist.stream().noneMatch(s::contains)) {
|
||||||
|
config.set(s, newConfig.get(s));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
if (this.removeUnused) {
|
||||||
|
config.getKeys(true).forEach((s -> {
|
||||||
|
if (!newConfig.getKeys(true).contains(s)) {
|
||||||
|
if (updateBlacklist.stream().noneMatch(s::contains)) {
|
||||||
|
config.set(s, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
config.save(this.getConfigFile());
|
||||||
|
} catch (IOException | InvalidConfigurationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,13 @@
|
|||||||
package com.willfp.eco.util.display;
|
package com.willfp.eco.util.display;
|
||||||
|
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
|
import org.apache.commons.lang.Validate;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -24,15 +30,9 @@ public class Display {
|
|||||||
private static final List<Function<ItemStack, ItemStack>> REVERT_FUNCTIONS = new ArrayList<>();
|
private static final List<Function<ItemStack, ItemStack>> REVERT_FUNCTIONS = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registered finalize functions.
|
* NamespacedKey for finalizing.
|
||||||
*/
|
*/
|
||||||
public static final List<Function<ItemStack, ItemStack>> FINALIZE_FUNCTIONS = new ArrayList<>();
|
private static NamespacedKey finalizeKey;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registered finalize test functions.
|
|
||||||
*/
|
|
||||||
public static final List<Predicate<ItemStack>> FINALIZE_TEST_FUNCTIONS = new ArrayList<>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register display module.
|
* Register display module.
|
||||||
@@ -66,30 +66,20 @@ public class Display {
|
|||||||
REVERT_FUNCTIONS.add(function);
|
REVERT_FUNCTIONS.add(function);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Register finalize function.
|
|
||||||
*
|
|
||||||
* @param function The function.
|
|
||||||
*/
|
|
||||||
public void registerFinalizeModule(@NotNull final Function<ItemStack, ItemStack> function) {
|
|
||||||
FINALIZE_FUNCTIONS.add(function);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register finalize test function.
|
|
||||||
*
|
|
||||||
* @param function The function.
|
|
||||||
*/
|
|
||||||
public void registerFinalizeTestModule(@NotNull final Predicate<ItemStack> function) {
|
|
||||||
FINALIZE_TEST_FUNCTIONS.add(function);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display on ItemStacks.
|
* Display on ItemStacks.
|
||||||
*
|
*
|
||||||
* @param itemStack The item.
|
* @param itemStack The item.
|
||||||
|
* @return The itemstack.
|
||||||
*/
|
*/
|
||||||
public ItemStack display(@NotNull final ItemStack itemStack) {
|
public ItemStack display(@NotNull final ItemStack itemStack) {
|
||||||
|
if (isFinalized(itemStack)) {
|
||||||
|
unfinalize(itemStack);
|
||||||
|
return itemStack;
|
||||||
|
}
|
||||||
|
|
||||||
|
revert(itemStack);
|
||||||
|
|
||||||
for (Map<String, Function<ItemStack, ItemStack>> displayFunctions : DISPLAY_FUNCTIONS) {
|
for (Map<String, Function<ItemStack, ItemStack>> displayFunctions : DISPLAY_FUNCTIONS) {
|
||||||
if (displayFunctions == null) {
|
if (displayFunctions == null) {
|
||||||
continue;
|
continue;
|
||||||
@@ -107,6 +97,7 @@ public class Display {
|
|||||||
* Display on ItemStacks and then finalize.
|
* Display on ItemStacks and then finalize.
|
||||||
*
|
*
|
||||||
* @param itemStack The item.
|
* @param itemStack The item.
|
||||||
|
* @return The itemstack.
|
||||||
*/
|
*/
|
||||||
public ItemStack displayAndFinalize(@NotNull final ItemStack itemStack) {
|
public ItemStack displayAndFinalize(@NotNull final ItemStack itemStack) {
|
||||||
return finalize(display(itemStack));
|
return finalize(display(itemStack));
|
||||||
@@ -116,11 +107,18 @@ public class Display {
|
|||||||
* Revert on ItemStacks.
|
* Revert on ItemStacks.
|
||||||
*
|
*
|
||||||
* @param itemStack The item.
|
* @param itemStack The item.
|
||||||
|
* @return The itemstack.
|
||||||
*/
|
*/
|
||||||
public ItemStack revert(@NotNull final ItemStack itemStack) {
|
public ItemStack revert(@NotNull final ItemStack itemStack) {
|
||||||
|
if (isFinalized(itemStack)) {
|
||||||
|
unfinalize(itemStack);
|
||||||
|
return itemStack;
|
||||||
|
}
|
||||||
|
|
||||||
for (Function<ItemStack, ItemStack> displayFunction : REVERT_FUNCTIONS) {
|
for (Function<ItemStack, ItemStack> displayFunction : REVERT_FUNCTIONS) {
|
||||||
displayFunction.apply(itemStack);
|
displayFunction.apply(itemStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
return itemStack;
|
return itemStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,27 +126,88 @@ public class Display {
|
|||||||
* Finalize an ItemStacks.
|
* Finalize an ItemStacks.
|
||||||
*
|
*
|
||||||
* @param itemStack The item.
|
* @param itemStack The item.
|
||||||
|
* @return The itemstack.
|
||||||
*/
|
*/
|
||||||
public ItemStack finalize(@NotNull final ItemStack itemStack) {
|
public ItemStack finalize(@NotNull final ItemStack itemStack) {
|
||||||
for (Function<ItemStack, ItemStack> function : FINALIZE_FUNCTIONS) {
|
Validate.notNull(finalizeKey, "Key cannot be null!");
|
||||||
function.apply(itemStack);
|
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);
|
||||||
return itemStack;
|
return itemStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finalize an ItemStacks.
|
* Unfinalize an ItemStacks.
|
||||||
*
|
*
|
||||||
* @param itemStack The item.
|
* @param itemStack The item.
|
||||||
|
* @return The itemstack.
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
return itemStack;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If an item is finalized.
|
||||||
|
*
|
||||||
|
* @param itemStack The item.
|
||||||
|
* @return If finalized.
|
||||||
*/
|
*/
|
||||||
public boolean isFinalized(@NotNull final ItemStack itemStack) {
|
public boolean isFinalized(@NotNull final ItemStack itemStack) {
|
||||||
for (Predicate<ItemStack> function : FINALIZE_TEST_FUNCTIONS) {
|
Validate.notNull(finalizeKey, "Key cannot be null!");
|
||||||
if (function.test(itemStack)) {
|
ItemMeta meta = itemStack.getItemMeta();
|
||||||
return true;
|
if (meta == null) {
|
||||||
}
|
return false;
|
||||||
}
|
}
|
||||||
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
return container.has(finalizeKey, PersistentDataType.INTEGER);
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @param finalizeKey The key.
|
||||||
|
*/
|
||||||
|
@ApiStatus.Internal
|
||||||
|
public static void setFinalizeKey(@NotNull final NamespacedKey finalizeKey) {
|
||||||
|
Display.finalizeKey = finalizeKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
|||||||
@@ -2,14 +2,24 @@ package com.willfp.eco.util.drops.internal;
|
|||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
public final class DropManager {
|
public final class DropManager {
|
||||||
/**
|
/**
|
||||||
* The currently used type, or implementation, of {@link AbstractDropQueue}.
|
* The currently used type, or implementation, of {@link AbstractDropQueue}.
|
||||||
* <p>
|
* <p>
|
||||||
* Standard by default, used if drops.collate key is not present in config.
|
* Default is {@link DropQueueType#COLLATED}, however this can be changed.
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
private DropQueueType type = DropQueueType.COLLATED;
|
private DropQueueType type = DropQueueType.COLLATED;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the type of Drop Queue to be used.
|
||||||
|
*
|
||||||
|
* @param type The type.
|
||||||
|
*/
|
||||||
|
public static void setType(@NotNull final DropQueueType type) {
|
||||||
|
DropManager.type = type;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import lombok.AccessLevel;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.ExperienceOrb;
|
import org.bukkit.entity.ExperienceOrb;
|
||||||
@@ -133,6 +134,11 @@ public class InternalDropQueue implements AbstractDropQueue {
|
|||||||
assert world != null;
|
assert world != null;
|
||||||
loc = loc.add(0.5, 0.5, 0.5);
|
loc = loc.add(0.5, 0.5, 0.5);
|
||||||
|
|
||||||
|
items.removeIf(itemStack -> itemStack.getType() == Material.AIR);
|
||||||
|
if (items.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (hasTelekinesis) {
|
if (hasTelekinesis) {
|
||||||
HashMap<Integer, ItemStack> leftover = player.getInventory().addItem(items.toArray(new ItemStack[0]));
|
HashMap<Integer, ItemStack> leftover = player.getInventory().addItem(items.toArray(new ItemStack[0]));
|
||||||
for (ItemStack drop : leftover.values()) {
|
for (ItemStack drop : leftover.values()) {
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package com.willfp.eco.util.integrations.mcmmo;
|
||||||
|
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public class McmmoManager {
|
||||||
|
/**
|
||||||
|
* A set of all registered integrations.
|
||||||
|
*/
|
||||||
|
private final Set<McmmoWrapper> regsistered = new HashSet<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a new integration.
|
||||||
|
*
|
||||||
|
* @param integration The integration to register.
|
||||||
|
*/
|
||||||
|
public void register(@NotNull final McmmoWrapper integration) {
|
||||||
|
regsistered.add(integration);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get bonus drop count from block.
|
||||||
|
*
|
||||||
|
* @param block The block.
|
||||||
|
* @return The bonus drop count.
|
||||||
|
*/
|
||||||
|
public int getBonusDropCount(@NotNull final Block block) {
|
||||||
|
for (McmmoWrapper mcmmoWrapper : regsistered) {
|
||||||
|
return mcmmoWrapper.getBonusDropCount(block);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get if event is fake.
|
||||||
|
*
|
||||||
|
* @param event The event to check.
|
||||||
|
* @return If the event is fake.
|
||||||
|
*/
|
||||||
|
public boolean isFake(@NotNull final Event event) {
|
||||||
|
for (McmmoWrapper mcmmoWrapper : regsistered) {
|
||||||
|
return mcmmoWrapper.isFake(event);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.willfp.eco.util.integrations.mcmmo;
|
||||||
|
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public interface McmmoWrapper {
|
||||||
|
/**
|
||||||
|
* Get bonus drop count of block.
|
||||||
|
*
|
||||||
|
* @param block The block.
|
||||||
|
* @return The drop multiplier.
|
||||||
|
*/
|
||||||
|
int getBonusDropCount(@NotNull Block block);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get if event is fake.
|
||||||
|
*
|
||||||
|
* @param event The event.
|
||||||
|
* @return If is fake.
|
||||||
|
*/
|
||||||
|
boolean isFake(@NotNull Event event);
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@ import com.willfp.eco.util.integrations.placeholder.PlaceholderManager;
|
|||||||
import com.willfp.eco.util.integrations.placeholder.plugins.PlaceholderIntegrationPAPI;
|
import com.willfp.eco.util.integrations.placeholder.plugins.PlaceholderIntegrationPAPI;
|
||||||
import com.willfp.eco.util.optional.Prerequisite;
|
import com.willfp.eco.util.optional.Prerequisite;
|
||||||
import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
|
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.recipe.RecipeManager;
|
||||||
import com.willfp.eco.util.updater.UpdateChecker;
|
import com.willfp.eco.util.updater.UpdateChecker;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -214,6 +215,7 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
|||||||
this.getLog().info("Loading " + this.color + this.pluginName);
|
this.getLog().info("Loading " + this.color + this.pluginName);
|
||||||
|
|
||||||
this.getEventManager().registerListener(new ArrowDataListener(this));
|
this.getEventManager().registerListener(new ArrowDataListener(this));
|
||||||
|
this.getEventManager().registerListener(new RecipeListener(this));
|
||||||
|
|
||||||
new UpdateChecker(this).getVersion(version -> {
|
new UpdateChecker(this).getVersion(version -> {
|
||||||
DefaultArtifactVersion currentVersion = new DefaultArtifactVersion(this.getDescription().getVersion());
|
DefaultArtifactVersion currentVersion = new DefaultArtifactVersion(this.getDescription().getVersion());
|
||||||
@@ -248,14 +250,11 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
Prerequisite.update();
|
Prerequisite.update();
|
||||||
|
|
||||||
|
this.getPacketAdapters().forEach(abstractPacketAdapter -> {
|
||||||
if (ClassUtils.exists("com.comphenix.protocol.events.PacketAdapter")) {
|
if (!abstractPacketAdapter.isPostLoad()) {
|
||||||
this.getPacketAdapters().forEach(abstractPacketAdapter -> {
|
abstractPacketAdapter.register();
|
||||||
if (!abstractPacketAdapter.isPostLoad()) {
|
}
|
||||||
abstractPacketAdapter.register();
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
updatableClasses.addAll(this.getUpdatableClasses());
|
updatableClasses.addAll(this.getUpdatableClasses());
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
version = 3.1.0
|
version = 3.6.0
|
||||||
plugin-name = eco
|
plugin-name = eco
|
||||||
Reference in New Issue
Block a user