From 07fb4113afd6a5a18d6f2022f6d6d487ad6d4200 Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Thu, 17 Nov 2016 15:27:48 -0500 Subject: [PATCH] Coded the Gold Standard of Insurance --- .../components/insurance/Insurance.java | 71 +++++++++++++++++++ .../insurance/InsuranceComponent.java | 17 +++++ .../components/insurance/getInsurance.java | 52 ++++++++++++++ .../components/insurance/getInsuranceBar.java | 23 ++++++ .../insurance/getInsuranceBlock.java | 23 ++++++ .../insurance/getInsuranceNugget.java | 23 ++++++ .../metrics/commands/TestEnchantment.java | 50 +++++++++++++ 7 files changed, 259 insertions(+) create mode 100644 src/alisolarflare/components/insurance/Insurance.java create mode 100644 src/alisolarflare/components/insurance/InsuranceComponent.java create mode 100644 src/alisolarflare/components/insurance/getInsurance.java create mode 100644 src/alisolarflare/components/insurance/getInsuranceBar.java create mode 100644 src/alisolarflare/components/insurance/getInsuranceBlock.java create mode 100644 src/alisolarflare/components/insurance/getInsuranceNugget.java create mode 100644 src/alisolarflare/components/metrics/commands/TestEnchantment.java diff --git a/src/alisolarflare/components/insurance/Insurance.java b/src/alisolarflare/components/insurance/Insurance.java new file mode 100644 index 0000000..50d458d --- /dev/null +++ b/src/alisolarflare/components/insurance/Insurance.java @@ -0,0 +1,71 @@ +package alisolarflare.components.insurance; + +import java.util.Arrays; +import java.util.List; + +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.ItemStack; + +import alisolarflare.components.BaseCommand; +import alisolarflare.components.insurance.Insurance.InsuranceType; + +public class Insurance { + public static enum InsuranceType{ + Nugget, Ingot, Block + }; + public static ItemStack getInsurance(InsuranceType insuranceType){ + ItemStack insuranceItem; + List lore; + switch(insuranceType){ + case Nugget: + insuranceItem = new ItemStack(Material.GOLD_NUGGET); + lore = Arrays.asList( + "This insurance nugget will protect one inventory slot from death! Be careful" + + "though, insurance is removed whenever you die, with each itemslot costing" + + "one nugget." + ); + break; + case Ingot: + insuranceItem = new ItemStack(Material.GOLD_INGOT); + lore = Arrays.asList( + "This insurance ingot will protect nine inventory slots from death! Be " + + "careful though, insurance is removed whenever you die, with each " + + "inventory row costing one ingot." + ); + break; + case Block: + insuranceItem = new ItemStack(Material.GOLD_BLOCK); + lore = Arrays.asList( + "This insurance block will give your inventory full protection against death! " + + "Be careful though, this block will split into ingots, and you'll lose 3" + + "upon death." + ); + break; + default: + + lore = Arrays.asList( + "The InsuranceType " + insuranceType.toString() + " is not handled by the " + + "Insurance Class in" + Insurance.class.getPackage().getName() + ". Contact a "+ + "developer with a screenshot of this message" + ); + insuranceItem = BaseCommand.CreateDebugPotato(lore); + } + insuranceItem.addEnchantment(Enchantment.DURABILITY, 10); + insuranceItem.getItemMeta().setLore(lore); + return insuranceItem; + } + public static ItemStack getInsurance(InsuranceType insuranceType, int amount){ + ItemStack insurance = Insurance.getInsurance(insuranceType); + insurance.setAmount(amount); + return insurance; + } + public static boolean isInsuranceType(String string){ + for (InsuranceType insuranceType : Insurance.InsuranceType.values()){ + if (string.equalsIgnoreCase(insuranceType.toString())){ + return true; + } + } + return false; + } +} diff --git a/src/alisolarflare/components/insurance/InsuranceComponent.java b/src/alisolarflare/components/insurance/InsuranceComponent.java new file mode 100644 index 0000000..41a36d0 --- /dev/null +++ b/src/alisolarflare/components/insurance/InsuranceComponent.java @@ -0,0 +1,17 @@ +package alisolarflare.components.insurance; + +import org.bukkit.plugin.java.JavaPlugin; + +import alisolarflare.components.Component; + +public class InsuranceComponent extends Component { + + @Override + public void register(JavaPlugin plugin) { + registerCommand(plugin, new getInsurance()); + registerCommand(plugin, new getInsuranceNugget()); + registerCommand(plugin, new getInsuranceBar()); + registerCommand(plugin, new getInsuranceBlock()); + } + +} diff --git a/src/alisolarflare/components/insurance/getInsurance.java b/src/alisolarflare/components/insurance/getInsurance.java new file mode 100644 index 0000000..382a572 --- /dev/null +++ b/src/alisolarflare/components/insurance/getInsurance.java @@ -0,0 +1,52 @@ +package alisolarflare.components.insurance; + +import org.apache.commons.lang.StringUtils; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import alisolarflare.components.ModCommand; +import alisolarflare.components.insurance.Insurance.InsuranceType; + +public class getInsurance extends ModCommand { + + @Override + public boolean OnCommand(CommandSender sender, String alias, String[] args) { + Player player = (Player) sender; + if (args.length == 0){ + player.getInventory().addItem(Insurance.getInsurance(InsuranceType.Block)); + return true; + }else if(args.length == 1){ + if (StringUtils.isNumeric(args[0])){ + int amount = Integer.parseInt(args[0]); + player.getInventory().addItem(Insurance.getInsurance(InsuranceType.Block, amount)); + return true; + }else{ + if (Insurance.isInsuranceType(args[0])){ + player.getInventory().addItem((Insurance.getInsurance(InsuranceType.valueOf(args[0])))); + return true; + }else{ + return false; + } + } + }else if (args.length >=2){ + if (StringUtils.isNumeric(args[0]) && Insurance.isInsuranceType(args[1])){ + player.getInventory().addItem((Insurance.getInsurance(InsuranceType.valueOf(args[1]), Integer.parseInt(args[0])))); + return true; + }else{ + return false; + } + } + return false; + } + @Override + public String[] GetHelpText(String alias){ + return new String[]{ + "Usage: /getInsurance [amount] [type:nugget/bar/block/compound]", + "Use this command to get gold-standard inventory insurance, that saves ", + "items in an inventory upon death. One nugget saves one ItemStack, a bar", + "saves nine, a block saves 54. Compound converts amount (in nuggets) to a", + "mix of both nuggets, bars and blocks" + }; + } + +} diff --git a/src/alisolarflare/components/insurance/getInsuranceBar.java b/src/alisolarflare/components/insurance/getInsuranceBar.java new file mode 100644 index 0000000..a024f82 --- /dev/null +++ b/src/alisolarflare/components/insurance/getInsuranceBar.java @@ -0,0 +1,23 @@ +package alisolarflare.components.insurance; + +import org.apache.commons.lang3.StringUtils; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import alisolarflare.components.ModCommand; +import alisolarflare.components.insurance.Insurance.InsuranceType; + +public class getInsuranceBar extends ModCommand { + + @Override + public boolean OnCommand(CommandSender sender, String alias, String[] args) { + Player player = (Player) sender; + if (args.length > 0 || StringUtils.isNumeric(args[0])){ + player.getInventory().addItem(Insurance.getInsurance(InsuranceType.Ingot, Integer.parseInt(args[0]))); + }else{ + player.getInventory().addItem(Insurance.getInsurance(InsuranceType.Ingot)); + } + return false; + } + +} diff --git a/src/alisolarflare/components/insurance/getInsuranceBlock.java b/src/alisolarflare/components/insurance/getInsuranceBlock.java new file mode 100644 index 0000000..223db3e --- /dev/null +++ b/src/alisolarflare/components/insurance/getInsuranceBlock.java @@ -0,0 +1,23 @@ +package alisolarflare.components.insurance; + +import org.apache.commons.lang3.StringUtils; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import alisolarflare.components.ModCommand; +import alisolarflare.components.insurance.Insurance.InsuranceType; + +public class getInsuranceBlock extends ModCommand { + + @Override + public boolean OnCommand(CommandSender sender, String alias, String[] args) { + Player player = (Player) sender; + if (args.length > 0 || StringUtils.isNumeric(args[0])){ + player.getInventory().addItem(Insurance.getInsurance(InsuranceType.Block, Integer.parseInt(args[0]))); + }else{ + player.getInventory().addItem(Insurance.getInsurance(InsuranceType.Block)); + } + return false; + } + +} diff --git a/src/alisolarflare/components/insurance/getInsuranceNugget.java b/src/alisolarflare/components/insurance/getInsuranceNugget.java new file mode 100644 index 0000000..c1a0ad3 --- /dev/null +++ b/src/alisolarflare/components/insurance/getInsuranceNugget.java @@ -0,0 +1,23 @@ +package alisolarflare.components.insurance; + +import org.apache.commons.lang3.StringUtils; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import alisolarflare.components.ModCommand; +import alisolarflare.components.insurance.Insurance.InsuranceType; + +public class getInsuranceNugget extends ModCommand { + + @Override + public boolean OnCommand(CommandSender sender, String alias, String[] args) { + Player player = (Player) sender; + if (args.length > 0 || StringUtils.isNumeric(args[0])){ + player.getInventory().addItem(Insurance.getInsurance(InsuranceType.Nugget, Integer.parseInt(args[0]))); + }else{ + player.getInventory().addItem(Insurance.getInsurance(InsuranceType.Nugget)); + } + return false; + } + +} diff --git a/src/alisolarflare/components/metrics/commands/TestEnchantment.java b/src/alisolarflare/components/metrics/commands/TestEnchantment.java new file mode 100644 index 0000000..8cde4ff --- /dev/null +++ b/src/alisolarflare/components/metrics/commands/TestEnchantment.java @@ -0,0 +1,50 @@ +package alisolarflare.components.metrics.commands; + +import org.bukkit.enchantments.Enchantment; +import org.bukkit.enchantments.EnchantmentTarget; +import org.bukkit.inventory.ItemStack; + +public class TestEnchantment extends Enchantment { + + public TestEnchantment(int id) { + super(id); + // TODO Auto-generated constructor stub + } + + @Override + public String getName() { + // TODO Auto-generated method stub + return null; + } + + @Override + public int getMaxLevel() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public int getStartLevel() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public EnchantmentTarget getItemTarget() { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean conflictsWith(Enchantment other) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean canEnchantItem(ItemStack item) { + // TODO Auto-generated method stub + return false; + } + +}