From 26010c6ba2bf0b1b19d4a170596614e7f4b20344 Mon Sep 17 00:00:00 2001 From: DroppingAnvil Date: Sun, 15 Sep 2019 17:08:36 -0500 Subject: [PATCH] Added a new F Upgrade type! --- .../com/massivecraft/factions/Faction.java | 4 ++ .../zcore/fupgrades/FUpgradesGUI.java | 51 ++++++++++++++++- .../factions/zcore/fupgrades/UpgradeType.java | 3 +- .../zcore/fupgrades/UpgradesListener.java | 15 +++++ .../factions/zcore/persist/MemoryFaction.java | 7 +++ src/main/resources/config.yml | 56 +++++++++++++++---- 6 files changed, 122 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/Faction.java b/src/main/java/com/massivecraft/factions/Faction.java index 440f5860..c7974f98 100644 --- a/src/main/java/com/massivecraft/factions/Faction.java +++ b/src/main/java/com/massivecraft/factions/Faction.java @@ -23,6 +23,10 @@ import java.util.concurrent.ConcurrentHashMap; public interface Faction extends EconomyParticipator { + double getReinforcedArmor(); + + void setReinforcedArmor(double percent); + int getWarpsLimit(); void setWarpsLimit(int limit); diff --git a/src/main/java/com/massivecraft/factions/zcore/fupgrades/FUpgradesGUI.java b/src/main/java/com/massivecraft/factions/zcore/fupgrades/FUpgradesGUI.java index 61355408..f2e990aa 100644 --- a/src/main/java/com/massivecraft/factions/zcore/fupgrades/FUpgradesGUI.java +++ b/src/main/java/com/massivecraft/factions/zcore/fupgrades/FUpgradesGUI.java @@ -45,6 +45,7 @@ public class FUpgradesGUI implements Listener { List increaseSlots = FactionsPlugin.getInstance().getConfig().getIntegerList("fupgrades.MainMenu.DamageIncrease.IncreaseItem.slots"); List tntSlots = FactionsPlugin.getInstance().getConfig().getIntegerList("fupgrades.MainMenu.TNT.TntItem.slots"); List warpSlots = FactionsPlugin.getInstance().getConfig().getIntegerList("fupgrades.MainMenu.Warps.WarpItem.slots"); + List armorSlots = FactionsPlugin.getInstance().getConfig().getIntegerList("fupgrades.MainMenu.Armor.ArmorItem.slots"); for (Integer cropSlot : cropSlots) if (cropSlot != -1) inventory.setItem(cropSlot, items[2]); @@ -68,6 +69,8 @@ public class FUpgradesGUI implements Listener { for(Integer warpSlot : warpSlots) if(warpSlot != -1) inventory.setItem(warpSlot, items[10]); + for(Integer armorSlot : armorSlots) if(armorSlot != -1) inventory.setItem(armorSlot, items[11]); + fme.getPlayer().openInventory(inventory); } @@ -91,6 +94,7 @@ public class FUpgradesGUI implements Listener { ItemStack increaseItem = items[8]; ItemStack tntItem = items[9]; ItemStack warpItem = items[10]; + ItemStack armorItem = items[11]; if (e.getCurrentItem().equals(cropItem)) { int cropLevel = fme.getFaction().getUpgrade(UpgradeType.CROP); @@ -186,6 +190,24 @@ public class FUpgradesGUI implements Listener { break; } } + } else if (e.getCurrentItem().equals(armorItem)) { + int armorLevel = fme.getFaction().getUpgrade(UpgradeType.REINFORCEDARMOR); + switch (armorLevel) { + case 3: + return; + case 2: { + if (upgradeItem(fme, UpgradeType.REINFORCEDARMOR, 3, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Armor.Cost.level-3"))) + break; + } + case 1: { + if (upgradeItem(fme, UpgradeType.REINFORCEDARMOR, 2, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Armor.Cost.level-2"))) + break; + } + case 0: { + if (upgradeItem(fme, UpgradeType.REINFORCEDARMOR, 1, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Armor.Cost.level-1"))) + break; + } + } } else if (e.getCurrentItem().equals(memberItem)) { int memberLevel = fme.getFaction().getUpgrade(UpgradeType.MEMBERS) + 1; if (!FactionsPlugin.getInstance().getConfig().isSet("fupgrades.MainMenu.Members.Cost.level-" + memberLevel)) { @@ -580,7 +602,34 @@ public class FUpgradesGUI implements Listener { warpItem.setAmount(warpLevel); } - return new ItemStack[]{expItem, spawnerItem, cropItem, chestItem, powerItem, redItem, memberItem, reduceItem, increaseItem, tntItem, warpItem}; + Material armorMaterial = Material.getMaterial(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Armor.ArmorItem.Type")); + int armorAmt = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Armor.ArmorItem.Amount"); + short armorData = Short.parseShort(FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Armor.ArmorItem.Damage") + ""); + String armorName = FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Armor.ArmorItem.Name")); + List armorLore = FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fupgrades.MainMenu.Armor.ArmorItem.Lore")); + int armorLevel = fme.getFaction().getUpgrade(UpgradeType.REINFORCEDARMOR); + + for (int i = 0; i <= armorLore.size() - 1; i++) { + String line = armorLore.get(i); + line = line.replace("{level}", armorLevel + ""); + armorLore.set(i, line); + } + + ItemStack armorItem = FactionsPlugin.getInstance().createItem(armorMaterial, armorAmt, armorData, armorName, armorLore); + armorItem.getItemMeta().setLore(armorLore); + + if (armorLevel >= 1) { + ItemMeta itemMeta = armorItem.getItemMeta(); + if (!FactionsPlugin.getInstance().mc17) { + itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); + } + itemMeta.addEnchant(Enchantment.DURABILITY, 3, true); + armorItem.setItemMeta(itemMeta); + + armorItem.setAmount(armorLevel); + } + + return new ItemStack[]{expItem, spawnerItem, cropItem, chestItem, powerItem, redItem, memberItem, reduceItem, increaseItem, tntItem, warpItem, armorItem}; } private void updateTntBanks(Faction faction) { diff --git a/src/main/java/com/massivecraft/factions/zcore/fupgrades/UpgradeType.java b/src/main/java/com/massivecraft/factions/zcore/fupgrades/UpgradeType.java index 99ac0289..2e945b48 100644 --- a/src/main/java/com/massivecraft/factions/zcore/fupgrades/UpgradeType.java +++ b/src/main/java/com/massivecraft/factions/zcore/fupgrades/UpgradeType.java @@ -12,7 +12,8 @@ public enum UpgradeType { TNT("TNT"), WARP("Warps"), DAMAGEINCREASE("DamageIncrease"), - DAMAGEDECREASE("DamageDecrease"); + DAMAGEDECREASE("DamageDecrease"), + REINFORCEDARMOR("ReinforcedArmor"); private String id; diff --git a/src/main/java/com/massivecraft/factions/zcore/fupgrades/UpgradesListener.java b/src/main/java/com/massivecraft/factions/zcore/fupgrades/UpgradesListener.java index 583f7755..aa8f88bf 100644 --- a/src/main/java/com/massivecraft/factions/zcore/fupgrades/UpgradesListener.java +++ b/src/main/java/com/massivecraft/factions/zcore/fupgrades/UpgradesListener.java @@ -15,6 +15,7 @@ import org.bukkit.event.block.BlockGrowEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.SpawnerSpawnEvent; +import org.bukkit.event.player.PlayerItemDamageEvent; import org.bukkit.material.Crops; import java.util.List; @@ -171,4 +172,18 @@ public class UpgradesListener implements Listener { e.setDamage(damage + damage / 100.0 * increase); } } + @EventHandler + public void onArmorDamage(PlayerItemDamageEvent e) { + if (FPlayers.getInstance().getByPlayer(e.getPlayer()) == null) { + return; + } + System.out.print(e.getItem().toString()); + if (e.getItem().getType().toString().contains("LEGGINGS") || e.getItem().getType().toString().contains("CHESTPLATE") || e.getItem().getType().toString().contains("HELMET") || e.getItem().getType().toString().contains("BOOTS")) { + int lvl = FPlayers.getInstance().getByPlayer(e.getPlayer()).getFaction().getUpgrade(UpgradeType.REINFORCEDARMOR); + double drop = FactionsPlugin.getInstance().getConfig().getDouble("fupgrades.MainMenu.Armor.Armor-HP-Drop.level-" + lvl); + int newDamage = (int) Math.round(e.getDamage() - e.getDamage() * drop); + System.out.print(newDamage); + e.setDamage(newDamage); + } + } } diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java index 0347217f..1698f58e 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java @@ -82,6 +82,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { private boolean weeWoo; private int tntBankSize; private int warpLimit; + private double reinforcedArmor; // -------------------------------------------- // @@ -481,6 +482,12 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { tntBankSize = newLimit; } + @Override + public double getReinforcedArmor() { return this.reinforcedArmor; } + + @Override + public void setReinforcedArmor(double newPercent) { reinforcedArmor = newPercent; } + @Override public ItemStack getBanner() { if (bannerSerialized == null) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index e07b40df..41c8a6bf 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -875,7 +875,7 @@ fupgrades: - '' - '&e&lClick to &nUnlock' slots: - - 18 + - 31 EXP: EXP-Boost: level-1: 1.5 @@ -906,7 +906,7 @@ fupgrades: - '' - '&e&lClick to &nUnlock' slots: - - 20 + - 32 Power: Power-Boost: level-1: 100.0 @@ -938,7 +938,7 @@ fupgrades: - '' - '&e&lClick to &nUnlock' slots: - - 4 + - 22 Redstone: Cost: 1000000 RedstoneItem: @@ -955,7 +955,7 @@ fupgrades: - '&7 - Cost: $1,000,000' - '&e&lClick to &nUnlock' slots: - - 26 + - 23 Spawners: Spawner-Boost: # This is a Percentage so .10 means 10% lowered spawner delay! @@ -987,7 +987,7 @@ fupgrades: - '' - '&e&lClick to &nUnlock' slots: - - 24 + - 30 DamageReduct: DamageReductPercent: level-1: 3 @@ -999,7 +999,7 @@ fupgrades: level-3: 6000000 ReduceItem: Name: '&c&lDamage Reduction Upgrade' - Type: DIAMOND_CHESTPLATE + Type: GOLD_CHESTPLATE Amount: 1 Damage: 0 Lore: @@ -1019,7 +1019,7 @@ fupgrades: - '' - '&e&lClick to &nUnlock' slots: - - 0 + - 7 DamageIncrease: DamageIncreasePercent: level-1: 3 @@ -1051,7 +1051,7 @@ fupgrades: - '' - '&e&lClick to &nUnlock' slots: - - 8 + - 1 TNT: tnt-limit: level-1: 500000 @@ -1083,7 +1083,7 @@ fupgrades: - '' - '&e&lClick to &nUnlock' slots: - - 36 + - 21 Warps: warp-limit: level-1: 3 @@ -1115,7 +1115,7 @@ fupgrades: - '' - '&e&lClick to &nUnlock' slots: - - 44 + - 24 Chest: Chest-Size: # This is rows @@ -1147,7 +1147,7 @@ fupgrades: - '' - '&e&lClick to &nUnlock' slots: - - 40 + - 20 Members: Members-Limit: level-1: 30 @@ -1178,7 +1178,39 @@ fupgrades: - '' - '&e&lClick to &nUnlock' slots: - - 22 + - 40 + Armor: + Armor-HP-Drop: + # HP Drop is in percent so .10 would mean it would drop 10% of the damage to the armor + level-1: .10 + level-2: .15 + level-3: .20 + Cost: + level-1: 1000000 + level-2: 2000000 + level-3: 3000000 + ArmorItem: + Name: '&c&lReinforced Armor Upgrade' + Type: DIAMOND_CHESTPLATE + Amount: 1 + Damage: 0 + Lore: + - '&7Decreases damage to armor.' + - '' + - '&c&lTier' + - '&f&l* &7Current Level: &3{level}/3' + - '' + - '&c&lPerks' + - '&f&l* &7Level 1 - &f10% Reduction' + - '&7 - Cost: $1,000,000' + - '&f&l* &7Level 2 - &f15% Reduction' + - '&7 - Cost: $2,000,000' + - '&f&l* &7Level 3 - &f20% Reduction' + - '&7 - Cost: $3,000,000' + - '' + - '&e&lClick to &nUnlock' + slots: + - 4 ############################################################ # +------------------------------------------------------+ #