Merge branch 'master' of https://github.com/lucko/LuckPerms
This commit is contained in:
commit
2413f0f379
@ -12,14 +12,10 @@ import me.lucko.luckperms.runnables.UpdateTask;
|
|||||||
import me.lucko.luckperms.users.BukkitUserManager;
|
import me.lucko.luckperms.users.BukkitUserManager;
|
||||||
import me.lucko.luckperms.users.UserManager;
|
import me.lucko.luckperms.users.UserManager;
|
||||||
import me.lucko.luckperms.utils.LPConfiguration;
|
import me.lucko.luckperms.utils.LPConfiguration;
|
||||||
import me.lucko.luckperms.vaulthooks.VaultChatHook;
|
import me.lucko.luckperms.vaulthooks.VaultHook;
|
||||||
import me.lucko.luckperms.vaulthooks.VaultPermissionHook;
|
|
||||||
import net.milkbowl.vault.chat.Chat;
|
|
||||||
import net.milkbowl.vault.permission.Permission;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.PluginCommand;
|
import org.bukkit.command.PluginCommand;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.ServicePriority;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -85,19 +81,12 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Provide vault support
|
// Provide vault support
|
||||||
try {
|
|
||||||
if (getServer().getPluginManager().isPluginEnabled("Vault")) {
|
if (getServer().getPluginManager().isPluginEnabled("Vault")) {
|
||||||
final VaultPermissionHook permsHook = new VaultPermissionHook(this);
|
VaultHook.hook(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.");
|
getLogger().info("Registered Vault permission & chat hook.");
|
||||||
} else {
|
} else {
|
||||||
getLogger().info("Vault not found.");
|
getLogger().info("Vault not found.");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
getLogger().warning("Error whilst hooking into Vault.");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,9 +9,9 @@ import net.milkbowl.vault.permission.Permission;
|
|||||||
*
|
*
|
||||||
* Registered on the lowest priority so other plugins can override
|
* 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);
|
super(perms);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package me.lucko.luckperms.vaulthooks;
|
package me.lucko.luckperms.vaulthooks;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.Setter;
|
||||||
import me.lucko.luckperms.LPBukkitPlugin;
|
import me.lucko.luckperms.LPBukkitPlugin;
|
||||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||||
import me.lucko.luckperms.exceptions.ObjectLacksPermissionException;
|
import me.lucko.luckperms.exceptions.ObjectLacksPermissionException;
|
||||||
@ -8,9 +8,10 @@ import me.lucko.luckperms.groups.Group;
|
|||||||
import me.lucko.luckperms.users.User;
|
import me.lucko.luckperms.users.User;
|
||||||
import net.milkbowl.vault.permission.Permission;
|
import net.milkbowl.vault.permission.Permission;
|
||||||
|
|
||||||
@AllArgsConstructor
|
class VaultPermissionHook extends Permission {
|
||||||
public class VaultPermissionHook extends Permission {
|
|
||||||
private final LPBukkitPlugin plugin;
|
@Setter
|
||||||
|
private LPBukkitPlugin plugin;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
@ -21,7 +21,7 @@ public abstract class Datastore {
|
|||||||
protected Datastore(LuckPermsPlugin plugin, String name) {
|
protected Datastore(LuckPermsPlugin plugin, String name) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.acceptingLogins = true;
|
this.acceptingLogins = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,12 +89,12 @@ public class FlatfileDatastore extends Datastore {
|
|||||||
try {
|
try {
|
||||||
makeFiles();
|
makeFiles();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// TODO catch here or something
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uuidCache.putAll(getUUIDCache());
|
uuidCache.putAll(getUUIDCache());
|
||||||
|
setAcceptingLogins(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void makeFiles() throws IOException {
|
private void makeFiles() throws IOException {
|
||||||
|
@ -6,6 +6,7 @@ import me.lucko.luckperms.data.MySQLConfiguration;
|
|||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class MySQLDatastore extends SQLDatastore {
|
public class MySQLDatastore extends SQLDatastore {
|
||||||
|
|
||||||
@ -38,7 +39,12 @@ public class MySQLDatastore extends SQLDatastore {
|
|||||||
hikari.addDataSourceProperty("user", username);
|
hikari.addDataSourceProperty("user", username);
|
||||||
hikari.addDataSourceProperty("password", password);
|
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
|
@Override
|
||||||
|
@ -113,17 +113,13 @@ abstract class SQLDatastore extends Datastore {
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupTables(String... tableQueries) {
|
boolean setupTables(String... tableQueries) {
|
||||||
boolean success = true;
|
boolean success = true;
|
||||||
for (String q : tableQueries) {
|
for (String q : tableQueries) {
|
||||||
if (!runQuery(new Query(q))) success = false;
|
if (!runQuery(new Query(q))) success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!success) {
|
return success;
|
||||||
plugin.getLogger().log(Level.SEVERE, "Error occurred whilst initialising the database. All connections are disallowed.");
|
|
||||||
shutdown();
|
|
||||||
setAcceptingLogins(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -6,6 +6,7 @@ import java.io.File;
|
|||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class SQLiteDatastore extends SQLDatastore {
|
public class SQLiteDatastore extends SQLDatastore {
|
||||||
|
|
||||||
@ -23,12 +24,23 @@ public class SQLiteDatastore extends SQLDatastore {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
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
|
@Override
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
|
try {
|
||||||
|
if (connection != null && !connection.isClosed()) {
|
||||||
|
connection.close();
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user