1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00
This commit is contained in:
TheBusyBiscuit 2020-04-13 17:40:09 +02:00
parent 5842598f8e
commit 6dd02aaf6a
10 changed files with 65 additions and 35 deletions

View File

@ -79,6 +79,7 @@
* Fixed unpermitted items still showing up in the guide if researches are disabled
* Fixed unpermitted items in the book guide triggering the search function
* Fixed #1803
* Fixed #1806
## Release Candidate 10 (28 Mar 2020)

View File

@ -40,7 +40,7 @@ public class CoolerListener implements Listener {
@EventHandler
public void onStarve(FoodLevelChangeEvent e) {
if (cooler.isDisabled()) {
if (cooler == null || cooler.isDisabled()) {
return;
}

View File

@ -29,7 +29,7 @@ public class SeismicAxeListener implements Listener {
@EventHandler
public void onBlockFall(EntityChangeBlockEvent e) {
if (seismicAxe.isDisabled()) {
if (seismicAxe == null || seismicAxe.isDisabled()) {
return;
}

View File

@ -34,7 +34,7 @@ public class VampireBladeListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onDamage(EntityDamageByEntityEvent e) {
if (blade.isDisabled()) {
if (blade == null || blade.isDisabled()) {
return;
}

View File

@ -70,6 +70,16 @@ public class RecipeType implements Keyed {
this.key = new NamespacedKey(SlimefunPlugin.instance, "null");
}
/**
* @deprecated Use the constructor with {@link NamespacedKey} instead
* @param item
* The {@link ItemStack} to use for this {@link RecipeType}
*/
@Deprecated
public RecipeType(ItemStack item) {
this(item, "");
}
public RecipeType(ItemStack item, String machine) {
this.item = item;
this.machine = machine;
@ -99,20 +109,10 @@ public class RecipeType implements Keyed {
}
}
/**
* @deprecated Use the constructor with {@link NamespacedKey} instead
* @param item
* The {@link ItemStack} to use for this {@link RecipeType}
*/
@Deprecated
public RecipeType(ItemStack item) {
this(item, "");
}
public RecipeType(NamespacedKey key, ItemStack item) {
this.key = key;
this.item = item;
this.machine = "";
this.machine = item instanceof SlimefunItemStack ? ((SlimefunItemStack) item).getItemID() : "";
}
public RecipeType(MinecraftRecipe<?> recipe) {

View File

@ -354,6 +354,7 @@ 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);
@ -397,7 +398,6 @@ public class SlimefunItem implements Placeable {
disenchantable = SlimefunPlugin.getItemCfg().getBoolean(id + ".allow-disenchanting");
SlimefunPlugin.getRegistry().getEnabledSlimefunItems().add(this);
SlimefunPlugin.getRegistry().getSlimefunItemIds().put(id, this);
loadItemHandlers();
}
else if (this instanceof VanillaItem) {

View File

@ -5,6 +5,7 @@ import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Chest;
import org.bukkit.block.data.type.Dispenser;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
@ -60,11 +61,20 @@ public abstract class MultiBlockMachine extends SlimefunMachine {
public abstract void onInteract(Player p, Block b);
// Overloaded method for finding a potential output chest. Fallbacks to the old system of putting the adding back
// into the dispenser.
// Optional last argument Inventory placeCheckerInv is for multiblock machines that create a dummy inventory to
// check if there's a space for the adding,
// i.e. Enhanced crafting table
/**
* Overloaded method for finding a potential output chest.
* Fallbacks to the old system of putting the adding back into the dispenser.
* Optional last argument Inventory placeCheckerInv is for a {@link MultiBlockMachine} that create
* a dummy inventory to check if there's a space for the adding, i.e. Enhanced crafting table
*
* @param adding
* The {@link ItemStack} that should be added
* @param dispBlock
* The {@link Block} of our {@link Dispenser}
* @param dispInv
* The {@link Inventory} of our {@link Dispenser}
* @return The target {@link Inventory}
*/
protected Inventory findOutputInventory(ItemStack adding, Block dispBlock, Inventory dispInv) {
return findOutputInventory(adding, dispBlock, dispInv, dispInv);
}

View File

@ -22,8 +22,12 @@ public abstract class BlockTicker implements ItemHandler {
@Override
public Optional<IncompatibleItemHandlerException> validate(SlimefunItem item) {
if (item instanceof NotPlaceable || !item.getItem().getType().isBlock()) {
return Optional.of(new IncompatibleItemHandlerException("Only blocks that are not marked as 'NotPlaceable' can have a BlockTicker.", item, this));
if (!item.getItem().getType().isBlock()) {
return Optional.of(new IncompatibleItemHandlerException("Only Materials that are blocks can have a BlockTicker.", item, this));
}
if (item instanceof NotPlaceable) {
return Optional.of(new IncompatibleItemHandlerException("Only Slimefun items that are not marked as 'NotPlaceable' can have a BlockTicker.", item, this));
}
return Optional.empty();

View File

@ -1,9 +1,14 @@
package me.mrCookieSlime.Slimefun.Objects.handlers;
import java.util.Optional;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import io.github.thebusybiscuit.slimefun4.api.exceptions.IncompatibleItemHandlerException;
import io.github.thebusybiscuit.slimefun4.core.MultiBlock;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunMachine;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.multiblocks.MultiBlockMachine;
/**
@ -24,6 +29,16 @@ public interface MultiBlockInteractionHandler extends ItemHandler {
boolean onInteract(Player p, MultiBlock mb, Block b);
@Override
default Optional<IncompatibleItemHandlerException> validate(SlimefunItem item) {
// Change this to "MultiBlockMachine" once SlimefunMachine was removed or deprecated
if (!(item instanceof SlimefunMachine)) {
return Optional.of(new IncompatibleItemHandlerException("Only class inheriting 'MultiBlockMachine' can have a MultiBlockInteractionHandler", item, this));
}
return Optional.empty();
}
@Override
default Class<? extends ItemHandler> getIdentifier() {
return MultiBlockInteractionHandler.class;

View File

@ -91,7 +91,7 @@ public class BlockStorage {
return;
}
Slimefun.getLogger().log(Level.INFO, "Loading Blocks for World \"" + w.getName() + "\"");
Slimefun.getLogger().log(Level.INFO, "Loading Blocks for World \"{0}\"", w.getName());
Slimefun.getLogger().log(Level.INFO, "This may take a long time...");
File dir = new File(PATH_BLOCKS + w.getName());
@ -135,9 +135,8 @@ public class BlockStorage {
// It should not be possible to have two blocks on the same location. Ignore the
// new entry if a block is already present and print an error to the console.
Slimefun.getLogger().log(Level.INFO, "Ignoring duplicate block @ " + l.getBlockX() + ", " + l.getBlockY() + ", " + l.getBlockZ());
Slimefun.getLogger().log(Level.INFO, "Old block data: {0}", serializeBlockInfo(storage.get(l)));
Slimefun.getLogger().log(Level.INFO, "New block data ({0}): {1}", new Object[] { key, json });
Slimefun.getLogger().log(Level.INFO, "Ignoring duplicate block @ {0}, {1}, {2}", new Object[] { l.getBlockX(), l.getBlockY(), l.getBlockZ() });
Slimefun.getLogger().log(Level.INFO, "New: {0} | Old: {1}", new Object[] { key, serializeBlockInfo(storage.get(l)) });
continue;
}
@ -155,7 +154,7 @@ public class BlockStorage {
}
}
catch (Exception x) {
Slimefun.getLogger().log(Level.WARNING, "Failed to load " + file.getName() + '(' + key + ") for Slimefun " + SlimefunPlugin.getVersion(), x);
Slimefun.getLogger().log(Level.WARNING, x, () -> "Failed to load " + file.getName() + '(' + key + ") for Slimefun " + SlimefunPlugin.getVersion());
}
}
done++;
@ -188,7 +187,7 @@ public class BlockStorage {
}
}
catch (Exception x) {
Slimefun.getLogger().log(Level.WARNING, "Failed to load " + chunks.getName() + " in World " + world.getName() + '(' + key + ") for Slimefun " + SlimefunPlugin.getVersion(), x);
Slimefun.getLogger().log(Level.WARNING, x, () -> "Failed to load " + chunks.getName() + " in World " + world.getName() + '(' + key + ") for Slimefun " + SlimefunPlugin.getVersion());
}
}
}
@ -212,7 +211,7 @@ public class BlockStorage {
}
}
catch (Exception x) {
Slimefun.getLogger().log(Level.SEVERE, "An Error occured while loading this Inventory: " + file.getName(), x);
Slimefun.getLogger().log(Level.SEVERE, x, () -> "An Error occured while loading this Inventory: " + file.getName());
}
}
}
@ -258,7 +257,7 @@ public class BlockStorage {
if (computeChanges) computeChanges();
if (changes == 0) return;
Slimefun.getLogger().log(Level.INFO, "Saving Blocks for World \"" + world.getName() + "\" (" + changes + " Change(s) queued)");
Slimefun.getLogger().log(Level.INFO, "Saving Blocks for World \"{0}\" ({1} Change(s) queued)", new Object[] { world.getName(), changes });
Map<String, Config> cache = new HashMap<>(blocksCache);
@ -268,8 +267,9 @@ public class BlockStorage {
if (cfg.getKeys().isEmpty()) {
File file = cfg.getFile();
if (file.exists() && !file.delete()) {
Slimefun.getLogger().log(Level.WARNING, "Could not delete File: " + file.getName());
Slimefun.getLogger().log(Level.WARNING, "Could not delete File: {0}", file.getName());
}
}
else {
@ -280,7 +280,7 @@ public class BlockStorage {
Files.move(tmpFile.toPath(), cfg.getFile().toPath(), StandardCopyOption.ATOMIC_MOVE);
}
catch (IOException x) {
Slimefun.getLogger().log(Level.SEVERE, "An Error occured while copying a temporary File for Slimefun " + SlimefunPlugin.getVersion(), x);
Slimefun.getLogger().log(Level.SEVERE, x, () -> "An Error occured while copying a temporary File for Slimefun " + SlimefunPlugin.getVersion());
}
}
}
@ -373,12 +373,12 @@ public class BlockStorage {
catch (Exception x) {
Logger logger = Slimefun.getLogger();
logger.log(Level.WARNING, x.getClass().getName());
logger.log(Level.WARNING, "Failed to parse BlockInfo for Block @ " + l.getBlockX() + ", " + l.getBlockY() + ", " + l.getBlockZ());
logger.log(Level.WARNING, "Failed to parse BlockInfo for Block @ {0}, {1}, {2}", new Object[] { l.getBlockX(), l.getBlockY(), l.getBlockZ() });
logger.log(Level.WARNING, json);
logger.log(Level.WARNING, "");
logger.log(Level.WARNING, "IGNORE THIS ERROR UNLESS IT IS SPAMMING");
logger.log(Level.WARNING, "");
logger.log(Level.SEVERE, "An Error occured while parsing Block Info for Slimefun " + SlimefunPlugin.getVersion(), x);
logger.log(Level.SEVERE, x, () -> "An Error occured while parsing Block Info for Slimefun " + SlimefunPlugin.getVersion());
return null;
}
}
@ -697,7 +697,7 @@ public class BlockStorage {
return cfg == null ? new BlockInfoConfig() : cfg;
}
catch (Exception e) {
Slimefun.getLogger().log(Level.SEVERE, "Failed to parse ChunkInfo for Slimefun " + SlimefunPlugin.getVersion(), x);
Slimefun.getLogger().log(Level.SEVERE, e, () -> "Failed to parse ChunkInfo for Slimefun " + SlimefunPlugin.getVersion());
return new BlockInfoConfig();
}
}