Coded the Gold Standard of Insurance
This commit is contained in:
parent
52c97535ab
commit
07fb4113af
7 changed files with 259 additions and 0 deletions
71
src/alisolarflare/components/insurance/Insurance.java
Normal file
71
src/alisolarflare/components/insurance/Insurance.java
Normal file
|
@ -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<String> 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
52
src/alisolarflare/components/insurance/getInsurance.java
Normal file
52
src/alisolarflare/components/insurance/getInsurance.java
Normal file
|
@ -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"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
23
src/alisolarflare/components/insurance/getInsuranceBar.java
Normal file
23
src/alisolarflare/components/insurance/getInsuranceBar.java
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue