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
|
||||
{
|
||||
private final NBTEditor nbtEditor;
|
||||
private final NBTEditor nbtEditor;
|
||||
|
||||
public FlyDurabilityHandler(NBTEditor nbtEditor)
|
||||
{
|
||||
this.nbtEditor = nbtEditor;
|
||||
}
|
||||
public FlyDurabilityHandler(NBTEditor nbtEditor)
|
||||
{
|
||||
this.nbtEditor = nbtEditor;
|
||||
}
|
||||
|
||||
// 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.
|
||||
@EventHandler
|
||||
public void onItemDamage(PlayerItemDamageEvent e)
|
||||
{
|
||||
if (e.getItem().getType() == Material.ELYTRA)
|
||||
if (nbtEditor.getArmorTier(e.getItem()) != ArmorTier.NONE)
|
||||
if (e.getPlayer().isFlying())
|
||||
e.setCancelled(true);
|
||||
}
|
||||
// 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.
|
||||
@EventHandler
|
||||
public void onItemDamage(PlayerItemDamageEvent e)
|
||||
{
|
||||
if (e.getItem().getType() == Material.ELYTRA)
|
||||
if (nbtEditor.getArmorTier(e.getItem()) != ArmorTier.NONE)
|
||||
if (e.getPlayer().isFlying())
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ public class GetArmorValueOld implements GetArmorValue
|
||||
int pos = nbtString.indexOf(",Slot:\"chest\",AttributeName:\"generic.armor\"");
|
||||
if (pos > 0)
|
||||
{
|
||||
// If so, get the value of the generic.armor attribute.
|
||||
pos--;
|
||||
String stringAtPos = nbtString.substring(pos, pos + 1);
|
||||
return Integer.parseInt(stringAtPos);
|
||||
|
@ -74,8 +74,7 @@ public class NBTEditor
|
||||
return;
|
||||
}
|
||||
|
||||
// Old versions use the old format. It is assumed here that all versions from 1.13.2 on will use the
|
||||
// new format. Might want to put this in a nice interface instead of an ugly boolean.
|
||||
// Old versions use the old format. It is assumed here that all versions from 1.13.2 on will use the new format.
|
||||
// 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") ||
|
||||
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");
|
||||
NBTTagIntCtor = NBTTagInt.getConstructor(int.class);
|
||||
|
||||
NBTTagCompound = getNMSClass("NBTTagCompound");
|
||||
setTag = NBTTagCompound.getMethod("set", String.class, NBTBase);
|
||||
NBTTagCompound = getNMSClass("NBTTagCompound");
|
||||
setTag = NBTTagCompound.getMethod("set", String.class, NBTBase);
|
||||
|
||||
NBTTagList = getNMSClass("NBTTagList");
|
||||
addCompound = NBTTagList.getMethod("add", NBTBase);
|
||||
@ -219,7 +218,6 @@ public class NBTEditor
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Class<?> getNMSClass(String name) throws ClassNotFoundException
|
||||
{
|
||||
return Class.forName(NMSbase + name);
|
||||
|
@ -2,5 +2,5 @@ package nl.pim16aap2.armoredElytra.util;
|
||||
|
||||
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
|
||||
{
|
||||
// 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 Material repair;
|
||||
// Tier: armor-value, 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 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.toughness = toughness;
|
||||
this.repair = repair;
|
||||
}
|
||||
|
||||
|
||||
// return the armor value of a tier.
|
||||
public static int getArmor (ArmorTier tier) { return tier.armor; }
|
||||
|
||||
|
||||
// return the armor toughness of a tier.
|
||||
public static int getToughness (ArmorTier tier) { return tier.toughness; }
|
||||
|
||||
|
||||
// return the repair item of a tier
|
||||
public static Material getRepairItem (ArmorTier tier) { return tier.repair; }
|
||||
}
|
||||
|
@ -13,67 +13,67 @@ import nl.pim16aap2.armoredElytra.ArmoredElytra;
|
||||
|
||||
public class Messages
|
||||
{
|
||||
private Map<String, String> messageMap = new HashMap<String, String>();
|
||||
private Map<String, String> messageMap = new HashMap<>();
|
||||
private ArmoredElytra plugin;
|
||||
private String locale;
|
||||
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)))
|
||||
{
|
||||
String sCurrentLine;
|
||||
public Messages(ArmoredElytra plugin)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
locale = plugin.getLocale();
|
||||
textFile = new File(plugin.getDataFolder(), locale + ".txt");
|
||||
readFile();
|
||||
}
|
||||
|
||||
while ((sCurrentLine = br.readLine()) != null)
|
||||
{
|
||||
String key, value;
|
||||
String[] parts = sCurrentLine.split("=", 2);
|
||||
key = parts[0];
|
||||
value = parts[1].replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
||||
String[] newLineSplitter = value.split("\\\\n"); // Wut? Can I haz more backslash?
|
||||
|
||||
String values = newLineSplitter[0];
|
||||
|
||||
for (int idx = 1; idx < newLineSplitter.length; ++idx)
|
||||
values += "\n" + newLineSplitter[idx];
|
||||
|
||||
this.messageMap.put(key, values);
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
plugin.myLogger(Level.SEVERE, "Locale file " + this.locale + ".txt does not exist!");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
plugin.myLogger(Level.SEVERE, "Could not read locale file! (" + this.locale + ".txt)");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// Get a string from a key. Returns "null" if null.
|
||||
public String getString(String key)
|
||||
{
|
||||
String value = null;
|
||||
value = this.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;
|
||||
}
|
||||
// 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(textFile)))
|
||||
{
|
||||
String sCurrentLine;
|
||||
|
||||
while ((sCurrentLine = br.readLine()) != null)
|
||||
{
|
||||
String key, value;
|
||||
String[] parts = sCurrentLine.split("=", 2);
|
||||
key = parts[0];
|
||||
value = parts[1].replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
||||
String[] newLineSplitter = value.split("\\\\n"); // Wut? Can I haz more backslash?
|
||||
|
||||
String values = newLineSplitter[0];
|
||||
|
||||
for (int idx = 1; idx < newLineSplitter.length; ++idx)
|
||||
values += "\n" + newLineSplitter[idx];
|
||||
|
||||
messageMap.put(key, values);
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
plugin.myLogger(Level.SEVERE, "Locale file " + locale + ".txt does not exist!");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
plugin.myLogger(Level.SEVERE, "Could not read locale file! (" + locale + ".txt)");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
// Get the version's title
|
||||
this.versionName = (String) latest.get(API_NAME_VALUE);
|
||||
versionName = (String) latest.get(API_NAME_VALUE);
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
@ -141,7 +141,7 @@ public class Update
|
||||
// There was an error reading the query.
|
||||
// Does not print stacktrace, so people won't see any errors from this plugin
|
||||
// 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
|
||||
// warning in the log instead.
|
||||
|
||||
|
@ -8,8 +8,8 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
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)
|
||||
{
|
||||
return item.getDurability() >= item.getType().getMaxDurability();
|
||||
@ -19,7 +19,7 @@ public class Util
|
||||
public static ArmorTier armorToTier(Material item)
|
||||
{
|
||||
ArmorTier ret = ArmorTier.NONE;
|
||||
|
||||
|
||||
switch (item)
|
||||
{
|
||||
case LEATHER_CHESTPLATE:
|
||||
@ -42,12 +42,12 @@ public class Util
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
// Check if mat is a chest plate.
|
||||
public static boolean isChestPlate(Material mat)
|
||||
{
|
||||
if (mat == Material.LEATHER_CHESTPLATE || mat == Material.GOLD_CHESTPLATE ||
|
||||
mat == Material.CHAINMAIL_CHESTPLATE || mat == Material.IRON_CHESTPLATE ||
|
||||
if (mat == Material.LEATHER_CHESTPLATE || mat == Material.GOLD_CHESTPLATE ||
|
||||
mat == Material.CHAINMAIL_CHESTPLATE || mat == Material.IRON_CHESTPLATE ||
|
||||
mat == Material.DIAMOND_CHESTPLATE)
|
||||
return true;
|
||||
return false;
|
||||
@ -69,22 +69,22 @@ public class Util
|
||||
ret += 16;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
public static boolean playerHasCraftPerm(Player player, ArmorTier armorTier)
|
||||
{
|
||||
return ((armorTier == ArmorTier.LEATHER && player.hasPermission("armoredelytra.craft.leather")) ||
|
||||
(armorTier == ArmorTier.GOLD && player.hasPermission("armoredelytra.craft.gold" )) ||
|
||||
(armorTier == ArmorTier.CHAIN && player.hasPermission("armoredelytra.craft.chain" )) ||
|
||||
(armorTier == ArmorTier.IRON && player.hasPermission("armoredelytra.craft.iron" )) ||
|
||||
return ((armorTier == ArmorTier.LEATHER && player.hasPermission("armoredelytra.craft.leather")) ||
|
||||
(armorTier == ArmorTier.GOLD && player.hasPermission("armoredelytra.craft.gold" )) ||
|
||||
(armorTier == ArmorTier.CHAIN && player.hasPermission("armoredelytra.craft.chain" )) ||
|
||||
(armorTier == ArmorTier.IRON && player.hasPermission("armoredelytra.craft.iron" )) ||
|
||||
(armorTier == ArmorTier.DIAMOND && player.hasPermission("armoredelytra.craft.diamond")));
|
||||
}
|
||||
|
||||
|
||||
public static boolean playerHasWearPerm(Player player, ArmorTier armorTier)
|
||||
{
|
||||
return ((armorTier == ArmorTier.LEATHER && player.hasPermission("armoredelytra.wear.leather" )) ||
|
||||
(armorTier == ArmorTier.GOLD && player.hasPermission("armoredelytra.wear.gold" )) ||
|
||||
(armorTier == ArmorTier.CHAIN && player.hasPermission("armoredelytra.wear.chain" )) ||
|
||||
(armorTier == ArmorTier.IRON && player.hasPermission("armoredelytra.wear.iron" )) ||
|
||||
return ((armorTier == ArmorTier.LEATHER && player.hasPermission("armoredelytra.wear.leather" )) ||
|
||||
(armorTier == ArmorTier.GOLD && player.hasPermission("armoredelytra.wear.gold" )) ||
|
||||
(armorTier == ArmorTier.CHAIN && player.hasPermission("armoredelytra.wear.chain" )) ||
|
||||
(armorTier == ArmorTier.IRON && player.hasPermission("armoredelytra.wear.iron" )) ||
|
||||
(armorTier == ArmorTier.DIAMOND && player.hasPermission("armoredelytra.wear.diamond" )));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user