General cleanup
This commit is contained in:
parent
07f4e10b62
commit
fa15557cb8
@ -26,21 +26,16 @@ import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
// TODO: Figure out if the config really does read the list of enchantments accurately. A bug report with a customized config seemed to load the default settings...
|
||||
// TODO: Verify enchantments on startup.
|
||||
// TODO: Enchanting should require XP.
|
||||
|
||||
public class ArmoredElytra extends JavaPlugin implements Listener
|
||||
{
|
||||
private static final MinecraftVersion minecraftVersion = MinecraftVersion
|
||||
.get(Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]);
|
||||
|
||||
private static ArmoredElytra instance;
|
||||
private static ArmoredElytra INSTANCE;
|
||||
private Messages messages;
|
||||
private ConfigLoader config;
|
||||
|
||||
private final Map<ArmorTier, ArmorTierName> armorTierNames = new EnumMap<>(ArmorTier.class);
|
||||
private boolean upToDate;
|
||||
private UpdateManager updateManager;
|
||||
|
||||
private INBTEditor nbtEditor;
|
||||
@ -48,7 +43,7 @@ public class ArmoredElytra extends JavaPlugin implements Listener
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
instance = this;
|
||||
INSTANCE = this;
|
||||
if (minecraftVersion.isOlderThan(MinecraftVersion.v1_15))
|
||||
{
|
||||
myLogger(Level.SEVERE, "Trying to run this plugin on an unsupported version... ABORT!");
|
||||
@ -87,22 +82,8 @@ public class ArmoredElytra extends JavaPlugin implements Listener
|
||||
myLogger(Level.INFO,
|
||||
"Stats disabled, not loading stats :(... Please consider enabling it! I am a simple man, seeing higher user numbers helps me stay motivated!");
|
||||
|
||||
// Load the files for the correct version of Minecraft.
|
||||
if (compatibleMCVer())
|
||||
{
|
||||
Bukkit.getPluginManager()
|
||||
.registerEvents(new EventHandlers(this, config.craftingInSmithingTable()), this);
|
||||
getCommand("ArmoredElytra").setExecutor(new CommandHandler(this));
|
||||
}
|
||||
else
|
||||
{
|
||||
Bukkit.getPluginManager().registerEvents(new LoginHandler(this,
|
||||
"The Armored Elytra plugin failed to start correctly! Please send the startup log to pim16aap2!"),
|
||||
this);
|
||||
myLogger(Level.WARNING,
|
||||
"Plugin failed to load! Either your version isn't supported or something went horribly wrong! Please contact pim16aap2!");
|
||||
return;
|
||||
}
|
||||
Bukkit.getPluginManager().registerEvents(new EventHandlers(this, config.craftingInSmithingTable()), this);
|
||||
getCommand("ArmoredElytra").setExecutor(new CommandHandler(this));
|
||||
|
||||
// Load the plugin normally if not in uninstall mode.
|
||||
if (!config.uninstallMode())
|
||||
@ -179,29 +160,12 @@ public class ArmoredElytra extends JavaPlugin implements Listener
|
||||
player.hasPermission("armoredelytra.craft." + ArmorTier.getName(armorTier));
|
||||
}
|
||||
|
||||
public static MinecraftVersion getMinecraftVersion()
|
||||
{
|
||||
return minecraftVersion;
|
||||
}
|
||||
|
||||
public boolean playerHasWearPerm(Player player, ArmorTier armorTier)
|
||||
{
|
||||
return getConfigLoader().bypassWearPerm() ||
|
||||
player.hasPermission("armoredelytra.wear." + ArmorTier.getName(armorTier));
|
||||
}
|
||||
|
||||
// Returns true if this is the latest version of this plugin.
|
||||
public boolean isUpToDate()
|
||||
{
|
||||
return upToDate;
|
||||
}
|
||||
|
||||
// Get this.
|
||||
public ArmoredElytra getPlugin()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
// Returns the config handler.
|
||||
public ConfigLoader getConfigLoader()
|
||||
{
|
||||
@ -281,15 +245,9 @@ public class ArmoredElytra extends JavaPlugin implements Listener
|
||||
return updateManager;
|
||||
}
|
||||
|
||||
// Check + initialize for the correct version of Minecraft.
|
||||
public boolean compatibleMCVer()
|
||||
{
|
||||
return minecraftVersion.isNewerThan(MinecraftVersion.v1_8);
|
||||
}
|
||||
|
||||
public static ArmoredElytra getInstance()
|
||||
{
|
||||
return instance;
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public String getArmoredElytraName(ArmorTier tier)
|
||||
@ -301,9 +259,4 @@ public class ArmoredElytra extends JavaPlugin implements Listener
|
||||
}
|
||||
return armorTierNames.get(tier).getLongName();
|
||||
}
|
||||
|
||||
public void setUpToDate(boolean upToDate)
|
||||
{
|
||||
this.upToDate = upToDate;
|
||||
}
|
||||
}
|
||||
|
@ -9,17 +9,15 @@ import java.util.List;
|
||||
|
||||
public class EnchantmentManager
|
||||
{
|
||||
private final ArmoredElytra armoredElytra;
|
||||
private final List<EnchantmentContainer> containers = new ArrayList<>();
|
||||
private Integer count = null;
|
||||
|
||||
public EnchantmentManager(final ItemStack is)
|
||||
{
|
||||
armoredElytra = ArmoredElytra.getInstance();
|
||||
EnchantmentPlatformManager.get().getPlatforms().forEach(platform ->
|
||||
containers.add(platform.getEnchantments(is)));
|
||||
|
||||
Collection<String> filter = armoredElytra.getConfigLoader().allowedEnchantments();
|
||||
Collection<String> filter = ArmoredElytra.getInstance().getConfigLoader().allowedEnchantments();
|
||||
containers.forEach(container -> container.filter(filter));
|
||||
}
|
||||
|
||||
|
@ -97,10 +97,9 @@ public class CommandHandler implements CommandExecutor
|
||||
{
|
||||
ItemStack newElytra;
|
||||
final String tier = args[1];
|
||||
if (Bukkit.getPlayer(args[0]) != null)
|
||||
player = Bukkit.getPlayer(args[0]);
|
||||
if (player != null)
|
||||
{
|
||||
player = Bukkit.getPlayer(args[0]);
|
||||
|
||||
ArmorTier armorTier = ArmorTier.valueOfName(tier.toLowerCase());
|
||||
if (armorTier == null)
|
||||
return false;
|
||||
|
@ -45,18 +45,8 @@ public class EventHandlers implements Listener
|
||||
|
||||
private void initializeArmorEquipEvent()
|
||||
{
|
||||
Bukkit.getPluginManager().registerEvents(new ArmorListener(new ArrayList<String>()), plugin);
|
||||
try
|
||||
{
|
||||
// Older versions did not have this event. So try to load it if possible, but
|
||||
// don't worry
|
||||
// about it not working.
|
||||
Class.forName("org.bukkit.event.block.BlockDispenseArmorEvent");
|
||||
plugin.getServer().getPluginManager().registerEvents(new DispenserArmorListener(), plugin);
|
||||
}
|
||||
catch (Exception ignored)
|
||||
{
|
||||
}
|
||||
Bukkit.getPluginManager().registerEvents(new ArmorListener(new ArrayList<>()), plugin);
|
||||
Bukkit.getPluginManager().registerEvents(new DispenserArmorListener(), plugin);
|
||||
}
|
||||
|
||||
private void moveChestplateToInventory(Player player)
|
||||
|
@ -14,19 +14,8 @@ import org.bukkit.persistence.PersistentDataType;
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
|
||||
// TODO: Consider using static UUIDs, to ensure attributes aren't stacked.
|
||||
public class NBTEditor implements INBTEditor
|
||||
{
|
||||
// private static final Map<ArmorTier, NamespacedKey> namespaceKeys;
|
||||
//
|
||||
// static
|
||||
// {
|
||||
// final Map<ArmorTier, NamespacedKey> namespaceKeysTmp = new EnumMap<ArmorTier, NamespacedKey>(ArmorTier.class);
|
||||
// for (final ArmorTier tier : ArmorTier.values())
|
||||
// namespaceKeysTmp.put(tier, new NamespacedKey(ArmoredElytra.getInstance(), "ARMORTIER_" + tier.name()));
|
||||
// namespaceKeys = Collections.unmodifiableMap(namespaceKeysTmp);
|
||||
// }
|
||||
|
||||
private static final NamespacedKey armorTierKey = new NamespacedKey(ArmoredElytra.getInstance(),
|
||||
"ARMOR_TIER_LEVEL");
|
||||
|
||||
|
@ -23,9 +23,9 @@ public enum ArmorTier
|
||||
private final double knockbackResistance;
|
||||
private final Material repair;
|
||||
private final String name;
|
||||
private static Map<String, ArmorTier> map = new HashMap<>();
|
||||
private static Map<Integer, ArmorTier> armorValueMap = new HashMap<>();
|
||||
private static Map<Integer, ArmorTier> armorIDMap = new HashMap<>();
|
||||
private static final Map<String, ArmorTier> map = new HashMap<>();
|
||||
private static final Map<Integer, ArmorTier> armorValueMap = new HashMap<>();
|
||||
private static final Map<Integer, ArmorTier> armorIDMap = new HashMap<>();
|
||||
|
||||
ArmorTier(int tierID, int armor, int toughness, double knockbackResistance, Material repair, String name)
|
||||
{
|
||||
@ -101,6 +101,7 @@ public enum ArmorTier
|
||||
// This value is the same as netherite's tier. However, with the introduction of the NETHERITE armor tier,
|
||||
// a new system was introduced that doesn't rely on the armor value for determining the armortier.
|
||||
// Therefore, when using the old backup system, it is always going to be the diamond tier instead.
|
||||
// While no new elytras cna be created using the old system, some may still be around from when it was still used.
|
||||
armorValueMap.put(ArmorTier.DIAMOND.armor, ArmorTier.DIAMOND);
|
||||
}
|
||||
}
|
||||
|
@ -35,8 +35,6 @@ public class Util
|
||||
{
|
||||
ArmorTier ret = ArmorTier.NONE;
|
||||
XMaterial xmat = XMaterial.matchXMaterial(mat);
|
||||
if (xmat == null)
|
||||
return ret;
|
||||
|
||||
switch (xmat)
|
||||
{
|
||||
@ -70,13 +68,10 @@ public class Util
|
||||
try
|
||||
{
|
||||
XMaterial xmat = XMaterial.matchXMaterial(mat);
|
||||
if (xmat == null)
|
||||
return false;
|
||||
if (xmat == XMaterial.LEATHER_CHESTPLATE || xmat == XMaterial.GOLDEN_CHESTPLATE ||
|
||||
|
||||
return xmat == XMaterial.LEATHER_CHESTPLATE || xmat == XMaterial.GOLDEN_CHESTPLATE ||
|
||||
xmat == XMaterial.CHAINMAIL_CHESTPLATE || xmat == XMaterial.IRON_CHESTPLATE ||
|
||||
xmat == XMaterial.DIAMOND_CHESTPLATE || xmat == XMaterial.NETHERITE_CHESTPLATE)
|
||||
return true;
|
||||
return false;
|
||||
xmat == XMaterial.DIAMOND_CHESTPLATE || xmat == XMaterial.NETHERITE_CHESTPLATE;
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
@ -86,7 +81,6 @@ public class Util
|
||||
}
|
||||
|
||||
// Function that returns which/how many protection enchantments there are.
|
||||
// TODO: Use bit flags for this.
|
||||
public static int getProtectionEnchantmentsVal(Map<Enchantment, Integer> enchantments)
|
||||
{
|
||||
int ret = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user