From d65233d9e03c0ffaca2da424179064fd966fcbac Mon Sep 17 00:00:00 2001 From: Driftay Date: Fri, 24 May 2019 19:30:37 -0400 Subject: [PATCH] Changes for upgrades - ProSavage --- .../com/massivecraft/factions/Faction.java | 6 +- .../zcore/fupgrades/CropUpgrades.java | 2 +- .../factions/zcore/fupgrades/EXPUpgrade.java | 2 +- .../zcore/fupgrades/FUpgradesGUI.java | 62 +++++++++---------- .../zcore/fupgrades/RedstoneUpgrade.java | 2 +- .../zcore/fupgrades/SpawnerUpgrades.java | 2 +- .../{Upgrade.java => UpgradeType.java} | 4 +- .../factions/zcore/persist/MemoryFPlayer.java | 5 ++ .../factions/zcore/persist/MemoryFaction.java | 8 +-- 9 files changed, 49 insertions(+), 44 deletions(-) rename src/main/java/com/massivecraft/factions/zcore/fupgrades/{Upgrade.java => UpgradeType.java} (83%) diff --git a/src/main/java/com/massivecraft/factions/Faction.java b/src/main/java/com/massivecraft/factions/Faction.java index ce25eeac..72558b6b 100644 --- a/src/main/java/com/massivecraft/factions/Faction.java +++ b/src/main/java/com/massivecraft/factions/Faction.java @@ -10,7 +10,7 @@ import com.massivecraft.factions.util.LazyLocation; import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.Permissable; import com.massivecraft.factions.zcore.fperms.PermissableAction; -import com.massivecraft.factions.zcore.fupgrades.Upgrade; +import com.massivecraft.factions.zcore.fupgrades.UpgradeType; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -76,9 +76,9 @@ public interface Faction extends EconomyParticipator { void deinvite(FPlayer fplayer); - void setUpgrade(Upgrade upgrade, int level); + void setUpgrade(UpgradeType upgrade, int level); - int getUpgrade(Upgrade upgrade); + int getUpgrade(UpgradeType upgrade); boolean isInvited(FPlayer fplayer); diff --git a/src/main/java/com/massivecraft/factions/zcore/fupgrades/CropUpgrades.java b/src/main/java/com/massivecraft/factions/zcore/fupgrades/CropUpgrades.java index a98490ac..3efad298 100644 --- a/src/main/java/com/massivecraft/factions/zcore/fupgrades/CropUpgrades.java +++ b/src/main/java/com/massivecraft/factions/zcore/fupgrades/CropUpgrades.java @@ -23,7 +23,7 @@ public class CropUpgrades implements Listener { Faction factionAtLoc = Board.getInstance().getFactionAt(floc); if (!factionAtLoc.isWilderness()) { - int level = factionAtLoc.getUpgrade(Upgrade.CROP); + int level = factionAtLoc.getUpgrade(UpgradeType.CROP); if (level != 0) { int chance = -1; diff --git a/src/main/java/com/massivecraft/factions/zcore/fupgrades/EXPUpgrade.java b/src/main/java/com/massivecraft/factions/zcore/fupgrades/EXPUpgrade.java index a5a13594..e0f5ca3a 100644 --- a/src/main/java/com/massivecraft/factions/zcore/fupgrades/EXPUpgrade.java +++ b/src/main/java/com/massivecraft/factions/zcore/fupgrades/EXPUpgrade.java @@ -23,7 +23,7 @@ public class EXPUpgrade implements Listener { Faction faction = Board.getInstance().getFactionAt(floc); if (!faction.isWilderness()) { - int level = faction.getUpgrade(Upgrade.EXP); + int level = faction.getUpgrade(UpgradeType.EXP); if (level != 0) { double multiplier = -1; 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 980b2efe..48212bc3 100644 --- a/src/main/java/com/massivecraft/factions/zcore/fupgrades/FUpgradesGUI.java +++ b/src/main/java/com/massivecraft/factions/zcore/fupgrades/FUpgradesGUI.java @@ -82,95 +82,95 @@ public class FUpgradesGUI implements Listener { ItemStack redItem = items[5]; if (e.getCurrentItem().equals(cropItem)) { - int cropLevel = fme.getFaction().getUpgrade(Upgrade.CROP); + int cropLevel = fme.getFaction().getUpgrade(UpgradeType.CROP); switch (cropLevel) { case 3: return; case 2: - upgradeItem(fme, Upgrade.CROP, 3, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Crops.Cost.level-3")); + upgradeItem(fme, UpgradeType.CROP, 3, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Crops.Cost.level-3")); break; case 1: - upgradeItem(fme, Upgrade.CROP, 2, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Crops.Cost.level-2")); + upgradeItem(fme, UpgradeType.CROP, 2, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Crops.Cost.level-2")); break; case 0: - upgradeItem(fme, Upgrade.CROP, 1, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Crops.Cost.level-1")); + upgradeItem(fme, UpgradeType.CROP, 1, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Crops.Cost.level-1")); break; } } else if (e.getCurrentItem().equals(powerItem)) { - int powerLevel = fme.getFaction().getUpgrade(Upgrade.POWER); + int powerLevel = fme.getFaction().getUpgrade(UpgradeType.POWER); switch (powerLevel) { case 3: return; case 2: - upgradeItem(fme, Upgrade.POWER, 3, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Power.Cost.level-3")); + upgradeItem(fme, UpgradeType.POWER, 3, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Power.Cost.level-3")); updatePower(fme.getFaction()); break; case 1: - upgradeItem(fme, Upgrade.POWER, 2, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Power.Cost.level-2")); + upgradeItem(fme, UpgradeType.POWER, 2, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Power.Cost.level-2")); updatePower(fme.getFaction()); break; case 0: - upgradeItem(fme, Upgrade.POWER, 1, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Power.Cost.level-1")); + upgradeItem(fme, UpgradeType.POWER, 1, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Power.Cost.level-1")); updatePower(fme.getFaction()); break; } } else if (e.getCurrentItem().equals(spawnerItem)) { - int spawnerLevel = fme.getFaction().getUpgrade(Upgrade.SPAWNER); + int spawnerLevel = fme.getFaction().getUpgrade(UpgradeType.SPAWNER); switch (spawnerLevel) { case 3: return; case 2: - upgradeItem(fme, Upgrade.SPAWNER, 3, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Spawners.Cost.level-3")); + upgradeItem(fme, UpgradeType.SPAWNER, 3, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Spawners.Cost.level-3")); break; case 1: - upgradeItem(fme, Upgrade.SPAWNER, 2, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Spawners.Cost.level-2")); + upgradeItem(fme, UpgradeType.SPAWNER, 2, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Spawners.Cost.level-2")); break; case 0: - upgradeItem(fme, Upgrade.SPAWNER, 1, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Spawners.Cost.level-1")); + upgradeItem(fme, UpgradeType.SPAWNER, 1, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Spawners.Cost.level-1")); break; } } else if (e.getCurrentItem().equals(expItem)) { - int expLevel = fme.getFaction().getUpgrade(Upgrade.EXP); + int expLevel = fme.getFaction().getUpgrade(UpgradeType.EXP); switch (expLevel) { case 3: return; case 2: - upgradeItem(fme, Upgrade.EXP, 3, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.EXP.Cost.level-3")); + upgradeItem(fme, UpgradeType.EXP, 3, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.EXP.Cost.level-3")); break; case 1: - upgradeItem(fme, Upgrade.EXP, 2, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.EXP.Cost.level-2")); + upgradeItem(fme, UpgradeType.EXP, 2, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.EXP.Cost.level-2")); break; case 0: - upgradeItem(fme, Upgrade.EXP, 1, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.EXP.Cost.level-1")); + upgradeItem(fme, UpgradeType.EXP, 1, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.EXP.Cost.level-1")); break; } } else if (e.getCurrentItem().equals(redItem)) { - int redLevel = fme.getFaction().getUpgrade(Upgrade.REDSTONE); + int redLevel = fme.getFaction().getUpgrade(UpgradeType.REDSTONE); switch (redLevel) { case 1: return; case 0: - upgradeItem(fme, Upgrade.REDSTONE, 1, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Redstone.Cost")); + upgradeItem(fme, UpgradeType.REDSTONE, 1, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Redstone.Cost")); break; } } else if (e.getCurrentItem().equals(chestitem)) { - int chestLevel = fme.getFaction().getUpgrade(Upgrade.CHEST); + int chestLevel = fme.getFaction().getUpgrade(UpgradeType.CHEST); switch (chestLevel) { case 3: return; case 2: { - if (upgradeItem(fme, Upgrade.CHEST, 3, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Chest.Cost.level-3"))) + if (upgradeItem(fme, UpgradeType.CHEST, 3, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Chest.Cost.level-3"))) updateChests(fme.getFaction()); break; } case 1: { - if (upgradeItem(fme, Upgrade.CHEST, 2, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Chest.Cost.level-2"))) + if (upgradeItem(fme, UpgradeType.CHEST, 2, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Chest.Cost.level-2"))) updateChests(fme.getFaction()); break; } case 0: { - if (upgradeItem(fme, Upgrade.CHEST, 1, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Chest.Cost.level-1"))) + if (upgradeItem(fme, UpgradeType.CHEST, 1, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Chest.Cost.level-1"))) updateChests(fme.getFaction()); break; } @@ -187,7 +187,7 @@ public class FUpgradesGUI implements Listener { player.closeInventory(); } - int level = faction.getUpgrade(Upgrade.CHEST); + int level = faction.getUpgrade(UpgradeType.CHEST); int size = 1; switch (level) { @@ -205,7 +205,7 @@ public class FUpgradesGUI implements Listener { } private void updatePower(Faction faction) { - int level = faction.getUpgrade(Upgrade.POWER); + int level = faction.getUpgrade(UpgradeType.POWER); double power = 0.0; switch (level) { @@ -229,7 +229,7 @@ public class FUpgradesGUI implements Listener { short expData = Short.parseShort(SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.EXP.EXPItem.Damage") + ""); String expName = SavageFactions.plugin.color(SavageFactions.plugin.getConfig().getString("fupgrades.MainMenu.EXP.EXPItem.Name")); List expLore = SavageFactions.plugin.colorList(SavageFactions.plugin.getConfig().getStringList("fupgrades.MainMenu.EXP.EXPItem.Lore")); - int expLevel = fme.getFaction().getUpgrade(Upgrade.EXP); + int expLevel = fme.getFaction().getUpgrade(UpgradeType.EXP); for (int i = 0; i <= expLore.size() - 1; i++) expLore.set(i, expLore.get(i).replace("{level}", expLevel + "")); @@ -254,7 +254,7 @@ public class FUpgradesGUI implements Listener { List spawnerLore = SavageFactions.plugin.colorList(SavageFactions.plugin.getConfig().getStringList("fupgrades.MainMenu.Spawners.SpawnerItem.Lore")); List spawnerSlots = SavageFactions.plugin.getConfig().getIntegerList("fupgrades.MainMenu.Spawners.SpawnerItem.slots"); - int spawnerLevel = fme.getFaction().getUpgrade(Upgrade.SPAWNER); + int spawnerLevel = fme.getFaction().getUpgrade(UpgradeType.SPAWNER); for (int i = 0; i <= spawnerLore.size() - 1; i++) { spawnerLore.set(i, spawnerLore.get(i).replace("{level}", spawnerLevel + "")); @@ -265,7 +265,7 @@ public class FUpgradesGUI implements Listener { short cropData = Short.parseShort(SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Crops.CropItem.Damage") + ""); String cropName = SavageFactions.plugin.color(SavageFactions.plugin.getConfig().getString("fupgrades.MainMenu.Crops.CropItem.Name")); List cropLore = SavageFactions.plugin.colorList(SavageFactions.plugin.getConfig().getStringList("fupgrades.MainMenu.Crops.CropItem.Lore")); - int cropLevel = fme.getFaction().getUpgrade(Upgrade.CROP); + int cropLevel = fme.getFaction().getUpgrade(UpgradeType.CROP); for (int i = 0; i <= cropLore.size() - 1; i++) { String line = cropLore.get(i); @@ -305,7 +305,7 @@ public class FUpgradesGUI implements Listener { short chestData = Short.parseShort(SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Chest.ChestItem.Damage") + ""); String chestName = SavageFactions.plugin.color(SavageFactions.plugin.getConfig().getString("fupgrades.MainMenu.Chest.ChestItem.Name", "&e&lUpgrade Chest Size")); List chestLore = SavageFactions.plugin.colorList(SavageFactions.plugin.getConfig().getStringList("fupgrades.MainMenu.Chest.ChestItem.Lore")); - int chestlevel = fme.getFaction().getUpgrade(Upgrade.CHEST); + int chestlevel = fme.getFaction().getUpgrade(UpgradeType.CHEST); for (int i = 0; i <= chestLore.size() - 1; i++) { String line = chestLore.get(i); @@ -331,7 +331,7 @@ public class FUpgradesGUI implements Listener { short powerData = Short.parseShort(SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Power.PowerItem.Damage") + ""); String powerName = SavageFactions.plugin.color(SavageFactions.plugin.getConfig().getString("fupgrades.MainMenu.Power.PowerItem.Name")); List powerLore = SavageFactions.plugin.colorList(SavageFactions.plugin.getConfig().getStringList("fupgrades.MainMenu.Power.PowerItem.Lore")); - int powerLevel = fme.getFaction().getUpgrade(Upgrade.POWER); + int powerLevel = fme.getFaction().getUpgrade(UpgradeType.POWER); for (int i = 0; i <= powerLore.size() - 1; i++) { String line = powerLore.get(i); @@ -358,7 +358,7 @@ public class FUpgradesGUI implements Listener { short redData = Short.parseShort(SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Redstone.RedstoneItem.Damage") + ""); String redName = SavageFactions.plugin.color(SavageFactions.plugin.getConfig().getString("fupgrades.MainMenu.Redstone.RedstoneItem.Name")); List redLore = SavageFactions.plugin.colorList(SavageFactions.plugin.getConfig().getStringList("fupgrades.MainMenu.Redstone.RedstoneItem.Lore")); - int redLevel = fme.getFaction().getUpgrade(Upgrade.REDSTONE); + int redLevel = fme.getFaction().getUpgrade(UpgradeType.REDSTONE); for (int i = 0; i <= redLore.size() - 1; i++) { String line = redLore.get(i); @@ -393,7 +393,7 @@ public class FUpgradesGUI implements Listener { fme.takeMoney(amt); } - private boolean upgradeItem(FPlayer fme, Upgrade upgrade, int level, int cost) { + private boolean upgradeItem(FPlayer fme, UpgradeType upgrade, int level, int cost) { if (hasMoney(fme, cost)) { takeMoney(fme, cost); fme.getFaction().setUpgrade(upgrade, level); diff --git a/src/main/java/com/massivecraft/factions/zcore/fupgrades/RedstoneUpgrade.java b/src/main/java/com/massivecraft/factions/zcore/fupgrades/RedstoneUpgrade.java index 106f1495..93573c86 100644 --- a/src/main/java/com/massivecraft/factions/zcore/fupgrades/RedstoneUpgrade.java +++ b/src/main/java/com/massivecraft/factions/zcore/fupgrades/RedstoneUpgrade.java @@ -20,7 +20,7 @@ public class RedstoneUpgrade implements Listener { Faction factionAtLoc = Board.getInstance().getFactionAt(floc); if (!factionAtLoc.isWilderness()) { - int level = factionAtLoc.getUpgrade(Upgrade.REDSTONE); + int level = factionAtLoc.getUpgrade(UpgradeType.REDSTONE); if (level != 0) { switch (level) { case 1: diff --git a/src/main/java/com/massivecraft/factions/zcore/fupgrades/SpawnerUpgrades.java b/src/main/java/com/massivecraft/factions/zcore/fupgrades/SpawnerUpgrades.java index ad36505f..2f03732e 100644 --- a/src/main/java/com/massivecraft/factions/zcore/fupgrades/SpawnerUpgrades.java +++ b/src/main/java/com/massivecraft/factions/zcore/fupgrades/SpawnerUpgrades.java @@ -16,7 +16,7 @@ public class SpawnerUpgrades implements Listener { Faction factionAtLoc = Board.getInstance().getFactionAt(floc); if (!factionAtLoc.isWilderness()) { - int level = factionAtLoc.getUpgrade(Upgrade.SPAWNER); + int level = factionAtLoc.getUpgrade(UpgradeType.SPAWNER); if (level != 0) { switch (level) { case 1: diff --git a/src/main/java/com/massivecraft/factions/zcore/fupgrades/Upgrade.java b/src/main/java/com/massivecraft/factions/zcore/fupgrades/UpgradeType.java similarity index 83% rename from src/main/java/com/massivecraft/factions/zcore/fupgrades/Upgrade.java rename to src/main/java/com/massivecraft/factions/zcore/fupgrades/UpgradeType.java index 73791be8..e5367882 100644 --- a/src/main/java/com/massivecraft/factions/zcore/fupgrades/Upgrade.java +++ b/src/main/java/com/massivecraft/factions/zcore/fupgrades/UpgradeType.java @@ -1,13 +1,13 @@ package com.massivecraft.factions.zcore.fupgrades; -public enum Upgrade { +public enum UpgradeType { CHEST("Chest"), SPAWNER("Spawner"), EXP("Exp"), CROP("Crop"), POWER("Power"), REDSTONE("Redstone"); private String id; - Upgrade(String id) { + UpgradeType(String id) { this.id = id; } diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java index babbe71b..82f37baa 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java @@ -1065,6 +1065,11 @@ public abstract class MemoryFPlayer implements FPlayer { @Override public boolean checkIfNearbyEnemies() { Player me = this.getPlayer(); + + if (me == null) { + return false; + } + int radius = Conf.stealthFlyCheckRadius; for (Entity e : me.getNearbyEntities(radius, 255, radius)) { if (e == null) { 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 f6ae71eb..86d0a758 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java @@ -18,7 +18,7 @@ import com.massivecraft.factions.util.RelationUtil; import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.Permissable; import com.massivecraft.factions.zcore.fperms.PermissableAction; -import com.massivecraft.factions.zcore.fupgrades.Upgrade; +import com.massivecraft.factions.zcore.fupgrades.UpgradeType; import com.massivecraft.factions.zcore.util.TL; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -383,7 +383,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { vault = newlocation; } - public int getUpgrade(Upgrade upgrade) { + public int getUpgrade(UpgradeType upgrade) { if (upgrades.keySet().contains(upgrade.toString())) { return upgrades.get(upgrade.toString()); } @@ -395,7 +395,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { if (chest != null) { return chest; } else { - int level = getUpgrade(Upgrade.CHEST); + int level = getUpgrade(UpgradeType.CHEST); int size = 9; if (level == 1) { size = SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Chest.Chest-Size.level-1") * 9; @@ -433,7 +433,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { return ItemStack.deserialize(bannerSerialized); } - public void setUpgrade(Upgrade upgrade, int level) { + public void setUpgrade(UpgradeType upgrade, int level) { upgrades.put(upgrade.toString(), level); }