AuthMe 3.0 Support

This commit is contained in:
Jascha Starke 2013-10-17 20:29:21 +02:00
parent 18b90dedc9
commit 9b3617ecba
8 changed files with 178 additions and 4 deletions

View file

@ -86,6 +86,12 @@
<artifactId>authme</artifactId>
<version>2.9.5</version>
</dependency>
<dependency>
<!-- http://dev.bukkit.org/server-mods/authme-reloaded/ -->
<groupId>fr.xephi</groupId>
<artifactId>authme</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<!-- http://dev.bukkit.org/server-mods/multiverse-core/ -->
<groupId>com.onarandombox.multiversecore</groupId>
@ -96,7 +102,7 @@
<!-- http://dev.bukkit.org/bukkit-plugins/multiworld-v-2-0/ -->
<groupId>multiworld</groupId>
<artifactId>multiworld</artifactId>
<version>4.6.6</version>
<version>4.7.2</version>
</dependency>
<dependency>
<!-- http://dev.bukkit.org/server-mods/xauth/ -->

View file

@ -4,6 +4,7 @@ import org.bukkit.Bukkit;
import de.jaschastarke.hooking.BooleanHooker;
import de.jaschastarke.hooking.GetHooker;
import de.jaschastarke.minecraft.limitedcreative.hooks.AuthMe3Hooks;
import de.jaschastarke.minecraft.limitedcreative.hooks.AuthMeHooks;
import de.jaschastarke.minecraft.limitedcreative.hooks.MultiVerseHooks;
import de.jaschastarke.minecraft.limitedcreative.hooks.PlayerCheckHooker;
@ -26,10 +27,12 @@ public final class Hooks {
IsMultiVerse.clearHooks();
InventoryIncompatible.clearHooks();
if (isPluginEnabled("AuthMe")) {
if (isAuthMePresent()) {
new AuthMeHooks(plugin);
} else if (isAuthMe3Present()) {
plugin.getModules().addSharedModule(new AuthMe3Hooks(plugin));
}
if (isPluginEnabled("xAuth")) {
if (isXAuth20Present()) {
new xAuthHooks(plugin);
}
if (isPluginEnabled("Multiverse-Core")) {
@ -49,4 +52,37 @@ public final class Hooks {
}
});
}
public static boolean isAuthMePresent() {
if (isPluginEnabled("AuthMe")) {
try {
return Class.forName("uk.org.whoami.authme.api.API") != null;
} catch (ClassNotFoundException e) {
return false;
}
}
return false;
}
public static boolean isAuthMe3Present() {
if (isPluginEnabled("AuthMe")) {
try {
return Class.forName("fr.xephi.authme.api.API") != null;
} catch (ClassNotFoundException e) {
return false;
}
}
return false;
}
public static boolean isXAuth20Present() {
if (isPluginEnabled("xAuth")) {
try {
return Class.forName("com.cypherx.xauth.xAuth") != null;
} catch (ClassNotFoundException e) {
return false;
}
}
return false;
}
}

View file

