v1.4.6b:
- Support AuthMe Inventory-Events: * So login and logout _should_ never again f*ckup inventories
This commit is contained in:
parent
9773ce0343
commit
6ff79cfc9e
8 changed files with 136 additions and 21 deletions
|
@ -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:
|
||||
|
|
4
pom.xml
4
pom.xml
|
@ -3,7 +3,7 @@
|
|||
<groupId>de.jaschastarke</groupId>
|
||||
<artifactId>LimitedCreative</artifactId>
|
||||
<name>LimitedCreative</name>
|
||||
<version>1.4.6a</version>
|
||||
<version>1.4.6b</version>
|
||||
<url>https://github.com/possi/LimitedCreative</url>
|
||||
<scm>
|
||||
<connection>scm:git:git://github.com/possi/LimitedCreative.git</connection>
|
||||
|
@ -102,7 +102,7 @@
|
|||
<dependency>
|
||||
<groupId>uk.org.whoami</groupId>
|
||||
<artifactId>authme</artifactId>
|
||||
<version>2.7.0</version>
|
||||
<version>2.7.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.onarandombox.multiversecore</groupId>
|
||||
|
|
|
@ -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<Class<?>, CommunicationBridge> bridges = new HashMap<Class<?>, 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 extends CommunicationBridge> T getBridge(Class<T> cls) {
|
||||
if (!bridges.containsKey(cls)) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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;*/
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue