1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

[CI skip] A lot of internal cleanup, performance improvements

This commit is contained in:
TheBusyBiscuit 2020-02-10 12:42:34 +01:00
parent e53746990e
commit b916c3636b
11 changed files with 103 additions and 183 deletions

View File

@ -155,29 +155,10 @@ public class BlockListener implements Listener {
e.getBlockPlaced().getWorld().dropItemNaturally(e.getBlockPlaced().getLocation(), gifts.get(ThreadLocalRandom.current().nextInt(gifts.size())));
}
else if (SlimefunManager.isItemSimilar(item, SlimefunItems.CARGO_INPUT, false)) {
if (e.getBlock().getY() != e.getBlockAgainst().getY()) {
SlimefunPlugin.getLocal().sendMessage(e.getPlayer(), "machines.CARGO_NODES.must-be-placed", true);
e.setCancelled(true);
}
}
else if (SlimefunManager.isItemSimilar(item, SlimefunItems.CARGO_OUTPUT, false)) {
if (e.getBlock().getY() != e.getBlockAgainst().getY()) {
SlimefunPlugin.getLocal().sendMessage(e.getPlayer(), "machines.CARGO_NODES.must-be-placed", true);
e.setCancelled(true);
}
}
else if (SlimefunManager.isItemSimilar(item, SlimefunItems.CARGO_OUTPUT_ADVANCED, false)) {
if (e.getBlock().getY() != e.getBlockAgainst().getY()) {
SlimefunPlugin.getLocal().sendMessage(e.getPlayer(), "machines.CARGO_NODES.must-be-placed", true);
e.setCancelled(true);
}
}
else if (SlimefunManager.isItemSimilar(item, SlimefunItems.CT_IMPORT_BUS, false) && e.getBlock().getY() != e.getBlockAgainst().getY()) {
else if (e.getBlock().getY() != e.getBlockAgainst().getY() && (SlimefunManager.isItemSimilar(item, SlimefunItems.CARGO_INPUT, false) || SlimefunManager.isItemSimilar(item, SlimefunItems.CARGO_OUTPUT, false) || SlimefunManager.isItemSimilar(item, SlimefunItems.CARGO_OUTPUT_ADVANCED, false))) {
SlimefunPlugin.getLocal().sendMessage(e.getPlayer(), "machines.CARGO_NODES.must-be-placed", true);
e.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)

View File

@ -122,9 +122,7 @@ public class SlimefunItemListener implements Listener {
private boolean canPlaceCargoNodes(Player p, ItemStack item, Block b) {
return canPlaceBlock(p, b) && (SlimefunManager.isItemSimilar(item, SlimefunItems.CARGO_INPUT, true)
|| SlimefunManager.isItemSimilar(item, SlimefunItems.CARGO_OUTPUT, true)
|| SlimefunManager.isItemSimilar(item, SlimefunItems.CARGO_OUTPUT_ADVANCED, true)
|| SlimefunManager.isItemSimilar(item, SlimefunItems.CT_IMPORT_BUS, true)
|| SlimefunManager.isItemSimilar(item, SlimefunItems.CT_EXPORT_BUS, true));
|| SlimefunManager.isItemSimilar(item, SlimefunItems.CARGO_OUTPUT_ADVANCED, true));
}
private boolean canPlaceBlock(Player p, Block relative) {

View File

@ -766,11 +766,4 @@ public final class SlimefunItems {
static {
INFUSED_ELYTRA.addUnsafeEnchantment(Enchantment.MENDING, 1);
}
// ChestTerminal Addon
public static final ItemStack CHEST_TERMINAL = new SlimefunItemStack("CHEST_TERMINAL", "7a44ff3a5f49c69cab676bad8d98a063fa78cfa61916fdef3e267557fec18283", "&3CT Access Terminal", "&7If this Block is connected to a", "&7Cargo Network, it will allow you to remotely", "&7interact with any Items supplied by", "&7Nodes tuned into the ChestTerminal Channel");
public static final ItemStack CT_IMPORT_BUS = new SlimefunItemStack("CT_IMPORT_BUS", "113db2e7e72ea4432eefbd6e58a85eaa2423f83e642ca41abc6a9317757b889", "&3CT Import Bus", "&7If this Block is connected to a", "&7Cargo Network, it will pull any Items from", "&7the Inventory it is attached to and place it", "&7into the CT Network Channel");
public static final ItemStack CT_EXPORT_BUS = new SlimefunItemStack("CT_EXPORT_BUS", "113db2e7e72ea4432eefbd6e58a85eaa2423f83e642ca41abc6a9317757b889", "&3CT Export Bus", "&7If this Block is connected to a", "&7Cargo Network, it will pull any Items from", "&7the CT Network Channel and place these", "&7into the Inventory it is attached to");
}

View File

@ -27,7 +27,7 @@ public class EnderTalisman extends Talisman {
}
@Override
public void create() {
public void postRegister() {
// Let's override that, otherwise we would be creating Ender Talismans
// for every Ender Talisman
}

View File

@ -11,7 +11,7 @@ public class ReplacingItem extends SlimefunItem {
public ReplacingItem(Category category, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, id, recipeType, recipe);
this.setReplacing(true);
useableInWorkbench = true;
}
}

View File

@ -20,7 +20,6 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.collections.OptionalMap;
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
import io.github.thebusybiscuit.slimefun4.api.items.Placeable;
import io.github.thebusybiscuit.slimefun4.core.SlimefunRegistry;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
@ -39,15 +38,16 @@ import me.mrCookieSlime.Slimefun.api.energy.EnergyNetComponent;
import me.mrCookieSlime.Slimefun.api.energy.EnergyTicker;
public class SlimefunItem implements Placeable {
private String id;
private ItemState state;
private ItemStack item;
private Category category;
private ItemStack[] recipe;
private RecipeType recipeType;
protected String id;
protected ItemStack item;
protected Category category;
protected ItemStack[] recipe;
protected RecipeType recipeType;
protected ItemStack recipeOutput;
private Research research;
protected Research research;
protected boolean enchantable = true;
protected boolean disenchantable = true;
@ -57,13 +57,15 @@ public class SlimefunItem implements Placeable {
private boolean addon = false;
private String permission = "";
private List<String> noPermissionTooltip;
private String[] keys;
private Object[] values;
private String wiki = null;
private final OptionalMap<Class<? extends ItemHandler>, ItemHandler> itemhandlers = new OptionalMap<>(HashMap::new);
private boolean ticking = false;
private BlockTicker blockTicker;
private EnergyTicker energyTicker;
private String[] keys;
private Object[] values;
private String wiki = null;
@Deprecated
public SlimefunItem(Category category, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe) {
@ -92,12 +94,6 @@ public class SlimefunItem implements Placeable {
this(category, item, id, recipeType, recipe, null, keys, values);
}
@Deprecated
public SlimefunItem(Category category, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe, boolean hidden) {
this(category, item, id, recipeType, recipe);
this.hidden = hidden;
}
// Root constructor
public SlimefunItem(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput, String[] keys, Object[] values) {
this.category = category;
@ -129,43 +125,73 @@ public class SlimefunItem implements Placeable {
*
* @since 4.1.11, rename of {@link #getName()}.
*/
public String getID() { return id; }
public String getID() {
return id;
}
public ItemState getState() { return state; }
public ItemStack getItem() { return item; }
public Category getCategory() { return category; }
public ItemStack[] getRecipe() { return recipe; }
public RecipeType getRecipeType() { return recipeType; }
public ItemState getState() {
return state;
}
/**
* @since 4.1.11, rename of {@link #getCustomOutput()}.
*/
public ItemStack getRecipeOutput() { return recipeOutput; }
public Research getResearch() { return research; }
public boolean isEnchantable() { return enchantable; }
public boolean isDisenchantable() { return disenchantable; }
/**
* @since 4.1.11
*/
public boolean isHidden() { return hidden; }
public ItemStack getItem() {
return item;
}
public Category getCategory() {
return category;
}
public ItemStack[] getRecipe() {
return recipe;
}
public RecipeType getRecipeType() {
return recipeType;
}
public ItemStack getRecipeOutput() {
return recipeOutput;
}
public Research getResearch() {
return research;
}
public boolean isEnchantable() {
return enchantable;
}
public boolean isDisenchantable() {
return disenchantable;
}
@Deprecated
public boolean isReplacing() { return useableInWorkbench; }
public boolean isAddonItem() { return addon; }
/**
* @since 4.1.11
*/
public String getPermission() { return permission; }
public List<String> getNoPermissionTooltip() { return noPermissionTooltip; }
/**
* @since 4.1.11, rename of {@link #getTicker()}.
*/
public BlockTicker getBlockTicker() { return blockTicker; }
public EnergyTicker getEnergyTicker() { return energyTicker; }
public String[] listKeys() { return keys; }
public Object[] listValues() { return values; }
public boolean isDisabled() { return state != ItemState.ENABLED; }
public boolean isHidden() {
return hidden;
}
public boolean isAddonItem() {
return addon;
}
public String getPermission() {
return permission;
}
public List<String> getNoPermissionTooltip() {
return noPermissionTooltip;
}
public BlockTicker getBlockTicker() {
return blockTicker;
}
public EnergyTicker getEnergyTicker() {
return energyTicker;
}
public boolean isDisabled() {
return state != ItemState.ENABLED;
}
public void register() {
register(false);
@ -229,8 +255,6 @@ public class SlimefunItem implements Placeable {
SlimefunPlugin.getRegistry().getEnabledSlimefunItems().add(this);
SlimefunPlugin.getRegistry().getSlimefunItemIds().put(this.id, this);
create();
for (ItemHandler handler : itemhandlers.values()) {
if (areItemHandlersPrivate()) continue;
@ -257,15 +281,6 @@ public class SlimefunItem implements Placeable {
}
}
/**
* @deprecated Use {@link SlimefunRegistry#getEnabledSlimefunItems()}
* @return A list of all enabled Slimefun Items
*/
@Deprecated
public static List<SlimefunItem> list() {
return SlimefunPlugin.getRegistry().getEnabledSlimefunItems();
}
public void bindToResearch(Research r) {
if (r != null) r.getAffectedItems().add(this);
this.research = r;
@ -287,18 +302,10 @@ public class SlimefunItem implements Placeable {
this.recipeOutput = output;
}
@Deprecated
public void setReplacing(boolean replacing) {
this.useableInWorkbench = replacing;
}
public boolean isUseableInWorkbench() {
return useableInWorkbench;
}
/**
* @since 4.1.11, rename of {@link #getByName(String)}.
*/
public static SlimefunItem getByID(String id) {
return SlimefunPlugin.getRegistry().getSlimefunItemIds().get(id);
}
@ -385,37 +392,11 @@ public class SlimefunItem implements Placeable {
}
}
public static ItemState getState(ItemStack item) {
for (SlimefunItem i : SlimefunPlugin.getRegistry().getAllSlimefunItems()) {
if (i.isItem(item)) {
return i.getState();
}
}
return ItemState.ENABLED;
}
public static boolean isDisabled(ItemStack item) {
for (SlimefunItem i : SlimefunPlugin.getRegistry().getAllSlimefunItems()) {
if (i.isItem(item)) {
return i.isDisabled();
}
}
return false;
}
@Deprecated
public void install() {
// Deprecated
}
/**
* @deprecated Use {@link SlimefunItem#postRegister()} instead
*/
@Deprecated
public void create() {
// Deprecated
}
public void addItemHandler(ItemHandler... handlers) {
for (ItemHandler handler : handlers) {
itemhandlers.put(handler.getIdentifier(), handler);

View File

@ -92,7 +92,7 @@ public class Talisman extends SlimefunItem {
}
@Override
public void create() {
public void postRegister() {
EnderTalisman talisman = new EnderTalisman(this);
talisman.register(!isAddonItem());
}

View File

@ -14,7 +14,6 @@ import io.github.thebusybiscuit.cscorelib2.skull.SkullItem;
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
@ -112,7 +111,7 @@ public class AdvancedCargoOutputNode extends SlimefunItem {
int channel = ((!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "frequency") == null) ? 0: (Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency"))));
if (channel == 16) {
menu.replaceExistingItem(42, new CustomItem(SlimefunItems.CHEST_TERMINAL, "&bChannel ID: &3" + (channel + 1)));
menu.replaceExistingItem(42, new CustomItem(SkullItem.fromHash("7a44ff3a5f49c69cab676bad8d98a063fa78cfa61916fdef3e267557fec18283"), "&bChannel ID: &3" + (channel + 1)));
menu.addMenuClickHandler(42, ChestMenuUtils.getEmptyClickHandler());
}
else {

View File

@ -14,7 +14,6 @@ import io.github.thebusybiscuit.cscorelib2.skull.SkullItem;
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
@ -130,7 +129,7 @@ public class CargoInputNode extends SlimefunItem {
int channel = ((!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "frequency") == null) ? 0: (Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency"))));
if (channel == 16) {
menu.replaceExistingItem(42, new CustomItem(SlimefunItems.CHEST_TERMINAL, "&bChannel ID: &3" + (channel + 1)));
menu.replaceExistingItem(42, new CustomItem(SkullItem.fromHash("7a44ff3a5f49c69cab676bad8d98a063fa78cfa61916fdef3e267557fec18283"), "&bChannel ID: &3" + (channel + 1)));
menu.addMenuClickHandler(42, ChestMenuUtils.getEmptyClickHandler());
}
else {

View File

@ -12,7 +12,6 @@ import io.github.thebusybiscuit.cscorelib2.skull.SkullItem;
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
@ -56,7 +55,7 @@ public class CargoOutputNode extends SlimefunItem {
int channel = ((!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "frequency") == null) ? 0: (Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency"))));
if (channel == 16) {
menu.replaceExistingItem(13, new CustomItem(SlimefunItems.CHEST_TERMINAL, "&bChannel ID: &3" + (channel + 1)));
menu.replaceExistingItem(13, new CustomItem(SkullItem.fromHash("7a44ff3a5f49c69cab676bad8d98a063fa78cfa61916fdef3e267557fec18283"), "&bChannel ID: &3" + (channel + 1)));
menu.addMenuClickHandler(13, ChestMenuUtils.getEmptyClickHandler());
}
else {

View File

@ -12,8 +12,6 @@ import org.bukkit.scheduler.BukkitTask;
import io.github.thebusybiscuit.cscorelib2.config.Config;
import io.github.thebusybiscuit.slimefun4.api.gps.GPSNetwork;
import io.github.thebusybiscuit.slimefun4.core.SlimefunRegistry;
import io.github.thebusybiscuit.slimefun4.core.services.LocalizationService;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Objects.Research;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.ItemState;
@ -128,30 +126,27 @@ public final class Slimefun {
*/
public static boolean hasUnlocked(Player p, ItemStack item, boolean message) {
SlimefunItem sfItem = SlimefunItem.getByItem(item);
ItemState state = SlimefunItem.getState(item);
if (sfItem == null) {
if (state != ItemState.ENABLED) {
if (message && state != ItemState.VANILLA) {
SlimefunPlugin.getLocal().sendMessage(p, "messages.disabled-item", true);
}
if (sfItem != null) {
if (sfItem.getState() == ItemState.DISABLED) {
if (message) SlimefunPlugin.getLocal().sendMessage(p, "messages.disabled-item", true);
return false;
}
else return true;
}
else if (isEnabled(p, item, message) && hasPermission(p, sfItem, message)) {
if (sfItem.getResearch() == null) return true;
else if (PlayerProfile.get(p).hasUnlocked(sfItem.getResearch())) return true;
else {
if (message && !(sfItem instanceof VanillaItem)) {
SlimefunPlugin.getLocal().sendMessage(p, "messages.not-researched", true);
if (isEnabled(p, item, message) && hasPermission(p, sfItem, message)) {
if (sfItem.getResearch() == null) return true;
else if (PlayerProfile.get(p).hasUnlocked(sfItem.getResearch())) return true;
else {
if (message && !(sfItem instanceof VanillaItem)) {
SlimefunPlugin.getLocal().sendMessage(p, "messages.not-researched", true);
}
return false;
}
return false;
}
else return false;
}
else return false;
else return true;
}
/**
@ -208,7 +203,8 @@ public final class Slimefun {
*/
public static boolean isEnabled(Player p, ItemStack item, boolean message) {
SlimefunItem sfItem = SlimefunItem.getByItem(item);
if (sfItem == null) return !SlimefunItem.isDisabled(item);
if (sfItem == null) return true;
else return isEnabled(p, sfItem, message);
}
@ -246,37 +242,11 @@ public final class Slimefun {
else return true;
}
/**
* Lists all the IDs of the enabled items.
*
* @deprecated Use {@link SlimefunRegistry#getEnabledSlimefunItemIds()}
*
* @return the list of all the IDs of the enabled items.
*/
@Deprecated
public static List<String> listIDs() {
List<String> ids = new ArrayList<>();
for (SlimefunItem item : SlimefunItem.list()) {
ids.add(item.getID());
}
return ids;
}
@Deprecated
public static List<GuideHandler> getGuideHandlers(int tier) {
return SlimefunPlugin.getRegistry().getGuideHandlers().getOrDefault(tier, new ArrayList<>());
}
@Deprecated
public static String getVersion() {
return SlimefunPlugin.instance.getDescription().getVersion();
}
@Deprecated
public static LocalizationService getLocal() {
return SlimefunPlugin.getLocal();
}
public static BukkitTask runSync(Runnable r) {
return Bukkit.getScheduler().runTask(SlimefunPlugin.instance, r);
}