Made an Upgrade Enum, the code in /f upgrades is horrible, will be working on improving it.

This commit is contained in:
ProSavage 2018-12-15 23:04:23 -06:00
parent 70bc5b5d6c
commit cc1714b757
7 changed files with 86 additions and 41 deletions

View File

@ -10,6 +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 org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@ -64,9 +65,9 @@ public interface Faction extends EconomyParticipator {
void deinvite(FPlayer fplayer);
void setUpgrades(String key, int level);
void setUpgrade(Upgrade upgrade, int level);
int getUpgrade(String key);
int getUpgrade(Upgrade upgrade);
boolean isInvited(FPlayer fplayer);

View File

@ -1,6 +1,9 @@
package com.massivecraft.factions.zcore.fupgrades;
import com.massivecraft.factions.*;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.SavageFactions;
import org.bukkit.CropState;
import org.bukkit.Material;
import org.bukkit.block.Block;
@ -20,7 +23,7 @@ public class CropUpgrades implements Listener {
Faction factionAtLoc = Board.getInstance().getFactionAt(floc);
if (!factionAtLoc.isWilderness()) {
int level = factionAtLoc.getUpgrade("Crop");
int level = factionAtLoc.getUpgrade(Upgrade.CROP);
if (level != 0) {
int chance = -1;

View File

@ -1,7 +1,9 @@
package com.massivecraft.factions.zcore.fupgrades;
import com.massivecraft.factions.*;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.SavageFactions;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -21,7 +23,7 @@ public class EXPUpgrade implements Listener {
Faction faction = Board.getInstance().getFactionAt(floc);
if (!faction.isWilderness()) {
int level = faction.getUpgrade("Exp");
int level = faction.getUpgrade(Upgrade.EXP);
if (level != 0) {
double multiplier = -1;

View File

@ -72,59 +72,77 @@ public class FUpgradesGUI implements Listener {
ItemStack spawnerItem = items[1];
if (e.getCurrentItem().equals(cropItem)) {
int cropLevel = fme.getFaction().getUpgrade("Crop");
int cropLevel = fme.getFaction().getUpgrade(Upgrade.CROP);
switch (cropLevel)
{
case 3: return;
case 2: upgradeItem(fme, "Crop", 3, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Crops.Cost.level-3")); break;
case 1: upgradeItem(fme, "Crop", 2, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Crops.Cost.level-2")); break;
case 0: upgradeItem(fme, "Crop", 1, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Crops.Cost.level-1")); break;
case 2:
upgradeItem(fme, Upgrade.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"));
break;
case 0:
upgradeItem(fme, Upgrade.CROP, 1, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Crops.Cost.level-1"));
break;
}
}
else if (e.getCurrentItem().equals(spawnerItem)) {
int spawnerLevel = fme.getFaction().getUpgrade("Spawner");
int spawnerLevel = fme.getFaction().getUpgrade(Upgrade.SPAWNER);
switch(spawnerLevel)
{
case 3: return;
case 2: upgradeItem(fme, "Spawner", 3, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Spawners.Cost.level-3")); break;
case 1: upgradeItem(fme, "Spawner", 2, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Spawners.Cost.level-2")); break;
case 0: upgradeItem(fme, "Spawner", 1, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Spawners.Cost.level-1")); break;
case 2:
upgradeItem(fme, Upgrade.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"));
break;
case 0:
upgradeItem(fme, Upgrade.SPAWNER, 1, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Spawners.Cost.level-1"));
break;
}
}
else if (e.getCurrentItem().equals(expItem)) {
int expLevel = fme.getFaction().getUpgrade("Exp");
int expLevel = fme.getFaction().getUpgrade(Upgrade.EXP);
switch (expLevel)
{
case 3: return;
case 2: upgradeItem(fme, "Exp", 3, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.EXP.Cost.level-3")); break;
case 1: upgradeItem(fme, "Exp", 2, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.EXP.Cost.level-2")); break;
case 0: upgradeItem(fme, "Exp", 1, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.EXP.Cost.level-1")); break;
case 2:
upgradeItem(fme, Upgrade.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"));
break;
case 0:
upgradeItem(fme, Upgrade.EXP, 1, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.EXP.Cost.level-1"));
break;
}
}
else if (e.getCurrentItem().equals(chestitem)) {
int chestLevel = fme.getFaction().getUpgrade("Chest");
int chestLevel = fme.getFaction().getUpgrade(Upgrade.CHEST);
switch (chestLevel)
{
case 3: return;
case 2:
{
if (upgradeItem(fme, "Chest", 3, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Chest.Cost.level-3")))
if (upgradeItem(fme, Upgrade.CHEST, 3, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Chest.Cost.level-3")))
updateChests(fme.getFaction());
break;
}
case 1:
{
if (upgradeItem(fme, "Chest", 2, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Chest.Cost.level-2")))
if (upgradeItem(fme, Upgrade.CHEST, 2, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Chest.Cost.level-2")))
updateChests(fme.getFaction());
break;
}
case 0:
{
if (upgradeItem(fme, "Chest", 1, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Chest.Cost.level-1")))
if (upgradeItem(fme, Upgrade.CHEST, 1, SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Chest.Cost.level-1")))
updateChests(fme.getFaction());
break;
}
@ -141,7 +159,7 @@ public class FUpgradesGUI implements Listener {
player.closeInventory();
}
int level = faction.getUpgrade("Chest");
int level = faction.getUpgrade(Upgrade.CHEST);
int size = 1;
switch (level)
@ -160,7 +178,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<String> expLore = SavageFactions.plugin.colorList(SavageFactions.plugin.getConfig().getStringList("fupgrades.MainMenu.EXP.EXPItem.Lore"));
int expLevel = fme.getFaction().getUpgrade("Exp");
int expLevel = fme.getFaction().getUpgrade(Upgrade.EXP);
for (int i = 0; i <= expLore.size() - 1; i++)
expLore.set(i, expLore.get(i).replace("{level}", expLevel + ""));
@ -185,7 +203,7 @@ public class FUpgradesGUI implements Listener {
List<String> spawnerLore = SavageFactions.plugin.colorList(SavageFactions.plugin.getConfig().getStringList("fupgrades.MainMenu.Spawners.SpawnerItem.Lore"));
List<Integer> spawnerSlots = SavageFactions.plugin.getConfig().getIntegerList("fupgrades.MainMenu.Spawners.SpawnerItem.slots");
int spawnerLevel = fme.getFaction().getUpgrade("Spawner");
int spawnerLevel = fme.getFaction().getUpgrade(Upgrade.SPAWNER);
for (int i = 0; i <= spawnerLore.size() - 1; i++) {
spawnerLore.set(i, spawnerLore.get(i).replace("{level}", spawnerLevel + ""));
@ -196,7 +214,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<String> cropLore = SavageFactions.plugin.colorList(SavageFactions.plugin.getConfig().getStringList("fupgrades.MainMenu.Crops.CropItem.Lore"));
int cropLevel = fme.getFaction().getUpgrade("Crop");
int cropLevel = fme.getFaction().getUpgrade(Upgrade.CROP);
for (int i = 0; i <= cropLore.size() - 1; i++) {
String line = cropLore.get(i);
@ -236,7 +254,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<String> chestLore = SavageFactions.plugin.colorList(SavageFactions.plugin.getConfig().getStringList("fupgrades.MainMenu.Chest.ChestItem.Lore"));
int chestlevel = fme.getFaction().getUpgrade("Chest");
int chestlevel = fme.getFaction().getUpgrade(Upgrade.CHEST);
for (int i = 0; i <= chestLore.size() - 1; i++) {
String line = chestLore.get(i);
@ -269,11 +287,11 @@ public class FUpgradesGUI implements Listener {
fme.takeMoney(amt);
}
private boolean upgradeItem(FPlayer fme, String upgrade, int level, int cost)
private boolean upgradeItem(FPlayer fme, Upgrade upgrade, int level, int cost)
{
if (hasMoney(fme, cost)) {
takeMoney(fme, cost);
fme.getFaction().setUpgrades(upgrade, level);
fme.getFaction().setUpgrade(upgrade, level);
fme.getPlayer().closeInventory();
return true;
}

View File

@ -1,7 +1,9 @@
package com.massivecraft.factions.zcore.fupgrades;
import com.massivecraft.factions.*;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.SavageFactions;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.SpawnerSpawnEvent;
@ -14,7 +16,7 @@ public class SpawnerUpgrades implements Listener {
Faction factionAtLoc = Board.getInstance().getFactionAt(floc);
if (!factionAtLoc.isWilderness()) {
int level = factionAtLoc.getUpgrade("Spawner");
int level = factionAtLoc.getUpgrade(Upgrade.SPAWNER);
if (level != 0) {
switch (level)
{

View File

@ -0,0 +1,18 @@
package com.massivecraft.factions.zcore.fupgrades;
public enum Upgrade {
CHEST("Chest"), SPAWNER("Spawner"), EXP("Exp"), CROP("Crop");
private String id;
Upgrade(String id) {
this.id = id;
}
@Override
public String toString() {
return this.id;
}
}

View File

@ -18,6 +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.util.TL;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -352,9 +353,9 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
vault = newlocation;
}
public int getUpgrade(String key) {
if (upgrades.keySet().contains(key)) {
return upgrades.get(key);
public int getUpgrade(Upgrade upgrade) {
if (upgrades.keySet().contains(upgrade.toString())) {
return upgrades.get(upgrade.toString());
}
return 0;
}
@ -364,7 +365,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
if (chest != null) {
return chest;
} else {
int level = getUpgrade("Chest");
int level = getUpgrade(Upgrade.CHEST);
int size = 9;
if (level == 1) {
size = SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Chest.Chest-Size.level-1") * 9;
@ -402,8 +403,8 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
return ItemStack.deserialize(bannerSerialized);
}
public void setUpgrades(String key, int level) {
upgrades.put(key, level);
public void setUpgrade(Upgrade upgrade, int level) {
upgrades.put(upgrade.toString(), level);
}
public Location getCheckpoint() {