mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Added NotConfigurable attribute
This commit is contained in:
parent
f98d048b55
commit
07c84af3b5
@ -33,6 +33,7 @@
|
||||
* You can now convert any gold ingot into gold dust with slightly less returns
|
||||
* Magical Zombie Pills now also work on Zombified Piglins
|
||||
* (API) Added SlimefunGuideOpenEvent
|
||||
* (API) Added "NotConfigurable" attribute to disable configurability
|
||||
|
||||
#### Changes
|
||||
* Improved Auto-Updater (Multi-Threading and more)
|
||||
@ -59,6 +60,7 @@
|
||||
* Fixed #2357
|
||||
* Fixed Auto Enchanters being unaffected by speed modifications from addons
|
||||
* Fixed Auto Disenchanters being unaffected by speed modifications from addons
|
||||
* Fixed radioactive items still being radioactive when disabled
|
||||
|
||||
## Release Candidate 16 (07 Sep 2020)
|
||||
https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#16
|
||||
|
@ -0,0 +1,14 @@
|
||||
package io.github.thebusybiscuit.slimefun4.core.attributes;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
|
||||
/**
|
||||
* Implement this interface for any {@link SlimefunItem} to prevent
|
||||
* that {@link SlimefunItem} from showing up in the {@code Items.yml} config file.
|
||||
*
|
||||
* @author TheBusyBiscuit
|
||||
*
|
||||
*/
|
||||
public interface NotConfigurable {
|
||||
|
||||
}
|
@ -8,6 +8,7 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -30,6 +31,7 @@ import io.github.thebusybiscuit.slimefun4.api.exceptions.UnregisteredItemExcepti
|
||||
import io.github.thebusybiscuit.slimefun4.api.exceptions.WrongItemStackException;
|
||||
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
|
||||
import io.github.thebusybiscuit.slimefun4.api.items.ItemState;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.NotConfigurable;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.Placeable;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.Radioactive;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.Rechargeable;
|
||||
@ -360,15 +362,18 @@ public class SlimefunItem implements Placeable {
|
||||
SlimefunPlugin.getRegistry().getAllSlimefunItems().add(this);
|
||||
SlimefunPlugin.getRegistry().getSlimefunItemIds().put(id, this);
|
||||
|
||||
SlimefunPlugin.getItemCfg().setDefaultValue(id + ".enabled", true);
|
||||
SlimefunPlugin.getItemCfg().setDefaultValue(id + ".can-be-used-in-workbenches", useableInWorkbench);
|
||||
SlimefunPlugin.getItemCfg().setDefaultValue(id + ".hide-in-guide", hidden);
|
||||
SlimefunPlugin.getItemCfg().setDefaultValue(id + ".allow-enchanting", enchantable);
|
||||
SlimefunPlugin.getItemCfg().setDefaultValue(id + ".allow-disenchanting", disenchantable);
|
||||
// Items that are "not-configurable" cannot be configured.
|
||||
if (!(this instanceof NotConfigurable)) {
|
||||
SlimefunPlugin.getItemCfg().setDefaultValue(id + ".enabled", true);
|
||||
SlimefunPlugin.getItemCfg().setDefaultValue(id + ".can-be-used-in-workbenches", useableInWorkbench);
|
||||
SlimefunPlugin.getItemCfg().setDefaultValue(id + ".hide-in-guide", hidden);
|
||||
SlimefunPlugin.getItemCfg().setDefaultValue(id + ".allow-enchanting", enchantable);
|
||||
SlimefunPlugin.getItemCfg().setDefaultValue(id + ".allow-disenchanting", disenchantable);
|
||||
|
||||
// Load all item settings
|
||||
for (ItemSetting<?> setting : itemSettings) {
|
||||
setting.load(this);
|
||||
// Load all item settings
|
||||
for (ItemSetting<?> setting : itemSettings) {
|
||||
setting.load(this);
|
||||
}
|
||||
}
|
||||
|
||||
if (ticking && !SlimefunPlugin.getCfg().getBoolean("URID.enable-tickers")) {
|
||||
@ -376,26 +381,17 @@ public class SlimefunItem implements Placeable {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this instanceof Radioactive) {
|
||||
SlimefunPlugin.getRegistry().getRadioactiveItems().add(this);
|
||||
}
|
||||
|
||||
if (SlimefunPlugin.getItemCfg().getBoolean(id + ".enabled")) {
|
||||
|
||||
if (!category.isRegistered()) {
|
||||
category.register();
|
||||
}
|
||||
|
||||
if (this instanceof NotConfigurable) {
|
||||
// Not-configurable items will be enabled.
|
||||
// Any other settings will remain as default.
|
||||
state = ItemState.ENABLED;
|
||||
}
|
||||
else if (SlimefunPlugin.getItemCfg().getBoolean(id + ".enabled")) {
|
||||
state = ItemState.ENABLED;
|
||||
checkForDeprecations(getClass());
|
||||
|
||||
useableInWorkbench = SlimefunPlugin.getItemCfg().getBoolean(id + ".can-be-used-in-workbenches");
|
||||
hidden = SlimefunPlugin.getItemCfg().getBoolean(id + ".hide-in-guide");
|
||||
enchantable = SlimefunPlugin.getItemCfg().getBoolean(id + ".allow-enchanting");
|
||||
disenchantable = SlimefunPlugin.getItemCfg().getBoolean(id + ".allow-disenchanting");
|
||||
|
||||
SlimefunPlugin.getRegistry().getEnabledSlimefunItems().add(this);
|
||||
loadItemHandlers();
|
||||
}
|
||||
else if (this instanceof VanillaItem) {
|
||||
state = ItemState.VANILLA_FALLBACK;
|
||||
@ -404,19 +400,43 @@ public class SlimefunItem implements Placeable {
|
||||
state = ItemState.DISABLED;
|
||||
}
|
||||
|
||||
// Now we can be certain this item should be enabled
|
||||
if (state == ItemState.ENABLED) {
|
||||
// Register the Category too if it hasn't been registered yet
|
||||
if (!category.isRegistered()) {
|
||||
category.register();
|
||||
}
|
||||
|
||||
// Send out deprecation warnings for any classes or intefaces
|
||||
checkForDeprecations(getClass());
|
||||
|
||||
// Add it to the list of enabled items
|
||||
SlimefunPlugin.getRegistry().getEnabledSlimefunItems().add(this);
|
||||
|
||||
// Load our Item Handlers
|
||||
loadItemHandlers();
|
||||
|
||||
// Properly mark this Item as radioactive
|
||||
if (this instanceof Radioactive) {
|
||||
SlimefunPlugin.getRegistry().getRadioactiveItems().add(this);
|
||||
}
|
||||
}
|
||||
|
||||
// Lock the SlimefunItemStack from any accidental manipulations
|
||||
if (item instanceof SlimefunItemStack && isItemStackImmutable()) {
|
||||
((SlimefunItemStack) item).lock();
|
||||
}
|
||||
|
||||
postRegister();
|
||||
|
||||
// handle runtime-registrations / auto-loading
|
||||
if (SlimefunPlugin.getRegistry().isAutoLoadingEnabled() && state == ItemState.ENABLED) {
|
||||
info("Item was registered during runtime.");
|
||||
load();
|
||||
}
|
||||
}
|
||||
catch (Exception x) {
|
||||
error("Registering " + toString() + " has failed", x);
|
||||
error("Registering " + toString() + " has failed!", x);
|
||||
}
|
||||
}
|
||||
|
||||
@ -464,7 +484,7 @@ public class SlimefunItem implements Placeable {
|
||||
* @param c
|
||||
* The {@link Class} from which to start this operation.
|
||||
*/
|
||||
private void checkForDeprecations(Class<?> c) {
|
||||
private void checkForDeprecations(@Nullable Class<?> c) {
|
||||
if (SlimefunPlugin.getUpdater().getBranch() == SlimefunBranch.DEVELOPMENT) {
|
||||
// This method is currently way too spammy with all the restructuring going on...
|
||||
// Since DEV builds are anyway under "development", things may be relocated.
|
||||
@ -526,6 +546,12 @@ public class SlimefunItem implements Placeable {
|
||||
this.recipeType = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* This sets the {@link Category} in which this {@link SlimefunItem} will be displayed.
|
||||
*
|
||||
* @param category
|
||||
* The new {@link Category}
|
||||
*/
|
||||
public void setCategory(@Nonnull Category category) {
|
||||
Validate.notNull(category, "The Category is not allowed to be null!");
|
||||
|
||||
@ -590,6 +616,7 @@ public class SlimefunItem implements Placeable {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the given item is a SlimefunitemStack, simply compare the id
|
||||
if (item instanceof SlimefunItemStack) {
|
||||
return getID().equals(((SlimefunItemStack) item).getItemId());
|
||||
}
|
||||
@ -670,6 +697,10 @@ public class SlimefunItem implements Placeable {
|
||||
throw new UnsupportedOperationException("You cannot add an ItemSetting after the SlimefunItem was registered.");
|
||||
}
|
||||
|
||||
if (this instanceof NotConfigurable) {
|
||||
throw new UnsupportedOperationException("This Item has been marked as NotConfigurable and cannot accept Item Settings!");
|
||||
}
|
||||
|
||||
for (ItemSetting<?> setting : settings) {
|
||||
if (setting != null) {
|
||||
// Prevent two Item Settings with the same key
|
||||
@ -817,12 +848,28 @@ public class SlimefunItem implements Placeable {
|
||||
return getDrops();
|
||||
}
|
||||
|
||||
public void info(String message) {
|
||||
/**
|
||||
* This will send an info message to the console and signal that this message came
|
||||
* from this {@link SlimefunItem}, the message will be sent using the {@link Logger}
|
||||
* of the {@link SlimefunAddon} which registered this {@link SlimefunItem}.
|
||||
*
|
||||
* @param message
|
||||
* The message to send
|
||||
*/
|
||||
public void info(@Nonnull String message) {
|
||||
String msg = toString() + ": " + message;
|
||||
addon.getLogger().log(Level.INFO, msg);
|
||||
}
|
||||
|
||||
public void warn(String message) {
|
||||
/**
|
||||
* This will send a warning to the console and signal that this warning came from
|
||||
* this {@link SlimefunItem}, the warning will be sent using the {@link Logger}
|
||||
* of the {@link SlimefunAddon} which registered this {@link SlimefunItem}.
|
||||
*
|
||||
* @param message
|
||||
* The message to send
|
||||
*/
|
||||
public void warn(@Nonnull String message) {
|
||||
String msg = toString() + ": " + message;
|
||||
addon.getLogger().log(Level.WARNING, msg);
|
||||
|
||||
@ -841,7 +888,7 @@ public class SlimefunItem implements Placeable {
|
||||
* @param throwable
|
||||
* The {@link Throwable} to throw as a stacktrace.
|
||||
*/
|
||||
public void error(String message, Throwable throwable) {
|
||||
public void error(@Nonnull String message, @Nonnull Throwable throwable) {
|
||||
addon.getLogger().log(Level.SEVERE, "Item \"{0}\" from {1} v{2} has caused an Error!", new Object[] { id, addon.getName(), addon.getPluginVersion() });
|
||||
|
||||
if (addon.getBugTrackerURL() != null) {
|
||||
|
Loading…
Reference in New Issue
Block a user