BREAKING: refactored LegacyMaterials -> CompatibleMaterial

This commit is contained in:
jascotty2 2019-09-09 09:09:49 -05:00
parent fe62b96c4a
commit 1783fa18ac
23 changed files with 293 additions and 191 deletions

View File

@ -7,7 +7,7 @@ import com.songoda.core.core.SongodaCoreCommand;
import com.songoda.core.core.SongodaCoreDiagCommand; import com.songoda.core.core.SongodaCoreDiagCommand;
import com.songoda.core.commands.CommandManager; import com.songoda.core.commands.CommandManager;
import com.songoda.core.compatibility.ClientVersion; import com.songoda.core.compatibility.ClientVersion;
import com.songoda.core.compatibility.LegacyMaterials; import com.songoda.core.compatibility.CompatibleMaterial;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@ -62,7 +62,7 @@ public class SongodaCore {
return !SongodaCore.class.getPackage().getName().equals(new String(new char[]{'c','o','m','.','s','o','n','g','o','d','a','.','c','o','r','e'})); return !SongodaCore.class.getPackage().getName().equals(new String(new char[]{'c','o','m','.','s','o','n','g','o','d','a','.','c','o','r','e'}));
} }
public static void registerPlugin(JavaPlugin plugin, int pluginID, LegacyMaterials icon) { public static void registerPlugin(JavaPlugin plugin, int pluginID, CompatibleMaterial icon) {
registerPlugin(plugin, pluginID, icon == null ? "STONE" : icon.name()); registerPlugin(plugin, pluginID, icon == null ? "STONE" : icon.name());
} }
@ -172,61 +172,61 @@ public class SongodaCore {
PluginManager pm = Bukkit.getPluginManager(); PluginManager pm = Bukkit.getPluginManager();
String p; String p;
if (!isRegistered(p = "EpicAnchors") && pm.isPluginEnabled(p)) { if (!isRegistered(p = "EpicAnchors") && pm.isPluginEnabled(p)) {
register((JavaPlugin) pm.getPlugin(p), 31, LegacyMaterials.END_PORTAL_FRAME.name()); register((JavaPlugin) pm.getPlugin(p), 31, CompatibleMaterial.END_PORTAL_FRAME.name());
} }
if (!isRegistered(p = "EpicBosses") && pm.isPluginEnabled(p)) { if (!isRegistered(p = "EpicBosses") && pm.isPluginEnabled(p)) {
register((JavaPlugin) pm.getPlugin(p), 19, LegacyMaterials.ZOMBIE_SPAWN_EGG.name()); register((JavaPlugin) pm.getPlugin(p), 19, CompatibleMaterial.ZOMBIE_SPAWN_EGG.name());
} }
if (!isRegistered(p = "EpicEnchants") && pm.isPluginEnabled(p)) { if (!isRegistered(p = "EpicEnchants") && pm.isPluginEnabled(p)) {
register((JavaPlugin) pm.getPlugin(p), 67, LegacyMaterials.DIAMOND_SWORD.name()); register((JavaPlugin) pm.getPlugin(p), 67, CompatibleMaterial.DIAMOND_SWORD.name());
} }
if (!isRegistered(p = "EpicFarming") && pm.isPluginEnabled(p)) { if (!isRegistered(p = "EpicFarming") && pm.isPluginEnabled(p)) {
register((JavaPlugin) pm.getPlugin(p), 21, LegacyMaterials.WHEAT.name()); register((JavaPlugin) pm.getPlugin(p), 21, CompatibleMaterial.WHEAT.name());
} }
if (!isRegistered(p = "EpicFurnaces") && pm.isPluginEnabled(p)) { if (!isRegistered(p = "EpicFurnaces") && pm.isPluginEnabled(p)) {
register((JavaPlugin) pm.getPlugin(p), 22, LegacyMaterials.FURNACE.name()); register((JavaPlugin) pm.getPlugin(p), 22, CompatibleMaterial.FURNACE.name());
} }
if (!isRegistered(p = "EpicHeads") && pm.isPluginEnabled(p)) { if (!isRegistered(p = "EpicHeads") && pm.isPluginEnabled(p)) {
register((JavaPlugin) pm.getPlugin(p), 26, LegacyMaterials.PLAYER_HEAD.name()); register((JavaPlugin) pm.getPlugin(p), 26, CompatibleMaterial.PLAYER_HEAD.name());
} }
if (!isRegistered(p = "EpicHoppers") && pm.isPluginEnabled(p)) { if (!isRegistered(p = "EpicHoppers") && pm.isPluginEnabled(p)) {
register((JavaPlugin) pm.getPlugin(p), 15, LegacyMaterials.HOPPER.name()); register((JavaPlugin) pm.getPlugin(p), 15, CompatibleMaterial.HOPPER.name());
} }
if (!isRegistered(p = "EpicLevels") && pm.isPluginEnabled(p)) { if (!isRegistered(p = "EpicLevels") && pm.isPluginEnabled(p)) {
register((JavaPlugin) pm.getPlugin(p), 44, LegacyMaterials.NETHER_STAR.name()); register((JavaPlugin) pm.getPlugin(p), 44, CompatibleMaterial.NETHER_STAR.name());
} }
if (!isRegistered(p = "EpicSpawners") && pm.isPluginEnabled(p)) { if (!isRegistered(p = "EpicSpawners") && pm.isPluginEnabled(p)) {
register((JavaPlugin) pm.getPlugin(p), 13, LegacyMaterials.SPAWNER.name()); register((JavaPlugin) pm.getPlugin(p), 13, CompatibleMaterial.SPAWNER.name());
} }
if (!isRegistered(p = "EpicVouchers") && pm.isPluginEnabled(p)) { if (!isRegistered(p = "EpicVouchers") && pm.isPluginEnabled(p)) {
register((JavaPlugin) pm.getPlugin(p), 25, LegacyMaterials.EMERALD.name()); register((JavaPlugin) pm.getPlugin(p), 25, CompatibleMaterial.EMERALD.name());
} }
if (!isRegistered(p = "FabledSkyBlock") && pm.isPluginEnabled(p)) { if (!isRegistered(p = "FabledSkyBlock") && pm.isPluginEnabled(p)) {
register((JavaPlugin) pm.getPlugin(p), 17, LegacyMaterials.GRASS_BLOCK.name()); register((JavaPlugin) pm.getPlugin(p), 17, CompatibleMaterial.GRASS_BLOCK.name());
} }
if (!isRegistered(p = "UltimateCatcher") && pm.isPluginEnabled(p)) { if (!isRegistered(p = "UltimateCatcher") && pm.isPluginEnabled(p)) {
register((JavaPlugin) pm.getPlugin(p), 51, LegacyMaterials.EGG.name()); register((JavaPlugin) pm.getPlugin(p), 51, CompatibleMaterial.EGG.name());
} }
if (!isRegistered(p = "UltimateClaims") && pm.isPluginEnabled(p)) { if (!isRegistered(p = "UltimateClaims") && pm.isPluginEnabled(p)) {
register((JavaPlugin) pm.getPlugin(p), 65, LegacyMaterials.CHEST.name()); register((JavaPlugin) pm.getPlugin(p), 65, CompatibleMaterial.CHEST.name());
} }
if (!isRegistered(p = "UltimateFishing") && pm.isPluginEnabled(p)) { if (!isRegistered(p = "UltimateFishing") && pm.isPluginEnabled(p)) {
register((JavaPlugin) pm.getPlugin(p), 59, LegacyMaterials.COD.name()); register((JavaPlugin) pm.getPlugin(p), 59, CompatibleMaterial.COD.name());
} }
if (!isRegistered(p = "UltimateKits") && pm.isPluginEnabled(p)) { if (!isRegistered(p = "UltimateKits") && pm.isPluginEnabled(p)) {
register((JavaPlugin) pm.getPlugin(p), 14, LegacyMaterials.BEACON.name()); register((JavaPlugin) pm.getPlugin(p), 14, CompatibleMaterial.BEACON.name());
} }
if (!isRegistered(p = "UltimateModeration") && pm.isPluginEnabled(p)) { if (!isRegistered(p = "UltimateModeration") && pm.isPluginEnabled(p)) {
register((JavaPlugin) pm.getPlugin(p), 29, LegacyMaterials.DIAMOND_CHESTPLATE.name()); register((JavaPlugin) pm.getPlugin(p), 29, CompatibleMaterial.DIAMOND_CHESTPLATE.name());
} }
if (!isRegistered(p = "UltimateRepairing") && pm.isPluginEnabled(p)) { if (!isRegistered(p = "UltimateRepairing") && pm.isPluginEnabled(p)) {
register((JavaPlugin) pm.getPlugin(p), 20, LegacyMaterials.ANVIL.name()); register((JavaPlugin) pm.getPlugin(p), 20, CompatibleMaterial.ANVIL.name());
} }
if (!isRegistered(p = "UltimateStacker") && pm.isPluginEnabled(p)) { if (!isRegistered(p = "UltimateStacker") && pm.isPluginEnabled(p)) {
register((JavaPlugin) pm.getPlugin(p), 16, LegacyMaterials.IRON_INGOT.name()); register((JavaPlugin) pm.getPlugin(p), 16, CompatibleMaterial.IRON_INGOT.name());
} }
if (!isRegistered(p = "UltimateTimber") && pm.isPluginEnabled(p)) { if (!isRegistered(p = "UltimateTimber") && pm.isPluginEnabled(p)) {
register((JavaPlugin) pm.getPlugin(p), 18, LegacyMaterials.IRON_AXE.name()); register((JavaPlugin) pm.getPlugin(p), 18, CompatibleMaterial.IRON_AXE.name());
} }
} }

View File