@ -9,7 +9,9 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import de.jaschastarke.bukkit.lib.CoreModule;
import de.jaschastarke.minecraft.limitedcreative.hooks.AuthMe3Hooks;
import de.jaschastarke.minecraft.limitedcreative.inventories.ArmoryConfig;
import de.jaschastarke.minecraft.limitedcreative.inventories.AuthMe3Inventories;
import de.jaschastarke.minecraft.limitedcreative.inventories.AuthMeInventories;
import de.jaschastarke.minecraft.limitedcreative.inventories.Inventory;
import de.jaschastarke.minecraft.limitedcreative.inventories.InventoryConfig;
@ -41,8 +43,11 @@ public class ModInventories extends CoreModule<LimitedCreative> {
config = plugin.getPluginConfig().registerSection(new InventoryConfig(this, entry));
armor_config = config.registerSection(new ArmoryConfig(this));
if (plugin.getServer().getPluginManager().isPluginEnabled("AuthMe")) {
if (Hooks.isAuthMePresent()) {
addModule(new AuthMeInventories(plugin, this));
} else if (Hooks.isAuthMe3Present()) {
modules.linkSharedModule(AuthMe3Hooks.class, plugin.getModules());
addModule(new AuthMe3Inventories(plugin, this));
}
String incomp = Hooks.InventoryIncompatible.test();
if (config.getEnabled() && incomp != null) {

View file

@ -6,6 +6,7 @@ import org.bukkit.entity.Player;
import de.jaschastarke.bukkit.lib.CoreModule;
import de.jaschastarke.bukkit.lib.commands.AliasHelpedCommand;
import de.jaschastarke.minecraft.limitedcreative.hooks.AuthMe3Hooks;
import de.jaschastarke.minecraft.limitedcreative.regions.BlockListener;
import de.jaschastarke.minecraft.limitedcreative.regions.IWorldGuardIntegration;
import de.jaschastarke.minecraft.limitedcreative.regions.PlayerData;
@ -49,6 +50,9 @@ public class ModRegions extends CoreModule<LimitedCreative> {
entry.deactivateUsage();
return;
}
if (Hooks.isAuthMe3Present()) {
modules.linkSharedModule(AuthMe3Hooks.class, plugin.getModules());
}
command = new RegionsCommand(this);

View file

@ -0,0 +1,69 @@
package de.jaschastarke.minecraft.limitedcreative.hooks;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.plugin.IllegalPluginAccessException;
import de.jaschastarke.bukkit.lib.SimpleModule;
import de.jaschastarke.minecraft.limitedcreative.Hooks;
import de.jaschastarke.minecraft.limitedcreative.LimitedCreative;
import fr.xephi.authme.api.API;
import fr.xephi.authme.events.LoginEvent;
public class AuthMe3Hooks extends SimpleModule<LimitedCreative> implements Listener {
private Map<String, Boolean> users = new HashMap<String, Boolean>();
private PlayerCheckHooker.Check check;
public AuthMe3Hooks(final LimitedCreative plugin) {
super(plugin);
check = new PlayerCheckHooker.Check() {
@Override
public boolean test(Player player) {
if (users.containsKey(player.getName())) {
if (plugin.isDebug()) // not nessesary, but so no string concation without debug needed
plugin.getLog().debug("AuthMe: "+player.getName()+": Event logged in: "+users.get(player.getName()));
return users.get(player.getName());
} else {
boolean li = API.isAuthenticated(player);
if (plugin.isDebug()) // not nessesary, but so no string concation without debug needed
plugin.getLog().debug("AuthMe: "+player.getName()+": logged in: "+li);
return li;
}
}
};
}
@Override
public void onEnable() {
try {
super.onEnable();
} catch (IllegalPluginAccessException e) {
enabled = true;
plugin.getLog().warn("AuthMe 3.0 Bug detected. Update AuthMe to a newer version as soon as avilable.");
}
Hooks.IsLoggedIn.register(check);
}
@Override
public void onDisable() {
super.onDisable();
Hooks.IsLoggedIn.unregister(check);
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerLogin(PlayerLoginEvent event) {
if (event.getPlayer() == null)
return;
users.put(event.getPlayer().getName(), API.isAuthenticated(event.getPlayer()));
}
@EventHandler
public void onAuthMeLogin(LoginEvent event) {
users.put(event.getPlayer().getName(), true);
}
}

View file

@ -6,6 +6,7 @@ import uk.org.whoami.authme.api.API;
import de.jaschastarke.minecraft.limitedcreative.Hooks;
import de.jaschastarke.minecraft.limitedcreative.LimitedCreative;
@Deprecated // AuthMe 3.0 released. Compatibility for older versions will be removed sometime
public class AuthMeHooks {
public AuthMeHooks(final LimitedCreative plugin) {
Hooks.IsLoggedIn.register(new PlayerCheckHooker.Check() {

View file

@ -0,0 +1,52 @@
package de.jaschastarke.minecraft.limitedcreative.inventories;
import org.bukkit.GameMode;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import de.jaschastarke.bukkit.lib.SimpleModule;
import de.jaschastarke.minecraft.limitedcreative.LimitedCreative;
import de.jaschastarke.minecraft.limitedcreative.ModInventories;
import fr.xephi.authme.events.RestoreInventoryEvent;
import fr.xephi.authme.events.StoreInventoryEvent;
public class AuthMe3Inventories extends SimpleModule<LimitedCreative> implements Listener {
ModInventories invmod;
public AuthMe3Inventories(LimitedCreative plugin, ModInventories modInventories) {
super(plugin);
invmod = modInventories;
}
@EventHandler
public void onStoreInventory(StoreInventoryEvent event) {
if (isDebug())
getLog().debug("AuthMe Store Event: "+event.getPlayer().getName());
event.getPlayer().closeInventory();
GameMode cgm = event.getPlayer().getGameMode();
if (cgm == GameMode.ADVENTURE && !invmod.getConfig().getSeparateAdventure())
cgm = GameMode.SURVIVAL;
if (cgm != GameMode.CREATIVE || invmod.getConfig().getStoreCreative()) {
invmod.getInventory(event.getPlayer()).save(cgm);
}
}
@EventHandler
public void onRestoreInventory(RestoreInventoryEvent event) {
if (isDebug())
getLog().debug("AuthMe Restore Event: "+event.getPlayer().getName());
event.getPlayer().closeInventory();
GameMode cgm = event.getPlayer().getGameMode();
if (cgm == GameMode.ADVENTURE && !invmod.getConfig().getSeparateAdventure())
cgm = GameMode.SURVIVAL;
Inventory inv = invmod.getInventory(event.getPlayer());
if (inv.isStored(cgm)) {
inv.load(cgm);
event.setCancelled(true);
}
}
}

View file

@ -10,6 +10,7 @@ import de.jaschastarke.bukkit.lib.SimpleModule;
import de.jaschastarke.minecraft.limitedcreative.LimitedCreative;
import de.jaschastarke.minecraft.limitedcreative.ModInventories;
@Deprecated // AuthMe 3.0 released. Compatibility for older versions will be removed sometime
public class AuthMeInventories extends SimpleModule<LimitedCreative> implements Listener {
ModInventories invmod;
public AuthMeInventories(LimitedCreative plugin, ModInventories modInventories) {