Skip to content

Commit

Permalink
chore: 优化性能
Browse files Browse the repository at this point in the history
  • Loading branch information
mcchampions committed Nov 30, 2024
1 parent 1cf142c commit c7ac804
Show file tree
Hide file tree
Showing 19 changed files with 48 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public void removeBlock(Location l) {
}

if (Slimefun.getRegistry().getTickerBlocks().contains(removed.getSfId())) {
if (removed.getSfId().equalsIgnoreCase("CARGO_MANAGER")) {
if ("CARGO_MANAGER".equalsIgnoreCase(removed.getSfId())) {
Slimefun.instance().getCargoTickerTask().enableTicker(l);
} else {
Slimefun.getTickerTask().enableTicker(l);
Expand Down Expand Up @@ -550,7 +550,7 @@ public void setBlockDataLocation(SlimefunBlockData blockData, Location target) {
var hasTicker = false;

if (blockData.isDataLoaded() && Slimefun.getRegistry().getTickerBlocks().contains(blockData.getSfId())) {
if (blockData.getSfId().equalsIgnoreCase("CARGO_MANAGER")) {
if ("CARGO_MANAGER".equalsIgnoreCase(blockData.getSfId())) {
Slimefun.instance().getCargoTickerTask().disableTicker(blockData.getLocation());
} else {
Slimefun.getTickerTask().disableTicker(blockData.getLocation());
Expand Down Expand Up @@ -611,7 +611,7 @@ public void setBlockDataLocation(SlimefunBlockData blockData, Location target) {
scheduleWriteTask(scopeKey, key, data, true);

if (hasTicker) {
if (blockData.getSfId().equalsIgnoreCase("CARGO_MANAGER")) {
if ("CARGO_MANAGER".equalsIgnoreCase(blockData.getSfId())) {
Slimefun.instance().getCargoTickerTask().enableTicker(target);
} else {
Slimefun.getTickerTask().enableTicker(target);
Expand Down Expand Up @@ -1280,7 +1280,7 @@ private void deleteChunkAndBlockDataDirectly(String cKey) {
private void clearBlockCacheAndTasks(SlimefunBlockData blockData) {
var l = blockData.getLocation();
if (blockData.isDataLoaded() && Slimefun.getRegistry().getTickerBlocks().contains(blockData.getSfId())) {
if (blockData.getSfId().equalsIgnoreCase("CARGO_MANAGER")) {
if ("CARGO_MANAGER".equalsIgnoreCase(blockData.getSfId())) {
Slimefun.instance().getCargoTickerTask().disableTicker(blockData.getLocation());
} else {
Slimefun.getTickerTask().disableTicker(blockData.getLocation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,31 @@ public static List<String> onTabComplete(List<String> args) {
}
case 2 -> {
String param = args.get(0);
if (param.equalsIgnoreCase("banitem")) {
if ("banitem".equalsIgnoreCase(param)) {
return createReturnList(getSlimefunItems(), args.get(1));
}
if (param.equalsIgnoreCase("unbanitem")) {
if ("unbanitem".equalsIgnoreCase(param)) {
Set<String> set = Slimefun.getRegistry().getDisabledSlimefunItemsToSet().stream()
.map(SlimefunItem::getItemNormalName)
.collect(Collectors.toSet());
return createReturnList(set, args.get(1));
}
if (param.equalsIgnoreCase("cleardata")) {
if ("cleardata".equalsIgnoreCase(param)) {
Set<String> set = Bukkit.getWorlds().stream().map(WorldInfo::getName).collect(Collectors.toSet());
set.add("*");
return createReturnList(set, args.get(1));
}
if (param.equalsIgnoreCase("calc")) {
if ("calc".equalsIgnoreCase(param)) {
return createReturnList(getSlimefunItems(), args.get(1));
}
return getPlayerList(args.get(1));
}
case 3 -> {
String param = args.get(0);
if (param.equalsIgnoreCase("give")) {
if ("give".equalsIgnoreCase(param)) {
return createReturnList(getSlimefunItems(), args.get(2));
}
if (param.equalsIgnoreCase("research")) {
if ("research".equalsIgnoreCase(param)) {
List<Research> researches = Slimefun.getRegistry().getResearches();
Set<String> suggestions = new HashSet<>();

Expand All @@ -62,17 +62,17 @@ public static List<String> onTabComplete(List<String> args) {

return createReturnList(suggestions, args.get(2));
}
if (param.equalsIgnoreCase("cleardata")) {
if ("cleardata".equalsIgnoreCase(param)) {
return createReturnList(Arrays.asList("block", "oil", "*"), args.get(2));
}

if (param.equalsIgnoreCase("calc")) {
if ("calc".equalsIgnoreCase(param)) {
return createReturnList(COUNT_LIST, args.get(2));
}
return Collections.emptyList();
}
case 4 -> {
if (args.get(0).equalsIgnoreCase("give")) {
if ("give".equalsIgnoreCase(args.get(0))) {
return createReturnList(COUNT_LIST, args.get(3));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void onExecute(CommandSender sender, String[] args) {
return;
}

if (key.equalsIgnoreCase("id")) {
if ("id".equalsIgnoreCase(key)) {
ChatUtils.sendMessage(player, "&c你不能修改方块的 ID!");
return;
}
Expand All @@ -87,7 +87,7 @@ public void onExecute(CommandSender sender, String[] args) {
.replace("%value%", value));
}
case "remove" -> {
if (key.equalsIgnoreCase("id")) {
if ("id".equalsIgnoreCase(key)) {
ChatUtils.sendMessage(player, "&c你不能修改方块的 ID!");
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void onExecute(CommandSender sender, String[] args) {
Slimefun.getLocalization().sendMessage(sender, "commands.cleardata.confirm", true);
return;
}
if (args.length < 3 || !args[3].equalsIgnoreCase("confirm")) {
if (args.length < 3 || !"confirm".equalsIgnoreCase(args[3])) {
Slimefun.getLocalization()
.sendMessage(
sender,
Expand All @@ -44,7 +44,7 @@ public void onExecute(CommandSender sender, String[] args) {
String block = Slimefun.getLocalization().getMessage("commands.cleardata.block");
String oil = Slimefun.getLocalization().getMessage("commands.cleardata.oil");
BlockDataController controller = Slimefun.getDatabaseManager().getBlockDataController();
if (args[1].equals("*")) {
if ("*".equals(args[1])) {
worlds.addAll(Bukkit.getWorlds());
} else {
World toAdd = Bukkit.getWorld(args[1]);
Expand All @@ -54,15 +54,15 @@ public void onExecute(CommandSender sender, String[] args) {
}
}

if (args[2].equals("*")) {
if ("*".equals(args[2])) {
clearTypes.addAll(ValidClearTypes);
} else if (ValidClearTypes.contains(args[2])) {
clearTypes.add(args[2]);
}

for (World world : worlds) {
for (String cleartype : clearTypes) {
if (cleartype.equals("block")) {
if ("block".equals(cleartype)) {
controller.removeAllDataInWorldAsync(
world,
() -> Slimefun.runSync(() -> Slimefun.getLocalization()
Expand All @@ -71,7 +71,7 @@ public void onExecute(CommandSender sender, String[] args) {
.replace("{1}", block))));
continue;
}
if (cleartype.equals("oil")) {
if ("oil".equals(cleartype)) {
GEOResource oilresource = null;
for (GEOResource resource :
Slimefun.getRegistry().getGEOResources().values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ public void onExecute(CommandSender sender, String[] args) {

// Getting the PlayerProfile async
PlayerProfile.get(p, profile -> {
if (args[2].equalsIgnoreCase("all")) {
if ("all".equalsIgnoreCase(args[2])) {
researchAll(sender, profile, p);
return;
}
if (args[2].equalsIgnoreCase("reset")) {
if ("reset".equalsIgnoreCase(args[2])) {
reset(profile, p);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public boolean hasPermission(Permissible p, SlimefunItem item) {
}

String permission = permissions.get(item.getId());
return permission == null || permission.equals("none") || p.hasPermission(permission);
return permission == null || "none".equals(permission) || p.hasPermission(permission);
}

/**
Expand All @@ -109,7 +109,7 @@ public boolean hasPermission(Permissible p, SlimefunItem item) {
public Optional<String> getPermission(SlimefunItem item) {
String permission = permissions.get(item.getId());

if (permission == null || permission.equals("none")) {
if (permission == null || "none".equals(permission)) {
return Optional.empty();
} else {
return Optional.of(permission);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ private void onPluginStart() {
config.getBoolean("networks.enable-visualizer"),
config.getBoolean("networks.delete-excess-items"));
// load language cache
LanguageService.get().load();
LanguageService.load();
// Registering all GEO Resources

logger.log(Level.INFO, "加载矿物资源...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected void updateBlockMenu(BlockMenu menu, Block b) {
SlimefunBlockData blockData = StorageCacheUtils.getBlock(b.getLocation());
String filterType = blockData.getData(FILTER_TYPE);

if (filterType == null || filterType.equals("whitelist")) {
if (filterType == null || "whitelist".equals(filterType)) {
menu.replaceExistingItem(15, new CustomItemStack(Material.WHITE_WOOL, "&7模式: &r白名单", "", "&e> 单击切换至黑名单"));
menu.addMenuClickHandler(15, (p, slot, item, action) -> {
StorageCacheUtils.setData(b.getLocation(), FILTER_TYPE, "blacklist");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public ItemUseHandler getItemHandler() {
if (!(fc instanceof TextComponent firstComponent)) return;

List<Component> list = firstComponent.children();
if (list.size() >= 2 && ((TextComponent) list.get(1)).content().equals("None")) {
if (list.size() >= 2 && "None".equals(((TextComponent) list.get(1)).content())) {
lore.set(0, new QsTextComponentImpl("主人: ").color(NamedTextColor.GRAY)
.append(new QsTextComponentImpl(p.getName()).color(NamedTextColor.GRAY)));
lore.set(1, new QsTextComponentImpl(p.getUniqueId().toString()).color(NamedTextColor.BLACK));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ private void breakBlocks(
*/
if (Bukkit.getPluginManager().isPluginEnabled("ExoticGarden")) {
blocksToDestroy.sort((block1, block2) -> Boolean.compare(
block2.getType().equals(Material.PLAYER_HEAD),
block1.getType().equals(Material.PLAYER_HEAD)));
block2.getType() == Material.PLAYER_HEAD,
block1.getType() == Material.PLAYER_HEAD));
}

if (!event.isCancelled()) {
Expand Down Expand Up @@ -174,7 +174,7 @@ private void breakBlock(BlockBreakEvent event, Player player, ItemStack item, Bl
* 若为叶子则尝试获取该处的 SlimefunItem,若能获取得到则此处应为异域花园植物,将叶子处直接设置为 AIR 并移除该处 Slimefun 方块数据。
*/
if (Bukkit.getPluginManager().isPluginEnabled("ExoticGarden")
&& block.getType().equals(Material.PLAYER_HEAD)) {
&& block.getType() == Material.PLAYER_HEAD) {
Location leavesLocation = blockLocation.clone();
leavesLocation.setY(leavesLocation.getY() - 1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AltarRecipe;
import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientAltar;
import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientPedestal;
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.AbstractMonsterSpawner;
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.RepairedSpawner;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.AncientAltarTask;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
Expand Down Expand Up @@ -119,7 +120,7 @@ private void usePedestal(Block pedestal, Player p) {
}

// getting the currently placed item
Optional<Item> stack = pedestalItem.getPlacedItem(pedestal);
Optional<Item> stack = AncientPedestal.getPlacedItem(pedestal);

if (stack.isEmpty()) {
// Check if the Item in hand is valid
Expand Down Expand Up @@ -149,7 +150,7 @@ private void usePedestal(Block pedestal, Player p) {
* no stack space left else add remaining items from the returned map value
*/
Map<Integer, ItemStack> remainingItemMap =
p.getInventory().addItem(pedestalItem.getOriginalItemStack(entity));
p.getInventory().addItem(AncientPedestal.getOriginalItemStack(entity));

for (ItemStack item : remainingItemMap.values()) {
p.getWorld().dropItem(pedestal.getLocation().add(0, 1, 0), item.clone());
Expand Down Expand Up @@ -204,9 +205,9 @@ private void startRitual(Player p, Block b, List<Block> pedestals, ItemStack cat
List<ItemStack> input = new ArrayList<>();

for (Block pedestal : pedestals) {
Optional<Item> stack = pedestalItem.getPlacedItem(pedestal);
Optional<Item> stack = AncientPedestal.getPlacedItem(pedestal);

stack.ifPresent(item -> input.add(pedestalItem.getOriginalItemStack(item)));
stack.ifPresent(item -> input.add(AncientPedestal.getOriginalItemStack(item)));
}

Optional<ItemStack> result = getRecipeOutput(catalyst, input);
Expand Down Expand Up @@ -315,7 +316,7 @@ public Optional<ItemStack> getRecipeOutput(ItemStack catalyst, List<ItemStack> i

RepairedSpawner spawner = (RepairedSpawner) SlimefunItems.REPAIRED_SPAWNER.getItem();
return Optional.of(
spawner.getItemForEntityType(spawner.getEntityType(wrapper).orElse(EntityType.PIG)));
spawner.getItemForEntityType(AbstractMonsterSpawner.getEntityType(wrapper).orElse(EntityType.PIG)));
}

return checkRecipe(wrapper, items);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler;
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler;
import io.github.thebusybiscuit.slimefun4.core.handlers.ToolUseHandler;
import io.github.thebusybiscuit.slimefun4.core.services.BlockDataService;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedEnchantment;
import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag;
Expand Down Expand Up @@ -135,7 +136,7 @@ public void onBlockPlace(BlockPlaceEvent e) {
if (placeEvent.isCancelled()) {
e.setCancelled(true);
} else {
if (Slimefun.getBlockDataService().isTileEntity(block.getType())) {
if (BlockDataService.isTileEntity(block.getType())) {
Slimefun.getBlockDataService().setBlockData(block, sfItem.getId());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private void onFallDamage(EntityDamageEvent e) {

if (boots instanceof StomperBoots stomperBoots) {
e.setCancelled(true);
stomperBoots.stomp(e);
StomperBoots.stomp(e);
} else if (boots instanceof LongFallBoots longFallBoots) {
e.setCancelled(true);
longFallBoots.getSoundEffect().playAt(p.getLocation(), SoundCategory.PLAYERS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ private static void loadSmelteryRecipes() {

for (SlimefunItem item : Slimefun.getRegistry().getEnabledSlimefunItems()) {
if (item instanceof AContainer machine) {
if (machine.getMachineIdentifier().equals("ELECTRIC_SMELTERY")) {
if ("ELECTRIC_SMELTERY".equals(machine.getMachineIdentifier())) {
List<MachineRecipe> recipes = machine.getMachineRecipes();
recipes.sort(Comparator.comparingInt(recipe -> recipe == null ? 0 : -recipe.getInput().length));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static void setCharge(ItemMeta meta, float charge, float capacity) {
for (int i = 0; i < lore.size(); i++) {
Component line = lore.get(i);
if (line instanceof TextComponent c) {
if (c.content().equals("\u21E8")) {
if ("\u21E8".equals(c.content())) {
List<Component> children = c.children();
if (children.size() < 2) {
continue;
Expand All @@ -73,7 +73,7 @@ public static void setCharge(ItemMeta meta, float charge, float capacity) {
}

TextComponent fc = (TextComponent) children.get(0);
if (fc.content().equals("\u21E8 ")) {
if ("\u21E8 ".equals(fc.content())) {
TextComponent tc = (TextComponent) children.get(2);
String content = tc.content();
if (REGEX_NEW.matcher(content).matches()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,9 @@ private static boolean equalsItemMeta(ItemMeta itemMeta, ItemMeta sfitemMeta, bo
//noinspection ConstantValue
return potionMeta.getBasePotionType() != null
&& sfPotionMeta.getBasePotionType() != null
&& potionMeta.getBasePotionType().equals(sfPotionMeta.getBasePotionType());
&& potionMeta.getBasePotionType() == sfPotionMeta.getBasePotionType();
} else if (SlimefunExtended.getMinecraftVersion().isAtLeast(1, 20, 2)) {
return potionMeta.getBasePotionType().equals(sfPotionMeta.getBasePotionType());
return potionMeta.getBasePotionType() == sfPotionMeta.getBasePotionType();
} else {
//noinspection deprecation
return potionMeta.getBasePotionData().equals(sfPotionMeta.getBasePotionData());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/qscbm/slimefun4/helper/ItemHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static String getItemName(ItemStack stack) {
}

String type = wrapper.getType().name().toLowerCase(Locale.ROOT);
if (type.contains("potion") || type.equals("tipped_arrow")) {
if (type.contains("potion") || "tipped_arrow".equals(type)) {
//noinspection deprecation
String potion = ((PotionMeta) (meta == null ? stack.getItemMeta() : meta))
.getBasePotionData().getType().toString().toLowerCase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public static void onAsyncTabCompleteEvent(AsyncTabCompleteEvent e) {
String commandLabel = buffer.substring(0, firstPlace).toLowerCase();
String[] parts = commandLabel.split(":");
if (parts.length > 1) {
if (!parts[0].equals("slimefun")) {
if (!"slimefun".equals(parts[0])) {
return;
}
commandLabel = parts[1];
}
if (!SlimefunCommand.COMMAND_ALIASES.contains(commandLabel) && !commandLabel.equals("slimefun")) {
if (!SlimefunCommand.COMMAND_ALIASES.contains(commandLabel) && !"slimefun".equals(commandLabel)) {
return;
}
List<String> args = new QuotedStringTokenizer(buffer.substring(firstPlace + 1)).tokenize(false);
Expand Down
Loading

0 comments on commit c7ac804

Please sign in to comment.