mirror of
https://github.com/moparisthebest/xAuth
synced 2024-12-22 07:08:51 -05:00
1. Fixed BukkitContrib compatibility
2. Refactored xAuthPermissions & xAuthHelp
This commit is contained in:
parent
06b56509ff
commit
658d8da32d
@ -8,16 +8,17 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.command.ConsoleCommandSender;
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
||||||
import com.cypherx.xauth.Account;
|
import com.cypherx.xauth.Account;
|
||||||
import com.cypherx.xauth.TeleLocation;
|
import com.cypherx.xauth.TeleLocation;
|
||||||
import com.cypherx.xauth.Util;
|
import com.cypherx.xauth.Util;
|
||||||
import com.cypherx.xauth.xAuth;
|
import com.cypherx.xauth.xAuth;
|
||||||
import com.cypherx.xauth.xAuthLog;
|
import com.cypherx.xauth.xAuthLog;
|
||||||
import com.cypherx.xauth.xAuthMessages;
|
import com.cypherx.xauth.xAuthMessages;
|
||||||
import com.cypherx.xauth.xAuthPermissions;
|
|
||||||
import com.cypherx.xauth.xAuthPlayer;
|
import com.cypherx.xauth.xAuthPlayer;
|
||||||
import com.cypherx.xauth.xAuthSettings;
|
import com.cypherx.xauth.xAuthSettings;
|
||||||
import com.cypherx.xauth.database.DbUtil;
|
import com.cypherx.xauth.database.DbUtil;
|
||||||
|
import com.cypherx.xauth.plugins.xPermissions;
|
||||||
|
|
||||||
public class xAuthCommand implements CommandExecutor {
|
public class xAuthCommand implements CommandExecutor {
|
||||||
private final xAuth plugin;
|
private final xAuth plugin;
|
||||||
@ -70,7 +71,7 @@ public class xAuthCommand implements CommandExecutor {
|
|||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
Player player = (Player)sender;
|
Player player = (Player)sender;
|
||||||
|
|
||||||
if (!xAuthPermissions.has(player, "xauth.admin.register")) {
|
if (!xPermissions.has(player, "xauth.admin.register")) {
|
||||||
xAuthMessages.send("admnPermission", player);
|
xAuthMessages.send("admnPermission", player);
|
||||||
return true;
|
return true;
|
||||||
} else if (args.length < 3) {
|
} else if (args.length < 3) {
|
||||||
@ -124,7 +125,7 @@ public class xAuthCommand implements CommandExecutor {
|
|||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
Player player = (Player)sender;
|
Player player = (Player)sender;
|
||||||
|
|
||||||
if (!xAuthPermissions.has(player, "xauth.admin.changepw")) {
|
if (!xPermissions.has(player, "xauth.admin.changepw")) {
|
||||||
xAuthMessages.send("admnPermission", player);
|
xAuthMessages.send("admnPermission", player);
|
||||||
return true;
|
return true;
|
||||||
} else if (args.length < 3) {
|
} else if (args.length < 3) {
|
||||||
@ -174,7 +175,7 @@ public class xAuthCommand implements CommandExecutor {
|
|||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
Player player = (Player)sender;
|
Player player = (Player)sender;
|
||||||
|
|
||||||
if (!xAuthPermissions.has(player, "xauth.admin.logout")) {
|
if (!xPermissions.has(player, "xauth.admin.logout")) {
|
||||||
xAuthMessages.send("admnPermission", player);
|
xAuthMessages.send("admnPermission", player);
|
||||||
return true;
|
return true;
|
||||||
} else if (args.length < 2) {
|
} else if (args.length < 2) {
|
||||||
@ -224,7 +225,7 @@ public class xAuthCommand implements CommandExecutor {
|
|||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
Player player = (Player)sender;
|
Player player = (Player)sender;
|
||||||
|
|
||||||
if (!xAuthPermissions.has(player, "xauth.admin.unregister")) {
|
if (!xPermissions.has(player, "xauth.admin.unregister")) {
|
||||||
xAuthMessages.send("admnPermission", player);
|
xAuthMessages.send("admnPermission", player);
|
||||||
return true;
|
return true;
|
||||||
} else if (args.length < 2) {
|
} else if (args.length < 2) {
|
||||||
@ -284,7 +285,7 @@ public class xAuthCommand implements CommandExecutor {
|
|||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
Player player = (Player)sender;
|
Player player = (Player)sender;
|
||||||
|
|
||||||
if (!xAuthPermissions.has(player, "xauth.admin.location")) {
|
if (!xPermissions.has(player, "xauth.admin.location")) {
|
||||||
xAuthMessages.send("admnPermission", player);
|
xAuthMessages.send("admnPermission", player);
|
||||||
return true;
|
return true;
|
||||||
} else if (args.length < 2 || !(args[1].equals("set") || args[1].equals("remove"))) {
|
} else if (args.length < 2 || !(args[1].equals("set") || args[1].equals("remove"))) {
|
||||||
@ -340,7 +341,7 @@ public class xAuthCommand implements CommandExecutor {
|
|||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
Player player = (Player)sender;
|
Player player = (Player)sender;
|
||||||
|
|
||||||
if (!xAuthPermissions.has(player, "xauth.admin.config")) {
|
if (!xPermissions.has(player, "xauth.admin.config")) {
|
||||||
xAuthMessages.send("admnPermission", player);
|
xAuthMessages.send("admnPermission", player);
|
||||||
return true;
|
return true;
|
||||||
} else if (args.length < 2) {
|
} else if (args.length < 2) {
|
||||||
@ -464,7 +465,7 @@ public class xAuthCommand implements CommandExecutor {
|
|||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
Player player = (Player)sender;
|
Player player = (Player)sender;
|
||||||
|
|
||||||
if (xAuthPermissions.has(player, "xauth.admin.reload")) {
|
if (xPermissions.has(player, "xauth.admin.reload")) {
|
||||||
plugin.reload();
|
plugin.reload();
|
||||||
xAuthMessages.send("admnReloadSuccess", player);
|
xAuthMessages.send("admnReloadSuccess", player);
|
||||||
xAuthLog.info("Reloaded by " + player.getName());
|
xAuthLog.info("Reloaded by " + player.getName());
|
||||||
|
@ -16,6 +16,7 @@ import com.cypherx.xauth.xAuthMessages;
|
|||||||
import com.cypherx.xauth.xAuthPlayer;
|
import com.cypherx.xauth.xAuthPlayer;
|
||||||
import com.cypherx.xauth.xAuthSettings;
|
import com.cypherx.xauth.xAuthSettings;
|
||||||
import com.cypherx.xauth.database.DbUtil;
|
import com.cypherx.xauth.database.DbUtil;
|
||||||
|
import com.cypherx.xauth.plugins.xBukkitContrib;
|
||||||
|
|
||||||
public class xAuthPlayerListener extends PlayerListener {
|
public class xAuthPlayerListener extends PlayerListener {
|
||||||
private final xAuth plugin;
|
private final xAuth plugin;
|
||||||
@ -55,8 +56,6 @@ public class xAuthPlayerListener extends PlayerListener {
|
|||||||
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
|
|
||||||
//Easyban fix?
|
|
||||||
if (player == null)
|
if (player == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -131,7 +130,7 @@ public class xAuthPlayerListener extends PlayerListener {
|
|||||||
//if (!xAuthSettings.rstrCommands && !xPlayer.isRegistered())
|
//if (!xAuthSettings.rstrCommands && !xPlayer.isRegistered())
|
||||||
//return;
|
//return;
|
||||||
|
|
||||||
if (xPlayer.isGuest()) {
|
if (xPlayer.isGuest() && !xBukkitContrib.isVersionCommand(event.getMessage())) {
|
||||||
String command = event.getMessage().split(" ")[0].replaceFirst("/", "");
|
String command = event.getMessage().split(" ")[0].replaceFirst("/", "");
|
||||||
|
|
||||||
if (xAuthSettings.allowedCmds.contains(command))
|
if (xAuthSettings.allowedCmds.contains(command))
|
||||||
|
31
src/main/java/com/cypherx/xauth/plugins/xBukkitContrib.java
Normal file
31
src/main/java/com/cypherx/xauth/plugins/xBukkitContrib.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package com.cypherx.xauth.plugins;
|
||||||
|
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import com.cypherx.xauth.xAuth;
|
||||||
|
|
||||||
|
public class xBukkitContrib {
|
||||||
|
private static Plugin bcPlugin;
|
||||||
|
|
||||||
|
public static void setup(xAuth plugin) {
|
||||||
|
bcPlugin = plugin.getServer().getPluginManager().getPlugin("BukkitContrib");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isVersionCommand(String message) {
|
||||||
|
if (bcPlugin == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
String split[] = message.substring(1).split("\\.");
|
||||||
|
if (split.length == 3) {
|
||||||
|
try {
|
||||||
|
Integer.valueOf(split[0]);
|
||||||
|
Integer.valueOf(split[1]);
|
||||||
|
Integer.valueOf(split[2]);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
31
src/main/java/com/cypherx/xauth/plugins/xHelp.java
Normal file
31
src/main/java/com/cypherx/xauth/plugins/xHelp.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package com.cypherx.xauth.plugins;
|
||||||
|
|
||||||
|
import me.taylorkelly.help.Help;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import com.cypherx.xauth.xAuth;
|
||||||
|
import com.cypherx.xauth.xAuthLog;
|
||||||
|
|
||||||
|
public class xHelp {
|
||||||
|
public static void setup(xAuth plugin) {
|
||||||
|
Plugin test = plugin.getServer().getPluginManager().getPlugin("Help");
|
||||||
|
if (test != null) {
|
||||||
|
Help helpPlugin = ((Help) test);
|
||||||
|
String[] permissions = new String[]{"xauth.admin.register", "xauth.admin.changepw", "xauth.admin.logout", "xauth.admin.unregister", "xauth.admin.location", "xauth.admin.config", "xauth.admin.reload"};
|
||||||
|
helpPlugin.registerCommand("register [password] (email)", "Create an in-game account linked to your player name", plugin, true);
|
||||||
|
helpPlugin.registerCommand("login [password]", "Authenticate yourself as the account owner", plugin, true);
|
||||||
|
helpPlugin.registerCommand("changepw [old password] [new password]", "Change your password", plugin);
|
||||||
|
helpPlugin.registerCommand("logout", "Terminate your session", plugin);
|
||||||
|
helpPlugin.registerCommand("xauth register [player] [password] (email)", "Create an account for [player]", plugin, permissions[0]);
|
||||||
|
helpPlugin.registerCommand("xauth changepw [player] [new password]", "Change [player]'s password to [new password]", plugin, permissions[1]);
|
||||||
|
helpPlugin.registerCommand("xauth logout [player]", "Terminate [player]'s session", plugin, permissions[2]);
|
||||||
|
helpPlugin.registerCommand("xauth unregister [player]", "Remove [player]'s account", plugin, permissions[3]);
|
||||||
|
helpPlugin.registerCommand("xauth location set", "Set your current location as this worlds teleport location", plugin, permissions[4]);
|
||||||
|
helpPlugin.registerCommand("xauth location remove", "Remove this worlds teleport location", plugin, permissions[4]);
|
||||||
|
helpPlugin.registerCommand("xauth config [setting] (new value)", "View info about or change a setting", plugin, permissions[5]);
|
||||||
|
helpPlugin.registerCommand("xauth reload", "Reload the xAuth configuration and accounts", plugin, permissions[6]);
|
||||||
|
xAuthLog.info("'Help' support enabled");
|
||||||
|
}/* else
|
||||||
|
xAuthLog.info("'Help' isn't detected. No /help support");*/
|
||||||
|
}
|
||||||
|
}
|
32
src/main/java/com/cypherx/xauth/plugins/xPermissions.java
Normal file
32
src/main/java/com/cypherx/xauth/plugins/xPermissions.java
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package com.cypherx.xauth.plugins;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import com.cypherx.xauth.xAuth;
|
||||||
|
import com.cypherx.xauth.xAuthLog;
|
||||||
|
import com.nijiko.permissions.PermissionHandler;
|
||||||
|
import com.nijikokun.bukkit.Permissions.Permissions;
|
||||||
|
|
||||||
|
public class xPermissions {
|
||||||
|
private static PermissionHandler permissionHandler;
|
||||||
|
|
||||||
|
public static void setup(xAuth plugin) {
|
||||||
|
Plugin permissionsPlugin = plugin.getServer().getPluginManager().getPlugin("Permissions");
|
||||||
|
|
||||||
|
if (permissionHandler == null) {
|
||||||
|
if (permissionsPlugin != null) {
|
||||||
|
permissionHandler = ((Permissions) permissionsPlugin).getHandler();
|
||||||
|
xAuthLog.info("'Permission' support enabled");
|
||||||
|
} else
|
||||||
|
xAuthLog.info("Permission system not detected, defaulting to OP");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean has(Player player, String permission) {
|
||||||
|
if (permissionHandler == null)
|
||||||
|
return player.isOp();
|
||||||
|
|
||||||
|
return permissionHandler.has(player, permission);
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,9 @@ package com.cypherx.xauth;
|
|||||||
import com.cypherx.xauth.commands.*;
|
import com.cypherx.xauth.commands.*;
|
||||||
import com.cypherx.xauth.database.*;
|
import com.cypherx.xauth.database.*;
|
||||||
import com.cypherx.xauth.listeners.*;
|
import com.cypherx.xauth.listeners.*;
|
||||||
|
import com.cypherx.xauth.plugins.xBukkitContrib;
|
||||||
|
import com.cypherx.xauth.plugins.xHelp;
|
||||||
|
import com.cypherx.xauth.plugins.xPermissions;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -24,6 +27,7 @@ import org.bukkit.inventory.PlayerInventory;
|
|||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
|
||||||
public class xAuth extends JavaPlugin {
|
public class xAuth extends JavaPlugin {
|
||||||
public static PluginDescriptionFile desc;
|
public static PluginDescriptionFile desc;
|
||||||
public static File dataFolder;
|
public static File dataFolder;
|
||||||
@ -46,6 +50,12 @@ public class xAuth extends JavaPlugin {
|
|||||||
xAuthLog.info("v" + desc.getVersion() + " Disabled!");
|
xAuthLog.info("v" + desc.getVersion() + " Disabled!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initializePlugins() {
|
||||||
|
xBukkitContrib.setup(this);
|
||||||
|
xHelp.setup(this);
|
||||||
|
xPermissions.setup(this);
|
||||||
|
}
|
||||||
|
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
desc = getDescription();
|
desc = getDescription();
|
||||||
dataFolder = getDataFolder();
|
dataFolder = getDataFolder();
|
||||||
@ -62,8 +72,7 @@ public class xAuth extends JavaPlugin {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
xAuthPermissions.setup(this);
|
initializePlugins();
|
||||||
xAuthHelp.setup(this);
|
|
||||||
|
|
||||||
Database.connect();
|
Database.connect();
|
||||||
if (!Database.isConnected()) {
|
if (!Database.isConnected()) {
|
||||||
|
@ -5,8 +5,11 @@ import java.sql.Timestamp;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.cypherx.xauth.plugins.xPermissions;
|
||||||
//import org.bukkit.inventory.ItemStack;
|
//import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
|
||||||
public class xAuthPlayer {
|
public class xAuthPlayer {
|
||||||
private String playerName;
|
private String playerName;
|
||||||
private Account account;
|
private Account account;
|
||||||
@ -51,7 +54,7 @@ public class xAuthPlayer {
|
|||||||
if (xAuthSettings.regForced)
|
if (xAuthSettings.regForced)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return xAuthPermissions.has(getPlayer(), "xauth.register");
|
return xPermissions.has(getPlayer(), "xauth.register");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canNotify() {
|
public boolean canNotify() {
|
||||||
|
Loading…
Reference in New Issue
Block a user