Run IntelliJ IDEA code formatter

This commit is contained in:
KingRainbow44
2023-03-31 17:19:26 -04:00
parent 5bf5fb07a2
commit 15e2f3ca34
917 changed files with 30030 additions and 22446 deletions

View File

@@ -4,7 +4,6 @@ import emu.grasscutter.Grasscutter;
import emu.grasscutter.plugin.api.ServerHook;
import emu.grasscutter.server.game.GameServer;
import emu.grasscutter.utils.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -25,8 +24,9 @@ public abstract class Plugin {
/**
* This method is reflected into.
*
* <p>
* Set plugin variables.
*
* @param identifier The plugin's identifier.
*/
private void initializePlugin(PluginIdentifier identifier, URLClassLoader classLoader) {
@@ -42,12 +42,12 @@ public abstract class Plugin {
if (!this.dataFolder.exists() && !this.dataFolder.mkdirs()) {
Grasscutter.getLogger().warn("Failed to create plugin data folder for " + this.identifier.name);
return;
}
}
/**
* The plugin's identifier instance.
*
* @return An instance of {@link PluginIdentifier}.
*/
public final PluginIdentifier getIdentifier() {
@@ -77,6 +77,7 @@ public abstract class Plugin {
/**
* Returns the server that initialized the plugin.
*
* @return A server instance.
*/
public final GameServer getServer() {
@@ -85,6 +86,7 @@ public abstract class Plugin {
/**
* Returns an input stream for a resource in the JAR file.
*
* @param resourceName The name of the resource.
* @return An input stream.
*/
@@ -94,6 +96,7 @@ public abstract class Plugin {
/**
* Returns a directory where plugins can store data files.
*
* @return A directory on the file system.
*/
public final File getDataFolder() {
@@ -102,6 +105,7 @@ public abstract class Plugin {
/**
* Returns the server hook.
*
* @return A server hook singleton.
*/
public final ServerHook getHandle() {
@@ -110,6 +114,7 @@ public abstract class Plugin {
/**
* Returns the plugin's logger.
*
* @return A SLF4J logger.
*/
public final Logger getLogger() {
@@ -117,9 +122,14 @@ public abstract class Plugin {
}
/* Called when the plugin is first loaded. */
public void onLoad() { }
public void onLoad() {
}
/* Called after (most of) the server enables. */
public void onEnable() { }
public void onEnable() {
}
/* Called before the server disables. */
public void onDisable() { }
public void onDisable() {
}
}

View File

@@ -11,6 +11,7 @@ public final class PluginConfig {
/**
* Attempts to validate this config instance.
*
* @return True if the config is valid, false otherwise.
*/
@SuppressWarnings("BooleanMethodIsAlwaysInverted")

View File

@@ -4,10 +4,10 @@ package emu.grasscutter.plugin;
public final class PluginIdentifier {
public final String name, description, version;
public final String[] authors;
public PluginIdentifier(
String name, String description, String version,
String[] authors
String name, String description, String version,
String[] authors
) {
this.name = name;
this.description = description;
@@ -19,11 +19,11 @@ public final class PluginIdentifier {
* Converts a {@link PluginConfig} into a {@link PluginIdentifier}.
*/
public static PluginIdentifier fromPluginConfig(PluginConfig config) {
if(!config.validate())
if (!config.validate())
throw new IllegalArgumentException("A valid plugin config is required to convert into a plugin identifier.");
return new PluginIdentifier(
config.name, config.description, config.version,
config.authors
config.name, config.description, config.version,
config.authors
);
}
}

View File

@@ -1,21 +1,28 @@
package emu.grasscutter.plugin;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.server.event.*;
import emu.grasscutter.server.event.Event;
import emu.grasscutter.server.event.EventHandler;
import emu.grasscutter.server.event.HandlerPriority;
import emu.grasscutter.utils.FileUtils;
import emu.grasscutter.utils.JsonUtils;
import lombok.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import javax.annotation.Nullable;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.*;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import static emu.grasscutter.utils.Language.translate;
import java.io.*;
import java.lang.reflect.Method;
import java.net.*;
import java.util.*;
import java.util.jar.*;
/**
* Manages the server's plugins and the event system.
*/
@@ -29,15 +36,6 @@ public final class PluginManager {
this.loadPlugins(); // Load all plugins from the plugins directory.
}
/* Data about an unloaded plugin. */
@AllArgsConstructor @Getter
static class PluginData {
private Plugin plugin;
private PluginIdentifier identifier;
private URLClassLoader classLoader;
private String[] dependencies;
}
/**
* Loads plugins from the config-specified directory.
*/
@@ -130,7 +128,8 @@ public final class PluginManager {
}
// Load plugins with dependencies.
int depth = 0; final int maxDepth = 30;
int depth = 0;
final int maxDepth = 30;
while (!dependencies.isEmpty()) {
// Check if the depth is too high.
if (depth >= maxDepth) {
@@ -154,7 +153,8 @@ public final class PluginManager {
// Load the plugin.
this.loadPlugin(pluginData.getPlugin(), pluginData.getIdentifier(), pluginData.getClassLoader());
} catch (Exception exception) {
Grasscutter.getLogger().error(translate("plugin.failed_to_load"), exception); depth++;
Grasscutter.getLogger().error(translate("plugin.failed_to_load"), exception);
depth++;
}
}
}
@@ -218,7 +218,7 @@ public final class PluginManager {
/**
* Registers a plugin's event listener.
*
* @param plugin The plugin registering the listener.
* @param plugin The plugin registering the listener.
* @param listener The event listener.
*/
public void registerListener(Plugin plugin, EventHandler<? extends Event> listener) {
@@ -306,4 +306,14 @@ public final class PluginManager {
(event.isCanceled() && handler.ignoresCanceled())
) handler.getCallback().consume((T) event);
}
/* Data about an unloaded plugin. */
@AllArgsConstructor
@Getter
static class PluginData {
private Plugin plugin;
private PluginIdentifier identifier;
private URLClassLoader classLoader;
private String[] dependencies;
}
}

View File

@@ -20,6 +20,7 @@ public final class PlayerHook {
/**
* Hooks into the player.
*
* @param player The player to hook into.
*/
public PlayerHook(Player player) {
@@ -36,6 +37,7 @@ public final class PlayerHook {
/**
* Sends a player to another scene.
*
* @param sceneId The scene to send the player to.
*/
public void changeScenes(int sceneId) {
@@ -44,6 +46,7 @@ public final class PlayerHook {
/**
* Broadcasts an avatar property notify to all world players.
*
* @param property The property that was updated.
*/
public void updateFightProperty(FightProperty property) {
@@ -52,6 +55,7 @@ public final class PlayerHook {
/**
* Broadcasts the packet sent to all world players.
*
* @param packet The packet to send.
*/
public void broadcastPacketToWorld(BasePacket packet) {
@@ -60,6 +64,7 @@ public final class PlayerHook {
/**
* Set the currently equipped avatar's health.
*
* @param health The health to set the avatar to.
*/
public void setHealth(float health) {
@@ -69,6 +74,7 @@ public final class PlayerHook {
/**
* Revives the specified avatar.
*
* @param avatar The avatar to revive.
*/
public void reviveAvatar(Avatar avatar) {
@@ -78,18 +84,20 @@ public final class PlayerHook {
/**
* Teleports a player to a position.
* This will **not** transfer the player to another scene.
*
* @param position The position to teleport the player to.
*/
public void teleport(Position position) {
this.player.getPosition().set(position);
this.player.sendPacket(new PacketPlayerEnterSceneNotify(this.player,
EnterType.ENTER_TYPE_JUMP, EnterReason.TransPoint,
this.player.getSceneId(), position
EnterType.ENTER_TYPE_JUMP, EnterReason.TransPoint,
this.player.getSceneId(), position
));
}
/**
* Gets the currently selected avatar's max health.
*
* @return The max health as a float.
*/
public float getMaxHealth() {
@@ -98,6 +106,7 @@ public final class PlayerHook {
/**
* Gets the currently selected avatar in entity form.
*
* @return The avatar as an {@link EntityAvatar}.
*/
public EntityAvatar getCurrentAvatarEntity() {
@@ -106,6 +115,7 @@ public final class PlayerHook {
/**
* Gets the currently selected avatar.
*
* @return The avatar as an {@link Avatar}.
*/
public Avatar getCurrentAvatar() {

View File

@@ -23,16 +23,9 @@ public final class ServerHook {
private final GameServer gameServer;
private final HttpServer httpServer;
/**
* Gets the server hook instance.
* @return A {@link ServerHook} singleton.
*/
public static ServerHook getInstance() {
return instance;
}
/**
* Hooks into a server.
*
* @param gameServer The game server to hook into.
* @param httpServer The HTTP server to hook into.
*/
@@ -43,6 +36,15 @@ public final class ServerHook {
instance = this;
}
/**
* Gets the server hook instance.
*
* @return A {@link ServerHook} singleton.
*/
public static ServerHook getInstance() {
return instance;
}
/**
* @return The game server.
*/
@@ -59,6 +61,7 @@ public final class ServerHook {
/**
* Gets all online players.
*
* @return Players connected to the server.
*/
@Deprecated(forRemoval = true)
@@ -68,6 +71,7 @@ public final class ServerHook {
/**
* Gets all online players.
*
* @return Players connected to the server.
*/
public Stream<Player> getOnlinePlayersStream() {
@@ -76,6 +80,7 @@ public final class ServerHook {
/**
* Registers a command to the {@link emu.grasscutter.command.CommandMap}.
*
* @param handler The command handler.
*/
public void registerCommand(CommandHandler handler) {
@@ -88,6 +93,7 @@ public final class ServerHook {
/**
* Adds a router using an instance of a class.
*
* @param router A router instance.
*/
public void addRouter(Router router) {
@@ -96,6 +102,7 @@ public final class ServerHook {
/**
* Adds a router using a class.
*
* @param router The class of the router.
*/
public void addRouter(Class<? extends Router> router) {
@@ -104,6 +111,7 @@ public final class ServerHook {
/**
* Sets the server's authentication system.
*
* @param authSystem An instance of the authentication system.
*/
public void setAuthSystem(AuthenticationSystem authSystem) {
@@ -112,6 +120,7 @@ public final class ServerHook {
/**
* Sets the server's permission handler.
*
* @param permHandler An instance of the permission handler.
*/
public void setPermissionHandler(PermissionHandler permHandler) {