This commit is contained in:
Luck 2016-07-05 20:54:09 +01:00
commit 2413f0f379
9 changed files with 74 additions and 34 deletions

View File

@ -12,14 +12,10 @@ import me.lucko.luckperms.runnables.UpdateTask;
import me.lucko.luckperms.users.BukkitUserManager;
import me.lucko.luckperms.users.UserManager;
import me.lucko.luckperms.utils.LPConfiguration;
import me.lucko.luckperms.vaulthooks.VaultChatHook;
import me.lucko.luckperms.vaulthooks.VaultPermissionHook;
import net.milkbowl.vault.chat.Chat;
import net.milkbowl.vault.permission.Permission;
import me.lucko.luckperms.vaulthooks.VaultHook;
import org.bukkit.Bukkit;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.ServicePriority;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
@ -85,18 +81,11 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
}
// Provide vault support
try {
if (getServer().getPluginManager().isPluginEnabled("Vault")) {
final VaultPermissionHook permsHook = new VaultPermissionHook(this);
getServer().getServicesManager().register(Permission.class, permsHook, this, ServicePriority.High);
getServer().getServicesManager().register(Chat.class, new VaultChatHook(permsHook), this, ServicePriority.Lowest);
getLogger().info("Registered Vault permission & chat hook.");
} else {
getLogger().info("Vault not found.");
}
} catch (Exception e) {
getLogger().warning("Error whilst hooking into Vault.");
e.printStackTrace();
if (getServer().getPluginManager().isPluginEnabled("Vault")) {
VaultHook.hook(this);
getLogger().info("Registered Vault permission & chat hook.");
} else {
getLogger().info("Vault not found.");
}
}

View File

@ -9,9 +9,9 @@ import net.milkbowl.vault.permission.Permission;
*
* Registered on the lowest priority so other plugins can override
*/
public class VaultChatHook extends Chat {
class VaultChatHook extends Chat {
public VaultChatHook(Permission perms) {
VaultChatHook(Permission perms) {
super(perms);
}

View File

@ -0,0 +1,36 @@
package me.lucko.luckperms.vaulthooks;
import me.lucko.luckperms.LPBukkitPlugin;
import net.milkbowl.vault.chat.Chat;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.plugin.ServicePriority;
import org.bukkit.plugin.ServicesManager;
public class VaultHook {
private static VaultChatHook chatHook = null;
private static VaultPermissionHook permissionHook = null;
public static void hook(LPBukkitPlugin plugin) {
try {
if (permissionHook == null) {
permissionHook = new VaultPermissionHook();
}
permissionHook.setPlugin(plugin);
if (chatHook == null) {
chatHook = new VaultChatHook(permissionHook);
}
final ServicesManager sm = plugin.getServer().getServicesManager();
sm.unregisterAll(plugin);
sm.register(Permission.class, permissionHook, plugin, ServicePriority.High);
sm.register(Chat.class, chatHook, plugin, ServicePriority.Lowest);
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -1,6 +1,6 @@
package me.lucko.luckperms.vaulthooks;
import lombok.AllArgsConstructor;
import lombok.Setter;
import me.lucko.luckperms.LPBukkitPlugin;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import me.lucko.luckperms.exceptions.ObjectLacksPermissionException;
@ -8,9 +8,10 @@ import me.lucko.luckperms.groups.Group;
import me.lucko.luckperms.users.User;
import net.milkbowl.vault.permission.Permission;
@AllArgsConstructor
public class VaultPermissionHook extends Permission {
private final LPBukkitPlugin plugin;
class VaultPermissionHook extends Permission {
@Setter
private LPBukkitPlugin plugin;
@Override
public String getName() {

View File

@ -21,7 +21,7 @@ public abstract class Datastore {
protected Datastore(LuckPermsPlugin plugin, String name) {
this.plugin = plugin;
this.name = name;
this.acceptingLogins = true;
this.acceptingLogins = false;
}
/**

View File

@ -89,12 +89,12 @@ public class FlatfileDatastore extends Datastore {
try {
makeFiles();
} catch (IOException e) {
// TODO catch here or something
e.printStackTrace();
return;
}
uuidCache.putAll(getUUIDCache());
setAcceptingLogins(true);
}
private void makeFiles() throws IOException {

View File

@ -6,6 +6,7 @@ import me.lucko.luckperms.data.MySQLConfiguration;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.logging.Level;
public class MySQLDatastore extends SQLDatastore {
@ -38,7 +39,12 @@ public class MySQLDatastore extends SQLDatastore {
hikari.addDataSourceProperty("user", username);
hikari.addDataSourceProperty("password", password);
setupTables(CREATETABLE_UUID, CREATETABLE_USERS, CREATETABLE_GROUPS);
if (!setupTables(CREATETABLE_UUID, CREATETABLE_USERS, CREATETABLE_GROUPS)) {
plugin.getLogger().log(Level.SEVERE, "Error occurred whilst initialising the database. All connections are disallowed.");
shutdown();
} else {
setAcceptingLogins(true);
}
}
@Override

View File

@ -113,17 +113,13 @@ abstract class SQLDatastore extends Datastore {
return success;
}
void setupTables(String... tableQueries) {
boolean setupTables(String... tableQueries) {
boolean success = true;
for (String q : tableQueries) {
if (!runQuery(new Query(q))) success = false;
}
if (!success) {
plugin.getLogger().log(Level.SEVERE, "Error occurred whilst initialising the database. All connections are disallowed.");
shutdown();
setAcceptingLogins(false);
}
return success;
}
@Override

View File

@ -6,6 +6,7 @@ import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
public class SQLiteDatastore extends SQLDatastore {
@ -23,12 +24,23 @@ public class SQLiteDatastore extends SQLDatastore {
@Override
public void init() {
setupTables(CREATETABLE_UUID, CREATETABLE_USERS, CREATETABLE_GROUPS);
if (!setupTables(CREATETABLE_UUID, CREATETABLE_USERS, CREATETABLE_GROUPS)) {
plugin.getLogger().log(Level.SEVERE, "Error occurred whilst initialising the database. All connections are disallowed.");
shutdown();
} else {
setAcceptingLogins(true);
}
}
@Override
public void shutdown() {
try {
if (connection != null && !connection.isClosed()) {
connection.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
@Override