1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

Added a State enum for SlimefunItem

Related to https://github.com/TheBusyBiscuit/Slimefun4/pull/337,
https://github.com/TheBusyBiscuit/Slimefun4/issues/231
This commit is contained in:
Poslovitch 2017-06-22 22:16:22 +02:00
parent 19af94c6ea
commit e388bf01f1
2 changed files with 38 additions and 20 deletions

View File

@ -64,6 +64,14 @@ public class SlimefunItem {
EnergyTicker energy; EnergyTicker energy;
public String hash; public String hash;
State state;
public enum State {
ENABLED,
DISABLED,
VANILLA;
}
int month = -1; int month = -1;
public int getMonth() { public int getMonth() {
@ -97,7 +105,6 @@ public class SlimefunItem {
this.replacing = false; this.replacing = false;
this.enchantable = true; this.enchantable = true;
this.disenchantable = true; this.disenchantable = true;
itemhandlers = new HashSet<ItemHandler>(); itemhandlers = new HashSet<ItemHandler>();
urid = URID.nextURID(this, false); urid = URID.nextURID(this, false);
@ -206,6 +213,9 @@ public class SlimefunItem {
} }
else if (SlimefunStartup.getItemCfg().getBoolean(this.name + ".enabled")) { else if (SlimefunStartup.getItemCfg().getBoolean(this.name + ".enabled")) {
if (!Category.list().contains(category)) category.register(); if (!Category.list().contains(category)) category.register();
this.state = State.ENABLED;
this.replacing = SlimefunStartup.getItemCfg().getBoolean(this.name + ".can-be-used-in-workbenches"); this.replacing = SlimefunStartup.getItemCfg().getBoolean(this.name + ".can-be-used-in-workbenches");
this.enchantable = SlimefunStartup.getItemCfg().getBoolean(this.name + ".allow-enchanting"); this.enchantable = SlimefunStartup.getItemCfg().getBoolean(this.name + ".allow-enchanting");
this.disenchantable = SlimefunStartup.getItemCfg().getBoolean(this.name + ".allow-disenchanting"); this.disenchantable = SlimefunStartup.getItemCfg().getBoolean(this.name + ".allow-disenchanting");
@ -220,6 +230,9 @@ public class SlimefunItem {
} }
if (SlimefunStartup.getCfg().getBoolean("options.print-out-loading")) System.out.println("[Slimefun] Loaded Item \"" + this.getName() + "\""); if (SlimefunStartup.getCfg().getBoolean("options.print-out-loading")) System.out.println("[Slimefun] Loaded Item \"" + this.getName() + "\"");
} else if (!SlimefunStartup.getItemCfg().getBoolean(this.name + ".enabled")) {
if (this instanceof VanillaItem) this.state = State.VANILLA;
else this.state = State.DISABLED;
} }
} catch(Exception x) { } catch(Exception x) {
System.err.println("[Slimefun] Item Registration failed: " + this.name); System.err.println("[Slimefun] Item Registration failed: " + this.name);
@ -305,25 +318,30 @@ public class SlimefunItem {
} }
} }
public static State getState(ItemStack item) {
for (SlimefunItem i: all) {
if (i.isItem(item)) {
return i.getState();
}
}
return State.DISABLED;
}
public static boolean isDisabled(ItemStack item) { public static boolean isDisabled(ItemStack item) {
boolean contains1 = false; for (SlimefunItem i: all) {
boolean contains2 = false;
for (SlimefunItem i: all) {
if (i.isItem(item)) { if (i.isItem(item)) {
contains1 = true; return i.isDisabled();
break;
} }
} }
return false;
for (SlimefunItem i: items) { }
if (i.isItem(item)) {
contains2 = true; public State getState(){
break; return state;
} }
}
public boolean isDisabled(){
return contains1 && !contains2; return state != State.ENABLED;
} }
public void install() {} public void install() {}

View File

@ -15,7 +15,7 @@ import me.mrCookieSlime.Slimefun.GPS.GPSNetwork;
import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.Research; import me.mrCookieSlime.Slimefun.Objects.Research;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.VanillaItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem.State;
import me.mrCookieSlime.Slimefun.Setup.Messages; import me.mrCookieSlime.Slimefun.Setup.Messages;
public class Slimefun { public class Slimefun {
@ -62,7 +62,7 @@ public class Slimefun {
SlimefunItem sfItem = SlimefunItem.getByItem(item); SlimefunItem sfItem = SlimefunItem.getByItem(item);
if (sfItem == null) { if (sfItem == null) {
if (SlimefunItem.isDisabled(item)) { if (SlimefunItem.isDisabled(item)) {
if (message && !(sfItem instanceof VanillaItem)) Messages.local.sendTranslation(p, "messages.disabled-item", true); if (message && SlimefunItem.getState(item).equals(State.DISABLED)) Messages.local.sendTranslation(p, "messages.disabled-item", true);
return false; return false;
} }
else return true; else return true;
@ -71,7 +71,7 @@ public class Slimefun {
if (sfItem.getResearch() == null) return true; if (sfItem.getResearch() == null) return true;
else if (sfItem.getResearch().hasUnlocked(p)) return true; else if (sfItem.getResearch().hasUnlocked(p)) return true;
else { else {
if (message && !(sfItem instanceof VanillaItem)) Messages.local.sendTranslation(p, "messages.not-researched", true); if (message && sfItem.getState().equals(State.DISABLED)) Messages.local.sendTranslation(p, "messages.not-researched", true);
return false; return false;
} }
} }
@ -83,7 +83,7 @@ public class Slimefun {
if (sfItem.getResearch() == null) return true; if (sfItem.getResearch() == null) return true;
else if (sfItem.getResearch().hasUnlocked(p)) return true; else if (sfItem.getResearch().hasUnlocked(p)) return true;
else { else {
if (message && !(sfItem instanceof VanillaItem)) Messages.local.sendTranslation(p, "messages.not-researched", true); if (message && sfItem.getState().equals(State.DISABLED)) Messages.local.sendTranslation(p, "messages.not-researched", true);
return false; return false;
} }
} }