Skip to content

Commit

Permalink
chore: 综合性能优化
Browse files Browse the repository at this point in the history
减少内存使用量
  • Loading branch information
mcchampions committed Dec 19, 2024
1 parent 11bd144 commit a3ecc84
Show file tree
Hide file tree
Showing 47 changed files with 6,193 additions and 6,136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
import me.qscbm.slimefun4.utils.QsConstants;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
Expand Down Expand Up @@ -79,7 +80,7 @@ public void newInstance(BlockMenu menu, Block b) {

@Override
public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) {
return new int[0];
return QsConstants.EMPTY_INTS;
}

@Override
Expand All @@ -96,7 +97,7 @@ public int[] getSlotsAccessedByItemTransport(DirtyChestMenu menu, ItemTransportF
if (SlimefunUtils.isItemSimilar(itemInSlot, wrapper, true, false)
&& (itemAmount += itemInSlot.getAmount()) > amountLimit) {
// Amount has reached the limited, just return.
return new int[0];
return QsConstants.EMPTY_INTS;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,6 @@ public static int execUpdate(Connection conn, String sql) throws SQLException {
}

private static boolean isWildcardsMatching(String val) {
return val.endsWith("%") || val.contains("%");
return val.charAt(val.length() - 1) == '%' || val.contains("%");
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.xzavier0722.mc.plugin.slimefun4.storage.common;

import lombok.Getter;
import me.qscbm.slimefun4.utils.QsConstants;

@Getter
public enum DataScope {
Expand All @@ -20,7 +21,7 @@ public enum DataScope {
private final FieldKey[] primaryKeys;

DataScope() {
primaryKeys = new FieldKey[0];
primaryKeys = QsConstants.EMPTY_FIELD_KEYS;
}

DataScope(FieldKey[] primaryKeys) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,9 @@ void saveUniversalData(UUID uuid, String sfId, Set<UniversalDataTrait> traits) {
public void removeBlock(Location l) { SlimefunBlockData removed = getChunkDataCache(l.getChunk(), true).removeBlockData(l);
if (removed == null) {
getUniversalBlockDataFromCache(l)
.ifPresentOrElse(data -> removeUniversalBlockData(data.getUUID(), l), () -> {
Slimefun.getBlockDataService()
.getUniversalDataUUID(l.getBlock())
.ifPresent(uuid -> removeUniversalBlockData(uuid, l));
});
.ifPresentOrElse(data -> removeUniversalBlockData(data.getUUID(), l), () -> Slimefun.getBlockDataService()
.getUniversalDataUUID(l.getBlock())
.ifPresent(uuid -> removeUniversalBlockData(uuid, l)));
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class ProfileDataController extends ADataController {

int bNum = result.get(0).getInt(FieldKey.BACKPACK_NUMBER);

Set<Research> researches = new HashSet<Research>();
Set<Research> researches = new HashSet<>();
getUnlockedResearchKeys(uuid).forEach(rKey -> Research.getResearch(rKey).ifPresent(researches::add));

re = new PlayerProfile(p, bNum, researches);
Expand Down Expand Up @@ -187,7 +187,7 @@ public Set<PlayerBackpack> getBackpacks(String pUuid) {
return Collections.emptySet();
}

Set<PlayerBackpack> re = new HashSet<PlayerBackpack>();
Set<PlayerBackpack> re = new HashSet<>();
result.forEach(bUuid -> re.add(getBackpack(bUuid.get(FieldKey.BACKPACK_ID))));
return re;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public class SlimefunBlockBreakEvent extends Event implements Cancellable {
* @param slimefunItem The {@link SlimefunItem} within the {@link ItemStack}
*/
public SlimefunBlockBreakEvent(Player player, ItemStack heldItem, Block blockBroken, SlimefunItem slimefunItem) {
super();

this.player = player;
this.heldItem = heldItem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public class SlimefunBlockPlaceEvent extends Event implements Cancellable {
* @param slimefunItem The {@link SlimefunItem} within the {@link ItemStack}
*/
public SlimefunBlockPlaceEvent(Player player, ItemStack placedItem, Block blockPlaced, SlimefunItem slimefunItem) {
super();

this.player = player;
this.placedItem = placedItem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ private void updateProgress(
60,
0);

source.getWorld().spawnParticle(Particle.PORTAL, source, progress * 2, 0.2F, 0.8F, 0.2F);
source.getWorld().spawnParticle(Particle.PORTAL, source, progress << 1, 0.2F, 0.8F, 0.2F);
SoundEffect.TELEPORT_UPDATE_SOUND.playFor(p);
Slimefun.runSync(
() -> updateProgress(uuid, speed, progress + speed, source, destination, resistance), 10L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public static List<ItemStack[]> getRecipeInputList(MultiBlockMachine machine) {

public static ItemStack getRecipeOutput(MultiBlockMachine machine, ItemStack input) {
List<ItemStack[]> recipes = machine.getRecipes();
return recipes.get(((getRecipeInputs(machine).indexOf(input) * 2) + 1))[0].clone();
return recipes.get(((getRecipeInputs(machine).indexOf(input) << 1) + 1))[0].clone();
}

public static ItemStack getRecipeOutputList(MultiBlockMachine machine, ItemStack[] input) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import javax.annotation.Nullable;

import lombok.Getter;
import me.qscbm.slimefun4.utils.QsConstants;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
Expand Down Expand Up @@ -63,7 +64,7 @@ protected MultiBlockMachine(
}

protected MultiBlockMachine(ItemGroup itemGroup, SlimefunItemStack item, ItemStack[] recipe, BlockFace trigger) {
this(itemGroup, item, recipe, new ItemStack[0], trigger);
this(itemGroup, item, recipe, QsConstants.EMPTY_ITEM_STACKS, trigger);
}

protected void registerDefaultRecipes(List<ItemStack> recipes) {
Expand Down Expand Up @@ -215,6 +216,6 @@ private static Material[] convertItemStacksToMaterial(ItemStack[] items) {
}
}

return materials.toArray(new Material[0]);
return materials.toArray(QsConstants.EMPTY_MATERIALS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import java.util.Optional;
import java.util.function.Consumer;
import javax.annotation.Nullable;

import me.qscbm.slimefun4.utils.QsConstants;
import org.bukkit.Bukkit;
import org.bukkit.Keyed;
import org.bukkit.NamespacedKey;
Expand Down Expand Up @@ -141,7 +143,7 @@ public static RecipeChoice[] getRecipeShape(Recipe recipe) {
}
}

return choices.toArray(new RecipeChoice[0]);
return choices.toArray(QsConstants.EMPTY_RECIPE_CHOICES);
} else {
return RecipeSnapshot.getRecipeInput(recipe);
}
Expand All @@ -158,9 +160,9 @@ public static RecipeChoice[] getRecipeShape(Recipe recipe) {
*/
public Recipe[] getRecipesFor(@Nullable ItemStack item) {
if (snapshot == null || item == null) {
return new Recipe[0];
return QsConstants.EMPTY_RECIPES;
} else {
return snapshot.getRecipesFor(item).toArray(new Recipe[0]);
return snapshot.getRecipesFor(item).toArray(QsConstants.EMPTY_RECIPES);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ public final class Slimefun extends JavaPlugin implements SlimefunAddon, ICompat
* Our default constructor for {@link Slimefun}.
*/
public Slimefun() {
super();
}

private boolean initialized;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu.MenuClickHandler;
import me.qscbm.slimefun4.utils.QsConstants;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Tag;
Expand Down Expand Up @@ -217,7 +218,7 @@ private void showItemGroup(ChestMenu menu, Player p, PlayerProfile profile, Item
+ Slimefun.getLocalization().getMessage(p, "guide.locked")
+ " &7- &f"
+ group.getItem(p).getItemMeta().getDisplayName(),
lore.toArray(new String[0])));
lore.toArray(QsConstants.EMPTY_STRINGS)));
menu.addMenuClickHandler(index, ChestMenuUtils.getEmptyClickHandler());
}
}
Expand Down Expand Up @@ -306,7 +307,7 @@ private void displaySlimefunItem(
new CustomItemStack(
ChestMenuUtils.getNoPermissionItem(),
sfitem.getItemName(),
message.toArray(new String[0])));
message.toArray(QsConstants.EMPTY_STRINGS)));
menu.addMenuClickHandler(index, ChestMenuUtils.getEmptyClickHandler());
} else if (isSurvivalMode() && research != null && !profile.hasUnlocked(research)) {
String lore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.InventoryBlock;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
import me.qscbm.slimefun4.utils.QsConstants;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
Expand Down Expand Up @@ -162,7 +163,7 @@ public void newInstance(UniversalMenu menu, Block b) {

@Override
public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) {
return new int[0];
return QsConstants.EMPTY_INTS;
}
};

Expand Down Expand Up @@ -721,7 +722,7 @@ public List<ItemStack> getDisplayRecipes() {

@Override
public int[] getInputSlots() {
return new int[0];
return QsConstants.EMPTY_INTS;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.github.thebusybiscuit.slimefun4.utils.ChatUtils;
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
import lombok.Getter;
import me.qscbm.slimefun4.utils.QsConstants;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
Expand Down Expand Up @@ -121,7 +122,7 @@ ItemStack getAsItemStack(ProgrammableAndroid android, Player p) {
lore.add("&eShift + 右键 &f差评");
}

return new CustomItemStack(android.getItem(), "&b" + name, lore.toArray(new String[0]));
return new CustomItemStack(android.getItem(), "&b" + name, lore.toArray(QsConstants.EMPTY_STRINGS));
}

private String getScriptRatingPercentage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Arrays;

import lombok.Getter;
import me.qscbm.slimefun4.utils.QsConstants;
import org.bukkit.Color;
import org.bukkit.DyeColor;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -43,7 +44,7 @@ public RainbowArmorPiece(
RecipeType recipeType,
ItemStack[] recipe,
DyeColor[] dyeColors) {
super(itemGroup, item, recipeType, recipe, new PotionEffect[0]);
super(itemGroup, item, recipeType, recipe, QsConstants.EMPTY_POTION_EFFECTS);

// TODO Change this validation over to our custom validation blocked by
// https://github.com/baked-libs/dough/pull/184
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import javax.annotation.Nullable;

import me.qscbm.slimefun4.utils.QsConstants;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
Expand All @@ -21,7 +22,7 @@ public SlimefunArmorPiece(
@Nullable PotionEffect[] effects) {
super(itemGroup, item, recipeType, recipe);

this.effects = effects == null ? new PotionEffect[0] : effects;
this.effects = effects == null ? QsConstants.EMPTY_POTION_EFFECTS : effects;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
import me.qscbm.slimefun4.utils.QsConstants;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -64,7 +65,7 @@ public boolean canOpen(Block b, Player p) {

@Override
public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) {
return new int[0];
return QsConstants.EMPTY_INTS;
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.qscbm.slimefun4.utils.QsConstants;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -45,7 +46,7 @@ public int[] getInputSlots() {

@Override
public int[] getOutputSlots() {
return new int[0];
return QsConstants.EMPTY_INTS;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public List<ItemStack> getDisplayRecipes() {
ItemMeta im = item.getItemMeta();
List<String> lore = new ArrayList<>();
lore.add("§8\u21E8 §7持续时间 " + NumberUtils.getTimeLeft(fuel.getTicks() / 2));
lore.add("§8\u21E8 §e\u26A1 §7" + getEnergyProduction() * 2 + " J/s");
lore.add("§8\u21E8 §e\u26A1 §7" + (getEnergyProduction() << 1) + " J/s");
lore.add("§8\u21E8 §e\u26A1 §7最大储存量: "
+ NumberUtils.getCompactDouble((double) fuel.getTicks() * getEnergyProduction())
+ " J");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public ItemStack getProgressBar() {

@Override
public List<ItemStack> getDisplayRecipes() {
List<ItemStack> displayRecipes = new ArrayList<>(recipes.size() * 2);
List<ItemStack> displayRecipes = new ArrayList<>(recipes.size() << 1);

for (MachineRecipe recipe : recipes) {
displayRecipes.add(recipe.getInput()[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
import me.qscbm.slimefun4.items.machines.ASpeedableContainer;
import me.qscbm.slimefun4.utils.QsConstants;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -54,7 +55,7 @@ public boolean canOpen(Block b, Player p) {

@Override
public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) {
return new int[0];
return QsConstants.EMPTY_INTS;
}

@Override
Expand All @@ -81,7 +82,7 @@ public int[] getSlotsAccessedByItemTransport(DirtyChestMenu menu, ItemTransportF
return getInputSlots();
} else if (fullSlots == slots.size()) {
// All slots with that item are already full
return new int[0];
return QsConstants.EMPTY_INTS;
} else {
slots.sort(compareSlots(menu));
int[] array = new int[slots.size()];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected void registerDefaultRecipes() {

@Override
public List<ItemStack> getDisplayRecipes() {
List<ItemStack> displayRecipes = new ArrayList<>(recipes.size() * 2);
List<ItemStack> displayRecipes = new ArrayList<>(recipes.size() << 1);

for (MachineRecipe recipe : recipes) {
displayRecipes.add(recipe.getInput()[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
import me.qscbm.slimefun4.items.machines.ASpeedableContainer;
import me.qscbm.slimefun4.utils.QsConstants;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -41,7 +42,7 @@ public boolean canOpen(Block b, Player p) {

@Override
public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) {
return new int[0];
return QsConstants.EMPTY_INTS;
}

@Override
Expand Down
Loading

0 comments on commit a3ecc84

Please sign in to comment.