geforkt von Mirrors/Paper
Implemented ebeans
By: Dinnerbone <dinnerbone@dinnerbone.com>
Dieser Commit ist enthalten in:
Ursprung
41bcf14b27
Commit
0373e53844
@ -34,5 +34,10 @@
|
|||||||
<artifactId>json-simple</artifactId>
|
<artifactId>json-simple</artifactId>
|
||||||
<version>1.1</version>
|
<version>1.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.avaje</groupId>
|
||||||
|
<artifactId>ebean</artifactId>
|
||||||
|
<version>2.7.3</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@ -31,7 +31,7 @@ public final class Bukkit {
|
|||||||
*/
|
*/
|
||||||
public static void setServer(Server server) {
|
public static void setServer(Server server) {
|
||||||
if (Bukkit.server != null) {
|
if (Bukkit.server != null) {
|
||||||
throw new UnsupportedOperationException("Cannot redelcare singleton Server");
|
throw new UnsupportedOperationException("Cannot redefine singleton Server");
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.server = server;
|
Bukkit.server = server;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
package org.bukkit;
|
package org.bukkit;
|
||||||
|
|
||||||
|
import com.avaje.ebean.config.ServerConfig;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@ -186,4 +187,11 @@ public interface Server {
|
|||||||
* @throws CommandException Thrown when the executor for the given command fails with an unhandled exception
|
* @throws CommandException Thrown when the executor for the given command fails with an unhandled exception
|
||||||
*/
|
*/
|
||||||
public boolean dispatchCommand(CommandSender sender, String commandLine);
|
public boolean dispatchCommand(CommandSender sender, String commandLine);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Populates a given {@link ServerConfig} with values attributes to this server
|
||||||
|
*
|
||||||
|
* @param config ServerConfig to populate
|
||||||
|
*/
|
||||||
|
public void configureDbConfig(ServerConfig config);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
package org.bukkit.plugin;
|
package org.bukkit.plugin;
|
||||||
|
|
||||||
|
import com.avaje.ebean.EbeanServer;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
@ -80,4 +81,11 @@ public interface Plugin extends CommandExecutor {
|
|||||||
* @param canNag is this plugin still naggable?
|
* @param canNag is this plugin still naggable?
|
||||||
*/
|
*/
|
||||||
public void setNaggable(boolean canNag);
|
public void setNaggable(boolean canNag);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the {@link EbeanServer} tied to this plugin
|
||||||
|
*
|
||||||
|
* @return Ebean server instance
|
||||||
|
*/
|
||||||
|
public EbeanServer getDatabase();
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ public final class PluginDescriptionFile {
|
|||||||
private String description = null;
|
private String description = null;
|
||||||
private ArrayList<String> authors = new ArrayList<String>();
|
private ArrayList<String> authors = new ArrayList<String>();
|
||||||
private String website = null;
|
private String website = null;
|
||||||
|
private boolean database = false;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public PluginDescriptionFile(final InputStream stream) throws InvalidDescriptionException {
|
public PluginDescriptionFile(final InputStream stream) throws InvalidDescriptionException {
|
||||||
@ -120,6 +121,14 @@ public final class PluginDescriptionFile {
|
|||||||
return website;
|
return website;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isDatabaseEnabled() {
|
||||||
|
return database;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDatabaseEnabled(boolean database) {
|
||||||
|
this.database = database;
|
||||||
|
}
|
||||||
|
|
||||||
private void loadMap(Map<String, Object> map) throws InvalidDescriptionException {
|
private void loadMap(Map<String, Object> map) throws InvalidDescriptionException {
|
||||||
try {
|
try {
|
||||||
name = map.get("name").toString();
|
name = map.get("name").toString();
|
||||||
@ -164,6 +173,14 @@ public final class PluginDescriptionFile {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (map.containsKey("database")) {
|
||||||
|
try {
|
||||||
|
database = (Boolean)map.get("database");
|
||||||
|
} catch (ClassCastException ex) {
|
||||||
|
throw new InvalidDescriptionException(ex, "database is of wrong type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (map.containsKey("website")) {
|
if (map.containsKey("website")) {
|
||||||
try {
|
try {
|
||||||
website = (String)map.get("website");
|
website = (String)map.get("website");
|
||||||
@ -204,6 +221,7 @@ public final class PluginDescriptionFile {
|
|||||||
map.put("name", name);
|
map.put("name", name);
|
||||||
map.put("main", main);
|
map.put("main", main);
|
||||||
map.put("version", version);
|
map.put("version", version);
|
||||||
|
map.put("database", database);
|
||||||
|
|
||||||
if (commands != null) map.put("command", commands);
|
if (commands != null) map.put("command", commands);
|
||||||
if (depend != null) map.put("depend", depend);
|
if (depend != null) map.put("depend", depend);
|
||||||
|
@ -1,7 +1,13 @@
|
|||||||
|
|
||||||
package org.bukkit.plugin.java;
|
package org.bukkit.plugin.java;
|
||||||
|
|
||||||
|
import com.avaje.ebean.EbeanServer;
|
||||||
|
import com.avaje.ebean.EbeanServerFactory;
|
||||||
|
import com.avaje.ebean.config.DataSourceConfig;
|
||||||
|
import com.avaje.ebean.config.ServerConfig;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -25,6 +31,7 @@ public abstract class JavaPlugin implements Plugin {
|
|||||||
private ClassLoader classLoader = null;
|
private ClassLoader classLoader = null;
|
||||||
private Configuration config = null;
|
private Configuration config = null;
|
||||||
private boolean naggable = true;
|
private boolean naggable = true;
|
||||||
|
private EbeanServer ebean = null;
|
||||||
|
|
||||||
public JavaPlugin() {
|
public JavaPlugin() {
|
||||||
}
|
}
|
||||||
@ -147,8 +154,40 @@ public abstract class JavaPlugin implements Plugin {
|
|||||||
this.classLoader = classLoader;
|
this.classLoader = classLoader;
|
||||||
this.config = new Configuration(new File(dataFolder, "config.yml"));
|
this.config = new Configuration(new File(dataFolder, "config.yml"));
|
||||||
this.config.load();
|
this.config.load();
|
||||||
|
|
||||||
|
if (description.isDatabaseEnabled()) {
|
||||||
|
ServerConfig db = new ServerConfig();
|
||||||
|
|
||||||
|
db.setDefaultServer(false);
|
||||||
|
db.setRegister(false);
|
||||||
|
db.setClasses(getDatabaseClasses());
|
||||||
|
db.setName(description.getName());
|
||||||
|
server.configureDbConfig(db);
|
||||||
|
|
||||||
|
DataSourceConfig ds = db.getDataSourceConfig();
|
||||||
|
ds.setUrl(replaceDatabaseString(ds.getUrl()));
|
||||||
|
getDataFolder().mkdirs();
|
||||||
|
|
||||||
|
ClassLoader previous = Thread.currentThread().getContextClassLoader();
|
||||||
|
Thread.currentThread().setContextClassLoader(classLoader);
|
||||||
|
ebean = EbeanServerFactory.create(db);
|
||||||
|
Thread.currentThread().setContextClassLoader(previous);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides a list of all classes that should be persisted in the database
|
||||||
|
*
|
||||||
|
* @return List of Classes that are Ebeans
|
||||||
|
*/
|
||||||
|
public List<Class<?>> getDatabaseClasses() {
|
||||||
|
return new ArrayList<Class<?>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String replaceDatabaseString(String input) {
|
||||||
|
return input.replaceAll("\\{DIR\\}", getDataFolder().getPath().replaceAll("\\\\", "/"));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the initialization status of this plugin
|
* Gets the initialization status of this plugin
|
||||||
@ -199,4 +238,7 @@ public abstract class JavaPlugin implements Plugin {
|
|||||||
this.naggable = canNag;;
|
this.naggable = canNag;;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EbeanServer getDatabase() {
|
||||||
|
return ebean;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren