1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Improved Slimefun Guide History, it now remembers category pages

This commit is contained in:
TheBusyBiscuit 2020-03-19 20:38:13 +01:00
parent afac5cc0ce
commit 84dbea4473
41 changed files with 636 additions and 551 deletions

View File

@ -54,6 +54,7 @@
* Added "Snow blocks to Ice" recipe to the Freezer
* You can now use Cooked Salmon in an Auto Drier to craft Fish Jerky
* The Lumber Axe can now strip logs too
* The Slimefun Guide can now remember what page of a Category or Minecraft Item you were on
#### Changes
* Removed some deprecated parts of the API
@ -75,6 +76,8 @@
* Fixed #1711
* Fixed Slimefun Guide showing shaped recipes incorrectly
* Fixed #1719
* Fixed death waypoints not having the correct texture
* Fixed Androids having no texture when moving
## Release Candidate 9 (07 Mar 2020)

View File

@ -86,7 +86,7 @@ public class ErrorReport {
Slimefun.getLogger().log(Level.WARNING, "");
}
catch (FileNotFoundException x) {
Slimefun.getLogger().log(Level.SEVERE, "An Error occured while saving an Error-Report for Slimefun " + SlimefunPlugin.getVersion(), x);
Slimefun.getLogger().log(Level.SEVERE, x, () -> "An Error occured while saving an Error-Report for Slimefun " + SlimefunPlugin.getVersion());
}
});
}

View File

