Slightly improve API, bump version to 3.2.0 for release

Methods are now properly annotated @Nullable when they may return null. More descriptive exceptions are thrown when issues occur instead of just returning null.
This commit is contained in:
Jikoo 2017-06-08 18:36:01 -04:00
parent 01f147b13c
commit 96c59f163d
35 changed files with 530 additions and 508 deletions

View file

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvparent</artifactId> <artifactId>openinvparent</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</parent> </parent>
<artifactId>openinvapi</artifactId> <artifactId>openinvapi</artifactId>

View file

@ -1,5 +1,7 @@
package com.lishid.openinv; package com.lishid.openinv;
import javax.annotation.Nullable;
import com.lishid.openinv.internal.IAnySilentContainer; import com.lishid.openinv.internal.IAnySilentContainer;
import com.lishid.openinv.internal.IInventoryAccess; import com.lishid.openinv.internal.IInventoryAccess;
import com.lishid.openinv.internal.ISpecialEnderChest; import com.lishid.openinv.internal.ISpecialEnderChest;
@ -11,145 +13,172 @@ import org.bukkit.plugin.Plugin;
/** /**
* Interface defining behavior for the OpenInv plugin. * Interface defining behavior for the OpenInv plugin.
* *
* @author Jikoo * @author Jikoo
*/ */
public interface IOpenInv { public interface IOpenInv {
/**
* Checks if the server version is supported by OpenInv.
*
* @return true if the server version is supported
*/
public boolean isSupportedVersion();
/**
* Gets the active IInventoryAccess implementation. May return null if the server version is
* unsupported.
*
* @return the IInventoryAccess
*/
public IInventoryAccess getInventoryAccess();
/**
* Gets the active ISilentContainer implementation. May return null if the server version is
* unsupported.
*
* @return the ISilentContainer
*/
public IAnySilentContainer getAnySilentContainer();
/**
* Gets an ISpecialPlayerInventory for the given Player.
*
* @param player the Player
* @param online true if the Player is currently online
* @return the ISpecialPlayerInventory
*/
public ISpecialPlayerInventory getInventory(Player player, boolean online);
/**
* Gets an ISpecialEnderChest for the given Player.
*
* @param player the Player
* @param online true if the Player is currently online
* @return the ISpecialEnderChest
*/
public ISpecialEnderChest getEnderChest(Player player, boolean online);
/**
* Forcibly unload a cached Player's data.
*
* @param player the OfflinePlayer to unload
*/
public void unload(OfflinePlayer player);
/** /**
* Check the configuration value for whether or not OpenInv saves player data when unloading * Check the configuration value for whether or not OpenInv saves player data when unloading
* players. This is exclusively for users who do not allow editing of inventories, only viewing, * players. This is exclusively for users who do not allow editing of inventories, only viewing,
* and wish to prevent any possibility of bugs such as lishid#40. If true, OpenInv will not ever * and wish to prevent any possibility of bugs such as lishid#40. If true, OpenInv will not ever
* save any edits made to players. * save any edits made to players.
* *
* @return false unless configured otherwise * @return false unless configured otherwise
*/ */
public boolean disableSaving(); public boolean disableSaving();
/** /**
* Check the configuration value for whether or not OpenInv displays a notification to the user * Gets the active ISilentContainer implementation. May return null if the server version is
* when a container is activated with SilentChest. * unsupported.
* *
* @return true unless configured otherwise * @return the ISilentContainer
* @throws IllegalStateException if the server version is unsupported
*/ */
public boolean notifySilentChest(); public IAnySilentContainer getAnySilentContainer();
/** /**
* Check the configuration value for whether or not OpenInv displays a notification to the user * Gets an ISpecialEnderChest for the given Player. Returns null if the ISpecialEnderChest could
* when a container is activated with AnyChest. * not be instantiated.
* *
* @return true unless configured otherwise * @deprecated Use {@link IOpenInv#getSpecialEnderChest(Player, boolean)}
* @param player the Player
* @param online true if the Player is currently online
* @return the ISpecialEnderChest
* @throws IllegalStateException if the server version is unsupported
*/ */
public boolean notifyAnyChest(); @Deprecated
@Nullable
public ISpecialEnderChest getEnderChest(Player player, boolean online);
/** /**
* Gets a player's SilentChest setting. * Gets an ISpecialPlayerInventory for the given Player. Returns null if the
* * ISpecialPlayerInventory could not be instantiated.
* @param player the OfflinePlayer *
* @return true if SilentChest is enabled * @deprecated Use {@link IOpenInv#getSpecialInventory(Player, boolean)}
* @param player the Player
* @param online true if the Player is currently online
* @return the ISpecialPlayerInventory
* @throws IllegalStateException if the server version is unsupported
*/ */
public boolean getPlayerSilentChestStatus(OfflinePlayer player); @Deprecated
@Nullable
public ISpecialPlayerInventory getInventory(Player player, boolean online);
/** /**
* Sets a player's SilentChest setting. * Gets the active IInventoryAccess implementation. May return null if the server version is
* * unsupported.
* @param player the OfflinePlayer *
* @param status the status * @return the IInventoryAccess
* @throws IllegalStateException if the server version is unsupported
*/ */
public void setPlayerSilentChestStatus(OfflinePlayer player, boolean status); public IInventoryAccess getInventoryAccess();
/** /**
* Gets the provided player's AnyChest setting. * Gets the provided player's AnyChest setting.
* *
* @param player the OfflinePlayer * @param player the OfflinePlayer
* @return true if AnyChest is enabled * @return true if AnyChest is enabled
* @throws IllegalStateException if the server version is unsupported
*/ */
public boolean getPlayerAnyChestStatus(OfflinePlayer player); public boolean getPlayerAnyChestStatus(OfflinePlayer player);
/**
* Sets a player's AnyChest setting.
*
* @param player the OfflinePlayer
* @param status the status
*/
public void setPlayerAnyChestStatus(OfflinePlayer player, boolean status);
/** /**
* Gets a unique identifier by which the OfflinePlayer can be referenced. Using the value * Gets a unique identifier by which the OfflinePlayer can be referenced. Using the value
* returned to look up a Player will generally be much faster for later implementations. * returned to look up a Player will generally be much faster for later implementations.
* *
* @param offline the OfflinePlayer * @param offline the OfflinePlayer
* @return the identifier * @return the identifier
* @throws IllegalStateException if the server version is unsupported
*/ */
public String getPlayerID(OfflinePlayer offline); public String getPlayerID(OfflinePlayer offline);
/**
* Gets a player's SilentChest setting.
*
* @param player the OfflinePlayer
* @return true if SilentChest is enabled
* @throws IllegalStateException if the server version is unsupported
*/
public boolean getPlayerSilentChestStatus(OfflinePlayer player);
/**
* Gets an ISpecialEnderChest for the given Player.
*
* @param player the Player
* @param online true if the Player is currently online
* @return the ISpecialEnderChest
* @throws IllegalStateException if the server version is unsupported
* @throws InstantiationException if the ISpecialEnderChest could not be instantiated
*/
public ISpecialEnderChest getSpecialEnderChest(Player player, boolean online) throws InstantiationException;
/**
* Gets an ISpecialPlayerInventory for the given Player.
*
* @param player the Player
* @param online true if the Player is currently online
* @return the ISpecialPlayerInventory
* @throws IllegalStateException if the server version is unsupported
* @throws InstantiationException if the ISpecialPlayerInventory could not be instantiated
*/
public ISpecialPlayerInventory getSpecialInventory(Player player, boolean online) throws InstantiationException;
/**
* Checks if the server version is supported by OpenInv.
*
* @return true if the server version is supported
*/
public boolean isSupportedVersion();
/**
* Load a Player from an OfflinePlayer. May return null under some circumstances.
*
* @param offline the OfflinePlayer to load a Player for
* @return the Player, or null
* @throws IllegalStateException if the server version is unsupported
*/
@Nullable
public Player loadPlayer(final OfflinePlayer offline);
/** /**
* Get an OfflinePlayer by name. * Get an OfflinePlayer by name.
* <p> * <p>
* Note: This method is potentially very heavily blocking. It should not ever be called on the * Note: This method is potentially very heavily blocking. It should not ever be called on the
* main thread, and if it is, a stack trace will be displayed alerting server owners to the * main thread, and if it is, a stack trace will be displayed alerting server owners to the
* call. * call.
* *
* @param name the name of the Player * @param name the name of the Player
* @return the OfflinePlayer with the closest matching name or null if no players have ever logged in * @return the OfflinePlayer with the closest matching name or null if no players have ever logged in
*/ */
@Nullable
public OfflinePlayer matchPlayer(String name); public OfflinePlayer matchPlayer(String name);
/** /**
* Load a Player from an OfflinePlayer. May return null under some circumstances. * Check the configuration value for whether or not OpenInv displays a notification to the user
* * when a container is activated with AnyChest.
* @param offline the OfflinePlayer to load a Player for *
* @return the Player * @return true unless configured otherwise
*/ */
public Player loadPlayer(final OfflinePlayer offline); public boolean notifyAnyChest();
/**
* Check the configuration value for whether or not OpenInv displays a notification to the user
* when a container is activated with SilentChest.
*
* @return true unless configured otherwise
*/
public boolean notifySilentChest();
/**
* Mark a Player as no longer in use by a Plugin to allow OpenInv to remove it from the cache
* when eligible.
*
* @param player the Player
* @param plugin the Plugin no longer holding a reference to the Player
* @throws IllegalStateException if the server version is unsupported
*/
public void releasePlayer(Player player, Plugin plugin);
/** /**
* Mark a Player as in use by a Plugin to prevent it from being removed from the cache. Used to * Mark a Player as in use by a Plugin to prevent it from being removed from the cache. Used to
@ -169,19 +198,37 @@ public interface IOpenInv {
* {@link #disableSaving()} returns false. If you are making changes that OpenInv does not cause * {@link #disableSaving()} returns false. If you are making changes that OpenInv does not cause
* to persist when a Player logs in as noted above, it is suggested that you manually call * to persist when a Player logs in as noted above, it is suggested that you manually call
* {@link Player#saveData()} when releasing your reference to ensure your changes persist. * {@link Player#saveData()} when releasing your reference to ensure your changes persist.
* *
* @param player the Player * @param player the Player
* @param plugin the Plugin holding the reference to the Player * @param plugin the Plugin holding the reference to the Player
* @throws IllegalStateException if the server version is unsupported
*/ */
public void retainPlayer(Player player, Plugin plugin); public void retainPlayer(Player player, Plugin plugin);
/** /**
* Mark a Player as no longer in use by a Plugin to allow OpenInv to remove it from the cache * Sets a player's AnyChest setting.
* when eligible. *
* * @param player the OfflinePlayer
* @param player the Player * @param status the status
* @param plugin the Plugin no longer holding a reference to the Player * @throws IllegalStateException if the server version is unsupported
*/ */
public void releasePlayer(Player player, Plugin plugin); public void setPlayerAnyChestStatus(OfflinePlayer player, boolean status);
/**
* Sets a player's SilentChest setting.
*
* @param player the OfflinePlayer
* @param status the status
* @throws IllegalStateException if the server version is unsupported
*/
public void setPlayerSilentChestStatus(OfflinePlayer player, boolean status);
/**
* Forcibly unload a cached Player's data.
*
* @param player the OfflinePlayer to unload
* @throws IllegalStateException if the server version is unsupported
*/
public void unload(OfflinePlayer player);
} }

