Compare commits

..

7 Commits
2.2.5 ... 2.2.9

Author SHA1 Message Date
Jikoo
8f17bd0237 Remove update checker and bumped version for release
Added myself to the authors list as I've been maintaining this fork for a while
2015-11-16 23:21:34 -05:00
Jikoo
20fb61705d Update to 1.8.8, properly declare permissions in plugin.yml 2015-11-16 23:12:46 -05:00
Jikoo
c0f513177a Removed additional async lookup notification, current is pretty fast. 2015-05-19 08:11:53 -04:00
Jikoo
b3a3947b03 1.8.4
The easiest NMS update ever.
2015-05-19 08:10:39 -04:00
Jikoo
c7bab7d451 Whoops, didn't make sure my autoformatter's settings matched the style. 2015-03-12 16:42:00 -04:00
Jikoo
4058463f7f OpenInv 2.2.7
Updated for Spigot 1.8.3
Dropped support for all other versions
Fixed lookup not working for players on first login/incomplete names
2015-03-11 16:48:21 -04:00
Jikoo
21cd1926ae Don't find username on the main thread. Not friendly with partial names. 2014-12-01 16:11:52 -05:00
17 changed files with 226 additions and 572 deletions

View File

@@ -26,14 +26,18 @@ import org.bukkit.permissions.Permissible;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import com.lishid.openinv.commands.*;
import com.lishid.openinv.commands.AnyChestPluginCommand;
import com.lishid.openinv.commands.OpenEnderPluginCommand;
import com.lishid.openinv.commands.OpenInvPluginCommand;
import com.lishid.openinv.commands.SearchInvPluginCommand;
import com.lishid.openinv.commands.SilentChestPluginCommand;
import com.lishid.openinv.commands.ToggleOpenInvPluginCommand;
import com.lishid.openinv.internal.IAnySilentChest;
import com.lishid.openinv.internal.IInventoryAccess;
import com.lishid.openinv.internal.IPlayerDataManager;
import com.lishid.openinv.internal.ISpecialEnderChest;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import com.lishid.openinv.internal.InternalAccessor;
import com.lishid.openinv.utils.UpdateManager;
/**
* Open other player's inventory
@@ -46,14 +50,13 @@ public class OpenInv extends JavaPlugin {
public static HashMap<String, ISpecialPlayerInventory> inventories = new HashMap<String, ISpecialPlayerInventory>();
public static HashMap<String, ISpecialEnderChest> enderChests = new HashMap<String, ISpecialEnderChest>();
private UpdateManager updater = new UpdateManager();
public static OpenInv mainPlugin;
public static IPlayerDataManager playerLoader;
public static IInventoryAccess inventoryAccess;
public static IAnySilentChest anySilentChest;
@Override
public void onEnable() {
// Get plugin manager
PluginManager pm = getServer().getPluginManager();
@@ -74,7 +77,6 @@ public class OpenInv extends JavaPlugin {
mainPlugin = this;
FileConfiguration config = getConfig();
config.set("CheckForUpdates", config.getBoolean("CheckForUpdates", true));
config.set("NotifySilentChest", config.getBoolean("NotifySilentChest", true));
config.set("NotifyAnyChest", config.getBoolean("NotifyAnyChest", true));
config.set("ItemOpenInvItemID", config.getInt("ItemOpenInvItemID", 280));
@@ -96,7 +98,6 @@ public class OpenInv extends JavaPlugin {
getCommand("anychest").setExecutor(new AnyChestPluginCommand(this));
getCommand("openender").setExecutor(new OpenEnderPluginCommand(this));
updater.Initialize(this, getFile());
}
public static boolean NotifySilentChest() {

View File

@@ -23,22 +23,18 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.Permissions;
public class AnyChestPluginCommand implements CommandExecutor {
public AnyChestPluginCommand(OpenInv plugin) {
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
return true;
}
if (!OpenInv.hasPermission(sender, Permissions.PERM_ANYCHEST)) {
sender.sendMessage(ChatColor.RED + "You do not have permission to use anychest.");
return true;
}
if (args.length > 0) {
if (args[0].equalsIgnoreCase("check")) {

View File

@@ -17,12 +17,17 @@
package com.lishid.openinv.commands;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.Permissions;
@@ -37,24 +42,19 @@ public class OpenEnderPluginCommand implements CommandExecutor {
this.plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
return true;
}
if (!OpenInv.hasPermission(sender, Permissions.PERM_ENDERCHEST)) {
sender.sendMessage(ChatColor.RED + "You do not have permission to access player enderchest");
return true;
}
if (args.length > 0 && args[0].equalsIgnoreCase("?")) {
OpenInv.ShowHelp((Player) sender);
return true;
}
Player player = (Player) sender;
boolean offline = false;
final Player player = (Player) sender;
// History management
String history = openEnderHistory.get(player);
@@ -64,55 +64,78 @@ public class OpenEnderPluginCommand implements CommandExecutor {
openEnderHistory.put(player, history);
}
// Target selecting
Player target;
String name = "";
final String name;
// Read from history if target is not named
if (args.length < 1) {
if (history != null && history != "") {
name = history;
}
else {
sender.sendMessage(ChatColor.RED + "OpenEnder history is empty!");
return true;
}
name = history;
}
else {
name = args[0];
}
target = this.plugin.getServer().getPlayer(name);
final UUID senderID = player.getUniqueId();
new BukkitRunnable() {
@Override
public void run() {
List<Player> matches = Bukkit.matchPlayer(name);
if (!matches.isEmpty()) {
openInventory(player, matches.get(0).getUniqueId());
return;
}
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(name);
if (Bukkit.getPlayer(senderID) == null) {
return;
}
if (offlinePlayer == null || !offlinePlayer.hasPlayedBefore()) {
player.sendMessage(ChatColor.RED + "Player not found!");
return;
}
new BukkitRunnable() {
@Override
public void run() {
if (Bukkit.getPlayer(senderID) == null) {
return;
}
openInventory(player, offlinePlayer.getUniqueId());
}
}.runTask(plugin);
}
}.runTaskAsynchronously(plugin);
return true;
}
private void openInventory(Player player, UUID uuid) {
Player target = this.plugin.getServer().getPlayer(uuid);
if (target == null) {
// Try loading the player's data
target = OpenInv.playerLoader.loadPlayer(name);
target = OpenInv.playerLoader.loadPlayer(uuid);
if (target == null) {
sender.sendMessage(ChatColor.RED + "Player " + name + " not found!");
return true;
player.sendMessage(ChatColor.RED + "Player not found!");
return;
}
}
if (target != sender && !OpenInv.hasPermission(sender, Permissions.PERM_ENDERCHEST_ALL)) {
sender.sendMessage(ChatColor.RED + "You do not have permission to access other player's enderchest");
return true;
if (target != player && !OpenInv.hasPermission(player, Permissions.PERM_ENDERCHEST_ALL)) {
player.sendMessage(ChatColor.RED + "You do not have permission to access other player's enderchest");
return;
}
// Record the target
history = target.getName();
openEnderHistory.put(player, history);
openEnderHistory.put(player, target.getName());
// Create the inventory
ISpecialEnderChest chest = OpenInv.enderChests.get(target.getName().toLowerCase());
if (chest == null) {
chest = InternalAccessor.Instance.newSpecialEnderChest(target, !offline);
chest = InternalAccessor.Instance.newSpecialEnderChest(target, !target.isOnline());
}
// Open the inventory
player.openInventory(chest.getBukkitInventory());
return true;
}
}

View File

@@ -17,12 +17,17 @@
package com.lishid.openinv.commands;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.Permissions;
@@ -37,23 +42,19 @@ public class OpenInvPluginCommand implements CommandExecutor {
this.plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
return true;
}
if (!OpenInv.hasPermission(sender, Permissions.PERM_OPENINV)) {
sender.sendMessage(ChatColor.RED + "You do not have permission to access player inventories");
return true;
}
if (args.length > 0 && args[0].equalsIgnoreCase("?")) {
OpenInv.ShowHelp((Player) sender);
return true;
}
Player player = (Player) sender;
boolean offline = false;
final Player player = (Player) sender;
// History management
String history = openInvHistory.get(player);
@@ -63,10 +64,7 @@ public class OpenInvPluginCommand implements CommandExecutor {
openInvHistory.put(player, history);
}
// Target selecting
Player target;
String name = "";
final String name;
// Read from history if target is not named
if (args.length < 1) {
@@ -76,51 +74,80 @@ public class OpenInvPluginCommand implements CommandExecutor {
name = args[0];
}
target = this.plugin.getServer().getPlayer(name);
final UUID senderID = player.getUniqueId();
new BukkitRunnable() {
@Override
public void run() {
List<Player> matches = Bukkit.matchPlayer(name);
if (!matches.isEmpty()) {
openInventory(player, matches.get(0).getUniqueId());
return;
}
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(name);
if (Bukkit.getPlayer(senderID) == null) {
return;
}
if (offlinePlayer == null || !offlinePlayer.hasPlayedBefore()) {
player.sendMessage(ChatColor.RED + "Player not found!");
return;
}
new BukkitRunnable() {
@Override
public void run() {
if (Bukkit.getPlayer(senderID) == null) {
return;
}
openInventory(player, offlinePlayer.getUniqueId());
}
}.runTask(plugin);
}
}.runTaskAsynchronously(plugin);
return true;
}
private void openInventory(Player player, UUID uuid) {
Player target = this.plugin.getServer().getPlayer(uuid);
if (target == null) {
if (target == null) {
// Try loading the player's data
target = OpenInv.playerLoader.loadPlayer(name);
// Try loading the player's data
target = OpenInv.playerLoader.loadPlayer(uuid);
if (target == null) {
sender.sendMessage(ChatColor.RED + "Player " + name + " not found!");
return true;
}
if (target == null) {
player.sendMessage(ChatColor.RED + "Player not found!");
return;
}
}
// Permissions checks
if (!OpenInv.hasPermission(player, Permissions.PERM_OVERRIDE) && OpenInv.hasPermission(target, Permissions.PERM_EXEMPT)) {
sender.sendMessage(ChatColor.RED + target.getDisplayName() + "'s inventory is protected!");
return true;
player.sendMessage(ChatColor.RED + target.getDisplayName() + "'s inventory is protected!");
return;
}
// Crosswork check
if ((!OpenInv.hasPermission(player, Permissions.PERM_CROSSWORLD) && !OpenInv.hasPermission(player, Permissions.PERM_OVERRIDE)) && target.getWorld() != player.getWorld()) {
sender.sendMessage(ChatColor.RED + target.getDisplayName() + " is not in your world!");
return true;
player.sendMessage(ChatColor.RED + target.getDisplayName() + " is not in your world!");
return;
}
// Self-open check
if (!OpenInv.hasPermission(player, Permissions.PERM_OPENSELF) && target.equals(player)) {
sender.sendMessage(ChatColor.RED + "You're not allowed to openinv yourself.");
return true;
player.sendMessage(ChatColor.RED + "You're not allowed to openinv yourself.");
return;
}
// Record the target
history = target.getName();
openInvHistory.put(player, history);
openInvHistory.put(player, target.getName());
// Create the inventory
ISpecialPlayerInventory inv = OpenInv.inventories.get(target.getName().toLowerCase());
if (inv == null) {
inv = InternalAccessor.Instance.newSpecialPlayerInventory(target, !offline);
inv = InternalAccessor.Instance.newSpecialPlayerInventory(target, !target.isOnline());
}
// Open the inventory
player.openInventory(inv.getBukkitInventory());
return true;
}
}

View File

@@ -24,22 +24,13 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.Permissions;
public class SearchInvPluginCommand implements CommandExecutor {
public SearchInvPluginCommand() {
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player) {
if (!OpenInv.hasPermission(sender, Permissions.PERM_SEARCH)) {
sender.sendMessage(ChatColor.RED + "You do not have permission to access player inventories");
return true;
}
}
String PlayerList = "";
Material material = null;

View File

@@ -23,22 +23,18 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.Permissions;
public class SilentChestPluginCommand implements CommandExecutor {
public SilentChestPluginCommand(OpenInv plugin) {
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
return true;
}
if (!OpenInv.hasPermission(sender, Permissions.PERM_SILENT)) {
sender.sendMessage(ChatColor.RED + "You do not have permission to use silent chest.");
return true;
}
if (args.length > 0) {
if (args[0].equalsIgnoreCase("check")) {

View File

@@ -24,19 +24,15 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.Permissions;
public class ToggleOpenInvPluginCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
return true;
}
if (!OpenInv.hasPermission(sender, Permissions.PERM_OPENINV)) {
sender.sendMessage(ChatColor.RED + "You do not have permission to access player inventories");
return true;
}
Player player = (Player) sender;
if (args.length > 0) {

View File

@@ -16,8 +16,11 @@
package com.lishid.openinv.internal;
import java.util.UUID;
import org.bukkit.entity.Player;
public interface IPlayerDataManager {
public Player loadPlayer(String name);
public Player loadPlayer(UUID uuid);
}

View File

@@ -14,7 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_8_R1;
package com.lishid.openinv.internal.v1_8_R3;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
@@ -22,17 +22,21 @@ import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.IAnySilentChest;
//Volatile
import net.minecraft.server.v1_8_R1.*;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_8_R1.entity.*;
import net.minecraft.server.v1_8_R3.Block;
import net.minecraft.server.v1_8_R3.BlockPosition;
import net.minecraft.server.v1_8_R3.EntityPlayer;
import net.minecraft.server.v1_8_R3.IInventory;
import net.minecraft.server.v1_8_R3.ITileInventory;
import net.minecraft.server.v1_8_R3.InventoryLargeChest;
import net.minecraft.server.v1_8_R3.PacketPlayOutOpenWindow;
import net.minecraft.server.v1_8_R3.TileEntityChest;
import net.minecraft.server.v1_8_R3.World;
public class AnySilentChest implements IAnySilentChest {
@Override
public boolean IsAnyChestNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
@@ -56,10 +60,11 @@ public class AnySilentChest implements IAnySilentChest {
return false;
}
@Override
public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
Object chest = (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z));
Object chest = world.getTileEntity(new BlockPosition(x, y, z));
if (chest == null)
return true;

View File

@@ -14,7 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_8_R1;
package com.lishid.openinv.internal.v1_8_R3;
import java.lang.reflect.Field;
@@ -26,10 +26,12 @@ import com.lishid.openinv.Permissions;
import com.lishid.openinv.internal.IInventoryAccess;
//Volatile
import net.minecraft.server.v1_8_R1.*;
import org.bukkit.craftbukkit.v1_8_R1.inventory.*;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventory;
import net.minecraft.server.v1_8_R3.IInventory;
public class InventoryAccess implements IInventoryAccess {
@Override
public boolean check(Inventory inventory, HumanEntity player) {
IInventory inv = grabInventory(inventory);

View File

@@ -14,7 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_8_R1;
package com.lishid.openinv.internal.v1_8_R3;
import java.io.File;
import java.util.UUID;
@@ -28,11 +28,14 @@ import com.lishid.openinv.internal.IPlayerDataManager;
import com.mojang.authlib.GameProfile;
//Volatile
import net.minecraft.server.v1_8_R1.*;
import org.bukkit.craftbukkit.v1_8_R3.CraftServer;
import org.bukkit.craftbukkit.v1_8_R1.*;
import net.minecraft.server.v1_8_R3.EntityPlayer;
import net.minecraft.server.v1_8_R3.MinecraftServer;
import net.minecraft.server.v1_8_R3.PlayerInteractManager;
public class PlayerDataManager implements IPlayerDataManager {
@Override
public Player loadPlayer(String name) {
try {
UUID uuid = matchUser(name);
@@ -101,4 +104,29 @@ public class PlayerDataManager implements IPlayerDataManager {
return found;
}
/* (non-Javadoc)
* @see com.lishid.openinv.internal.IPlayerDataManager#loadPlayer(java.util.UUID)
*/
@Override
public Player loadPlayer(UUID uuid) {
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
if (player == null || !player.hasPlayedBefore()) {
return null;
}
GameProfile profile = new GameProfile(uuid, player.getName());
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
// Create an entity to load the player data
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0)));
// Get the bukkit entity
Player target = (entity == null) ? null : entity.getBukkitEntity();
if (target != null) {
// Load data
target.loadData();
// Return the entity
return target;
}
return null;
}
}

View File

@@ -14,10 +14,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_8_R1;
package com.lishid.openinv.internal.v1_8_R3;
//Volatile
import net.minecraft.server.v1_8_R1.*;
import net.minecraft.server.v1_8_R3.ContainerChest;
import net.minecraft.server.v1_8_R3.EntityHuman;
import net.minecraft.server.v1_8_R3.IInventory;
public class SilentContainerChest extends ContainerChest {
public IInventory inv;

View File

@@ -14,32 +14,38 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_8_R1;
package com.lishid.openinv.internal.v1_8_R3;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialEnderChest;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialEnderChest;
//Volatile
import net.minecraft.server.v1_8_R1.*;
import org.bukkit.craftbukkit.v1_8_R1.entity.*;
import org.bukkit.craftbukkit.v1_8_R1.inventory.*;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventory;
import net.minecraft.server.v1_8_R3.EntityHuman;
import net.minecraft.server.v1_8_R3.IInventory;
import net.minecraft.server.v1_8_R3.InventoryEnderChest;
import net.minecraft.server.v1_8_R3.InventorySubcontainer;
import net.minecraft.server.v1_8_R3.ItemStack;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
public boolean playerOnline = false;
private CraftPlayer owner;
private InventoryEnderChest enderChest;
private final CraftPlayer owner;
private final InventoryEnderChest enderChest;
private int maxStack = MAX_STACK;
private CraftInventory inventory = new CraftInventory(this);
private final CraftInventory inventory = new CraftInventory(this);
public SpecialEnderChest(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().hasCustomName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
@@ -50,10 +56,12 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
OpenInv.enderChests.put(owner.getName().toLowerCase(), this);
}
@Override
public Inventory getBukkitInventory() {
return inventory;
}
@Override
public void InventoryRemovalCheck() {
owner.saveData();
if (transaction.isEmpty() && !playerOnline) {
@@ -61,6 +69,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
}
}
@Override
public void PlayerGoOnline(Player p) {
if (!playerOnline) {
try {
@@ -75,39 +84,48 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
}
}
@Override
public void PlayerGoOffline() {
playerOnline = false;
}
@Override
public ItemStack[] getContents() {
return this.items;
}
@Override
public void onOpen(CraftHumanEntity who) {
transaction.add(who);
}
@Override
public void onClose(CraftHumanEntity who) {
transaction.remove(who);
this.InventoryRemovalCheck();
}
@Override
public List<HumanEntity> getViewers() {
return transaction;
}
@Override
public InventoryHolder getOwner() {
return this.owner;
}
@Override
public void setMaxStackSize(int size) {
maxStack = size;
}
@Override
public int getMaxStackSize() {
return maxStack;
}
@Override
public boolean a(EntityHuman entityhuman) {
return true;
}
@@ -120,6 +138,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
}
@Override
public void update() {
enderChest.update();
}

View File

@@ -14,7 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_8_R1;
package com.lishid.openinv.internal.v1_8_R3;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
@@ -23,15 +23,19 @@ import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
//Volatile
import net.minecraft.server.v1_8_R1.*;
import org.bukkit.craftbukkit.v1_8_R1.entity.*;
import org.bukkit.craftbukkit.v1_8_R1.inventory.*;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventory;
import net.minecraft.server.v1_8_R3.EntityHuman;
import net.minecraft.server.v1_8_R3.ItemStack;
import net.minecraft.server.v1_8_R3.PlayerInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
CraftPlayer owner;
public boolean playerOnline = false;
private ItemStack[] extra = new ItemStack[5];
private CraftInventory inventory = new CraftInventory(this);
private final ItemStack[] extra = new ItemStack[5];
private final CraftInventory inventory = new CraftInventory(this);
public SpecialPlayerInventory(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle());
@@ -82,7 +86,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
public ItemStack[] getContents() {
ItemStack[] C = new ItemStack[getSize()];
System.arraycopy(items, 0, C, 0, items.length);
System.arraycopy(items, 0, C, items.length, armor.length);
System.arraycopy(armor, 0, C, items.length, armor.length);
return C;
}
@@ -143,7 +147,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
return itemstack;
}
else {
itemstack = is[i].a(j);
itemstack = is[i].cloneAndSubtract(j);
if (is[i].count == 0) {
is[i] = null;
}

View File

@@ -1,34 +0,0 @@
package com.lishid.openinv.utils;
import java.io.File;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.utils.Updater.UpdateResult;
public class UpdateManager {
public Updater updater;
public void Initialize(OpenInv plugin, File file) {
updater = new Updater(plugin, 31432, file);
// Create task to update
plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() {
@Override
public void run() {
// Check for updates
if (OpenInv.GetCheckForUpdates()) {
UpdateResult result = updater.update();
if (result != UpdateResult.NO_UPDATE) {
if (result == UpdateResult.SUCCESS) {
OpenInv.log("Update found! Downloaded new version.");
OpenInv.log("This behaviour can be disabled in the config.yml");
}
else {
OpenInv.log("Update failed, reason: " + result.toString());
}
}
}
}
}, 0, 20 * 60 * 1000); // Update every once a while
}
}

View File

@@ -1,412 +0,0 @@
/*
* Updater for Bukkit.
*
* This class provides the means to safely and easily update a plugin, or check to see if it is updated using dev.bukkit.org
*/
package com.lishid.openinv.utils;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Enumeration;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.bukkit.plugin.Plugin;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
/**
* Check dev.bukkit.org to find updates for a given plugin, and download the updates if needed.
* <p/>
* <b>VERY, VERY IMPORTANT</b>: Because there are no standards for adding auto-update toggles in your plugin's config, this system provides NO CHECK WITH YOUR CONFIG to make sure the user has allowed
* auto-updating. <br>
* It is a <b>BUKKIT POLICY</b> that you include a boolean value in your config that prevents the auto-updater from running <b>AT ALL</b>. <br>
* If you fail to include this option in your config, your plugin will be <b>REJECTED</b> when you attempt to submit it to dev.bukkit.org.
* <p/>
* An example of a good configuration option would be something similar to 'auto-update: true' - if this value is set to false you may NOT run the auto-updater. <br>
* If you are unsure about these rules, please read the plugin submission guidelines: http://goo.gl/8iU5l
*
* @author Gravity
* @version 2.0
*/
public class Updater {
private Plugin plugin;
private String versionName;
private String versionLink;
@SuppressWarnings("unused")
private String versionType;
@SuppressWarnings("unused")
private String versionGameVersion;
private boolean announce; // Whether to announce file downloads
private URL url; // Connecting to RSS
private File file; // The plugin's file
private int id = 31432; // Project's Curse ID
// SEE https://dev.bukkit.org/home/servermods-apikey/
private String apiKey = null; // BukkitDev ServerMods API key
private static final String TITLE_VALUE = "name"; // Gets remote file's title
private static final String LINK_VALUE = "downloadUrl"; // Gets remote file's download link
private static final String TYPE_VALUE = "releaseType"; // Gets remote file's release type
private static final String VERSION_VALUE = "gameVersion"; // Gets remote file's build version
private static final String QUERY = "/servermods/files?projectIds="; // Path to GET
private static final String HOST = "https://api.curseforge.com"; // Slugs will be appended to this to get to the project's RSS feed
private static final String[] NO_UPDATE_TAG = { "-DEV", "-PRE", "-SNAPSHOT" }; // If the version number contains one of these, don't update.
private static final int BYTE_SIZE = 1024; // Used for downloading files
private String updateFolder;// The folder that downloads will be placed in
private Updater.UpdateResult result = Updater.UpdateResult.SUCCESS; // Used for determining the outcome of the update process
/**
* Gives the dev the result of the update process. Can be obtained by called getResult().
*/
public enum UpdateResult {
/**
* The updater found an update, and has readied it to be loaded the next time the server restarts/reloads.
*/
SUCCESS,
/**
* The updater did not find an update, and nothing was downloaded.
*/
NO_UPDATE,
/**
* The server administrator has disabled the updating system
*/
DISABLED,
/**
* The updater found an update, but was unable to download it.
*/
FAIL_DOWNLOAD,
/**
* For some reason, the updater was unable to contact dev.bukkit.org to download the file.
*/
FAIL_DBO,
/**
* When running the version check, the file on DBO did not contain the a version in the format 'vVersion' such as 'v1.0'.
*/
FAIL_NOVERSION,
/**
* The id provided by the plugin running the updater was invalid and doesn't exist on DBO.
*/
FAIL_BADID,
/**
* The server administrator has improperly configured their API key in the configuration
*/
FAIL_APIKEY,
/**
* The updater found an update, but because of the UpdateType being set to NO_DOWNLOAD, it wasn't downloaded.
*/
UPDATE_AVAILABLE
}
/**
* Initialize the updater
*
* @param plugin The plugin that is checking for an update.
* @param id The dev.bukkit.org id of the project
* @param file The file that the plugin is running from, get this by doing this.getFile() from within your main class.
*/
public Updater(Plugin plugin, int id, File file) {
this.plugin = plugin;
this.file = file;
this.id = id;
this.updateFolder = plugin.getServer().getUpdateFolder();
try {
this.url = new URL(Updater.HOST + Updater.QUERY + id);
}
catch (final MalformedURLException e) {
plugin.getLogger().severe("The project ID provided for updating, " + id + " is invalid.");
this.result = UpdateResult.FAIL_BADID;
e.printStackTrace();
}
}
/**
* Save an update from dev.bukkit.org into the server's update folder.
*/
private void saveFile(File folder, String file, String u) {
if (!folder.exists()) {
folder.mkdir();
}
BufferedInputStream in = null;
FileOutputStream fout = null;
try {
// Download the file
final URL url = new URL(u);
final int fileLength = url.openConnection().getContentLength();
in = new BufferedInputStream(url.openStream());
fout = new FileOutputStream(folder.getAbsolutePath() + "/" + file);
final byte[] data = new byte[Updater.BYTE_SIZE];
int count;
if (this.announce) {
this.plugin.getLogger().info("About to download a new update: " + this.versionName);
}
long downloaded = 0;
while ((count = in.read(data, 0, Updater.BYTE_SIZE)) != -1) {
downloaded += count;
fout.write(data, 0, count);
final int percent = (int) ((downloaded * 100) / fileLength);
if (this.announce && ((percent % 10) == 0)) {
this.plugin.getLogger().info("Downloading update: " + percent + "% of " + fileLength + " bytes.");
}
}
// Just a quick check to make sure we didn't leave any files from last time...
for (final File xFile : new File(this.plugin.getDataFolder().getParent(), this.updateFolder).listFiles()) {
if (xFile.getName().endsWith(".zip")) {
xFile.delete();
}
}
// Check to see if it's a zip file, if it is, unzip it.
final File dFile = new File(folder.getAbsolutePath() + "/" + file);
if (dFile.getName().endsWith(".zip")) {
// Unzip
this.unzip(dFile.getCanonicalPath());
}
if (this.announce) {
this.plugin.getLogger().info("Finished updating.");
}
}
catch (final Exception ex) {
this.plugin.getLogger().warning("The auto-updater tried to download a new update, but was unsuccessful.");
this.result = Updater.UpdateResult.FAIL_DOWNLOAD;
}
finally {
try {
if (in != null) {
in.close();
}
if (fout != null) {
fout.close();
}
}
catch (final Exception ex) {}
}
}
/**
* Part of Zip-File-Extractor, modified by Gravity for use with Bukkit
*/
private void unzip(String file) {
try {
final File fSourceZip = new File(file);
final String zipPath = file.substring(0, file.length() - 4);
ZipFile zipFile = new ZipFile(fSourceZip);
Enumeration<? extends ZipEntry> e = zipFile.entries();
while (e.hasMoreElements()) {
ZipEntry entry = e.nextElement();
File destinationFilePath = new File(zipPath, entry.getName());
destinationFilePath.getParentFile().mkdirs();
if (entry.isDirectory()) {
continue;
}
else {
final BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry));
int b;
final byte buffer[] = new byte[Updater.BYTE_SIZE];
final FileOutputStream fos = new FileOutputStream(destinationFilePath);
final BufferedOutputStream bos = new BufferedOutputStream(fos, Updater.BYTE_SIZE);
while ((b = bis.read(buffer, 0, Updater.BYTE_SIZE)) != -1) {
bos.write(buffer, 0, b);
}
bos.flush();
bos.close();
bis.close();
final String name = destinationFilePath.getName();
if (name.endsWith(".jar") && this.pluginFile(name)) {
destinationFilePath.renameTo(new File(this.plugin.getDataFolder().getParent(), this.updateFolder + "/" + name));
}
}
entry = null;
destinationFilePath = null;
}
e = null;
zipFile.close();
zipFile = null;
// Move any plugin data folders that were included to the right place, Bukkit won't do this for us.
for (final File dFile : new File(zipPath).listFiles()) {
if (dFile.isDirectory()) {
if (this.pluginFile(dFile.getName())) {
final File oFile = new File(this.plugin.getDataFolder().getParent(), dFile.getName()); // Get current dir
final File[] contents = oFile.listFiles(); // List of existing files in the current dir
for (final File cFile : dFile.listFiles()) // Loop through all the files in the new dir
{
boolean found = false;
for (final File xFile : contents) // Loop through contents to see if it exists
{
if (xFile.getName().equals(cFile.getName())) {
found = true;
break;
}
}
if (!found) {
// Move the new file into the current dir
cFile.renameTo(new File(oFile.getCanonicalFile() + "/" + cFile.getName()));
}
else {
// This file already exists, so we don't need it anymore.
cFile.delete();
}
}
}
}
dFile.delete();
}
new File(zipPath).delete();
fSourceZip.delete();
}
catch (final IOException ex) {
this.plugin.getLogger().warning("The auto-updater tried to unzip a new update file, but was unsuccessful.");
this.result = Updater.UpdateResult.FAIL_DOWNLOAD;
ex.printStackTrace();
}
new File(file).delete();
}
/**
* Check if the name of a jar is one of the plugins currently installed, used for extracting the correct files out of a zip.
*/
private boolean pluginFile(String name) {
for (final File file : new File("plugins").listFiles()) {
if (file.getName().equals(name)) {
return true;
}
}
return false;
}
/**
* Check to see if the program should continue by evaluation whether the plugin is already updated, or shouldn't be updated
*/
private boolean versionCheck(String title) {
final String version = this.plugin.getDescription().getVersion();
if (title.split(" ").length == 2) {
final String remoteVersion = title.split(" ")[1].split(" ")[0]; // Get the newest file's version number
if (this.hasTag(version) || version.equalsIgnoreCase(remoteVersion) || !isNewer(version, remoteVersion)) {
// We already have the latest version, or this build is tagged for no-update
this.result = Updater.UpdateResult.NO_UPDATE;
return false;
}
}
else {
this.plugin.getLogger().warning("File versions should follow the format 'PluginName VERSION'");
this.result = Updater.UpdateResult.FAIL_NOVERSION;
return false;
}
return true;
}
/**
* Evaluate whether the version number is marked showing that it should not be updated by this program
*/
private boolean hasTag(String version) {
for (final String string : Updater.NO_UPDATE_TAG) {
if (version.contains(string)) {
return true;
}
}
return false;
}
private boolean read() {
try {
final URLConnection conn = this.url.openConnection();
conn.setConnectTimeout(5000);
if (this.apiKey != null) {
conn.addRequestProperty("X-API-Key", this.apiKey);
}
conn.addRequestProperty("User-Agent", "Updater");
conn.setDoOutput(true);
final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
final String response = reader.readLine();
final JSONArray array = (JSONArray) JSONValue.parse(response);
if (array.size() == 0) {
this.plugin.getLogger().warning("The updater could not find any files for the project id " + this.id);
this.result = UpdateResult.FAIL_BADID;
return false;
}
this.versionName = (String) ((JSONObject) array.get(array.size() - 1)).get(Updater.TITLE_VALUE);
this.versionLink = (String) ((JSONObject) array.get(array.size() - 1)).get(Updater.LINK_VALUE);
this.versionType = (String) ((JSONObject) array.get(array.size() - 1)).get(Updater.TYPE_VALUE);
this.versionGameVersion = (String) ((JSONObject) array.get(array.size() - 1)).get(Updater.VERSION_VALUE);
return true;
}
catch (final IOException e) {
if (e.getMessage().contains("HTTP response code: 403")) {
this.plugin.getLogger().warning("dev.bukkit.org rejected the API key provided in plugins/Updater/config.yml");
this.plugin.getLogger().warning("Please double-check your configuration to ensure it is correct.");
this.result = UpdateResult.FAIL_APIKEY;
}
else {
this.plugin.getLogger().warning("The updater could not contact curse for updating.");
this.result = UpdateResult.FAIL_DBO;
}
e.printStackTrace();
return false;
}
}
private static boolean isNewer(String oldVers, String newVers) {
String s1 = normalisedVersion(oldVers);
String s2 = normalisedVersion(newVers);
int cmp = s1.compareTo(s2);
return cmp < 0;
}
public static String normalisedVersion(String version) {
return normalisedVersion(version, ".", 3);
}
public static String normalisedVersion(String version, String sep, int maxWidth) {
String[] split = Pattern.compile(sep, Pattern.LITERAL).split(version);
StringBuilder sb = new StringBuilder();
for (String s : split) {
sb.append(String.format("%" + maxWidth + 's', s));
}
return sb.toString();
}
public UpdateResult update() {
if (Updater.this.url != null) {
// Obtain the results of the project's file feed
if (Updater.this.read()) {
if (Updater.this.versionCheck(Updater.this.versionName)) {
if (Updater.this.versionLink != null) {
String name = Updater.this.file.getName();
// If it's a zip file, it shouldn't be downloaded as the plugin's name
if (Updater.this.versionLink.endsWith(".zip")) {
final String[] split = Updater.this.versionLink.split("/");
name = split[split.length - 1];
}
Updater.this.saveFile(new File(Updater.this.plugin.getDataFolder().getParent(), Updater.this.updateFolder), name, Updater.this.versionLink);
}
}
}
}
return this.result;
}
}

View File

@@ -1,38 +1,45 @@
name: OpenInv
main: com.lishid.openinv.OpenInv
version: 2.2.5
version: 2.2.9
author: lishid
authors: [Jikoo]
description: >
This plugin allows you to open a player's inventory as a chest and interact with it in real time.
commands:
openinv:
aliases: [oi, inv, open]
description: Open a player's inventory
permission: OpenInv.openinv
usage: |
/<command> - Open last person's inventory
/<command> <Player> - Open a player's inventory
openender:
aliases: [oe]
description: Opens the enderchest of a player
permission: OpenInv.openender
usage: |
/<command> <Player> - Opens a player's enderchest
searchinv:
aliases: [si]
description: Search and list players having a specific item
permission: OpenInv.search
usage: |
/<command> <Item> [MinAmount] - Item can be the Item ID or the CraftBukkit Item Name, MinAmount is the minimum amount to be considered.
toggleopeninv:
aliases: [toi, toggleoi, toggleinv]
description: Toggle item openinv function
permission: OpenInv.openinv
usage: |
/<command> [Check] - Checks whether item openinv is enabled
silentchest:
aliases: [sc, silent]
description: Toggle silent chest function, which hides the animation of a chest when opened or closed, and suppresses the sound.
permission: OpenInv.silent
usage: |
/<command> [Check] - Checks whether silent chest is enabled
anychest:
aliases: [ac]
description: Toggle anychest function, which allows opening of blocked chests.
permission: OpenInv.anychest
usage: |
/<command> [Check] - Checks whether anychest is enabled