diff --git a/plugin.yml b/plugin.yml
index ffdaacb..60d6a68 100644
--- a/plugin.yml
+++ b/plugin.yml
@@ -1,6 +1,6 @@
name: LimitedCreative
main: de.jaschastarke.minecraft.limitedcreative.Core
-version: 1.4.6a
+version: 1.4.6b
softdepend: [WorldGuard, WorldEdit, MultiInv]
dev-url: http://dev.bukkit.org/server-mods/limited-creative/
commands:
diff --git a/pom.xml b/pom.xml
index 0b3260d..4aeefc4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
de.jaschastarke
LimitedCreative
LimitedCreative
- 1.4.6a
+ 1.4.6b
https://github.com/possi/LimitedCreative
scm:git:git://github.com/possi/LimitedCreative.git
@@ -102,7 +102,7 @@
uk.org.whoami
authme
- 2.7.0
+ 2.7.1
com.onarandombox.multiversecore
diff --git a/src/de/jaschastarke/minecraft/integration/AbstractCommunicator.java b/src/de/jaschastarke/minecraft/integration/AbstractCommunicator.java
index 4f458f3..3fc454b 100644
--- a/src/de/jaschastarke/minecraft/integration/AbstractCommunicator.java
+++ b/src/de/jaschastarke/minecraft/integration/AbstractCommunicator.java
@@ -20,6 +20,8 @@ package de.jaschastarke.minecraft.integration;
//import java.util.HashMap;
//import java.util.Map;
+import static de.jaschastarke.minecraft.utils.Util.compareVersion;
+
//import org.bukkit.event.EventHandler;
//import org.bukkit.event.Listener;
/*import org.bukkit.event.server.PluginDisableEvent;
@@ -27,7 +29,7 @@ import org.bukkit.event.server.PluginEnableEvent;*/
import org.bukkit.plugin.java.JavaPlugin;
abstract public class AbstractCommunicator /*implements Listener*/ {
- private JavaPlugin plugin;
+ protected JavaPlugin plugin;
//private Map, CommunicationBridge> bridges = new HashMap, CommunicationBridge>();
public AbstractCommunicator(JavaPlugin plugin) {
@@ -37,6 +39,13 @@ abstract public class AbstractCommunicator /*implements Listener*/ {
protected boolean isPluginEnabled(String plugin) {
return this.plugin.getServer().getPluginManager().isPluginEnabled(plugin);
}
+ protected boolean isPluginEnabled(String plugin, String minVersion) {
+ if (isPluginEnabled(plugin)) {
+ String ver = this.plugin.getServer().getPluginManager().getPlugin(plugin).getDescription().getVersion();
+ return compareVersion(ver, minVersion) > 0;
+ }
+ return false;
+ }
/*@SuppressWarnings("unchecked")
protected T getBridge(Class cls) {
if (!bridges.containsKey(cls)) {
diff --git a/src/de/jaschastarke/minecraft/integration/AuthMeInventories.java b/src/de/jaschastarke/minecraft/integration/AuthMeInventories.java
new file mode 100644
index 0000000..a87754a
--- /dev/null
+++ b/src/de/jaschastarke/minecraft/integration/AuthMeInventories.java
@@ -0,0 +1,51 @@
+package de.jaschastarke.minecraft.integration;
+
+import org.bukkit.GameMode;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.plugin.java.JavaPlugin;
+
+import uk.org.whoami.authme.events.RestoreInventoryEvent;
+import uk.org.whoami.authme.events.StoreInventoryEvent;
+
+import de.jaschastarke.minecraft.limitedcreative.Core;
+import de.jaschastarke.minecraft.limitedcreative.LCPlayer;
+import de.jaschastarke.minecraft.limitedcreative.Players;
+
+public class AuthMeInventories implements Listener {
+ public AuthMeInventories(JavaPlugin plugin) {
+ plugin.getServer().getPluginManager().registerEvents(this, plugin);
+ }
+
+ @EventHandler
+ public void onStoreInventory(StoreInventoryEvent event) {
+ Core.debug("AuthMe Store Event: "+event.getPlayer().getName());
+ LCPlayer player = Players.get(event.getPlayer());
+
+ event.getPlayer().closeInventory();
+ GameMode cgm = event.getPlayer().getGameMode();
+
+ if (cgm == GameMode.ADVENTURE && !Core.plugin.config.getAdventureInv())
+ cgm = GameMode.SURVIVAL;
+
+ if (cgm != GameMode.CREATIVE || Core.plugin.config.getStoreCreative()) {
+ player.getInv().save(cgm);
+ }
+ }
+ @EventHandler
+ public void onRestoreInventory(RestoreInventoryEvent event) {
+ Core.debug("AuthMe Restore Event: "+event.getPlayer().getName());
+ LCPlayer player = Players.get(event.getPlayer());
+
+ event.getPlayer().closeInventory();
+ GameMode cgm = event.getPlayer().getGameMode();
+
+ if (cgm == GameMode.ADVENTURE && !Core.plugin.config.getAdventureInv())
+ cgm = GameMode.SURVIVAL;
+
+ if (player.getInv().isStored(cgm)) {
+ player.getInv().load(cgm);
+ event.setCancelled(true);
+ }
+ }
+}
diff --git a/src/de/jaschastarke/minecraft/integration/Communicator.java b/src/de/jaschastarke/minecraft/integration/Communicator.java
index 283c085..2af494a 100644
--- a/src/de/jaschastarke/minecraft/integration/Communicator.java
+++ b/src/de/jaschastarke/minecraft/integration/Communicator.java
@@ -31,12 +31,25 @@ public class Communicator extends AbstractCommunicator {
}
public boolean isLoggedIn(Player player) {
- if (isPluginEnabled("AuthMe") && !AuthMe.isLoggedInComplete(player))
+ if (isPluginEnabled("AuthMe") && !AuthMe.isLoggedIn(player))
return false;
if (isPluginEnabled("xAuth") && !xAuth.isLoggedInNotGuest(player))
return false;
return true;
}
+
+ public boolean isLoggedInComplete(Player player) {
+ if (isPluginEnabled("AuthMe") && !AuthMe.isLoggedInComplete(player))
+ return false;
+ return true;
+ }
+
+
+ public void hookAuthInvs() {
+ if (isPluginEnabled("AuthMe", "2.7.0b2")) {
+ new AuthMeInventories(this.plugin);
+ }
+ }
public boolean isCreative(World world) {
boolean creative = Bukkit.getServer().getDefaultGameMode() == GameMode.CREATIVE;
diff --git a/src/de/jaschastarke/minecraft/limitedcreative/Core.java b/src/de/jaschastarke/minecraft/limitedcreative/Core.java
index f221a4e..f8839da 100644
--- a/src/de/jaschastarke/minecraft/limitedcreative/Core.java
+++ b/src/de/jaschastarke/minecraft/limitedcreative/Core.java
@@ -76,6 +76,9 @@ public class Core extends JavaPlugin {
warn(L("basic.conflict", "MultiInv", L("basic.feature.store")));
config.setTempStoreEnabled(false);
}
+ if (config.getStoreEnabled()) {
+ com.hookAuthInvs();
+ }
getServer().getPluginManager().registerEvents(new MainListener(this), this);
// 2nd Feature: Creative Limitations (Restrictions)
diff --git a/src/de/jaschastarke/minecraft/limitedcreative/LCPlayer.java b/src/de/jaschastarke/minecraft/limitedcreative/LCPlayer.java
index 0b2bf3a..26599fa 100644
--- a/src/de/jaschastarke/minecraft/limitedcreative/LCPlayer.java
+++ b/src/de/jaschastarke/minecraft/limitedcreative/LCPlayer.java
@@ -62,7 +62,7 @@ public class LCPlayer {
//name = player.getName();
//touch();
- if (!this.isActiveRegionGameMode(player.getGameMode())) {
+ if (!this.isActiveRegionGameMode(player.getGameMode()) && plugin.com.isLoggedInComplete(getPlayer())) {
setInPermanentGameMode(player.getGameMode());
}
}
@@ -170,22 +170,24 @@ public class LCPlayer {
public boolean onSetGameMode(GameMode gm) {
Core.debug(getName() + " going into " + gm);
- if (isActiveRegionGameMode()) { // change to the other gamemode as the area defines
- if (!isActiveRegionGameMode(gm)) { // only when we are not switching to the mode the region allows
- if (!plugin.config.getRegionOptional() && !hasPermission(Perms.REGIONS_BYPASS)) {
- getPlayer().sendMessage(ChatColor.RED + L("exception.region.not_optional", gm.toString().toLowerCase()));
- Core.debug("... denied");
- return false;
+ if (plugin.com.isLoggedInComplete(getPlayer())) { // if authme is changing GameMode before going to teleport, this should be remembered
+ if (isActiveRegionGameMode()) { // change to the other gamemode as the area defines
+ if (!isActiveRegionGameMode(gm)) { // only when we are not switching to the mode the region allows
+ if (!plugin.config.getRegionOptional() && !hasPermission(Perms.REGIONS_BYPASS)) {
+ getPlayer().sendMessage(ChatColor.RED + L("exception.region.not_optional", gm.toString().toLowerCase()));
+ Core.debug("... denied");
+ return false;
+ } else {
+ setOptionalRegionGameMode(gm);
+ }
} else {
- setOptionalRegionGameMode(gm);
+ // we are changing to the mode the region defines, thats not permanent
+ setOptionalRegionGameMode(null);
+ setInPermanentGameMode(null);
}
} else {
- // we are changing to the mode the region defines, thats not permanent
- setOptionalRegionGameMode(null);
- setInPermanentGameMode(null);
+ setInPermanentGameMode(gm); // we are not in a region, so the mode change is permanent
}
- } else {
- setInPermanentGameMode(gm); // we are not in a region, so the mode change is permanent
}
/*
@@ -412,9 +414,6 @@ public class LCPlayer {
return true;
}
- /*
- * Attention: "Creative" stands for "the other gamemode". So true may mean, "be survival in creative world".
- */
public void setRegionGameMode(GameMode region_gamemode, PlayerAreaEvent area_event) {
Core.debug(getName()+": changed region: "+region_gamemode+": " + area_event);
@@ -458,6 +457,11 @@ public class LCPlayer {
// 3. (because of else) we are not longer in that mode
// result: advise him to not longer allowed to that region
storeActiveRegionGameMode(null);
+ } else if (region_gamemode == CURRENT_GAMEMODE && !this.isInPermanentGameMode(CURRENT_GAMEMODE)) {
+ if (!isActiveRegionGameMode(region_gamemode)) {
+ // we have no information why we are already in this gamemode, so this may be because of an AuthMe change-and-teleport
+ storeActiveRegionGameMode(region_gamemode);
+ }
}
/** At the moment, in permanent game mode, it ignores all regions
else if (this.isRegionGameMode()) {
diff --git a/src/de/jaschastarke/minecraft/utils/Util.java b/src/de/jaschastarke/minecraft/utils/Util.java
index cda6270..cf76008 100644
--- a/src/de/jaschastarke/minecraft/utils/Util.java
+++ b/src/de/jaschastarke/minecraft/utils/Util.java
@@ -91,4 +91,39 @@ final public class Util {
public static String toString(Location loc) {
return "{X: "+loc.getBlockX()+", Y: "+loc.getBlockY()+", Z: "+loc.getBlockZ()+"}";
}
+
+ /**
+ * Compares 2 Version Strings
+ *
+ * Only Numbers are interpreted. Any non-numeric char separates sub-versions.
+ *
+ * @param v1 First version String
+ * @param v2 Version String to compare with
+ * @return -1 when v1 < v2; 1 when v1 > v2; 0 when equal
+ */
+ public static int compareVersion(String v1, String v2) {
+ String[] ver1 = v1.split("[^0-9]+");
+ String[] ver2 = v2.split("[^0-9]+");
+
+ for (int i = 0; i < Math.min(ver1.length, ver2.length); i++) {
+ int diff = new Integer(ver1[i]).compareTo(new Integer(ver2[i]));
+ if (diff != 0)
+ return diff < 0 ? -1 : 1;
+ }
+ return ver1.length == ver2.length ? 0 : ver1.length < ver2.length ? -1 : 1;
+
+ /*String[] vals1 = v1.split("\\.");
+ String[] vals2 = v2.split("\\.");
+ int i=0;
+ while (i < vals1.length && i < vals2.length && vals1[i].equals(vals2[i])) {
+ i++;
+ }
+
+ if (i < vals1.length && i < vals2.length) {
+ int diff = new Integer(vals1[i]).compareTo(new Integer(vals2[i]));
+ return diff < 0 ? -1 : diff == 0 ? 0 : 1;
+ }
+
+ return vals1.length < vals2.length ? -1 : vals1.length == vals2.length ? 0 : 1;*/
+ }
}