View file

@ -1,57 +1,61 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2014 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.lishid.openinv.internal; package com.lishid.openinv.internal;
import javax.annotation.Nullable;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
public interface IInventoryAccess { public interface IInventoryAccess {
/** /**
* Check if an Inventory is an ISpecialPlayerInventory implementation. * Gets an ISpecialEnderChest from an Inventory or null if the Inventory is not backed by an
* * ISpecialEnderChest.
*
* @param inventory the Inventory * @param inventory the Inventory
* @return true if the Inventory is backed by an ISpecialPlayerInventory * @return the ISpecialEnderChest or null
*/ */
public boolean isSpecialPlayerInventory(Inventory inventory); @Nullable
public ISpecialEnderChest getSpecialEnderChest(Inventory inventory);
/** /**
* Gets an ISpecialPlayerInventory from an Inventory or null if the Inventory is not backed by * Gets an ISpecialPlayerInventory from an Inventory or null if the Inventory is not backed by
* an ISpecialPlayerInventory. * an ISpecialPlayerInventory.
* *
* @param inventory the Inventory * @param inventory the Inventory
* @return the ISpecialPlayerInventory or null * @return the ISpecialPlayerInventory or null
*/ */
@Nullable
public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory); public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory);
/** /**
* Check if an Inventory is an ISpecialEnderChest implementation. * Check if an Inventory is an ISpecialEnderChest implementation.
* *
* @param inventory the Inventory * @param inventory the Inventory
* @return true if the Inventory is backed by an ISpecialEnderChest * @return true if the Inventory is backed by an ISpecialEnderChest
*/ */
public boolean isSpecialEnderChest(Inventory inventory); public boolean isSpecialEnderChest(Inventory inventory);
/** /**
* Gets an ISpecialEnderChest from an Inventory or null if the Inventory is not backed by an * Check if an Inventory is an ISpecialPlayerInventory implementation.
* ISpecialEnderChest. *
*
* @param inventory the Inventory * @param inventory the Inventory
* @return the ISpecialEnderChest or null * @return true if the Inventory is backed by an ISpecialPlayerInventory
*/ */
public ISpecialEnderChest getSpecialEnderChest(Inventory inventory); public boolean isSpecialPlayerInventory(Inventory inventory);
} }

View file

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvparent</artifactId> <artifactId>openinvparent</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</parent> </parent>
<artifactId>openinvassembly</artifactId> <artifactId>openinvassembly</artifactId>

View file

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvparent</artifactId> <artifactId>openinvparent</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</parent> </parent>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
@ -22,7 +22,7 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvapi</artifactId> <artifactId>openinvapi</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -1,15 +1,15 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2014 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@ -18,6 +18,7 @@ package com.lishid.openinv.util;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import com.lishid.openinv.internal.IAnySilentContainer; import com.lishid.openinv.internal.IAnySilentContainer;
import com.lishid.openinv.internal.IInventoryAccess; import com.lishid.openinv.internal.IInventoryAccess;
@ -30,144 +31,8 @@ import org.bukkit.plugin.Plugin;
public class InternalAccessor { public class InternalAccessor {
private final Plugin plugin; public static <T> T grabFieldOfTypeFromObject(final Class<T> type, final Object object) {
// Use reflection to find the IInventory
private final String version;
private boolean supported = false;
public InternalAccessor(Plugin plugin) {
this.plugin = plugin;
String packageName = plugin.getServer().getClass().getPackage().getName();
version = packageName.substring(packageName.lastIndexOf('.') + 1);
try {
Class.forName("com.lishid.openinv.internal." + version + ".PlayerDataManager");
supported = true;
} catch (Exception e) {}
}
/**
* Gets the server implementation version. If not initialized, returns the string "null"
* instead.
*
* @return the version, or "null"
*/
public String getVersion() {
return this.version != null ? this.version : "null";
}
/**
* Checks if the server implementation is supported.
*
* @return true if initialized for a supported server version
*/
public boolean isSupported() {
return this.supported;
}
/**
* Creates an instance of the IPlayerDataManager implementation for the current server version,
* or null if unsupported.
*
* @return the IPlayerDataManager
*/
public IPlayerDataManager newPlayerDataManager() {
return createObject(IPlayerDataManager.class, "PlayerDataManager");
}
/**
* Creates an instance of the IInventoryAccess implementation for the current server version, or
* null if unsupported.
*
* @return the IInventoryAccess
*/
public IInventoryAccess newInventoryAccess() {
return createObject(IInventoryAccess.class, "InventoryAccess");
}
/**
* Creates an instance of the IAnySilentContainer implementation for the current server version,
* or null if unsupported.
*
* @return the IAnySilentContainer
*/
public IAnySilentContainer newAnySilentContainer() {
return createObject(IAnySilentContainer.class, "AnySilentContainer");
}
/**
* Creates an instance of the ISpecialPlayerInventory implementation for the given Player, or
* null if the current version is unsupported.
*
* @param player the Player
* @param online true if the Player is online
* @return the ISpecialPlayerInventory created
*/
public ISpecialPlayerInventory newSpecialPlayerInventory(Player player, boolean online) {
return createObject(ISpecialPlayerInventory.class, "SpecialPlayerInventory", player, online);
}
/**
* Creates an instance of the ISpecialEnderChest implementation for the given Player, or
* null if the current version is unsupported.
*
* @param player the Player
* @param online true if the Player is online
* @return the ISpecialEnderChest created
*/
public ISpecialEnderChest newSpecialEnderChest(Player player, boolean online) {
return createObject(ISpecialEnderChest.class, "SpecialEnderChest", player, online);
}
private <T> T createObject(Class<? extends T> assignableClass, String className, Object... params) {
try {
// Check if internal versioned class exists
Class<?> internalClass = Class.forName("com.lishid.openinv.internal." + version + "." + className);
if (!assignableClass.isAssignableFrom(internalClass)) {
plugin.getLogger().warning("Found class " + internalClass.getName() + " but cannot cast to " + assignableClass.getName());
return null;
}
// Quick return: no parameters, no need to fiddle about finding the correct constructor.
if (params.length == 0) {
return assignableClass.cast(internalClass.getConstructor().newInstance());
}
// Search constructors for one matching the given parameters
nextConstructor: for (Constructor<?> constructor : internalClass.getConstructors()) {
Class<?>[] requiredClasses = constructor.getParameterTypes();
if (requiredClasses.length != params.length) {
continue;
}
for (int i = 0; i < params.length; ++i) {
if (!requiredClasses[i].isAssignableFrom(params[i].getClass())) {
continue nextConstructor;
}
}
return assignableClass.cast(constructor.newInstance(params));
}
StringBuilder message = new StringBuilder("Found class ").append(internalClass.getName())
.append(" but cannot find any matching constructors for [");
for (Object object : params) {
message.append(object.getClass().getName()).append(", ");
}
if (params.length > 0) {
message.delete(message.length() - 2, message.length());
}
plugin.getLogger().warning(message.append(']').toString());
} catch (Exception e) {
plugin.getLogger().warning("OpenInv encountered an error with the CraftBukkit version \"" + version + "\". Please look for an updated version of OpenInv.");
e.printStackTrace();
}
return null;
}
public static <T> T grabFieldOfTypeFromObject(Class<T> type, Object object) {
// Use reflection to find the iinventory
Class<?> clazz = object.getClass(); Class<?> clazz = object.getClass();
T result = null; T result = null;
for (Field f : clazz.getDeclaredFields()) { for (Field f : clazz.getDeclaredFields()) {
@ -183,4 +48,171 @@ public class InternalAccessor {
return result; return result;
} }
private final Plugin plugin;
private final String version;
private boolean supported = false;
private IPlayerDataManager playerDataManager;
private IInventoryAccess inventoryAccess;
private IAnySilentContainer anySilentContainer;
public InternalAccessor(final Plugin plugin) {
this.plugin = plugin;
String packageName = plugin.getServer().getClass().getPackage().getName();
this.version = packageName.substring(packageName.lastIndexOf('.') + 1);
try {
Class.forName("com.lishid.openinv.internal." + this.version + ".SpecialPlayerInventory");
Class.forName("com.lishid.openinv.internal." + this.version + ".SpecialEnderChest");
this.playerDataManager = this.createObject(IPlayerDataManager.class, "PlayerDataManager");
this.inventoryAccess = this.createObject(IInventoryAccess.class, "InventoryAccess");
this.anySilentContainer = this.createObject(IAnySilentContainer.class, "AnySilentContainer");
this.supported = true;
} catch (Exception e) {}
}
private <T> T createObject(final Class<? extends T> assignableClass, final String className,
final Object... params) throws ClassCastException, ClassNotFoundException,
InstantiationException, IllegalAccessException, IllegalArgumentException,
InvocationTargetException, NoSuchMethodException, SecurityException {
// Fetch internal class if it exists.
Class<?> internalClass = Class.forName("com.lishid.openinv.internal." + this.version + "." + className);
if (!assignableClass.isAssignableFrom(internalClass)) {
String message = String.format("Found class %s but cannot cast to %s!", internalClass.getName(), assignableClass.getName());
this.plugin.getLogger().warning(message);
throw new IllegalStateException(message);
}
// Quick return: no parameters, no need to fiddle about finding the correct constructor.
if (params.length == 0) {
return assignableClass.cast(internalClass.getConstructor().newInstance());
}
// Search constructors for one matching the given parameters
nextConstructor: for (Constructor<?> constructor : internalClass.getConstructors()) {
Class<?>[] requiredClasses = constructor.getParameterTypes();
if (requiredClasses.length != params.length) {
continue;
}
for (int i = 0; i < params.length; ++i) {
if (!requiredClasses[i].isAssignableFrom(params[i].getClass())) {
continue nextConstructor;
}
}
return assignableClass.cast(constructor.newInstance(params));
}
StringBuilder builder = new StringBuilder("Found class ").append(internalClass.getName())
.append(" but cannot find any matching constructors for [");
for (Object object : params) {
builder.append(object.getClass().getName()).append(", ");
}
if (params.length > 0) {
builder.delete(builder.length() - 2, builder.length());
}
String message = builder.append(']').toString();
this.plugin.getLogger().warning(message);
throw new IllegalArgumentException(message);
}
/**
* Creates an instance of the IAnySilentContainer implementation for the current server version.
*
* @return the IAnySilentContainer
* @throws IllegalStateException if server version is unsupported
*/
public IAnySilentContainer getAnySilentContainer() {
if (!this.supported) {
throw new IllegalStateException(String.format("Unsupported server version %s!", this.version));
}
return this.anySilentContainer;
}
/**
* Creates an instance of the IInventoryAccess implementation for the current server version.
*
* @return the IInventoryAccess
* @throws IllegalStateException if server version is unsupported
*/
public IInventoryAccess getInventoryAccess() {
if (!this.supported) {
throw new IllegalStateException(String.format("Unsupported server version %s!", this.version));
}
return this.inventoryAccess;
}
/**
* Creates an instance of the IPlayerDataManager implementation for the current server version.
*
* @return the IPlayerDataManager
* @throws IllegalStateException if server version is unsupported
*/
public IPlayerDataManager getPlayerDataManager() {
if (!this.supported) {
throw new IllegalStateException(String.format("Unsupported server version %s!", this.version));
}
return this.playerDataManager;
}
/**
* Gets the server implementation version. If not initialized, returns the string "null"
* instead.
*
* @return the version, or "null"
*/
public String getVersion() {
return this.version != null ? this.version : "null";
}
/**
* Checks if the server implementation is supported.
*
* @return true if initialized for a supported server version
*/
public boolean isSupported() {
return this.supported;
}
/**
* Creates an instance of the ISpecialEnderChest implementation for the given Player, or
* null if the current version is unsupported.
*
* @param player the Player
* @param online true if the Player is online
* @return the ISpecialEnderChest created
* @throws InstantiationException if the ISpecialEnderChest could not be instantiated
*/
public ISpecialEnderChest newSpecialEnderChest(final Player player, final boolean online) throws InstantiationException {
if (!this.supported) {
throw new IllegalStateException(String.format("Unsupported server version %s!", this.version));
}
try {
return this.createObject(ISpecialEnderChest.class, "SpecialEnderChest", player, online);
} catch (Exception e) {
throw new InstantiationException(String.format("Unable to create a new ISpecialEnderChest: %s", e.getMessage()));
}
}
/**
* Creates an instance of the ISpecialPlayerInventory implementation for the given Player..
*
* @param player the Player
* @param online true if the Player is online
* @return the ISpecialPlayerInventory created
* @throws InstantiationException if the ISpecialPlayerInventory could not be instantiated
*/
public ISpecialPlayerInventory newSpecialPlayerInventory(final Player player, final boolean online) throws InstantiationException {
if (!this.supported) {
throw new IllegalStateException(String.format("Unsupported server version %s!", this.version));
}
try {
return this.createObject(ISpecialPlayerInventory.class, "SpecialPlayerInventory", player, online);
} catch (Exception e) {
throw new InstantiationException(String.format("Unable to create a new ISpecialPlayerInventory: %s", e.getMessage()));
}
}
} }

View file

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId> <artifactId>openinvinternal</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</parent> </parent>
<artifactId>openinvadapter1_4_5</artifactId> <artifactId>openinvadapter1_4_5</artifactId>
@ -21,7 +21,7 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId> <artifactId>openinvinternal</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</parent> </parent>
<artifactId>openinvadapter1_4_6</artifactId> <artifactId>openinvadapter1_4_6</artifactId>
@ -21,7 +21,7 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvparent</artifactId> <artifactId>openinvparent</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</parent> </parent>
<artifactId>openinvinternal</artifactId> <artifactId>openinvinternal</artifactId>

View file

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId> <artifactId>openinvinternal</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</parent> </parent>
<artifactId>openinvadapter1_10_R1</artifactId> <artifactId>openinvadapter1_10_R1</artifactId>
@ -21,7 +21,7 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId> <artifactId>openinvinternal</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</parent> </parent>
<artifactId>openinvadapter1_11_R1</artifactId> <artifactId>openinvadapter1_11_R1</artifactId>
@ -21,7 +21,7 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId> <artifactId>openinvinternal</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</parent> </parent>
<artifactId>openinvadapter1_12_R1</artifactId> <artifactId>openinvadapter1_12_R1</artifactId>
@ -21,7 +21,7 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId> <artifactId>openinvinternal</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</parent> </parent>
<artifactId>openinvadapter1_4_R1</artifactId> <artifactId>openinvadapter1_4_R1</artifactId>
@ -21,7 +21,7 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId> <artifactId>openinvinternal</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</parent> </parent>
<artifactId>openinvadapter1_5_R2</artifactId> <artifactId>openinvadapter1_5_R2</artifactId>
@ -21,7 +21,7 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId> <artifactId>openinvinternal</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</parent> </parent>
<artifactId>openinvadapter1_5_R3</artifactId> <artifactId>openinvadapter1_5_R3</artifactId>
@ -21,7 +21,7 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId> <artifactId>openinvinternal</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</parent> </parent>
<artifactId>openinvadapter1_6_R1</artifactId> <artifactId>openinvadapter1_6_R1</artifactId>
@ -21,7 +21,7 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId> <artifactId>openinvinternal</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</parent> </parent>
<artifactId>openinvadapter1_6_R2</artifactId> <artifactId>openinvadapter1_6_R2</artifactId>
@ -21,7 +21,7 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId> <artifactId>openinvinternal</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</parent> </parent>
<artifactId>openinvadapter1_6_R3</artifactId> <artifactId>openinvadapter1_6_R3</artifactId>
@ -21,7 +21,7 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId> <artifactId>openinvinternal</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</parent> </parent>
<artifactId>openinvadapter1_7_R1</artifactId> <artifactId>openinvadapter1_7_R1</artifactId>
@ -21,7 +21,7 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId> <artifactId>openinvinternal</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</parent> </parent>
<artifactId>openinvadapter1_7_R2</artifactId> <artifactId>openinvadapter1_7_R2</artifactId>
@ -21,7 +21,7 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId> <artifactId>openinvinternal</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</parent> </parent>
<artifactId>openinvadapter1_7_R3</artifactId> <artifactId>openinvadapter1_7_R3</artifactId>
@ -21,7 +21,7 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId> <artifactId>openinvinternal</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</parent> </parent>
<artifactId>openinvadapter1_7_R4</artifactId> <artifactId>openinvadapter1_7_R4</artifactId>
@ -27,7 +27,7 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId> <artifactId>openinvinternal</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</parent> </parent>
<artifactId>openinvadapter1_8_R1</artifactId> <artifactId>openinvadapter1_8_R1</artifactId>
@ -21,7 +21,7 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId> <artifactId>openinvinternal</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</parent> </parent>
<artifactId>openinvadapter1_8_R2</artifactId> <artifactId>openinvadapter1_8_R2</artifactId>
@ -21,7 +21,7 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId> <artifactId>openinvinternal</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</parent> </parent>
<artifactId>openinvadapter1_8_R3</artifactId> <artifactId>openinvadapter1_8_R3</artifactId>
@ -21,7 +21,7 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId> <artifactId>openinvinternal</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</parent> </parent>
<artifactId>openinvadapter1_9_R1</artifactId> <artifactId>openinvadapter1_9_R1</artifactId>
@ -21,7 +21,7 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View file

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId> <artifactId>openinvinternal</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</parent> </parent>
<artifactId>openinvadapter1_9_R2</artifactId> <artifactId>openinvadapter1_9_R2</artifactId>
@ -21,7 +21,7 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvplugin</artifactId> <artifactId>openinvplugin</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</parent> </parent>
<artifactId>openinvplugincore</artifactId> <artifactId>openinvplugincore</artifactId>
@ -22,12 +22,12 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvpluginv1_10_r1</artifactId> <artifactId>openinvpluginv1_10_r1</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -28,6 +28,8 @@ import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import javax.annotation.Nullable;
import com.lishid.openinv.commands.AnyChestPluginCommand; import com.lishid.openinv.commands.AnyChestPluginCommand;
import com.lishid.openinv.commands.OpenEnderPluginCommand; import com.lishid.openinv.commands.OpenEnderPluginCommand;
import com.lishid.openinv.commands.OpenInvPluginCommand; import com.lishid.openinv.commands.OpenInvPluginCommand;
@ -36,7 +38,6 @@ import com.lishid.openinv.commands.SearchInvPluginCommand;
import com.lishid.openinv.commands.SilentChestPluginCommand; import com.lishid.openinv.commands.SilentChestPluginCommand;
import com.lishid.openinv.internal.IAnySilentContainer; import com.lishid.openinv.internal.IAnySilentContainer;
import com.lishid.openinv.internal.IInventoryAccess; import com.lishid.openinv.internal.IInventoryAccess;
import com.lishid.openinv.internal.IPlayerDataManager;
import com.lishid.openinv.internal.ISpecialEnderChest; import com.lishid.openinv.internal.ISpecialEnderChest;
import com.lishid.openinv.internal.ISpecialPlayerInventory; import com.lishid.openinv.internal.ISpecialPlayerInventory;
import com.lishid.openinv.listeners.InventoryClickListener; import com.lishid.openinv.listeners.InventoryClickListener;
@ -78,7 +79,7 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
new Function<Player>() { new Function<Player>() {
@Override @Override
public boolean run(final Player value) { public boolean run(final Player value) {
String key = OpenInv.this.playerLoader.getPlayerDataID(value); String key = OpenInv.this.accessor.getPlayerDataManager().getPlayerDataID(value);
return OpenInv.this.inventories.containsKey(key) return OpenInv.this.inventories.containsKey(key)
&& OpenInv.this.inventories.get(key).isInUse() && OpenInv.this.inventories.get(key).isInUse()
|| OpenInv.this.enderChests.containsKey(key) || OpenInv.this.enderChests.containsKey(key)
@ -88,7 +89,7 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
}, new Function<Player>() { }, new Function<Player>() {
@Override @Override
public boolean run(final Player value) { public boolean run(final Player value) {
String key = OpenInv.this.playerLoader.getPlayerDataID(value); String key = OpenInv.this.accessor.getPlayerDataManager().getPlayerDataID(value);
// Check if inventory is stored, and if it is, remove it and eject all viewers // Check if inventory is stored, and if it is, remove it and eject all viewers
if (OpenInv.this.inventories.containsKey(key)) { if (OpenInv.this.inventories.containsKey(key)) {
@ -114,9 +115,6 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
}); });
private InternalAccessor accessor; private InternalAccessor accessor;
private IPlayerDataManager playerLoader;
private IInventoryAccess inventoryAccess;
private IAnySilentContainer anySilentContainer;
/** /**
* Evicts all viewers lacking cross-world permissions from a Player's inventory. * Evicts all viewers lacking cross-world permissions from a Player's inventory.
@ -125,7 +123,7 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
*/ */
public void changeWorld(final Player player) { public void changeWorld(final Player player) {
String key = this.playerLoader.getPlayerDataID(player); String key = this.accessor.getPlayerDataManager().getPlayerDataID(player);
// Check if the player is cached. If not, neither of their inventories is open. // Check if the player is cached. If not, neither of their inventories is open.
if (!this.playerCache.containsKey(key)) { if (!this.playerCache.containsKey(key)) {
@ -159,77 +157,41 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
} }
} }
/**
* Check the configuration value for whether or not OpenInv saves player data when unloading
* players. This is exclusively for users who do not allow editing of inventories, only viewing,
* and wish to prevent any possibility of bugs such as lishid#40. If true, OpenInv will not ever
* save any edits made to players.
*
* @return false unless configured otherwise
*/
@Override @Override
public boolean disableSaving() { public boolean disableSaving() {
return this.getConfig().getBoolean("settings.disable-saving", false); return this.getConfig().getBoolean("settings.disable-saving", false);
} }
/**
* Gets the active ISilentContainer implementation. May return null if the server version is
* unsupported.
*
* @return the ISilentContainer
*/
@Override @Override
public IAnySilentContainer getAnySilentContainer() { public IAnySilentContainer getAnySilentContainer() {
return this.anySilentContainer; return this.accessor.getAnySilentContainer();
} }
/** @Deprecated
* Gets an ISpecialEnderChest for the given Player.
*
* @param player the Player
* @param online true if the Player is currently online
* @return the ISpecialEnderChest
*/
@Override @Override
public ISpecialEnderChest getEnderChest(final Player player, final boolean online) { public ISpecialEnderChest getEnderChest(final Player player, final boolean online) {
String id = this.playerLoader.getPlayerDataID(player); try {
if (this.enderChests.containsKey(id)) { return this.getSpecialEnderChest(player, online);
return this.enderChests.get(id); } catch (InstantiationException e) {
e.printStackTrace();
return null;
} }
ISpecialEnderChest inv = this.accessor.newSpecialEnderChest(player, online);
this.enderChests.put(id, inv);
this.playerCache.put(id, player);
return inv;
} }
/** @Deprecated
* Gets an ISpecialPlayerInventory for the given Player.
*
* @param player the Player
* @param online true if the Player is currently online
* @return the ISpecialPlayerInventory
*/
@Override @Override
public ISpecialPlayerInventory getInventory(final Player player, final boolean online) { public ISpecialPlayerInventory getInventory(final Player player, final boolean online) {
String id = this.playerLoader.getPlayerDataID(player); try {
if (this.inventories.containsKey(id)) { return this.getSpecialInventory(player, online);
return this.inventories.get(id); } catch (InstantiationException e) {
e.printStackTrace();
return null;
} }
ISpecialPlayerInventory inv = this.accessor.newSpecialPlayerInventory(player, online);
this.inventories.put(id, inv);
this.playerCache.put(id, player);
return inv;
} }
/**
* Gets the active IInventoryAccess implementation. May return null if the server version is
* unsupported.
*
* @return the IInventoryAccess
*/
@Override @Override
public IInventoryAccess getInventoryAccess() { public IInventoryAccess getInventoryAccess() {
return this.inventoryAccess; return this.accessor.getInventoryAccess();
} }
private int getLevenshteinDistance(final String string1, final String string2) { private int getLevenshteinDistance(final String string1, final String string2) {
@ -279,8 +241,8 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Collection<? extends Player> getOnlinePlayers() { public Collection<? extends Player> getOnlinePlayers() {
if (this.playerLoader != null) { if (this.accessor.isSupported()) {
return this.playerLoader.getOnlinePlayers(); return this.accessor.getPlayerDataManager().getOnlinePlayers();
} }
Method getOnlinePlayers; Method getOnlinePlayers;
@ -306,56 +268,53 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
return Arrays.asList((Player[]) onlinePlayers); return Arrays.asList((Player[]) onlinePlayers);
} }
/**
* Gets the provided player's AnyChest setting.
*
* @param player the OfflinePlayer
* @return true if AnyChest is enabled
*/
@Override @Override
public boolean getPlayerAnyChestStatus(final OfflinePlayer player) { public boolean getPlayerAnyChestStatus(final OfflinePlayer player) {
return this.getConfig().getBoolean("toggles.any-chest." + this.playerLoader.getPlayerDataID(player), false); return this.getConfig().getBoolean("toggles.any-chest." + this.accessor.getPlayerDataManager().getPlayerDataID(player), false);
} }
/**
* Gets a unique identifier by which the OfflinePlayer can be referenced. Using the value
* returned to look up a Player will generally be much faster for later implementations.
*
* @param offline the OfflinePlayer
* @return the identifier
*/
@Override @Override
public String getPlayerID(final OfflinePlayer offline) { public String getPlayerID(final OfflinePlayer offline) {
return this.playerLoader.getPlayerDataID(offline); return this.accessor.getPlayerDataManager().getPlayerDataID(offline);
} }
/**
* Gets a player's SilentChest setting.
*
* @param player the OfflinePlayer
* @return true if SilentChest is enabled
*/
@Override @Override
public boolean getPlayerSilentChestStatus(final OfflinePlayer player) { public boolean getPlayerSilentChestStatus(final OfflinePlayer player) {
return this.getConfig().getBoolean("toggles.silent-chest." + this.playerLoader.getPlayerDataID(player), false); return this.getConfig().getBoolean("toggles.silent-chest." + this.accessor.getPlayerDataManager().getPlayerDataID(player), false);
}
@Override
public ISpecialEnderChest getSpecialEnderChest(final Player player, final boolean online)
throws InstantiationException {
String id = this.accessor.getPlayerDataManager().getPlayerDataID(player);
if (this.enderChests.containsKey(id)) {
return this.enderChests.get(id);
}
ISpecialEnderChest inv = this.accessor.newSpecialEnderChest(player, online);
this.enderChests.put(id, inv);
this.playerCache.put(id, player);
return inv;
}
@Override
public ISpecialPlayerInventory getSpecialInventory(final Player player, final boolean online)
throws InstantiationException {
String id = this.accessor.getPlayerDataManager().getPlayerDataID(player);
if (this.inventories.containsKey(id)) {
return this.inventories.get(id);
}
ISpecialPlayerInventory inv = this.accessor.newSpecialPlayerInventory(player, online);
this.inventories.put(id, inv);
this.playerCache.put(id, player);
return inv;
} }
/**
* Checks if the server version is supported by OpenInv.
*
* @return true if the server version is supported
*/
@Override @Override
public boolean isSupportedVersion() { public boolean isSupportedVersion() {
return this.accessor != null && this.accessor.isSupported(); return this.accessor != null && this.accessor.isSupported();
} }
/** @Nullable
* Load a Player from an OfflinePlayer. May return null under some circumstances.
*
* @param offline the OfflinePlayer to load a Player for
* @return the Player
*/
@Override @Override
public Player loadPlayer(final OfflinePlayer offline) { public Player loadPlayer(final OfflinePlayer offline) {
@ -363,7 +322,7 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
return null; return null;
} }
String key = this.playerLoader.getPlayerDataID(offline); String key = this.accessor.getPlayerDataManager().getPlayerDataID(offline);
if (this.playerCache.containsKey(key)) { if (this.playerCache.containsKey(key)) {
return this.playerCache.get(key); return this.playerCache.get(key);
} }
@ -377,15 +336,19 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
return loaded; return loaded;
} }
if (!this.isSupportedVersion()) {
return null;
}
if (Bukkit.isPrimaryThread()) { if (Bukkit.isPrimaryThread()) {
return this.playerLoader.loadPlayer(offline); return this.accessor.getPlayerDataManager().loadPlayer(offline);
} }
Future<Player> future = Bukkit.getScheduler().callSyncMethod(this, Future<Player> future = Bukkit.getScheduler().callSyncMethod(this,
new Callable<Player>() { new Callable<Player>() {
@Override @Override
public Player call() throws Exception { public Player call() throws Exception {
return OpenInv.this.playerLoader.loadPlayer(offline); return OpenInv.this.accessor.getPlayerDataManager().loadPlayer(offline);
} }
}); });
@ -421,16 +384,7 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
return loaded; return loaded;
} }
/** @Nullable
* Get an OfflinePlayer by name.
* <p>
* Note: This method is potentially very heavily blocking. It should not ever be called on the
* main thread, and if it is, a stack trace will be displayed alerting server owners to the
* call.
*
* @param name the name of the Player
* @return the OfflinePlayer with the closest matching name or null if no players have ever logged in
*/
@Override @Override
public OfflinePlayer matchPlayer(final String name) { public OfflinePlayer matchPlayer(final String name) {
@ -444,11 +398,15 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
} }
} }
// Attempt exact offline match first - adds UUID support for later versions OfflinePlayer player;
OfflinePlayer player = this.playerLoader.getPlayerByID(name);
if (player != null) { if (this.isSupportedVersion()) {
return player; // Attempt exact offline match first - adds UUID support for later versions
player = this.accessor.getPlayerDataManager().getPlayerByID(name);
if (player != null) {
return player;
}
} }
// Ensure name is valid if server is in online mode to avoid unnecessary searching // Ensure name is valid if server is in online mode to avoid unnecessary searching
@ -503,23 +461,11 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
return player; return player;
} }
/**
* Check the configuration value for whether or not OpenInv displays a notification to the user
* when a container is activated with AnyChest.
*
* @return true unless configured otherwise
*/
@Override @Override
public boolean notifyAnyChest() { public boolean notifyAnyChest() {
return this.getConfig().getBoolean("notify.any-chest", true); return this.getConfig().getBoolean("notify.any-chest", true);
} }
/**
* Check the configuration value for whether or not OpenInv displays a notification to the user
* when a container is activated with SilentChest.
*
* @return true unless configured otherwise
*/
@Override @Override
public boolean notifySilentChest() { public boolean notifySilentChest() {
return this.getConfig().getBoolean("notify.silent-chest", true); return this.getConfig().getBoolean("notify.silent-chest", true);
@ -532,7 +478,9 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
return; return;
} }
this.playerCache.invalidateAll(); if (this.isSupportedVersion()) {
this.playerCache.invalidateAll();
}
} }
@Override @Override
@ -550,10 +498,6 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
return; return;
} }
this.playerLoader = this.accessor.newPlayerDataManager();
this.inventoryAccess = this.accessor.newInventoryAccess();
this.anySilentContainer = this.accessor.newAnySilentContainer();
new ConfigUpdater(this).checkForUpdates(); new ConfigUpdater(this).checkForUpdates();
// Register listeners // Register listeners
@ -575,21 +519,13 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
} }
/**
* Unmark any Players in use by the specified Plugin.
*
* @param plugin
*/
public void releaseAllPlayers(final Plugin plugin) { public void releaseAllPlayers(final Plugin plugin) {
this.pluginUsage.removeAll(plugin.getClass()); this.pluginUsage.removeAll(plugin.getClass());
} }
/**
* @see com.lishid.openinv.IOpenInv#releasePlayer(org.bukkit.entity.Player, org.bukkit.plugin.Plugin)
*/
@Override @Override
public void releasePlayer(final Player player, final Plugin plugin) { public void releasePlayer(final Player player, final Plugin plugin) {
String key = this.playerLoader.getPlayerDataID(player); String key = this.accessor.getPlayerDataManager().getPlayerDataID(player);
if (!this.pluginUsage.containsEntry(key, plugin.getClass())) { if (!this.pluginUsage.containsEntry(key, plugin.getClass())) {
return; return;
@ -598,12 +534,9 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
this.pluginUsage.remove(key, plugin.getClass()); this.pluginUsage.remove(key, plugin.getClass());
} }
/**
* @see com.lishid.openinv.IOpenInv#retainPlayer(org.bukkit.entity.Player, org.bukkit.plugin.Plugin)
*/
@Override @Override
public void retainPlayer(final Player player, final Plugin plugin) { public void retainPlayer(final Player player, final Plugin plugin) {
String key = this.playerLoader.getPlayerDataID(player); String key = this.accessor.getPlayerDataManager().getPlayerDataID(player);
if (this.pluginUsage.containsEntry(key, plugin.getClass())) { if (this.pluginUsage.containsEntry(key, plugin.getClass())) {
return; return;
@ -612,15 +545,9 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
this.pluginUsage.put(key, plugin.getClass()); this.pluginUsage.put(key, plugin.getClass());
} }
/**
* Sets a player's AnyChest setting.
*
* @param player the OfflinePlayer
* @param status the status
*/
@Override @Override
public void setPlayerAnyChestStatus(final OfflinePlayer player, final boolean status) { public void setPlayerAnyChestStatus(final OfflinePlayer player, final boolean status) {
this.getConfig().set("toggles.any-chest." + this.playerLoader.getPlayerDataID(player), status); this.getConfig().set("toggles.any-chest." + this.accessor.getPlayerDataManager().getPlayerDataID(player), status);
this.saveConfig(); this.saveConfig();
} }
@ -628,10 +555,11 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
* Method for handling a Player going offline. * Method for handling a Player going offline.
* *
* @param player the Player * @param player the Player
* @throws IllegalStateException if the server version is unsupported
*/ */
public void setPlayerOffline(final Player player) { public void setPlayerOffline(final Player player) {
String key = this.playerLoader.getPlayerDataID(player); String key = this.accessor.getPlayerDataManager().getPlayerDataID(player);
// Check if the player is cached. If not, neither of their inventories is open. // Check if the player is cached. If not, neither of their inventories is open.
if (!this.playerCache.containsKey(key)) { if (!this.playerCache.containsKey(key)) {
@ -651,10 +579,11 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
* Method for handling a Player coming online. * Method for handling a Player coming online.
* *
* @param player the Player * @param player the Player
* @throws IllegalStateException if the server version is unsupported
*/ */
public void setPlayerOnline(final Player player) { public void setPlayerOnline(final Player player) {
String key = this.playerLoader.getPlayerDataID(player); String key = this.accessor.getPlayerDataManager().getPlayerDataID(player);
// Check if the player is cached. If not, neither of their inventories is open. // Check if the player is cached. If not, neither of their inventories is open.
if (!this.playerCache.containsKey(key)) { if (!this.playerCache.containsKey(key)) {
@ -681,15 +610,9 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
} }
} }
/**
* Sets a player's SilentChest setting.
*
* @param player the OfflinePlayer
* @param status the status
*/
@Override @Override
public void setPlayerSilentChestStatus(final OfflinePlayer player, final boolean status) { public void setPlayerSilentChestStatus(final OfflinePlayer player, final boolean status) {
this.getConfig().set("toggles.silent-chest." + this.playerLoader.getPlayerDataID(player), status); this.getConfig().set("toggles.silent-chest." + this.accessor.getPlayerDataManager().getPlayerDataID(player), status);
this.saveConfig(); this.saveConfig();
} }
@ -728,14 +651,9 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
} }
} }
/**
* Forcibly unload a cached Player's data.
*
* @param player the OfflinePlayer to unload
*/
@Override @Override
public void unload(final OfflinePlayer player) { public void unload(final OfflinePlayer player) {
this.playerCache.invalidate(this.playerLoader.getPlayerDataID(player)); this.playerCache.invalidate(this.accessor.getPlayerDataManager().getPlayerDataID(player));
} }
} }

View file

@ -1,38 +1,39 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2014 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.lishid.openinv.commands; package com.lishid.openinv.commands;
import com.lishid.openinv.OpenInv;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
public class AnyChestPluginCommand implements CommandExecutor { public class AnyChestPluginCommand implements CommandExecutor {
private final OpenInv plugin; private final OpenInv plugin;
public AnyChestPluginCommand(OpenInv plugin) { public AnyChestPluginCommand(final OpenInv plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { @Override
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
if (!(sender instanceof Player)) { if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "You can't use this from the console."); sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
return true; return true;
@ -41,12 +42,12 @@ public class AnyChestPluginCommand implements CommandExecutor {
Player player = (Player) sender; Player player = (Player) sender;
if (args.length > 0 && args[0].equalsIgnoreCase("check")) { if (args.length > 0 && args[0].equalsIgnoreCase("check")) {
sender.sendMessage("AnyChest is " + (plugin.getPlayerAnyChestStatus(player) ? "ON" : "OFF") + "."); sender.sendMessage("AnyChest is " + (this.plugin.getPlayerAnyChestStatus(player) ? "ON" : "OFF") + ".");
return true; return true;
} }
plugin.setPlayerAnyChestStatus(player, !plugin.getPlayerAnyChestStatus(player)); this.plugin.setPlayerAnyChestStatus(player, !this.plugin.getPlayerAnyChestStatus(player));
sender.sendMessage("AnyChest is now " + (plugin.getPlayerAnyChestStatus(player) ? "ON" : "OFF") + "."); sender.sendMessage("AnyChest is now " + (this.plugin.getPlayerAnyChestStatus(player) ? "ON" : "OFF") + ".");
return true; return true;
} }

View file

@ -1,15 +1,15 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2014 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@ -35,30 +35,30 @@ public class OpenEnderPluginCommand implements CommandExecutor {
private final OpenInv plugin; private final OpenInv plugin;
private final HashMap<Player, String> openEnderHistory = new HashMap<Player, String>(); private final HashMap<Player, String> openEnderHistory = new HashMap<Player, String>();
public OpenEnderPluginCommand(OpenInv plugin) { public OpenEnderPluginCommand(final OpenInv plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
if (!(sender instanceof Player)) { if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "You can't use this from the console."); sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
return true; return true;
} }
if (args.length > 0 && args[0].equalsIgnoreCase("?")) { if (args.length > 0 && args[0].equalsIgnoreCase("?")) {
plugin.showHelp((Player) sender); this.plugin.showHelp((Player) sender);
return true; return true;
} }
final Player player = (Player) sender; final Player player = (Player) sender;
// History management // History management
String history = openEnderHistory.get(player); String history = this.openEnderHistory.get(player);
if (history == null || history == "") { if (history == null || history == "") {
history = player.getName(); history = player.getName();
openEnderHistory.put(player, history); this.openEnderHistory.put(player, history);
} }
final String name; final String name;
@ -73,7 +73,7 @@ public class OpenEnderPluginCommand implements CommandExecutor {
new BukkitRunnable() { new BukkitRunnable() {
@Override @Override
public void run() { public void run() {
final OfflinePlayer offlinePlayer = plugin.matchPlayer(name); final OfflinePlayer offlinePlayer = OpenEnderPluginCommand.this.plugin.matchPlayer(name);
if (offlinePlayer == null || !offlinePlayer.hasPlayedBefore() && !offlinePlayer.isOnline()) { if (offlinePlayer == null || !offlinePlayer.hasPlayedBefore() && !offlinePlayer.isOnline()) {
player.sendMessage(ChatColor.RED + "Player not found!"); player.sendMessage(ChatColor.RED + "Player not found!");
@ -86,24 +86,24 @@ public class OpenEnderPluginCommand implements CommandExecutor {
if (!player.isOnline()) { if (!player.isOnline()) {
return; return;
} }
openInventory(player, offlinePlayer); OpenEnderPluginCommand.this.openInventory(player, offlinePlayer);
} }
}.runTask(plugin); }.runTask(OpenEnderPluginCommand.this.plugin);
} }
}.runTaskAsynchronously(plugin); }.runTaskAsynchronously(this.plugin);
return true; return true;
} }
private void openInventory(Player player, OfflinePlayer target) { private void openInventory(final Player player, final OfflinePlayer target) {
Player onlineTarget; Player onlineTarget;
boolean online = target.isOnline(); boolean online = target.isOnline();
if (!online) { if (!online) {
// Try loading the player's data // Try loading the player's data
onlineTarget = plugin.loadPlayer(target); onlineTarget = this.plugin.loadPlayer(target);
if (onlineTarget == null) { if (onlineTarget == null) {
player.sendMessage(ChatColor.RED + "Player not found!"); player.sendMessage(ChatColor.RED + "Player not found!");
@ -118,21 +118,30 @@ public class OpenEnderPluginCommand implements CommandExecutor {
player.sendMessage(ChatColor.RED + "You do not have permission to access other players' enderchests."); player.sendMessage(ChatColor.RED + "You do not have permission to access other players' enderchests.");
return; return;
} }
if (!Permissions.CROSSWORLD.hasPermission(player) && !player.getWorld().equals(onlineTarget.getWorld())) { if (!Permissions.CROSSWORLD.hasPermission(player)
&& !player.getWorld().equals(onlineTarget.getWorld())) {
player.sendMessage(ChatColor.RED + onlineTarget.getDisplayName() + " is not in your world!"); player.sendMessage(ChatColor.RED + onlineTarget.getDisplayName() + " is not in your world!");
return; return;
} }
if (!Permissions.OVERRIDE.hasPermission(player) && Permissions.EXEMPT.hasPermission(onlineTarget)) { if (!Permissions.OVERRIDE.hasPermission(player)
&& Permissions.EXEMPT.hasPermission(onlineTarget)) {
player.sendMessage(ChatColor.RED + onlineTarget.getDisplayName() + "'s inventory is protected!"); player.sendMessage(ChatColor.RED + onlineTarget.getDisplayName() + "'s inventory is protected!");
return; return;
} }
} }
// Record the target // Record the target
openEnderHistory.put(player, onlineTarget.getName()); this.openEnderHistory.put(player, onlineTarget.getName());
// Create the inventory // Create the inventory
ISpecialEnderChest chest = plugin.getEnderChest(onlineTarget, online); ISpecialEnderChest chest;
try {
chest = this.plugin.getSpecialEnderChest(onlineTarget, online);
} catch (Exception e) {
player.sendMessage(ChatColor.RED + "An error occurred creating " + onlineTarget.getDisplayName() + "'s inventory!");
e.printStackTrace();
return;
}
// Open the inventory // Open the inventory
player.openInventory(chest.getBukkitInventory()); player.openInventory(chest.getBukkitInventory());

View file

@ -1,15 +1,15 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2014 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@ -35,30 +35,30 @@ public class OpenInvPluginCommand implements CommandExecutor {
private final OpenInv plugin; private final OpenInv plugin;
private final HashMap<Player, String> openInvHistory = new HashMap<Player, String>(); private final HashMap<Player, String> openInvHistory = new HashMap<Player, String>();
public OpenInvPluginCommand(OpenInv plugin) { public OpenInvPluginCommand(final OpenInv plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
if (!(sender instanceof Player)) { if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "You can't use this from the console."); sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
return true; return true;
} }
if (args.length > 0 && args[0].equalsIgnoreCase("?")) { if (args.length > 0 && args[0].equalsIgnoreCase("?")) {
plugin.showHelp((Player) sender); this.plugin.showHelp((Player) sender);
return true; return true;
} }
final Player player = (Player) sender; final Player player = (Player) sender;
// History management // History management
String history = openInvHistory.get(player); String history = this.openInvHistory.get(player);
if (history == null || history == "") { if (history == null || history == "") {
history = player.getName(); history = player.getName();
openInvHistory.put(player, history); this.openInvHistory.put(player, history);
} }
final String name; final String name;
@ -73,7 +73,7 @@ public class OpenInvPluginCommand implements CommandExecutor {
new BukkitRunnable() { new BukkitRunnable() {
@Override @Override
public void run() { public void run() {
final OfflinePlayer offlinePlayer = plugin.matchPlayer(name); final OfflinePlayer offlinePlayer = OpenInvPluginCommand.this.plugin.matchPlayer(name);
if (offlinePlayer == null || !offlinePlayer.hasPlayedBefore() && !offlinePlayer.isOnline()) { if (offlinePlayer == null || !offlinePlayer.hasPlayedBefore() && !offlinePlayer.isOnline()) {
player.sendMessage(ChatColor.RED + "Player not found!"); player.sendMessage(ChatColor.RED + "Player not found!");
@ -86,17 +86,17 @@ public class OpenInvPluginCommand implements CommandExecutor {
if (!player.isOnline()) { if (!player.isOnline()) {
return; return;
} }
openInventory(player, offlinePlayer); OpenInvPluginCommand.this.openInventory(player, offlinePlayer);
} }
}.runTask(plugin); }.runTask(OpenInvPluginCommand.this.plugin);
} }
}.runTaskAsynchronously(plugin); }.runTaskAsynchronously(this.plugin);
return true; return true;
} }
private void openInventory(Player player, OfflinePlayer target) { private void openInventory(final Player player, final OfflinePlayer target) {
Player onlineTarget; Player onlineTarget;
@ -104,7 +104,7 @@ public class OpenInvPluginCommand implements CommandExecutor {
if (!online) { if (!online) {
// Try loading the player's data // Try loading the player's data
onlineTarget = plugin.loadPlayer(target); onlineTarget = this.plugin.loadPlayer(target);
if (onlineTarget == null) { if (onlineTarget == null) {
player.sendMessage(ChatColor.RED + "Player not found!"); player.sendMessage(ChatColor.RED + "Player not found!");
@ -123,23 +123,34 @@ public class OpenInvPluginCommand implements CommandExecutor {
} }
} else { } else {
// Protected check // Protected check
if (!Permissions.OVERRIDE.hasPermission(player) && Permissions.EXEMPT.hasPermission(onlineTarget)) { if (!Permissions.OVERRIDE.hasPermission(player)
&& Permissions.EXEMPT.hasPermission(onlineTarget)) {
player.sendMessage(ChatColor.RED + onlineTarget.getDisplayName() + "'s inventory is protected!"); player.sendMessage(ChatColor.RED + onlineTarget.getDisplayName() + "'s inventory is protected!");
return; return;
} }
// Crossworld check // Crossworld check
if ((!Permissions.CROSSWORLD.hasPermission(player) && !Permissions.OVERRIDE.hasPermission(player)) && onlineTarget.getWorld() != player.getWorld()) { if (!Permissions.CROSSWORLD.hasPermission(player)
player.sendMessage(ChatColor.RED + onlineTarget.getDisplayName() + " is not in your world!"); && !Permissions.OVERRIDE.hasPermission(player)
&& !onlineTarget.getWorld().equals(player.getWorld())) {
player.sendMessage(
ChatColor.RED + onlineTarget.getDisplayName() + " is not in your world!");
return; return;
} }
} }
// Record the target // Record the target
openInvHistory.put(player, onlineTarget.getName()); this.openInvHistory.put(player, onlineTarget.getName());
// Create the inventory // Create the inventory
ISpecialPlayerInventory inv = plugin.getInventory(onlineTarget, online); ISpecialPlayerInventory inv;
try {
inv = this.plugin.getSpecialInventory(onlineTarget, online);
} catch (Exception e) {
player.sendMessage(ChatColor.RED + "An error occurred creating " + onlineTarget.getDisplayName() + "'s inventory!");
e.printStackTrace();
return;
}
// Open the inventory // Open the inventory
player.openInventory(inv.getBukkitInventory()); player.openInventory(inv.getBukkitInventory());

View file

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvplugin</artifactId> <artifactId>openinvplugin</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</parent> </parent>
<artifactId>openinvpluginv1_10_r1</artifactId> <artifactId>openinvpluginv1_10_r1</artifactId>
@ -21,7 +21,7 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvparent</artifactId> <artifactId>openinvparent</artifactId>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
</parent> </parent>
<artifactId>openinvplugin</artifactId> <artifactId>openinvplugin</artifactId>

View file

@ -6,7 +6,7 @@
<artifactId>openinvparent</artifactId> <artifactId>openinvparent</artifactId>
<name>OpenInvParent</name> <name>OpenInvParent</name>
<url>http://dev.bukkit.org/bukkit-plugins/openinv/</url> <url>http://dev.bukkit.org/bukkit-plugins/openinv/</url>
<version>3.1.3-SNAPSHOT</version> <version>3.2.0</version>
<packaging>pom</packaging> <packaging>pom</packaging>