mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Merge branch 'master' of https://github.com/TheBusyBiscuit/Slimefun4
into experimental Conflicts: src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java
This commit is contained in:
commit
9426ebb2e9
31
CHANGELOG.md
31
CHANGELOG.md
@ -35,22 +35,34 @@
|
||||
* Added Clay -> Clay blocks recipe to the Electric Press
|
||||
* (1.16+) Slimefun guide can now show Smithing Table recipes
|
||||
* (1.16+) Added Nether Gold Ore recipe to the Ore Crusher
|
||||
* (1.16+) Added Gilded Blackstone recipe to the Ore Crusher
|
||||
* (1.16+) Added Shroomlights to the fuel list for the Bio Generator
|
||||
* (1.16+) Added Warped and Crimson Fungus to the fuel list for the Bio Generator
|
||||
* Added an AoE damage effect to the Explosive Bow
|
||||
* Added runtime deprecation warnings for ItemHandlers and Attributes used by Addons
|
||||
* Added a proper lag profiler
|
||||
* Added per-plugin lag info to /sf timings
|
||||
|
||||
#### Changes
|
||||
* Coolant Cells now last twice as long
|
||||
* Ticking blocks will now catch more errors caused by addons
|
||||
* Massive performance improvements to GPS/GEO machines, especially Oil Pump and GEO Miner
|
||||
* Changed the texture for the Nuclear Reactor
|
||||
* Changed the texture for the Nether Star Reactor
|
||||
* Performance improvements to Rainbow Blocks
|
||||
* Crafting Tin cans now produces 8 items instead of 4
|
||||
* Multi Tool lore now says "Crouch" instead of "Hold Shift"
|
||||
* items which cannot be distributed by a Cargo Net will be dropped on the ground now instead of getting deleted
|
||||
* Small performance improvements to the Cargo Net
|
||||
* Items which cannot be distributed by a Cargo Net will be dropped on the ground now instead of getting deleted
|
||||
* Slimefun no longer supports CraftBukkit
|
||||
* Item Energy is now also stored persistently via NBT
|
||||
* Performance improvements to GPS/GEO machines, especially Oil Pump and GEO Miner
|
||||
* Performance improvements for ticking blocks
|
||||
* Performance improvements to the Cargo Net
|
||||
* performance improvements to the Energy Net
|
||||
* Performance improvements to Rainbow Blocks
|
||||
* Performance improvements to Androids
|
||||
* performance improvements to Generators and Electric Machines
|
||||
* Cargo timings will now be attributed to the corresponding node and not the Cargo manager
|
||||
* Thunderstorms now count as night time for Solar Generators
|
||||
* Fixed an issue with moving androids getting stuck
|
||||
|
||||
#### Fixes
|
||||
* Fixed #2005
|
||||
@ -64,6 +76,17 @@
|
||||
* Fixed a rare concurrency issue with world saving
|
||||
* Fixed some contributors showing up twice
|
||||
* Fixed #2062
|
||||
* Fixed Grappling hooks disappearing when fired at Item frames or paintaings
|
||||
* Fixed Grappling hooks not getting removed when the Player leaves
|
||||
* Fixed Grappling hooks making Bat sounds
|
||||
* Fixed #1959
|
||||
* Fixed Melon Juice requiring Melons instead of Melon Slices
|
||||
* Fixed Cargo networks not showing up in /sf timings
|
||||
* Fixed /sf timings reporting slightly inaccurate timings
|
||||
* Fixed concurrency-related issues with the profiling
|
||||
* Fixed #2066
|
||||
* Fixed Rainbow Glass Panes not properly connecting to blocks
|
||||
* Fixed Androids turning in the wrong direction
|
||||
|
||||
## Release Candidate 13 (16 Jun 2020)
|
||||
https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#13
|
||||
|
@ -2,8 +2,8 @@ package io.github.thebusybiscuit.slimefun4.api.exceptions;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler;
|
||||
|
||||
/**
|
||||
|
@ -8,6 +8,7 @@ import java.util.Set;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Particle.DustOptions;
|
||||
|
||||
@ -26,6 +27,34 @@ import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
*/
|
||||
public abstract class Network {
|
||||
|
||||
private final NetworkManager manager;
|
||||
protected Location regulator;
|
||||
private Queue<Location> nodeQueue = new ArrayDeque<>();
|
||||
|
||||
protected final Set<Location> connectedLocations = new HashSet<>();
|
||||
protected final Set<Location> regulatorNodes = new HashSet<>();
|
||||
protected final Set<Location> connectorNodes = new HashSet<>();
|
||||
protected final Set<Location> terminusNodes = new HashSet<>();
|
||||
|
||||
/**
|
||||
* This constructs a new {@link Network} at the given {@link Location}.
|
||||
*
|
||||
* @param manager
|
||||
* The {@link NetworkManager} instance
|
||||
* @param regulator
|
||||
* The {@link Location} marking the regulator of this {@link Network}.
|
||||
*/
|
||||
protected Network(NetworkManager manager, Location regulator) {
|
||||
Validate.notNull(manager, "A NetworkManager must be provided");
|
||||
Validate.notNull(regulator, "No regulator was specified");
|
||||
|
||||
this.manager = manager;
|
||||
this.regulator = regulator;
|
||||
|
||||
connectedLocations.add(regulator);
|
||||
nodeQueue.add(regulator.clone());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the range of the {@link Network}.
|
||||
* The range determines how far the {@link Network} will search for
|
||||
@ -60,34 +89,6 @@ public abstract class Network {
|
||||
*/
|
||||
public abstract void onClassificationChange(Location l, NetworkComponent from, NetworkComponent to);
|
||||
|
||||
protected Location regulator;
|
||||
private Queue<Location> nodeQueue = new ArrayDeque<>();
|
||||
|
||||
private final NetworkManager manager;
|
||||
protected final Set<Location> connectedLocations = new HashSet<>();
|
||||
protected final Set<Location> regulatorNodes = new HashSet<>();
|
||||
protected final Set<Location> connectorNodes = new HashSet<>();
|
||||
protected final Set<Location> terminusNodes = new HashSet<>();
|
||||
|
||||
/**
|
||||
* This constructs a new {@link Network} at the given {@link Location}.
|
||||
*
|
||||
* @param manager
|
||||
* The {@link NetworkManager} instance
|
||||
* @param regulator
|
||||
* The {@link Location} marking the regulator of this {@link Network}.
|
||||
*/
|
||||
protected Network(NetworkManager manager, Location regulator) {
|
||||
Validate.notNull(manager, "A NetworkManager must be provided");
|
||||
Validate.notNull(regulator, "No regulator was specified");
|
||||
|
||||
this.manager = manager;
|
||||
this.regulator = regulator;
|
||||
|
||||
connectedLocations.add(regulator);
|
||||
nodeQueue.add(regulator.clone());
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns the size of this {@link Network}. It is equivalent to the amount
|
||||
* of {@link Location Locations} connected to this {@link Network}.
|
||||
@ -208,14 +209,18 @@ public abstract class Network {
|
||||
|
||||
/**
|
||||
* This method runs the network visualizer which displays a {@link Particle} on
|
||||
* every {@link Location} that this {@link Network} can connect to.
|
||||
* every {@link Location} that this {@link Network} is connected to.
|
||||
*/
|
||||
public void display() {
|
||||
Slimefun.runSync(() -> {
|
||||
DustOptions options = new DustOptions(Color.BLUE, 2F);
|
||||
DustOptions options = new DustOptions(Color.BLUE, 3F);
|
||||
|
||||
for (Location l : connectedLocations) {
|
||||
l.getWorld().spawnParticle(Particle.REDSTONE, l.getX() + 0.5, l.getY() + 0.5, l.getZ() + 0.5, 1, 0, 0, 0, 1, options);
|
||||
Material type = l.getBlock().getType();
|
||||
|
||||
if (type == Material.PLAYER_HEAD || type == Material.PLAYER_WALL_HEAD) {
|
||||
l.getWorld().spawnParticle(Particle.REDSTONE, l.getX() + 0.5, l.getY() + 0.5, l.getZ() + 0.5, 1, 0, 0, 0, 1, options);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.collections.KeyMap;
|
||||
import io.github.thebusybiscuit.cscorelib2.config.Config;
|
||||
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
|
||||
import io.github.thebusybiscuit.slimefun4.api.geo.GEOResource;
|
||||
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.WitherProof;
|
||||
@ -25,6 +26,7 @@ import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideImplementation
|
||||
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout;
|
||||
import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlock;
|
||||
import io.github.thebusybiscuit.slimefun4.core.researching.Research;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.guide.BookSlimefunGuide;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.guide.CheatSheetSlimefunGuide;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.guide.ChestSlimefunGuide;
|
||||
@ -99,7 +101,7 @@ public class SlimefunRegistry {
|
||||
|
||||
researchRanks.addAll(cfg.getStringList("research-ranks"));
|
||||
|
||||
backwardsCompatibility = cfg.getBoolean("options.backwards-compatibility");
|
||||
backwardsCompatibility = cfg.getBoolean("options.backwards-compatibility") || SlimefunPlugin.getMinecraftVersion().isBefore(MinecraftVersion.MINECRAFT_1_14);
|
||||
freeCreativeResearches = cfg.getBoolean("researches.free-in-creative-mode");
|
||||
researchFireworks = cfg.getBoolean("researches.enable-fireworks");
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
@ -26,7 +27,8 @@ import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
|
||||
final class RechargeableHelper {
|
||||
|
||||
private static final NamespacedKey CHARGE_KEY = new NamespacedKey(SlimefunPlugin.instance, "item_charge");
|
||||
private static final String LORE_PREFIX = ChatColors.color("&c&o&8\u21E8 &e\u26A1 &7");
|
||||
private static final String LORE_PREFIX = ChatColors.color("&8\u21E8 &e\u26A1 &7");
|
||||
private static final Pattern REGEX = Pattern.compile(ChatColors.color("(&c&o)?" + LORE_PREFIX) + "[0-9\\.]+ \\/ [0-9\\.]+ J");
|
||||
|
||||
private RechargeableHelper() {}
|
||||
|
||||
@ -42,7 +44,7 @@ final class RechargeableHelper {
|
||||
for (int i = 0; i < lore.size(); i++) {
|
||||
String line = lore.get(i);
|
||||
|
||||
if (line.startsWith(LORE_PREFIX)) {
|
||||
if (REGEX.matcher(line).matches()) {
|
||||
lore.set(i, LORE_PREFIX + value + " / " + capacity + " J");
|
||||
meta.setLore(lore);
|
||||
return;
|
||||
@ -66,7 +68,7 @@ final class RechargeableHelper {
|
||||
// If no persistent data exists, we will just fall back to the lore
|
||||
if (meta.hasLore()) {
|
||||
for (String line : meta.getLore()) {
|
||||
if (line.startsWith(LORE_PREFIX) && line.contains(" / ") && line.endsWith(" J")) {
|
||||
if (REGEX.matcher(line).matches()) {
|
||||
return Float.parseFloat(PatternUtils.SLASH_SEPARATOR.split(line)[0].replace(LORE_PREFIX, ""));
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,8 @@ class TimingsCommand extends SubCommand {
|
||||
@Override
|
||||
public void onExecute(CommandSender sender, String[] args) {
|
||||
if (sender.hasPermission("slimefun.command.timings") || sender instanceof ConsoleCommandSender) {
|
||||
SlimefunPlugin.getTickerTask().info(sender);
|
||||
sender.sendMessage("Please wait a second... The results are coming in!");
|
||||
SlimefunPlugin.getProfiler().requestSummary(sender);
|
||||
}
|
||||
else {
|
||||
SlimefunPlugin.getLocalization().sendMessage(sender, "messages.no-permission", true);
|
||||
|
@ -0,0 +1,19 @@
|
||||
package io.github.thebusybiscuit.slimefun4.core.handlers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface BlockBreakHandler extends ItemHandler {
|
||||
|
||||
boolean onBlockBreak(BlockBreakEvent e, ItemStack item, int fortune, List<ItemStack> drops);
|
||||
|
||||
@Override
|
||||
default Class<? extends ItemHandler> getIdentifier() {
|
||||
return BlockBreakHandler.class;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package me.mrCookieSlime.Slimefun.Objects.handlers;
|
||||
package io.github.thebusybiscuit.slimefun4.core.handlers;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@ -11,6 +11,7 @@ import io.github.thebusybiscuit.slimefun4.api.exceptions.IncompatibleItemHandler
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.BlockPlacer;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler;
|
||||
|
||||
/**
|
||||
* This {@link ItemHandler} is triggered when the {@link SlimefunItem} it was assigned to
|
@ -1,12 +1,15 @@
|
||||
package me.mrCookieSlime.Slimefun.Objects.handlers;
|
||||
package io.github.thebusybiscuit.slimefun4.core.handlers;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface BlockPlaceHandler extends ItemHandler {
|
||||
|
||||
boolean onBlockPlace(BlockPlaceEvent e, ItemStack item);
|
||||
boolean onBlockPlace(Player p, BlockPlaceEvent e, ItemStack item);
|
||||
|
||||
@Override
|
||||
default Class<? extends ItemHandler> getIdentifier() {
|
@ -1,4 +1,4 @@
|
||||
package me.mrCookieSlime.Slimefun.Objects.handlers;
|
||||
package io.github.thebusybiscuit.slimefun4.core.handlers;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@ -6,6 +6,7 @@ import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent;
|
||||
import io.github.thebusybiscuit.slimefun4.api.exceptions.IncompatibleItemHandlerException;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface BlockUseHandler extends ItemHandler {
|
@ -1,4 +1,4 @@
|
||||
package me.mrCookieSlime.Slimefun.Objects.handlers;
|
||||
package io.github.thebusybiscuit.slimefun4.core.handlers;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@ -9,6 +9,7 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import io.github.thebusybiscuit.slimefun4.api.exceptions.IncompatibleItemHandlerException;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.SlimefunBow;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler;
|
||||
|
||||
/**
|
||||
* This {@link ItemHandler} is triggered when the {@link SlimefunItem} it was assigned to
|
@ -1,4 +1,4 @@
|
||||
package me.mrCookieSlime.Slimefun.Objects.handlers;
|
||||
package io.github.thebusybiscuit.slimefun4.core.handlers;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -8,6 +8,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler;
|
||||
|
||||
/**
|
||||
* This is triggered when a {@link Player} interacts with an {@link Entity}.
|
@ -1,4 +1,4 @@
|
||||
package me.mrCookieSlime.Slimefun.Objects.handlers;
|
||||
package io.github.thebusybiscuit.slimefun4.core.handlers;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -7,6 +7,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler;
|
||||
|
||||
/**
|
||||
* If this {@link ItemHandler} is added to a {@link SlimefunItem} it will listen
|
@ -1,4 +1,4 @@
|
||||
package me.mrCookieSlime.Slimefun.Objects.handlers;
|
||||
package io.github.thebusybiscuit.slimefun4.core.handlers;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerItemConsumeEvent;
|
||||
@ -8,6 +8,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.food.DietCookie;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.food.FortuneCookie;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler;
|
||||
|
||||
/**
|
||||
* This {@link ItemHandler} is triggered when the {@link SlimefunItem} it was assigned to
|
@ -1,9 +1,11 @@
|
||||
package me.mrCookieSlime.Slimefun.Objects.handlers;
|
||||
package io.github.thebusybiscuit.slimefun4.core.handlers;
|
||||
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ItemDropHandler extends ItemHandler {
|
||||
|
@ -0,0 +1,37 @@
|
||||
package io.github.thebusybiscuit.slimefun4.core.handlers;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler;
|
||||
|
||||
/**
|
||||
* This {@link ItemHandler} is triggered when the {@link SlimefunItem} it was assigned to
|
||||
* is right-clicked.
|
||||
*
|
||||
* @author TheBusyBiscuit
|
||||
*
|
||||
* @see ItemHandler
|
||||
* @see SimpleSlimefunItem
|
||||
*
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface ItemUseHandler extends ItemHandler {
|
||||
|
||||
/**
|
||||
* This function is triggered when a {@link Player} right clicks with the assigned {@link SlimefunItem}
|
||||
* in his hand.
|
||||
*
|
||||
* @param e
|
||||
* The {@link PlayerRightClickEvent} that was triggered
|
||||
*/
|
||||
void onRightClick(PlayerRightClickEvent e);
|
||||
|
||||
@Override
|
||||
default Class<? extends ItemHandler> getIdentifier() {
|
||||
return ItemUseHandler.class;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package io.github.thebusybiscuit.slimefun4.core.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.multiblocks.MultiBlock;
|
||||
import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlockMachine;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler;
|
||||
|
||||
/**
|
||||
* This {@link ItemHandler} is called whenever a {@link Player} interacts with
|
||||
* this {@link MultiBlock}.
|
||||
* Note that this {@link MultiBlockInteractionHandler} should be assigned to
|
||||
* a class that inherits from {@link MultiBlockMachine}.
|
||||
*
|
||||
* @author TheBusyBiscuit
|
||||
*
|
||||
* @see ItemHandler
|
||||
* @see MultiBlock
|
||||
* @see MultiBlockMachine
|
||||
*
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface MultiBlockInteractionHandler extends ItemHandler {
|
||||
|
||||
boolean onInteract(Player p, MultiBlock mb, Block b);
|
||||
|
||||
@Override
|
||||
default Optional<IncompatibleItemHandlerException> validate(SlimefunItem item) {
|
||||
if (!(item instanceof MultiBlockMachine)) {
|
||||
return Optional.of(new IncompatibleItemHandlerException("Only classes inheriting 'MultiBlockMachine' can have a MultiBlockInteractionHandler", item, this));
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
default Class<? extends ItemHandler> getIdentifier() {
|
||||
return MultiBlockInteractionHandler.class;
|
||||
}
|
||||
}
|
@ -1,11 +1,13 @@
|
||||
package me.mrCookieSlime.Slimefun.Objects.handlers;
|
||||
package io.github.thebusybiscuit.slimefun4.core.handlers;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Waterlogged;
|
||||
import org.bukkit.block.data.type.GlassPane;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.collections.LoopIterator;
|
||||
import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollection;
|
||||
@ -14,6 +16,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.RainbowBlock;
|
||||
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
|
||||
|
||||
/**
|
||||
* This is a {@link BlockTicker} that is exclusively used for Rainbow blocks.
|
||||
@ -25,34 +28,36 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
* @see RainbowBlock
|
||||
*
|
||||
*/
|
||||
public class RainbowTicker extends BlockTicker {
|
||||
public class RainbowTickHandler extends BlockTicker {
|
||||
|
||||
private final LoopIterator<Material> iterator;
|
||||
private final boolean waterlogged;
|
||||
private final boolean glassPanes;
|
||||
private Material material;
|
||||
|
||||
public RainbowTicker(Material... materials) {
|
||||
public RainbowTickHandler(Material... materials) {
|
||||
Validate.noNullElements(materials, "A RainbowTicker cannot have a Material that is null!");
|
||||
|
||||
if (materials.length == 0) {
|
||||
throw new IllegalArgumentException("A RainbowTicker must have at least one Material associated with it!");
|
||||
}
|
||||
|
||||
waterlogged = containsWaterlogged(materials);
|
||||
glassPanes = containsGlassPanes(materials);
|
||||
iterator = new LoopIterator<>(Arrays.asList(materials));
|
||||
material = iterator.next();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method checks whether a given {@link Material} array contains any {@link Material}
|
||||
* that would result in a {@link Waterlogged} {@link BlockData}.
|
||||
* that would result in a {@link GlassPane} {@link BlockData}.
|
||||
* This is done to save performance, so we don't have to validate {@link BlockData} at
|
||||
* runtime.
|
||||
*
|
||||
* @param materials
|
||||
* The {@link Material} Array to check
|
||||
*
|
||||
* @return Whether the array contained any {@link Waterlogged} materials
|
||||
* @return Whether the array contained any {@link GlassPane} materials
|
||||
*/
|
||||
private boolean containsWaterlogged(Material[] materials) {
|
||||
private boolean containsGlassPanes(Material[] materials) {
|
||||
if (SlimefunPlugin.getMinecraftVersion() == MinecraftVersion.UNIT_TEST) {
|
||||
// BlockData is not available to us during Unit Tests :/
|
||||
return false;
|
||||
@ -61,8 +66,8 @@ public class RainbowTicker extends BlockTicker {
|
||||
for (Material type : materials) {
|
||||
// This BlockData is purely virtual and only created on startup, it should have
|
||||
// no impact on performance, in fact it should save performance as it preloads
|
||||
// the data but also saves heavy calls for non-waterlogged Materials
|
||||
if (type.createBlockData() instanceof Waterlogged) {
|
||||
// the data but also saves heavy calls for other Materials
|
||||
if (type.createBlockData() instanceof GlassPane) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -70,7 +75,7 @@ public class RainbowTicker extends BlockTicker {
|
||||
return false;
|
||||
}
|
||||
|
||||
public RainbowTicker(MaterialCollection collection) {
|
||||
public RainbowTickHandler(MaterialCollection collection) {
|
||||
this(collection.getAsArray());
|
||||
}
|
||||
|
||||
@ -82,20 +87,29 @@ public class RainbowTicker extends BlockTicker {
|
||||
return;
|
||||
}
|
||||
|
||||
if (waterlogged) {
|
||||
if (glassPanes) {
|
||||
BlockData blockData = b.getBlockData();
|
||||
|
||||
b.setType(material, true);
|
||||
if (blockData instanceof GlassPane) {
|
||||
BlockData block = material.createBlockData(bd -> {
|
||||
if (bd instanceof GlassPane) {
|
||||
GlassPane previousData = (GlassPane) blockData;
|
||||
GlassPane nextData = (GlassPane) bd;
|
||||
|
||||
nextData.setWaterlogged(previousData.isWaterlogged());
|
||||
|
||||
for (BlockFace face : previousData.getAllowedFaces()) {
|
||||
nextData.setFace(face, previousData.hasFace(face));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (blockData instanceof Waterlogged && ((Waterlogged) blockData).isWaterlogged()) {
|
||||
Waterlogged block = (Waterlogged) b.getBlockData();
|
||||
block.setWaterlogged(true);
|
||||
b.setBlockData(block);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
b.setType(material, false);
|
||||
}
|
||||
|
||||
b.setType(material, false);
|
||||
}
|
||||
|
||||
@Override
|
@ -0,0 +1,5 @@
|
||||
/**
|
||||
* This package contains all variations of {@link me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler} that
|
||||
* can be assigned to a {@link me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem}
|
||||
*/
|
||||
package io.github.thebusybiscuit.slimefun4.core.handlers;
|
@ -13,9 +13,9 @@ import org.bukkit.block.BlockFace;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
|
||||
import io.github.thebusybiscuit.slimefun4.api.events.MultiBlockInteractEvent;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.MultiBlockInteractionHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.MultiBlockInteractionHandler;
|
||||
|
||||
/**
|
||||
* A {@link MultiBlock} represents a structure build in a {@link World}.
|
||||
|
@ -20,11 +20,11 @@ import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
|
||||
import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.MultiBlockInteractionHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.MultiBlockInteractionHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
@ -8,17 +8,17 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.api.network.Network;
|
||||
import io.github.thebusybiscuit.slimefun4.api.network.NetworkComponent;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.holograms.SimpleHologram;
|
||||
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
|
||||
@ -111,6 +111,8 @@ public class CargoNet extends ChestTerminalNetwork {
|
||||
|
||||
@Override
|
||||
public void onClassificationChange(Location l, NetworkComponent from, NetworkComponent to) {
|
||||
connectorCache.remove(l);
|
||||
|
||||
if (from == NetworkComponent.TERMINUS) {
|
||||
inputNodes.remove(l);
|
||||
outputNodes.remove(l);
|
||||
@ -120,7 +122,8 @@ public class CargoNet extends ChestTerminalNetwork {
|
||||
}
|
||||
|
||||
if (to == NetworkComponent.TERMINUS) {
|
||||
switch (BlockStorage.checkID(l)) {
|
||||
String id = BlockStorage.checkID(l);
|
||||
switch (id) {
|
||||
case "CARGO_NODE_INPUT":
|
||||
inputNodes.add(l);
|
||||
break;
|
||||
@ -156,28 +159,63 @@ public class CargoNet extends ChestTerminalNetwork {
|
||||
}
|
||||
else {
|
||||
SimpleHologram.update(b, "&7Status: &a&lONLINE");
|
||||
Map<Integer, List<Location>> output = mapOutputNodes();
|
||||
|
||||
// Chest Terminal Stuff
|
||||
Set<Location> destinations = new HashSet<>();
|
||||
List<Location> output16 = output.get(16);
|
||||
|
||||
if (output16 != null) {
|
||||
destinations.addAll(output16);
|
||||
// Skip ticking if the threshold is not reached. The delay is not same as minecraft tick,
|
||||
// but it's based on 'custom-ticker-delay' config.
|
||||
if (tickDelayThreshold < TICK_DELAY) {
|
||||
tickDelayThreshold++;
|
||||
return;
|
||||
}
|
||||
|
||||
Slimefun.runSync(() -> run(b, destinations, output));
|
||||
// Reset the internal threshold, so we can start skipping again
|
||||
tickDelayThreshold = 0;
|
||||
|
||||
// Chest Terminal Stuff
|
||||
Set<Location> chestTerminalInputs = new HashSet<>();
|
||||
Set<Location> chestTerminalOutputs = new HashSet<>();
|
||||
|
||||
Map<Location, Integer> inputs = mapInputNodes(chestTerminalInputs);
|
||||
Map<Integer, List<Location>> outputs = mapOutputNodes(chestTerminalOutputs);
|
||||
|
||||
if (BlockStorage.getLocationInfo(b.getLocation(), "visualizer") == null) {
|
||||
display();
|
||||
}
|
||||
|
||||
SlimefunPlugin.getProfiler().scheduleEntries(1 + inputNodes.size());
|
||||
Slimefun.runSync(() -> run(inputs, outputs, chestTerminalInputs, chestTerminalOutputs));
|
||||
}
|
||||
}
|
||||
|
||||
private Map<Integer, List<Location>> mapOutputNodes() {
|
||||
private Map<Location, Integer> mapInputNodes(Set<Location> chestTerminalNodes) {
|
||||
Map<Location, Integer> inputs = new HashMap<>();
|
||||
|
||||
for (Location node : inputNodes) {
|
||||
int frequency = getFrequency(node);
|
||||
|
||||
if (frequency == 16) {
|
||||
chestTerminalNodes.add(node);
|
||||
}
|
||||
else if (frequency >= 0 && frequency < 16) {
|
||||
inputs.put(node, frequency);
|
||||
}
|
||||
}
|
||||
|
||||
return inputs;
|
||||
}
|
||||
|
||||
private Map<Integer, List<Location>> mapOutputNodes(Set<Location> chestTerminalOutputs) {
|
||||
Map<Integer, List<Location>> output = new HashMap<>();
|
||||
|
||||
List<Location> list = new LinkedList<>();
|
||||
int lastFrequency = -1;
|
||||
|
||||
for (Location outputNode : outputNodes) {
|
||||
int frequency = getFrequency(outputNode);
|
||||
for (Location node : outputNodes) {
|
||||
int frequency = getFrequency(node);
|
||||
|
||||
if (frequency == 16) {
|
||||
chestTerminalOutputs.add(node);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (frequency != lastFrequency && lastFrequency != -1) {
|
||||
output.merge(lastFrequency, list, (prev, next) -> {
|
||||
@ -188,7 +226,7 @@ public class CargoNet extends ChestTerminalNetwork {
|
||||
list = new LinkedList<>();
|
||||
}
|
||||
|
||||
list.add(outputNode);
|
||||
list.add(node);
|
||||
lastFrequency = frequency;
|
||||
}
|
||||
|
||||
@ -202,59 +240,42 @@ public class CargoNet extends ChestTerminalNetwork {
|
||||
return output;
|
||||
}
|
||||
|
||||
private void run(Block b, Set<Location> destinations, Map<Integer, List<Location>> output) {
|
||||
if (BlockStorage.getLocationInfo(b.getLocation(), "visualizer") == null) {
|
||||
display();
|
||||
}
|
||||
|
||||
// Skip ticking if the threshold is not reached. The delay is not same as minecraft tick,
|
||||
// but it's based on 'custom-ticker-delay' config.
|
||||
if (tickDelayThreshold < TICK_DELAY) {
|
||||
tickDelayThreshold++;
|
||||
return;
|
||||
}
|
||||
|
||||
// Reset the internal threshold, so we can start skipping again
|
||||
tickDelayThreshold = 0;
|
||||
|
||||
Map<Location, Integer> inputs = new HashMap<>();
|
||||
Set<Location> providers = new HashSet<>();
|
||||
|
||||
for (Location node : inputNodes) {
|
||||
int frequency = getFrequency(node);
|
||||
|
||||
if (frequency == 16) {
|
||||
providers.add(node);
|
||||
}
|
||||
else if (frequency >= 0 && frequency < 16) {
|
||||
inputs.put(node, frequency);
|
||||
}
|
||||
}
|
||||
private void run(Map<Location, Integer> inputs, Map<Integer, List<Location>> outputs, Set<Location> chestTerminalInputs, Set<Location> chestTerminalOutputs) {
|
||||
long timestamp = System.nanoTime();
|
||||
|
||||
// Chest Terminal Code
|
||||
if (SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled()) {
|
||||
handleItemRequests(providers, destinations);
|
||||
handleItemRequests(chestTerminalInputs, chestTerminalOutputs);
|
||||
}
|
||||
|
||||
// All operations happen here: Everything gets iterated from the Input Nodes.
|
||||
// (Apart from ChestTerminal Buses)
|
||||
for (Map.Entry<Location, Integer> entry : inputs.entrySet()) {
|
||||
long nodeTimestamp = System.nanoTime();
|
||||
Location input = entry.getKey();
|
||||
Optional<Block> attachedBlock = getAttachedBlock(input.getBlock());
|
||||
|
||||
if (attachedBlock.isPresent()) {
|
||||
routeItems(input, attachedBlock.get(), entry.getValue(), output);
|
||||
routeItems(input, attachedBlock.get(), entry.getValue(), outputs);
|
||||
}
|
||||
|
||||
// This will prevent this timings from showing up for the Cargo Manager
|
||||
timestamp += SlimefunPlugin.getProfiler().closeEntry(entry.getKey(), SlimefunItems.CARGO_INPUT_NODE.getItem(), nodeTimestamp);
|
||||
}
|
||||
|
||||
// Chest Terminal Code
|
||||
if (SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled()) {
|
||||
updateTerminals(providers);
|
||||
updateTerminals(chestTerminalInputs);
|
||||
}
|
||||
|
||||
// Submit a timings report
|
||||
SlimefunPlugin.getProfiler().closeEntry(regulator, SlimefunItems.CARGO_MANAGER.getItem(), timestamp);
|
||||
}
|
||||
|
||||
private void routeItems(Location inputNode, Block inputTarget, int frequency, Map<Integer, List<Location>> outputNodes) {
|
||||
ItemStackAndInteger slot = CargoUtils.withdraw(inputNode.getBlock(), inputTarget);
|
||||
AtomicReference<Object> inventory = new AtomicReference<>();
|
||||
ItemStackAndInteger slot = CargoUtils.withdraw(inputNode.getBlock(), inputTarget, inventory);
|
||||
|
||||
if (slot == null) {
|
||||
return;
|
||||
}
|
||||
@ -268,9 +289,11 @@ public class CargoNet extends ChestTerminalNetwork {
|
||||
}
|
||||
|
||||
if (stack != null) {
|
||||
DirtyChestMenu menu = CargoUtils.getChestMenu(inputTarget);
|
||||
Object inputInventory = inventory.get();
|
||||
|
||||
if (inputInventory instanceof DirtyChestMenu) {
|
||||
DirtyChestMenu menu = (DirtyChestMenu) inputInventory;
|
||||
|
||||
if (menu != null) {
|
||||
if (menu.getItemInSlot(previousSlot) == null) {
|
||||
menu.replaceExistingItem(previousSlot, stack);
|
||||
}
|
||||
@ -278,18 +301,15 @@ public class CargoNet extends ChestTerminalNetwork {
|
||||
inputTarget.getWorld().dropItem(inputTarget.getLocation().add(0, 1, 0), stack);
|
||||
}
|
||||
}
|
||||
else if (CargoUtils.hasInventory(inputTarget)) {
|
||||
BlockState state = inputTarget.getState();
|
||||
|
||||
if (state instanceof InventoryHolder) {
|
||||
Inventory inv = ((InventoryHolder) state).getInventory();
|
||||
if (inputInventory instanceof Inventory) {
|
||||
Inventory inv = (Inventory) inputInventory;
|
||||
|
||||
if (inv.getItem(previousSlot) == null) {
|
||||
inv.setItem(previousSlot, stack);
|
||||
}
|
||||
else {
|
||||
inputTarget.getWorld().dropItem(inputTarget.getLocation().add(0, 1, 0), stack);
|
||||
}
|
||||
if (inv.getItem(previousSlot) == null) {
|
||||
inv.setItem(previousSlot, stack);
|
||||
}
|
||||
else {
|
||||
inputTarget.getWorld().dropItem(inputTarget.getLocation().add(0, 1, 0), stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package io.github.thebusybiscuit.slimefun4.core.networks.cargo;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Material;
|
||||
@ -153,7 +154,7 @@ final class CargoUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
static ItemStackAndInteger withdraw(Block node, Block target) {
|
||||
static ItemStackAndInteger withdraw(Block node, Block target, AtomicReference<Object> inventory) {
|
||||
DirtyChestMenu menu = getChestMenu(target);
|
||||
|
||||
if (menu != null) {
|
||||
@ -162,6 +163,7 @@ final class CargoUtils {
|
||||
|
||||
if (matchesFilter(node, is)) {
|
||||
menu.replaceExistingItem(slot, null);
|
||||
inventory.set(menu);
|
||||
return new ItemStackAndInteger(is, slot);
|
||||
}
|
||||
}
|
||||
@ -189,6 +191,7 @@ final class CargoUtils {
|
||||
|
||||
if (matchesFilter(node, is)) {
|
||||
inv.setItem(slot, null);
|
||||
inventory.set(inv);
|
||||
return new ItemStackAndInteger(is, slot);
|
||||
}
|
||||
}
|
||||
@ -365,6 +368,7 @@ final class CargoUtils {
|
||||
|
||||
try {
|
||||
BlockMenu menu = BlockStorage.getInventory(block.getLocation());
|
||||
|
||||
if (menu == null) {
|
||||
return false;
|
||||
}
|
||||
|
@ -3,13 +3,16 @@ package io.github.thebusybiscuit.slimefun4.core.networks.cargo;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -30,6 +33,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
|
||||
import me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu;
|
||||
@ -57,13 +61,24 @@ abstract class ChestTerminalNetwork extends Network {
|
||||
// This represents a Queue of requests to handle
|
||||
private final Queue<ItemRequest> itemRequests = new LinkedList<>();
|
||||
|
||||
// This is a cache for the BlockFace a node is facing, so we don't need to request the
|
||||
// BlockData each time we visit a node
|
||||
protected Map<Location, BlockFace> connectorCache = new HashMap<>();
|
||||
|
||||
protected ChestTerminalNetwork(Location regulator) {
|
||||
super(SlimefunPlugin.getNetworkManager(), regulator);
|
||||
}
|
||||
|
||||
protected static Optional<Block> getAttachedBlock(Block block) {
|
||||
protected Optional<Block> getAttachedBlock(Block block) {
|
||||
if (block.getType() == Material.PLAYER_WALL_HEAD) {
|
||||
BlockFace cached = connectorCache.get(block.getLocation());
|
||||
|
||||
if (cached != null) {
|
||||
return Optional.of(block.getRelative(cached));
|
||||
}
|
||||
|
||||
BlockFace face = ((Directional) block.getBlockData()).getFacing().getOppositeFace();
|
||||
connectorCache.put(block.getLocation(), face);
|
||||
return Optional.of(block.getRelative(face));
|
||||
}
|
||||
|
||||
@ -170,14 +185,17 @@ abstract class ChestTerminalNetwork extends Network {
|
||||
}
|
||||
|
||||
private void collectImportRequests() {
|
||||
SlimefunItem item = SlimefunItem.getByID("CT_IMPORT_BUS");
|
||||
|
||||
for (Location bus : imports) {
|
||||
long timestamp = SlimefunPlugin.getProfiler().newEntry();
|
||||
BlockMenu menu = BlockStorage.getInventory(bus);
|
||||
|
||||
if (menu.getItemInSlot(17) == null) {
|
||||
Optional<Block> target = getAttachedBlock(bus.getBlock());
|
||||
|
||||
if (target.isPresent()) {
|
||||
ItemStackAndInteger stack = CargoUtils.withdraw(bus.getBlock(), target.get());
|
||||
ItemStackAndInteger stack = CargoUtils.withdraw(bus.getBlock(), target.get(), new AtomicReference<>());
|
||||
|
||||
if (stack != null) {
|
||||
menu.replaceExistingItem(17, stack.getItem());
|
||||
@ -188,11 +206,16 @@ abstract class ChestTerminalNetwork extends Network {
|
||||
if (menu.getItemInSlot(17) != null) {
|
||||
itemRequests.add(new ItemRequest(bus, 17, menu.getItemInSlot(17), ItemTransportFlow.INSERT));
|
||||
}
|
||||
|
||||
SlimefunPlugin.getProfiler().closeEntry(bus, item, timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
private void collectExportRequests() {
|
||||
SlimefunItem item = SlimefunItem.getByID("CT_EXPORT_BUS");
|
||||
|
||||
for (Location bus : exports) {
|
||||
long timestamp = SlimefunPlugin.getProfiler().newEntry();
|
||||
BlockMenu menu = BlockStorage.getInventory(bus);
|
||||
|
||||
if (menu.getItemInSlot(17) != null) {
|
||||
@ -223,17 +246,24 @@ abstract class ChestTerminalNetwork extends Network {
|
||||
itemRequests.add(new ItemRequest(bus, 17, items.get(index), ItemTransportFlow.WITHDRAW));
|
||||
}
|
||||
}
|
||||
|
||||
SlimefunPlugin.getProfiler().closeEntry(bus, item, timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
private void collectTerminalRequests() {
|
||||
SlimefunItem item = SlimefunItem.getByID("CHEST_TERMINAL");
|
||||
|
||||
for (Location terminal : terminals) {
|
||||
long timestamp = SlimefunPlugin.getProfiler().newEntry();
|
||||
BlockMenu menu = BlockStorage.getInventory(terminal);
|
||||
ItemStack sendingItem = menu.getItemInSlot(TERMINAL_OUT_SLOT);
|
||||
|
||||
if (sendingItem != null) {
|
||||
itemRequests.add(new ItemRequest(terminal, TERMINAL_OUT_SLOT, sendingItem, ItemTransportFlow.INSERT));
|
||||
}
|
||||
|
||||
SlimefunPlugin.getProfiler().closeEntry(terminal, item, timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
@ -269,6 +299,7 @@ abstract class ChestTerminalNetwork extends Network {
|
||||
ItemStackAndInteger item = items.get(index);
|
||||
|
||||
ItemStack stack = item.getItem().clone();
|
||||
stack.setAmount(1);
|
||||
ItemMeta im = stack.getItemMeta();
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add("");
|
||||
@ -366,7 +397,7 @@ abstract class ChestTerminalNetwork extends Network {
|
||||
}
|
||||
|
||||
if (add) {
|
||||
items.add(new ItemStackAndInteger(new CustomItem(is, 1), is.getAmount() + stored));
|
||||
items.add(new ItemStackAndInteger(is, is.getAmount() + stored));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -378,19 +409,19 @@ abstract class ChestTerminalNetwork extends Network {
|
||||
}
|
||||
}
|
||||
|
||||
private void filter(ItemStack is, List<ItemStackAndInteger> items, Location l) {
|
||||
if (is != null && CargoUtils.matchesFilter(l.getBlock(), is)) {
|
||||
private void filter(ItemStack stack, List<ItemStackAndInteger> items, Location node) {
|
||||
if (stack != null && CargoUtils.matchesFilter(node.getBlock(), stack)) {
|
||||
boolean add = true;
|
||||
|
||||
for (ItemStackAndInteger item : items) {
|
||||
if (SlimefunUtils.isItemSimilar(is, item.getItem(), true)) {
|
||||
if (SlimefunUtils.isItemSimilar(stack, item.getItem(), true)) {
|
||||
add = false;
|
||||
item.add(is.getAmount());
|
||||
item.add(stack.getAmount());
|
||||
}
|
||||
}
|
||||
|
||||
if (add) {
|
||||
items.add(new ItemStackAndInteger(new CustomItem(is, 1), is.getAmount()));
|
||||
items.add(new ItemStackAndInteger(stack, stack.getAmount()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ package io.github.thebusybiscuit.slimefun4.core.networks.energy;
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.function.LongConsumer;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -13,6 +15,7 @@ import io.github.thebusybiscuit.slimefun4.api.ErrorReport;
|
||||
import io.github.thebusybiscuit.slimefun4.api.network.Network;
|
||||
import io.github.thebusybiscuit.slimefun4.api.network.NetworkComponent;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.reactors.Reactor;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.holograms.SimpleHologram;
|
||||
@ -127,6 +130,8 @@ public class EnergyNet extends Network {
|
||||
}
|
||||
|
||||
public void tick(Block b) {
|
||||
AtomicLong timestamp = new AtomicLong(SlimefunPlugin.getProfiler().newEntry());
|
||||
|
||||
if (!regulator.equals(b.getLocation())) {
|
||||
SimpleHologram.update(b, "&4Multiple Energy Regulators connected");
|
||||
return;
|
||||
@ -138,85 +143,90 @@ public class EnergyNet extends Network {
|
||||
SimpleHologram.update(b, "&4No Energy Network found");
|
||||
}
|
||||
else {
|
||||
double supply = DoubleHandler.fixDouble(tickAllGenerators() + tickAllCapacitors());
|
||||
double supply = DoubleHandler.fixDouble(tickAllGenerators(timestamp::getAndAdd) + tickAllCapacitors());
|
||||
double demand = 0;
|
||||
|
||||
int available = (int) supply;
|
||||
int availableEnergy = (int) supply;
|
||||
|
||||
for (Location destination : consumers) {
|
||||
int capacity = ChargableBlock.getMaxCharge(destination);
|
||||
int charge = ChargableBlock.getCharge(destination);
|
||||
for (Location machine : consumers) {
|
||||
int capacity = ChargableBlock.getMaxCharge(machine);
|
||||
int charge = ChargableBlock.getCharge(machine);
|
||||
|
||||
if (charge < capacity) {
|
||||
int rest = capacity - charge;
|
||||
demand += rest;
|
||||
int availableSpace = capacity - charge;
|
||||
demand += availableSpace;
|
||||
|
||||
if (available > 0) {
|
||||
if (available > rest) {
|
||||
ChargableBlock.setUnsafeCharge(destination, capacity, false);
|
||||
available = available - rest;
|
||||
if (availableEnergy > 0) {
|
||||
if (availableEnergy > availableSpace) {
|
||||
ChargableBlock.setUnsafeCharge(machine, capacity, false);
|
||||
availableEnergy -= availableSpace;
|
||||
}
|
||||
else {
|
||||
ChargableBlock.setUnsafeCharge(destination, charge + available, false);
|
||||
available = 0;
|
||||
ChargableBlock.setUnsafeCharge(machine, charge + availableEnergy, false);
|
||||
availableEnergy = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Location battery : storage) {
|
||||
if (available > 0) {
|
||||
int capacity = ChargableBlock.getMaxCharge(battery);
|
||||
storeExcessEnergy(availableEnergy);
|
||||
updateHologram(b, supply, demand);
|
||||
}
|
||||
|
||||
// We have subtracted the timings from Generators, so they do not show up twice.
|
||||
SlimefunPlugin.getProfiler().closeEntry(b.getLocation(), SlimefunItems.ENERGY_REGULATOR.getItem(), timestamp.get());
|
||||
}
|
||||
|
||||
private void storeExcessEnergy(int available) {
|
||||
for (Location capacitor : storage) {
|
||||
if (available > 0) {
|
||||
int capacity = ChargableBlock.getMaxCharge(capacitor);
|
||||
|
||||
if (available > capacity) {
|
||||
ChargableBlock.setUnsafeCharge(capacitor, capacity, true);
|
||||
available -= capacity;
|
||||
}
|
||||
else {
|
||||
ChargableBlock.setUnsafeCharge(capacitor, available, true);
|
||||
available = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ChargableBlock.setUnsafeCharge(capacitor, 0, true);
|
||||
}
|
||||
}
|
||||
|
||||
for (Location generator : generators) {
|
||||
int capacity = ChargableBlock.getMaxCharge(generator);
|
||||
|
||||
if (capacity > 0) {
|
||||
if (available > 0) {
|
||||
if (available > capacity) {
|
||||
ChargableBlock.setUnsafeCharge(battery, capacity, true);
|
||||
ChargableBlock.setUnsafeCharge(generator, capacity, false);
|
||||
available = available - capacity;
|
||||
}
|
||||
else {
|
||||
ChargableBlock.setUnsafeCharge(battery, available, true);
|
||||
ChargableBlock.setUnsafeCharge(generator, available, false);
|
||||
available = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ChargableBlock.setUnsafeCharge(battery, 0, true);
|
||||
ChargableBlock.setUnsafeCharge(generator, 0, false);
|
||||
}
|
||||
}
|
||||
|
||||
for (Location source : generators) {
|
||||
if (ChargableBlock.isChargable(source)) {
|
||||
if (available > 0) {
|
||||
int capacity = ChargableBlock.getMaxCharge(source);
|
||||
|
||||
if (available > capacity) {
|
||||
ChargableBlock.setUnsafeCharge(source, capacity, false);
|
||||
available = available - capacity;
|
||||
}
|
||||
else {
|
||||
ChargableBlock.setUnsafeCharge(source, available, false);
|
||||
available = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ChargableBlock.setUnsafeCharge(source, 0, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateHologram(b, supply, demand);
|
||||
}
|
||||
}
|
||||
|
||||
private double tickAllGenerators() {
|
||||
private double tickAllGenerators(LongConsumer timeCallback) {
|
||||
double supply = 0;
|
||||
Set<Location> exploded = new HashSet<>();
|
||||
|
||||
for (Location source : generators) {
|
||||
long timestamp = System.currentTimeMillis();
|
||||
SlimefunItem item = BlockStorage.check(source);
|
||||
long timestamp = SlimefunPlugin.getProfiler().newEntry();
|
||||
Config config = BlockStorage.getLocationInfo(source);
|
||||
SlimefunItem item = SlimefunItem.getByID(config.getString("id"));
|
||||
|
||||
if (item != null) {
|
||||
Config config = BlockStorage.getLocationInfo(source);
|
||||
|
||||
try {
|
||||
GeneratorTicker generator = item.getEnergyTicker();
|
||||
|
||||
@ -247,7 +257,8 @@ public class EnergyNet extends Network {
|
||||
new ErrorReport(t, source, item);
|
||||
}
|
||||
|
||||
SlimefunPlugin.getTickerTask().addBlockTimings(source, System.currentTimeMillis() - timestamp);
|
||||
long time = SlimefunPlugin.getProfiler().closeEntry(source, item, timestamp);
|
||||
timeCallback.accept(time);
|
||||
}
|
||||
else {
|
||||
// This block seems to be gone now, better remove it to be extra safe
|
||||
@ -263,8 +274,8 @@ public class EnergyNet extends Network {
|
||||
private double tickAllCapacitors() {
|
||||
double supply = 0;
|
||||
|
||||
for (Location battery : storage) {
|
||||
supply += ChargableBlock.getCharge(battery);
|
||||
for (Location capacitor : storage) {
|
||||
supply += ChargableBlock.getCharge(capacitor);
|
||||
}
|
||||
|
||||
return supply;
|
||||
|
@ -56,7 +56,7 @@ class GitHubTask implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
if (requests >= MAX_REQUESTS_PER_MINUTE) {
|
||||
if (requests >= MAX_REQUESTS_PER_MINUTE && SlimefunPlugin.instance != null && SlimefunPlugin.instance.isEnabled()) {
|
||||
// Slow down API requests and wait a minute after more than x requests were made
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(SlimefunPlugin.instance, this::grabTextures, 2 * 60 * 20L);
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ class PlaceholderAPIHook extends PlaceholderExpansion {
|
||||
}
|
||||
|
||||
if (params.equals("timings_lag")) {
|
||||
return SlimefunPlugin.getTickerTask().getTime() + "ms";
|
||||
return SlimefunPlugin.getProfiler().getTime();
|
||||
}
|
||||
|
||||
if (params.equals("language")) {
|
||||
|
@ -0,0 +1,52 @@
|
||||
package io.github.thebusybiscuit.slimefun4.core.services.profiler;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
/**
|
||||
* This enum is used to quantify Slimefun's performance impact. This way we can assign a
|
||||
* "grade" to each timings report and also use this for metrics collection.
|
||||
*
|
||||
* @author TheBusyBiscuit
|
||||
*
|
||||
* @see SlimefunProfiler
|
||||
*
|
||||
*/
|
||||
public enum PerformanceRating implements Predicate<Float> {
|
||||
|
||||
// Thresholds might change in the future!
|
||||
|
||||
UNKNOWN(ChatColor.WHITE, -1),
|
||||
|
||||
GOOD(ChatColor.DARK_GREEN, 10),
|
||||
FINE(ChatColor.DARK_GREEN, 20),
|
||||
OKAY(ChatColor.GREEN, 30),
|
||||
MODERATE(ChatColor.YELLOW, 55),
|
||||
SEVERE(ChatColor.RED, 85),
|
||||
HURTFUL(ChatColor.DARK_RED, 500),
|
||||
BAD(ChatColor.DARK_RED, Float.MAX_VALUE);
|
||||
|
||||
private final ChatColor color;
|
||||
private final float threshold;
|
||||
|
||||
PerformanceRating(ChatColor color, float threshold) {
|
||||
this.color = color;
|
||||
this.threshold = threshold;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Float value) {
|
||||
if (value == null) {
|
||||
// null will only test true for UNKNOWN
|
||||
return threshold < 0;
|
||||
}
|
||||
|
||||
return value <= threshold;
|
||||
}
|
||||
|
||||
public ChatColor getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,199 @@
|
||||
package io.github.thebusybiscuit.slimefun4.core.services.profiler;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.ChatUtils;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
class PerformanceSummary {
|
||||
|
||||
// The threshold at which a Block or Chunk is significant enough to appear in /sf timings
|
||||
private static final int VISIBILITY_THRESHOLD = 280_000;
|
||||
private static final int MIN_ITEMS = 3;
|
||||
private static final int MAX_ITEMS = 10;
|
||||
|
||||
// A minecraft server tick is 50ms and Slimefun ticks are stretched across
|
||||
// two ticks (sync and async blocks), so we use 100ms as a reference here
|
||||
static final int MAX_TICK_DURATION = 100;
|
||||
|
||||
private final SlimefunProfiler profiler;
|
||||
private final PerformanceRating rating;
|
||||
private final long totalElapsedTime;
|
||||
private final int totalTickedBlocks;
|
||||
private final float percentage;
|
||||
|
||||
private final Map<String, Long> chunks;
|
||||
private final Map<String, Long> plugins;
|
||||
private final Map<String, Long> items;
|
||||
|
||||
PerformanceSummary(SlimefunProfiler profiler, long totalElapsedTime, int totalTickedBlocks) {
|
||||
this.profiler = profiler;
|
||||
this.rating = profiler.getPerformance();
|
||||
this.percentage = profiler.getPercentageOfTick();
|
||||
this.totalElapsedTime = totalElapsedTime;
|
||||
this.totalTickedBlocks = totalTickedBlocks;
|
||||
|
||||
chunks = profiler.getByChunk();
|
||||
plugins = profiler.getByPlugin();
|
||||
items = profiler.getByItem();
|
||||
}
|
||||
|
||||
public void send(CommandSender sender) {
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage(ChatColor.GREEN + "===== Slimefun Lag Profiler =====");
|
||||
sender.sendMessage(ChatColor.GOLD + "Total: " + ChatColor.YELLOW + NumberUtils.getAsMillis(totalElapsedTime));
|
||||
sender.sendMessage(ChatColor.GOLD + "Performance: " + getPerformanceRating());
|
||||
sender.sendMessage("");
|
||||
|
||||
summarizeTimings(totalTickedBlocks, "block", sender, items, entry -> {
|
||||
int count = profiler.getBlocksOfId(entry.getKey());
|
||||
String time = NumberUtils.getAsMillis(entry.getValue());
|
||||
|
||||
if (count > 1) {
|
||||
String average = NumberUtils.getAsMillis(entry.getValue() / count);
|
||||
|
||||
return entry.getKey() + " - " + count + "x (" + time + " | avg: " + average + ')';
|
||||
}
|
||||
else {
|
||||
return entry.getKey() + " - " + count + "x (" + time + ')';
|
||||
}
|
||||
});
|
||||
|
||||
summarizeTimings(chunks.size(), "chunk", sender, chunks, entry -> {
|
||||
int count = profiler.getBlocksInChunk(entry.getKey());
|
||||
String time = NumberUtils.getAsMillis(entry.getValue());
|
||||
|
||||
return entry.getKey() + " - " + count + " block" + (count != 1 ? 's' : "") + " (" + time + ")";
|
||||
});
|
||||
|
||||
summarizeTimings(plugins.size(), "plugin", sender, plugins, entry -> {
|
||||
int count = profiler.getBlocksFromPlugin(entry.getKey());
|
||||
String time = NumberUtils.getAsMillis(entry.getValue());
|
||||
|
||||
return entry.getKey() + " - " + count + " block" + (count != 1 ? 's' : "") + " (" + time + ")";
|
||||
});
|
||||
}
|
||||
|
||||
private void summarizeTimings(int count, String name, CommandSender sender, Map<String, Long> map, Function<Map.Entry<String, Long>, String> formatter) {
|
||||
Stream<Map.Entry<String, Long>> stream = map.entrySet().stream();
|
||||
List<Entry<String, Long>> results = stream.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).collect(Collectors.toList());
|
||||
String prefix = count + " " + name + (count != 1 ? 's' : "");
|
||||
|
||||
if (sender instanceof Player) {
|
||||
TextComponent component = summarizeAsTextComponent(count, prefix, results, formatter);
|
||||
sender.spigot().sendMessage(component);
|
||||
}
|
||||
else {
|
||||
String text = summarizeAsString(count, prefix, results, formatter);
|
||||
sender.sendMessage(text);
|
||||
}
|
||||
}
|
||||
|
||||
private TextComponent summarizeAsTextComponent(int count, String prefix, List<Map.Entry<String, Long>> results, Function<Entry<String, Long>, String> formatter) {
|
||||
TextComponent component = new TextComponent(prefix);
|
||||
component.setColor(ChatColor.YELLOW);
|
||||
|
||||
if (count > 0) {
|
||||
TextComponent hoverComponent = new TextComponent(" (Hover for details)");
|
||||
hoverComponent.setColor(ChatColor.GRAY);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
int displayed = 0;
|
||||
int hidden = 0;
|
||||
|
||||
for (Map.Entry<String, Long> entry : results) {
|
||||
if (displayed < MAX_ITEMS && (displayed < MIN_ITEMS || entry.getValue() > VISIBILITY_THRESHOLD)) {
|
||||
builder.append("\n").append(ChatColor.YELLOW).append(formatter.apply(entry));
|
||||
displayed++;
|
||||
}
|
||||
else {
|
||||
hidden++;
|
||||
}
|
||||
}
|
||||
|
||||
if (hidden > 0) {
|
||||
builder.append("\n\n&c+ &6").append(hidden).append(" more");
|
||||
}
|
||||
|
||||
hoverComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(ChatColors.color(builder.toString()))));
|
||||
|
||||
component.addExtra(hoverComponent);
|
||||
}
|
||||
|
||||
return component;
|
||||
}
|
||||
|
||||
private String summarizeAsString(int count, String prefix, List<Entry<String, Long>> results, Function<Entry<String, Long>, String> formatter) {
|
||||
int displayed = 0;
|
||||
int hidden = 0;
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(ChatColor.GOLD);
|
||||
builder.append(prefix);
|
||||
|
||||
if (count > 0) {
|
||||
builder.append(ChatColor.YELLOW);
|
||||
|
||||
for (Map.Entry<String, Long> entry : results) {
|
||||
if (displayed < MAX_ITEMS && (displayed < MIN_ITEMS || entry.getValue() > VISIBILITY_THRESHOLD)) {
|
||||
builder.append("\n ");
|
||||
builder.append(ChatColor.stripColor(formatter.apply(entry)));
|
||||
displayed++;
|
||||
}
|
||||
else {
|
||||
hidden++;
|
||||
}
|
||||
}
|
||||
|
||||
if (hidden > 0) {
|
||||
builder.append("\n+ ");
|
||||
builder.append(hidden);
|
||||
builder.append(" more...");
|
||||
}
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private String getPerformanceRating() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(NumberUtils.getColorFromPercentage(100 - Math.min(percentage, 100)));
|
||||
|
||||
int rest = 20;
|
||||
for (int i = (int) Math.min(percentage, 100); i >= 5; i = i - 5) {
|
||||
builder.append(':');
|
||||
rest--;
|
||||
}
|
||||
|
||||
builder.append(ChatColor.DARK_GRAY);
|
||||
|
||||
for (int i = 0; i < rest; i++) {
|
||||
builder.append(':');
|
||||
}
|
||||
|
||||
builder.append(" - ");
|
||||
|
||||
builder.append(rating.getColor() + ChatUtils.humanize(rating.name()));
|
||||
|
||||
builder.append(ChatColor.GRAY);
|
||||
builder.append(" (");
|
||||
builder.append(NumberUtils.roundDecimalNumber(percentage));
|
||||
builder.append("%)");
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package io.github.thebusybiscuit.slimefun4.core.services.profiler;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.blocks.BlockPosition;
|
||||
import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
|
||||
class ProfiledBlock {
|
||||
|
||||
private final BlockPosition position;
|
||||
private final SlimefunItem item;
|
||||
|
||||
ProfiledBlock(BlockPosition position, SlimefunItem item) {
|
||||
this.position = position;
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
ProfiledBlock(Block b) {
|
||||
this(new BlockPosition(b), null);
|
||||
}
|
||||
|
||||
public BlockPosition getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return item.getID();
|
||||
}
|
||||
|
||||
public SlimefunAddon getAddon() {
|
||||
return item.getAddon();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof ProfiledBlock) {
|
||||
return position.equals(((ProfiledBlock) obj).position);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return position.hashCode();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,316 @@
|
||||
package io.github.thebusybiscuit.slimefun4.core.services.profiler;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.blocks.BlockPosition;
|
||||
import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.tasks.TickerTask;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
|
||||
/**
|
||||
* The {@link SlimefunProfiler} works closely to the {@link TickerTask} and is
|
||||
* responsible for monitoring that task.
|
||||
* It collects timings data for any ticked {@link Block} and the corresponding {@link SlimefunItem}.
|
||||
* This allows developers to identify laggy {@link SlimefunItem SlimefunItems} or {@link SlimefunAddon SlimefunAddons}.
|
||||
* But it also enables Server Admins to locate lag-inducing areas on the {@link Server}.
|
||||
*
|
||||
* @author TheBusyBiscuit
|
||||
*
|
||||
* @see TickerTask
|
||||
*
|
||||
*/
|
||||
public class SlimefunProfiler {
|
||||
|
||||
private final ExecutorService executor = Executors.newFixedThreadPool(3);
|
||||
private final AtomicBoolean running = new AtomicBoolean(false);
|
||||
private final AtomicInteger queued = new AtomicInteger(0);
|
||||
|
||||
private long totalElapsedTime;
|
||||
|
||||
private final Map<ProfiledBlock, Long> timings = new ConcurrentHashMap<>();
|
||||
private final Queue<CommandSender> requests = new ConcurrentLinkedQueue<>();
|
||||
|
||||
/**
|
||||
* This method starts the profiling, data from previous runs will be cleared.
|
||||
*/
|
||||
public void start() {
|
||||
running.set(true);
|
||||
queued.set(0);
|
||||
timings.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method starts a new profiler entry.
|
||||
*
|
||||
* @return A timestamp, best fed back into {@link #closeEntry(Location, SlimefunItem, long)}
|
||||
*/
|
||||
public long newEntry() {
|
||||
if (!running.get()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
queued.incrementAndGet();
|
||||
return System.nanoTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method schedules a given amount of entries for the future.
|
||||
* Be careful to {@link #closeEntry(Location, SlimefunItem, long)} all of them again!
|
||||
* No {@link PerformanceSummary} will be sent until all entires were closed.
|
||||
*
|
||||
* @param amount
|
||||
* The amount of entries that should be scheduled.
|
||||
*/
|
||||
public void scheduleEntries(int amount) {
|
||||
if (running.get()) {
|
||||
queued.getAndAdd(amount);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method closes a previously started entry.
|
||||
* Make sure to call {@link #newEntry()} to get the timestamp in advance.
|
||||
*
|
||||
* @param l
|
||||
* The {@link Location} of our {@link Block}
|
||||
* @param item
|
||||
* The {@link SlimefunItem} at this {@link Location}
|
||||
* @param timestamp
|
||||
* The timestamp marking the start of this entry, you can retrieve it using {@link #newEntry()}
|
||||
*
|
||||
* @return The total timings of this entry
|
||||
*/
|
||||
public long closeEntry(Location l, SlimefunItem item, long timestamp) {
|
||||
Validate.notNull(l, "Location must not be null!");
|
||||
Validate.notNull(item, "You need to specify a SlimefunItem!");
|
||||
|
||||
if (timestamp == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
long elapsedTime = System.nanoTime() - timestamp;
|
||||
|
||||
executor.execute(() -> {
|
||||
ProfiledBlock block = new ProfiledBlock(new BlockPosition(l), item);
|
||||
timings.put(block, elapsedTime);
|
||||
queued.decrementAndGet();
|
||||
});
|
||||
|
||||
return elapsedTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* This stops the profiling.
|
||||
*/
|
||||
public void stop() {
|
||||
running.set(false);
|
||||
|
||||
if (SlimefunPlugin.instance == null || !SlimefunPlugin.instance.isEnabled()) {
|
||||
// Slimefun has been disabled
|
||||
return;
|
||||
}
|
||||
|
||||
// Since we got more than one Thread in our pool, blocking this one is completely fine
|
||||
executor.execute(() -> {
|
||||
|
||||
// Wait for all timing results to come in
|
||||
while (queued.get() > 0 && !running.get()) {
|
||||
try {
|
||||
Thread.sleep(1);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
Slimefun.getLogger().log(Level.SEVERE, "A waiting Thread was interrupted", e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
if (running.get()) {
|
||||
// Looks like the next profiling has already started, abort!
|
||||
return;
|
||||
}
|
||||
|
||||
totalElapsedTime = timings.values().stream().mapToLong(Long::longValue).sum();
|
||||
|
||||
if (!requests.isEmpty()) {
|
||||
PerformanceSummary summary = new PerformanceSummary(this, totalElapsedTime, timings.size());
|
||||
Iterator<CommandSender> iterator = requests.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
summary.send(iterator.next());
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method requests a summary for the given {@link CommandSender}.
|
||||
* The summary will be sent upon the next available moment in time.
|
||||
*
|
||||
* @param sender
|
||||
* The {@link CommandSender} who shall receive this summary.
|
||||
*/
|
||||
public void requestSummary(CommandSender sender) {
|
||||
Validate.notNull(sender, "Cannot request a summary for null");
|
||||
|
||||
requests.add(sender);
|
||||
}
|
||||
|
||||
protected Map<String, Long> getByItem() {
|
||||
Map<String, Long> map = new HashMap<>();
|
||||
|
||||
for (Map.Entry<ProfiledBlock, Long> entry : timings.entrySet()) {
|
||||
map.merge(entry.getKey().getId(), entry.getValue(), Long::sum);
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
protected Map<String, Long> getByPlugin() {
|
||||
Map<String, Long> map = new HashMap<>();
|
||||
|
||||
for (Map.Entry<ProfiledBlock, Long> entry : timings.entrySet()) {
|
||||
map.merge(entry.getKey().getAddon().getName(), entry.getValue(), Long::sum);
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
protected Map<String, Long> getByChunk() {
|
||||
Map<String, Long> map = new HashMap<>();
|
||||
|
||||
for (Map.Entry<ProfiledBlock, Long> entry : timings.entrySet()) {
|
||||
String world = entry.getKey().getPosition().getWorld().getName();
|
||||
int x = entry.getKey().getPosition().getChunkX();
|
||||
int z = entry.getKey().getPosition().getChunkZ();
|
||||
|
||||
map.merge(world + " (" + x + ',' + z + ')', entry.getValue(), Long::sum);
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
protected int getBlocksInChunk(String chunk) {
|
||||
int blocks = 0;
|
||||
|
||||
for (ProfiledBlock block : timings.keySet()) {
|
||||
String world = block.getPosition().getWorld().getName();
|
||||
int x = block.getPosition().getChunkX();
|
||||
int z = block.getPosition().getChunkZ();
|
||||
|
||||
if (chunk.equals(world + " (" + x + ',' + z + ')')) {
|
||||
blocks++;
|
||||
}
|
||||
}
|
||||
|
||||
return blocks;
|
||||
}
|
||||
|
||||
protected int getBlocksOfId(String id) {
|
||||
int blocks = 0;
|
||||
|
||||
for (ProfiledBlock block : timings.keySet()) {
|
||||
if (block.getId().equals(id)) {
|
||||
blocks++;
|
||||
}
|
||||
}
|
||||
|
||||
return blocks;
|
||||
}
|
||||
|
||||
protected int getBlocksFromPlugin(String id) {
|
||||
int blocks = 0;
|
||||
|
||||
for (ProfiledBlock block : timings.keySet()) {
|
||||
if (block.getAddon().getName().equals(id)) {
|
||||
blocks++;
|
||||
}
|
||||
}
|
||||
|
||||
return blocks;
|
||||
}
|
||||
|
||||
protected float getPercentageOfTick() {
|
||||
float millis = totalElapsedTime / 1000000.0F;
|
||||
float fraction = (millis * 100.0F) / PerformanceSummary.MAX_TICK_DURATION;
|
||||
return Math.round((fraction * 100.0F) / 100.0F);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the current {@link PerformanceRating}.
|
||||
*
|
||||
* @return The current performance grade
|
||||
*/
|
||||
public PerformanceRating getPerformance() {
|
||||
float percentage = getPercentageOfTick();
|
||||
|
||||
for (PerformanceRating rating : PerformanceRating.values()) {
|
||||
if (rating.test(percentage)) {
|
||||
return rating;
|
||||
}
|
||||
}
|
||||
|
||||
return PerformanceRating.UNKNOWN;
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return NumberUtils.getAsMillis(totalElapsedTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method checks whether the {@link SlimefunProfiler} has collected timings on
|
||||
* the given {@link Block}
|
||||
*
|
||||
* @param b
|
||||
* The {@link Block}
|
||||
*
|
||||
* @return Whether timings of this {@link Block} have been collected
|
||||
*/
|
||||
public boolean hasTimings(Block b) {
|
||||
Validate.notNull("Cannot get timings for a null Block");
|
||||
return timings.containsKey(new ProfiledBlock(b));
|
||||
}
|
||||
|
||||
public String getTime(Block b) {
|
||||
Validate.notNull("Cannot get timings for a null Block");
|
||||
|
||||
long time = timings.getOrDefault(new ProfiledBlock(b), 0L);
|
||||
return NumberUtils.getAsMillis(time);
|
||||
}
|
||||
|
||||
public String getTime(Chunk chunk) {
|
||||
Validate.notNull("Cannot get timings for a null Chunk");
|
||||
|
||||
long time = getByChunk().getOrDefault(chunk.getWorld().getName() + " (" + chunk.getX() + ',' + chunk.getZ() + ')', 0L);
|
||||
return NumberUtils.getAsMillis(time);
|
||||
}
|
||||
|
||||
public String getTime(SlimefunItem item) {
|
||||
Validate.notNull("Cannot get timings for a null SlimefunItem");
|
||||
|
||||
long time = getByItem().getOrDefault(item.getID(), 0L);
|
||||
return NumberUtils.getAsMillis(time);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
/**
|
||||
* This package holds classes related to the
|
||||
* {@link io.github.thebusybiscuit.slimefun4.core.services.profiler.SlimefunProfiler}.
|
||||
* The {@link io.github.thebusybiscuit.slimefun4.core.services.profiler.SlimefunProfiler} is used to determine
|
||||
* {@link org.bukkit.block.Block Blocks}, {@link org.bukkit.Chunk Chunks} or
|
||||
* {@link me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem SlimefunItems} that cause lag or performance
|
||||
* drops.
|
||||
*/
|
||||
package io.github.thebusybiscuit.slimefun4.core.services.profiler;
|
@ -43,6 +43,7 @@ import io.github.thebusybiscuit.slimefun4.core.services.UpdaterService;
|
||||
import io.github.thebusybiscuit.slimefun4.core.services.github.GitHubService;
|
||||
import io.github.thebusybiscuit.slimefun4.core.services.metrics.MetricsService;
|
||||
import io.github.thebusybiscuit.slimefun4.core.services.plugins.ThirdPartyPluginService;
|
||||
import io.github.thebusybiscuit.slimefun4.core.services.profiler.SlimefunProfiler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientAltar;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.Cooler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.BasicCircuitBoard;
|
||||
@ -127,6 +128,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
|
||||
private final PerWorldSettingsService worldSettingsService = new PerWorldSettingsService(this);
|
||||
private final ThirdPartyPluginService thirdPartySupportService = new ThirdPartyPluginService(this);
|
||||
private final MinecraftRecipeService recipeService = new MinecraftRecipeService(this);
|
||||
private final SlimefunProfiler profiler = new SlimefunProfiler();
|
||||
private LocalizationService local;
|
||||
|
||||
private GPSNetwork gpsNetwork;
|
||||
@ -155,8 +157,9 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
|
||||
if (minecraftVersion == MinecraftVersion.UNIT_TEST) {
|
||||
instance = this;
|
||||
local = new LocalizationService(this, "", null);
|
||||
gpsNetwork = new GPSNetwork();
|
||||
command.register();
|
||||
@ -170,14 +173,13 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
|
||||
return;
|
||||
}
|
||||
|
||||
instance = this;
|
||||
|
||||
// Creating all necessary Folders
|
||||
getLogger().log(Level.INFO, "Loading various systems...");
|
||||
getLogger().log(Level.INFO, "Creating directories...");
|
||||
createDirectories();
|
||||
registry.load(config);
|
||||
|
||||
// Set up localization
|
||||
getLogger().log(Level.INFO, "Loading language files...");
|
||||
local = new LocalizationService(this, config.getString("options.chat-prefix"), config.getString("options.language"));
|
||||
|
||||
// Setting up Networks
|
||||
@ -217,69 +219,23 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
|
||||
registry.setResearchingEnabled(getResearchCfg().getBoolean("enable-researching"));
|
||||
PostSetup.setupWiki();
|
||||
|
||||
// All Slimefun Listeners
|
||||
new SlimefunBootsListener(this);
|
||||
new SlimefunItemListener(this);
|
||||
new SlimefunItemConsumeListener(this);
|
||||
new BlockPhysicsListener(this);
|
||||
new CargoNodeListener(this);
|
||||
new MultiBlockListener(this);
|
||||
new GadgetsListener(this);
|
||||
new DispenserListener(this);
|
||||
new BlockListener(this);
|
||||
new EnhancedFurnaceListener(this);
|
||||
new ItemPickupListener(this);
|
||||
new DeathpointListener(this);
|
||||
new ExplosionsListener(this);
|
||||
new DebugFishListener(this);
|
||||
new VanillaMachinesListener(this);
|
||||
new FireworksListener(this);
|
||||
new WitherListener(this);
|
||||
new IronGolemListener(this);
|
||||
new PlayerInteractEntityListener(this);
|
||||
if (minecraftVersion.isAtLeast(MinecraftVersion.MINECRAFT_1_15)) {
|
||||
new BeeListener(this);
|
||||
}
|
||||
getLogger().log(Level.INFO, "Registering listeners...");
|
||||
registerListeners();
|
||||
|
||||
new MobDropListener(this, (BasicCircuitBoard) SlimefunItems.BASIC_CIRCUIT_BOARD.getItem());
|
||||
|
||||
// Item-specific Listeners
|
||||
new VampireBladeListener(this, (VampireBlade) SlimefunItems.BLADE_OF_VAMPIRES.getItem());
|
||||
new CoolerListener(this, (Cooler) SlimefunItems.COOLER.getItem());
|
||||
new SeismicAxeListener(this, (SeismicAxe) SlimefunItems.SEISMIC_AXE.getItem());
|
||||
grapplingHookListener.register(this, (GrapplingHook) SlimefunItems.GRAPPLING_HOOK.getItem());
|
||||
ancientAltarListener.register(this, (AncientAltar) SlimefunItems.ANCIENT_ALTAR.getItem());
|
||||
|
||||
bowListener.register(this);
|
||||
|
||||
// Toggleable Listeners for performance reasons
|
||||
if (config.getBoolean("items.talismans")) {
|
||||
new TalismanListener(this);
|
||||
}
|
||||
|
||||
if (config.getBoolean("items.soulbound")) {
|
||||
new SoulboundListener(this);
|
||||
}
|
||||
|
||||
if (config.getBoolean("items.backpacks")) {
|
||||
backpackListener.register(this);
|
||||
}
|
||||
|
||||
// Handle Slimefun Guide being given on Join
|
||||
new SlimefunGuideListener(this, config.getBoolean("guide.receive-on-first-join"));
|
||||
|
||||
// Load/Unload Worlds in Slimefun
|
||||
new WorldListener(this);
|
||||
|
||||
// Clear the Slimefun Guide History upon Player Leaving
|
||||
new PlayerProfileListener(this);
|
||||
|
||||
// Initiating various Stuff and all Items with a slightly delay (0ms after the Server finished loading)
|
||||
// Initiating various Stuff and all items with a slight delay (0ms after the Server finished loading)
|
||||
Slimefun.runSync(new SlimefunStartupTask(this, () -> {
|
||||
protections = new ProtectionManager(getServer());
|
||||
textureService.register(registry.getAllSlimefunItems(), true);
|
||||
permissionsService.register(registry.getAllSlimefunItems(), true);
|
||||
recipeService.refresh();
|
||||
|
||||
// This try/catch should prevent buggy Spigot builds from blocking item loading
|
||||
try {
|
||||
recipeService.refresh();
|
||||
}
|
||||
catch (Exception | LinkageError x) {
|
||||
getLogger().log(Level.SEVERE, x, () -> "An Exception occured while iterating through the Recipe list on Minecraft Version " + minecraftVersion.getName() + " (Slimefun v" + getVersion() + ")");
|
||||
}
|
||||
|
||||
}), 0);
|
||||
|
||||
// Setting up the command /sf and all subcommands
|
||||
@ -299,6 +255,8 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
|
||||
getLogger().log(Level.INFO, "Slimefun has finished loading in {0}", getStartupTime(timestamp));
|
||||
}
|
||||
else {
|
||||
instance = null;
|
||||
|
||||
getLogger().log(Level.INFO, "#################### - INFO - ####################");
|
||||
getLogger().log(Level.INFO, " ");
|
||||
getLogger().log(Level.INFO, "Slimefun could not be loaded (yet).");
|
||||
@ -430,7 +388,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
|
||||
|
||||
private void createDirectories() {
|
||||
String[] storageFolders = { "Players", "blocks", "stored-blocks", "stored-inventories", "stored-chunks", "universal-inventories", "waypoints", "block-backups" };
|
||||
String[] pluginFolders = { "scripts", "generators", "error-reports", "cache/github", "world-settings" };
|
||||
String[] pluginFolders = { "scripts", "error-reports", "cache/github", "world-settings" };
|
||||
|
||||
for (String folder : storageFolders) {
|
||||
File file = new File("data-storage/Slimefun", folder);
|
||||
@ -449,6 +407,65 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
|
||||
}
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
new SlimefunBootsListener(this);
|
||||
new SlimefunItemListener(this);
|
||||
new SlimefunItemConsumeListener(this);
|
||||
new BlockPhysicsListener(this);
|
||||
new CargoNodeListener(this);
|
||||
new MultiBlockListener(this);
|
||||
new GadgetsListener(this);
|
||||
new DispenserListener(this);
|
||||
new BlockListener(this);
|
||||
new EnhancedFurnaceListener(this);
|
||||
new ItemPickupListener(this);
|
||||
new DeathpointListener(this);
|
||||
new ExplosionsListener(this);
|
||||
new DebugFishListener(this);
|
||||
new VanillaMachinesListener(this);
|
||||
new FireworksListener(this);
|
||||
new WitherListener(this);
|
||||
new IronGolemListener(this);
|
||||
new PlayerInteractEntityListener(this);
|
||||
|
||||
if (minecraftVersion.isAtLeast(MinecraftVersion.MINECRAFT_1_15)) {
|
||||
new BeeListener(this);
|
||||
}
|
||||
|
||||
new MobDropListener(this, (BasicCircuitBoard) SlimefunItems.BASIC_CIRCUIT_BOARD.getItem());
|
||||
|
||||
// Item-specific Listeners
|
||||
new VampireBladeListener(this, (VampireBlade) SlimefunItems.BLADE_OF_VAMPIRES.getItem());
|
||||
new CoolerListener(this, (Cooler) SlimefunItems.COOLER.getItem());
|
||||
new SeismicAxeListener(this, (SeismicAxe) SlimefunItems.SEISMIC_AXE.getItem());
|
||||
grapplingHookListener.register(this, (GrapplingHook) SlimefunItems.GRAPPLING_HOOK.getItem());
|
||||
ancientAltarListener.register(this, (AncientAltar) SlimefunItems.ANCIENT_ALTAR.getItem());
|
||||
|
||||
bowListener.register(this);
|
||||
|
||||
// Toggleable Listeners for performance reasons
|
||||
if (config.getBoolean("items.talismans")) {
|
||||
new TalismanListener(this);
|
||||
}
|
||||
|
||||
if (config.getBoolean("items.soulbound")) {
|
||||
new SoulboundListener(this);
|
||||
}
|
||||
|
||||
if (config.getBoolean("items.backpacks")) {
|
||||
backpackListener.register(this);
|
||||
}
|
||||
|
||||
// Handle Slimefun Guide being given on Join
|
||||
new SlimefunGuideListener(this, config.getBoolean("guide.receive-on-first-join"));
|
||||
|
||||
// Load/Unload Worlds in Slimefun
|
||||
new WorldListener(this);
|
||||
|
||||
// Clear the Slimefun Guide History upon Player Leaving
|
||||
new PlayerProfileListener(this);
|
||||
}
|
||||
|
||||
private void loadItems() {
|
||||
try {
|
||||
SlimefunItemSetup.setup(this);
|
||||
@ -602,6 +619,10 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
|
||||
return instance.command;
|
||||
}
|
||||
|
||||
public static SlimefunProfiler getProfiler() {
|
||||
return instance.profiler;
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns the currently installed version of Minecraft.
|
||||
*
|
||||
|
@ -44,10 +44,7 @@ public abstract class AdvancedFarmerAndroid extends FarmerAndroid {
|
||||
if (result.isPresent()) {
|
||||
ItemStack drop = result.get();
|
||||
menu.pushItem(drop, getOutputSlots());
|
||||
|
||||
if (menu.fits(drop, getOutputSlots())) {
|
||||
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType());
|
||||
}
|
||||
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -62,10 +62,7 @@ public abstract class FisherAndroid extends ProgrammableAndroid {
|
||||
|
||||
if (ThreadLocalRandom.current().nextInt(100) < 10 * getTier()) {
|
||||
ItemStack drop = fishingLoot.getRandom();
|
||||
|
||||
if (menu.fits(drop, getOutputSlots())) {
|
||||
menu.pushItem(drop, getOutputSlots());
|
||||
}
|
||||
menu.pushItem(drop, getOutputSlots());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -41,12 +41,12 @@ enum Instruction {
|
||||
// Directions
|
||||
TURN_LEFT(AndroidType.NONE, HeadTexture.SCRIPT_LEFT, (android, b, inv, face) -> {
|
||||
int mod = -1;
|
||||
android.rotate(b, mod);
|
||||
android.rotate(b, face, mod);
|
||||
}),
|
||||
|
||||
TURN_RIGHT(AndroidType.NONE, HeadTexture.SCRIPT_RIGHT, (android, b, inv, face) -> {
|
||||
int mod = 1;
|
||||
android.rotate(b, mod);
|
||||
android.rotate(b, face, mod);
|
||||
}),
|
||||
|
||||
// Action - Pickaxe
|
||||
|
@ -2,7 +2,6 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.androids;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Predicate;
|
||||
@ -16,6 +15,7 @@ import org.bukkit.Tag;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.Dispenser;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Rotatable;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -49,6 +49,7 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineFuel;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.InventoryBlock;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
|
||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
|
||||
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
|
||||
@ -198,8 +199,8 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent
|
||||
|
||||
@Override
|
||||
public void tick(Block b, SlimefunItem item, Config data) {
|
||||
if (b != null) {
|
||||
ProgrammableAndroid.this.tick(b);
|
||||
if (b != null && data != null) {
|
||||
ProgrammableAndroid.this.tick(b, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -387,23 +388,7 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent
|
||||
}
|
||||
else {
|
||||
Script script = scripts.get(target);
|
||||
List<String> lore = new LinkedList<>();
|
||||
lore.add("&7by &r" + script.getAuthor());
|
||||
lore.add("");
|
||||
lore.add("&7Downloads: &r" + script.getDownloads());
|
||||
lore.add("&7Rating: " + getScriptRatingPercentage(script));
|
||||
lore.add("&a" + script.getUpvotes() + " \u263A &7| &4\u2639 " + script.getDownvotes());
|
||||
lore.add("");
|
||||
lore.add("&eLeft Click &rto download this Script");
|
||||
lore.add("&4(This will override your current Script)");
|
||||
|
||||
if (script.canRate(p)) {
|
||||
lore.add("&eShift + Left Click &rto leave a positive Rating");
|
||||
lore.add("&eShift + Right Click &rto leave a negative Rating");
|
||||
}
|
||||
|
||||
ItemStack item = new CustomItem(getItem(), "&b" + script.getName(), lore.toArray(new String[0]));
|
||||
menu.addItem(index, item, (player, slot, stack, action) -> {
|
||||
menu.addItem(index, script.getAsItemStack(this, p), (player, slot, stack, action) -> {
|
||||
if (action.isShiftClicked()) {
|
||||
if (script.isAuthor(player)) {
|
||||
SlimefunPlugin.getLocalization().sendMessage(player, "android.scripts.rating.own", true);
|
||||
@ -509,11 +494,6 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent
|
||||
return list;
|
||||
}
|
||||
|
||||
protected String getScriptRatingPercentage(Script script) {
|
||||
float percentage = script.getRating();
|
||||
return NumberUtils.getColorFromPercentage(percentage) + String.valueOf(percentage) + ChatColor.RESET + "% ";
|
||||
}
|
||||
|
||||
protected void editInstruction(Player p, Block b, String[] script, int index) {
|
||||
ChestMenu menu = new ChestMenu(ChatColor.DARK_AQUA + SlimefunPlugin.getLocalization().getMessage(p, "android.scripts.editor"));
|
||||
ChestMenuUtils.drawBackground(menu, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
@ -627,60 +607,69 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent
|
||||
|
||||
public abstract int getTier();
|
||||
|
||||
protected void tick(Block b) {
|
||||
protected void tick(Block b, Config data) {
|
||||
if (b.getType() != Material.PLAYER_HEAD) {
|
||||
// The Android was destroyed or moved.
|
||||
return;
|
||||
}
|
||||
|
||||
if ("false".equals(BlockStorage.getLocationInfo(b.getLocation(), "paused"))) {
|
||||
if ("false".equals(data.getString("paused"))) {
|
||||
BlockMenu menu = BlockStorage.getInventory(b);
|
||||
float fuel = Float.parseFloat(BlockStorage.getLocationInfo(b.getLocation(), "fuel"));
|
||||
String fuelData = data.getString("fuel");
|
||||
float fuel = fuelData == null ? 0 : Float.parseFloat(fuelData);
|
||||
|
||||
if (fuel < 0.001) {
|
||||
consumeFuel(b, menu);
|
||||
}
|
||||
else {
|
||||
String[] script = PatternUtils.DASH.split(BlockStorage.getLocationInfo(b.getLocation(), "script"));
|
||||
String code = data.getString("script");
|
||||
String[] script = PatternUtils.DASH.split(code == null ? DEFAULT_SCRIPT : code);
|
||||
|
||||
String indexData = data.getString("index");
|
||||
int index = (indexData == null ? 0 : Integer.parseInt(indexData)) + 1;
|
||||
|
||||
int index = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "index")) + 1;
|
||||
if (index >= script.length) {
|
||||
index = 0;
|
||||
}
|
||||
|
||||
boolean refresh = true;
|
||||
BlockStorage.addBlockInfo(b, "fuel", String.valueOf(fuel - 1));
|
||||
Instruction instruction = Instruction.valueOf(script[index]);
|
||||
|
||||
if (getAndroidType().isType(instruction.getRequiredType())) {
|
||||
BlockFace face = BlockFace.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "rotation"));
|
||||
|
||||
switch (instruction) {
|
||||
case START:
|
||||
case WAIT:
|
||||
// Just "waiting" here which means we do nothing
|
||||
break;
|
||||
case REPEAT:
|
||||
BlockStorage.addBlockInfo(b, "index", String.valueOf(0));
|
||||
break;
|
||||
case CHOP_TREE:
|
||||
refresh = chopTree(b, menu, face);
|
||||
break;
|
||||
default:
|
||||
instruction.execute(this, b, menu, face);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (refresh) {
|
||||
BlockStorage.addBlockInfo(b, "index", String.valueOf(index));
|
||||
}
|
||||
executeInstruction(instruction, b, menu, data, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void rotate(Block b, int mod) {
|
||||
BlockFace current = BlockFace.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "rotation"));
|
||||
private void executeInstruction(Instruction instruction, Block b, BlockMenu inv, Config data, int index) {
|
||||
if (getAndroidType().isType(instruction.getRequiredType())) {
|
||||
String rotationData = data.getString("rotation");
|
||||
BlockFace face = rotationData == null ? BlockFace.NORTH : BlockFace.valueOf(rotationData);
|
||||
|
||||
switch (instruction) {
|
||||
case START:
|
||||
case WAIT:
|
||||
// We are "waiting" here, so we only move a step forward
|
||||
BlockStorage.addBlockInfo(b, "index", String.valueOf(index));
|
||||
break;
|
||||
case REPEAT:
|
||||
// "repeat" just means, we reset our index
|
||||
BlockStorage.addBlockInfo(b, "index", String.valueOf(0));
|
||||
break;
|
||||
case CHOP_TREE:
|
||||
// We only move to the next step if we finished chopping wood
|
||||
if (chopTree(b, inv, face)) {
|
||||
BlockStorage.addBlockInfo(b, "index", String.valueOf(index));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// We set the index here in advance to fix moving android issues
|
||||
BlockStorage.addBlockInfo(b, "index", String.valueOf(index));
|
||||
instruction.execute(this, b, inv, face);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void rotate(Block b, BlockFace current, int mod) {
|
||||
int index = POSSIBLE_ROTATIONS.indexOf(current) + mod;
|
||||
|
||||
if (index == POSSIBLE_ROTATIONS.size()) {
|
||||
@ -693,7 +682,7 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent
|
||||
BlockFace rotation = POSSIBLE_ROTATIONS.get(index);
|
||||
|
||||
Rotatable rotatatable = (Rotatable) b.getBlockData();
|
||||
rotatatable.setRotation(rotation);
|
||||
rotatatable.setRotation(rotation.getOppositeFace());
|
||||
b.setBlockData(rotatatable);
|
||||
BlockStorage.addBlockInfo(b, "rotation", rotation.name());
|
||||
}
|
||||
@ -739,7 +728,7 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent
|
||||
dispenser.setItem(slot, null);
|
||||
return true;
|
||||
}
|
||||
else if (SlimefunUtils.isItemSimilar(newFuel, currentFuel, true)) {
|
||||
else if (SlimefunUtils.isItemSimilar(newFuel, currentFuel, true, false)) {
|
||||
int rest = newFuel.getType().getMaxStackSize() - currentFuel.getAmount();
|
||||
|
||||
if (rest > 0) {
|
||||
@ -766,7 +755,8 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent
|
||||
menu.pushItem(new ItemStack(Material.BUCKET), getOutputSlots());
|
||||
}
|
||||
|
||||
BlockStorage.addBlockInfo(b, "fuel", String.valueOf((int) (fuel.getTicks() * this.getFuelEfficiency())));
|
||||
int fuelLevel = (int) (fuel.getTicks() * getFuelEfficiency());
|
||||
BlockStorage.addBlockInfo(b, "fuel", String.valueOf(fuelLevel));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -809,12 +799,15 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent
|
||||
|
||||
protected void move(Block b, BlockFace face, Block block) {
|
||||
if (block.getY() > 0 && block.getY() < block.getWorld().getMaxHeight() && (block.getType() == Material.AIR || block.getType() == Material.CAVE_AIR)) {
|
||||
block.setType(Material.PLAYER_HEAD);
|
||||
Rotatable blockData = (Rotatable) block.getBlockData();
|
||||
blockData.setRotation(face.getOppositeFace());
|
||||
block.setBlockData(blockData);
|
||||
BlockData blockData = Material.PLAYER_HEAD.createBlockData(data -> {
|
||||
if (data instanceof Rotatable) {
|
||||
Rotatable rotatable = ((Rotatable) data);
|
||||
rotatable.setRotation(face.getOppositeFace());
|
||||
}
|
||||
});
|
||||
|
||||
SkullBlock.setFromBase64(block, texture);
|
||||
block.setBlockData(blockData);
|
||||
Slimefun.runSync(() -> SkullBlock.setFromBase64(block, texture));
|
||||
|
||||
b.setType(Material.AIR);
|
||||
BlockStorage.moveBlockInfo(b.getLocation(), block.getLocation());
|
||||
|
@ -11,11 +11,15 @@ import java.util.logging.Level;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.config.Config;
|
||||
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.ChatUtils;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
|
||||
public final class Script {
|
||||
@ -105,6 +109,30 @@ public final class Script {
|
||||
return !upvoters.contains(p.getUniqueId().toString()) && !downvoters.contains(p.getUniqueId().toString());
|
||||
}
|
||||
|
||||
ItemStack getAsItemStack(ProgrammableAndroid android, Player p) {
|
||||
List<String> lore = new LinkedList<>();
|
||||
lore.add("&7by &r" + getAuthor());
|
||||
lore.add("");
|
||||
lore.add("&7Downloads: &r" + getDownloads());
|
||||
lore.add("&7Rating: " + getScriptRatingPercentage());
|
||||
lore.add("&a" + getUpvotes() + " \u263A &7| &4\u2639 " + getDownvotes());
|
||||
lore.add("");
|
||||
lore.add("&eLeft Click &rto download this Script");
|
||||
lore.add("&4(This will override your current Script)");
|
||||
|
||||
if (canRate(p)) {
|
||||
lore.add("&eShift + Left Click &rto leave a positive Rating");
|
||||
lore.add("&eShift + Right Click &rto leave a negative Rating");
|
||||
}
|
||||
|
||||
return new CustomItem(android.getItem(), "&b" + getName(), lore.toArray(new String[0]));
|
||||
}
|
||||
|
||||
private String getScriptRatingPercentage() {
|
||||
float percentage = getRating();
|
||||
return NumberUtils.getColorFromPercentage(percentage) + String.valueOf(percentage) + ChatColor.RESET + "% ";
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the amount of upvotes this {@link Script} has received.
|
||||
*
|
||||
|
@ -7,12 +7,13 @@ import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.blocks.Vein;
|
||||
import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections;
|
||||
import io.github.thebusybiscuit.cscorelib2.materials.MaterialConverter;
|
||||
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
@ -24,6 +25,8 @@ import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
|
||||
|
||||
public abstract class WoodcutterAndroid extends ProgrammableAndroid {
|
||||
|
||||
private static final int MAX_REACH = 160;
|
||||
|
||||
public WoodcutterAndroid(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
||||
super(category, item, recipeType, recipe);
|
||||
}
|
||||
@ -35,14 +38,17 @@ public abstract class WoodcutterAndroid extends ProgrammableAndroid {
|
||||
|
||||
@Override
|
||||
protected boolean chopTree(Block b, BlockMenu menu, BlockFace face) {
|
||||
if (MaterialCollections.getAllLogs().contains(b.getRelative(face).getType())) {
|
||||
List<Block> list = Vein.find(b.getRelative(face), 180, block -> MaterialCollections.getAllLogs().contains(block.getType()));
|
||||
Block target = b.getRelative(face);
|
||||
|
||||
if (Tag.LOGS.isTagged(target.getType())) {
|
||||
List<Block> list = Vein.find(target, MAX_REACH, block -> Tag.LOGS.isTagged(block.getType()));
|
||||
|
||||
if (!list.isEmpty()) {
|
||||
Block log = list.get(list.size() - 1);
|
||||
log.getWorld().playEffect(log.getLocation(), Effect.STEP_SOUND, log.getType());
|
||||
|
||||
if (SlimefunPlugin.getProtectionManager().hasPermission(Bukkit.getOfflinePlayer(UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner"))), log.getLocation(), ProtectableAction.BREAK_BLOCK)) {
|
||||
OfflinePlayer owner = Bukkit.getOfflinePlayer(UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")));
|
||||
if (SlimefunPlugin.getProtectionManager().hasPermission(owner, log.getLocation(), ProtectableAction.BREAK_BLOCK)) {
|
||||
breakLog(log, b, menu, face);
|
||||
}
|
||||
|
||||
|
@ -5,10 +5,10 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class EnderBackpack extends SimpleSlimefunItem<ItemUseHandler> implements NotPlaceable {
|
||||
|
@ -5,13 +5,13 @@ import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.api.player.PlayerBackpack;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.BackpackListener;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
/**
|
||||
|
@ -19,12 +19,12 @@ import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
|
||||
import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections;
|
||||
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockDispenseHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockDispenseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
@ -20,12 +20,12 @@ import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections;
|
||||
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
|
||||
import io.github.thebusybiscuit.cscorelib2.scheduling.TaskQueue;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
|
@ -17,12 +17,12 @@ import org.bukkit.inventory.ItemStack;
|
||||
import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections;
|
||||
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
@ -30,14 +30,14 @@ public class EnhancedFurnace extends SimpleSlimefunItem<BlockTicker> {
|
||||
|
||||
private final int speed;
|
||||
private final int efficiency;
|
||||
private final int fortune;
|
||||
private final int fortuneLevel;
|
||||
|
||||
public EnhancedFurnace(Category category, int speed, int efficiency, int fortune, SlimefunItemStack item, ItemStack[] recipe) {
|
||||
super(category, item, RecipeType.ENHANCED_CRAFTING_TABLE, recipe);
|
||||
|
||||
this.speed = speed - 1;
|
||||
this.efficiency = efficiency - 1;
|
||||
this.fortune = fortune - 1;
|
||||
this.fortuneLevel = fortune - 1;
|
||||
}
|
||||
|
||||
public int getSpeed() {
|
||||
@ -49,11 +49,8 @@ public class EnhancedFurnace extends SimpleSlimefunItem<BlockTicker> {
|
||||
}
|
||||
|
||||
public int getOutput() {
|
||||
int bonus = this.fortune;
|
||||
bonus = ThreadLocalRandom.current().nextInt(bonus + 2) - 1;
|
||||
if (bonus <= 0) bonus = 0;
|
||||
bonus++;
|
||||
return bonus;
|
||||
int bonus = ThreadLocalRandom.current().nextInt(fortuneLevel + 2);
|
||||
return 1 + bonus;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -11,6 +11,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
|
||||
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
|
||||
import io.github.thebusybiscuit.cscorelib2.math.DoubleHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.ChatUtils;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.holograms.SimpleHologram;
|
||||
@ -21,7 +22,6 @@ 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.UnregisterReason;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
|
@ -2,24 +2,24 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.blocks;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.RainbowTickHandler;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.RainbowTicker;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class RainbowBlock extends SimpleSlimefunItem<RainbowTicker> {
|
||||
public class RainbowBlock extends SimpleSlimefunItem<RainbowTickHandler> {
|
||||
|
||||
private final RainbowTicker ticker;
|
||||
private final RainbowTickHandler ticker;
|
||||
|
||||
public RainbowBlock(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput, RainbowTicker ticker) {
|
||||
public RainbowBlock(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput, RainbowTickHandler ticker) {
|
||||
super(category, item, recipeType, recipe, recipeOutput);
|
||||
|
||||
this.ticker = ticker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RainbowTicker getItemHandler() {
|
||||
public RainbowTickHandler getItemHandler() {
|
||||
return ticker;
|
||||
}
|
||||
|
||||
|
@ -8,12 +8,12 @@ import org.bukkit.block.CreatureSpawner;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockPlaceHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class RepairedSpawner extends SimpleSlimefunItem<BlockPlaceHandler> {
|
||||
@ -24,7 +24,7 @@ public class RepairedSpawner extends SimpleSlimefunItem<BlockPlaceHandler> {
|
||||
|
||||
@Override
|
||||
public BlockPlaceHandler getItemHandler() {
|
||||
return (e, item) -> {
|
||||
return (p, e, item) -> {
|
||||
// We need to explicitly ignore the lore here
|
||||
if (SlimefunUtils.isItemSimilar(item, SlimefunItems.REPAIRED_SPAWNER, false, false)) {
|
||||
Optional<EntityType> entity = getEntityType(item);
|
||||
|
@ -4,10 +4,10 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class UnplaceableBlock extends SimpleSlimefunItem<ItemUseHandler> implements NotPlaceable {
|
||||
|
@ -5,11 +5,11 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.core.networks.cargo.CargoNet;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class CargoConnectorNode extends SimpleSlimefunItem<BlockUseHandler> {
|
||||
|
@ -8,6 +8,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.core.networks.cargo.CargoNet;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.holograms.SimpleHologram;
|
||||
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
|
||||
@ -15,7 +16,6 @@ import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
|
@ -160,7 +160,10 @@ public class ReactorAccessPort extends SlimefunItem {
|
||||
Location reactorL = new Location(l.getWorld(), l.getX(), l.getY() - 3, l.getZ());
|
||||
|
||||
SlimefunItem item = BlockStorage.check(reactorL.getBlock());
|
||||
if (item instanceof Reactor) return BlockStorage.getInventory(reactorL);
|
||||
|
||||
if (item instanceof Reactor) {
|
||||
return BlockStorage.getInventory(reactorL);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@ -5,10 +5,10 @@ import org.bukkit.inventory.ItemStack;
|
||||
import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent;
|
||||
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class BasicCircuitBoard extends SimpleSlimefunItem<ItemUseHandler> implements NotPlaceable {
|
||||
|
@ -11,12 +11,12 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.Rechargeable;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockBreakHandler;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class MultiTool extends SlimefunItem implements Rechargeable {
|
||||
|
@ -7,11 +7,11 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.math.DoubleHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
|
||||
|
||||
|
@ -7,13 +7,13 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNetComponentType;
|
||||
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.GeneratorTicker;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
@ -68,11 +68,18 @@ public abstract class SolarGenerator extends SimpleSlimefunItem<GeneratorTicker>
|
||||
return 0;
|
||||
}
|
||||
|
||||
boolean isDaytime = isDaytime(world);
|
||||
|
||||
// Performance optimization for daytime-only solar generators
|
||||
if (!isDaytime && getNightEnergy() < 0.1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!world.isChunkLoaded(l.getBlockX() >> 4, l.getBlockZ() >> 4) || l.getBlock().getLightFromSky() != 15) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (world.getTime() < 12300 || world.getTime() > 23850) {
|
||||
if (isDaytime) {
|
||||
return getDayEnergy();
|
||||
}
|
||||
|
||||
@ -86,6 +93,19 @@ public abstract class SolarGenerator extends SimpleSlimefunItem<GeneratorTicker>
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns whether a given {@link World} has daytime.
|
||||
* It will also return false if a thunderstorm is active in this world.
|
||||
*
|
||||
* @param world
|
||||
* The {@link World} to check
|
||||
*
|
||||
* @return Whether the given {@link World} has daytime and no active thunderstorm
|
||||
*/
|
||||
private boolean isDaytime(World world) {
|
||||
return !world.hasStorm() && !world.isThundering() && (world.getTime() < 12300 || world.getTime() > 23850);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preRegister() {
|
||||
super.preRegister();
|
||||
|
@ -57,12 +57,12 @@ public abstract class AutoAnvil extends AContainer {
|
||||
if (timeleft > 0) {
|
||||
ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar());
|
||||
|
||||
if (ChargableBlock.isChargable(b)) {
|
||||
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) return;
|
||||
ChargableBlock.addCharge(b, -getEnergyConsumption());
|
||||
progress.put(b, timeleft - 1);
|
||||
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
|
||||
return;
|
||||
}
|
||||
else progress.put(b, timeleft - 1);
|
||||
|
||||
ChargableBlock.addCharge(b, -getEnergyConsumption());
|
||||
progress.put(b, timeleft - 1);
|
||||
}
|
||||
else {
|
||||
menu.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "));
|
||||
|
@ -68,17 +68,12 @@ public abstract class AutoBrewer extends AContainer {
|
||||
if (timeleft > 0) {
|
||||
ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar());
|
||||
|
||||
if (ChargableBlock.isChargable(b)) {
|
||||
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
|
||||
return;
|
||||
}
|
||||
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ChargableBlock.addCharge(b, -getEnergyConsumption());
|
||||
progress.put(b, timeleft - 1);
|
||||
}
|
||||
else {
|
||||
progress.put(b, timeleft - 1);
|
||||
}
|
||||
ChargableBlock.addCharge(b, -getEnergyConsumption());
|
||||
progress.put(b, timeleft - 1);
|
||||
}
|
||||
else {
|
||||
menu.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "));
|
||||
|
@ -78,15 +78,12 @@ public class AutoDisenchanter extends AContainer {
|
||||
if (timeleft > 0) {
|
||||
ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar());
|
||||
|
||||
if (ChargableBlock.isChargable(b)) {
|
||||
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ChargableBlock.addCharge(b, -getEnergyConsumption());
|
||||
progress.put(b, timeleft - 1);
|
||||
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
|
||||
return;
|
||||
}
|
||||
else progress.put(b, timeleft - 1);
|
||||
|
||||
ChargableBlock.addCharge(b, -getEnergyConsumption());
|
||||
progress.put(b, timeleft - 1);
|
||||
}
|
||||
else {
|
||||
menu.replaceExistingItem(22, new CustomItem(Material.BLACK_STAINED_GLASS_PANE, " "));
|
||||
|
@ -104,12 +104,12 @@ public class AutoDrier extends AContainer implements RecipeDisplayItem {
|
||||
if (timeleft > 0) {
|
||||
ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar());
|
||||
|
||||
if (ChargableBlock.isChargable(b)) {
|
||||
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) return;
|
||||
ChargableBlock.addCharge(b, -getEnergyConsumption());
|
||||
progress.put(b, timeleft - 1);
|
||||
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
|
||||
return;
|
||||
}
|
||||
else progress.put(b, timeleft - 1);
|
||||
|
||||
ChargableBlock.addCharge(b, -getEnergyConsumption());
|
||||
progress.put(b, timeleft - 1);
|
||||
}
|
||||
else {
|
||||
menu.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "));
|
||||
|
@ -67,17 +67,12 @@ public class AutoEnchanter extends AContainer {
|
||||
if (timeleft > 0) {
|
||||
ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar());
|
||||
|
||||
if (ChargableBlock.isChargable(b)) {
|
||||
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
|
||||
return;
|
||||
}
|
||||
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ChargableBlock.addCharge(b, -getEnergyConsumption());
|
||||
progress.put(b, timeleft - 1);
|
||||
}
|
||||
else {
|
||||
progress.put(b, timeleft - 1);
|
||||
}
|
||||
ChargableBlock.addCharge(b, -getEnergyConsumption());
|
||||
progress.put(b, timeleft - 1);
|
||||
}
|
||||
else {
|
||||
menu.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "));
|
||||
|
@ -59,18 +59,14 @@ public abstract class ElectricDustWasher extends AContainer {
|
||||
if (timeleft > 0 && getSpeed() < 10) {
|
||||
ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar());
|
||||
|
||||
if (ChargableBlock.isChargable(b)) {
|
||||
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
|
||||
return;
|
||||
}
|
||||
ChargableBlock.addCharge(b, -getEnergyConsumption());
|
||||
progress.put(b, timeleft - 1);
|
||||
}
|
||||
else {
|
||||
progress.put(b, timeleft - 1);
|
||||
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ChargableBlock.addCharge(b, -getEnergyConsumption());
|
||||
progress.put(b, timeleft - 1);
|
||||
}
|
||||
else if (ChargableBlock.isChargable(b)) {
|
||||
else {
|
||||
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
|
||||
return;
|
||||
}
|
||||
|
@ -63,19 +63,14 @@ public abstract class ElectricGoldPan extends AContainer implements RecipeDispla
|
||||
if (timeleft > 0 && getSpeed() < 10) {
|
||||
ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar());
|
||||
|
||||
if (ChargableBlock.isChargable(b)) {
|
||||
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
|
||||
return;
|
||||
}
|
||||
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ChargableBlock.addCharge(b, -getEnergyConsumption());
|
||||
progress.put(b, timeleft - 1);
|
||||
}
|
||||
else {
|
||||
progress.put(b, timeleft - 1);
|
||||
}
|
||||
ChargableBlock.addCharge(b, -getEnergyConsumption());
|
||||
progress.put(b, timeleft - 1);
|
||||
}
|
||||
else if (ChargableBlock.isChargable(b)) {
|
||||
else {
|
||||
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
|
||||
return;
|
||||
}
|
||||
|
@ -53,10 +53,9 @@ public class ElectricIngotPulverizer extends AContainer implements RecipeDisplay
|
||||
|
||||
@Override
|
||||
protected void registerDefaultRecipes() {
|
||||
// this is an extra recipe on top of PostSetup.loadSmelteryRecipes() for converting Vanilla Gold Ingot to Slimefun gold dust
|
||||
registerRecipe(3,
|
||||
new ItemStack(Material.GOLD_INGOT),
|
||||
SlimefunItems.GOLD_DUST);
|
||||
// this is an extra recipe on top of PostSetup.loadSmelteryRecipes() for converting
|
||||
// Vanilla Gold Ingot to Slimefun gold dust
|
||||
registerRecipe(3, new ItemStack(Material.GOLD_INGOT), SlimefunItems.GOLD_DUST);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -148,17 +148,12 @@ public abstract class HeatedPressureChamber extends AContainer {
|
||||
if (timeleft > 0) {
|
||||
ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar());
|
||||
|
||||
if (ChargableBlock.isChargable(b)) {
|
||||
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
|
||||
return;
|
||||
}
|
||||
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ChargableBlock.addCharge(b, -getEnergyConsumption());
|
||||
progress.put(b, timeleft - 1);
|
||||
}
|
||||
else {
|
||||
progress.put(b, timeleft - 1);
|
||||
}
|
||||
ChargableBlock.addCharge(b, -getEnergyConsumption());
|
||||
progress.put(b, timeleft - 1);
|
||||
}
|
||||
else {
|
||||
menu.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "));
|
||||
|
@ -278,7 +278,7 @@ public abstract class Reactor extends AbstractEnergyProvider {
|
||||
|
||||
if (timeleft > 0) {
|
||||
int produced = getEnergyProduction();
|
||||
int space = ChargableBlock.getMaxCharge(l) - charge;
|
||||
int space = getCapacity() - charge;
|
||||
|
||||
if (space >= produced || !ReactorMode.GENERATOR.toString().equals(BlockStorage.getLocationInfo(l, MODE))) {
|
||||
progress.put(l, timeleft - 1);
|
||||
@ -347,7 +347,7 @@ public abstract class Reactor extends AbstractEnergyProvider {
|
||||
}
|
||||
|
||||
private void createByproduct(Location l, BlockMenu inv, BlockMenu accessPort) {
|
||||
inv.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "));
|
||||
inv.replaceExistingItem(22, new CustomItem(Material.BLACK_STAINED_GLASS_PANE, " "));
|
||||
|
||||
if (processing.get(l).getOutput() != null) {
|
||||
inv.pushItem(processing.get(l).getOutput(), getOutputSlots());
|
||||
|
@ -5,11 +5,11 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemConsumptionHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemConsumptionHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
/**
|
||||
|
@ -7,13 +7,13 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemConsumptionHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.core.services.LocalizationService;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemConsumptionHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
/**
|
||||
|
@ -9,10 +9,10 @@ import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class MagicSugar extends SimpleSlimefunItem<ItemUseHandler> {
|
||||
|
@ -3,10 +3,10 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.food;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemConsumptionHandler;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemConsumptionHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
/**
|
||||
|
@ -4,10 +4,10 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemConsumptionHandler;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemConsumptionHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
|
@ -3,11 +3,11 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.geo;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class GEOScanner extends SimpleSlimefunItem<BlockUseHandler> {
|
||||
|
@ -5,11 +5,11 @@ import java.util.Optional;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class PortableGEOScanner extends SimpleSlimefunItem<ItemUseHandler> {
|
||||
|
@ -20,6 +20,7 @@ import io.github.thebusybiscuit.cscorelib2.chat.json.ClickEvent;
|
||||
import io.github.thebusybiscuit.cscorelib2.chat.json.CustomBookInterface;
|
||||
import io.github.thebusybiscuit.cscorelib2.chat.json.HoverEvent;
|
||||
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.ChatUtils;
|
||||
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu;
|
||||
@ -29,7 +30,6 @@ 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.UnregisterReason;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
@ -2,11 +2,11 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.gps;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class GPSControlPanel extends SimpleSlimefunItem<BlockUseHandler> {
|
||||
|
@ -4,11 +4,11 @@ import org.bukkit.block.Block;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class GPSMarkerTool extends SimpleSlimefunItem<ItemUseHandler> implements NotPlaceable {
|
||||
|
@ -3,10 +3,10 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.gps;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.RainbowTickHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.RainbowBlock;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.RainbowTicker;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
/**
|
||||
@ -17,12 +17,12 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
*
|
||||
* @see Teleporter
|
||||
* @see RainbowBlock
|
||||
* @see RainbowTicker
|
||||
* @see RainbowTickHandler
|
||||
*/
|
||||
public class TeleporterPylon extends RainbowBlock {
|
||||
|
||||
public TeleporterPylon(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) {
|
||||
super(category, item, recipeType, recipe, recipeOutput, new RainbowTicker(Material.CYAN_STAINED_GLASS, Material.PURPLE_STAINED_GLASS));
|
||||
super(category, item, recipeType, recipe, recipeOutput, new RainbowTickHandler(Material.CYAN_STAINED_GLASS, Material.PURPLE_STAINED_GLASS));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,10 +11,10 @@ import org.bukkit.event.Event.Result;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class InfernalBonemeal extends SimpleSlimefunItem<ItemUseHandler> {
|
||||
|
@ -5,12 +5,12 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
/**
|
||||
|
@ -14,12 +14,12 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
|
||||
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
|
||||
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.core.researching.Research;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class KnowledgeTome extends SimpleSlimefunItem<ItemUseHandler> {
|
||||
|
@ -6,12 +6,12 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class MagicEyeOfEnder extends SimpleSlimefunItem<ItemUseHandler> {
|
||||
|
@ -8,12 +8,12 @@ import org.bukkit.entity.ZombieVillager;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.EntityInteractHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.EntityInteractHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
/**
|
||||
|
@ -12,6 +12,7 @@ import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.Soulbound;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemDropHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||
@ -19,7 +20,6 @@ import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemDropHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
|
@ -17,13 +17,13 @@ import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
|
||||
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
/**
|
||||
|
@ -7,11 +7,11 @@ import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
/**
|
||||
|
@ -3,12 +3,12 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.magical;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
/**
|
||||
|
@ -9,11 +9,11 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class WindStaff extends SimpleSlimefunItem<ItemUseHandler> {
|
||||
|
@ -10,10 +10,10 @@ import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class Bandage extends SimpleSlimefunItem<ItemUseHandler> {
|
||||
|
@ -3,10 +3,10 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.medical;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemConsumptionHandler;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemConsumptionHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class Medicine extends SimpleSlimefunItem<ItemConsumptionHandler> {
|
||||
|
@ -10,10 +10,10 @@ import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class Rag extends SimpleSlimefunItem<ItemUseHandler> {
|
||||
|
@ -9,10 +9,10 @@ import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class Splint extends SimpleSlimefunItem<ItemUseHandler> {
|
||||
|
@ -8,10 +8,10 @@ import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class Vitamins extends SimpleSlimefunItem<ItemUseHandler> {
|
||||
|
@ -48,6 +48,9 @@ public class OreCrusher extends MultiBlockMachine {
|
||||
if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_16)) {
|
||||
displayRecipes.add(new ItemStack(Material.NETHER_GOLD_ORE));
|
||||
displayRecipes.add(doubleOres.getGoldNuggets());
|
||||
|
||||
displayRecipes.add(new ItemStack(Material.GILDED_BLACKSTONE));
|
||||
displayRecipes.add(doubleOres.getGoldNuggets());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,11 +7,11 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.FireworkUtils;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockPlaceHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class ChristmasPresent extends SimpleSlimefunItem<BlockPlaceHandler> implements NotPlaceable {
|
||||
@ -26,7 +26,7 @@ public class ChristmasPresent extends SimpleSlimefunItem<BlockPlaceHandler> impl
|
||||
|
||||
@Override
|
||||
public BlockPlaceHandler getItemHandler() {
|
||||
return (e, item) -> {
|
||||
return (p, e, item) -> {
|
||||
if (isItem(item)) {
|
||||
e.setCancelled(true);
|
||||
|
||||
@ -34,7 +34,7 @@ public class ChristmasPresent extends SimpleSlimefunItem<BlockPlaceHandler> impl
|
||||
ItemUtils.consumeItem(item, false);
|
||||
}
|
||||
|
||||
FireworkUtils.launchRandom(e.getPlayer(), 3);
|
||||
FireworkUtils.launchRandom(p, 3);
|
||||
|
||||
ItemStack gift = gifts[ThreadLocalRandom.current().nextInt(gifts.length)].clone();
|
||||
e.getBlockPlaced().getWorld().dropItemNaturally(e.getBlockPlaced().getLocation(), gift);
|
||||
|
@ -7,12 +7,12 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.FireworkUtils;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
/**
|
||||
|
@ -13,6 +13,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
* @author TheBusyBiscuit
|
||||
*
|
||||
* @see ExplosiveShovel
|
||||
* @see ExplosiveTool
|
||||
*
|
||||
*/
|
||||
public class ExplosivePickaxe extends ExplosiveTool {
|
||||
|
@ -3,7 +3,6 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.tools;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -22,6 +21,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
* @author Linox
|
||||
*
|
||||
* @see ExplosivePickaxe
|
||||
* @see ExplosiveTool
|
||||
*
|
||||
*/
|
||||
public class ExplosiveShovel extends ExplosiveTool {
|
||||
@ -36,14 +36,8 @@ public class ExplosiveShovel extends ExplosiveTool {
|
||||
SlimefunPlugin.getProtectionManager().logAction(p, b, ProtectableAction.BREAK_BLOCK);
|
||||
|
||||
b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType());
|
||||
b.breakNaturally(item);
|
||||
|
||||
for (ItemStack drop : b.getDrops(getItem())) {
|
||||
if (drop != null) {
|
||||
b.getWorld().dropItemNaturally(b.getLocation(), drop);
|
||||
}
|
||||
}
|
||||
|
||||
b.setType(Material.AIR);
|
||||
damageItem(p, item);
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
|
||||
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.DamageableItem;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
@ -26,7 +27,6 @@ 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.UnregisterReason;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockBreakHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
@ -53,23 +53,27 @@ class ExplosiveTool extends SimpleSlimefunItem<BlockBreakHandler> implements Not
|
||||
@Override
|
||||
public boolean onBlockBreak(BlockBreakEvent e, ItemStack item, int fortune, List<ItemStack> drops) {
|
||||
if (isItem(item)) {
|
||||
if (Slimefun.hasUnlocked(e.getPlayer(), ExplosiveTool.this, true)) {
|
||||
e.getBlock().getWorld().createExplosion(e.getBlock().getLocation(), 0.0F);
|
||||
e.getBlock().getWorld().playSound(e.getBlock().getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 0.2F, 1F);
|
||||
Player p = e.getPlayer();
|
||||
if (Slimefun.hasUnlocked(p, ExplosiveTool.this, true)) {
|
||||
Block b = e.getBlock();
|
||||
|
||||
List<Block> blocks = findBlocks(e.getBlock());
|
||||
b.getWorld().createExplosion(b.getLocation(), 0.0F);
|
||||
b.getWorld().playSound(b.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 0.2F, 1F);
|
||||
|
||||
List<Block> blocks = findBlocks(b);
|
||||
if (callExplosionEvent.getValue().booleanValue()) {
|
||||
BlockExplodeEvent blockExplodeEvent = new BlockExplodeEvent(e.getBlock(), blocks, 0);
|
||||
BlockExplodeEvent blockExplodeEvent = new BlockExplodeEvent(b, blocks, 0);
|
||||
Bukkit.getServer().getPluginManager().callEvent(blockExplodeEvent);
|
||||
|
||||
if (!blockExplodeEvent.isCancelled()) {
|
||||
blockExplodeEvent.blockList().forEach(b -> breakBlock(e.getPlayer(), item, b, fortune, drops));
|
||||
for (Block block : blockExplodeEvent.blockList()) {
|
||||
breakBlock(p, item, block, fortune, drops);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (Block b : blocks) {
|
||||
breakBlock(e.getPlayer(), item, b, fortune, drops);
|
||||
for (Block block : blocks) {
|
||||
breakBlock(p, item, block, fortune, drops);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import io.github.thebusybiscuit.cscorelib2.collections.RandomizedSet;
|
||||
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
|
||||
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.ElectricGoldPan;
|
||||
@ -23,7 +24,6 @@ import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
/**
|
||||
|
@ -13,11 +13,11 @@ import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class GrapplingHook extends SimpleSlimefunItem<ItemUseHandler> {
|
||||
@ -55,14 +55,15 @@ public class GrapplingHook extends SimpleSlimefunItem<ItemUseHandler> {
|
||||
arrow.setShooter(p);
|
||||
arrow.setVelocity(direction);
|
||||
|
||||
Bat b = (Bat) p.getWorld().spawnEntity(p.getLocation(), EntityType.BAT);
|
||||
b.setCanPickupItems(false);
|
||||
b.setAI(false);
|
||||
b.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 100000, 100000));
|
||||
b.setLeashHolder(arrow);
|
||||
Bat bat = (Bat) p.getWorld().spawnEntity(p.getLocation(), EntityType.BAT);
|
||||
bat.setCanPickupItems(false);
|
||||
bat.setAI(false);
|
||||
bat.setSilent(true);
|
||||
bat.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 100000, 100000));
|
||||
bat.setLeashHolder(arrow);
|
||||
|
||||
boolean state = item.getType() != Material.SHEARS;
|
||||
SlimefunPlugin.getGrapplingHookListener().addGrapplingHook(uuid, arrow, b, state, despawnTicks.getValue() * 20L);
|
||||
SlimefunPlugin.getGrapplingHookListener().addGrapplingHook(p, arrow, bat, state, despawnTicks.getValue());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user