Compare commits

...

31 Commits
4.2.0 ... 4.3.0

Author SHA1 Message Date
Auxilor
9565ab0641 Fixed StaticOptionalConfig 2021-04-02 12:26:56 +01:00
Auxilor
45c53b96dc Updated to 4.3.0 2021-04-02 12:24:49 +01:00
Auxilor
861325ac3f Added serialization system 2021-04-02 12:24:38 +01:00
Auxilor
70c015c1f0 Updated to 4.2.9 2021-03-29 20:15:58 +01:00
Auxilor
8f3755b130 Fixed NCP integration 2021-03-29 20:15:45 +01:00
Auxilor
697ff0ccbb Updated to 4.2.8 2021-03-29 08:54:46 +01:00
Auxilor
f117847fc3 Fixed towny again 2021-03-29 08:54:36 +01:00
Auxilor
bd88d40309 Updated to 4.2.7 2021-03-28 21:39:44 +01:00
Auxilor
2fd8aab230 Fixed towny integration 2021-03-28 21:39:15 +01:00
Auxilor
5ec10ec617 Fixed ComabatLogX integration 2021-03-27 19:57:43 +00:00
Auxilor
270270d015 Added support for CombatLogX NewbieHelper and UltimateLands 2021-03-27 19:53:51 +00:00
Auxilor
3364b01c9d Added combatlogx integration 2021-03-27 19:37:30 +00:00
Auxilor
4beda35adf Updated to 4.2.6 2021-03-27 19:16:34 +00:00
Auxilor
fd3e79378b Fixed display occuring twice 2021-03-27 19:15:51 +00:00
Auxilor
4d0068e551 Fixed varargs breaking plugins using new display system 2021-03-27 19:15:40 +00:00
Auxilor
6933c0e5ef Added backend for future dependencies 2021-03-27 19:15:07 +00:00
Auxilor
839b3724e7 Updated to 4.2.5 2021-03-24 18:31:57 +00:00
Auxilor
6006865358 Merge remote-tracking branch 'origin/master' into master 2021-03-24 18:30:46 +00:00
Auxilor
4907b4b6e6 Updated to 4.2.4 2021-03-24 18:30:31 +00:00
Auxilor
29735cdf83 Fixed mcMMO Integration when running an old version 2021-03-24 18:30:08 +00:00
Auxilor
ae4b2ce0d0 Updated to 4.2.4 2021-03-21 16:26:06 +00:00
Auxilor
786cbbcd7d Added CMI hex code support 2021-03-21 16:21:50 +00:00
Auxilor
6d3f2fc5dc Improved consistency of config list getters 2021-03-18 18:55:50 +00:00
Auxilor
6697cc412e Updated to 4.2.3 2021-03-12 22:33:19 +00:00
Auxilor
17a877a89a Merge remote-tracking branch 'origin/master' into master 2021-03-12 22:32:36 +00:00
Auxilor
9d4149c58f Switched illusioner with ecobosses 2021-03-12 22:32:26 +00:00
Auxilor
123ac79918 Updated to 4.2.2 2021-03-06 18:03:50 +00:00
Auxilor
1670c8b3fb Merge pull request #5 from PaulBGD/master 2021-03-06 17:15:42 +00:00
Paul Sauve
6125044e4c Do less work with displaying items 2021-03-06 11:07:18 -06:00
Auxilor
492439470c Updated to 4.2.1 2021-02-26 10:12:33 +00:00
Auxilor
e9e39345ed Reworked finalize system 2021-02-26 10:12:22 +00:00
27 changed files with 733 additions and 180 deletions

View File