@ -14,7 +14,7 @@ import org.bukkit.inventory.ItemStack;
* @since 2019-08-23 * @since 2019-08-23
* @author jascotty2 * @author jascotty2
*/ */
public enum LegacyMaterials { public enum CompatibleMaterial {
/* /*
TODO: add another handler for getBlockItem() for materials and fallback materials TODO: add another handler for getBlockItem() for materials and fallback materials
@ -1008,7 +1008,7 @@ public enum LegacyMaterials {
ZOMBIE_WALL_HEAD("SKULL", (byte) 2),; ZOMBIE_WALL_HEAD("SKULL", (byte) 2),;
private final String modern, modern2, legacy; private final String modern, modern2, legacy;
private final LegacyAnalouges compatibleMaterial; private final LegacyMaterialAnalouge compatibleMaterial;
private final boolean legacyRequiresData; private final boolean legacyRequiresData;
// some materials (I'm looking at you, GREEN_DYE) have changed ID more than once // some materials (I'm looking at you, GREEN_DYE) have changed ID more than once
// minVersion is the min for modern, and minVersion2 is min to use legacyCompat1 // minVersion is the min for modern, and minVersion2 is min to use legacyCompat1
@ -1019,43 +1019,43 @@ public enum LegacyMaterials {
// quick test to see if our version is < 1.13 // quick test to see if our version is < 1.13
protected static final boolean useLegacy = ServerVersion.isServerVersionBelow(ServerVersion.V1_13); protected static final boolean useLegacy = ServerVersion.isServerVersionBelow(ServerVersion.V1_13);
// map to speed up name->material lookups // map to speed up name->material lookups
private static final Map<String, LegacyMaterials> lookupMap = new HashMap(); private static final Map<String, CompatibleMaterial> lookupMap = new HashMap();
static { static {
for (LegacyMaterials m : values()) { for (CompatibleMaterial m : values()) {
lookupMap.put(m.name(), m); lookupMap.put(m.name(), m);
if (!m.usesCompatibility()) { if (!m.usesCompatibility()) {
lookupMap.put(m.material + ":" + (m.data == null ? "" : m.data), m); lookupMap.put(m.material + ":" + (m.data == null ? "" : m.data), m);
} }
} }
for (LegacyMaterials m : values()) { for (CompatibleMaterial m : values()) {
if (!m.usesCompatibility() && !lookupMap.containsKey(m.legacy)) { if (!m.usesCompatibility() && !lookupMap.containsKey(m.legacy)) {
lookupMap.put(m.legacy, m); lookupMap.put(m.legacy, m);
} }
} }
} }
LegacyMaterials() { CompatibleMaterial() {
this(ServerVersion.UNKNOWN, null, null); this(ServerVersion.UNKNOWN, null, null);
} }
LegacyMaterials(String legacy) { CompatibleMaterial(String legacy) {
this(ServerVersion.V1_13, null, null, legacy, null); this(ServerVersion.V1_13, null, null, legacy, null);
} }
LegacyMaterials(String legacy, byte legacyData) { CompatibleMaterial(String legacy, byte legacyData) {
this(ServerVersion.V1_13, null, null, legacy, legacyData); this(ServerVersion.V1_13, null, null, legacy, legacyData);
} }
LegacyMaterials(ServerVersion modernMinimum, String legacy) { CompatibleMaterial(ServerVersion modernMinimum, String legacy) {
this(modernMinimum, null, null, legacy, null); this(modernMinimum, null, null, legacy, null);
} }
LegacyMaterials(ServerVersion modernMinimum, String legacy, Byte legacyData) { CompatibleMaterial(ServerVersion modernMinimum, String legacy, Byte legacyData) {
this(modernMinimum, null, null, legacy, legacyData); this(modernMinimum, null, null, legacy, legacyData);
} }
LegacyMaterials(ServerVersion modernMinimum, String modern2, ServerVersion modern2Minimum, String legacyMaterial, Byte legacyData) { CompatibleMaterial(ServerVersion modernMinimum, String modern2, ServerVersion modern2Minimum, String legacyMaterial, Byte legacyData) {
this.modern = name(); this.modern = name();
this.modern2 = modern2; this.modern2 = modern2;
this.minVersion = modernMinimum; this.minVersion = modernMinimum;
@ -1063,7 +1063,7 @@ public enum LegacyMaterials {
this.legacy = legacyMaterial; this.legacy = legacyMaterial;
this.legacyData = legacyData == null ? 0 : legacyData; this.legacyData = legacyData == null ? 0 : legacyData;
this.legacyRequiresData = legacyData != null; this.legacyRequiresData = legacyData != null;
this.compatibleMaterial = LegacyAnalouges.lookupAnalouge(modern); this.compatibleMaterial = LegacyMaterialAnalouge.lookupAnalouge(modern);
if (compatibleMaterial != null && ServerVersion.isServerVersionBelow(compatibleMaterial.versionLessThan)) { if (compatibleMaterial != null && ServerVersion.isServerVersionBelow(compatibleMaterial.versionLessThan)) {
// server older than this item: use a proxy // server older than this item: use a proxy
@ -1157,7 +1157,7 @@ public enum LegacyMaterials {
* @param name item to lookup * @param name item to lookup
* @return LegacyMaterial or null if none found * @return LegacyMaterial or null if none found
*/ */
public static LegacyMaterials getMaterial(String name) { public static CompatibleMaterial getMaterial(String name) {
return name == null ? null : lookupMap.get(name.toUpperCase()); return name == null ? null : lookupMap.get(name.toUpperCase());
} }
@ -1170,7 +1170,7 @@ public enum LegacyMaterials {
* @param def default item if this is not a valid material * @param def default item if this is not a valid material
* @return LegacyMaterial or null if none found * @return LegacyMaterial or null if none found
*/ */
public static LegacyMaterials getMaterial(String name, LegacyMaterials def) { public static CompatibleMaterial getMaterial(String name, CompatibleMaterial def) {
return name == null ? def : lookupMap.getOrDefault(name.toUpperCase(), def); return name == null ? def : lookupMap.getOrDefault(name.toUpperCase(), def);
} }
@ -1180,7 +1180,7 @@ public enum LegacyMaterials {
* @param mat item to lookup * @param mat item to lookup
* @return LegacyMaterial or null if none found * @return LegacyMaterial or null if none found
*/ */
public static LegacyMaterials getMaterial(Material mat) { public static CompatibleMaterial getMaterial(Material mat) {
return mat == null ? null : lookupMap.get(mat.name()); return mat == null ? null : lookupMap.get(mat.name());
} }
@ -1190,21 +1190,21 @@ public enum LegacyMaterials {
* @param item item to lookup * @param item item to lookup
* @return LegacyMaterial or null if none found * @return LegacyMaterial or null if none found
*/ */
public static LegacyMaterials getMaterial(ItemStack item) { public static CompatibleMaterial getMaterial(ItemStack item) {
if (item == null) { if (item == null) {
return null; return null;
} }
String key = item.getType() + ":"; String key = item.getType() + ":";
LegacyMaterials m = lookupMap.get(key); CompatibleMaterial m = lookupMap.get(key);
return m != null ? m : lookupMap.get(key + item.getDurability()); return m != null ? m : lookupMap.get(key + item.getDurability());
} }
static LinkedHashSet<LegacyMaterials> all = null; static LinkedHashSet<CompatibleMaterial> all = null;
public static Set<LegacyMaterials> getAllValidItemMaterials() { public static Set<CompatibleMaterial> getAllValidItemMaterials() {
if (all == null) { if (all == null) {
all = new LinkedHashSet(); all = new LinkedHashSet();
for (LegacyMaterials mat : values()) { for (CompatibleMaterial mat : values()) {
if (mat.isValidItem() && !mat.usesCompatibility()) { if (mat.isValidItem() && !mat.usesCompatibility()) {
all.add(mat); all.add(mat);
} }
@ -1226,7 +1226,7 @@ public enum LegacyMaterials {
if (name == null) { if (name == null) {
return null; return null;
} }
LegacyMaterials m = lookupMap.get(name.toUpperCase()); CompatibleMaterial m = lookupMap.get(name.toUpperCase());
if (m != null) { if (m != null) {
return m.getItem(); return m.getItem();
} }
@ -2030,14 +2030,14 @@ public enum LegacyMaterials {
return false; return false;
} }
public static LegacyMaterials getSpawnEgg(EntityType type) { public static CompatibleMaterial getSpawnEgg(EntityType type) {
if(type == EntityType.MUSHROOM_COW) { if(type == EntityType.MUSHROOM_COW) {
return MOOSHROOM_SPAWN_EGG; return MOOSHROOM_SPAWN_EGG;
} }
return lookupMap.get(type.name() + "_SPAWN_EGG"); return lookupMap.get(type.name() + "_SPAWN_EGG");
} }
public static LegacyMaterials getGlassPaneColor(int color) { public static CompatibleMaterial getGlassPaneColor(int color) {
switch (color) { switch (color) {
case 0: case 0:
return WHITE_STAINED_GLASS_PANE; return WHITE_STAINED_GLASS_PANE;
@ -2075,7 +2075,7 @@ public enum LegacyMaterials {
return WHITE_STAINED_GLASS_PANE; return WHITE_STAINED_GLASS_PANE;
} }
public static LegacyMaterials getGlassColor(int color) { public static CompatibleMaterial getGlassColor(int color) {
switch (color) { switch (color) {
case 0: case 0:
return WHITE_STAINED_GLASS; return WHITE_STAINED_GLASS;
@ -2113,7 +2113,7 @@ public enum LegacyMaterials {
return WHITE_STAINED_GLASS; return WHITE_STAINED_GLASS;
} }
public static LegacyMaterials getDyeColor(int color) { public static CompatibleMaterial getDyeColor(int color) {
switch (color) { switch (color) {
case 0: case 0:
return BLACK_DYE; return BLACK_DYE;

View File

@ -9,7 +9,7 @@ import org.bukkit.Location;
import org.bukkit.Particle; import org.bukkit.Particle;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
public class ParticleHandler { public class CompatibleParticleHandler {
public static enum ParticleType { public static enum ParticleType {
EXPLOSION_NORMAL(), EXPLOSION_NORMAL(),

View File

@ -14,7 +14,7 @@ import org.bukkit.Sound;
* @since 2019-08-25 * @since 2019-08-25
* @author jascotty2 * @author jascotty2
*/ */
public enum CompatibleSounds { public enum CompatibleSound {
// some of these values are missing an API value.. // some of these values are missing an API value..
// would using the raw strings be better? // would using the raw strings be better?
@ -820,7 +820,7 @@ public enum CompatibleSounds {
protected /*final*/ boolean compatibilityMode; protected /*final*/ boolean compatibilityMode;
protected static final boolean DEBUG = false; protected static final boolean DEBUG = false;
private CompatibleSounds() { private CompatibleSound() {
// This could get risky, since we haven't finished this // This could get risky, since we haven't finished this
//sound = Sound.valueOf(name()); //sound = Sound.valueOf(name());
Sound find = null; Sound find = null;
@ -838,7 +838,7 @@ public enum CompatibleSounds {
} }
// if the sound ony ever changed from 1.8 -> 1.9 // if the sound ony ever changed from 1.8 -> 1.9
private CompatibleSounds(String compatibility_18) { private CompatibleSound(String compatibility_18) {
try { try {
compatibilityMode = false; compatibilityMode = false;
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_9)) { if (ServerVersion.isServerVersionBelow(ServerVersion.V1_9)) {
@ -852,7 +852,7 @@ public enum CompatibleSounds {
} }
} }
private CompatibleSounds(Version... versions) { private CompatibleSound(Version... versions) {
try { try {
for (Version v : versions) { for (Version v : versions) {
if (v.sound != null && ServerVersion.isServerVersionAtLeast(v.version)) { if (v.sound != null && ServerVersion.isServerVersionAtLeast(v.version)) {
@ -880,7 +880,7 @@ public enum CompatibleSounds {
compatibilityMode = find == null; compatibilityMode = find == null;
} }
private CompatibleSounds(ServerVersion minVersion, Version... versions) { private CompatibleSound(ServerVersion minVersion, Version... versions) {
try { try {
if (ServerVersion.isServerVersionAtLeast(minVersion)) { if (ServerVersion.isServerVersionAtLeast(minVersion)) {
// should be good to use this sound // should be good to use this sound

View File

@ -10,7 +10,7 @@ import org.bukkit.inventory.ItemStack;
* @since 2019-08-23 * @since 2019-08-23
* @author jascotty2 * @author jascotty2
*/ */
public enum LegacyAnalouges { public enum LegacyMaterialAnalouge {
ACACIA_BOAT(ServerVersion.V1_9, "BOAT"), ACACIA_BOAT(ServerVersion.V1_9, "BOAT"),
ACACIA_BUTTON(ServerVersion.V1_13, "WOOD_BUTTON"), ACACIA_BUTTON(ServerVersion.V1_13, "WOOD_BUTTON"),
@ -486,47 +486,47 @@ public enum LegacyAnalouges {
final Byte data; final Byte data;
// map to speed up name->material lookups // map to speed up name->material lookups
private static final Map<String, LegacyAnalouges> lookupMap = new HashMap(); private static final Map<String, LegacyMaterialAnalouge> lookupMap = new HashMap();
static { static {
for (LegacyAnalouges m : values()) { for (LegacyMaterialAnalouge m : values()) {
lookupMap.put(m.name(), m); lookupMap.put(m.name(), m);
} }
} }
public static LegacyAnalouges lookupAnalouge(String material) { public static LegacyMaterialAnalouge lookupAnalouge(String material) {
return lookupMap.get(material); return lookupMap.get(material);
} }
private LegacyAnalouges(ServerVersion versionLessThan, String legacyMaterial, byte legacyData) { private LegacyMaterialAnalouge(ServerVersion versionLessThan, String legacyMaterial, byte legacyData) {
this(versionLessThan, null, legacyMaterial, legacyData, null, null, null); this(versionLessThan, null, legacyMaterial, legacyData, null, null, null);
} }
private LegacyAnalouges(ServerVersion versionLessThan, String legacyMaterial) { private LegacyMaterialAnalouge(ServerVersion versionLessThan, String legacyMaterial) {
this(versionLessThan, null, legacyMaterial, null, null, null, null); this(versionLessThan, null, legacyMaterial, null, null, null, null);
} }
private LegacyAnalouges(ServerVersion versionLessThan, String modernAnalouge, String legacyMaterial) { private LegacyMaterialAnalouge(ServerVersion versionLessThan, String modernAnalouge, String legacyMaterial) {
this(versionLessThan, modernAnalouge, legacyMaterial, null, null, null, null); this(versionLessThan, modernAnalouge, legacyMaterial, null, null, null, null);
} }
private LegacyAnalouges(ServerVersion versionLessThan, String modernAnalouge, String legacyMaterial, byte legacyData) { private LegacyMaterialAnalouge(ServerVersion versionLessThan, String modernAnalouge, String legacyMaterial, byte legacyData) {
this(versionLessThan, modernAnalouge, legacyMaterial, legacyData, null, null, null); this(versionLessThan, modernAnalouge, legacyMaterial, legacyData, null, null, null);
} }
private LegacyAnalouges(ServerVersion versionLessThan, String legacyMaterial, byte legacyData, ServerVersion legacyMinimum, String compatMaterial, byte compatData) { private LegacyMaterialAnalouge(ServerVersion versionLessThan, String legacyMaterial, byte legacyData, ServerVersion legacyMinimum, String compatMaterial, byte compatData) {
this(versionLessThan, null, legacyMaterial, legacyData, legacyMinimum, compatMaterial, compatData); this(versionLessThan, null, legacyMaterial, legacyData, legacyMinimum, compatMaterial, compatData);
} }
private LegacyAnalouges(ServerVersion versionLessThan, String legacyMaterial, ServerVersion legacyMinimum, String compatMaterial, byte compatData) { private LegacyMaterialAnalouge(ServerVersion versionLessThan, String legacyMaterial, ServerVersion legacyMinimum, String compatMaterial, byte compatData) {
this(versionLessThan, null, legacyMaterial, null, legacyMinimum, compatMaterial, compatData); this(versionLessThan, null, legacyMaterial, null, legacyMinimum, compatMaterial, compatData);
} }
private LegacyAnalouges(ServerVersion versionLessThan, String legacyMaterial, byte legacyData, ServerVersion legacyMinimum, String compatMaterial) { private LegacyMaterialAnalouge(ServerVersion versionLessThan, String legacyMaterial, byte legacyData, ServerVersion legacyMinimum, String compatMaterial) {
this(versionLessThan, null, legacyMaterial, legacyData, legacyMinimum, compatMaterial, null); this(versionLessThan, null, legacyMaterial, legacyData, legacyMinimum, compatMaterial, null);
} }
private LegacyAnalouges(ServerVersion versionLessThan, String legacyMaterial, ServerVersion legacyMinimum, String compatMaterial) { private LegacyMaterialAnalouge(ServerVersion versionLessThan, String legacyMaterial, ServerVersion legacyMinimum, String compatMaterial) {
this(versionLessThan, null, legacyMaterial, null, legacyMinimum, compatMaterial, null); this(versionLessThan, null, legacyMaterial, null, legacyMinimum, compatMaterial, null);
} }
@ -537,7 +537,7 @@ public enum LegacyAnalouges {
* @param legacyMaterial pre-1.13 material name * @param legacyMaterial pre-1.13 material name
* @param legacyData data for defining specific legacy items * @param legacyData data for defining specific legacy items
*/ */
private LegacyAnalouges(ServerVersion versionLessThan, String modernAnalouge, String legacyMaterial, Byte legacyData, ServerVersion legacyMinimum, String compatMaterial, Byte compatData) { private LegacyMaterialAnalouge(ServerVersion versionLessThan, String modernAnalouge, String legacyMaterial, Byte legacyData, ServerVersion legacyMinimum, String compatMaterial, Byte compatData) {
this.versionLessThan = versionLessThan; this.versionLessThan = versionLessThan;
this.modernMaterial = modernAnalouge; this.modernMaterial = modernAnalouge;
this.legacyMaterial = legacyMaterial; this.legacyMaterial = legacyMaterial;

View File

@ -6,7 +6,7 @@ import org.bukkit.Bukkit;
public enum ServerProject { public enum ServerProject {
UNKNOWN, CRAFTBUKKIT, SPIGOT, PAPER, TACO, GLOWSTONE; UNKNOWN, CRAFTBUKKIT, SPIGOT, PAPER, TACO, GLOWSTONE;
private static ServerProject serverProject = checkProject(); private final static ServerProject serverProject = checkProject();
private static ServerProject checkProject() { private static ServerProject checkProject() {
String serverPath = Bukkit.getServer().getClass().getName(); String serverPath = Bukkit.getServer().getClass().getName();

View File

@ -9,16 +9,16 @@ public enum ServerVersion {
private final static String serverPackagePath = Bukkit.getServer().getClass().getPackage().getName(); private final static String serverPackagePath = Bukkit.getServer().getClass().getPackage().getName();
private final static String serverPackageVersion = serverPackagePath.substring(serverPackagePath.lastIndexOf('.') + 1); private final static String serverPackageVersion = serverPackagePath.substring(serverPackagePath.lastIndexOf('.') + 1);
private static ServerVersion serverVersion = UNKNOWN; private final static String serverReleaseVersion = serverPackageVersion.indexOf('R') != -1 ? serverPackageVersion.substring(serverPackageVersion.indexOf('R') + 1) : "";
private static String serverReleaseVersion; private final static ServerVersion serverVersion = getVersion();
static { private static ServerVersion getVersion() {
for (ServerVersion version : values()) { for (ServerVersion version : values()) {
if (serverPackageVersion.toUpperCase().startsWith(version.name())) { if (serverPackageVersion.toUpperCase().startsWith(version.name())) {
serverVersion = version; return version;
serverReleaseVersion = serverPackageVersion.substring(version.name().length() + 2);
} }
} }
return UNKNOWN;
} }
public boolean isLessThan(ServerVersion other) { public boolean isLessThan(ServerVersion other) {

View File

@ -1,7 +1,6 @@
package com.songoda.core.configuration; package com.songoda.core.configuration;
import com.songoda.core.compatibility.LegacyMaterials; import com.songoda.core.compatibility.CompatibleMaterial;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -257,12 +256,12 @@ public class ConfigFileConfigurationAdapter extends FileConfiguration {
} }
@Nullable @Nullable
public LegacyMaterials getMaterial(@NotNull String path) { public CompatibleMaterial getMaterial(@NotNull String path) {
return config.getMaterial(path); return config.getMaterial(path);
} }
@Nullable @Nullable
public LegacyMaterials getMaterial(@NotNull String path, @Nullable LegacyMaterials def) { public CompatibleMaterial getMaterial(@NotNull String path, @Nullable CompatibleMaterial def) {
return config.getMaterial(path, def); return config.getMaterial(path, def);
} }

View File

@ -1,6 +1,6 @@
package com.songoda.core.configuration; package com.songoda.core.configuration;
import com.songoda.core.compatibility.LegacyMaterials; import com.songoda.core.compatibility.CompatibleMaterial;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -631,16 +631,16 @@ public class ConfigSection extends MemoryConfiguration {
} }
@Nullable @Nullable
public LegacyMaterials getMaterial(@NotNull String path) { public CompatibleMaterial getMaterial(@NotNull String path) {
String val = getString(path); String val = getString(path);
LegacyMaterials mat = val != null ? LegacyMaterials.getMaterial(val) : null; CompatibleMaterial mat = val != null ? CompatibleMaterial.getMaterial(val) : null;
return mat; return mat;
} }
@Nullable @Nullable
public LegacyMaterials getMaterial(@NotNull String path, @Nullable LegacyMaterials def) { public CompatibleMaterial getMaterial(@NotNull String path, @Nullable CompatibleMaterial def) {
String val = getString(path); String val = getString(path);
LegacyMaterials mat = val != null ? LegacyMaterials.getMaterial(val) : null; CompatibleMaterial mat = val != null ? CompatibleMaterial.getMaterial(val) : null;
return mat != null ? mat : def; return mat != null ? mat : def;
} }

View File

@ -1,6 +1,6 @@
package com.songoda.core.configuration; package com.songoda.core.configuration;
import com.songoda.core.compatibility.LegacyMaterials; import com.songoda.core.compatibility.CompatibleMaterial;
import java.util.List; import java.util.List;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -105,16 +105,16 @@ public class ConfigSetting {
} }
@NotNull @NotNull
public LegacyMaterials getMaterial() { public CompatibleMaterial getMaterial() {
LegacyMaterials m = getMaterial(null); CompatibleMaterial m = getMaterial(null);
return m != null ? m : LegacyMaterials.STONE; return m != null ? m : CompatibleMaterial.STONE;
} }
@Nullable @Nullable
public LegacyMaterials getMaterial(@Nullable LegacyMaterials def) { public CompatibleMaterial getMaterial(@Nullable CompatibleMaterial def) {
//return config.getMaterial(key, def); //return config.getMaterial(key, def);
String val = config.getString(key); String val = config.getString(key);
LegacyMaterials mat = val != null ? LegacyMaterials.getMaterial(val) : null; CompatibleMaterial mat = val != null ? CompatibleMaterial.getMaterial(val) : null;
if (mat == null) { if (mat == null) {
System.out.println(String.format("Config value \"%s\" has an invalid material name: \"%s\"", key, val)); System.out.println(String.format("Config value \"%s\" has an invalid material name: \"%s\"", key, val));

View File

@ -1,6 +1,6 @@
package com.songoda.core.configuration.editor; package com.songoda.core.configuration.editor;
import com.songoda.core.compatibility.LegacyMaterials; import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.gui.Gui; import com.songoda.core.gui.Gui;
import com.songoda.core.gui.GuiUtils; import com.songoda.core.gui.GuiUtils;
import com.songoda.core.gui.SimplePagedGui; import com.songoda.core.gui.SimplePagedGui;
@ -49,7 +49,7 @@ public class ConfigEditorGui extends SimplePagedGui {
this.file = file; this.file = file;
this.config = config; this.config = config;
this.node = node; this.node = node;
this.blankItem = GuiUtils.getBorderItem(LegacyMaterials.LIGHT_GRAY_STAINED_GLASS_PANE); this.blankItem = GuiUtils.getBorderItem(CompatibleMaterial.LIGHT_GRAY_STAINED_GLASS_PANE);
// if we have a ConfigSection, we can also grab comments // if we have a ConfigSection, we can also grab comments
try { try {
@ -60,10 +60,10 @@ public class ConfigEditorGui extends SimplePagedGui {
// decorate header // decorate header
this.setTitle(ChatColor.DARK_BLUE + file); this.setTitle(ChatColor.DARK_BLUE + file);
this.setUseHeader(true); this.setUseHeader(true);
headerBackItem = footerBackItem = GuiUtils.getBorderItem(LegacyMaterials.GRAY_STAINED_GLASS_PANE.getItem()); headerBackItem = footerBackItem = GuiUtils.getBorderItem(CompatibleMaterial.GRAY_STAINED_GLASS_PANE.getItem());
final String path = node.getCurrentPath(); final String path = node.getCurrentPath();
this.setItem(4, configItem(LegacyMaterials.FILLED_MAP, !path.isEmpty() ? path : file , config, !path.isEmpty() ? path : null, ChatColor.BLACK.toString())); this.setItem(4, configItem(CompatibleMaterial.FILLED_MAP, !path.isEmpty() ? path : file , config, !path.isEmpty() ? path : null, ChatColor.BLACK.toString()));
this.setButton(8, GuiUtils.createButtonItem(LegacyMaterials.OAK_DOOR, "Exit"), (event) -> event.player.closeInventory()); this.setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_DOOR, "Exit"), (event) -> event.player.closeInventory());
// compile list of settings // compile list of settings
for (String key : node.getKeys(false)) { for (String key : node.getKeys(false)) {
@ -77,7 +77,7 @@ public class ConfigEditorGui extends SimplePagedGui {
// next we need to display the config settings // next we need to display the config settings
int index = 9; int index = 9;
for (final String sectionKey : sections) { for (final String sectionKey : sections) {
setButton(index++, configItem(LegacyMaterials.WRITABLE_BOOK, ChatColor.YELLOW + sectionKey, node, sectionKey, "Click to open this section"), setButton(index++, configItem(CompatibleMaterial.WRITABLE_BOOK, ChatColor.YELLOW + sectionKey, node, sectionKey, "Click to open this section"),
(event) -> event.manager.showGUI(event.player, new ConfigEditorGui(plugin, this, file, config, node.getConfigurationSection(sectionKey)))); (event) -> event.manager.showGUI(event.player, new ConfigEditorGui(plugin, this, file, config, node.getConfigurationSection(sectionKey))));
} }
@ -87,14 +87,14 @@ public class ConfigEditorGui extends SimplePagedGui {
if(val == null) continue; if(val == null) continue;
else if (val instanceof Boolean) { else if (val instanceof Boolean) {
// toggle switch // toggle switch
setButton(index, configItem(LegacyMaterials.LEVER, ChatColor.YELLOW + settingKey, node, settingKey, String.valueOf((Boolean) val), "Click to toggle this setting"), setButton(index, configItem(CompatibleMaterial.LEVER, ChatColor.YELLOW + settingKey, node, settingKey, String.valueOf((Boolean) val), "Click to toggle this setting"),
(event) -> this.toggle(event.slot, settingKey)); (event) -> this.toggle(event.slot, settingKey));
if ((Boolean) val) { if ((Boolean) val) {
highlightItem(index); highlightItem(index);
} }
} else if (isNumber(val)) { } else if (isNumber(val)) {
// number dial // number dial
this.setButton(index, configItem(LegacyMaterials.CLOCK, ChatColor.YELLOW + settingKey, node, settingKey, String.valueOf((Number) val), "Click to edit this setting"), this.setButton(index, configItem(CompatibleMaterial.CLOCK, ChatColor.YELLOW + settingKey, node, settingKey, String.valueOf((Number) val), "Click to edit this setting"),
(event) -> { (event) -> {
event.gui.exit(); event.gui.exit();
ChatPrompt.showPrompt(plugin, event.player, "Enter a new number value for " + settingKey + ":", response -> { ChatPrompt.showPrompt(plugin, event.player, "Enter a new number value for " + settingKey + ":", response -> {
@ -107,14 +107,14 @@ public class ConfigEditorGui extends SimplePagedGui {
} else if (isMaterial(val)) { } else if (isMaterial(val)) {
// changing a block // changing a block
// isMaterial is more of a guess, to be honest. // isMaterial is more of a guess, to be honest.
setButton(index, configItem(LegacyMaterials.STONE, ChatColor.YELLOW + settingKey, node, settingKey, val.toString(), "Click to edit this setting"), setButton(index, configItem(CompatibleMaterial.STONE, ChatColor.YELLOW + settingKey, node, settingKey, val.toString(), "Click to edit this setting"),
(event) -> { (event) -> {
SimplePagedGui paged = new SimplePagedGui(this); SimplePagedGui paged = new SimplePagedGui(this);
paged.setTitle(ChatColor.BLUE + settingKey); paged.setTitle(ChatColor.BLUE + settingKey);
paged.setHeaderBackItem(headerBackItem).setFooterBackItem(footerBackItem).setDefaultItem(blankItem); paged.setHeaderBackItem(headerBackItem).setFooterBackItem(footerBackItem).setDefaultItem(blankItem);
paged.setItem(4, configItem(LegacyMaterials.FILLED_MAP, settingKey, node, settingKey, "Choose an item to change this value to")); paged.setItem(4, configItem(CompatibleMaterial.FILLED_MAP, settingKey, node, settingKey, "Choose an item to change this value to"));
int i = 9; int i = 9;
for(LegacyMaterials mat : LegacyMaterials.getAllValidItemMaterials()) { for(CompatibleMaterial mat : CompatibleMaterial.getAllValidItemMaterials()) {
paged.setButton(i++, GuiUtils.createButtonItem(mat, mat.name()), ClickType.LEFT, (matEvent) -> { paged.setButton(i++, GuiUtils.createButtonItem(mat, mat.name()), ClickType.LEFT, (matEvent) -> {
setMaterial(event.slot, settingKey, matEvent.clickedItem); setMaterial(event.slot, settingKey, matEvent.clickedItem);
matEvent.player.closeInventory(); matEvent.player.closeInventory();
@ -125,7 +125,7 @@ public class ConfigEditorGui extends SimplePagedGui {
} else if (val instanceof String) { } else if (val instanceof String) {
// changing a "string" value (or change to a feather for writing quill) // changing a "string" value (or change to a feather for writing quill)
setButton(index, configItem(LegacyMaterials.STRING, ChatColor.YELLOW + settingKey, node, settingKey, val.toString(), "Click to edit this setting"), setButton(index, configItem(CompatibleMaterial.STRING, ChatColor.YELLOW + settingKey, node, settingKey, val.toString(), "Click to edit this setting"),
(event) -> { (event) -> {
event.gui.exit(); event.gui.exit();
ChatPrompt.showPrompt(plugin, event.player, "Enter a new value for " + settingKey + ":", response -> { ChatPrompt.showPrompt(plugin, event.player, "Enter a new value for " + settingKey + ":", response -> {
@ -135,7 +135,7 @@ public class ConfigEditorGui extends SimplePagedGui {
.setOnCancel(() -> {event.player.sendMessage(ChatColor.RED + "Edit canceled"); event.manager.showGUI(event.player, this);}); .setOnCancel(() -> {event.player.sendMessage(ChatColor.RED + "Edit canceled"); event.manager.showGUI(event.player, this);});
}); });
} else if (val instanceof List) { } else if (val instanceof List) {
setButton(index, configItem(LegacyMaterials.WRITABLE_BOOK, ChatColor.YELLOW + settingKey, node, settingKey, String.format("(%d values)", ((List) val).size()), "Click to edit this setting"), setButton(index, configItem(CompatibleMaterial.WRITABLE_BOOK, ChatColor.YELLOW + settingKey, node, settingKey, String.format("(%d values)", ((List) val).size()), "Click to edit this setting"),
(event) -> { (event) -> {
event.manager.showGUI(event.player, (new ConfigEditorListEditorGui(this, settingKey, (List) val)).setOnClose((gui) -> { event.manager.showGUI(event.player, (new ConfigEditorListEditorGui(this, settingKey, (List) val)).setOnClose((gui) -> {
if(((ConfigEditorListEditorGui) gui.gui).saveChanges) { if(((ConfigEditorListEditorGui) gui.gui).saveChanges) {
@ -208,9 +208,9 @@ public class ConfigEditorGui extends SimplePagedGui {
} }
void setMaterial(int clickCell, String path, ItemStack item) { void setMaterial(int clickCell, String path, ItemStack item) {
LegacyMaterials mat = LegacyMaterials.getMaterial(item); CompatibleMaterial mat = CompatibleMaterial.getMaterial(item);
if (mat == null) { if (mat == null) {
node.set(path, LegacyMaterials.STONE.name()); node.set(path, CompatibleMaterial.STONE.name());
} else { } else {
node.set(path, mat.name()); node.set(path, mat.name());
} }
@ -244,12 +244,12 @@ public class ConfigEditorGui extends SimplePagedGui {
} }
private boolean isMaterial(Object value) { private boolean isMaterial(Object value) {
LegacyMaterials m; CompatibleMaterial m;
return value instanceof String && value.toString().equals(value.toString().toUpperCase()) return value instanceof String && value.toString().equals(value.toString().toUpperCase())
&& (m = LegacyMaterials.getMaterial(value.toString())) != null && m.isValidItem(); && (m = CompatibleMaterial.getMaterial(value.toString())) != null && m.isValidItem();
} }
protected ItemStack configItem(LegacyMaterials type, String name, ConfigurationSection node, String path, String def) { protected ItemStack configItem(CompatibleMaterial type, String name, ConfigurationSection node, String path, String def) {
String[] info = null; String[] info = null;
if (configSection_getCommentString != null) { if (configSection_getCommentString != null) {
try { try {
@ -263,7 +263,7 @@ public class ConfigEditorGui extends SimplePagedGui {
return GuiUtils.createButtonItem(type, name, info != null ? info : (def != null ? def.split("\n") : null)); return GuiUtils.createButtonItem(type, name, info != null ? info : (def != null ? def.split("\n") : null));
} }
protected ItemStack configItem(LegacyMaterials type, String name, ConfigurationSection node, String path, String value, String def) { protected ItemStack configItem(CompatibleMaterial type, String name, ConfigurationSection node, String path, String value, String def) {
if(value == null) value = ""; if(value == null) value = "";
String[] info = null; String[] info = null;
if (configSection_getCommentString != null) { if (configSection_getCommentString != null) {

View File

@ -1,12 +1,11 @@
package com.songoda.core.configuration.editor; package com.songoda.core.configuration.editor;
import com.songoda.core.compatibility.LegacyMaterials; import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.gui.GuiUtils; import com.songoda.core.gui.GuiUtils;
import com.songoda.core.gui.SimplePagedGui; import com.songoda.core.gui.SimplePagedGui;
import com.songoda.core.input.ChatPrompt; import com.songoda.core.input.ChatPrompt;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
@ -30,16 +29,16 @@ public class ConfigEditorListEditorGui extends SimplePagedGui {
headerBackItem = footerBackItem = current.getHeaderBackItem(); headerBackItem = footerBackItem = current.getHeaderBackItem();
setTitle(ChatColor.DARK_BLUE + "String List Editor"); setTitle(ChatColor.DARK_BLUE + "String List Editor");
this.setUseHeader(true); this.setUseHeader(true);
this.setItem(4, current.configItem(LegacyMaterials.FILLED_MAP, key, current.getCurrentNode(), key, null)); this.setItem(4, current.configItem(CompatibleMaterial.FILLED_MAP, key, current.getCurrentNode(), key, null));
this.setButton(8, GuiUtils.createButtonItem(LegacyMaterials.OAK_DOOR, "Exit"), (event) -> event.player.closeInventory()); this.setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_DOOR, "Exit"), (event) -> event.player.closeInventory());
this.values = new ArrayList(val); this.values = new ArrayList(val);
this.setButton(8, GuiUtils.createButtonItem(LegacyMaterials.LAVA_BUCKET, ChatColor.RED + "Discard Changes"), (event) -> event.player.closeInventory()); this.setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.LAVA_BUCKET, ChatColor.RED + "Discard Changes"), (event) -> event.player.closeInventory());
this.setButton(0, GuiUtils.createButtonItem(LegacyMaterials.REDSTONE, ChatColor.GREEN + "Save"), (event) -> { this.setButton(0, GuiUtils.createButtonItem(CompatibleMaterial.REDSTONE, ChatColor.GREEN + "Save"), (event) -> {
saveChanges = true; saveChanges = true;
event.player.closeInventory(); event.player.closeInventory();
}); });
this.setButton(1, GuiUtils.createButtonItem(LegacyMaterials.CHEST, ChatColor.BLUE + "Add Item"), this.setButton(1, GuiUtils.createButtonItem(CompatibleMaterial.CHEST, ChatColor.BLUE + "Add Item"),
(event) -> { (event) -> {
event.gui.exit(); event.gui.exit();
ChatPrompt.showPrompt(event.manager.getPlugin(), event.player, "Enter a new value to add:", response -> { ChatPrompt.showPrompt(event.manager.getPlugin(), event.player, "Enter a new value to add:", response -> {
@ -68,7 +67,7 @@ public class ConfigEditorListEditorGui extends SimplePagedGui {
int i = 9; int i = 9;
for (String item : values) { for (String item : values) {
final int index = i - 9; final int index = i - 9;
setButton(i++, GuiUtils.createButtonItem(LegacyMaterials.PAPER, item, "Right-click to remove"), ClickType.RIGHT, (event) -> { setButton(i++, GuiUtils.createButtonItem(CompatibleMaterial.PAPER, item, "Right-click to remove"), ClickType.RIGHT, (event) -> {
values.remove(index); values.remove(index);
redraw(); redraw();
}); });

View File

@ -1,7 +1,7 @@
package com.songoda.core.configuration.editor; package com.songoda.core.configuration.editor;
import com.songoda.core.SongodaPlugin; import com.songoda.core.SongodaPlugin;
import com.songoda.core.compatibility.LegacyMaterials; import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.configuration.Config; import com.songoda.core.configuration.Config;
import com.songoda.core.gui.Gui; import com.songoda.core.gui.Gui;
import com.songoda.core.gui.GuiUtils; import com.songoda.core.gui.GuiUtils;
@ -79,18 +79,18 @@ public class PluginConfigGui extends SimplePagedGui {
} }
private void init() { private void init() {
this.blankItem = GuiUtils.getBorderItem(LegacyMaterials.LIGHT_GRAY_STAINED_GLASS_PANE); this.blankItem = GuiUtils.getBorderItem(CompatibleMaterial.LIGHT_GRAY_STAINED_GLASS_PANE);
// decorate header // decorate header
this.setTitle(ChatColor.DARK_BLUE + plugin.getName() + " Plugin Config"); this.setTitle(ChatColor.DARK_BLUE + plugin.getName() + " Plugin Config");
this.setUseHeader(true); this.setUseHeader(true);
headerBackItem = footerBackItem = GuiUtils.getBorderItem(LegacyMaterials.GRAY_STAINED_GLASS_PANE.getItem()); headerBackItem = footerBackItem = GuiUtils.getBorderItem(CompatibleMaterial.GRAY_STAINED_GLASS_PANE.getItem());
this.setButton(8, GuiUtils.createButtonItem(LegacyMaterials.OAK_DOOR, "Exit"), (event) -> event.player.closeInventory()); this.setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_DOOR, "Exit"), (event) -> event.player.closeInventory());
// List out all config files that this plugin has // List out all config files that this plugin has
int i = 9; int i = 9;
for (Map.Entry<String, MemoryConfiguration> config : configs.entrySet()) { for (Map.Entry<String, MemoryConfiguration> config : configs.entrySet()) {
this.setButton(i++, GuiUtils.createButtonItem(LegacyMaterials.BOOK, ChatColor.YELLOW + config.getKey(), "Click to edit this config"), this.setButton(i++, GuiUtils.createButtonItem(CompatibleMaterial.BOOK, ChatColor.YELLOW + config.getKey(), "Click to edit this config"),
(event) -> event.manager.showGUI(event.player, new ConfigEditorGui(plugin, this, config.getKey(), config.getValue()))); (event) -> event.manager.showGUI(event.player, new ConfigEditorGui(plugin, this, config.getKey(), config.getValue())));
} }
} }

View File

@ -1,6 +1,6 @@
package com.songoda.core.core; package com.songoda.core.core;
import com.songoda.core.compatibility.LegacyMaterials; import com.songoda.core.compatibility.CompatibleMaterial;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
@ -13,7 +13,7 @@ public final class PluginInfo {
protected final JavaPlugin javaPlugin; protected final JavaPlugin javaPlugin;
protected final int songodaId; protected final int songodaId;
protected final String coreIcon; protected final String coreIcon;
protected final LegacyMaterials icon; protected final CompatibleMaterial icon;
private final List<PluginInfoModule> modules = new ArrayList<>(); private final List<PluginInfoModule> modules = new ArrayList<>();
private boolean hasUpdate = false; private boolean hasUpdate = false;
private String latestVersion; private String latestVersion;
@ -26,7 +26,7 @@ public final class PluginInfo {
this.javaPlugin = javaPlugin; this.javaPlugin = javaPlugin;
this.songodaId = songodaId; this.songodaId = songodaId;
this.coreIcon = icon; this.coreIcon = icon;
this.icon = LegacyMaterials.getMaterial(icon); this.icon = CompatibleMaterial.getMaterial(icon);
} }
public String getLatestVersion() { public String getLatestVersion() {

View File

@ -1,7 +1,7 @@
package com.songoda.core.core; package com.songoda.core.core;
import com.songoda.core.SongodaCore; import com.songoda.core.SongodaCore;
import com.songoda.core.compatibility.LegacyMaterials; import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.configuration.editor.PluginConfigGui; import com.songoda.core.configuration.editor.PluginConfigGui;
import com.songoda.core.gui.Gui; import com.songoda.core.gui.Gui;
import com.songoda.core.gui.GuiUtils; import com.songoda.core.gui.GuiUtils;
@ -23,7 +23,7 @@ final class SongodaCoreOverviewGUI extends Gui {
for (int i = 0; i < plugins.size(); i++) { for (int i = 0; i < plugins.size(); i++) {
final PluginInfo plugin = plugins.get(i); final PluginInfo plugin = plugins.get(i);
if (plugin.hasUpdate()) { if (plugin.hasUpdate()) {
setButton(i, GuiUtils.createButtonItem(plugin.icon != null ? plugin.icon : LegacyMaterials.STONE, setButton(i, GuiUtils.createButtonItem(plugin.icon != null ? plugin.icon : CompatibleMaterial.STONE,
ChatColor.GOLD + plugin.getJavaPlugin().getName(), ChatColor.GOLD + plugin.getJavaPlugin().getName(),
ChatColor.GRAY + "Latest Version: " + plugin.getLatestVersion(), ChatColor.GRAY + "Latest Version: " + plugin.getLatestVersion(),
ChatColor.GRAY + "Installed Version: " + plugin.getJavaPlugin().getDescription().getVersion(), ChatColor.GRAY + "Installed Version: " + plugin.getJavaPlugin().getDescription().getVersion(),
@ -38,7 +38,7 @@ final class SongodaCoreOverviewGUI extends Gui {
setAction(i, ClickType.RIGHT, (event) -> event.manager.showGUI(event.player, new PluginConfigGui(plugin.getJavaPlugin(), event.gui))); setAction(i, ClickType.RIGHT, (event) -> event.manager.showGUI(event.player, new PluginConfigGui(plugin.getJavaPlugin(), event.gui)));
highlightItem(i); highlightItem(i);
} else { } else {
setButton(i, GuiUtils.createButtonItem(plugin.icon != null ? plugin.icon : LegacyMaterials.STONE, setButton(i, GuiUtils.createButtonItem(plugin.icon != null ? plugin.icon : CompatibleMaterial.STONE,
ChatColor.GOLD + plugin.getJavaPlugin().getName(), ChatColor.GOLD + plugin.getJavaPlugin().getName(),
ChatColor.GRAY + "Installed Version: " + plugin.getJavaPlugin().getDescription().getVersion(), ChatColor.GRAY + "Installed Version: " + plugin.getJavaPlugin().getDescription().getVersion(),
"", "",

View File

@ -1,6 +1,6 @@
package com.songoda.core.gui; package com.songoda.core.gui;
import com.songoda.core.compatibility.LegacyMaterials; import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.configuration.DataStoreObject; import com.songoda.core.configuration.DataStoreObject;
import com.songoda.core.configuration.SimpleDataStore; import com.songoda.core.configuration.SimpleDataStore;
import com.songoda.core.gui.methods.Clickable; import com.songoda.core.gui.methods.Clickable;
@ -52,7 +52,7 @@ public class CustomizableGui extends Gui {
@Override @Override
public CustomizableGui setDefaultItem(ItemStack item) { public CustomizableGui setDefaultItem(ItemStack item) {
if ((blankItem = item) != null) { if ((blankItem = item) != null) {
buttons.put("__DEFAULT__", (new CustomButton("__DEFAULT__")).setIcon(LegacyMaterials.getMaterial(item))); buttons.put("__DEFAULT__", (new CustomButton("__DEFAULT__")).setIcon(CompatibleMaterial.getMaterial(item)));
} }
return this; return this;
} }
@ -72,7 +72,7 @@ public class CustomizableGui extends Gui {
public CustomizableGui setItem(int defaultCell, @NotNull String key, @NotNull ItemStack item) { public CustomizableGui setItem(int defaultCell, @NotNull String key, @NotNull ItemStack item) {
CustomButton btn = key == null ? null : buttons.get(key = key.toLowerCase()); CustomButton btn = key == null ? null : buttons.get(key = key.toLowerCase());
if (btn == null) { if (btn == null) {
buttons.put(key, btn = (new CustomButton(key, defaultCell)).setIcon(LegacyMaterials.getMaterial(item))); buttons.put(key, btn = (new CustomButton(key, defaultCell)).setIcon(CompatibleMaterial.getMaterial(item)));
} else { } else {
ItemStack btnItem = btn.icon.getItem(); ItemStack btnItem = btn.icon.getItem();
ItemMeta itemMeta = item.getItemMeta(); ItemMeta itemMeta = item.getItemMeta();
@ -92,13 +92,13 @@ public class CustomizableGui extends Gui {
} }
@NotNull @NotNull
public CustomizableGui setItem(int defaultRow, int defaultCol, @NotNull String key, @NotNull LegacyMaterials defaultItem, @NotNull String title, @NotNull String... lore) { public CustomizableGui setItem(int defaultRow, int defaultCol, @NotNull String key, @NotNull CompatibleMaterial defaultItem, @NotNull String title, @NotNull String... lore) {
final int cell = defaultCol + defaultRow * 9; final int cell = defaultCol + defaultRow * 9;
return setItem(cell, key, defaultItem, title, lore); return setItem(cell, key, defaultItem, title, lore);
} }
@NotNull @NotNull
public CustomizableGui setItem(int defaultCell, @NotNull String key, @NotNull LegacyMaterials defaultItem, @NotNull String title, @NotNull String... lore) { public CustomizableGui setItem(int defaultCell, @NotNull String key, @NotNull CompatibleMaterial defaultItem, @NotNull String title, @NotNull String... lore) {
CustomButton btn = key == null ? null : buttons.get(key = key.toLowerCase()); CustomButton btn = key == null ? null : buttons.get(key = key.toLowerCase());
if (btn == null) { if (btn == null) {
buttons.put(key, btn = (new CustomButton(key, defaultCell)).setIcon(defaultItem)); buttons.put(key, btn = (new CustomButton(key, defaultCell)).setIcon(defaultItem));
@ -129,6 +129,33 @@ public class CustomizableGui extends Gui {
return this; return this;
} }
@NotNull
public Gui updateItemLore(@NotNull String key, @NotNull String... lore) {
CustomButton btn = key == null ? null : buttons.get(key.toLowerCase());
if (btn != null) {
this.updateItemLore(btn.position, lore);
}
return this;
}
@NotNull
public Gui updateItemLore(@NotNull String key, @Nullable List<String> lore) {
CustomButton btn = key == null ? null : buttons.get(key.toLowerCase());
if (btn != null) {
this.updateItemLore(btn.position, lore);
}
return this;
}
@NotNull
public Gui updateItemName(@NotNull String key, @Nullable String name) {
CustomButton btn = key == null ? null : buttons.get(key.toLowerCase());
if (btn != null) {
this.updateItemName(btn.position, title);
}
return this;
}
@NotNull @NotNull
public CustomizableGui updateItem(@NotNull String key, @Nullable String title, @NotNull String... lore) { public CustomizableGui updateItem(@NotNull String key, @Nullable String title, @NotNull String... lore) {
CustomButton btn = key == null ? null : buttons.get(key.toLowerCase()); CustomButton btn = key == null ? null : buttons.get(key.toLowerCase());
@ -148,7 +175,7 @@ public class CustomizableGui extends Gui {
} }
@NotNull @NotNull
public CustomizableGui updateItem(@NotNull String key, @NotNull LegacyMaterials itemTo, @NotNull String title, @NotNull String... lore) { public CustomizableGui updateItem(@NotNull String key, @NotNull CompatibleMaterial itemTo, @NotNull String title, @NotNull String... lore) {
CustomButton btn = key == null ? null : buttons.get(key.toLowerCase()); CustomButton btn = key == null ? null : buttons.get(key.toLowerCase());
if (btn != null) { if (btn != null) {
this.updateItem(btn.position, itemTo, title, lore); this.updateItem(btn.position, itemTo, title, lore);
@ -157,7 +184,7 @@ public class CustomizableGui extends Gui {
} }
@NotNull @NotNull
public CustomizableGui updateItem(@NotNull String key, @NotNull LegacyMaterials itemTo, @NotNull String title, @Nullable List<String> lore) { public CustomizableGui updateItem(@NotNull String key, @NotNull CompatibleMaterial itemTo, @NotNull String title, @Nullable List<String> lore) {
CustomButton btn = key == null ? null : buttons.get(key.toLowerCase()); CustomButton btn = key == null ? null : buttons.get(key.toLowerCase());
if (btn != null) { if (btn != null) {
this.updateItem(btn.position, itemTo, title, lore); this.updateItem(btn.position, itemTo, title, lore);
@ -224,7 +251,7 @@ public class CustomizableGui extends Gui {
public CustomizableGui setNextPage(int cell, @NotNull ItemStack item) { public CustomizableGui setNextPage(int cell, @NotNull ItemStack item) {
CustomButton btn = buttons.get("__NEXT__"); CustomButton btn = buttons.get("__NEXT__");
if (btn == null) { if (btn == null) {
buttons.put("__NEXT__", btn = (new CustomButton("__NEXT__", cell)).setIcon(LegacyMaterials.getMaterial(item))); buttons.put("__NEXT__", btn = (new CustomButton("__NEXT__", cell)).setIcon(CompatibleMaterial.getMaterial(item)));
} else { } else {
ItemStack btnItem = btn.icon.getItem(); ItemStack btnItem = btn.icon.getItem();
ItemMeta itemMeta = item.getItemMeta(); ItemMeta itemMeta = item.getItemMeta();
@ -250,7 +277,7 @@ public class CustomizableGui extends Gui {
public CustomizableGui setPrevPage(int cell, @NotNull ItemStack item) { public CustomizableGui setPrevPage(int cell, @NotNull ItemStack item) {
CustomButton btn = buttons.get("__PREV__"); CustomButton btn = buttons.get("__PREV__");
if (btn == null) { if (btn == null) {
buttons.put("__PREV__", btn = (new CustomButton("__PREV__", cell)).setIcon(LegacyMaterials.getMaterial(item))); buttons.put("__PREV__", btn = (new CustomButton("__PREV__", cell)).setIcon(CompatibleMaterial.getMaterial(item)));
} else { } else {
ItemStack btnItem = btn.icon.getItem(); ItemStack btnItem = btn.icon.getItem();
ItemMeta itemMeta = item.getItemMeta(); ItemMeta itemMeta = item.getItemMeta();
@ -278,7 +305,7 @@ public class CustomizableGui extends Gui {
boolean _changed = false; boolean _changed = false;
final String key; final String key;
int position = -1; int position = -1;
LegacyMaterials icon = LegacyMaterials.STONE; CompatibleMaterial icon = CompatibleMaterial.STONE;
public CustomButton(String key) { public CustomButton(String key) {
this.key = key; this.key = key;
@ -291,7 +318,7 @@ public class CustomizableGui extends Gui {
public static CustomButton loadFromSection(ConfigurationSection sec) { public static CustomButton loadFromSection(ConfigurationSection sec) {
CustomButton dat = new CustomButton(sec.getName()); CustomButton dat = new CustomButton(sec.getName());
dat.icon = sec.contains("icon") ? LegacyMaterials.getMaterial(sec.getString("icon"), LegacyMaterials.STONE) : LegacyMaterials.STONE; dat.icon = sec.contains("icon") ? CompatibleMaterial.getMaterial(sec.getString("icon"), CompatibleMaterial.STONE) : CompatibleMaterial.STONE;
dat.position = sec.getInt("position"); dat.position = sec.getInt("position");
return dat; return dat;
} }
@ -322,12 +349,12 @@ public class CustomizableGui extends Gui {
_changed = isChanged; _changed = isChanged;
} }
public LegacyMaterials getIcon() { public CompatibleMaterial getIcon() {
return icon; return icon;
} }
public CustomButton setIcon(LegacyMaterials icon) { public CustomButton setIcon(CompatibleMaterial icon) {
this.icon = icon != null ? icon : LegacyMaterials.STONE; this.icon = icon != null ? icon : CompatibleMaterial.STONE;
_changed = true; _changed = true;
return this; return this;
} }

View File

@ -1,6 +1,6 @@
package com.songoda.core.gui; package com.songoda.core.gui;
import com.songoda.core.compatibility.LegacyMaterials; import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.gui.events.GuiClickEvent; import com.songoda.core.gui.events.GuiClickEvent;
import com.songoda.core.gui.events.GuiDropItemEvent; import com.songoda.core.gui.events.GuiDropItemEvent;
import com.songoda.core.gui.methods.Clickable; import com.songoda.core.gui.methods.Clickable;
@ -378,12 +378,12 @@ public class DoubleGui extends Gui {
} }
@Override @Override
public DoubleGui updateItem(int row, int col, LegacyMaterials itemTo, String title, String... lore) { public DoubleGui updateItem(int row, int col, CompatibleMaterial itemTo, String title, String... lore) {
return (DoubleGui) super.updateItem(col + row * 9, itemTo, title, lore); return (DoubleGui) super.updateItem(col + row * 9, itemTo, title, lore);
} }
@Override @Override
public DoubleGui updateItem(int cell, LegacyMaterials itemTo, String title, String... lore) { public DoubleGui updateItem(int cell, CompatibleMaterial itemTo, String title, String... lore) {
return (DoubleGui) super.updateItem(cell, itemTo, title, lore); return (DoubleGui) super.updateItem(cell, itemTo, title, lore);
} }
@ -398,12 +398,12 @@ public class DoubleGui extends Gui {
} }
@Override @Override
public DoubleGui updateItem(int row, int col, LegacyMaterials itemTo, String title, List<String> lore) { public DoubleGui updateItem(int row, int col, CompatibleMaterial itemTo, String title, List<String> lore) {
return (DoubleGui) super.updateItem(col + row * 9, itemTo, title, lore); return (DoubleGui) super.updateItem(col + row * 9, itemTo, title, lore);
} }
@Override @Override
public DoubleGui updateItem(int cell, LegacyMaterials itemTo, String title, List<String> lore) { public DoubleGui updateItem(int cell, CompatibleMaterial itemTo, String title, List<String> lore) {
return (DoubleGui) super.updateItem(cell, itemTo, title, lore); return (DoubleGui) super.updateItem(cell, itemTo, title, lore);
} }

View File

@ -1,6 +1,6 @@
package com.songoda.core.gui; package com.songoda.core.gui;
import com.songoda.core.compatibility.LegacyMaterials; import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.gui.events.GuiClickEvent; import com.songoda.core.gui.events.GuiClickEvent;
import com.songoda.core.gui.events.GuiCloseEvent; import com.songoda.core.gui.events.GuiCloseEvent;
import com.songoda.core.gui.events.GuiDropItemEvent; import com.songoda.core.gui.events.GuiDropItemEvent;
@ -330,6 +330,48 @@ public class Gui {
return this; return this;
} }
@NotNull
public Gui updateItemLore(int row, int col, @NotNull String... lore) {
return updateItemLore(col + row * 9, lore);
}
@NotNull
public Gui updateItemLore(int cell, @NotNull String... lore) {
ItemStack item = cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) {
setItem(cell, GuiUtils.updateItemLore(item, lore));
}
return this;
}
@NotNull
public Gui updateItemLore(int row, int col, @Nullable List<String> lore) {
return updateItemLore(col + row * 9, lore);
}
@NotNull
public Gui updateItemLore(int cell, @Nullable List<String> lore) {
ItemStack item = cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) {
setItem(cell, GuiUtils.updateItemLore(item, lore));
}
return this;
}
@NotNull
public Gui updateItemName(int row, int col, @Nullable String name) {
return updateItemName(col + row * 9, name);
}
@NotNull
public Gui updateItemName(int cell, @Nullable String name) {
ItemStack item = cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) {
setItem(cell, GuiUtils.updateItemName(item, name));
}
return this;
}
@NotNull @NotNull
public Gui updateItem(int row, int col, @Nullable String name, @NotNull String... lore) { public Gui updateItem(int row, int col, @Nullable String name, @NotNull String... lore) {
return updateItem(col + row * 9, name, lore); return updateItem(col + row * 9, name, lore);
@ -373,12 +415,12 @@ public class Gui {
} }
@NotNull @NotNull
public Gui updateItem(int row, int col, @NotNull LegacyMaterials itemTo, @Nullable String title, @NotNull String... lore) { public Gui updateItem(int row, int col, @NotNull CompatibleMaterial itemTo, @Nullable String title, @NotNull String... lore) {
return updateItem(col + row * 9, itemTo, title, lore); return updateItem(col + row * 9, itemTo, title, lore);
} }
@NotNull @NotNull
public Gui updateItem(int cell, @NotNull LegacyMaterials itemTo, @Nullable String title, @Nullable String... lore) { public Gui updateItem(int cell, @NotNull CompatibleMaterial itemTo, @Nullable String title, @Nullable String... lore) {
ItemStack item = cellItems.get(cell); ItemStack item = cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) { if (item != null && item.getType() != Material.AIR) {
setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore)); setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore));
@ -401,12 +443,12 @@ public class Gui {
} }
@NotNull @NotNull
public Gui updateItem(int row, int col, @NotNull LegacyMaterials itemTo, @Nullable String title, @Nullable List<String> lore) { public Gui updateItem(int row, int col, @NotNull CompatibleMaterial itemTo, @Nullable String title, @Nullable List<String> lore) {
return updateItem(col + row * 9, itemTo, title, lore); return updateItem(col + row * 9, itemTo, title, lore);
} }
@NotNull @NotNull
public Gui updateItem(int cell, @NotNull LegacyMaterials itemTo, @Nullable String title, @Nullable List<String> lore) { public Gui updateItem(int cell, @NotNull CompatibleMaterial itemTo, @Nullable String title, @Nullable List<String> lore) {
ItemStack item = cellItems.get(cell); ItemStack item = cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) { if (item != null && item.getType() != Material.AIR) {
setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore)); setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore));

View File

@ -1,8 +1,8 @@
package com.songoda.core.gui; package com.songoda.core.gui;
import com.songoda.core.compatibility.ClientVersion; import com.songoda.core.compatibility.ClientVersion;
import com.songoda.core.compatibility.CompatibleSounds; import com.songoda.core.compatibility.CompatibleSound;
import com.songoda.core.compatibility.LegacyMaterials; import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.compatibility.ServerVersion; import com.songoda.core.compatibility.ServerVersion;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -95,14 +95,14 @@ public class GuiManager {
} }
public void showPopup(Player player, String message) { public void showPopup(Player player, String message) {
showPopup(player, message, LegacyMaterials.NETHER_STAR, BackgroundType.ADVENTURE); showPopup(player, message, CompatibleMaterial.NETHER_STAR, BackgroundType.ADVENTURE);
} }
public void showPopup(Player player, String message, LegacyMaterials icon) { public void showPopup(Player player, String message, CompatibleMaterial icon) {
showPopup(player, message, icon, BackgroundType.ADVENTURE); showPopup(player, message, icon, BackgroundType.ADVENTURE);
} }
public void showPopup(Player player, String message, LegacyMaterials icon, BackgroundType background) { public void showPopup(Player player, String message, CompatibleMaterial icon, BackgroundType background) {
if (ClientVersion.getClientVersion(player).isServerVersionAtLeast(ServerVersion.V1_12)) { if (ClientVersion.getClientVersion(player).isServerVersionAtLeast(ServerVersion.V1_12)) {
PopupMessage popup = new PopupMessage(plugin, icon, message, background); PopupMessage popup = new PopupMessage(plugin, icon, message, background);
popup.add(); popup.add();
@ -176,12 +176,12 @@ public class GuiManager {
event.setCancelled(!gui.unlockedCells.entrySet().stream().anyMatch(e -> event.getSlot() == e.getKey() && e.getValue())); event.setCancelled(!gui.unlockedCells.entrySet().stream().anyMatch(e -> event.getSlot() == e.getKey() && e.getValue()));
// process button press // process button press
if (gui.onClick(manager, player, openInv, event)) { if (gui.onClick(manager, player, openInv, event)) {
player.playSound(player.getLocation(), CompatibleSounds.UI_BUTTON_CLICK.getSound(), 1F, 1F); player.playSound(player.getLocation(), CompatibleSound.UI_BUTTON_CLICK.getSound(), 1F, 1F);
} }
} else { } else {
// Player clicked in the bottom inventory while GUI is open // Player clicked in the bottom inventory while GUI is open
if (gui.onClickPlayerInventory(manager, player, openInv, event)) { if (gui.onClickPlayerInventory(manager, player, openInv, event)) {
player.playSound(player.getLocation(), CompatibleSounds.UI_BUTTON_CLICK.getSound(), 1F, 1F); player.playSound(player.getLocation(), CompatibleSound.UI_BUTTON_CLICK.getSound(), 1F, 1F);
} else if (!gui.acceptsItems || event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) { } else if (!gui.acceptsItems || event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
event.setCancelled(true); event.setCancelled(true);
} }

View File

@ -1,6 +1,6 @@
package com.songoda.core.gui; package com.songoda.core.gui;
import com.songoda.core.compatibility.LegacyMaterials; import com.songoda.core.compatibility.CompatibleMaterial;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -16,7 +16,7 @@ import org.bukkit.inventory.meta.ItemMeta;
public class GuiUtils { public class GuiUtils {
public static ItemStack getBorderGlassItem() { public static ItemStack getBorderGlassItem() {
ItemStack glass = LegacyMaterials.LIGHT_BLUE_STAINED_GLASS_PANE.getItem(); ItemStack glass = CompatibleMaterial.LIGHT_BLUE_STAINED_GLASS_PANE.getItem();
ItemMeta glassmeta = glass.getItemMeta(); ItemMeta glassmeta = glass.getItemMeta();
glassmeta.setDisplayName(ChatColor.BLACK.toString()); glassmeta.setDisplayName(ChatColor.BLACK.toString());
glass.setItemMeta(glassmeta); glass.setItemMeta(glassmeta);
@ -30,7 +30,7 @@ public class GuiUtils {
return item; return item;
} }
public static ItemStack getBorderItem(LegacyMaterials mat) { public static ItemStack getBorderItem(CompatibleMaterial mat) {
ItemStack item = mat.getItem(); ItemStack item = mat.getItem();
ItemMeta glassmeta = item.getItemMeta(); ItemMeta glassmeta = item.getItemMeta();
glassmeta.setDisplayName(ChatColor.BLACK.toString()); glassmeta.setDisplayName(ChatColor.BLACK.toString());
@ -88,7 +88,7 @@ public class GuiUtils {
return newLore; return newLore;
} }
public static ItemStack createButtonItem(LegacyMaterials mat, String title, String... lore) { public static ItemStack createButtonItem(CompatibleMaterial mat, String title, String... lore) {
ItemStack item = mat.getItem(); ItemStack item = mat.getItem();
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
if (meta != null) { if (meta != null) {
@ -103,7 +103,7 @@ public class GuiUtils {
return item; return item;
} }
public static ItemStack createButtonItem(LegacyMaterials mat, int amount, String title, String... lore) { public static ItemStack createButtonItem(CompatibleMaterial mat, int amount, String title, String... lore) {
ItemStack item = mat.getItem(); ItemStack item = mat.getItem();
item.setAmount(amount); item.setAmount(amount);
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
@ -129,12 +129,12 @@ public class GuiUtils {
} else { } else {
meta.setLore(Collections.EMPTY_LIST); meta.setLore(Collections.EMPTY_LIST);
} }
item.setItemMeta(meta);
} }
item.setItemMeta(meta);
return item; return item;
} }
public static ItemStack createButtonItem(LegacyMaterials mat, String title, List<String> lore) { public static ItemStack createButtonItem(CompatibleMaterial mat, String title, List<String> lore) {
ItemStack item = mat.getItem(); ItemStack item = mat.getItem();
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
if (meta != null) { if (meta != null) {
@ -144,12 +144,12 @@ public class GuiUtils {
} else { } else {
meta.setLore(Collections.EMPTY_LIST); meta.setLore(Collections.EMPTY_LIST);
} }
item.setItemMeta(meta);
} }
item.setItemMeta(meta);
return item; return item;
} }
public static ItemStack createButtonItem(LegacyMaterials mat, int amount, String title, List<String> lore) { public static ItemStack createButtonItem(CompatibleMaterial mat, int amount, String title, List<String> lore) {
ItemStack item = mat.getItem(); ItemStack item = mat.getItem();
item.setAmount(amount); item.setAmount(amount);
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
@ -160,8 +160,8 @@ public class GuiUtils {
} else { } else {
meta.setLore(Collections.EMPTY_LIST); meta.setLore(Collections.EMPTY_LIST);
} }
item.setItemMeta(meta);
} }
item.setItemMeta(meta);
return item; return item;
} }
@ -175,8 +175,8 @@ public class GuiUtils {
} else { } else {
meta.setLore(Collections.EMPTY_LIST); meta.setLore(Collections.EMPTY_LIST);
} }
item.setItemMeta(meta);
} }
item.setItemMeta(meta);
return item; return item;
} }
@ -189,12 +189,47 @@ public class GuiUtils {
} else { } else {
meta.setLore(Collections.EMPTY_LIST); meta.setLore(Collections.EMPTY_LIST);
} }
item.setItemMeta(meta);
} }
item.setItemMeta(meta);
return item; return item;
} }
public static ItemStack updateItem(ItemStack item, LegacyMaterials matTo, String title, String... lore) { public static ItemStack updateItemName(ItemStack item, String title) {
ItemMeta meta = item.getItemMeta();
if (meta != null) {
meta.setDisplayName(title);
item.setItemMeta(meta);
}
return item;
}
public static ItemStack updateItemLore(ItemStack item, String... lore) {
ItemMeta meta = item.getItemMeta();
if (meta != null) {
if (lore != null && lore.length != 0) {
meta.setLore(getSafeLore(lore));
} else {
meta.setLore(Collections.EMPTY_LIST);
}
item.setItemMeta(meta);
}
return item;
}
public static ItemStack updateItemLore(ItemStack item, List<String> lore) {
ItemMeta meta = item.getItemMeta();
if (meta != null) {
if (lore != null) {
meta.setLore(getSafeLore(lore));
} else {
meta.setLore(Collections.EMPTY_LIST);
}
item.setItemMeta(meta);
}
return item;
}
public static ItemStack updateItem(ItemStack item, CompatibleMaterial matTo, String title, String... lore) {
if (!matTo.matches(item)) { if (!matTo.matches(item)) {
item = matTo.getItem(); item = matTo.getItem();
} }
@ -206,13 +241,13 @@ public class GuiUtils {
} else { } else {
meta.setLore(Collections.EMPTY_LIST); meta.setLore(Collections.EMPTY_LIST);
} }
item.setItemMeta(meta);
} }
item.setItemMeta(meta);
return item; return item;
} }
public static ItemStack updateItem(ItemStack item, ItemStack to, String title, String... lore) { public static ItemStack updateItem(ItemStack item, ItemStack to, String title, String... lore) {
if (!LegacyMaterials.getMaterial(item).matches(to)) { if (!CompatibleMaterial.getMaterial(item).matches(to)) {
item = to.clone(); item = to.clone();
} }
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
@ -223,8 +258,8 @@ public class GuiUtils {
} else { } else {
meta.setLore(Collections.EMPTY_LIST); meta.setLore(Collections.EMPTY_LIST);
} }
item.setItemMeta(meta);
} }
item.setItemMeta(meta);
return item; return item;
} }
@ -237,12 +272,12 @@ public class GuiUtils {
} else { } else {
meta.setLore(Collections.EMPTY_LIST); meta.setLore(Collections.EMPTY_LIST);
} }
item.setItemMeta(meta);
} }
item.setItemMeta(meta);
return item; return item;
} }
public static ItemStack updateItem(ItemStack item, LegacyMaterials matTo, String title, List<String> lore) { public static ItemStack updateItem(ItemStack item, CompatibleMaterial matTo, String title, List<String> lore) {
if (!matTo.matches(item)) { if (!matTo.matches(item)) {
item = matTo.getItem(); item = matTo.getItem();
} }
@ -254,13 +289,13 @@ public class GuiUtils {
} else { } else {
meta.setLore(Collections.EMPTY_LIST); meta.setLore(Collections.EMPTY_LIST);
} }
item.setItemMeta(meta);
} }
item.setItemMeta(meta);
return item; return item;
} }
public static ItemStack updateItem(ItemStack item, ItemStack to, String title, List<String> lore) { public static ItemStack updateItem(ItemStack item, ItemStack to, String title, List<String> lore) {
if (!LegacyMaterials.getMaterial(item).matches(to)) { if (!CompatibleMaterial.getMaterial(item).matches(to)) {
item = to.clone(); item = to.clone();
} }
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
@ -271,8 +306,8 @@ public class GuiUtils {
} else { } else {
meta.setLore(Collections.EMPTY_LIST); meta.setLore(Collections.EMPTY_LIST);
} }
item.setItemMeta(meta);
} }
item.setItemMeta(meta);
return item; return item;
} }

View File

@ -4,7 +4,7 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.songoda.core.compatibility.LegacyMaterials; import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.compatibility.ServerVersion; import com.songoda.core.compatibility.ServerVersion;
import java.util.HashSet; import java.util.HashSet;
import java.util.UUID; import java.util.UUID;
@ -30,19 +30,19 @@ class PopupMessage {
final UUID id = UUID.randomUUID(); final UUID id = UUID.randomUUID();
private final NamespacedKey key; private final NamespacedKey key;
private final TextComponent title; private final TextComponent title;
LegacyMaterials icon; CompatibleMaterial icon;
int iconAmount = 1; // experimental, untested int iconAmount = 1; // experimental, untested
TriggerType trigger = TriggerType.IMPOSSIBLE; TriggerType trigger = TriggerType.IMPOSSIBLE;
FrameType frame = FrameType.GOAL; FrameType frame = FrameType.GOAL;
BackgroundType background = BackgroundType.ADVENTURE; BackgroundType background = BackgroundType.ADVENTURE;
PopupMessage(Plugin source, LegacyMaterials icon, String title) { PopupMessage(Plugin source, CompatibleMaterial icon, String title) {
this.key = new NamespacedKey(source, "popup/" + id); this.key = new NamespacedKey(source, "popup/" + id);
this.title = new TextComponent(title.length() < 74 ? title : (title.substring(0, 72) + "...")); this.title = new TextComponent(title.length() < 74 ? title : (title.substring(0, 72) + "..."));
this.icon = icon; this.icon = icon;
} }
PopupMessage(Plugin source, LegacyMaterials icon, String title, BackgroundType background) { PopupMessage(Plugin source, CompatibleMaterial icon, String title, BackgroundType background) {
this.key = new NamespacedKey(source, "popup/" + id); this.key = new NamespacedKey(source, "popup/" + id);
this.title = new TextComponent(title.length() < 74 ? title : (title.substring(0, 72) + "...")); this.title = new TextComponent(title.length() < 74 ? title : (title.substring(0, 72) + "..."));
this.icon = icon; this.icon = icon;

View File

@ -1,6 +1,6 @@
package com.songoda.core.gui; package com.songoda.core.gui;
import com.songoda.core.compatibility.LegacyMaterials; import com.songoda.core.compatibility.CompatibleMaterial;
import static com.songoda.core.gui.Gui.trimTitle; import static com.songoda.core.gui.Gui.trimTitle;
import com.songoda.core.gui.events.GuiClickEvent; import com.songoda.core.gui.events.GuiClickEvent;
import com.songoda.core.gui.methods.Clickable; import com.songoda.core.gui.methods.Clickable;
@ -35,8 +35,8 @@ public class SimplePagedGui extends Gui {
public SimplePagedGui(Gui parent) { public SimplePagedGui(Gui parent) {
super(parent); super(parent);
nextPage = GuiUtils.createButtonItem(LegacyMaterials.ARROW, "Next Page"); nextPage = GuiUtils.createButtonItem(CompatibleMaterial.ARROW, "Next Page");
prevPage = GuiUtils.createButtonItem(LegacyMaterials.ARROW, "Previous Page"); prevPage = GuiUtils.createButtonItem(CompatibleMaterial.ARROW, "Previous Page");
} }
public SimplePagedGui setUseHeader(boolean useHeader) { public SimplePagedGui setUseHeader(boolean useHeader) {

View File

@ -5,7 +5,7 @@ package com.songoda.core.utils;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.Property;
import com.songoda.core.compatibility.LegacyMaterials; import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.compatibility.ServerVersion; import com.songoda.core.compatibility.ServerVersion;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -243,7 +243,7 @@ public class ItemUtils {
} }
public static ItemStack getPlayerSkull(OfflinePlayer player) { public static ItemStack getPlayerSkull(OfflinePlayer player) {
ItemStack head = LegacyMaterials.PLAYER_HEAD.getItem(); ItemStack head = CompatibleMaterial.PLAYER_HEAD.getItem();
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_8)) { if (ServerVersion.isServerVersionBelow(ServerVersion.V1_8)) {
return head; return head;
} }
@ -258,7 +258,7 @@ public class ItemUtils {
} }
public static void setHeadOwner(ItemStack head, OfflinePlayer player) { public static void setHeadOwner(ItemStack head, OfflinePlayer player) {
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_8) || head == null || !LegacyMaterials.PLAYER_HEAD.matches(head)) { if (ServerVersion.isServerVersionBelow(ServerVersion.V1_8) || head == null || !CompatibleMaterial.PLAYER_HEAD.matches(head)) {
return; return;
} }
SkullMeta meta = (SkullMeta) head.getItemMeta(); SkullMeta meta = (SkullMeta) head.getItemMeta();
@ -270,7 +270,7 @@ public class ItemUtils {
} }
public static ItemStack getCustomHead(String texture) { public static ItemStack getCustomHead(String texture) {
ItemStack skullItem = LegacyMaterials.PLAYER_HEAD.getItem(); ItemStack skullItem = CompatibleMaterial.PLAYER_HEAD.getItem();
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_8)) { if (ServerVersion.isServerVersionBelow(ServerVersion.V1_8)) {
return skullItem; return skullItem;
} }
@ -332,8 +332,8 @@ public class ItemUtils {
* @return true if both items are of the same material * @return true if both items are of the same material
*/ */
public static boolean isSimilarMaterial(ItemStack is1, ItemStack is2) { public static boolean isSimilarMaterial(ItemStack is1, ItemStack is2) {
LegacyMaterials mat1 = LegacyMaterials.getMaterial(is1); CompatibleMaterial mat1 = CompatibleMaterial.getMaterial(is1);
return mat1 != null && mat1 == LegacyMaterials.getMaterial(is2); return mat1 != null && mat1 == CompatibleMaterial.getMaterial(is2);
} }
/** /**
@ -610,7 +610,7 @@ public class ItemUtils {
check = new boolean[3]; check = new boolean[3];
boolean isFuel = !item.getType().name().contains("LOG") && LegacyMaterials.getMaterial(item.getType()).isFuel(); boolean isFuel = !item.getType().name().contains("LOG") && CompatibleMaterial.getMaterial(item.getType()).isFuel();
// fuel is 2nd slot, input is first // fuel is 2nd slot, input is first
if (isFuel) { if (isFuel) {
@ -800,7 +800,7 @@ public class ItemUtils {
check = new boolean[3]; check = new boolean[3];
boolean isFuel = !item.getType().name().contains("LOG") && LegacyMaterials.getMaterial(item.getType()).isFuel(); boolean isFuel = !item.getType().name().contains("LOG") && CompatibleMaterial.getMaterial(item.getType()).isFuel();
// fuel is 2nd slot, input is first // fuel is 2nd slot, input is first
if (isFuel) { if (isFuel) {