Fix formating
- Removed all remaining tabs (not sure how to got through the last cleanup). - Updated some comments.
This commit is contained in:
parent
da224bfc1a
commit
4b5de17bb6
@ -10,21 +10,21 @@ import nl.pim16aap2.armoredElytra.util.ArmorTier;
|
|||||||
|
|
||||||
public class FlyDurabilityHandler implements Listener
|
public class FlyDurabilityHandler implements Listener
|
||||||
{
|
{
|
||||||
private final NBTEditor nbtEditor;
|
private final NBTEditor nbtEditor;
|
||||||
|
|
||||||
public FlyDurabilityHandler(NBTEditor nbtEditor)
|
public FlyDurabilityHandler(NBTEditor nbtEditor)
|
||||||
{
|
{
|
||||||
this.nbtEditor = nbtEditor;
|
this.nbtEditor = nbtEditor;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do not decrease elytra durability while flying. This also cancels durability decrease when
|
// Do not decrease elytra durability while flying. This also cancels durability decrease when
|
||||||
// it should (i.e. getting hit) while flying, but I don't really care.
|
// it should (i.e. getting hit) while flying, but I don't really care.
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onItemDamage(PlayerItemDamageEvent e)
|
public void onItemDamage(PlayerItemDamageEvent e)
|
||||||
{
|
{
|
||||||
if (e.getItem().getType() == Material.ELYTRA)
|
if (e.getItem().getType() == Material.ELYTRA)
|
||||||
if (nbtEditor.getArmorTier(e.getItem()) != ArmorTier.NONE)
|
if (nbtEditor.getArmorTier(e.getItem()) != ArmorTier.NONE)
|
||||||
if (e.getPlayer().isFlying())
|
if (e.getPlayer().isFlying())
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ public class GetArmorValueOld implements GetArmorValue
|
|||||||
int pos = nbtString.indexOf(",Slot:\"chest\",AttributeName:\"generic.armor\"");
|
int pos = nbtString.indexOf(",Slot:\"chest\",AttributeName:\"generic.armor\"");
|
||||||
if (pos > 0)
|
if (pos > 0)
|
||||||
{
|
{
|
||||||
// If so, get the value of the generic.armor attribute.
|
|
||||||
pos--;
|
pos--;
|
||||||
String stringAtPos = nbtString.substring(pos, pos + 1);
|
String stringAtPos = nbtString.substring(pos, pos + 1);
|
||||||
return Integer.parseInt(stringAtPos);
|
return Integer.parseInt(stringAtPos);
|
||||||
|
@ -74,8 +74,7 @@ public class NBTEditor
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Old versions use the old format. It is assumed here that all versions from 1.13.2 on will use the
|
// Old versions use the old format. It is assumed here that all versions from 1.13.2 on will use the new format.
|
||||||
// new format. Might want to put this in a nice interface instead of an ugly boolean.
|
|
||||||
// Spigot's 1.13.1 uses the old format, but 1.13.2 uses the new format. They share the same version number though.
|
// Spigot's 1.13.1 uses the old format, but 1.13.2 uses the new format. They share the same version number though.
|
||||||
if (version.equals("v1_9_R1" ) || version.equals("v1_9_R2" ) || version.equals("v1_10_R1") ||
|
if (version.equals("v1_9_R1" ) || version.equals("v1_9_R2" ) || version.equals("v1_10_R1") ||
|
||||||
version.equals("v1_11_R1") || version.equals("v1_12_R1") || version.equals("v1_13_R1") ||
|
version.equals("v1_11_R1") || version.equals("v1_12_R1") || version.equals("v1_13_R1") ||
|
||||||
@ -113,8 +112,8 @@ public class NBTEditor
|
|||||||
NBTTagInt = getNMSClass("NBTTagInt");
|
NBTTagInt = getNMSClass("NBTTagInt");
|
||||||
NBTTagIntCtor = NBTTagInt.getConstructor(int.class);
|
NBTTagIntCtor = NBTTagInt.getConstructor(int.class);
|
||||||
|
|
||||||
NBTTagCompound = getNMSClass("NBTTagCompound");
|
NBTTagCompound = getNMSClass("NBTTagCompound");
|
||||||
setTag = NBTTagCompound.getMethod("set", String.class, NBTBase);
|
setTag = NBTTagCompound.getMethod("set", String.class, NBTBase);
|
||||||
|
|
||||||
NBTTagList = getNMSClass("NBTTagList");
|
NBTTagList = getNMSClass("NBTTagList");
|
||||||
addCompound = NBTTagList.getMethod("add", NBTBase);
|
addCompound = NBTTagList.getMethod("add", NBTBase);
|
||||||
@ -219,7 +218,6 @@ public class NBTEditor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Class<?> getNMSClass(String name) throws ClassNotFoundException
|
private Class<?> getNMSClass(String name) throws ClassNotFoundException
|
||||||
{
|
{
|
||||||
return Class.forName(NMSbase + name);
|
return Class.forName(NMSbase + name);
|
||||||
|
@ -2,5 +2,5 @@ package nl.pim16aap2.armoredElytra.util;
|
|||||||
|
|
||||||
public enum Action
|
public enum Action
|
||||||
{
|
{
|
||||||
NONE, REPAIR, ENCHANT, COMBINE, CREATE, BLOCK
|
NONE, REPAIR, ENCHANT, COMBINE, CREATE, BLOCK
|
||||||
}
|
}
|
||||||
|
@ -4,31 +4,31 @@ import org.bukkit.Material;
|
|||||||
|
|
||||||
public enum ArmorTier
|
public enum ArmorTier
|
||||||
{
|
{
|
||||||
// Tier: tier armor-value, tier armor-toughness, repair
|
// Tier: armor-value, armor-toughness, repair
|
||||||
NONE (0 , 0 , null ),
|
NONE (0 , 0 , null ),
|
||||||
LEATHER (3 , 0 , Material.LEATHER ),
|
LEATHER (3 , 0 , Material.LEATHER ),
|
||||||
GOLD (5 , 0 , Material.GOLD_INGOT),
|
GOLD (5 , 0 , Material.GOLD_INGOT),
|
||||||
CHAIN (5 , 0 , Material.IRON_INGOT),
|
CHAIN (5 , 0 , Material.IRON_INGOT),
|
||||||
IRON (6 , 0 , Material.IRON_INGOT),
|
IRON (6 , 0 , Material.IRON_INGOT),
|
||||||
DIAMOND (8 , 2 , Material.DIAMOND );
|
DIAMOND (8 , 2 , Material.DIAMOND );
|
||||||
|
|
||||||
private int armor;
|
|
||||||
private int toughness;
|
|
||||||
private Material repair;
|
|
||||||
|
|
||||||
private ArmorTier (int armor, int toughness, Material repair)
|
private int armor;
|
||||||
|
private int toughness;
|
||||||
|
private Material repair;
|
||||||
|
|
||||||
|
private ArmorTier (int armor, int toughness, Material repair)
|
||||||
{
|
{
|
||||||
this.armor = armor;
|
this.armor = armor;
|
||||||
this.toughness = toughness;
|
this.toughness = toughness;
|
||||||
this.repair = repair;
|
this.repair = repair;
|
||||||
}
|
}
|
||||||
|
|
||||||
// return the armor value of a tier.
|
// return the armor value of a tier.
|
||||||
public static int getArmor (ArmorTier tier) { return tier.armor; }
|
public static int getArmor (ArmorTier tier) { return tier.armor; }
|
||||||
|
|
||||||
// return the armor toughness of a tier.
|
// return the armor toughness of a tier.
|
||||||
public static int getToughness (ArmorTier tier) { return tier.toughness; }
|
public static int getToughness (ArmorTier tier) { return tier.toughness; }
|
||||||
|
|
||||||
// return the repair item of a tier
|
// return the repair item of a tier
|
||||||
public static Material getRepairItem (ArmorTier tier) { return tier.repair; }
|
public static Material getRepairItem (ArmorTier tier) { return tier.repair; }
|
||||||
}
|
}
|
||||||
|
@ -13,67 +13,67 @@ import nl.pim16aap2.armoredElytra.ArmoredElytra;
|
|||||||
|
|
||||||
public class Messages
|
public class Messages
|
||||||
{
|
{
|
||||||
private Map<String, String> messageMap = new HashMap<String, String>();
|
private Map<String, String> messageMap = new HashMap<>();
|
||||||
private ArmoredElytra plugin;
|
private ArmoredElytra plugin;
|
||||||
private String locale;
|
private String locale;
|
||||||
private File textFile;
|
private File textFile;
|
||||||
|
|
||||||
public Messages(ArmoredElytra plugin)
|
|
||||||
{
|
|
||||||
this.plugin = plugin;
|
|
||||||
this.locale = plugin.getLocale();
|
|
||||||
textFile = new File(plugin.getDataFolder(), locale + ".txt");
|
|
||||||
readFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read locale file.
|
|
||||||
private void readFile()
|
|
||||||
{
|
|
||||||
// Load the default en_US from the resources.
|
|
||||||
plugin.saveResource("en_US.txt", true);
|
|
||||||
|
|
||||||
try (BufferedReader br = new BufferedReader(new FileReader(this.textFile)))
|
public Messages(ArmoredElytra plugin)
|
||||||
{
|
{
|
||||||
String sCurrentLine;
|
this.plugin = plugin;
|
||||||
|
locale = plugin.getLocale();
|
||||||
|
textFile = new File(plugin.getDataFolder(), locale + ".txt");
|
||||||
|
readFile();
|
||||||
|
}
|
||||||
|
|
||||||
while ((sCurrentLine = br.readLine()) != null)
|
// Read locale file.
|
||||||
{
|
private void readFile()
|
||||||
String key, value;
|
{
|
||||||
String[] parts = sCurrentLine.split("=", 2);
|
// Load the default en_US from the resources.
|
||||||
key = parts[0];
|
plugin.saveResource("en_US.txt", true);
|
||||||
value = parts[1].replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
|
||||||
String[] newLineSplitter = value.split("\\\\n"); // Wut? Can I haz more backslash?
|
try (BufferedReader br = new BufferedReader(new FileReader(textFile)))
|
||||||
|
{
|
||||||
String values = newLineSplitter[0];
|
String sCurrentLine;
|
||||||
|
|
||||||
for (int idx = 1; idx < newLineSplitter.length; ++idx)
|
while ((sCurrentLine = br.readLine()) != null)
|
||||||
values += "\n" + newLineSplitter[idx];
|
{
|
||||||
|
String key, value;
|
||||||
this.messageMap.put(key, values);
|
String[] parts = sCurrentLine.split("=", 2);
|
||||||
}
|
key = parts[0];
|
||||||
br.close();
|
value = parts[1].replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
||||||
}
|
String[] newLineSplitter = value.split("\\\\n"); // Wut? Can I haz more backslash?
|
||||||
catch (FileNotFoundException e)
|
|
||||||
{
|
String values = newLineSplitter[0];
|
||||||
plugin.myLogger(Level.SEVERE, "Locale file " + this.locale + ".txt does not exist!");
|
|
||||||
}
|
for (int idx = 1; idx < newLineSplitter.length; ++idx)
|
||||||
catch (IOException e)
|
values += "\n" + newLineSplitter[idx];
|
||||||
{
|
|
||||||
plugin.myLogger(Level.SEVERE, "Could not read locale file! (" + this.locale + ".txt)");
|
messageMap.put(key, values);
|
||||||
e.printStackTrace();
|
}
|
||||||
}
|
br.close();
|
||||||
}
|
}
|
||||||
|
catch (FileNotFoundException e)
|
||||||
// Get a string from a key. Returns "null" if null.
|
{
|
||||||
public String getString(String key)
|
plugin.myLogger(Level.SEVERE, "Locale file " + locale + ".txt does not exist!");
|
||||||
{
|
}
|
||||||
String value = null;
|
catch (IOException e)
|
||||||
value = this.messageMap.get(key);
|
{
|
||||||
if (value == null)
|
plugin.myLogger(Level.SEVERE, "Could not read locale file! (" + locale + ".txt)");
|
||||||
{
|
e.printStackTrace();
|
||||||
value = "ArmoredElytra: Translation not found! Contact server admin!";
|
}
|
||||||
plugin.myLogger(Level.WARNING, "Failed to get translation for key " + key);
|
}
|
||||||
}
|
|
||||||
return value;
|
// Get a string from a key. Returns "null" if null.
|
||||||
}
|
public String getString(String key)
|
||||||
|
{
|
||||||
|
String value = null;
|
||||||
|
value = messageMap.get(key);
|
||||||
|
if (value == null)
|
||||||
|
{
|
||||||
|
value = "ArmoredElytra: Translation not found! Contact server admin!";
|
||||||
|
plugin.myLogger(Level.WARNING, "Failed to get translation for key " + key);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ public class Update
|
|||||||
JSONObject latest = (JSONObject) array.get(array.size() - 1);
|
JSONObject latest = (JSONObject) array.get(array.size() - 1);
|
||||||
|
|
||||||
// Get the version's title
|
// Get the version's title
|
||||||
this.versionName = (String) latest.get(API_NAME_VALUE);
|
versionName = (String) latest.get(API_NAME_VALUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
@ -141,7 +141,7 @@ public class Update
|
|||||||
// There was an error reading the query.
|
// There was an error reading the query.
|
||||||
// Does not print stacktrace, so people won't see any errors from this plugin
|
// Does not print stacktrace, so people won't see any errors from this plugin
|
||||||
// when Bukkit Dev's servers are down,
|
// when Bukkit Dev's servers are down,
|
||||||
// So people won't think the plugin is broken, while the actualy problem is
|
// So people won't think the plugin is broken, while the actual problem is
|
||||||
// much, much smaller. latestVersion will be null, though, which will prompt a
|
// much, much smaller. latestVersion will be null, though, which will prompt a
|
||||||
// warning in the log instead.
|
// warning in the log instead.
|
||||||
|
|
||||||
|
@ -8,8 +8,8 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public class Util
|
public class Util
|
||||||
{
|
{
|
||||||
// Check if an item is broken or not.
|
// Check if an item is broken or not.
|
||||||
public static boolean isBroken(ItemStack item)
|
public static boolean isBroken(ItemStack item)
|
||||||
{
|
{
|
||||||
return item.getDurability() >= item.getType().getMaxDurability();
|
return item.getDurability() >= item.getType().getMaxDurability();
|
||||||
@ -19,7 +19,7 @@ public class Util
|
|||||||
public static ArmorTier armorToTier(Material item)
|
public static ArmorTier armorToTier(Material item)
|
||||||
{
|
{
|
||||||
ArmorTier ret = ArmorTier.NONE;
|
ArmorTier ret = ArmorTier.NONE;
|
||||||
|
|
||||||
switch (item)
|
switch (item)
|
||||||
{
|
{
|
||||||
case LEATHER_CHESTPLATE:
|
case LEATHER_CHESTPLATE:
|
||||||
@ -42,12 +42,12 @@ public class Util
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if mat is a chest plate.
|
// Check if mat is a chest plate.
|
||||||
public static boolean isChestPlate(Material mat)
|
public static boolean isChestPlate(Material mat)
|
||||||
{
|
{
|
||||||
if (mat == Material.LEATHER_CHESTPLATE || mat == Material.GOLD_CHESTPLATE ||
|
if (mat == Material.LEATHER_CHESTPLATE || mat == Material.GOLD_CHESTPLATE ||
|
||||||
mat == Material.CHAINMAIL_CHESTPLATE || mat == Material.IRON_CHESTPLATE ||
|
mat == Material.CHAINMAIL_CHESTPLATE || mat == Material.IRON_CHESTPLATE ||
|
||||||
mat == Material.DIAMOND_CHESTPLATE)
|
mat == Material.DIAMOND_CHESTPLATE)
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
@ -69,22 +69,22 @@ public class Util
|
|||||||
ret += 16;
|
ret += 16;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean playerHasCraftPerm(Player player, ArmorTier armorTier)
|
public static boolean playerHasCraftPerm(Player player, ArmorTier armorTier)
|
||||||
{
|
{
|
||||||
return ((armorTier == ArmorTier.LEATHER && player.hasPermission("armoredelytra.craft.leather")) ||
|
return ((armorTier == ArmorTier.LEATHER && player.hasPermission("armoredelytra.craft.leather")) ||
|
||||||
(armorTier == ArmorTier.GOLD && player.hasPermission("armoredelytra.craft.gold" )) ||
|
(armorTier == ArmorTier.GOLD && player.hasPermission("armoredelytra.craft.gold" )) ||
|
||||||
(armorTier == ArmorTier.CHAIN && player.hasPermission("armoredelytra.craft.chain" )) ||
|
(armorTier == ArmorTier.CHAIN && player.hasPermission("armoredelytra.craft.chain" )) ||
|
||||||
(armorTier == ArmorTier.IRON && player.hasPermission("armoredelytra.craft.iron" )) ||
|
(armorTier == ArmorTier.IRON && player.hasPermission("armoredelytra.craft.iron" )) ||
|
||||||
(armorTier == ArmorTier.DIAMOND && player.hasPermission("armoredelytra.craft.diamond")));
|
(armorTier == ArmorTier.DIAMOND && player.hasPermission("armoredelytra.craft.diamond")));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean playerHasWearPerm(Player player, ArmorTier armorTier)
|
public static boolean playerHasWearPerm(Player player, ArmorTier armorTier)
|
||||||
{
|
{
|
||||||
return ((armorTier == ArmorTier.LEATHER && player.hasPermission("armoredelytra.wear.leather" )) ||
|
return ((armorTier == ArmorTier.LEATHER && player.hasPermission("armoredelytra.wear.leather" )) ||
|
||||||
(armorTier == ArmorTier.GOLD && player.hasPermission("armoredelytra.wear.gold" )) ||
|
(armorTier == ArmorTier.GOLD && player.hasPermission("armoredelytra.wear.gold" )) ||
|
||||||
(armorTier == ArmorTier.CHAIN && player.hasPermission("armoredelytra.wear.chain" )) ||
|
(armorTier == ArmorTier.CHAIN && player.hasPermission("armoredelytra.wear.chain" )) ||
|
||||||
(armorTier == ArmorTier.IRON && player.hasPermission("armoredelytra.wear.iron" )) ||
|
(armorTier == ArmorTier.IRON && player.hasPermission("armoredelytra.wear.iron" )) ||
|
||||||
(armorTier == ArmorTier.DIAMOND && player.hasPermission("armoredelytra.wear.diamond" )));
|
(armorTier == ArmorTier.DIAMOND && player.hasPermission("armoredelytra.wear.diamond" )));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user