Skip to content

Commit

Permalink
Updated for Spigot 1.12, with baked-in ebean support
Browse files Browse the repository at this point in the history
  • Loading branch information
redwallhp committed Jun 13, 2017
1 parent a47c384 commit 5308b88
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
16 changes: 14 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>nu.nerd</groupId>
<artifactId>ModReq</artifactId>
<version>1.7</version>
<version>1.8</version>
<packaging>jar</packaging>
<name>ModReq</name>
<description>Moderator Request Sytem</description>
Expand Down Expand Up @@ -33,7 +33,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<version>1.12-R0.1-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
Expand All @@ -42,6 +42,11 @@
<artifactId>bukkit-migration-tools</artifactId>
<version>0.1</version>
</dependency>
<dependency>
<groupId>nu.nerd</groupId>
<artifactId>BukkitEbean</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -102,8 +107,15 @@
<artifactSet>
<includes>
<include>org.gestern:bukkit-migration-tools:jar:*</include>
<include>nu.nerd:BukkitEbean:jar:*</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>nu.nerd.BukkitEbean</pattern>
<shadedPattern>nu.nerd.modreq.BukkitEbean</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
Expand Down
19 changes: 13 additions & 6 deletions src/nu/nerd/modreq/ModReq.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package nu.nerd.modreq;

import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.SqlRow;

import java.io.File;
Expand All @@ -22,6 +23,8 @@

import javax.persistence.PersistenceException;

import nu.nerd.BukkitEbean.EbeanBuilder;
import nu.nerd.BukkitEbean.EbeanHelper;
import nu.nerd.modreq.database.Note;
import nu.nerd.modreq.database.NoteTable;
import nu.nerd.modreq.database.Request;
Expand Down Expand Up @@ -61,6 +64,7 @@ public class ModReq extends JavaPlugin {
Map<UUID, Integer> claimedIds = new HashMap<UUID, Integer>();
File claimsFile;

EbeanServer db;
RequestTable reqTable;
NoteTable noteTable;

Expand Down Expand Up @@ -90,11 +94,12 @@ public void onDisable() {

public boolean setupDatabase() {
try {
getDatabase().find(Request.class).findRowCount();
getDatabase().find(Note.class).findRowCount();
db = new EbeanBuilder(this).setClasses(getDatabaseClasses()).build();
db.find(Request.class).findRowCount();
db.find(Note.class).findRowCount();
} catch (PersistenceException ex) {
getLogger().log(Level.INFO, "First run, initializing database.");
installDDL();
EbeanHelper.installDDL(db);
return true;
}

Expand All @@ -113,7 +118,7 @@ public void resetDatabase() {
Set<String> unknownNames = new HashSet<String>();

getLogger().log(Level.INFO, "Executing remove ddl");
removeDDL();
EbeanHelper.removeDDL(db);

if (setupDatabase()) {
getLogger().log(Level.INFO, "Schema created, converting " + rowRequests.size() + " requests and " + rowNotes.size() + " notes");
Expand Down Expand Up @@ -268,14 +273,17 @@ public void resetDatabase() {
getLogger().log(Level.INFO, "Done");
}

@Override
public ArrayList<Class<?>> getDatabaseClasses() {
ArrayList<Class<?>> list = new ArrayList<Class<?>>();
list.add(Request.class);
list.add(Note.class);
return list;
}

public EbeanServer getDatabase() {
return db;
}

@Override
public boolean onCommand(CommandSender sender, Command command, String name, String[] args) {
String senderName = ChatColor.stripColor(sender.getName());
Expand Down Expand Up @@ -800,7 +808,6 @@ private void mrUpgrade() {

BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
scheduler.scheduleSyncDelayedTask(this, new Runnable() {
@Override
public void run() {
resetDatabase();
}
Expand Down

0 comments on commit 5308b88

Please sign in to comment.