- Added option to customise the names for every tier or armored elytra.
- When taking an armored elytra out of an anvil using shift + click will no longer destroy the armored elytra when there is no space in the user's inventory.
This commit is contained in:
parent
f1f8607dd4
commit
e5044a7300
2
pom.xml
2
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>nl.pim16aap2</groupId>
|
||||
<artifactId>ArmoredElytra</artifactId>
|
||||
<version>2.2.1-SNAPSHOT</version>
|
||||
<version>2.3-SNAPSHOT</version>
|
||||
|
||||
|
||||
<repositories>
|
||||
|
@ -26,62 +26,63 @@ import nl.pim16aap2.armoredElytra.util.Update;
|
||||
|
||||
public class ArmoredElytra extends JavaPlugin implements Listener
|
||||
{
|
||||
private NBTEditor nbtEditor;
|
||||
private ConfigLoader config;
|
||||
private NBTEditor nbtEditor;
|
||||
private ConfigLoader config;
|
||||
|
||||
private String usageDeniedMessage;
|
||||
private String elytraReceivedMessage;
|
||||
private String elytraName;
|
||||
private String elytraLore;
|
||||
private boolean upToDate;
|
||||
private boolean uninstallMode;
|
||||
private String usageDeniedMessage;
|
||||
private String elytraReceivedMessage;
|
||||
private String elytraLore;
|
||||
private boolean upToDate;
|
||||
private boolean uninstallMode;
|
||||
private String leatherName, ironName, goldName, chainName, diamondName;
|
||||
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
// Load the settings from the config file.
|
||||
config = new ConfigLoader(this);
|
||||
|
||||
// Replace color codes by the corresponding colors.
|
||||
usageDeniedMessage = config.getString("usageDeniedMessage" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
||||
elytraReceivedMessage = config.getString("elytraReceivedMessage" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
||||
elytraName = config.getString("elytraName" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
||||
elytraLore = config.getString("elytraLore" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
||||
readConfigValues();
|
||||
|
||||
// Change the string to null if it says "NONE".
|
||||
usageDeniedMessage = (Objects.equals(usageDeniedMessage, new String("NONE")) ? null : usageDeniedMessage );
|
||||
elytraReceivedMessage = (Objects.equals(elytraReceivedMessage, new String("NONE")) ? null : elytraReceivedMessage);
|
||||
elytraLore = (Objects.equals(elytraLore, new String("NONE")) ? null : elytraLore );
|
||||
|
||||
// Check if the plugin should go into uninstall mode.
|
||||
uninstallMode = config.getBool("uninstallMode");
|
||||
|
||||
// Check if the user allows checking for updates.
|
||||
if (config.getBool("checkForUpdates"))
|
||||
{
|
||||
Update update = new Update(278437, this);
|
||||
|
||||
String latestVersion = update.getLatestVersion();
|
||||
String thisVersion = this.getDescription().getVersion();
|
||||
// Check if this is the latest version or not.
|
||||
int updateStatus = update.versionCompare(latestVersion, thisVersion);
|
||||
|
||||
if (updateStatus > 0)
|
||||
{
|
||||
Thread thread = new Thread(new Runnable()
|
||||
{
|
||||
// TODO: Insert download link to latest version.
|
||||
// TODO: Use Spiget instead of the unreliable BukkitDev's update stuff?
|
||||
// TODO: Add auto update option?
|
||||
|
||||
// Load the loginHandler to show messages to the user when they join.
|
||||
Bukkit.getPluginManager().registerEvents(new LoginHandler(this, "The Armored Elytra plugin is out of date!"), this);
|
||||
myLogger(Level.INFO, "Plugin out of date! You are using version " + thisVersion + " but the latest version is version " + latestVersion + "!");
|
||||
this.upToDate = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.upToDate = true;
|
||||
myLogger(Level.INFO, "You seem to be using the latest version of this plugin!");
|
||||
}
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
ArmoredElytra plugin = getPlugin();
|
||||
Update update = new Update(278437, plugin);
|
||||
String latestVersion = update.getLatestVersion();
|
||||
|
||||
if (latestVersion == null)
|
||||
plugin.myLogger(Level.WARNING, "Encountered problem contacting update servers! Please check manually! The error above does not affect the plugin!");
|
||||
else
|
||||
{
|
||||
String thisVersion = plugin.getDescription().getVersion();
|
||||
// Check if this is the latest version or not.
|
||||
int updateStatus = update.versionCompare(latestVersion, thisVersion);
|
||||
|
||||
if (updateStatus > 0)
|
||||
{
|
||||
// TODO: Insert download link to latest version.
|
||||
// TODO: Use Spiget as backup?
|
||||
// TODO: Add auto update option?
|
||||
|
||||
// Load the loginHandler to show messages to the user when they join.
|
||||
Bukkit.getPluginManager().registerEvents(new LoginHandler(plugin, "The Armored Elytra plugin is out of date!"), plugin);
|
||||
plugin.myLogger(Level.INFO, "Plugin out of date! You are using version " + thisVersion + " but the latest version is version " + latestVersion + "!");
|
||||
plugin.setUpToDate(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
plugin.setUpToDate(true);
|
||||
plugin.myLogger(Level.INFO, "You seem to be using the latest version of this plugin!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
else
|
||||
myLogger(Level.INFO, "Plugin update checking not enabled! You will not receive any messages about new updates for this plugin. Please consider turning this on in the config.");
|
||||
@ -107,7 +108,7 @@ public class ArmoredElytra extends JavaPlugin implements Listener
|
||||
if (compatibleMCVer())
|
||||
{
|
||||
Bukkit.getPluginManager().registerEvents(new EventHandlers(this, nbtEditor), this);
|
||||
getCommand("ArmoredElytra").setExecutor(new CommandHandler(this, nbtEditor, uninstallMode));
|
||||
getCommand("ArmoredElytra").setExecutor(new CommandHandler(this, nbtEditor));
|
||||
}
|
||||
else
|
||||
myLogger(Level.WARNING, "Trying to load the plugin on an incompatible version of Minecraft!");
|
||||
@ -141,12 +142,43 @@ public class ArmoredElytra extends JavaPlugin implements Listener
|
||||
}
|
||||
}
|
||||
|
||||
public void readConfigValues()
|
||||
{
|
||||
// Load the settings from the config file.
|
||||
this.config = new ConfigLoader(this);
|
||||
|
||||
// Replace color codes by the corresponding colors.
|
||||
this.usageDeniedMessage = config.getString("usageDeniedMessage" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
||||
this.elytraReceivedMessage = config.getString("elytraReceivedMessage" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
||||
this.elytraLore = config.getString("elytraLore" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
||||
|
||||
this.leatherName = config.getString("leatherName" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
||||
this.goldName = config.getString("goldName" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
||||
this.chainName = config.getString("chainName" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
||||
this.ironName = config.getString("ironName" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
||||
this.diamondName = config.getString("diamondName" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
||||
|
||||
// Change the string to null if it says "NONE".
|
||||
this.usageDeniedMessage = (Objects.equals(usageDeniedMessage, new String("NONE")) ? null : usageDeniedMessage );
|
||||
this.elytraReceivedMessage = (Objects.equals(elytraReceivedMessage, new String("NONE")) ? null : elytraReceivedMessage);
|
||||
this.elytraLore = (Objects.equals(elytraLore, new String("NONE")) ? null : elytraLore );
|
||||
|
||||
// Check if the plugin should go into uninstall mode.
|
||||
this.uninstallMode = config.getBool("uninstallMode");
|
||||
}
|
||||
|
||||
// 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()
|
||||
{
|
||||
@ -170,7 +202,7 @@ public class ArmoredElytra extends JavaPlugin implements Listener
|
||||
{
|
||||
if (usageDeniedMessage != null)
|
||||
{
|
||||
String message = fillInArmorTierInString(usageDeniedMessage, armorTier);
|
||||
String message = fillInArmorTierInStringNoColor(usageDeniedMessage, armorTier);
|
||||
messagePlayer(player, ChatColor.RED, message);
|
||||
}
|
||||
}
|
||||
@ -180,15 +212,15 @@ public class ArmoredElytra extends JavaPlugin implements Listener
|
||||
{
|
||||
if (elytraReceivedMessage != null)
|
||||
{
|
||||
String message = fillInArmorTierInString(elytraReceivedMessage, armorTier);
|
||||
String message = fillInArmorTierInStringNoColor(elytraReceivedMessage, armorTier);
|
||||
messagePlayer(player, ChatColor.GREEN, message);
|
||||
}
|
||||
}
|
||||
|
||||
// Replace %ARMOR_TIER% by the name of that armor tier in a string.
|
||||
public String fillInArmorTierInString(String string, ArmorTier armorTier)
|
||||
// Replace %ARMOR_TIER% by the name of that armor tier in a string, but strip %ARMOR_TIER% of its color.
|
||||
public String fillInArmorTierInStringNoColor(String string, ArmorTier armorTier)
|
||||
{
|
||||
return string.replace("%ARMOR_TIER%", ArmorTier.getArmorName(armorTier));
|
||||
return string.replace("%ARMOR_TIER%", ChatColor.stripColor(getArmoredElytrName(armorTier)));
|
||||
}
|
||||
|
||||
// Print a string to the log.
|
||||
@ -220,18 +252,60 @@ public class ArmoredElytra extends JavaPlugin implements Listener
|
||||
{
|
||||
version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
|
||||
}
|
||||
catch (ArrayIndexOutOfBoundsException whatVersionAreYouUsingException)
|
||||
catch (ArrayIndexOutOfBoundsException useAVersionMentionedInTheDescriptionPleaseException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (version.equals("v1_10_R1"))
|
||||
nbtEditor = new NBTEditor_V1_10_R1(elytraName, elytraLore, this);
|
||||
nbtEditor = new NBTEditor_V1_10_R1(this);
|
||||
else if (version.equals("v1_11_R1"))
|
||||
nbtEditor = new NBTEditor_V1_11_R1(elytraName, elytraLore, this);
|
||||
nbtEditor = new NBTEditor_V1_11_R1(this);
|
||||
else if (version.equals("v1_12_R1"))
|
||||
nbtEditor = new NBTEditor_V1_12_R1(elytraName, elytraLore, this);
|
||||
nbtEditor = new NBTEditor_V1_12_R1(this);
|
||||
// Return true if compatible.
|
||||
return nbtEditor != null;
|
||||
}
|
||||
|
||||
public String getElytraLore()
|
||||
{
|
||||
return this.elytraLore;
|
||||
}
|
||||
|
||||
public String getArmoredElytrName(ArmorTier tier)
|
||||
{
|
||||
String ret;
|
||||
switch(tier)
|
||||
{
|
||||
case LEATHER:
|
||||
ret = this.leatherName;
|
||||
break;
|
||||
case GOLD:
|
||||
ret = this.goldName;
|
||||
break;
|
||||
case CHAIN:
|
||||
ret = this.chainName;
|
||||
break;
|
||||
case IRON:
|
||||
ret = this.ironName;
|
||||
break;
|
||||
case DIAMOND:
|
||||
ret = this.diamondName;
|
||||
break;
|
||||
default:
|
||||
ret = "NONE";
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
public void setUpToDate(boolean upToDate)
|
||||
{
|
||||
this.upToDate = upToDate;
|
||||
}
|
||||
|
||||
public boolean getUninstallMode()
|
||||
{
|
||||
return uninstallMode;
|
||||
}
|
||||
}
|
@ -19,13 +19,11 @@ public class CommandHandler implements CommandExecutor
|
||||
{
|
||||
ArmoredElytra plugin;
|
||||
NBTEditor nbtEditor;
|
||||
boolean uninstallMode;
|
||||
|
||||
public CommandHandler(ArmoredElytra plugin, NBTEditor nbtEditor, boolean uninstallMode)
|
||||
public CommandHandler(ArmoredElytra plugin, NBTEditor nbtEditor)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
this.nbtEditor = nbtEditor;
|
||||
this.uninstallMode = uninstallMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -37,7 +35,7 @@ public class CommandHandler implements CommandExecutor
|
||||
{
|
||||
player = (Player) sender;
|
||||
|
||||
if (uninstallMode)
|
||||
if (plugin.getUninstallMode())
|
||||
{
|
||||
plugin.messagePlayer(player, "Plugin in uninstall mode! New Armored Elytras are not allowed!");
|
||||
return true;
|
||||
@ -122,14 +120,14 @@ public class CommandHandler implements CommandExecutor
|
||||
plugin.giveArmoredElytraToPlayer(receiver, newElytra);
|
||||
}
|
||||
else
|
||||
plugin.messagePlayer(player, "You do not have the required permission node to give " + ArmorTier.getArmorName(armorTier) + " armored elytras.");
|
||||
plugin.messagePlayer(player, "You do not have the required permission node to give " + plugin.getArmoredElytrName(armorTier) + " armored elytras.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (uninstallMode)
|
||||
if (plugin.getUninstallMode())
|
||||
{
|
||||
plugin.myLogger(Level.INFO, "Plugin in uninstall mode! New Armored Elytras are not allowed!");
|
||||
return true;
|
||||
|
@ -427,7 +427,12 @@ public class EventHandlers implements Listener
|
||||
ItemStack result = nbtEditor.addArmorNBTTags(anvilInventory.getItem(2), armortier, plugin.getConfigLoader().getBool("unbreakable"));
|
||||
// Give the result to the player and clear the anvil's inventory.
|
||||
if (e.isShiftClick())
|
||||
{
|
||||
// If the player's inventory is full, don't do anything.
|
||||
if (p.getInventory().firstEmpty() == -1)
|
||||
return;
|
||||
p.getInventory().addItem(result);
|
||||
}
|
||||
else
|
||||
p.setItemOnCursor(result);
|
||||
// Clean the anvil's inventory after transferring the items.
|
||||
|
@ -2,7 +2,6 @@ package nl.pim16aap2.armoredElytra.nms;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -18,15 +17,11 @@ import nl.pim16aap2.armoredElytra.util.ArmorTier;
|
||||
|
||||
public class NBTEditor_V1_10_R1 implements NBTEditor
|
||||
{
|
||||
private String elytraName;
|
||||
private String elytraLore;
|
||||
private ArmoredElytra plugin;
|
||||
|
||||
// Get the names and lores for every tier of armor.
|
||||
public NBTEditor_V1_10_R1(String elytraName, String elytraLore, ArmoredElytra plugin)
|
||||
public NBTEditor_V1_10_R1(ArmoredElytra plugin)
|
||||
{
|
||||
this.elytraName = elytraName;
|
||||
this.elytraLore = elytraLore;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@ -37,11 +32,10 @@ public class NBTEditor_V1_10_R1 implements NBTEditor
|
||||
ItemMeta itemmeta = item.getItemMeta();
|
||||
int armorProtection = ArmorTier.getArmor (armorTier);
|
||||
int armorToughness = ArmorTier.getToughness(armorTier);
|
||||
ChatColor color = ArmorTier.getColor (armorTier);
|
||||
|
||||
itemmeta.setDisplayName(color+plugin.fillInArmorTierInString(elytraName, armorTier));
|
||||
if (elytraLore != null)
|
||||
itemmeta.setLore(Arrays.asList(plugin.fillInArmorTierInString(elytraLore, armorTier)));
|
||||
itemmeta.setDisplayName(plugin.getArmoredElytrName(armorTier));
|
||||
if (plugin.getElytraLore() != null)
|
||||
itemmeta.setLore(Arrays.asList(plugin.fillInArmorTierInStringNoColor(plugin.getElytraLore(), armorTier)));
|
||||
item.setItemMeta(itemmeta);
|
||||
|
||||
net.minecraft.server.v1_10_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(item);
|
||||
|
@ -2,7 +2,6 @@ package nl.pim16aap2.armoredElytra.nms;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -18,15 +17,11 @@ import nl.pim16aap2.armoredElytra.util.ArmorTier;
|
||||
|
||||
public class NBTEditor_V1_11_R1 implements NBTEditor
|
||||
{
|
||||
private String elytraName;
|
||||
private String elytraLore;
|
||||
private ArmoredElytra plugin;
|
||||
|
||||
// Get the names and lores for every tier of armor.
|
||||
public NBTEditor_V1_11_R1(String elytraName, String elytraLore, ArmoredElytra plugin)
|
||||
public NBTEditor_V1_11_R1(ArmoredElytra plugin)
|
||||
{
|
||||
this.elytraName = elytraName;
|
||||
this.elytraLore = elytraLore;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@ -37,11 +32,10 @@ public class NBTEditor_V1_11_R1 implements NBTEditor
|
||||
ItemMeta itemmeta = item.getItemMeta();
|
||||
int armorProtection = ArmorTier.getArmor (armorTier);
|
||||
int armorToughness = ArmorTier.getToughness(armorTier);
|
||||
ChatColor color = ArmorTier.getColor (armorTier);
|
||||
|
||||
itemmeta.setDisplayName(color+plugin.fillInArmorTierInString(elytraName, armorTier));
|
||||
if (elytraLore != null)
|
||||
itemmeta.setLore(Arrays.asList(plugin.fillInArmorTierInString(elytraLore, armorTier)));
|
||||
itemmeta.setDisplayName(plugin.getArmoredElytrName(armorTier));
|
||||
if (plugin.getElytraLore() != null)
|
||||
itemmeta.setLore(Arrays.asList(plugin.fillInArmorTierInStringNoColor(plugin.getElytraLore(), armorTier)));
|
||||
item.setItemMeta(itemmeta);
|
||||
|
||||
net.minecraft.server.v1_11_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(item);
|
||||
|
@ -2,7 +2,6 @@ package nl.pim16aap2.armoredElytra.nms;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -18,15 +17,11 @@ import nl.pim16aap2.armoredElytra.util.ArmorTier;
|
||||
|
||||
public class NBTEditor_V1_12_R1 implements NBTEditor
|
||||
{
|
||||
private String elytraName;
|
||||
private String elytraLore;
|
||||
private ArmoredElytra plugin;
|
||||
|
||||
// Get the names and lores for every tier of armor.
|
||||
public NBTEditor_V1_12_R1(String elytraName, String elytraLore, ArmoredElytra plugin)
|
||||
public NBTEditor_V1_12_R1(ArmoredElytra plugin)
|
||||
{
|
||||
this.elytraName = elytraName;
|
||||
this.elytraLore = elytraLore;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@ -37,11 +32,10 @@ public class NBTEditor_V1_12_R1 implements NBTEditor
|
||||
ItemMeta itemmeta = item.getItemMeta();
|
||||
int armorProtection = ArmorTier.getArmor (armorTier);
|
||||
int armorToughness = ArmorTier.getToughness(armorTier);
|
||||
ChatColor color = ArmorTier.getColor (armorTier);
|
||||
|
||||
itemmeta.setDisplayName(color+plugin.fillInArmorTierInString(elytraName, armorTier));
|
||||
if (elytraLore != null)
|
||||
itemmeta.setLore(Arrays.asList(plugin.fillInArmorTierInString(elytraLore, armorTier)));
|
||||
itemmeta.setDisplayName(plugin.getArmoredElytrName(armorTier));
|
||||
if (plugin.getElytraLore() != null)
|
||||
itemmeta.setLore(Arrays.asList(plugin.fillInArmorTierInStringNoColor(plugin.getElytraLore(), armorTier)));
|
||||
item.setItemMeta(itemmeta);
|
||||
|
||||
net.minecraft.server.v1_12_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(item);
|
||||
|
@ -1,30 +1,25 @@
|
||||
package nl.pim16aap2.armoredElytra.util;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
|
||||
public enum ArmorTier
|
||||
{
|
||||
// Tier: tier armor-value, tier armor-toughness, tier name color , tier name , repair
|
||||
NONE (0 , 0 , ChatColor.WHITE , "Unarmored", null ),
|
||||
LEATHER (3 , 0 , ChatColor.DARK_GREEN, "Leather" , Material.LEATHER ),
|
||||
GOLD (5 , 0 , ChatColor.YELLOW , "Gold" , Material.GOLD_INGOT),
|
||||
CHAIN (5 , 0 , ChatColor.DARK_GRAY , "Chain" , Material.IRON_INGOT),
|
||||
IRON (6 , 0 , ChatColor.GRAY , "Iron" , Material.IRON_INGOT),
|
||||
DIAMOND (8 , 2 , ChatColor.AQUA , "Diamond" , Material.DIAMOND );
|
||||
// Tier: tier armor-value, tier armor-toughness, repair
|
||||
NONE (0 , 0 , null ),
|
||||
LEATHER (3 , 0 , Material.LEATHER ),
|
||||
GOLD (5 , 0 , Material.GOLD_INGOT),
|
||||
CHAIN (5 , 0 , Material.IRON_INGOT),
|
||||
IRON (6 , 0 , Material.IRON_INGOT),
|
||||
DIAMOND (8 , 2 , Material.DIAMOND );
|
||||
|
||||
private int armor;
|
||||
private int toughness;
|
||||
private ChatColor color;
|
||||
private String name;
|
||||
private Material repair;
|
||||
|
||||
private ArmorTier (int armor, int toughness, ChatColor color, String name, Material repair)
|
||||
private ArmorTier (int armor, int toughness, Material repair)
|
||||
{
|
||||
this.armor = armor;
|
||||
this.color = color;
|
||||
this.toughness = toughness;
|
||||
this.name = name;
|
||||
this.repair = repair;
|
||||
}
|
||||
|
||||
@ -34,12 +29,6 @@ public enum ArmorTier
|
||||
// return the armor toughness of a tier.
|
||||
public static int getToughness (ArmorTier tier) { return tier.toughness; }
|
||||
|
||||
// return the color of a tier.
|
||||
public static ChatColor getColor (ArmorTier tier) { return tier.color; }
|
||||
|
||||
// return the name of a tier.
|
||||
public static String getArmorName (ArmorTier tier) { return tier.name; }
|
||||
|
||||
// return the repair item of a tier
|
||||
public static Material getRepairItem (ArmorTier tier) { return tier.repair; }
|
||||
}
|
||||
|
@ -15,22 +15,26 @@ import nl.pim16aap2.armoredElytra.ArmoredElytra;
|
||||
|
||||
public class ConfigLoader
|
||||
{
|
||||
private boolean unbreakable;
|
||||
private boolean noFlightDurability;
|
||||
private int LEATHER_TO_FULL;
|
||||
private int GOLD_TO_FULL;
|
||||
private int IRON_TO_FULL;
|
||||
private int DIAMONDS_TO_FULL;
|
||||
private boolean cursesAllowed;
|
||||
private List<String> allowedEnchantments;
|
||||
private String usageDeniedMessage;
|
||||
private String elytraReceivedMessage;
|
||||
private boolean checkForUpdates;
|
||||
private boolean allowStats;
|
||||
private boolean enableDebug;
|
||||
private boolean uninstallMode;
|
||||
private String elytraName;
|
||||
private String elytraLore;
|
||||
private boolean unbreakable;
|
||||
private boolean noFlightDurability;
|
||||
private int LEATHER_TO_FULL;
|
||||
private int GOLD_TO_FULL;
|
||||
private int IRON_TO_FULL;
|
||||
private int DIAMONDS_TO_FULL;
|
||||
private String leatherName;
|
||||
private String goldName;
|
||||
private String chainName;
|
||||
private String ironName;
|
||||
private String diamondName;
|
||||
private String elytraLore;
|
||||
private boolean cursesAllowed;
|
||||
private List<String> allowedEnchantments;
|
||||
private String usageDeniedMessage;
|
||||
private String elytraReceivedMessage;
|
||||
private boolean checkForUpdates;
|
||||
private boolean allowStats;
|
||||
private boolean enableDebug;
|
||||
private boolean uninstallMode;
|
||||
|
||||
// All the comments for the various config options.
|
||||
private String[] unbreakableComment =
|
||||
@ -42,27 +46,29 @@ public class ConfigLoader
|
||||
private String[] repairComment =
|
||||
{"Amount of items it takes to fully repair an armored elytra",
|
||||
"Repair cost for every tier of armored elytra in number of items to repair 100%."};
|
||||
private String[] tierNameComment =
|
||||
{"Name for every armored elytra tier."};
|
||||
private String[] cursesComment =
|
||||
{"Will curses (vanishing, binding) be transferred when creating armored elytras?"};
|
||||
private String[] enchantmentsComment =
|
||||
{"List of enchantments that are allowed to be put on an armored elytra.",
|
||||
"If you do not want to allow any enchantments, remove them all and add \"NONE\"",
|
||||
"You can find supported enchantments here:",
|
||||
"https://hub.spigotmc.org/javadocs/spigot/org/bukkit/enchantments/Enchantment.html"};
|
||||
"https://hub.spigotmc.org/javadocs/spigot/org/bukkit/enchantments/Enchantment.html",
|
||||
"Note that only 1 protection enchantment (PROTECTION_FIRE, PROTECTION_ENVIRONMENTAL etc) can be active on an elytra."};
|
||||
private String[] usageDeniedComment =
|
||||
{"Message players receive when they lack the required permissions to wear a certain armor tier. \"NONE\" = no message. ",
|
||||
"%ARMOR_TIER% is replaced by the name of the armor tier."};
|
||||
private String[] elytraReceivedComment =
|
||||
{"Message players receive when they are given an armored elytra using commands. \"NONE\" = no message. ",
|
||||
"%ARMOR_TIER% is replaced by the name of the armor tier."};
|
||||
private String[] elytraNameComment =
|
||||
{"The name of armored elytras. %ARMOR_TIER% is replaced by the name of the armor tier."};
|
||||
private String[] elytraLoreComment =
|
||||
{"The lore of armored elytras. \"NONE\" = no lore. %ARMOR_TIER% is replaced by the name of the armor tier."};
|
||||
private String[] updateComment =
|
||||
{"Allow this plugin to check for updates on startup. It will not download new versions!"};
|
||||
private String[] bStatsComment =
|
||||
{"Allow this plugin to send (anonymised) stats using bStats."};
|
||||
{"Allow this plugin to send (anonymised) stats using bStats. Please consider keeping it enabled.",
|
||||
"It has a negligible impact on performance and more users on stats keeps me more motivated to support this plugin!"};
|
||||
private String[] debugComment =
|
||||
{"Print debug messages to console. You will most likely never need this."};
|
||||
private String[] uninstallComment =
|
||||
@ -89,42 +95,52 @@ public class ConfigLoader
|
||||
|
||||
// Read all the options from the config, then put them in a configOption with their name, value and comment.
|
||||
// THen put all configOptions into an ArrayList.
|
||||
unbreakable = config.getBoolean("unbreakable", false);
|
||||
configOptionsList.add(new ConfigOption ("unbreakable", unbreakable, unbreakableComment));
|
||||
unbreakable = config.getBoolean("unbreakable" , false);
|
||||
configOptionsList.add(new ConfigOption ("unbreakable" , unbreakable , unbreakableComment ));
|
||||
noFlightDurability = config.getBoolean("noFlightDurability", false);
|
||||
configOptionsList.add(new ConfigOption ("noFlightDurability", noFlightDurability, flyDurabilityComment));
|
||||
|
||||
LEATHER_TO_FULL = config.getInt ("leatherRepair", 6);
|
||||
configOptionsList.add(new ConfigOption("leatherRepair", LEATHER_TO_FULL, repairComment));
|
||||
GOLD_TO_FULL = config.getInt ("goldRepair", 5);
|
||||
configOptionsList.add(new ConfigOption("goldRepair", GOLD_TO_FULL));
|
||||
IRON_TO_FULL = config.getInt ("ironRepair", 4);
|
||||
configOptionsList.add(new ConfigOption("ironRepair", IRON_TO_FULL));
|
||||
DIAMONDS_TO_FULL = config.getInt ("diamondsRepair", 3);
|
||||
configOptionsList.add(new ConfigOption("diamondsRepair", DIAMONDS_TO_FULL));
|
||||
LEATHER_TO_FULL = config.getInt ("leatherRepair" , 6);
|
||||
configOptionsList.add(new ConfigOption ("leatherRepair" , LEATHER_TO_FULL, repairComment));
|
||||
GOLD_TO_FULL = config.getInt ("goldRepair" , 5);
|
||||
configOptionsList.add(new ConfigOption ("goldRepair" , GOLD_TO_FULL));
|
||||
IRON_TO_FULL = config.getInt ("ironRepair" , 4);
|
||||
configOptionsList.add(new ConfigOption ("ironRepair" , IRON_TO_FULL));
|
||||
DIAMONDS_TO_FULL = config.getInt ("diamondsRepair", 3);
|
||||
configOptionsList.add(new ConfigOption ("diamondsRepair", DIAMONDS_TO_FULL));
|
||||
|
||||
cursesAllowed = config.getBoolean ("allowCurses", true);
|
||||
leatherName = config.getString ("leatherName", "&2Leather Armored Elytra" );
|
||||
configOptionsList.add(new ConfigOption ("leatherName", leatherName, tierNameComment));
|
||||
goldName = config.getString ("goldName" , "&EGolden Armored Elytra" );
|
||||
configOptionsList.add(new ConfigOption ("goldName" , goldName ));
|
||||
chainName = config.getString ("chainName" , "&8Chain Armored Elytra" );
|
||||
configOptionsList.add(new ConfigOption ("chainName" , chainName ));
|
||||
ironName = config.getString ("ironName" , "&7Iron Armored Elytra" );
|
||||
configOptionsList.add(new ConfigOption ("ironName" , ironName ));
|
||||
diamondName = config.getString ("diamondName", "&BDiamond Armored Elytra" );
|
||||
configOptionsList.add(new ConfigOption ("diamondName", diamondName ));
|
||||
|
||||
elytraLore = config.getString ("elytraLore");
|
||||
configOptionsList.add(new ConfigOption ("elytraLore", elytraLore, elytraLoreComment));
|
||||
|
||||
usageDeniedMessage = config.getString ("usageDeniedMessage" );
|
||||
configOptionsList.add(new ConfigOption ("usageDeniedMessage" , usageDeniedMessage , usageDeniedComment ));
|
||||
elytraReceivedMessage = config.getString ("elytraReceivedMessage" );
|
||||
configOptionsList.add(new ConfigOption ("elytraReceivedMessage", elytraReceivedMessage, elytraReceivedComment));
|
||||
|
||||
cursesAllowed = config.getBoolean ("allowCurses", true );
|
||||
configOptionsList.add(new ConfigOption ("allowCurses", cursesAllowed, cursesComment));
|
||||
allowedEnchantments = config.getStringList("allowedEnchantments");
|
||||
configOptionsList.add(new ConfigOption ("allowedEnchantments", allowedEnchantments, enchantmentsComment));
|
||||
configOptionsList.add(new ConfigOption ("allowedEnchantments", allowedEnchantments, enchantmentsComment ));
|
||||
|
||||
usageDeniedMessage = config.getString("usageDeniedMessage");
|
||||
configOptionsList.add(new ConfigOption ("usageDeniedMessage", usageDeniedMessage, usageDeniedComment));
|
||||
elytraReceivedMessage = config.getString("elytraReceivedMessage");
|
||||
configOptionsList.add(new ConfigOption ("elytraReceivedMessage", elytraReceivedMessage, elytraReceivedComment));
|
||||
elytraName = config.getString("elytraName");
|
||||
configOptionsList.add(new ConfigOption ("elytraName", elytraName, elytraNameComment));
|
||||
elytraLore = config.getString("elytraLore");
|
||||
configOptionsList.add(new ConfigOption ("elytraLore", elytraLore, elytraLoreComment));
|
||||
|
||||
checkForUpdates = config.getBoolean("checkForUpdates", true);
|
||||
checkForUpdates = config.getBoolean("checkForUpdates", true );
|
||||
configOptionsList.add(new ConfigOption ("checkForUpdates", checkForUpdates, updateComment));
|
||||
allowStats = config.getBoolean("allowStats", true);
|
||||
configOptionsList.add(new ConfigOption ("allowStats", allowStats, bStatsComment));
|
||||
enableDebug = config.getBoolean("enableDebug", false);
|
||||
configOptionsList.add(new ConfigOption ("enableDebug", enableDebug, debugComment));
|
||||
uninstallMode = config.getBoolean("uninstallMode", false);
|
||||
configOptionsList.add(new ConfigOption ("uninstallMode", uninstallMode, uninstallComment));
|
||||
allowStats = config.getBoolean("allowStats" , true );
|
||||
configOptionsList.add(new ConfigOption ("allowStats" , allowStats, bStatsComment));
|
||||
enableDebug = config.getBoolean("enableDebug" , false);
|
||||
configOptionsList.add(new ConfigOption ("enableDebug" , enableDebug, debugComment));
|
||||
uninstallMode = config.getBoolean("uninstallMode" , false);
|
||||
configOptionsList.add(new ConfigOption ("uninstallMode" , uninstallMode, uninstallComment));
|
||||
|
||||
writeConfig();
|
||||
}
|
||||
@ -155,7 +171,8 @@ public class ConfigLoader
|
||||
|
||||
pw.flush();
|
||||
pw.close();
|
||||
} catch (IOException e)
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Could not save config.yml! Please contact pim16aap2 and show him the following code:");
|
||||
e.printStackTrace();
|
||||
|
@ -14,7 +14,8 @@ import org.json.simple.JSONValue;
|
||||
import nl.pim16aap2.armoredElytra.ArmoredElytra;
|
||||
|
||||
|
||||
public class Update {
|
||||
public class Update
|
||||
{
|
||||
|
||||
// The project's unique ID
|
||||
private final int projectID;
|
||||
@ -27,7 +28,7 @@ public class Update {
|
||||
|
||||
// Static information for querying the API
|
||||
private static final String API_QUERY = "/servermods/files?projectIds=";
|
||||
private static final String API_HOST = "https://api.curseforge.com";
|
||||
private static final String API_HOST = "https://api.curseforge.com";
|
||||
|
||||
private String versionName;
|
||||
ArmoredElytra plugin;
|
||||
@ -37,7 +38,8 @@ public class Update {
|
||||
*
|
||||
* @param projectID The BukkitDev Project ID, found in the "Facts" panel on the right-side of your project page.
|
||||
*/
|
||||
public Update(int projectID, ArmoredElytra plugin) {
|
||||
public Update(int projectID, ArmoredElytra plugin)
|
||||
{
|
||||
this(projectID, null, plugin);
|
||||
}
|
||||
|
||||
@ -47,7 +49,8 @@ public class Update {
|
||||
* @param projectID The BukkitDev Project ID, found in the "Facts" panel on the right-side of your project page.
|
||||
* @param apiKey Your ServerMods API key, found at https://dev.bukkit.org/home/servermods-apikey/
|
||||
*/
|
||||
public Update(int projectID, String apiKey, ArmoredElytra plugin) {
|
||||
public Update(int projectID, String apiKey, ArmoredElytra plugin)
|
||||
{
|
||||
this.projectID = projectID;
|
||||
this.apiKey = apiKey;
|
||||
this.plugin = plugin;
|
||||
@ -57,16 +60,17 @@ public class Update {
|
||||
|
||||
|
||||
|
||||
public int versionCompare(String str1, String str2) {
|
||||
public int versionCompare(String str1, String str2)
|
||||
{
|
||||
String[] vals1 = str1.split("\\.");
|
||||
String[] vals2 = str2.split("\\.");
|
||||
int i = 0;
|
||||
// set index to first non-equal ordinal or length of shortest version string
|
||||
while (i < vals1.length && i < vals2.length && vals1[i].equals(vals2[i])) {
|
||||
i++;
|
||||
}
|
||||
while (i < vals1.length && i < vals2.length && vals1[i].equals(vals2[i]))
|
||||
i++;
|
||||
// compare first non-equal ordinal number
|
||||
if (i < vals1.length && i < vals2.length) {
|
||||
if (i < vals1.length && i < vals2.length)
|
||||
{
|
||||
int diff = Integer.valueOf(vals1[i]).compareTo(Integer.valueOf(vals2[i]));
|
||||
return Integer.signum(diff);
|
||||
}
|
||||
@ -78,6 +82,8 @@ public class Update {
|
||||
// Get the latest version of the plugin.
|
||||
public String getLatestVersion()
|
||||
{
|
||||
if (versionName == null)
|
||||
return null;
|
||||
return versionName.replaceAll("Armored Elytra ", "");
|
||||
}
|
||||
|
||||
@ -85,27 +91,31 @@ public class Update {
|
||||
/**
|
||||
* Query the API to find the latest approved file's details.
|
||||
*/
|
||||
public void query() {
|
||||
public void query()
|
||||
{
|
||||
URL url = null;
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
// Create the URL to query using the project's ID
|
||||
url = new URL(API_HOST + API_QUERY + projectID);
|
||||
} catch (MalformedURLException e) {
|
||||
}
|
||||
catch (MalformedURLException e)
|
||||
{
|
||||
// There was an error creating the URL
|
||||
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
// Open a connection and query the project
|
||||
URLConnection conn = url.openConnection();
|
||||
|
||||
if (apiKey != null) {
|
||||
if (apiKey != null)
|
||||
// Add the API key to the request if present
|
||||
conn.addRequestProperty("X-API-Key", apiKey);
|
||||
}
|
||||
|
||||
// Add the user-agent to identify the program
|
||||
conn.addRequestProperty("User-Agent", "ServerModsAPI-Example (by Gravity)");
|
||||
@ -118,16 +128,17 @@ public class Update {
|
||||
// Parse the array of files from the query's response
|
||||
JSONArray array = (JSONArray) JSONValue.parse(response);
|
||||
|
||||
if (array.size() > 0) {
|
||||
if (array.size() > 0)
|
||||
{
|
||||
// Get the newest file's details
|
||||
JSONObject latest = (JSONObject) array.get(array.size() - 1);
|
||||
|
||||
// Get the version's title
|
||||
this.versionName = (String) latest.get(API_NAME_VALUE);
|
||||
} else {
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
// There was an error reading the query
|
||||
|
||||
e.printStackTrace();
|
||||
|
@ -9,13 +9,6 @@ goldRepair: 5
|
||||
ironRepair: 4
|
||||
diamondsRepair: 3
|
||||
|
||||
# Name colors for every tier.
|
||||
leatherColor:
|
||||
goldColor:
|
||||
chainColor:
|
||||
ironColor:
|
||||
diamondColor:
|
||||
|
||||
# Name for every tier:
|
||||
leather:
|
||||
gold:
|
||||
|
@ -1,6 +1,6 @@
|
||||
name: ArmoredElytra
|
||||
main: nl.pim16aap2.armoredElytra.ArmoredElytra
|
||||
version: 2.2.1
|
||||
version: 2.3
|
||||
author: Pim
|
||||
commands:
|
||||
ArmoredElytra:
|
||||
|
Loading…
x
Reference in New Issue
Block a user