Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ziqian zhang
Grasscutter
Commits
dc26f9e2
Commit
dc26f9e2
authored
Apr 28, 2022
by
KingRainbow44
Browse files
Add plugin data folders
parent
91a2a55e
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/plugin/Plugin.java
View file @
dc26f9e2
...
@@ -4,6 +4,7 @@ import emu.grasscutter.Grasscutter;
...
@@ -4,6 +4,7 @@ import emu.grasscutter.Grasscutter;
import
emu.grasscutter.plugin.api.ServerHook
;
import
emu.grasscutter.plugin.api.ServerHook
;
import
emu.grasscutter.server.game.GameServer
;
import
emu.grasscutter.server.game.GameServer
;
import
java.io.File
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.net.URLClassLoader
;
import
java.net.URLClassLoader
;
...
@@ -15,6 +16,7 @@ public abstract class Plugin {
...
@@ -15,6 +16,7 @@ public abstract class Plugin {
private
PluginIdentifier
identifier
;
private
PluginIdentifier
identifier
;
private
URLClassLoader
classLoader
;
private
URLClassLoader
classLoader
;
private
File
dataFolder
;
/**
/**
* This method is reflected into.
* This method is reflected into.
...
@@ -23,11 +25,19 @@ public abstract class Plugin {
...
@@ -23,11 +25,19 @@ public abstract class Plugin {
* @param identifier The plugin's identifier.
* @param identifier The plugin's identifier.
*/
*/
private
void
initializePlugin
(
PluginIdentifier
identifier
,
URLClassLoader
classLoader
)
{
private
void
initializePlugin
(
PluginIdentifier
identifier
,
URLClassLoader
classLoader
)
{
if
(
this
.
identifier
==
null
)
if
(
this
.
identifier
!=
null
)
{
this
.
identifier
=
identifier
;
Grasscutter
.
getLogger
().
warn
(
this
.
identifier
.
name
+
" had a reinitialization attempt."
);
if
(
this
.
classLoader
==
null
)
return
;
this
.
classLoader
=
classLoader
;
}
else
Grasscutter
.
getLogger
().
warn
(
this
.
identifier
.
name
+
" had a reinitialization attempt."
);
this
.
identifier
=
identifier
;
this
.
classLoader
=
classLoader
;
this
.
dataFolder
=
new
File
(
Grasscutter
.
getConfig
().
PLUGINS_FOLDER
,
identifier
.
name
);
if
(!
this
.
dataFolder
.
exists
()
&&
!
this
.
dataFolder
.
mkdirs
())
{
Grasscutter
.
getLogger
().
warn
(
"Failed to create plugin data folder for "
+
this
.
identifier
.
name
);
return
;
}
}
}
/**
/**
...
@@ -76,6 +86,14 @@ public abstract class Plugin {
...
@@ -76,6 +86,14 @@ public abstract class Plugin {
return
this
.
classLoader
.
getResourceAsStream
(
resourceName
);
return
this
.
classLoader
.
getResourceAsStream
(
resourceName
);
}
}
/**
* Returns a directory where plugins can store data files.
* @return A directory on the file system.
*/
public
final
File
getDataFolder
()
{
return
this
.
dataFolder
;
}
/**
/**
* Returns the server hook.
* Returns the server hook.
* @return A server hook singleton.
* @return A server hook singleton.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment