Skip to content

Commit

Permalink
chore: 优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
mcchampions committed Nov 29, 2024
1 parent 0294ff5 commit 331e99f
Show file tree
Hide file tree
Showing 143 changed files with 336 additions and 322 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void onPlayerBreak(
});
}

private ItemStack getCountItem() {
private static ItemStack getCountItem() {
ItemStack countItem = new ItemStack(Material.CLOCK);
ItemMeta im = countItem.getItemMeta();
im.setDisplayName(ChatColor.BLUE + "合成表的原料数量");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
public class PlayerChatListener implements Listener {
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onChat(AsyncPlayerChatEvent e) {
public static void onChat(AsyncPlayerChatEvent e) {
Slimefun.getChatCatcher().pollCatcher(e.getPlayer().getUniqueId()).ifPresent(h -> {
e.setCancelled(true);
Slimefun.runSync(() -> h.accept(e.getMessage()));
});
}

@EventHandler(priority = EventPriority.MONITOR)
public void onLeave(PlayerQuitEvent e) {
public static void onLeave(PlayerQuitEvent e) {
Slimefun.getChatCatcher().pollCatcher(e.getPlayer().getUniqueId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ public synchronized void destroy() {
checkDestroy();

destroyed = true;
freeConn.forEach(this::tryClose);
usingConn.forEach(this::tryClose);
freeConn.forEach(ConnectionPool::tryClose);
usingConn.forEach(ConnectionPool::tryClose);
}

private boolean testConn(Connection conn) {
private static boolean testConn(Connection conn) {
try (var stmt = conn.createStatement()) {
stmt.execute("/* ping */ SHOW DATABASES");
return true;
Expand All @@ -88,7 +88,7 @@ private void checkDestroy() {
}
}

private void tryClose(Connection conn) {
private static void tryClose(Connection conn) {
try {
conn.close();
} catch (SQLException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.xzavier0722.mc.plugin.slimefun4.storage.util.DataUtils;

import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;

import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Level;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class ChunkListener implements Listener {
@EventHandler
public void onChunkLoad(ChunkLoadEvent e) {
public static void onChunkLoad(ChunkLoadEvent e) {
Slimefun.getDatabaseManager().getBlockDataController().loadChunk(e.getChunk(), e.isNewChunk());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class WorldListener implements Listener {
@EventHandler
public void onChunkLoad(WorldLoadEvent e) {
public static void onChunkLoad(WorldLoadEvent e) {
Slimefun.getDatabaseManager().getBlockDataController().loadWorld(e.getWorld());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.github.thebusybiscuit.slimefun4.api.events.GEOResourceGenerationEvent;
import io.github.thebusybiscuit.slimefun4.core.services.localization.Language;
import io.github.thebusybiscuit.slimefun4.core.services.localization.SlimefunLocalization;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.items.geo.GEOMiner;
import io.github.thebusybiscuit.slimefun4.implementation.items.geo.GEOScanner;
Expand Down Expand Up @@ -55,7 +56,7 @@ public interface GEOResource extends Keyed {
*
* @return The name of this Resource
*/

String getName();

/**
Expand All @@ -64,7 +65,7 @@ public interface GEOResource extends Keyed {
*
* @return The {@link ItemStack} version of this Resource.
*/

ItemStack getItem();

/**
Expand All @@ -90,9 +91,9 @@ default void register() {
* The {@link Player} to localize the name for.
* @return The localized name for this {@link GEOResource}
*/

default String getName(Player p) {
String name = Slimefun.getLocalization()
String name = SlimefunLocalization
.getResourceString(p, "resources." + getKey().getNamespace() + "." + getKey().getKey());
return name == null ? getName() : name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.github.bakedlibs.dough.config.Config;
import io.github.bakedlibs.dough.items.CustomItemStack;
import io.github.thebusybiscuit.slimefun4.api.events.GEOResourceGenerationEvent;
import io.github.thebusybiscuit.slimefun4.core.services.localization.SlimefunLocalization;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.items.geo.GEOMiner;
import io.github.thebusybiscuit.slimefun4.implementation.items.geo.GEOScanner;
Expand Down Expand Up @@ -87,7 +88,7 @@ void register(GEOResource resource) {
*
* @return An {@link OptionalInt}, either empty or containing the amount of the given {@link GEOResource}
*/
public OptionalInt getSupplies(GEOResource resource, World world, int x, int z) {
public static OptionalInt getSupplies(GEOResource resource, World world, int x, int z) {
String key = resource.getKey().toString().replace(':', '-');
var chunkData = Slimefun.getDatabaseManager().getBlockDataController().getChunkData(world.getChunkAt(x, z));
if (chunkData == null) {
Expand All @@ -102,7 +103,7 @@ public OptionalInt getSupplies(GEOResource resource, World world, int x, int z)
}
}

public void getSuppliesAsync(GEOResource resource, Chunk chunk, IAsyncReadCallback<Integer> callback) {
public static void getSuppliesAsync(GEOResource resource, Chunk chunk, IAsyncReadCallback<Integer> callback) {
Slimefun.getDatabaseManager().getBlockDataController().getChunkDataAsync(chunk, new IAsyncReadCallback<>() {
@Override
public boolean runOnMainThread() {
Expand Down Expand Up @@ -140,7 +141,7 @@ public void onResultNotFound() {
* @param value
* The new supply value
*/
public void setSupplies(GEOResource resource, World world, int x, int z, int value) {
public static void setSupplies(GEOResource resource, World world, int x, int z, int value) {
String key = resource.getKey().toString().replace(':', '-');
Slimefun.getDatabaseManager()
.getBlockDataController()
Expand Down Expand Up @@ -170,7 +171,7 @@ public void onResult(SlimefunChunkData result) {
*
* @return The new supply value
*/
private int generate(GEOResource resource, World world, int x, int y, int z) {
private static int generate(GEOResource resource, World world, int x, int y, int z) {
// Get the corresponding Block (and Biome)
Block block = world.getBlockAt(x << 4, y, z << 4);
Biome biome = block.getBiome();
Expand Down Expand Up @@ -224,7 +225,7 @@ public void scan(Player p, Block block, int page) {
int x = block.getX() >> 4;
int z = block.getZ() >> 4;

String title = "§4" + Slimefun.getLocalization().getResourceString(p, "tooltips.results");
String title = "§4" + SlimefunLocalization.getResourceString(p, "tooltips.results");
ChestMenu menu = new ChestMenu(title);

for (int slot : backgroundSlots) {
Expand All @@ -235,12 +236,12 @@ public void scan(Player p, Block block, int page) {
4,
new CustomItemStack(
HeadTexture.MINECRAFT_CHUNK.getAsItemStack(),
ChatColor.YELLOW + Slimefun.getLocalization().getResourceString(p, "tooltips.chunk"),
ChatColor.YELLOW + SlimefunLocalization.getResourceString(p, "tooltips.chunk"),
"",
"§8\u21E8 §7"
+ Slimefun.getLocalization().getResourceString(p, "tooltips.world")
+ ": "
+ block.getWorld().getName(),
+ SlimefunLocalization.getResourceString(p, "tooltips.world")
+ ": "
+ block.getWorld().getName(),
"§8\u21E8 §7X: " + x + " Z: " + z),
ChestMenuUtils.getEmptyClickHandler());
List<GEOResource> resources =
Expand All @@ -262,7 +263,7 @@ public void scan(Player p, Block block, int page) {
for (int i = page * 28; i < resources.size() && i < (page + 1) * 28; i++) {
GEOResource resource = resources.get(i);
int supplies = supplyMap.get(resource);
String suffix = Slimefun.getLocalization()
String suffix = SlimefunLocalization
.getResourceString(p, ChatUtils.checkPlurality("tooltips.unit", supplies));

ItemStack item = new CustomItemStack(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public void openTransmitterControlPanel(Player p) {
*
* @return An icon for this waypoint
*/
public ItemStack getIcon(String name, Environment environment) {
public static ItemStack getIcon(String name, Environment environment) {
if (name.startsWith("player:death ")) {
return HeadTexture.DEATHPOINT.getAsItemStack();
} else if (environment == Environment.NETHER) {
Expand All @@ -240,7 +240,7 @@ public ItemStack getIcon(String name, Environment environment) {
}
}

private String getStatusText(Player player, int complexity) {
private static String getStatusText(Player player, int complexity) {
if (complexity > 0) {
return "§2§l" + Slimefun.getLocalization().getMessage(player, "gps.status-online");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.github.bakedlibs.dough.common.ChatColors;
import io.github.bakedlibs.dough.items.CustomItemStack;
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
import io.github.thebusybiscuit.slimefun4.core.services.localization.SlimefunLocalization;
import io.github.thebusybiscuit.slimefun4.core.services.sounds.SoundEffect;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.items.teleporter.Teleporter;
Expand Down Expand Up @@ -97,10 +98,10 @@ public void openTeleporterGUI(Player p, UUID ownerUUID, Block b, int complexity)

String[] lore = {
"",
"§8\u21E8 &7"
+ Slimefun.getLocalization().getResourceString(p, "tooltips.world")
+ ": &f"
+ l.getWorld().getName(),
"§8\u21E8 &7"
+ SlimefunLocalization.getResourceString(p, "tooltips.world")
+ ": &f"
+ l.getWorld().getName(),
"§8\u21E8 &7X: &f" + l.getX(),
"§8\u21E8 &7Y: &f" + l.getY(),
"§8\u21E8 &7Z: &f" + l.getZ(),
Expand Down Expand Up @@ -161,7 +162,7 @@ public void teleport(UUID uuid, int complexity, Location source, Location destin
*
* @return The amount of time the teleportation will take
*/
public int getTeleportationTime(int complexity, Location source, Location destination) {
public static int getTeleportationTime(int complexity, Location source, Location destination) {
if (complexity < 100) {
return 100;
}
Expand All @@ -173,7 +174,7 @@ public int getTeleportationTime(int complexity, Location source, Location destin
return Math.max(1, unsafeTime);
}

private int distanceSquared(Location source, Location destination) {
private static int distanceSquared(Location source, Location destination) {
if (source.getWorld().getUID().equals(destination.getWorld().getUID())) {
int distance = (int) source.distanceSquared(destination);
return Math.min(distance, 100_000_000);
Expand All @@ -182,7 +183,7 @@ private int distanceSquared(Location source, Location destination) {
}
}

private boolean isValid(@Nullable Player p, Location source) {
private static boolean isValid(@Nullable Player p, Location source) {
return p != null
&& p.isValid()
&& p.getWorld().getUID().equals(source.getWorld().getUID())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import io.github.thebusybiscuit.slimefun4.api.events.WaypointCreateEvent;
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.items.teleporter.Teleporter;
import java.util.Objects;
import java.util.UUID;
Expand Down Expand Up @@ -127,7 +126,7 @@ public boolean isDeathpoint() {
*/

public ItemStack getIcon() {
return Slimefun.getGPSNetwork().getIcon(name, location.getWorld().getEnvironment());
return GPSNetwork.getIcon(name, location.getWorld().getEnvironment());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.github.thebusybiscuit.slimefun4.api.items.groups.LockedItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.groups.SeasonalItemGroup;
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide;
import io.github.thebusybiscuit.slimefun4.core.services.localization.SlimefunLocalization;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedItemFlag;
import java.util.ArrayList;
Expand Down Expand Up @@ -149,7 +150,7 @@ public void setTier(int tier) {
/**
* This refreshes the {@link ItemGroup} order.
*/
private void sortCategoriesByTier() {
private static void sortCategoriesByTier() {
List<ItemGroup> categories = Slimefun.getRegistry().getAllItemGroups();
categories.sort(Comparator.comparingInt(ItemGroup::getTier));
}
Expand Down Expand Up @@ -207,7 +208,7 @@ public void remove(SlimefunItem item) {
*/
public ItemStack getItem(Player p) {
return new CustomItemStack(item, meta -> {
String name = Slimefun.getLocalization().getItemGroupName(p, key);
String name = SlimefunLocalization.getItemGroupName(p, key);

if (name == null) {
name = item.getItemMeta().getDisplayName();
Expand Down Expand Up @@ -246,7 +247,7 @@ public String getUnlocalizedName() {
* @return The localized name of this {@link ItemGroup}
*/
public String getDisplayName(Player p) {
String localized = Slimefun.getLocalization().getItemGroupName(p, key);
String localized = SlimefunLocalization.getItemGroupName(p, key);

if (localized != null) {
return localized;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ public SlimefunItem(ItemGroup itemGroup, SlimefunItemStack item, RecipeType reci
* @param recipe An Array representing the recipe of this {@link SlimefunItem}
* @param recipeOutput The result of crafting this item
*/
@SuppressWarnings("DynamicRegexReplaceableByCompiledPattern")
public SlimefunItem(
ItemGroup itemGroup,
SlimefunItemStack item,
Expand All @@ -196,6 +197,7 @@ protected SlimefunItem(ItemGroup itemGroup, ItemStack item, String id, RecipeTyp
this.id = id;
this.recipeType = recipeType;
this.recipe = recipe;
//noinspection DynamicRegexReplaceableByCompiledPattern
normalItemName = TextUtils.toPlainText(itemStackTemplate.getItemMeta().getDisplayName()).replaceAll(" ", "_");
}

Expand Down Expand Up @@ -520,7 +522,7 @@ private void loadItemHandlers() {
*
* @return Whether the original {@link SlimefunItemStack} is immutable.
*/
protected boolean isItemStackImmutable() {
protected static boolean isItemStackImmutable() {
return true;
}

Expand All @@ -529,7 +531,7 @@ protected boolean isItemStackImmutable() {
*
* @param addon The {@link SlimefunAddon} trying to register this {@link SlimefunItem}
*/
private void checkDependencies(SlimefunAddon addon) {
private static void checkDependencies(SlimefunAddon addon) {
if (!addon.hasDependency("Slimefun")) {
throw new MissingDependencyException(addon, "Slimefun");
}
Expand Down Expand Up @@ -894,7 +896,7 @@ public void error(String message, Throwable throwable) {
*
* @param player The {@link Player} to inform.
*/
public void sendDeprecationWarning(Player player) {
public static void sendDeprecationWarning(Player player) {
Slimefun.getLocalization().sendMessage(player, "messages.deprecated-item");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public void setBackpackCount(int count) {
Slimefun.getDatabaseManager().getProfileDataController().saveProfileBackpackCount(this);
}

private int countNonEmptyResearches(Collection<Research> researches) {
private static int countNonEmptyResearches(Collection<Research> researches) {
int count = 0;
for (Research research : researches) {
if (research.hasEnabledItems()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlockMachine;
import io.github.thebusybiscuit.slimefun4.core.services.localization.SlimefunLocalization;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AltarRecipe;
Expand Down Expand Up @@ -228,7 +229,7 @@ public void unregister(ItemStack[] recipe, ItemStack result) {
}

public ItemStack getItem(Player p) {
return Slimefun.getLocalization().getRecipeTypeItem(p, this);
return SlimefunLocalization.getRecipeTypeItem(p, this);
}

public SlimefunItem getMachine() {
Expand Down
Loading

0 comments on commit 331e99f

Please sign in to comment.