mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Fixes #2081
This commit is contained in:
parent
6d3e4ca96b
commit
8fd0afd8bd
@ -93,6 +93,7 @@
|
|||||||
* Fixed "korean" showing up as "null"
|
* Fixed "korean" showing up as "null"
|
||||||
* Fixed an issue with moving androids getting stuck
|
* Fixed an issue with moving androids getting stuck
|
||||||
* Fixed Cargo nodes sometimes preventing chunks from unloading
|
* Fixed Cargo nodes sometimes preventing chunks from unloading
|
||||||
|
* Fixed #2081
|
||||||
|
|
||||||
## Release Candidate 13 (16 Jun 2020)
|
## Release Candidate 13 (16 Jun 2020)
|
||||||
https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#13
|
https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#13
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
package io.github.thebusybiscuit.slimefun4.api.exceptions;
|
||||||
|
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import io.github.thebusybiscuit.slimefun4.core.attributes.DamageableItem;
|
||||||
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||||
|
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@link WrongItemStackException} is thrown when someone tries to alter an {@link ItemStack}
|
||||||
|
* but actually wanted to alter a different one.
|
||||||
|
*
|
||||||
|
* If for example a {@link DamageableItem} accidentally damages the original {@link SlimefunItem}
|
||||||
|
* instead of the held {@link ItemStack}, this will be thrown.
|
||||||
|
*
|
||||||
|
* @author TheBusyBiscuit
|
||||||
|
*
|
||||||
|
* @see SlimefunItemStack
|
||||||
|
* @see SlimefunItem
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class WrongItemStackException extends RuntimeException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 9144658137363309071L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This constructs a new {@link WrongItemStackException} with the given error context.
|
||||||
|
*
|
||||||
|
* @param message
|
||||||
|
* An error message to display
|
||||||
|
*/
|
||||||
|
public WrongItemStackException(String message) {
|
||||||
|
super("You probably wanted alter a different ItemStack: " + message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -21,10 +21,10 @@ import io.github.thebusybiscuit.slimefun4.core.attributes.DamageableItem;
|
|||||||
import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
|
import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
|
||||||
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler;
|
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
|
||||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler;
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
|
||||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason;
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason;
|
||||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||||
@ -63,7 +63,7 @@ class ExplosiveTool extends SimpleSlimefunItem<BlockBreakHandler> implements Not
|
|||||||
b.getWorld().playSound(b.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 0.2F, 1F);
|
b.getWorld().playSound(b.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 0.2F, 1F);
|
||||||
|
|
||||||
List<Block> blocks = findBlocks(b);
|
List<Block> blocks = findBlocks(b);
|
||||||
breakBlocks(p, b, blocks, fortune, drops);
|
breakBlocks(p, item, b, blocks, fortune, drops);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -75,7 +75,7 @@ class ExplosiveTool extends SimpleSlimefunItem<BlockBreakHandler> implements Not
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void breakBlocks(Player p, Block b, List<Block> blocks, int fortune, List<ItemStack> drops) {
|
private void breakBlocks(Player p, ItemStack item, Block b, List<Block> blocks, int fortune, List<ItemStack> drops) {
|
||||||
if (callExplosionEvent.getValue().booleanValue()) {
|
if (callExplosionEvent.getValue().booleanValue()) {
|
||||||
BlockExplodeEvent blockExplodeEvent = new BlockExplodeEvent(b, blocks, 0);
|
BlockExplodeEvent blockExplodeEvent = new BlockExplodeEvent(b, blocks, 0);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(blockExplodeEvent);
|
Bukkit.getServer().getPluginManager().callEvent(blockExplodeEvent);
|
||||||
|
@ -24,6 +24,7 @@ import io.github.thebusybiscuit.slimefun4.api.exceptions.IdConflictException;
|
|||||||
import io.github.thebusybiscuit.slimefun4.api.exceptions.IncompatibleItemHandlerException;
|
import io.github.thebusybiscuit.slimefun4.api.exceptions.IncompatibleItemHandlerException;
|
||||||
import io.github.thebusybiscuit.slimefun4.api.exceptions.MissingDependencyException;
|
import io.github.thebusybiscuit.slimefun4.api.exceptions.MissingDependencyException;
|
||||||
import io.github.thebusybiscuit.slimefun4.api.exceptions.UnregisteredItemException;
|
import io.github.thebusybiscuit.slimefun4.api.exceptions.UnregisteredItemException;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.api.exceptions.WrongItemStackException;
|
||||||
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
|
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
|
||||||
import io.github.thebusybiscuit.slimefun4.api.items.ItemState;
|
import io.github.thebusybiscuit.slimefun4.api.items.ItemState;
|
||||||
import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent;
|
import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent;
|
||||||
@ -409,6 +410,10 @@ public class SlimefunItem implements Placeable {
|
|||||||
state = ItemState.DISABLED;
|
state = ItemState.DISABLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (item instanceof SlimefunItemStack && isItemStackImmutable()) {
|
||||||
|
((SlimefunItemStack) item).lock();
|
||||||
|
}
|
||||||
|
|
||||||
postRegister();
|
postRegister();
|
||||||
|
|
||||||
if (SlimefunPlugin.getRegistry().isAutoLoadingEnabled() && state == ItemState.ENABLED) {
|
if (SlimefunPlugin.getRegistry().isAutoLoadingEnabled() && state == ItemState.ENABLED) {
|
||||||
@ -442,6 +447,20 @@ public class SlimefunItem implements Placeable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method returns whether the original {@link SlimefunItemStack} of this
|
||||||
|
* {@link SlimefunItem} is immutable.
|
||||||
|
*
|
||||||
|
* If <code>true</code> is returned, then any changes to the original {@link SlimefunItemStack}
|
||||||
|
* will be rejected with a {@link WrongItemStackException}.
|
||||||
|
* This ensures integrity so developers don't accidentally damage the wrong {@link ItemStack}.
|
||||||
|
*
|
||||||
|
* @return Whether the original {@link SlimefunItemStack} is immutable.
|
||||||
|
*/
|
||||||
|
protected boolean isItemStackImmutable() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method checks recursively for all {@link Class} parents to look for any {@link Deprecated}
|
* This method checks recursively for all {@link Class} parents to look for any {@link Deprecated}
|
||||||
* elements.
|
* elements.
|
||||||
|
@ -24,6 +24,7 @@ import io.github.thebusybiscuit.cscorelib2.item.ImmutableItemMeta;
|
|||||||
import io.github.thebusybiscuit.cscorelib2.skull.SkullItem;
|
import io.github.thebusybiscuit.cscorelib2.skull.SkullItem;
|
||||||
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
|
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
|
||||||
import io.github.thebusybiscuit.slimefun4.api.exceptions.PrematureCodeException;
|
import io.github.thebusybiscuit.slimefun4.api.exceptions.PrematureCodeException;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.api.exceptions.WrongItemStackException;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||||
import io.github.thebusybiscuit.slimefun4.utils.HeadTexture;
|
import io.github.thebusybiscuit.slimefun4.utils.HeadTexture;
|
||||||
import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
|
import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
|
||||||
@ -34,6 +35,7 @@ public class SlimefunItemStack extends CustomItem {
|
|||||||
private String id;
|
private String id;
|
||||||
private ImmutableItemMeta immutableMeta;
|
private ImmutableItemMeta immutableMeta;
|
||||||
|
|
||||||
|
private boolean locked = false;
|
||||||
private String texture = null;
|
private String texture = null;
|
||||||
|
|
||||||
public SlimefunItemStack(String id, Material type, String name, String... lore) {
|
public SlimefunItemStack(String id, Material type, String name, String... lore) {
|
||||||
@ -206,11 +208,34 @@ public class SlimefunItemStack extends CustomItem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setItemMeta(ItemMeta meta) {
|
public boolean setItemMeta(ItemMeta meta) {
|
||||||
|
validate();
|
||||||
immutableMeta = new ImmutableItemMeta(meta);
|
immutableMeta = new ImmutableItemMeta(meta);
|
||||||
|
|
||||||
return super.setItemMeta(meta);
|
return super.setItemMeta(meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setType(Material type) {
|
||||||
|
validate();
|
||||||
|
super.setType(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setAmount(int amount) {
|
||||||
|
validate();
|
||||||
|
super.setAmount(amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validate() {
|
||||||
|
if (locked) {
|
||||||
|
throw new WrongItemStackException(id + " is not mutable.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lock() {
|
||||||
|
locked = true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack clone() {
|
public ItemStack clone() {
|
||||||
return new SlimefunItemStack(id, this);
|
return new SlimefunItemStack(id, this);
|
||||||
|
Loading…
Reference in New Issue
Block a user