@ -122,7 +122,7 @@ public class GPSNetwork {
public ItemStack getIcon(Map.Entry<String, Location> entry) {
Location l = entry.getValue();
if (entry.getKey().startsWith("&4Deathpoint")) {
if (entry.getKey().startsWith("player:death ")) {
return deathpointIcon;
}
else if (l.getWorld().getEnvironment() == Environment.NETHER) {
@ -164,7 +164,7 @@ public class GPSNetwork {
Location l = entry.getValue();
ItemStack globe = getIcon(entry);
menu.addItem(slot, new CustomItem(globe, entry.getKey(), "&8\u21E8 &7World: &r" + l.getWorld().getName(), "&8\u21E8 &7X: &r" + l.getX(), "&8\u21E8 &7Y: &r" + l.getY(), "&8\u21E8 &7Z: &r" + l.getZ(), "", "&8\u21E8 &cClick to delete"));
menu.addItem(slot, new CustomItem(globe, entry.getKey().replace("player:death ", ""), "&8\u21E8 &7World: &r" + l.getWorld().getName(), "&8\u21E8 &7X: &r" + l.getX(), "&8\u21E8 &7Y: &r" + l.getY(), "&8\u21E8 &7Z: &r" + l.getZ(), "", "&8\u21E8 &cClick to delete"));
menu.addMenuClickHandler(slot, (pl, slotn, item, action) -> {
String id = ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', entry.getKey())).toUpperCase().replace(' ', '_');
Config cfg = new Config(WAYPOINTS_DIRECTORY + pl.getUniqueId().toString() + ".yml");

View File

@ -65,7 +65,7 @@ public final class TeleportationManager {
Location l = entry.getValue();
ItemStack globe = network.getIcon(entry);
menu.addItem(slot, new CustomItem(globe, entry.getKey(), "", "&8\u21E8 &7" + SlimefunPlugin.getLocal().getResourceString(p, "tooltips.world") + ": &r" + l.getWorld().getName(), "&8\u21E8 &7X: &r" + l.getX(), "&8\u21E8 &7Y: &r" + l.getY(), "&8\u21E8 &7Z: &r" + l.getZ(), "&8\u21E8 &7" + SlimefunPlugin.getLocal().getMessage(p, "machines.TELEPORTER.gui.time") + ": &r" + DoubleHandler.fixDouble(0.5 * getTeleportationTime(complexity, source, l)) + "s", "", "&8\u21E8 &c" + SlimefunPlugin.getLocal().getMessage(p, "machines.TELEPORTER.gui.tooltip")));
menu.addItem(slot, new CustomItem(globe, entry.getKey().replace("player:death ", ""), "", "&8\u21E8 &7" + SlimefunPlugin.getLocal().getResourceString(p, "tooltips.world") + ": &r" + l.getWorld().getName(), "&8\u21E8 &7X: &r" + l.getX(), "&8\u21E8 &7Y: &r" + l.getY(), "&8\u21E8 &7Z: &r" + l.getZ(), "&8\u21E8 &7" + SlimefunPlugin.getLocal().getMessage(p, "machines.TELEPORTER.gui.time") + ": &r" + DoubleHandler.fixDouble(0.5 * getTeleportationTime(complexity, source, l)) + "s", "", "&8\u21E8 &c" + SlimefunPlugin.getLocal().getMessage(p, "machines.TELEPORTER.gui.tooltip")));
menu.addMenuClickHandler(slot, (pl, s, item, action) -> {
pl.closeInventory();
teleport(pl.getUniqueId(), complexity, source, l, false);

View File

@ -21,7 +21,6 @@ import io.github.thebusybiscuit.slimefun4.implementation.listeners.NetworkListen
public final class NetworkManager {
private final int maxNodes;
private boolean isChestTerminalInstalled = false;
private final List<Network> networks = new LinkedList<>();
public NetworkManager(int capacity) {
@ -32,14 +31,6 @@ public final class NetworkManager {
return maxNodes;
}
public boolean isChestTerminalInstalled() {
return isChestTerminalInstalled;
}
public void setChestTerminalInstalled(boolean installed) {
isChestTerminalInstalled = installed;
}
public List<Network> getNetworkList() {
return networks;
}

View File

@ -16,7 +16,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.listeners.BackpackListe
* be opened.
*
* It holds an actual {@link Inventory} and represents the backpack on the
* level of an individual{@link ItemStack} as opposed to the class {@link SlimefunBackpack}.
* level of an individual {@link ItemStack} as opposed to the class {@link SlimefunBackpack}.
*
* @author TheBusyBiscuit
*

View File

@ -4,7 +4,6 @@ import java.io.File;
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;
@ -22,6 +21,7 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.config.Config;
import io.github.thebusybiscuit.slimefun4.api.items.HashedArmorpiece;
import io.github.thebusybiscuit.slimefun4.core.guide.GuideHistory;
import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Objects.Research;
@ -47,7 +47,7 @@ public final class PlayerProfile {
private final Set<Research> researches = new HashSet<>();
private final Map<Integer, PlayerBackpack> backpacks = new HashMap<>();
private final LinkedList<Object> guideHistory = new LinkedList<>();
private final GuideHistory guideHistory = new GuideHistory(this);
private final HashedArmorpiece[] armor = { new HashedArmorpiece(), new HashedArmorpiece(), new HashedArmorpiece(), new HashedArmorpiece() };
@ -222,7 +222,7 @@ public final class PlayerProfile {
return Bukkit.getPlayer(getUUID());
}
public LinkedList<Object> getGuideHistory() {
public GuideHistory getGuideHistory() {
return guideHistory;
}

View File

@ -43,7 +43,7 @@ class GiveCommand extends SubCommand {
SlimefunItem sfItem = SlimefunItem.getByID(args[2].toUpperCase());
if (sfItem != null) {
int amount = parseAmount(sender, args);
int amount = parseAmount(args);
if (amount > 0) {
SlimefunPlugin.getLocal().sendMessage(p, "messages.given-item", true, msg -> msg.replace(PLACEHOLDER_ITEM, sfItem.getItemName()).replace(PLACEHOLDER_AMOUNT, String.valueOf(amount)));
@ -61,7 +61,7 @@ class GiveCommand extends SubCommand {
else SlimefunPlugin.getLocal().sendMessage(sender, "messages.no-permission", true);
}
private int parseAmount(CommandSender sender, String[] args) {
private int parseAmount(String[] args) {
int amount = 1;
if (args.length == 4) {

View File

@ -0,0 +1,25 @@
package io.github.thebusybiscuit.slimefun4.core.guide;
class GuideEntry<T> {
private final T object;
private int page;
GuideEntry(T object, int page) {
this.object = object;
this.page = page;
}
public T getIndexedObject() {
return object;
}
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
}

View File

@ -0,0 +1,111 @@
package io.github.thebusybiscuit.slimefun4.core.guide;
import java.util.Deque;
import java.util.LinkedList;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
/**
* {@link GuideHistory} represents the browsing history of a {@link Player} through the
* {@link SlimefunGuide}.
*
* @author TheBusyBiscuit
*
* @see SlimefunGuide
* @see PlayerProfile
*
*/
public class GuideHistory {
private final PlayerProfile profile;
private final Deque<GuideEntry<?>> queue = new LinkedList<>();
public GuideHistory(PlayerProfile profile) {
this.profile = profile;
}
public void clear() {
queue.clear();
}
public void add(Category category, int page) {
refresh(category, page);
}
public void add(ItemStack item, int page) {
refresh(item, page);
}
public void add(SlimefunItem item) {
queue.add(new GuideEntry<>(item, 0));
}
public void add(String searchTerm) {
queue.add(new GuideEntry<>(searchTerm, 0));
}
private <T> void refresh(T object, int page) {
GuideEntry<?> lastEntry = getLastEntry(false);
if (lastEntry != null && lastEntry.getIndexedObject() == object) {
lastEntry.setPage(page);
}
else {
queue.add(new GuideEntry<>(object, page));
}
}
public int size() {
return queue.size();
}
/**
* Retrieves the last page in the {@link SlimefunGuide} that was visited by a {@link Player}.
* Optionally also rewinds the history back to that entry.
*
* @param remove
* Whether to remove the current entry so it moves back to the entry returned.
* @return The last Guide Entry that was saved to the given Players guide history.
*/
private GuideEntry<?> getLastEntry(boolean remove) {
if (remove && !queue.isEmpty()) {
queue.removeLast();
}
return queue.isEmpty() ? null : queue.getLast();
}
public void openLastEntry(SlimefunGuideImplementation guide, boolean survival) {
GuideEntry<?> entry = getLastEntry(false);
open(guide, entry, survival);
}
public void goBack(SlimefunGuideImplementation guide, boolean survival) {
GuideEntry<?> entry = getLastEntry(true);
open(guide, entry, survival);
}
private <T> void open(SlimefunGuideImplementation guide, GuideEntry<T> entry, boolean survival) {
if (entry == null) {
guide.openMainMenu(profile, survival, 1);
}
else if (entry.getIndexedObject() instanceof Category) {
guide.openCategory(profile, (Category) entry.getIndexedObject(), survival, entry.getPage());
}
else if (entry.getIndexedObject() instanceof SlimefunItem) {
guide.displayItem(profile, (SlimefunItem) entry.getIndexedObject(), false);
}
else if (entry.getIndexedObject() instanceof String) {
guide.openSearch(profile, (String) entry.getIndexedObject(), survival, false);
}
else if (entry.getIndexedObject() instanceof ItemStack) {
guide.displayItem(profile, (ItemStack) entry.getIndexedObject(), entry.getPage(), false);
}
}
}

View File

@ -87,13 +87,12 @@ public final class SlimefunGuide {
if (!SlimefunPlugin.getWhitelist().getBoolean(p.getWorld().getName() + ".enabled")) return;
if (!SlimefunPlugin.getWhitelist().getBoolean(p.getWorld().getName() + ".enabled-items.SLIMEFUN_GUIDE")) return;
SlimefunGuideImplementation guide = SlimefunPlugin.getRegistry().getGuideLayout(layout);
Object last = null;
Optional<PlayerProfile> profile = PlayerProfile.find(p);
if (profile.isPresent()) {
last = guide.getLastEntry(profile.get(), false);
guide.openEntry(profile.get(), last, true);
Optional<PlayerProfile> optional = PlayerProfile.find(p);
if (optional.isPresent()) {
PlayerProfile profile = optional.get();
SlimefunGuideImplementation guide = SlimefunPlugin.getRegistry().getGuideLayout(layout);
profile.getGuideHistory().openLastEntry(guide, true);
}
else {
openMainMenuAsync(p, true, layout, 1);
@ -120,7 +119,7 @@ public final class SlimefunGuide {
}
public static void displayItem(PlayerProfile profile, ItemStack item, boolean addToHistory) {
SlimefunPlugin.getRegistry().getGuideLayout(SlimefunGuideLayout.CHEST).displayItem(profile, item, addToHistory);
SlimefunPlugin.getRegistry().getGuideLayout(SlimefunGuideLayout.CHEST).displayItem(profile, item, 0, addToHistory);
}
public static void displayItem(PlayerProfile profile, SlimefunItem item, boolean addToHistory) {

View File

@ -1,8 +1,5 @@
package io.github.thebusybiscuit.slimefun4.core.guide;
import java.util.LinkedList;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
@ -10,7 +7,6 @@ import io.github.thebusybiscuit.slimefun4.implementation.guide.BookSlimefunGuide
import io.github.thebusybiscuit.slimefun4.implementation.guide.ChestSlimefunGuide;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.GuideHandler;
/**
* This interface is used for the different implementations that add behaviour
@ -48,46 +44,8 @@ public interface SlimefunGuideImplementation {
void openSearch(PlayerProfile profile, String input, boolean survival, boolean addToHistory);
void displayItem(PlayerProfile profile, ItemStack item, boolean addToHistory);
void displayItem(PlayerProfile profile, ItemStack item, int index, boolean addToHistory);
void displayItem(PlayerProfile profile, SlimefunItem item, boolean addToHistory);
/**
* Retrieves the last page in the {@link SlimefunGuide} that was visited by a {@link Player}.
* Optionally also rewinds the history back to that entry.
*
* @param profile
* The {@link PlayerProfile} of the {@link Player} you are querying
* @param remove
* Whether to remove the current entry so it moves back to the entry returned.
* @return The last Guide Entry that was saved to the given Players guide history.
*/
default Object getLastEntry(PlayerProfile profile, boolean remove) {
LinkedList<Object> history = profile.getGuideHistory();
if (remove && !history.isEmpty()) {
history.removeLast();
}
return history.isEmpty() ? null : history.getLast();
}
/**
* Opens the given Guide Entry to the {@link Player} of the specified {@link PlayerProfile}.
*
* @param profile
* The {@link PlayerProfile} of the {@link Player} we are opening this to
* @param entry
* The Guide Entry to open
* @param survival
* Whether this is the survival-version of the guide or cheat sheet version
*/
default void openEntry(PlayerProfile profile, Object entry, boolean survival) {
if (entry == null) openMainMenu(profile, survival, 1);
else if (entry instanceof Category) openCategory(profile, (Category) entry, survival, 1);
else if (entry instanceof SlimefunItem) displayItem(profile, (SlimefunItem) entry, false);
else if (entry instanceof GuideHandler) ((GuideHandler) entry).run(profile.getPlayer(), survival, getLayout() == SlimefunGuideLayout.BOOK);
else if (entry instanceof String) openSearch(profile, (String) entry, survival, false);
else displayItem(profile, (ItemStack) entry, false);
}
}

View File

@ -53,7 +53,7 @@ public class BackupService implements Runnable {
}
}
catch (IOException x) {
Slimefun.getLogger().log(Level.SEVERE, "An Error occured while creating a backup for Slimefun " + SlimefunPlugin.getVersion(), x);
Slimefun.getLogger().log(Level.SEVERE, x, () -> "An Error occured while creating a backup for Slimefun " + SlimefunPlugin.getVersion());
}
}
}

View File

@ -143,7 +143,7 @@ public class LocalizationService extends SlimefunLocalization {
getConfig().getConfiguration().setDefaults(config);
}
catch (IOException e) {
Slimefun.getLogger().log(Level.SEVERE, "Failed to load language file: \"" + path + "\"", e);
Slimefun.getLogger().log(Level.SEVERE, e, () -> "Failed to load language file: \"" + path + "\"");
}
save();
@ -207,7 +207,7 @@ public class LocalizationService extends SlimefunLocalization {
return config;
}
catch (IOException e) {
Slimefun.getLogger().log(Level.SEVERE, "Failed to load language file into memory: \"" + path + "\"", e);
Slimefun.getLogger().log(Level.SEVERE, e, () -> "Failed to load language file into memory: \"" + path + "\"");
return null;
}
}

View File

@ -95,7 +95,7 @@ abstract class GitHubConnector {
onSuccess(element);
}
catch (IOException x) {
Slimefun.getLogger().log(Level.SEVERE, "An Error occured while parsing GitHub-Data for Slimefun " + SlimefunPlugin.getVersion(), x);
Slimefun.getLogger().log(Level.SEVERE, x, () -> "An Error occured while parsing GitHub-Data for Slimefun " + SlimefunPlugin.getVersion());
onFailure();
}
}

View File

@ -24,6 +24,7 @@ public class ThirdPartyPluginService {
private final SlimefunPlugin plugin;
private boolean isExoticGardenInstalled = false;
private boolean isChestTerminalInstalled = false;
private boolean isEmeraldEnchantsInstalled = false;
private boolean isCoreProtectInstalled = false;
private boolean isPlaceholderAPIInstalled = false;
@ -49,10 +50,9 @@ public class ThirdPartyPluginService {
}
isExoticGardenInstalled = isPluginInstalled("ExoticGarden");
isChestTerminalInstalled = isPluginInstalled("ChestTerminal");
isEmeraldEnchantsInstalled = isPluginInstalled("EmeraldEnchants");
SlimefunPlugin.getNetworkManager().setChestTerminalInstalled(isPluginInstalled("ChestTerminal"));
// WorldEdit Hook to clear Slimefun Data upon //set 0 //cut or any other equivalent
if (isPluginInstalled("WorldEdit")) {
try {
@ -60,8 +60,10 @@ public class ThirdPartyPluginService {
new WorldEditHook();
}
catch (Exception x) {
Slimefun.getLogger().log(Level.WARNING, "Failed to hook into WorldEdit!");
String version = plugin.getServer().getPluginManager().getPlugin("WorldEdit").getDescription().getVersion();
Slimefun.getLogger().log(Level.WARNING, "Maybe consider updating WorldEdit or Slimefun?");
Slimefun.getLogger().log(Level.WARNING, "Failed to hook into WorldEdit v" + version, x);
}
}
});
@ -81,6 +83,10 @@ public class ThirdPartyPluginService {
return isExoticGardenInstalled;
}
public boolean isChestTerminalInstalled() {
return isChestTerminalInstalled;
}
public boolean isEmeraldEnchantsInstalled() {
return isEmeraldEnchantsInstalled;
}

View File

@ -21,7 +21,7 @@ class WorldEditHook {
}
@Subscribe
public void wrapForLogging(final EditSessionEvent event) {
public void wrapForLogging(EditSessionEvent event) {
event.setExtent(new AbstractDelegateExtent(event.getExtent()) {
@Override
@ -37,6 +37,7 @@ class WorldEditHook {
}
}
}
return getExtent().setBlock(pos, block);
}

View File

@ -177,7 +177,7 @@ public class BookSlimefunGuide implements SlimefunGuideImplementation {
if (category.getItems().size() < 250) {
if (survival) {
profile.getGuideHistory().add(category);
profile.getGuideHistory().add(category, page);
}
List<TellRawMessage> pages = new ArrayList<>();
@ -293,7 +293,7 @@ public class BookSlimefunGuide implements SlimefunGuideImplementation {
}
@Override
public void displayItem(PlayerProfile profile, ItemStack item, boolean addToHistory) {
public void displayItem(PlayerProfile profile, ItemStack item, int index, boolean addToHistory) {
SlimefunGuide.displayItem(profile, item, addToHistory);
}

View File

@ -2,7 +2,6 @@ package io.github.thebusybiscuit.slimefun4.implementation.guide;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@ -26,6 +25,7 @@ import io.github.thebusybiscuit.cscorelib2.recipes.MinecraftRecipe;
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
import io.github.thebusybiscuit.slimefun4.core.MultiBlock;
import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem;
import io.github.thebusybiscuit.slimefun4.core.guide.GuideHistory;
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide;
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideImplementation;
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout;
@ -172,7 +172,7 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
if (p == null) return;
if (survival) {
profile.getGuideHistory().add(category);
profile.getGuideHistory().add(category, page);
}
ChestMenu menu = create(p);
@ -336,7 +336,7 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
}
@Override
public void displayItem(PlayerProfile profile, ItemStack item, boolean addToHistory) {
public void displayItem(PlayerProfile profile, ItemStack item, int index, boolean addToHistory) {
Player p = profile.getPlayer();
if (p == null) return;
@ -359,7 +359,7 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
return;
}
showMinecraftRecipe(recipes, 0, item, profile, p, addToHistory);
showMinecraftRecipe(recipes, index, item, profile, p, addToHistory);
}
private void showMinecraftRecipe(Recipe[] recipes, int index, ItemStack item, PlayerProfile profile, Player p, boolean addToHistory) {
@ -404,6 +404,11 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
}
ChestMenu menu = create(p);
if (addToHistory) {
profile.getGuideHistory().add(item, index);
}
displayItem(menu, profile, p, item, result, recipeType, recipeItems, task, addToHistory);
if (recipes.length > 1) {
@ -413,14 +418,14 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
menu.addItem(28, ChestMenuUtils.getPreviousButton(p, index + 1, recipes.length), (pl, slot, action, stack) -> {
if (index > 0) {
showMinecraftRecipe(recipes, index - 1, item, profile, p, false);
showMinecraftRecipe(recipes, index - 1, item, profile, p, true);
}
return false;
});
menu.addItem(34, ChestMenuUtils.getNextButton(p, index + 1, recipes.length), (pl, slot, action, stack) -> {
if (index < recipes.length - 1) {
showMinecraftRecipe(recipes, index + 1, item, profile, p, false);
showMinecraftRecipe(recipes, index + 1, item, profile, p, true);
}
return false;
});
@ -455,6 +460,10 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
RecipeChoiceTask task = new RecipeChoiceTask();
if (addToHistory) {
profile.getGuideHistory().add(item);
}
displayItem(menu, profile, p, item, result, recipeType, recipe, task, addToHistory);
if (item instanceof RecipeDisplayItem) {
@ -468,18 +477,13 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
}
}
private void displayItem(ChestMenu menu, PlayerProfile profile, Player p, Object obj, ItemStack output, RecipeType recipeType, ItemStack[] recipe, RecipeChoiceTask task, boolean addToHistory) {
LinkedList<Object> history = profile.getGuideHistory();
boolean isSlimefunRecipe = obj instanceof SlimefunItem;
if (addToHistory) {
history.add(obj);
}
private void displayItem(ChestMenu menu, PlayerProfile profile, Player p, Object item, ItemStack output, RecipeType recipeType, ItemStack[] recipe, RecipeChoiceTask task, boolean addToHistory) {
boolean isSlimefunRecipe = item instanceof SlimefunItem;
addBackButton(menu, 0, p, profile, true);
MenuClickHandler clickHandler = (pl, slot, itemstack, action) -> {
displayItem(profile, itemstack, true);
displayItem(profile, itemstack, 0, true);
return false;
};
@ -487,7 +491,7 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
ItemStack recipeItem = getDisplayItem(p, isSlimefunRecipe, recipe[i]);
menu.addItem(recipeSlots[i], recipeItem, clickHandler);
if (recipeItem != null && obj instanceof MultiBlockMachine) {
if (recipeItem != null && item instanceof MultiBlockMachine) {
for (Tag<Material> tag : MultiBlock.SUPPORTED_TAGS) {
if (tag.isTagged(recipeItem.getType())) {
task.add(recipeSlots[i], tag);
@ -530,9 +534,9 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
}
private void addBackButton(ChestMenu menu, int slot, Player p, PlayerProfile profile, boolean survival) {
List<Object> playerHistory = profile.getGuideHistory();
GuideHistory history = profile.getGuideHistory();
if (survival && playerHistory.size() > 1) {
if (survival && history.size() > 1) {
menu.addItem(slot, new CustomItem(ChestMenuUtils.getBackButton(p, "", "&rLeft Click: &7Go back to previous Page", "&rShift + left Click: &7Go back to Main Menu")));
menu.addMenuClickHandler(slot, (pl, s, is, action) -> {
@ -540,8 +544,7 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
openMainMenu(profile, survival, 1);
}
else {
Object last = getLastEntry(profile, true);
openEntry(profile, last, survival);
history.goBack(this, survival);
}
return false;
});
@ -626,7 +629,7 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
if (page == 0) {
menu.addMenuClickHandler(slot, (pl, s, itemstack, action) -> {
displayItem(profile, itemstack, true);
displayItem(profile, itemstack, 0, true);
return false;
});
}

View File

@ -17,6 +17,7 @@ import org.bukkit.entity.Animals;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@ -59,7 +60,7 @@ public abstract class ProgrammableAndroid extends Android implements InventoryBl
public ProgrammableAndroid(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe);
this.texture = item.getBase64Texture().orElse(null);
this.texture = item.getSkullTexture().orElse(null);
registerDefaultFuelTypes();
new BlockMenuPreset(getID(), "Programmable Android") {
@ -399,28 +400,32 @@ public abstract class ProgrammableAndroid extends Android implements InventoryBl
ItemStack item = d.getInventory().getItem(slot);
if (item != null) {
ItemStack currentFuel = menu.getItemInSlot(43);
if (currentFuel == null) {
menu.replaceExistingItem(43, item);
d.getInventory().setItem(slot, null);
break;
}
else if (SlimefunManager.isItemSimilar(item, currentFuel, true)) {
int rest = item.getType().getMaxStackSize() - currentFuel.getAmount();
if (rest > 0) {
int amount = item.getAmount() > rest ? rest : item.getAmount();
menu.replaceExistingItem(43, new CustomItem(item, currentFuel.getAmount() + amount));
ItemUtils.consumeItem(item, amount, false);
}
break;
}
insertFuel(menu, d.getInventory(), slot, menu.getItemInSlot(43), item);
}
}
}
}
private boolean insertFuel(BlockMenu menu, Inventory dispenser, int slot, ItemStack currentFuel, ItemStack newFuel) {
if (currentFuel == null) {
menu.replaceExistingItem(43, item);
dispenser.setItem(slot, null);
return true;
}
else if (SlimefunManager.isItemSimilar(item, currentFuel, true)) {
int rest = item.getType().getMaxStackSize() - currentFuel.getAmount();
if (rest > 0) {
int amount = item.getAmount() > rest ? rest : item.getAmount();
menu.replaceExistingItem(43, new CustomItem(item, currentFuel.getAmount() + amount));
ItemUtils.consumeItem(item, amount, false);
}
return true;
}
return false;
}
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);

View File

@ -99,7 +99,7 @@ public class AdvancedCargoOutputNode extends SlimefunItem {
menu.addMenuClickHandler(41, (p, slot, item, action) -> {
int channel = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")) - 1;
if (channel < 0) {
if (SlimefunPlugin.getNetworkManager().isChestTerminalInstalled()) channel = 16;
if (SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled()) channel = 16;
else channel = 15;
}
BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channel));
@ -122,7 +122,7 @@ public class AdvancedCargoOutputNode extends SlimefunItem {
menu.addMenuClickHandler(43, (p, slot, item, action) -> {
int channeln = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")) + 1;
if (SlimefunPlugin.getNetworkManager().isChestTerminalInstalled()) {
if (SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled()) {
if (channeln > 16) channeln = 0;
}
else {

View File

@ -117,7 +117,7 @@ public class CargoInputNode extends SlimefunItem {
menu.addMenuClickHandler(41, (p, slot, item, action) -> {
int channel = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")) - 1;
if (channel < 0) {
if (SlimefunPlugin.getNetworkManager().isChestTerminalInstalled()) channel = 16;
if (SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled()) channel = 16;
else channel = 15;
}
BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channel));
@ -140,7 +140,7 @@ public class CargoInputNode extends SlimefunItem {
menu.addMenuClickHandler(43, (p, slot, item, action) -> {
int channeln = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")) + 1;
if (SlimefunPlugin.getNetworkManager().isChestTerminalInstalled()) {
if (SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled()) {
if (channeln > 16) channeln = 0;
}
else {

View File

@ -43,7 +43,7 @@ public class CargoOutputNode extends SlimefunItem {
int channel = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")) - 1;
if (channel < 0) {
if (SlimefunPlugin.getNetworkManager().isChestTerminalInstalled()) channel = 16;
if (SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled()) channel = 16;
else channel = 15;
}
@ -67,7 +67,7 @@ public class CargoOutputNode extends SlimefunItem {
menu.addMenuClickHandler(14, (p, slot, item, action) -> {
int channeln = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")) + 1;
if (SlimefunPlugin.getNetworkManager().isChestTerminalInstalled()) {
if (SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled()) {
if (channeln > 16) channeln = 0;
}
else {

View File

@ -83,7 +83,8 @@ public abstract class SolarGenerator extends SimpleSlimefunItem<GeneratorTicker>
super.preRegister();
// This prevents Players from toggling the Daylight sensor
addItemHandler((BlockUseHandler) PlayerRightClickEvent::cancel);
BlockUseHandler handler = PlayerRightClickEvent::cancel;
addItemHandler(handler);
}
}

View File

@ -79,39 +79,56 @@ public abstract class ElectricDustWasher extends AContainer {
}
else {
for (int slot : getInputSlots()) {
if (SlimefunManager.isItemSimilar(menu.getItemInSlot(slot), SlimefunItems.SIFTED_ORE, true)) {
if (!legacyMode) {
boolean emptySlot = false;
for (int outputSlot : getOutputSlots()) {
if (menu.getItemInSlot(outputSlot) == null) {
emptySlot = true;
break;
}
}
if (!emptySlot) return;
}
ItemStack adding = oreWasher.getRandomDust();
MachineRecipe r = new MachineRecipe(4 / getSpeed(), new ItemStack[0], new ItemStack[] { adding });
if (legacyMode && !menu.fits(r.getOutput()[0], getOutputSlots())) return;
menu.consumeItem(slot);
processing.put(b, r);
progress.put(b, r.getTicks());
break;
}
else if (SlimefunManager.isItemSimilar(menu.getItemInSlot(slot), SlimefunItems.PULVERIZED_ORE, true)) {
MachineRecipe r = new MachineRecipe(4 / getSpeed(), new ItemStack[0], new ItemStack[] { SlimefunItems.PURE_ORE_CLUSTER });
if (!menu.fits(r.getOutput()[0], getOutputSlots())) return;
menu.consumeItem(slot);
processing.put(b, r);
progress.put(b, r.getTicks());
if (process(b, menu, slot)) {
break;
}
}
}
}
private boolean process(Block b, BlockMenu menu, int slot) {
if (SlimefunManager.isItemSimilar(menu.getItemInSlot(slot), SlimefunItems.SIFTED_ORE, true)) {
if (!legacyMode) {
boolean emptySlot = false;
for (int outputSlot : getOutputSlots()) {
if (menu.getItemInSlot(outputSlot) == null) {
emptySlot = true;
break;
}
}
if (!emptySlot) {
return true;
}
}
ItemStack adding = oreWasher.getRandomDust();
MachineRecipe r = new MachineRecipe(4 / getSpeed(), new ItemStack[0], new ItemStack[] { adding });
if (!legacyMode || menu.fits(r.getOutput()[0], getOutputSlots())) {
menu.consumeItem(slot);
processing.put(b, r);
progress.put(b, r.getTicks());
}
return true;
}
else if (SlimefunManager.isItemSimilar(menu.getItemInSlot(slot), SlimefunItems.PULVERIZED_ORE, true)) {
MachineRecipe r = new MachineRecipe(4 / getSpeed(), new ItemStack[0], new ItemStack[] { SlimefunItems.PURE_ORE_CLUSTER });
if (menu.fits(r.getOutput()[0], getOutputSlots())) {
menu.consumeItem(slot);
processing.put(b, r);
progress.put(b, r.getTicks());
}
return true;
}
return false;
}
@Override
public String getMachineIdentifier() {
return "ELECTRIC_DUST_WASHER";

View File

@ -117,33 +117,45 @@ public abstract class ElectricGoldPan extends AContainer implements RecipeDispla
}
else {
for (int slot : getInputSlots()) {
if (SlimefunManager.isItemSimilar(menu.getItemInSlot(slot), new ItemStack(Material.GRAVEL), true)) {
ItemStack output = randomizer.getRandom();
MachineRecipe r = new MachineRecipe(3 / getSpeed(), new ItemStack[0], new ItemStack[] {output});
if (!menu.fits(output, getOutputSlots())) return;
menu.consumeItem(slot);
processing.put(b, r);
progress.put(b, r.getTicks());
break;
}
else if (SlimefunManager.isItemSimilar(menu.getItemInSlot(slot), new ItemStack(Material.SOUL_SAND), true)) {
ItemStack output = randomizerNether.getRandom();
MachineRecipe r = new MachineRecipe(4 / getSpeed(), new ItemStack[0], new ItemStack[] {output});
if (!menu.fits(output, getOutputSlots())) return;
menu.consumeItem(slot);
processing.put(b, r);
progress.put(b, r.getTicks());
break;
if (process(b, menu, slot)) {
break;
}
}
}
}
@Override
private boolean process(Block b, BlockMenu menu, int slot) {
if (SlimefunManager.isItemSimilar(menu.getItemInSlot(slot), new ItemStack(Material.GRAVEL), true)) {
ItemStack output = randomizer.getRandom();
MachineRecipe r = new MachineRecipe(3 / getSpeed(), new ItemStack[0], new ItemStack[] {output});
if (menu.fits(output, getOutputSlots())) {
menu.consumeItem(slot);
processing.put(b, r);
progress.put(b, r.getTicks());
}
return true;
}
else if (SlimefunManager.isItemSimilar(menu.getItemInSlot(slot), new ItemStack(Material.SOUL_SAND), true)) {
ItemStack output = randomizerNether.getRandom();
MachineRecipe r = new MachineRecipe(4 / getSpeed(), new ItemStack[0], new ItemStack[] {output});
if (menu.fits(output, getOutputSlots())) {
menu.consumeItem(slot);
processing.put(b, r);
progress.put(b, r.getTicks());
}
return true;
}
return false;
}
@Override
public String getMachineIdentifier() {
return "ELECTRIC_GOLD_PAN";
}

View File

@ -58,7 +58,7 @@ public class Compressor extends MultiBlockMachine {
removing.setAmount(recipeInput.getAmount());
inv.removeItem(removing);
craft(p, output, inv, outputInv);
craft(p, output, outputInv);
}
else {
SlimefunPlugin.getLocal().sendMessage(p, "machines.full-inventory", true);
@ -72,7 +72,7 @@ public class Compressor extends MultiBlockMachine {
SlimefunPlugin.getLocal().sendMessage(p, "machines.unknown-material", true);
}
private void craft(Player p, ItemStack output, Inventory inv, Inventory outputInv) {
private void craft(Player p, ItemStack output, Inventory outputInv) {
for (int i = 0; i < 4; i++) {
int j = i;

View File

@ -21,12 +21,12 @@ public class DeathpointListener implements Listener {
}
@EventHandler
public void onDamage(EntityDeathEvent e) {
public void onDeath(EntityDeathEvent e) {
if (e.getEntity().getType() == EntityType.PLAYER) {
Player p = (Player) e.getEntity();
if (p.getInventory().containsAtLeast(SlimefunItems.GPS_EMERGENCY_TRANSMITTER, 1)) {
SlimefunPlugin.getGPSNetwork().addWaypoint(p, SlimefunPlugin.getLocal().getMessage(p, "gps.deathpoint").replace("%date%", format.format(new Date())), p.getLocation().getBlock().getLocation());
SlimefunPlugin.getGPSNetwork().addWaypoint(p, "player:death " + SlimefunPlugin.getLocal().getMessage(p, "gps.deathpoint").replace("%date%", format.format(new Date())), p.getLocation().getBlock().getLocation());
}
}
}

View File

@ -28,10 +28,12 @@ public class DispenserListener implements Listener {
SlimefunItem machine = BlockStorage.check(b);
if (machine != null) {
Dispenser dispenser = (Dispenser) b.getState();
BlockFace face = ((Directional) b.getBlockData()).getFacing();
Block block = b.getRelative(face);
machine.callItemHandler(BlockDispenseHandler.class, handler -> handler.onBlockDispense(e, dispenser, block, machine));
machine.callItemHandler(BlockDispenseHandler.class, handler -> {
Dispenser dispenser = (Dispenser) b.getState();
BlockFace face = ((Directional) b.getBlockData()).getFacing();
Block block = b.getRelative(face);
handler.onBlockDispense(e, dispenser, block, machine);
});
}
}
}

View File

@ -32,7 +32,7 @@ public class EnhancedFurnaceListener implements Listener {
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBurn(FurnaceBurnEvent e) {
public void onFuelBurn(FurnaceBurnEvent e) {
SlimefunItem furnace = BlockStorage.check(e.getBlock());
if (furnace instanceof EnhancedFurnace && ((EnhancedFurnace) furnace).getFuelEfficiency() > 0) {
@ -41,7 +41,7 @@ public class EnhancedFurnaceListener implements Listener {
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onSmelt(FurnaceSmeltEvent e) {
public void onItemSmelt(FurnaceSmeltEvent e) {
SlimefunItem sfItem = BlockStorage.check(e.getBlock());
if (sfItem instanceof EnhancedFurnace) {

View File

@ -23,7 +23,7 @@ public class ItemPickupListener implements Listener {
}
@EventHandler
public void onPickup(EntityPickupItemEvent e) {
public void onEntityPickup(EntityPickupItemEvent e) {
if (e.getItem().hasMetadata(METADATA_JEY)) {
e.setCancelled(true);
}
@ -34,7 +34,7 @@ public class ItemPickupListener implements Listener {
}
@EventHandler
public void onMinecartPickup(InventoryPickupItemEvent e) {
public void onHopperPickup(InventoryPickupItemEvent e) {
if (e.getItem().hasMetadata(METADATA_JEY)) {
e.setCancelled(true);
}

View File

@ -164,12 +164,6 @@ public class TalismanListener implements Listener {
}
}
/**
*
* @param e
* BlockBreakEvent
* @since 4.2.0
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent e) {
ItemStack item = e.getPlayer().getInventory().getItemInMainHand();

View File

@ -34,7 +34,7 @@ public class WorldListener implements Listener {
storage.save(true);
}
else {
Slimefun.getLogger().log(Level.SEVERE, "Could not save Slimefun Blocks for World \"" + e.getWorld().getName() + "\"");
Slimefun.getLogger().log(Level.SEVERE, "Could not save Slimefun Blocks for World \"{0}\"", e.getWorld().getName());
}
}

View File

@ -36,328 +36,301 @@ import me.mrCookieSlime.Slimefun.api.Slimefun;
public class TickerTask implements Runnable {
private final DecimalFormat decimalFormat = new DecimalFormat("#.###");
private final ConcurrentMap<Location, Location> move = new ConcurrentHashMap<>();
private final ConcurrentMap<Location, Boolean> delete = new ConcurrentHashMap<>();
private final ConcurrentMap<Location, Long> blockTimings = new ConcurrentHashMap<>();
private final ConcurrentMap<String, Integer> chunkItemCount = new ConcurrentHashMap<>();
private final ConcurrentMap<String, Integer> machineCount = new ConcurrentHashMap<>();
private final ConcurrentMap<String, Long> machineTimings = new ConcurrentHashMap<>();
private final ConcurrentMap<String, Long> chunkTimings = new ConcurrentHashMap<>();
private final ConcurrentMap<Location, Integer> buggedBlocks = new ConcurrentHashMap<>();
private final Set<String> chunksSkipped = new HashSet<>();
private final Set<BlockTicker> tickers = new HashSet<>();
private boolean halted = false;
private int skipped = 0;
private int chunks = 0;
private int machines = 0;
private long time = 0;
private boolean running = false;
public void abortTick() {
running = false;
}
@Override
public void run() {
if (running) return;
running = true;
long timestamp = System.nanoTime();
skipped = 0;
chunks = 0;
machines = 0;
chunkItemCount.clear();
machineCount.clear();
time = 0;
chunkTimings.clear();
chunksSkipped.clear();
machineTimings.clear();
blockTimings.clear();
private final DecimalFormat decimalFormat = new DecimalFormat("#.###");
private final ConcurrentMap<Location, Location> move = new ConcurrentHashMap<>();
private final ConcurrentMap<Location, Boolean> delete = new ConcurrentHashMap<>();
private final ConcurrentMap<Location, Long> blockTimings = new ConcurrentHashMap<>();
private final ConcurrentMap<String, Integer> chunkItemCount = new ConcurrentHashMap<>();
private final ConcurrentMap<String, Integer> machineCount = new ConcurrentHashMap<>();
private final ConcurrentMap<String, Long> machineTimings = new ConcurrentHashMap<>();
private final ConcurrentMap<String, Long> chunkTimings = new ConcurrentHashMap<>();
private final ConcurrentMap<Location, Integer> buggedBlocks = new ConcurrentHashMap<>();
private final Set<String> chunksSkipped = new HashSet<>();
Map<Location, Integer> bugged = new HashMap<>(buggedBlocks);
buggedBlocks.clear();
Map<Location, Boolean> remove = new HashMap<>(delete);
private final Set<BlockTicker> tickers = new HashSet<>();
for (Map.Entry<Location, Boolean> entry : remove.entrySet()) {
BlockStorage._integrated_removeBlockInfo(entry.getKey(), entry.getValue());
delete.remove(entry.getKey());
}
if (!halted) {
for (String tickedChunk : BlockStorage.getTickingChunks()) {
long timestamp2 = System.nanoTime();
chunks++;
for (Location l : BlockStorage.getTickingLocations(tickedChunk)) {
if (l.getWorld().isChunkLoaded(l.getBlockX() >> 4, l.getBlockZ() >> 4)) {
Block b = l.getBlock();
SlimefunItem item = BlockStorage.check(l);
if (item != null && item.getBlockTicker() != null) {
machines++;
try {
item.getBlockTicker().update();
if (item.getBlockTicker().isSynchronized()) {
Slimefun.runSync(() -> {
try {
long timestamp3 = System.nanoTime();
item.getBlockTicker().tick(b, item, BlockStorage.getLocationInfo(l));
Long machinetime = machineTimings.get(item.getID());
Integer chunk = chunkItemCount.get(tickedChunk);
Integer machine = machineCount.get(item.getID());
machineTimings.put(item.getID(), (machinetime != null ? machinetime: 0) + (System.nanoTime() - timestamp3));
chunkItemCount.put(tickedChunk, (chunk != null ? chunk: 0) + 1);
machineCount.put(item.getID(), (machine != null ? machine: 0) + 1);
blockTimings.put(l, System.nanoTime() - timestamp3);
} catch (Exception x) {
int errors = bugged.getOrDefault(l, 0);
reportErrors(l, item, x, errors);
}
});
}
else {
long timestamp3 = System.nanoTime();
item.getBlockTicker().tick(b, item, BlockStorage.getLocationInfo(l));
private boolean halted = false;
machineTimings.merge(item.getID(), (System.nanoTime() - timestamp3), Long::sum);
chunkItemCount.merge(tickedChunk, 1, Integer::sum);
machineCount.merge(item.getID(), 1, Integer::sum);
blockTimings.put(l, System.nanoTime() - timestamp3);
}
tickers.add(item.getBlockTicker());
} catch (Exception x) {
int errors = bugged.getOrDefault(l, 0);
reportErrors(l, item, x, errors);
}
}
else skipped++;
}
else {
skipped += BlockStorage.getTickingLocations(tickedChunk).size();
chunksSkipped.add(tickedChunk);
chunks--;
break;
}
}
chunkTimings.put(tickedChunk, System.nanoTime() - timestamp2);
}
}
private int skipped = 0;
private int chunks = 0;
private int machines = 0;
private long time = 0;
for (Map.Entry<Location, Location> entry : move.entrySet()) {
BlockStorage._integrated_moveLocationInfo(entry.getKey(), entry.getValue());
}
move.clear();
Iterator<BlockTicker> iterator = tickers.iterator();
while (iterator.hasNext()) {
iterator.next().startNewTick();
iterator.remove();
}
time = System.nanoTime() - timestamp;
running = false;
}
private boolean running = false;
private void reportErrors(Location l, SlimefunItem item, Exception x, int errors) {
errors++;
public void abortTick() {
running = false;
}
if (errors == 1) {
// Generate a new Error-Report
new ErrorReport(x, l, item);
@Override
public void run() {
if (running) return;
buggedBlocks.put(l, errors);
}
else if (errors == 4) {
Slimefun.getLogger().log(Level.SEVERE, "X: " + l.getBlockX() + " Y: " + l.getBlockY() + " Z: " + l.getBlockZ() + '(' + item.getID() + ")");
Slimefun.getLogger().log(Level.SEVERE, "has thrown 4 Exceptions in the last 4 Ticks, the Block has been terminated.");
Slimefun.getLogger().log(Level.SEVERE, "Check your /plugins/Slimefun/error-reports/ folder for details.");
Slimefun.getLogger().log(Level.SEVERE, " ");
running = true;
long timestamp = System.nanoTime();
BlockStorage._integrated_removeBlockInfo(l, true);
skipped = 0;
chunks = 0;
machines = 0;
chunkItemCount.clear();
machineCount.clear();
time = 0;
chunkTimings.clear();
chunksSkipped.clear();
machineTimings.clear();
blockTimings.clear();
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunPlugin.instance, () -> l.getBlock().setType(Material.AIR));
}
else {
buggedBlocks.put(l, errors);
}
}
Map<Location, Integer> bugged = new HashMap<>(buggedBlocks);
buggedBlocks.clear();
public String getTime() {
return toMillis(time);
}
Map<Location, Boolean> remove = new HashMap<>(delete);
public void info(CommandSender sender) {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&2== &aSlimefun Diagnostic Tool &2=="));
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6Halted: &e&l" + String.valueOf(halted).toUpperCase()));
sender.sendMessage("");
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6Impact: &e" + toMillis(time)));
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6Ticked Chunks: &e" + chunks));
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6Ticked Machines: &e" + machines));
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6Skipped Machines: &e" + skipped));
sender.sendMessage("");
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6Ticking Machines:"));
for (Map.Entry<Location, Boolean> entry : remove.entrySet()) {
BlockStorage._integrated_removeBlockInfo(entry.getKey(), entry.getValue());
delete.remove(entry.getKey());
}
List<Map.Entry<String, Long>> timings = machineCount.keySet().stream()
.map(key -> new AbstractMap.SimpleEntry<>(key, machineTimings.getOrDefault(key, 0L)))
.sorted((o1, o2) -> o2.getValue().compareTo(o1.getValue()))
.collect(Collectors.toList());
if (!halted) {
for (String tickedChunk : BlockStorage.getTickingChunks()) {
long timestamp2 = System.nanoTime();
chunks++;
if (sender instanceof Player) {
ChatComponent component = new ChatComponent(ChatColors.color(" &7&oHover for more Info"));
StringBuilder builder = new StringBuilder();
int hidden = 0;
for (Location l : BlockStorage.getTickingLocations(tickedChunk)) {
if (l.getWorld().isChunkLoaded(l.getBlockX() >> 4, l.getBlockZ() >> 4)) {
Block b = l.getBlock();
SlimefunItem item = BlockStorage.check(l);
for (Map.Entry<String, Long> entry : timings) {
int count = machineCount.get(entry.getKey());
if (entry.getValue() > 500_000) {
builder.append("\n&c")
.append(entry.getKey())
.append(" - ")
.append(count)
.append("x &7(")
.append(toMillis(entry.getValue()))
.append(", ")
.append(toMillis(entry.getValue() / count))
.append(" avg/machine)");
}
else hidden++;
}
if (item != null && item.getBlockTicker() != null) {
machines++;
builder.append("\n\n&c+ &4").append(hidden).append(" Hidden");
component.setHoverEvent(new HoverEvent(ChatColors.color(builder.toString())));
try {
item.getBlockTicker().update();
component.sendMessage((Player) sender);
}
else {
int hidden = 0;
if (item.getBlockTicker().isSynchronized()) {
Slimefun.runSync(() -> {
try {
long timestamp3 = System.nanoTime();
item.getBlockTicker().tick(b, item, BlockStorage.getLocationInfo(l));
for (Map.Entry<String, Long> entry : timings) {
int count = machineCount.get(entry.getKey());
if (entry.getValue() > 500_000) {
sender.sendMessage(" " + entry.getKey() + " - " + count + "x (" + toMillis(entry.getValue()) + ", " + toMillis(entry.getValue() / count) + " avg/machine)");
}
else hidden++;
}
Long machinetime = machineTimings.get(item.getID());
Integer chunk = chunkItemCount.get(tickedChunk);
Integer machine = machineCount.get(item.getID());
sender.sendMessage("+ " + hidden + " Hidden");
}
sender.sendMessage("");
sender.sendMessage(ChatColors.color("&6Ticking Chunks:"));
machineTimings.put(item.getID(), (machinetime != null ? machinetime : 0) + (System.nanoTime() - timestamp3));
chunkItemCount.put(tickedChunk, (chunk != null ? chunk : 0) + 1);
machineCount.put(item.getID(), (machine != null ? machine : 0) + 1);
blockTimings.put(l, System.nanoTime() - timestamp3);
}
catch (Exception x) {
int errors = bugged.getOrDefault(l, 0);
reportErrors(l, item, x, errors);
}
});
}
else {
long timestamp3 = System.nanoTime();
item.getBlockTicker().tick(b, item, BlockStorage.getLocationInfo(l));
timings = chunkTimings.entrySet().stream()
.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
.collect(Collectors.toList());
machineTimings.merge(item.getID(), (System.nanoTime() - timestamp3), Long::sum);
chunkItemCount.merge(tickedChunk, 1, Integer::sum);
machineCount.merge(item.getID(), 1, Integer::sum);
blockTimings.put(l, System.nanoTime() - timestamp3);
}
if (sender instanceof Player) {
ChatComponent component = new ChatComponent(ChatColors.color(" &7&oHover for more Info"));
StringBuilder builder = new StringBuilder();
int hidden = 0;
tickers.add(item.getBlockTicker());
}
catch (Exception x) {
int errors = bugged.getOrDefault(l, 0);
reportErrors(l, item, x, errors);
}
}
else skipped++;
}
else {
skipped += BlockStorage.getTickingLocations(tickedChunk).size();
chunksSkipped.add(tickedChunk);
chunks--;
break;
}
}
for (Map.Entry<String, Long> entry : timings) {
if (!chunksSkipped.contains(entry.getKey())) {
if (entry.getValue() > 0) {
builder.append("\n&c")
.append(formatChunk(entry.getKey()))
.append(" - ")
.append(chunkItemCount.getOrDefault(entry.getKey(), 0))
.append("x &7(")
.append(toMillis(entry.getValue()))
.append(')');
}
else hidden++;
}
}
builder.append("\n\n&c+ &4").append(hidden).append(" Hidden");
component.setHoverEvent(new HoverEvent(ChatColors.color(builder.toString())));
component.sendMessage((Player) sender);
}
else {
int hidden = 0;
for (Map.Entry<String, Long> entry : timings) {
if (!chunksSkipped.contains(entry.getKey())) {
if (entry.getValue() > 0) {
sender.sendMessage(" " + formatChunk(entry.getKey()) + " - " + (chunkItemCount.getOrDefault(entry.getKey(), 0)) + "x (" + toMillis(entry.getValue()) + ")");
}
else hidden++;
}
}
sender.sendMessage(ChatColors.color("&c+ &4" + hidden + " Hidden"));
}
}
private String formatChunk(String chunk) {
String[] components = PatternUtils.SEMICOLON.split(chunk);
return components[0] + " [" + components[2] + ',' + components[3] + ']';
}
public long getTimings(Block b) {
return blockTimings.getOrDefault(b.getLocation(), 0L);
}
public long getTimings(String item) {
return machineTimings.getOrDefault(item, 0L);
}
public long getTimings(Chunk c) {
return chunkTimings.getOrDefault(c.toString(), 0L);
}
chunkTimings.put(tickedChunk, System.nanoTime() - timestamp2);
}
}
public void addBlockTimings(Location l, long time) {
blockTimings.put(l, time);
}
public boolean isHalted() {
return halted;
}
public void halt() {
halted = true;
}
for (Map.Entry<Location, Location> entry : move.entrySet()) {
BlockStorage._integrated_moveLocationInfo(entry.getKey(), entry.getValue());
}
move.clear();
private String toMillis(long time) {
return decimalFormat.format(time / 1000000F) + "ms";
}
@Override
public String toString() {
return "TickerTask {\n"
+ " HALTED = " + halted + "\n"
+ " tickers = " + tickers + "\n"
+ " move = " + move + "\n"
+ " delete = " + delete + "\n"
+ " chunks = " + chunkItemCount + "\n"
+ " machines = " + machineCount + "\n"
+ " machinetime = " + machineTimings + "\n"
+ " chunktime = " + chunkTimings + "\n"
+ " skipped = " + chunksSkipped + "\n"
+ "}";
}
Iterator<BlockTicker> iterator = tickers.iterator();
while (iterator.hasNext()) {
iterator.next().startNewTick();
iterator.remove();
}
public void queueMove(Location from, Location to) {
move.put(from, to);
}
time = System.nanoTime() - timestamp;
running = false;
}
public void queueDelete(Location l, boolean destroy) {
delete.put(l, destroy);
}
private void reportErrors(Location l, SlimefunItem item, Exception x, int errors) {
errors++;
if (errors == 1) {
// Generate a new Error-Report
new ErrorReport(x, l, item);
buggedBlocks.put(l, errors);
}
else if (errors == 4) {
Slimefun.getLogger().log(Level.SEVERE, "X: {0} Y: {1} Z: {2} ({3})", new Object[] { l.getBlockX(), l.getBlockY(), l.getBlockZ(), item.getID() });
Slimefun.getLogger().log(Level.SEVERE, "has thrown 4 Exceptions in the last 4 Ticks, the Block has been terminated.");
Slimefun.getLogger().log(Level.SEVERE, "Check your /plugins/Slimefun/error-reports/ folder for details.");
Slimefun.getLogger().log(Level.SEVERE, " ");
BlockStorage._integrated_removeBlockInfo(l, true);
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunPlugin.instance, () -> l.getBlock().setType(Material.AIR));
}
else {
buggedBlocks.put(l, errors);
}
}
public String getTime() {
return toMillis(time);
}
public void info(CommandSender sender) {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&2== &aSlimefun Diagnostic Tool &2=="));
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6Halted: &e&l" + String.valueOf(halted).toUpperCase()));
sender.sendMessage("");
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6Impact: &e" + toMillis(time)));
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6Ticked Chunks: &e" + chunks));
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6Ticked Machines: &e" + machines));
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6Skipped Machines: &e" + skipped));
sender.sendMessage("");
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6Ticking Machines:"));
List<Map.Entry<String, Long>> timings = machineCount.keySet().stream().map(key -> new AbstractMap.SimpleEntry<>(key, machineTimings.getOrDefault(key, 0L))).sorted((o1, o2) -> o2.getValue().compareTo(o1.getValue())).collect(Collectors.toList());
if (sender instanceof Player) {
ChatComponent component = new ChatComponent(ChatColors.color(" &7&oHover for more Info"));
StringBuilder builder = new StringBuilder();
int hidden = 0;
for (Map.Entry<String, Long> entry : timings) {
int count = machineCount.get(entry.getKey());
if (entry.getValue() > 500_000) {
builder.append("\n&c").append(entry.getKey()).append(" - ").append(count).append("x &7(").append(toMillis(entry.getValue())).append(", ").append(toMillis(entry.getValue() / count)).append(" avg/machine)");
}
else hidden++;
}
builder.append("\n\n&c+ &4").append(hidden).append(" Hidden");
component.setHoverEvent(new HoverEvent(ChatColors.color(builder.toString())));
component.sendMessage((Player) sender);
}
else {
int hidden = 0;
for (Map.Entry<String, Long> entry : timings) {
int count = machineCount.get(entry.getKey());
if (entry.getValue() > 500_000) {
sender.sendMessage(" " + entry.getKey() + " - " + count + "x (" + toMillis(entry.getValue()) + ", " + toMillis(entry.getValue() / count) + " avg/machine)");
}
else hidden++;
}
sender.sendMessage("+ " + hidden + " Hidden");
}
sender.sendMessage("");
sender.sendMessage(ChatColors.color("&6Ticking Chunks:"));
timings = chunkTimings.entrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).collect(Collectors.toList());
if (sender instanceof Player) {
ChatComponent component = new ChatComponent(ChatColors.color(" &7&oHover for more Info"));
StringBuilder builder = new StringBuilder();
int hidden = 0;
for (Map.Entry<String, Long> entry : timings) {
if (!chunksSkipped.contains(entry.getKey())) {
if (entry.getValue() > 0) {
builder.append("\n&c").append(formatChunk(entry.getKey())).append(" - ").append(chunkItemCount.getOrDefault(entry.getKey(), 0)).append("x &7(").append(toMillis(entry.getValue())).append(')');
}
else hidden++;
}
}
builder.append("\n\n&c+ &4").append(hidden).append(" Hidden");
component.setHoverEvent(new HoverEvent(ChatColors.color(builder.toString())));
component.sendMessage((Player) sender);
}
else {
int hidden = 0;
for (Map.Entry<String, Long> entry : timings) {
if (!chunksSkipped.contains(entry.getKey())) {
if (entry.getValue() > 0) {
sender.sendMessage(" " + formatChunk(entry.getKey()) + " - " + (chunkItemCount.getOrDefault(entry.getKey(), 0)) + "x (" + toMillis(entry.getValue()) + ")");
}
else hidden++;
}
}
sender.sendMessage(ChatColors.color("&c+ &4" + hidden + " Hidden"));
}
}
private String formatChunk(String chunk) {
String[] components = PatternUtils.SEMICOLON.split(chunk);
return components[0] + " [" + components[2] + ',' + components[3] + ']';
}
public long getTimings(Block b) {
return blockTimings.getOrDefault(b.getLocation(), 0L);
}
public long getTimings(String item) {
return machineTimings.getOrDefault(item, 0L);
}
public long getTimings(Chunk c) {
return chunkTimings.getOrDefault(c.toString(), 0L);
}
public void addBlockTimings(Location l, long time) {
blockTimings.put(l, time);
}
public boolean isHalted() {
return halted;
}
public void halt() {
halted = true;
}
private String toMillis(long time) {
return decimalFormat.format(time / 1000000F) + "ms";
}
@Override
public String toString() {
return "TickerTask {\n" + " HALTED = " + halted + "\n" + " tickers = " + tickers + "\n" + " move = " + move + "\n" + " delete = " + delete + "\n" + " chunks = " + chunkItemCount + "\n" + " machines = " + machineCount + "\n" + " machinetime = " + machineTimings + "\n" + " chunktime = " + chunkTimings + "\n" + " skipped = " + chunksSkipped + "\n" + "}";
}
public void queueMove(Location from, Location to) {
move.put(from, to);
}
public void queueDelete(Location l, boolean destroy) {
delete.put(l, destroy);
}
}

View File

@ -25,7 +25,7 @@ public final class NumberUtils {
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date.replace('T', ' ').replace("Z", ""));
}
catch (ParseException x) {
Slimefun.getLogger().log(Level.SEVERE, "An Error occured while parsing a GitHub-Date for Slimefun " + SlimefunPlugin.getVersion(), x);
Slimefun.getLogger().log(Level.SEVERE, x, () -> "An Error occured while parsing a GitHub-Date for Slimefun " + SlimefunPlugin.getVersion());
return null;
}
}

View File

@ -8,7 +8,6 @@ import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.logging.Level;
import org.bukkit.ChatColor;
import org.bukkit.Keyed;
@ -25,7 +24,6 @@ import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunMachine;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.multiblocks.MultiBlockMachine;
import me.mrCookieSlime.Slimefun.api.Slimefun;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class RecipeType implements Keyed {
@ -153,18 +151,11 @@ public class RecipeType implements Keyed {
}
private static void registerMobDrop(ItemStack[] recipe, ItemStack output) {
String mob = null;
try {
mob = ChatColor.stripColor(recipe[4].getItemMeta().getDisplayName()).toUpperCase().replace(' ', '_');
EntityType entity = EntityType.valueOf(mob);
Set<ItemStack> dropping = SlimefunPlugin.getRegistry().getMobDrops().getOrDefault(entity, new HashSet<>());
dropping.add(output);
SlimefunPlugin.getRegistry().getMobDrops().put(entity, dropping);
}
catch (Exception x) {
Slimefun.getLogger().log(Level.WARNING, "An Exception occured when setting a Drop for the Mob Type: \"" + mob + "\"", x);
}
String mob = ChatColor.stripColor(recipe[4].getItemMeta().getDisplayName()).toUpperCase().replace(' ', '_');
EntityType entity = EntityType.valueOf(mob);
Set<ItemStack> dropping = SlimefunPlugin.getRegistry().getMobDrops().getOrDefault(entity, new HashSet<>());
dropping.add(output);
SlimefunPlugin.getRegistry().getMobDrops().put(entity, dropping);
}
public static List<ItemStack> getRecipeInputs(SlimefunMachine machine) {

View File

@ -2,7 +2,6 @@ package me.mrCookieSlime.Slimefun.Objects.SlimefunItem;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.bukkit.Material;

View File

@ -188,7 +188,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
SlimefunItemSetup.setup(this);
}
catch (Throwable x) {
getLogger().log(Level.SEVERE, "An Error occured while initializing SlimefunItems for Slimefun " + getVersion(), x);
getLogger().log(Level.SEVERE, x, () -> "An Error occured while initializing SlimefunItems for Slimefun " + getVersion());
}
getLogger().log(Level.INFO, "Loading Researches...");
@ -197,7 +197,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
ResearchSetup.setupResearches();
}
catch (Throwable x) {
getLogger().log(Level.SEVERE, "An Error occured while initializing Slimefun Researches for Slimefun " + getVersion(), x);
getLogger().log(Level.SEVERE, x, () -> "An Error occured while initializing Slimefun Researches for Slimefun " + getVersion());
}
registry.setResearchingEnabled(getResearchCfg().getBoolean("enable-researching"));
@ -313,8 +313,8 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
try {
ticker.run();
}
catch (Exception x) {
getLogger().log(Level.SEVERE, "An Exception was caught while ticking the Block Tickers Task for Slimefun v" + getVersion(), x);
catch (Throwable x) {
getLogger().log(Level.SEVERE, x, () -> "An Exception was caught while ticking the Block Tickers Task for Slimefun v" + getVersion());
ticker.abortTick();
}
}, 100L, config.getInt("URID.custom-ticker-delay"));
@ -370,8 +370,8 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
getLogger().log(Level.SEVERE, "### Slimefun was not installed correctly!");
getLogger().log(Level.SEVERE, "### You are using the wrong version of Minecraft!");
getLogger().log(Level.SEVERE, "###");
getLogger().log(Level.SEVERE, "### You are using Minecraft " + ReflectionUtils.getVersion());
getLogger().log(Level.SEVERE, "### but Slimefun v" + getDescription().getVersion() + " requires you to be using");
getLogger().log(Level.SEVERE, "### You are using Minecraft {0}", ReflectionUtils.getVersion());
getLogger().log(Level.SEVERE, "### but Slimefun v{0} requires you to be using", getDescription().getVersion());
getLogger().log(Level.SEVERE, "### Minecraft {0}", String.join(" / ", MinecraftVersion.getSupportedVersions()));
return true;
}
@ -409,11 +409,11 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
storage.save(true);
}
else {
getLogger().log(Level.SEVERE, "Could not save Slimefun Blocks for World \"" + world.getName() + "\"");
getLogger().log(Level.SEVERE, "Could not save Slimefun Blocks for World \"{0}\"", world.getName());
}
}
catch (Exception x) {
getLogger().log(Level.SEVERE, "An Error occured while saving Slimefun-Blocks in World '" + world.getName() + "' for Slimefun " + getVersion(), x);
getLogger().log(Level.SEVERE, x, () -> "An Error occured while saving Slimefun-Blocks in World '" + world.getName() + "' for Slimefun " + getVersion());
}
}

View File

@ -4,30 +4,28 @@ import java.util.List;
import org.bukkit.entity.Player;
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
import me.mrCookieSlime.CSCoreLibPlugin.PlayerRunnable;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu;
@Deprecated
public interface GuideHandler {
public abstract void addEntry(List<String> texts, List<String> tooltips);
public abstract PlayerRunnable getRunnable();
public abstract int getTier();
public abstract boolean trackHistory();
public abstract int next(Player p, int index, ChestMenu menu);
public abstract void addEntry(List<String> texts, List<String> tooltips);
default PlayerRunnable getRunnable(boolean book) {
return this.getRunnable();
}
default void run(Player p, boolean survival, boolean book) {
this.getRunnable(book).run(p);
if (survival && this.trackHistory()) {
PlayerProfile.get(p, profile -> profile.getGuideHistory().add(this));
}
}
public abstract PlayerRunnable getRunnable();
public abstract int getTier();
public abstract boolean trackHistory();
public abstract int next(Player p, int index, ChestMenu menu);
default PlayerRunnable getRunnable(boolean book) {
return this.getRunnable();
}
default void run(Player p, boolean survival, boolean book) {
this.getRunnable(book).run(p);
}
}

View File

@ -19,26 +19,24 @@ import org.bukkit.potion.PotionEffectType;
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.cscorelib2.item.ImmutableItemMeta;
import io.github.thebusybiscuit.cscorelib2.skull.SkullItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
public class SlimefunItemStack extends CustomItem {
private String id;
private ImmutableItemMeta immutableMeta;
private final String texture;
private String texture = null;
public SlimefunItemStack(String id, Material type, String name, String... lore) {
super(type, name, lore);
texture = null;
setID(id);
}
public SlimefunItemStack(String id, Material type, Color color, String name, String... lore) {
super(new ItemStack(type), color, name, lore);
texture = null;
setID(id);
}
@ -69,28 +67,23 @@ public class SlimefunItemStack extends CustomItem {
}
});
texture = null;
setID(id);
}
public SlimefunItemStack(String id, ItemStack item, String name, String... lore) {
super(item, name, lore);
texture = null;
setID(id);
}
public SlimefunItemStack(String id, ItemStack item) {
super(item);
texture = null;
setID(id);
}
public SlimefunItemStack(String id, ItemStack item, Consumer<ItemMeta> consumer) {
super(item, consumer);
texture = null;
setID(id);
}
@ -104,13 +97,12 @@ public class SlimefunItemStack extends CustomItem {
consumer.accept(meta);
});
texture = null;
setID(id);
}
public SlimefunItemStack(String id, String texture, String name, String... lore) {
super(getSkull(texture), name, lore);
this.texture = texture;
this.texture = getTexture(texture);
setID(id);
}
@ -124,14 +116,14 @@ public class SlimefunItemStack extends CustomItem {
consumer.accept(meta);
});
this.texture = texture;
this.texture = getTexture(texture);
setID(id);
}
public SlimefunItemStack(String id, String texture, Consumer<ItemMeta> consumer) {
super(getSkull(texture), consumer);
this.texture = texture;
this.texture = getTexture(texture);
setID(id);
}
@ -178,11 +170,15 @@ public class SlimefunItemStack extends CustomItem {
return item;
}
public Optional<String> getBase64Texture() {
public Optional<String> getSkullTexture() {
return Optional.ofNullable(texture);
}
private static ItemStack getSkull(String texture) {
return SkullItem.fromBase64(getTexture(texture));
}
private static String getTexture(String texture) {
String base64 = texture;
// At this point we can be sure it's not a base64 encoded texture
@ -190,7 +186,7 @@ public class SlimefunItemStack extends CustomItem {
base64 = Base64.getEncoder().encodeToString(("{\"textures\":{\"SKIN\":{\"url\":\"http://textures.minecraft.net/texture/" + texture + "\"}}}").getBytes());
}
return SkullItem.fromBase64(base64);
return base64;
}
}

View File

@ -195,14 +195,14 @@ public class CargoNet extends Network {
Slimefun.runSync(() -> run(b, providers, destinations, output));
}
}
private void run(Block b, Set<Location> providers, Set<Location> destinations, Map<Integer, List<Location>> output) {
if (BlockStorage.getLocationInfo(b.getLocation(), "visualizer") == null) {
display();
}
// Chest Terminal Code
if (SlimefunPlugin.getNetworkManager().isChestTerminalInstalled()) {
if (SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled()) {
for (Location bus : imports) {
BlockMenu menu = BlockStorage.getInventory(bus);
@ -408,7 +408,7 @@ public class CargoNet extends Network {
}
// Chest Terminal Code
if (SlimefunPlugin.getNetworkManager().isChestTerminalInstalled()) {
if (SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled()) {
List<ItemStackAndInteger> items = new ArrayList<>();
for (Location l : providers) {