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

[CI skip] Refactoring

This commit is contained in:
TheBusyBiscuit 2020-04-09 22:16:32 +02:00
parent f5bd880227
commit e3d84de7b9
17 changed files with 212 additions and 280 deletions

View File

@ -72,6 +72,8 @@
* Fixed #1779
* Fixed localized messages not showing in the book guide
* Fixed empty categories showing up when items inside were hidden
* Fixed ghost pages showing up when too many categories were disabled
* Fixed debug fish not showing the correct chunk timings
## Release Candidate 10 (28 Mar 2020)

View File

@ -110,7 +110,7 @@ public class SlimefunRegistry {
automaticallyLoadItems = mode;
}
public List<Category> getEnabledCategories() {
public List<Category> getCategories() {
return categories;
}

View File

@ -4,6 +4,7 @@ import java.time.LocalDate;
import java.time.Month;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import me.mrCookieSlime.Slimefun.Objects.Category;
@ -49,13 +50,12 @@ public class SeasonalCategory extends Category {
return month;
}
/**
* Checks if the category should currently be displayed in the Guide.
* This is based on {@link SeasonalCategory#getMonth()}.
*
* @return true if it should, otherwise false
*/
public boolean isVisible() {
return month == LocalDate.now().getMonth();
@Override
public boolean isHidden(Player p) {
if (month != LocalDate.now().getMonth()) {
return true;
}
return super.isHidden(p);
}
}

View File

@ -21,7 +21,6 @@ import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
import io.github.thebusybiscuit.slimefun4.core.categories.FlexCategory;
import io.github.thebusybiscuit.slimefun4.core.categories.SeasonalCategory;
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide;
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideImplementation;
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout;
@ -88,7 +87,7 @@ public class BookSlimefunGuide implements SlimefunGuideImplementation {
List<ChatComponent> lines = new LinkedList<>();
int tier = 0;
for (Category category : SlimefunPlugin.getRegistry().getEnabledCategories()) {
for (Category category : SlimefunPlugin.getRegistry().getCategories()) {
if (!category.isHidden(p) && (!(category instanceof FlexCategory) || ((FlexCategory) category).isVisible(p, profile, getLayout()))) {
if (tier < category.getTier()) {
tier = category.getTier();
@ -101,6 +100,7 @@ public class BookSlimefunGuide implements SlimefunGuideImplementation {
lines.add(new ChatComponent(ChatColor.DARK_GRAY + "\u21E8" + ChatColor.DARK_BLUE + " Tier " + tier + "\n"));
}
if (category instanceof LockedCategory && !((LockedCategory) category).hasUnlocked(p, profile)) {
List<String> lore = new LinkedList<>();
lore.add(ChatColor.DARK_RED + SlimefunPlugin.getLocal().getMessage(p, "guide.locked") + " " + ChatColor.GRAY + "- " + ChatColor.RESET + category.getItem(p).getItemMeta().getDisplayName());
@ -120,7 +120,7 @@ public class BookSlimefunGuide implements SlimefunGuideImplementation {
chatComponent.setHoverEvent(new HoverEvent(lore));
lines.add(chatComponent);
}
else if (!(category instanceof SeasonalCategory) || ((SeasonalCategory) category).isVisible()) {
else {
ChatComponent chatComponent = new ChatComponent(ChatUtils.crop(ChatColor.DARK_GREEN, ItemUtils.getItemName(category.getItem(p))) + "\n");
chatComponent.setHoverEvent(new HoverEvent(ItemUtils.getItemName(category.getItem(p)), "", ChatColor.GRAY + "\u21E8 " + ChatColor.GREEN + SlimefunPlugin.getLocal().getMessage(p, "guide.tooltips.open-category")));
chatComponent.setClickEvent(new ClickEvent(category.getKey(), pl -> openCategory(profile, category, 1)));

View File

@ -2,6 +2,7 @@ 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.Locale;
import java.util.Optional;
@ -27,7 +28,6 @@ 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.categories.FlexCategory;
import io.github.thebusybiscuit.slimefun4.core.categories.SeasonalCategory;
import io.github.thebusybiscuit.slimefun4.core.guide.GuideHistory;
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide;
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideImplementation;
@ -79,6 +79,18 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
return true;
}
private List<Category> getVisibleCategories(Player p, PlayerProfile profile) {
List<Category> categories = new LinkedList<>();
for (Category category : SlimefunPlugin.getRegistry().getCategories()) {
if (!category.isHidden(p) && (!(category instanceof FlexCategory) || ((FlexCategory) category).isVisible(p, profile, getLayout()))) {
categories.add(category);
}
}
return categories;
}
@Override
public void openMainMenu(PlayerProfile profile, int page) {
Player p = profile.getPlayer();
@ -90,11 +102,9 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
ChestMenu menu = create(p);
List<Category> categories = SlimefunPlugin.getRegistry().getEnabledCategories();
List<Category> categories = getVisibleCategories(p, profile);
int index = 9;
int pages = (categories.size() - 1) / CATEGORY_SIZE + 1;
createHeader(p, profile, menu);
int target = (CATEGORY_SIZE * (page - 1)) - 1;
@ -103,11 +113,12 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
target++;
Category category = categories.get(target);
if (!category.isHidden(p) && displayCategory(menu, p, profile, category, index)) {
index++;
}
displayCategory(menu, p, profile, category, index);
index++;
}
int pages = target == categories.size() - 1 ? page : (categories.size() - 1) / CATEGORY_SIZE + 1;
menu.addItem(46, ChestMenuUtils.getPreviousButton(p, page, pages));
menu.addMenuClickHandler(46, (pl, slot, item, action) -> {
int next = page - 1;
@ -125,22 +136,13 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
menu.open(p);
}
private boolean displayCategory(ChestMenu menu, Player p, PlayerProfile profile, Category category, int index) {
if (category instanceof FlexCategory && !((FlexCategory) category).isVisible(p, profile, getLayout())) {
return false;
}
else if (!(category instanceof LockedCategory)) {
if (!(category instanceof SeasonalCategory) || ((SeasonalCategory) category).isVisible()) {
menu.addItem(index, category.getItem(p));
menu.addMenuClickHandler(index, (pl, slot, item, action) -> {
openCategory(profile, category, 1);
return false;
});
return true;
}
return false;
private void displayCategory(ChestMenu menu, Player p, PlayerProfile profile, Category category, int index) {
if (!(category instanceof LockedCategory)) {
menu.addItem(index, category.getItem(p));
menu.addMenuClickHandler(index, (pl, slot, item, action) -> {
openCategory(profile, category, 1);
return false;
});
}
else if (!isSurvivalMode() || ((LockedCategory) category).hasUnlocked(p, profile)) {
menu.addItem(index, category.getItem(p));
@ -148,8 +150,6 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
openCategory(profile, category, 1);
return false;
});
return true;
}
else {
List<String> lore = new ArrayList<>();
@ -167,7 +167,6 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
menu.addItem(index, new CustomItem(Material.BARRIER, "&4" + SlimefunPlugin.getLocal().getMessage(p, "guide.locked") + " &7- &r" + category.getItem(p).getItemMeta().getDisplayName(), lore.toArray(new String[0])));
menu.addMenuClickHandler(index, ChestMenuUtils.getEmptyClickHandler());
return true;
}
}

View File

@ -72,8 +72,12 @@ public class EnhancedFurnace extends SimpleSlimefunItem<BlockTicker> {
if (furnace.getCookTime() > 0) {
int newCookTime = furnace.getCookTime() + getSpeed() * 10;
if (newCookTime > 200) furnace.setCookTime((short) 188);
else furnace.setCookTime((short) newCookTime);
if (newCookTime > 200) {
furnace.setCookTime((short) 188);
}
else {
furnace.setCookTime((short) newCookTime);
}
furnace.update(true, false);
}

View File

@ -1,15 +1,15 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.collections.RandomizedSet;
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem;
import io.github.thebusybiscuit.slimefun4.implementation.items.tools.GoldPan;
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
@ -18,151 +18,112 @@ import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.Slimefun;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
public abstract class ElectricGoldPan extends AContainer implements RecipeDisplayItem {
private final RandomizedSet<ItemStack> randomizer = new RandomizedSet<>();
private final RandomizedSet<ItemStack> randomizerNether = new RandomizedSet<>();
private final List<ItemStack> displayRecipes = Arrays.asList(
new ItemStack(Material.GRAVEL), new ItemStack(Material.FLINT),
new ItemStack(Material.GRAVEL), SlimefunItems.SIFTED_ORE,
new ItemStack(Material.GRAVEL), new ItemStack(Material.CLAY_BALL),
new ItemStack(Material.GRAVEL), new ItemStack(Material.IRON_NUGGET),
new ItemStack(Material.SOUL_SAND), new ItemStack(Material.QUARTZ),
new ItemStack(Material.SOUL_SAND), new ItemStack(Material.GOLD_NUGGET),
new ItemStack(Material.SOUL_SAND), new ItemStack(Material.NETHER_WART),
new ItemStack(Material.SOUL_SAND), new ItemStack(Material.BLAZE_POWDER),
new ItemStack(Material.SOUL_SAND), new ItemStack(Material.GLOWSTONE_DUST),
new ItemStack(Material.SOUL_SAND), new ItemStack(Material.GHAST_TEAR)
);
public ElectricGoldPan(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe);
}
@Override
public void postRegister() {
super.postRegister();
String goldPan = "GOLD_PAN";
String netherGoldPan = "NETHER_GOLD_PAN";
add(false, SlimefunItems.SIFTED_ORE, (int) Slimefun.getItemValue(goldPan, "chance.SIFTED_ORE"));
add(false, new ItemStack(Material.CLAY_BALL), (int) Slimefun.getItemValue(goldPan, "chance.CLAY"));
add(false, new ItemStack(Material.FLINT), (int) Slimefun.getItemValue(goldPan, "chance.FLINT"));
add(false, new ItemStack(Material.IRON_NUGGET), (int) Slimefun.getItemValue(goldPan, "chance.IRON_NUGGET"));
add(true, new ItemStack(Material.QUARTZ), (int) Slimefun.getItemValue(netherGoldPan, "chance.QUARTZ"));
add(true, new ItemStack(Material.GOLD_NUGGET), (int) Slimefun.getItemValue(netherGoldPan, "chance.GOLD_NUGGET"));
add(true, new ItemStack(Material.NETHER_WART), (int) Slimefun.getItemValue(netherGoldPan, "chance.NETHER_WART"));
add(true, new ItemStack(Material.BLAZE_POWDER), (int) Slimefun.getItemValue(netherGoldPan, "chance.BLAZE_POWDER"));
add(true, new ItemStack(Material.GLOWSTONE_DUST), (int) Slimefun.getItemValue(netherGoldPan, "chance.GLOWSTONE_DUST"));
add(true, new ItemStack(Material.GHAST_TEAR), (int) Slimefun.getItemValue(netherGoldPan, "chance.GHAST_TEAR"));
}
private void add(boolean nether, ItemStack item, int chance) {
if (nether) {
randomizerNether.add(item, chance);
}
else {
randomizer.add(item, chance);
}
}
private final GoldPan goldPan = (GoldPan) SlimefunItems.GOLD_PAN.getItem();
private final GoldPan netherGoldPan = (GoldPan) SlimefunItems.NETHER_GOLD_PAN.getItem();
@Override
public String getInventoryTitle() {
return "&6Electric Gold Pan";
}
@Override
public ItemStack getProgressBar() {
return new ItemStack(Material.DIAMOND_SHOVEL);
}
public abstract int getSpeed();
@Override
protected void tick(Block b) {
BlockMenu menu = BlockStorage.getInventory(b);
if (isProcessing(b)) {
int timeleft = progress.get(b);
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);
}
else if (ChargableBlock.isChargable(b)) {
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) return;
ChargableBlock.addCharge(b, -getEnergyConsumption());
menu.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "));
menu.pushItem(processing.get(b).getOutput()[0].clone(), getOutputSlots());
progress.remove(b);
processing.remove(b);
}
}
else {
for (int slot : getInputSlots()) {
if (process(b, menu, slot)) {
break;
}
}
}
}
private boolean process(Block b, BlockMenu menu, int slot) {
if (SlimefunUtils.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 (SlimefunUtils.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;
public ElectricGoldPan(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe);
}
@Override
public String getMachineIdentifier() {
return "ELECTRIC_GOLD_PAN";
}
@Override
public List<ItemStack> getDisplayRecipes() {
return displayRecipes;
}
public List<ItemStack> getDisplayRecipes() {
List<ItemStack> recipes = new ArrayList<>();
recipes.addAll(goldPan.getDisplayRecipes());
recipes.addAll(netherGoldPan.getDisplayRecipes());
return recipes;
}
@Override
public String getInventoryTitle() {
return "&6Electric Gold Pan";
}
@Override
public ItemStack getProgressBar() {
return new ItemStack(Material.DIAMOND_SHOVEL);
}
public abstract int getSpeed();
@Override
protected void tick(Block b) {
BlockMenu menu = BlockStorage.getInventory(b);
if (isProcessing(b)) {
int timeleft = progress.get(b);
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);
}
else if (ChargableBlock.isChargable(b)) {
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) return;
ChargableBlock.addCharge(b, -getEnergyConsumption());
menu.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "));
menu.pushItem(processing.get(b).getOutput()[0].clone(), getOutputSlots());
progress.remove(b);
processing.remove(b);
}
}
else {
for (int slot : getInputSlots()) {
if (process(b, menu, slot)) {
break;
}
}
}
}
private boolean process(Block b, BlockMenu menu, int slot) {
if (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), new ItemStack(Material.GRAVEL), true)) {
ItemStack output = goldPan.getRandomOutput();
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 (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), new ItemStack(Material.SOUL_SAND), true)) {
ItemStack output = netherGoldPan.getRandomOutput();
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

@ -17,7 +17,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
class EnderTalisman extends Talisman {
public EnderTalisman(Talisman parent) {
super(Categories.TALISMANS_2, parent.upgrade(), new ItemStack[] { SlimefunItems.ENDER_LUMP_3, null, SlimefunItems.ENDER_LUMP_3, null, parent.getItem(), null, SlimefunItems.ENDER_LUMP_3, null, SlimefunItems.ENDER_LUMP_3 }, parent.isConsumable(), parent.isEventCancelled(), parent.getSuffix(), parent.getChance(), parent.getEffects());
super(Categories.ENDER_TALISMANS, parent.upgrade(), new ItemStack[] { SlimefunItems.ENDER_LUMP_3, null, SlimefunItems.ENDER_LUMP_3, null, parent.getItem(), null, SlimefunItems.ENDER_LUMP_3, null, SlimefunItems.ENDER_LUMP_3 }, parent.isConsumable(), parent.isEventCancelled(), parent.getSuffix(), parent.getChance(), parent.getEffects());
}
@Override

View File

@ -44,7 +44,7 @@ public class Talisman extends SlimefunItem {
}
public Talisman(SlimefunItemStack item, ItemStack[] recipe, boolean consumable, boolean cancelEvent, String messageSuffix, int chance, PotionEffect... effects) {
this(Categories.TALISMANS_1, item, recipe, consumable, cancelEvent, messageSuffix, chance, effects);
this(Categories.TALISMANS, item, recipe, consumable, cancelEvent, messageSuffix, chance, effects);
}
protected Talisman(Category category, SlimefunItemStack item, ItemStack[] recipe, boolean consumable, boolean cancelEvent, String messageSuffix, int chance, PotionEffect... effects) {

View File

@ -76,7 +76,7 @@ public class DebugFishListener implements Listener {
p.sendMessage(" ");
p.sendMessage(ChatColors.color("&d" + b.getType() + " &e@ X: " + b.getX() + " Y: " + b.getY() + " Z: " + b.getZ()));
p.sendMessage(ChatColors.color("&dId: " + "&e" + item.getID()));
p.sendMessage(ChatColors.color("&Plugin: " + "&e" + item.getAddon().getName()));
p.sendMessage(ChatColors.color("&dPlugin: " + "&e" + item.getAddon().getName()));
if (b.getState() instanceof Skull) {
p.sendMessage(ChatColors.color("&dSkull: " + enabledTooltip));
@ -102,14 +102,14 @@ public class DebugFishListener implements Listener {
if (item.isTicking()) {
p.sendMessage(ChatColors.color("&dTicker: " + enabledTooltip));
p.sendMessage(ChatColors.color(" &dAsync: &e" + (BlockStorage.check(b).getBlockTicker().isSynchronized() ? disabledTooltip : enabledTooltip)));
p.sendMessage(ChatColors.color(" &dTimings: &e" + ticker.toMillis(ticker.getTimings(b), true) + "ms"));
p.sendMessage(ChatColors.color(" &dTotal Timings: &e" + ticker.toMillis(ticker.getTimings(BlockStorage.checkID(b)), true) + "ms"));
p.sendMessage(ChatColors.color(" &dChunk Timings: &e" + ticker.toMillis(ticker.getTimings(b.getChunk()), true) + "ms"));
p.sendMessage(ChatColors.color(" &dTimings: &e" + ticker.toMillis(ticker.getTimings(b), true)));
p.sendMessage(ChatColors.color(" &dTotal Timings: &e" + ticker.toMillis(ticker.getTimings(BlockStorage.checkID(b)), true)));
p.sendMessage(ChatColors.color(" &dChunk Timings: &e" + ticker.toMillis(ticker.getTimings(b.getChunk()), true)));
}
else if (item.getEnergyTicker() != null) {
p.sendMessage(ChatColors.color("&dTicking: " + "&3Indirect"));
p.sendMessage(ChatColors.color(" &dTimings: &e" + ticker.toMillis(ticker.getTimings(b), true) + "ms"));
p.sendMessage(ChatColors.color(" &dChunk Timings: &e" + ticker.toMillis(ticker.getTimings(b.getChunk()), true) + "ms"));
p.sendMessage(ChatColors.color(" &dTimings: &e" + ticker.toMillis(ticker.getTimings(b), true)));
p.sendMessage(ChatColors.color(" &dChunk Timings: &e" + ticker.toMillis(ticker.getTimings(b.getChunk()), true)));
}
else {
p.sendMessage(ChatColors.color("&dTicker: " + disabledTooltip));

View File

@ -1,6 +1,7 @@
package io.github.thebusybiscuit.slimefun4.implementation.listeners;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Result;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@ -8,10 +9,10 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide;
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout;
import io.github.thebusybiscuit.slimefun4.core.guide.options.SlimefunGuideSettings;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
public class SlimefunGuideListener implements Listener {
@ -27,7 +28,7 @@ public class SlimefunGuideListener implements Listener {
public void onJoin(PlayerJoinEvent e) {
if (giveOnFirstJoin && !e.getPlayer().hasPlayedBefore()) {
Player p = e.getPlayer();
if (!SlimefunPlugin.getWorldSettingsService().isWorldEnabled(p.getWorld())) {
return;
}
@ -40,52 +41,46 @@ public class SlimefunGuideListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST)
public void onInteract(PlayerRightClickEvent e) {
Player p = e.getPlayer();
ItemStack item = e.getItem();
if (SlimefunUtils.isItemSimilar(item, SlimefunGuide.getItem(SlimefunGuideLayout.BOOK), true)) {
e.cancel();
if (!SlimefunPlugin.getWorldSettingsService().isWorldEnabled(p.getWorld())) {
return;
}
if (openGuide(e, SlimefunGuideLayout.BOOK) == Result.ALLOW) {
if (p.isSneaking()) {
SlimefunGuideSettings.openSettings(p, item);
SlimefunGuideSettings.openSettings(p, e.getItem());
}
else {
SlimefunGuide.openGuide(p, SlimefunGuideLayout.BOOK);
}
}
else if (SlimefunUtils.isItemSimilar(item, SlimefunGuide.getItem(SlimefunGuideLayout.CHEST), true)) {
e.cancel();
if (!SlimefunPlugin.getWorldSettingsService().isWorldEnabled(p.getWorld())) {
return;
}
else if (openGuide(e, SlimefunGuideLayout.CHEST) == Result.ALLOW) {
if (p.isSneaking()) {
SlimefunGuideSettings.openSettings(p, item);
SlimefunGuideSettings.openSettings(p, e.getItem());
}
else {
SlimefunGuide.openGuide(p, SlimefunGuideLayout.CHEST);
}
}
else if (SlimefunUtils.isItemSimilar(item, SlimefunGuide.getItem(SlimefunGuideLayout.CHEAT_SHEET), true)) {
e.cancel();
if (!SlimefunPlugin.getWorldSettingsService().isWorldEnabled(p.getWorld())) {
return;
}
if (p.isSneaking()) {
SlimefunGuideSettings.openSettings(p, item);
}
else {
// We rather just run the command here,
// all necessary permission checks will be handled there.
p.chat("/sf cheat");
}
else if (openGuide(e, SlimefunGuideLayout.CHEAT_SHEET) == Result.ALLOW) {
// We rather just run the command here,
// all necessary permission checks will be handled there.
p.chat("/sf cheat");
}
}
private Result openGuide(PlayerRightClickEvent e, SlimefunGuideLayout layout) {
Player p = e.getPlayer();
ItemStack item = e.getItem();
if (SlimefunUtils.isItemSimilar(item, SlimefunGuide.getItem(layout), true)) {
e.cancel();
if (!SlimefunPlugin.getWorldSettingsService().isWorldEnabled(p.getWorld())) {
SlimefunPlugin.getLocal().sendMessage(p, "messages.disabled-item", true);
return Result.DENY;
}
return Result.ALLOW;
}
return Result.DEFAULT;
}
}

View File

@ -13,7 +13,6 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.logging.Level;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;
@ -204,15 +203,15 @@ public class TickerTask implements Runnable {
}
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(Locale.ROOT)));
sender.sendMessage(ChatColors.color("&2== &aSlimefun Diagnostic Tool &2=="));
sender.sendMessage(ChatColors.color("&6Halted: &e&l" + String.valueOf(halted).toUpperCase(Locale.ROOT)));
sender.sendMessage("");
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6Impact: &e" + toMillis(time, true)));
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(ChatColors.color("&6Impact: &e" + toMillis(time, true)));
sender.sendMessage(ChatColors.color("&6Ticked Chunks: &e" + chunks));
sender.sendMessage(ChatColors.color("&6Ticked Machines: &e" + machines));
sender.sendMessage(ChatColors.color("&6Skipped Machines: &e" + skipped));
sender.sendMessage("");
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6Ticking Machines:"));
sender.sendMessage(ChatColors.color("&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());
@ -240,7 +239,7 @@ public class TickerTask implements Runnable {
for (Map.Entry<String, Long> entry : timings) {
int count = machineCount.get(entry.getKey());
if (entry.getValue() > 500_000) {
if (entry.getValue() > 300_000) {
sender.sendMessage(" " + entry.getKey() + " - " + count + "x (" + toMillis(entry.getValue(), false) + ", " + toMillis(entry.getValue() / count, false) + " avg/machine)");
}
else hidden++;
@ -303,7 +302,8 @@ public class TickerTask implements Runnable {
}
public long getTimings(Chunk c) {
return chunkTimings.getOrDefault(c.toString(), 0L);
String id = c.getWorld().getName() + ';' + c.getX() + ';' + c.getZ();
return chunkTimings.getOrDefault(id, 0L);
}
public void addBlockTimings(Location l, long time) {
@ -319,14 +319,20 @@ public class TickerTask implements Runnable {
}
public String toMillis(long nanoseconds, boolean colors) {
String number = decimalFormat.format(nanoseconds / 1000000F);
String number = decimalFormat.format(nanoseconds / 1000000.0);
if (!colors) {
return number;
}
else {
String[] parts = PatternUtils.NUMBER_SEPERATOR.split(number);
return parts[0] + ',' + ChatColor.GRAY + parts[1] + "ms";
if (parts.length == 1) {
return parts[0];
}
else {
return parts[0] + ',' + ChatColor.GRAY + parts[1] + "ms";
}
}
}

View File

@ -42,12 +42,12 @@ public final class Categories {
public static final Category CARGO = new LockedCategory(new NamespacedKey(SlimefunPlugin.instance, "cargo"), new CustomItem(SlimefunItems.CARGO_MANAGER, "&cCargo Management"), 4, MACHINES_1);
public static final Category TECH_MISC = new Category(new NamespacedKey(SlimefunPlugin.instance, "tech_misc"), new CustomItem(SlimefunItems.HEATING_COIL, "&7Technical Components"), 2);
public static final Category MAGIC_ARMOR = new Category(new NamespacedKey(SlimefunPlugin.instance, "magical_armor"), new CustomItem(SlimefunItems.ENDER_HELMET, "&7Magical Armor"), 2);
public static final Category TALISMANS_1 = new Category(new NamespacedKey(SlimefunPlugin.instance, "talismans"), new CustomItem(SlimefunItems.TALISMAN, "&7Talismans - &aTier I"), 2);
public static final Category TALISMANS = new Category(new NamespacedKey(SlimefunPlugin.instance, "talismans"), new CustomItem(SlimefunItems.TALISMAN, "&7Talismans - &aTier I"), 2);
// Locked Categories
public static final LockedCategory ELECTRICITY = new LockedCategory(new NamespacedKey(SlimefunPlugin.instance, "electricity"), new CustomItem(SlimefunItems.NUCLEAR_REACTOR, "&bEnergy and Electricity"), 4, MACHINES_1);
public static final LockedCategory GPS = new LockedCategory(new NamespacedKey(SlimefunPlugin.instance, "gps"), new CustomItem(SlimefunItems.GPS_TRANSMITTER, "&bGPS-based Machines"), 4, MACHINES_1);
public static final LockedCategory TALISMANS_2 = new LockedCategory(new NamespacedKey(SlimefunPlugin.instance, "ender_talismans"), new CustomItem(SlimefunItems.ENDER_TALISMAN, "&7Talismans - &aTier II"), 3, TALISMANS_1);
public static final LockedCategory ENDER_TALISMANS = new LockedCategory(new NamespacedKey(SlimefunPlugin.instance, "ender_talismans"), new CustomItem(SlimefunItems.ENDER_TALISMAN, "&7Talismans - &aTier II"), 3, TALISMANS);
// Seasonal Categories
public static final SeasonalCategory CHRISTMAS = new SeasonalCategory(new NamespacedKey(SlimefunPlugin.instance, "christmas"), Month.DECEMBER, 1, new CustomItem(Material.NETHER_STAR, ChatUtils.christmas("Christmas") + " &7(December only)"));

View File

@ -84,13 +84,11 @@ public class Category implements Keyed {
/**
* Registers this category.
* <p>
* By default, a category is automatically registered when a {@link SlimefunItem} is bound to it.
* By default, a category is automatically registered when a {@link SlimefunItem} was added to it.
*/
public void register() {
if (!(this instanceof SeasonalCategory) || ((SeasonalCategory) this).isVisible()) {
SlimefunPlugin.getRegistry().getEnabledCategories().add(this);
Collections.sort(SlimefunPlugin.getRegistry().getEnabledCategories(), Comparator.comparingInt(Category::getTier));
}
SlimefunPlugin.getRegistry().getCategories().add(this);
Collections.sort(SlimefunPlugin.getRegistry().getCategories(), Comparator.comparingInt(Category::getTier));
}
/**

View File

@ -377,7 +377,7 @@ public class SlimefunItem implements Placeable {
if (SlimefunPlugin.getItemCfg().getBoolean(id + ".enabled")) {
if (!SlimefunPlugin.getRegistry().getEnabledCategories().contains(category)) {
if (!SlimefunPlugin.getRegistry().getCategories().contains(category)) {
category.register();
}

View File

@ -38,6 +38,7 @@ import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.inventory.UniversalBlockMenu;
// This class really needs a big overhaul
public class BlockStorage {
private static final String PATH_BLOCKS = "data-storage/Slimefun/stored-blocks/";

View File

@ -8,8 +8,6 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitTask;
import io.github.thebusybiscuit.cscorelib2.config.Config;
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
import io.github.thebusybiscuit.slimefun4.implementation.items.VanillaItem;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
@ -30,36 +28,6 @@ public final class Slimefun {
return SlimefunPlugin.instance.getLogger();
}
/**
* Returns the value associated to this key for the SlimefunItem corresponding to this id.
*
* @deprecated Please use the {@link ItemSetting} API instead.
*
* @param id
* the id of the SlimefunItem, not null
* @param key
* the key of the value to get, not null
*
* @return the value associated to the key for the SlimefunItem corresponding to the id,
* or null if it doesn't exist.
*/
@Deprecated
public static Object getItemValue(String id, String key) {
return getItemConfig().getValue(id + '.' + key);
}
/**
* Returns the {@link Config} instance of our Items.yml file.
*
* @deprecated Do not access this directly, use the {@link ItemSetting} API instead.
*
* @return the Items.yml Config instance.
*/
@Deprecated
public static Config getItemConfig() {
return SlimefunPlugin.getItemCfg();
}
/**
* Registers this Research and automatically binds these ItemStacks to it.
* <p>
@ -90,13 +58,7 @@ public final class Slimefun {
}
public static void registerResearch(NamespacedKey key, int id, String name, int cost, ItemStack... items) {
Research research = new Research(key, id, name, cost);
for (ItemStack item : items) {
research.addItems(SlimefunItem.getByItem(item));
}
research.register();
registerResearch(new Research(key, id, name, cost), items);
}
/**
@ -118,7 +80,10 @@ public final class Slimefun {
if (sfItem != null) {
if (sfItem.getState() == ItemState.DISABLED) {
if (message) SlimefunPlugin.getLocal().sendMessage(p, "messages.disabled-item", true);
if (message) {
SlimefunPlugin.getLocal().sendMessage(p, "messages.disabled-item", true);
}
return false;
}
@ -167,6 +132,7 @@ public final class Slimefun {
return false;
}
}
return false;
}