@@ -45,6 +45,9 @@ allprojects {
// NoCheatPlus // NoCheatPlus
maven { url 'https://repo.md-5.net/content/repositories/snapshots/' } maven { url 'https://repo.md-5.net/content/repositories/snapshots/' }
// CombatLogX
maven { url 'https://nexus.sirblobman.xyz/repository/public/' }
} }
dependencies { dependencies {

View File

@@ -19,7 +19,7 @@ public final class VillagerTrade implements VillagerTradeProxy {
fResult.setAccessible(true); fResult.setAccessible(true);
ItemStack result = merchantRecipe.getResult(); ItemStack result = merchantRecipe.getResult();
Display.display(result); Display.displayAndFinalize(result);
fResult.set(merchantRecipe, result); fResult.set(merchantRecipe, result);
// Get NMS MerchantRecipe from CraftMerchantRecipe // Get NMS MerchantRecipe from CraftMerchantRecipe
@@ -31,7 +31,7 @@ public final class VillagerTrade implements VillagerTradeProxy {
fSelling.setAccessible(true); fSelling.setAccessible(true);
ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem); ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem);
Display.display(selling); Display.displayAndFinalize(selling);
fSelling.set(handle, CraftItemStack.asNMSCopy(selling)); fSelling.set(handle, CraftItemStack.asNMSCopy(selling));
} catch (IllegalAccessException | NoSuchFieldException e) { } catch (IllegalAccessException | NoSuchFieldException e) {
e.printStackTrace(); e.printStackTrace();

View File

@@ -18,7 +18,7 @@ public final class VillagerTrade implements VillagerTradeProxy {
Field fResult = MerchantRecipe.class.getDeclaredField("result"); Field fResult = MerchantRecipe.class.getDeclaredField("result");
fResult.setAccessible(true); fResult.setAccessible(true);
ItemStack result = merchantRecipe.getResult(); ItemStack result = merchantRecipe.getResult();
Display.display(result); Display.displayAndFinalize(result);
fResult.set(merchantRecipe, result); fResult.set(merchantRecipe, result);
// Get NMS MerchantRecipe from CraftMerchantRecipe // Get NMS MerchantRecipe from CraftMerchantRecipe
@@ -30,7 +30,7 @@ public final class VillagerTrade implements VillagerTradeProxy {
fSelling.setAccessible(true); fSelling.setAccessible(true);
ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem); ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem);
Display.display(selling); Display.displayAndFinalize(selling);
fSelling.set(handle, CraftItemStack.asNMSCopy(selling)); fSelling.set(handle, CraftItemStack.asNMSCopy(selling));
} catch (IllegalAccessException | NoSuchFieldException e) { } catch (IllegalAccessException | NoSuchFieldException e) {

View File

@@ -18,7 +18,7 @@ public final class VillagerTrade implements VillagerTradeProxy {
Field fResult = MerchantRecipe.class.getDeclaredField("result"); Field fResult = MerchantRecipe.class.getDeclaredField("result");
fResult.setAccessible(true); fResult.setAccessible(true);
ItemStack result = merchantRecipe.getResult(); ItemStack result = merchantRecipe.getResult();
Display.display(result); Display.displayAndFinalize(result);
fResult.set(merchantRecipe, result); fResult.set(merchantRecipe, result);
// Get NMS MerchantRecipe from CraftMerchantRecipe // Get NMS MerchantRecipe from CraftMerchantRecipe
@@ -30,7 +30,7 @@ public final class VillagerTrade implements VillagerTradeProxy {
fSelling.setAccessible(true); fSelling.setAccessible(true);
ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem); ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem);
Display.display(selling); Display.displayAndFinalize(selling);
fSelling.set(handle, CraftItemStack.asNMSCopy(selling)); fSelling.set(handle, CraftItemStack.asNMSCopy(selling));
} catch (IllegalAccessException | NoSuchFieldException e) { } catch (IllegalAccessException | NoSuchFieldException e) {

View File

@@ -18,7 +18,7 @@ public final class VillagerTrade implements VillagerTradeProxy {
Field fResult = MerchantRecipe.class.getDeclaredField("result"); Field fResult = MerchantRecipe.class.getDeclaredField("result");
fResult.setAccessible(true); fResult.setAccessible(true);
ItemStack result = merchantRecipe.getResult(); ItemStack result = merchantRecipe.getResult();
Display.display(result); Display.displayAndFinalize(result);
fResult.set(merchantRecipe, result); fResult.set(merchantRecipe, result);
// Get NMS MerchantRecipe from CraftMerchantRecipe // Get NMS MerchantRecipe from CraftMerchantRecipe
@@ -30,7 +30,7 @@ public final class VillagerTrade implements VillagerTradeProxy {
fSelling.setAccessible(true); fSelling.setAccessible(true);
ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem); ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem);
Display.display(selling); Display.displayAndFinalize(selling);
fSelling.set(handle, CraftItemStack.asNMSCopy(selling)); fSelling.set(handle, CraftItemStack.asNMSCopy(selling));
} catch (IllegalAccessException | NoSuchFieldException e) { } catch (IllegalAccessException | NoSuchFieldException e) {

View File

@@ -16,11 +16,13 @@ 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;
import com.willfp.eco.spigot.integrations.antigrief.AntigriefCombatLogX;
import com.willfp.eco.spigot.integrations.antigrief.AntigriefFactionsUUID; import com.willfp.eco.spigot.integrations.antigrief.AntigriefFactionsUUID;
import com.willfp.eco.spigot.integrations.antigrief.AntigriefGriefPrevention; import com.willfp.eco.spigot.integrations.antigrief.AntigriefGriefPrevention;
import com.willfp.eco.spigot.integrations.antigrief.AntigriefKingdoms; import com.willfp.eco.spigot.integrations.antigrief.AntigriefKingdoms;
import com.willfp.eco.spigot.integrations.antigrief.AntigriefLands; 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.AntigriefUltimateLands;
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.spigot.recipes.RecipeListener; import com.willfp.eco.spigot.recipes.RecipeListener;
@@ -107,6 +109,8 @@ public class EcoPlugin extends AbstractEcoPlugin {
new IntegrationLoader("Towny", () -> AntigriefManager.register(new AntigriefTowny())), new IntegrationLoader("Towny", () -> AntigriefManager.register(new AntigriefTowny())),
new IntegrationLoader("Lands", () -> AntigriefManager.register(new AntigriefLands(this))), new IntegrationLoader("Lands", () -> AntigriefManager.register(new AntigriefLands(this))),
new IntegrationLoader("Kingdoms", () -> AntigriefManager.register(new AntigriefKingdoms())), new IntegrationLoader("Kingdoms", () -> AntigriefManager.register(new AntigriefKingdoms())),
new IntegrationLoader("ULands", () -> AntigriefManager.register(new AntigriefUltimateLands())),
new IntegrationLoader("CombatLogX", () -> AntigriefManager.register(new AntigriefCombatLogX())),
// Anticheat // Anticheat
new IntegrationLoader("AAC5", () -> AnticheatManager.register(this, new AnticheatAAC())), new IntegrationLoader("AAC5", () -> AnticheatManager.register(this, new AnticheatAAC())),

View File

@@ -23,7 +23,7 @@ public class AnticheatNCP implements AnticheatWrapper {
@Override @Override
public void exempt(@NotNull final Player player) { public void exempt(@NotNull final Player player) {
if (!NCPExemptionManager.isExempted(player, CheckType.ALL)) { if (NCPExemptionManager.isExempted(player, CheckType.ALL)) {
return; return;
} }

View File

@@ -0,0 +1,76 @@
package com.willfp.eco.spigot.integrations.antigrief;
import com.SirBlobman.combatlogx.api.ICombatLogX;
import com.SirBlobman.combatlogx.api.expansion.Expansion;
import com.SirBlobman.combatlogx.expansion.newbie.helper.NewbieHelper;
import com.SirBlobman.combatlogx.expansion.newbie.helper.listener.ListenerPVP;
import com.willfp.eco.spigot.EcoPlugin;
import com.willfp.eco.util.integrations.antigrief.AntigriefWrapper;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class AntigriefCombatLogX implements AntigriefWrapper {
/**
* Instance of CombatLogX.
*/
private final ICombatLogX instance = (ICombatLogX) Bukkit.getPluginManager().getPlugin("CombatLogX");
/**
* PVPManager for CombatLogX NewbieHelper.
*/
private ListenerPVP pvp = null;
/**
* Create new CombatLogX antigrief.
*/
public AntigriefCombatLogX() {
assert instance != null;
EcoPlugin.getInstance().getScheduler().runLater(() -> {
Expansion expansionUncast = instance.getExpansionManager().getExpansionByName("NewbieHelper").orElse(null);
if (expansionUncast instanceof NewbieHelper) {
pvp = ((NewbieHelper) expansionUncast).getPVPListener();
}
}, 3);
}
@Override
public boolean canBreakBlock(@NotNull final Player player,
@NotNull final Block block) {
return true;
}
@Override
public boolean canCreateExplosion(@NotNull final Player player,
@NotNull final Location location) {
return true;
}
@Override
public boolean canPlaceBlock(@NotNull final Player player,
@NotNull final Block block) {
return true;
}
@Override
public boolean canInjure(@NotNull final Player player,
@NotNull final LivingEntity victim) {
if (!(victim instanceof Player)) {
return true;
}
if (pvp == null) {
return true;
}
return (pvp.isPVPEnabled(player) && pvp.isPVPEnabled((Player) victim));
}
@Override
public String getPluginName() {
return "CombatLogX";
}
}

View File

@@ -1,7 +1,10 @@
package com.willfp.eco.spigot.integrations.antigrief; package com.willfp.eco.spigot.integrations.antigrief;
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.TownyUniverse;
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;
import com.palmergames.bukkit.towny.object.TownyWorld;
import com.palmergames.bukkit.towny.object.WorldCoord; import com.palmergames.bukkit.towny.object.WorldCoord;
import com.palmergames.bukkit.towny.utils.PlayerCacheUtil; import com.palmergames.bukkit.towny.utils.PlayerCacheUtil;
import com.willfp.eco.util.integrations.antigrief.AntigriefWrapper; import com.willfp.eco.util.integrations.antigrief.AntigriefWrapper;
@@ -16,24 +19,57 @@ public class AntigriefTowny 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) {
return PlayerCacheUtil.getCachePermission(player, block.getLocation(), block.getType(), TownyPermission.ActionType.DESTROY); TownyWorld world = TownyUniverse.getInstance().getWorldMap().get(block.getLocation().getWorld().getName());
if (world == null) {
return true;
}
if (TownyAPI.getInstance().isWilderness(block)) {
return true;
}
return PlayerCacheUtil.getCachePermission(player, block.getLocation(), block.getType(), TownyPermission.ActionType.DESTROY)
|| PlayerCacheUtil.getCachePermission(player, block.getLocation(), block.getType(), TownyPermission.ActionType.BUILD);
} }
@Override @Override
public boolean canCreateExplosion(@NotNull final Player player, public boolean canCreateExplosion(@NotNull final Player player,
@NotNull final Location location) { @NotNull final Location location) {
TownyWorld world = TownyUniverse.getInstance().getWorldMap().get(location.getWorld().getName());
if (world == null) {
return true;
}
if (TownyAPI.getInstance().isWilderness(location)) {
return true;
}
return PlayerCacheUtil.getCachePermission(player, location, Material.TNT, TownyPermission.ActionType.ITEM_USE); return PlayerCacheUtil.getCachePermission(player, location, Material.TNT, TownyPermission.ActionType.ITEM_USE);
} }
@Override @Override
public boolean canPlaceBlock(@NotNull final Player player, public boolean canPlaceBlock(@NotNull final Player player,
@NotNull final Block block) { @NotNull final Block block) {
TownyWorld world = TownyUniverse.getInstance().getWorldMap().get(block.getLocation().getWorld().getName());
if (world == null) {
return true;
}
if (TownyAPI.getInstance().isWilderness(block)) {
return true;
}
return PlayerCacheUtil.getCachePermission(player, block.getLocation(), block.getType(), TownyPermission.ActionType.BUILD); return PlayerCacheUtil.getCachePermission(player, block.getLocation(), block.getType(), TownyPermission.ActionType.BUILD);
} }
@Override @Override
public boolean canInjure(@NotNull final Player player, public boolean canInjure(@NotNull final Player player,
@NotNull final LivingEntity victim) { @NotNull final LivingEntity victim) {
TownyWorld world = TownyUniverse.getInstance().getWorldMap().get(victim.getLocation().getWorld().getName());
if (world == null) {
return true;
}
if (TownyAPI.getInstance().isWilderness(victim.getLocation())) {
if (victim instanceof Player) {
return world.isPVP();
} else {
return true;
}
}
if (victim instanceof Player) { if (victim instanceof Player) {
try { try {
Town town = WorldCoord.parseWorldCoord(victim.getLocation()).getTownBlock().getTown(); Town town = WorldCoord.parseWorldCoord(victim.getLocation()).getTownBlock().getTown();

View File

@@ -0,0 +1,40 @@
package com.willfp.eco.spigot.integrations.antigrief;
import com.willfp.eco.util.integrations.antigrief.AntigriefWrapper;
import me.ulrich.lands.api.LandsAPI;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class AntigriefUltimateLands implements AntigriefWrapper {
@Override
public boolean canBreakBlock(@NotNull final Player player,
@NotNull final Block block) {
return LandsAPI.getInstance().isOwnerOfChunk(player.getName(), block.getChunk()) || LandsAPI.getInstance().isMemberOfChunk(block.getChunk(), player);
}
@Override
public boolean canCreateExplosion(@NotNull final Player player,
@NotNull final Location location) {
return LandsAPI.getInstance().isOwnerOfChunk(player.getName(), location.getChunk()) || LandsAPI.getInstance().isMemberOfChunk(location.getChunk(), player);
}
@Override
public boolean canPlaceBlock(@NotNull final Player player,
@NotNull final Block block) {
return LandsAPI.getInstance().isOwnerOfChunk(player.getName(), block.getChunk()) || LandsAPI.getInstance().isMemberOfChunk(block.getChunk(), player);
}
@Override
public boolean canInjure(@NotNull final Player player,
@NotNull final LivingEntity victim) {
return LandsAPI.getInstance().isOwnerOfChunk(player.getName(), victim.getLocation().getChunk()) || LandsAPI.getInstance().isMemberOfChunk(victim.getLocation().getChunk(), player);
}
@Override
public String getPluginName() {
return "ULands";
}
}

View File

@@ -3,14 +3,33 @@ package com.willfp.eco.spigot.integrations.mcmmo;
import com.gmail.nossr50.datatypes.meta.BonusDropMeta; import com.gmail.nossr50.datatypes.meta.BonusDropMeta;
import com.gmail.nossr50.events.fake.FakeEvent; import com.gmail.nossr50.events.fake.FakeEvent;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.willfp.eco.util.ClassUtils;
import com.willfp.eco.util.integrations.mcmmo.McmmoWrapper; import com.willfp.eco.util.integrations.mcmmo.McmmoWrapper;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class McmmoIntegrationImpl implements McmmoWrapper { public class McmmoIntegrationImpl implements McmmoWrapper {
/**
* Disabled if mcmmo is outdated or missing classes.
*/
boolean disabled = false;
/**
* Initialize mcMMO integration.
*/
public McmmoIntegrationImpl() {
if (!ClassUtils.exists("com.gmail.nossr50.events.fake.FakeEvent")) {
disabled = true;
}
}
@Override @Override
public int getBonusDropCount(@NotNull final Block block) { public int getBonusDropCount(@NotNull final Block block) {
if (disabled) {
return 0;
}
if (block.getMetadata(mcMMO.BONUS_DROPS_METAKEY).size() > 0) { if (block.getMetadata(mcMMO.BONUS_DROPS_METAKEY).size() > 0) {
BonusDropMeta bonusDropMeta = (BonusDropMeta) block.getMetadata(mcMMO.BONUS_DROPS_METAKEY).get(0); BonusDropMeta bonusDropMeta = (BonusDropMeta) block.getMetadata(mcMMO.BONUS_DROPS_METAKEY).get(0);
return bonusDropMeta.asInt(); return bonusDropMeta.asInt();
@@ -21,6 +40,10 @@ public class McmmoIntegrationImpl implements McmmoWrapper {
@Override @Override
public boolean isFake(@NotNull final Event event) { public boolean isFake(@NotNull final Event event) {
if (disabled) {
return false;
}
return event instanceof FakeEvent; return event instanceof FakeEvent;
} }
} }

View File

@@ -9,7 +9,7 @@ loadbefore:
- Talismans - Talismans
- StatTrackers - StatTrackers
- EcoArmor - EcoArmor
- Illusioner - EcoBosses
depend: depend:
- ProtocolLib - ProtocolLib
softdepend: softdepend:
@@ -25,3 +25,5 @@ softdepend:
- Spartan - Spartan
- PlaceholderAPI - PlaceholderAPI
- mcMMO - mcMMO
- ULands
- CombatLogX

View File

@@ -16,13 +16,19 @@ import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
public abstract class AbstractConfig extends AbstractUndefinedConfig { public abstract class AbstractConfig extends AbstractUndefinedConfig<YamlConfiguration> {
/** /**
* The physical config file, as stored on disk. * The physical config file, as stored on disk.
*/ */
@Getter(AccessLevel.PROTECTED) @Getter(AccessLevel.PROTECTED)
private final File configFile; private final File configFile;
/**
* Plugin handle.
*/
@Getter(AccessLevel.PROTECTED)
private final AbstractEcoPlugin plugin;
/** /**
* The full name of the config file (eg config.yml). * The full name of the config file (eg config.yml).
*/ */
@@ -53,7 +59,8 @@ public abstract class AbstractConfig extends AbstractUndefinedConfig {
@NotNull final AbstractEcoPlugin plugin, @NotNull final AbstractEcoPlugin plugin,
@NotNull final String subDirectoryPath, @NotNull final String subDirectoryPath,
@NotNull final Class<?> source) { @NotNull final Class<?> source) {
super(configName, plugin); super(configName);
this.plugin = plugin;
this.name = configName + ".yml"; this.name = configName + ".yml";
this.source = source; this.source = source;
this.subDirectoryPath = subDirectoryPath; this.subDirectoryPath = subDirectoryPath;

View File

@@ -1,27 +1,29 @@
package com.willfp.eco.internal.config; package com.willfp.eco.internal.config;
import com.willfp.eco.util.SerializationUtils;
import com.willfp.eco.util.StringUtils; import com.willfp.eco.util.StringUtils;
import com.willfp.eco.util.internal.PluginDependent; import com.willfp.eco.util.config.Config;
import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.eco.util.serialization.EcoSerializable;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.MemorySection;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@SuppressWarnings({"unchecked", "unused"}) @SuppressWarnings({"unchecked", "unused", "DeprecatedIsStillUsed"})
public abstract class AbstractUndefinedConfig extends PluginDependent { public abstract class AbstractUndefinedConfig<T extends ConfigurationSection> implements Config {
/** /**
* The linked {@link YamlConfiguration} where values are physically stored. * The linked {@link MemorySection} where values are physically stored.
*/ */
@Getter(AccessLevel.PUBLIC) @Getter(AccessLevel.PUBLIC)
protected YamlConfiguration config = null; protected T config = null;
/** /**
* Cached values for faster reading. * Cached values for faster reading.
@@ -32,41 +34,80 @@ public abstract class AbstractUndefinedConfig extends PluginDependent {
* Abstract config. * Abstract config.
* *
* @param configName The name of the config * @param configName The name of the config
* @param plugin The plugin.
*/ */
protected AbstractUndefinedConfig(@NotNull final String configName, protected AbstractUndefinedConfig(@NotNull final String configName) {
@NotNull final AbstractEcoPlugin plugin) {
super(plugin);
} }
protected void init(@NotNull final YamlConfiguration config) { protected Config init(@NotNull final T config) {
this.config = config; this.config = config;
return this;
} }
/** @Override
* Clears cache.
*/
public final void clearCache() { public final void clearCache() {
cache.clear(); cache.clear();
} }
/** @Override
* Get if the config contains a key.
*
* @param path The key to check.
* @return If contained.
*/
public boolean has(@NotNull final String path) { public boolean has(@NotNull final String path) {
return config.contains(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 @NotNull
@Override
public List<String> getKeys(final boolean deep) {
return new ArrayList<>(config.getKeys(deep));
}
@Override
public void set(@NotNull final String path,
@NotNull final EcoSerializable<?> object) {
Config serializedConfig = object.serialize();
for (String key : serializedConfig.getKeys(true)) {
Object raw = serializedConfig.getRaw(key);
config.set(path + "." + key, raw);
cache.put(path + "." + key, raw);
}
}
@Override
@Nullable
public Object getRaw(@NotNull final String path) {
return config.get(path);
}
@Override
@NotNull
public <T extends EcoSerializable<T>> T get(@NotNull final String path,
@NotNull final Class<T> clazz) {
T object = getOrNull(path, clazz);
if (object == null) {
throw new NullPointerException("Object cannot be null!");
} else {
return object;
}
}
@Override
@Nullable
public <T extends EcoSerializable<T>> T getOrNull(@NotNull final String path,
@NotNull final Class<T> clazz) {
if (cache.containsKey(path)) {
return (T) cache.get(path);
} else {
Config section = getSubsectionOrNull(path);
if (section == null) {
return null;
}
cache.put(path, SerializationUtils.deserialize(section, clazz));
return getOrNull(path, clazz);
}
}
@Override
@NotNull
@Deprecated
public ConfigurationSection getSection(@NotNull final String path) { public ConfigurationSection getSection(@NotNull final String path) {
ConfigurationSection section = getSectionOrNull(path); ConfigurationSection section = getSectionOrNull(path);
if (section == null) { if (section == null) {
@@ -76,13 +117,9 @@ public abstract class AbstractUndefinedConfig extends PluginDependent {
} }
} }
/** @Override
* Get configuration section from config.
*
* @param path The key to check.
* @return The configuration section, or null if not found.
*/
@Nullable @Nullable
@Deprecated
public ConfigurationSection getSectionOrNull(@NotNull final String path) { public ConfigurationSection getSectionOrNull(@NotNull final String path) {
if (cache.containsKey(path)) { if (cache.containsKey(path)) {
return (ConfigurationSection) cache.get(path); return (ConfigurationSection) cache.get(path);
@@ -92,12 +129,23 @@ public abstract class AbstractUndefinedConfig extends PluginDependent {
} }
} }
/** @Override
* Get an integer from config. @NotNull
* public Config getSubsection(@NotNull final String path) {
* @param path The key to fetch the value from. return new ConfigSection(this.getSection(path));
* @return The found value, or 0 if not found. }
*/
@Override
@Nullable
public Config getSubsectionOrNull(@NotNull final String path) {
ConfigurationSection section = this.getSectionOrNull(path);
if (section == null) {
return null;
}
return new ConfigSection(section);
}
@Override
public int getInt(@NotNull final String path) { public int getInt(@NotNull final String path) {
if (cache.containsKey(path)) { if (cache.containsKey(path)) {
return (int) cache.get(path); return (int) cache.get(path);
@@ -107,12 +155,7 @@ public abstract class AbstractUndefinedConfig extends PluginDependent {
} }
} }
/** @Override
* Get an integer from config.
*
* @param path The key to fetch the value from.
* @return The found value, or null if not found.
*/
@Nullable @Nullable
public Integer getIntOrNull(@NotNull final String path) { public Integer getIntOrNull(@NotNull final String path) {
if (has(path)) { if (has(path)) {
@@ -122,13 +165,7 @@ public abstract class AbstractUndefinedConfig extends PluginDependent {
} }
} }
/** @Override
* 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, public int getInt(@NotNull final String path,
final int def) { final int def) {
if (cache.containsKey(path)) { if (cache.containsKey(path)) {
@@ -139,28 +176,18 @@ public abstract class AbstractUndefinedConfig extends PluginDependent {
} }
} }
/** @Override
* 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 @NotNull
public List<Integer> getInts(@NotNull final String path) { public List<Integer> getInts(@NotNull final String path) {
if (cache.containsKey(path)) { if (cache.containsKey(path)) {
return (List<Integer>) cache.get(path); return (List<Integer>) cache.get(path);
} else { } else {
cache.put(path, config.getIntegerList(path)); cache.put(path, has(path) ? new ArrayList<>(config.getIntegerList(path)) : new ArrayList<>());
return getInts(path); return getInts(path);
} }
} }
/** @Override
* 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 @Nullable
public List<Integer> getIntsOrNull(@NotNull final String path) { public List<Integer> getIntsOrNull(@NotNull final String path) {
if (has(path)) { if (has(path)) {
@@ -170,12 +197,7 @@ public abstract class AbstractUndefinedConfig extends PluginDependent {
} }
} }
/** @Override
* 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) { public boolean getBool(@NotNull final String path) {
if (cache.containsKey(path)) { if (cache.containsKey(path)) {
return (boolean) cache.get(path); return (boolean) cache.get(path);
@@ -185,12 +207,7 @@ public abstract class AbstractUndefinedConfig extends PluginDependent {
} }
} }
/** @Override
* Get a boolean from config.
*
* @param path The key to fetch the value from.
* @return The found value, or null if not found.
*/
@Nullable @Nullable
public Boolean getBoolOrNull(@NotNull final String path) { public Boolean getBoolOrNull(@NotNull final String path) {
if (has(path)) { if (has(path)) {
@@ -200,28 +217,18 @@ public abstract class AbstractUndefinedConfig extends PluginDependent {
} }
} }
/** @Override
* 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 @NotNull
public List<Boolean> getBools(@NotNull final String path) { public List<Boolean> getBools(@NotNull final String path) {
if (cache.containsKey(path)) { if (cache.containsKey(path)) {
return (List<Boolean>) cache.get(path); return (List<Boolean>) cache.get(path);
} else { } else {
cache.put(path, config.getBooleanList(path)); cache.put(path, has(path) ? new ArrayList<>(config.getBooleanList(path)) : new ArrayList<>());
return getBools(path); return getBools(path);
} }
} }
/** @Override
* 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 @Nullable
public List<Boolean> getBoolsOrNull(@NotNull final String path) { public List<Boolean> getBoolsOrNull(@NotNull final String path) {
if (has(path)) { if (has(path)) {
@@ -231,12 +238,7 @@ public abstract class AbstractUndefinedConfig extends PluginDependent {
} }
} }
/** @Override
* 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 @NotNull
public String getString(@NotNull final String path) { public String getString(@NotNull final String path) {
if (cache.containsKey(path)) { if (cache.containsKey(path)) {
@@ -247,12 +249,7 @@ public abstract class AbstractUndefinedConfig extends PluginDependent {
} }
} }
/** @Override
* Get a string from config.
*
* @param path The key to fetch the value from.
* @return The found value, or null if not found.
*/
@Nullable @Nullable
public String getStringOrNull(@NotNull final String path) { public String getStringOrNull(@NotNull final String path) {
if (has(path)) { if (has(path)) {
@@ -262,28 +259,18 @@ public abstract class AbstractUndefinedConfig extends PluginDependent {
} }
} }
/** @Override
* 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 @NotNull
public List<String> getStrings(@NotNull final String path) { public List<String> getStrings(@NotNull final String path) {
if (cache.containsKey(path)) { if (cache.containsKey(path)) {
return (List<String>) cache.get(path); return (List<String>) cache.get(path);
} else { } else {
cache.put(path, config.getStringList(path)); cache.put(path, has(path) ? new ArrayList<>(config.getStringList(path)) : new ArrayList<>());
return getStrings(path); return getStrings(path);
} }
} }
/** @Override
* 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 @Nullable
public List<String> getStringsOrNull(@NotNull final String path) { public List<String> getStringsOrNull(@NotNull final String path) {
if (has(path)) { if (has(path)) {
@@ -293,12 +280,7 @@ public abstract class AbstractUndefinedConfig extends PluginDependent {
} }
} }
/** @Override
* 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) { public double getDouble(@NotNull final String path) {
if (cache.containsKey(path)) { if (cache.containsKey(path)) {
return (double) cache.get(path); return (double) cache.get(path);
@@ -308,12 +290,7 @@ public abstract class AbstractUndefinedConfig extends PluginDependent {
} }
} }
/** @Override
* Get a decimal from config.
*
* @param path The key to fetch the value from.
* @return The found value, or null if not found.
*/
@Nullable @Nullable
public Double getDoubleOrNull(@NotNull final String path) { public Double getDoubleOrNull(@NotNull final String path) {
if (has(path)) { if (has(path)) {
@@ -323,28 +300,18 @@ public abstract class AbstractUndefinedConfig extends PluginDependent {
} }
} }
/** @Override
* 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 @NotNull
public List<Double> getDoubles(@NotNull final String path) { public List<Double> getDoubles(@NotNull final String path) {
if (cache.containsKey(path)) { if (cache.containsKey(path)) {
return (List<Double>) cache.get(path); return (List<Double>) cache.get(path);
} else { } else {
cache.put(path, config.getDoubleList(path)); cache.put(path, has(path) ? new ArrayList<>(config.getDoubleList(path)) : new ArrayList<>());
return getDoubles(path); return getDoubles(path);
} }
} }
/** @Override
* 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 @Nullable
public List<Double> getDoublesOrNull(@NotNull final String path) { public List<Double> getDoublesOrNull(@NotNull final String path) {
if (has(path)) { if (has(path)) {

View File

@@ -0,0 +1,16 @@
package com.willfp.eco.internal.config;
import org.bukkit.configuration.ConfigurationSection;
import org.jetbrains.annotations.NotNull;
public class ConfigSection extends AbstractUndefinedConfig<ConfigurationSection> {
/**
* Config section.
*
* @param section The section.
*/
protected ConfigSection(@NotNull final ConfigurationSection section) {
super("subsection");
this.init(section);
}
}

View File

@@ -0,0 +1,49 @@
package com.willfp.eco.util;
import com.willfp.eco.util.config.Config;
import com.willfp.eco.util.serialization.Deserializer;
import com.willfp.eco.util.serialization.EcoSerializable;
import com.willfp.eco.util.serialization.NoRegisteredDeserializerException;
import lombok.SneakyThrows;
import lombok.experimental.UtilityClass;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.Map;
@UtilityClass
public class SerializationUtils {
/**
* All registered deserializers.
*/
private static final Map<String, Deserializer<?>> REGISTRY = new HashMap<>();
/**
* Register deserializer.
*
* @param clazz The serializable class.
* @param deserializer The deserializer.
* @param <T> The object type.
*/
public <T extends EcoSerializable<T>> void registerDeserializer(@NotNull final Class<T> clazz,
@NotNull final Deserializer<T> deserializer) {
REGISTRY.put(clazz.getName(), deserializer);
}
/**
* Deserialize object.
*
* @param config The config.
* @param clazz The class.
* @param <T> The object type.
*/
@SneakyThrows
public <T extends EcoSerializable<T>> T deserialize(@NotNull final Config config,
@NotNull final Class<T> clazz) {
if (!REGISTRY.containsKey(clazz.getName())) {
throw new NoRegisteredDeserializerException("No deserializer registered for " + clazz.getName());
}
return clazz.cast(REGISTRY.get(clazz.getName()).deserialize(config));
}
}

View File

@@ -30,6 +30,11 @@ public class StringUtils {
*/ */
private static final Pattern HEX_PATTERN = Pattern.compile("&#" + "([A-Fa-f0-9]{6})" + ""); private static final Pattern HEX_PATTERN = Pattern.compile("&#" + "([A-Fa-f0-9]{6})" + "");
/**
* Regex for hex codes.
*/
private static final Pattern ALT_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.
* *
@@ -61,7 +66,22 @@ public class StringUtils {
} }
private static String translateHexColorCodes(@NotNull final String message) { private static String translateHexColorCodes(@NotNull final String message) {
Matcher matcher = HEX_PATTERN.matcher(message); String processedMessage = message;
for (HexParseMode parseMode : HexParseMode.values()) {
processedMessage = translateHexColorCodes(processedMessage, parseMode);
}
return processedMessage;
}
private static String translateHexColorCodes(@NotNull final String message,
@NotNull final HexParseMode mode) {
Matcher matcher;
if (mode == HexParseMode.CMI) {
matcher = ALT_HEX_PATTERN.matcher(message);
} else {
matcher = HEX_PATTERN.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);
@@ -201,4 +221,9 @@ public class StringUtils {
} }
return string; return string;
} }
private enum HexParseMode {
CMI,
NORMAL
}
} }

View File

@@ -0,0 +1,262 @@
package com.willfp.eco.util.config;
import com.willfp.eco.util.serialization.EcoSerializable;
import org.bukkit.configuration.ConfigurationSection;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public interface Config {
/**
* Clears cache.
*/
void clearCache();
/**
* Get if the config contains a key.
*
* @param path The key to check.
* @return If contained.
*/
boolean has(@NotNull String path);
/**
* Get config keys.
*
* @param deep If keys from subsections should be fetched too.
* @return A list of keys.
*/
@NotNull
List<String> getKeys(boolean deep);
/**
* Set an object in config.
*
* @param path The path.
* @param object The object.
*/
void set(@NotNull String path,
@NotNull EcoSerializable<?> object);
/**
* Get an object from config.
* Default implementations call {@link org.bukkit.configuration.file.YamlConfiguration#get(String)}.
*
* @param path The path.
* @return The object.
*/
@Nullable
Object getRaw(@NotNull String path);
/**
* Get an object from config.
*
* @param path The path.
* @param clazz The class of the object.
* @param <T> The type of the object.
* @return The object.
*/
@NotNull <T extends EcoSerializable<T>> T get(@NotNull String path,
@NotNull Class<T> clazz);
/**
* Get an object from config.
*
* @param path The path.
* @param clazz The class of the object.
* @param <T> The type of the object.
* @return The object, or null if not found.
*/
@Nullable <T extends EcoSerializable<T>> T getOrNull(@NotNull String path,
@NotNull Class<T> clazz);
/**
* Get bukkit configuration section from config.
*
* @param path The key to check.
* @return The configuration section. Throws NPE if not found.
*/
@NotNull
@Deprecated
ConfigurationSection getSection(@NotNull String path);
/**
* Get bukkit configuration section from config.
*
* @param path The key to check.
* @return The configuration section, or null if not found.
*/
@Nullable
@Deprecated
ConfigurationSection getSectionOrNull(@NotNull String path);
/**
* Get subsection from config.
*
* @param path The key to check.
* @return The subsection. Throws NPE if not found.
*/
@NotNull
Config getSubsection(@NotNull String path);
/**
* Get subsection from config.
*
* @param path The key to check.
* @return The subsection, or null if not found.
*/
@Nullable
Config getSubsectionOrNull(@NotNull String path);
/**
* 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.
*
* @param path The key to fetch the value from.
* @return The found value, or null if not found.
*/
@Nullable
Integer getIntOrNull(@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 list of integers from config.
*
* @param path The key to fetch the value from.
* @return The found value, or null if not found.
*/
@Nullable
List<Integer> getIntsOrNull(@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 boolean from config.
*
* @param path The key to fetch the value from.
* @return The found value, or null if not found.
*/
@Nullable
Boolean getBoolOrNull(@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 list of booleans from config.
*
* @param path The key to fetch the value from.
* @return The found value, or null if not found.
*/
@Nullable
List<Boolean> getBoolsOrNull(@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 string from config.
*
* @param path The key to fetch the value from.
* @return The found value, or null if not found.
*/
@Nullable
String getStringOrNull(@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 list of strings from config.
*
* @param path The key to fetch the value from.
* @return The found value, or null if not found.
*/
@Nullable
List<String> getStringsOrNull(@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 decimal from config.
*
* @param path The key to fetch the value from.
* @return The found value, or null if not found.
*/
@Nullable
Double getDoubleOrNull(@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);
/**
* 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
List<Double> getDoublesOrNull(@NotNull String path);
}

View File

@@ -5,7 +5,7 @@ import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public abstract class StaticOptionalConfig extends AbstractUndefinedConfig { public abstract class StaticOptionalConfig extends AbstractUndefinedConfig<YamlConfiguration> {
/** /**
* Config implementation for passing YamlConfigurations. * Config implementation for passing YamlConfigurations.
* <p> * <p>
@@ -14,11 +14,26 @@ public abstract class StaticOptionalConfig extends AbstractUndefinedConfig {
* @param configName The name of the config * @param configName The name of the config
* @param plugin The plugin. * @param plugin The plugin.
* @param config The YamlConfiguration handle. * @param config The YamlConfiguration handle.
* @deprecated Plugin not required.
*/ */
@Deprecated
public StaticOptionalConfig(@NotNull final String configName, public StaticOptionalConfig(@NotNull final String configName,
@NotNull final AbstractEcoPlugin plugin, @NotNull final AbstractEcoPlugin plugin,
@NotNull final YamlConfiguration config) { @NotNull final YamlConfiguration config) {
super(configName, plugin); this(configName, config);
}
/**
* Config implementation for passing YamlConfigurations.
* <p>
* Does not automatically update.
*
* @param configName The name of the config
* @param config The YamlConfiguration handle.
*/
public StaticOptionalConfig(@NotNull final String configName,
@NotNull final YamlConfiguration config) {
super(configName);
init(config); init(config);
} }

View File

@@ -55,9 +55,8 @@ public class Display {
* @return The itemstack. * @return The itemstack.
*/ */
public ItemStack display(@NotNull final ItemStack itemStack) { public ItemStack display(@NotNull final ItemStack itemStack) {
if (isFinalized(itemStack)) { if (!itemStack.hasItemMeta()) {
unfinalize(itemStack); return itemStack; // return early if there's no customization of the item
return itemStack;
} }
Map<String, Object[]> pluginVarArgs = new HashMap<>(); Map<String, Object[]> pluginVarArgs = new HashMap<>();
@@ -71,10 +70,6 @@ public class Display {
revert(itemStack); revert(itemStack);
if (!itemStack.hasItemMeta()) {
return itemStack;
}
ItemMeta meta = itemStack.getItemMeta(); ItemMeta meta = itemStack.getItemMeta();
if (meta == null) { if (meta == null) {
@@ -85,11 +80,8 @@ public class Display {
List<DisplayModule> modules = MODULES.get(priority); List<DisplayModule> modules = MODULES.get(priority);
for (DisplayModule module : modules) { for (DisplayModule module : modules) {
Object[] varargs = pluginVarArgs.get(module.getPluginName()); Object[] varargs = pluginVarArgs.get(module.getPluginName());
if (varargs.length == 0) { module.display(itemStack);
module.display(itemStack); module.display(itemStack, varargs);
} else {
module.display(itemStack, varargs);
}
} }
} }
@@ -113,9 +105,8 @@ public class Display {
* @return The itemstack. * @return The itemstack.
*/ */
public ItemStack revert(@NotNull final ItemStack itemStack) { public ItemStack revert(@NotNull final ItemStack itemStack) {
if (isFinalized(itemStack)) { if (Display.isFinalized(itemStack)) {
unfinalize(itemStack); unfinalize(itemStack);
return itemStack;
} }
if (!itemStack.hasItemMeta()) { if (!itemStack.hasItemMeta()) {
@@ -130,16 +121,11 @@ public class Display {
List<String> lore = meta.getLore(); List<String> lore = meta.getLore();
if (lore == null) { if (lore != null && lore.removeIf(line -> line.startsWith(Display.PREFIX))) { // only apply lore modification if needed
lore = new ArrayList<>(); meta.setLore(lore);
itemStack.setItemMeta(meta);
} }
lore.removeIf(line -> line.startsWith(Display.PREFIX));
meta.setLore(lore);
itemStack.setItemMeta(meta);
for (DisplayPriority priority : DisplayPriority.values()) { for (DisplayPriority priority : DisplayPriority.values()) {
List<DisplayModule> modules = MODULES.get(priority); List<DisplayModule> modules = MODULES.get(priority);
for (DisplayModule module : modules) { for (DisplayModule module : modules) {

View File

@@ -0,0 +1,14 @@
package com.willfp.eco.util.serialization;
import com.willfp.eco.util.config.Config;
import org.jetbrains.annotations.NotNull;
public abstract class Deserializer<T extends EcoSerializable<T>> {
/**
* Deserialize a config into an object.
*
* @param config The config.
* @return The object.
*/
public abstract T deserialize(@NotNull Config config);
}

View File

@@ -0,0 +1,14 @@
package com.willfp.eco.util.serialization;
import com.willfp.eco.util.config.Config;
import org.jetbrains.annotations.NotNull;
public interface EcoSerializable<T> {
/**
* Serialize an object into a config.
*
* @return The config.
*/
@NotNull
Config serialize();
}

View File

@@ -0,0 +1,14 @@
package com.willfp.eco.util.serialization;
import org.jetbrains.annotations.NotNull;
public class NoRegisteredDeserializerException extends Exception {
/**
* Create new NoRegisteredDeserializerException.
*
* @param message The message.
*/
public NoRegisteredDeserializerException(@NotNull final String message) {
super(message);
}
}

View File

@@ -1,2 +1,2 @@
version = 4.2.0 version = 4.3.0
plugin-name = eco plugin-name = eco

BIN
lib/CombatLogX.jar Normal file

Binary file not shown.

BIN
lib/Newbie Helper.jar Normal file

Binary file not shown.

BIN
lib/ULands-Addon-2.8.7.jar Normal file

Binary file not shown.