Compare commits

..

10 Commits
2.2.7 ... 2.3.0

Author SHA1 Message Date
Jikoo
3549431fbc Removed item wand functionality
Anyone who can use it has to be able to run the command anyway. If they can run the command, they can use tab completion to automatically fill in anyone online's name. There's no need to keep around a bunch of deprecated code for a function I sincerely doubt anyone actually uses.
2016-03-01 12:30:12 -05:00
Jikoo
17b0cb6efe Fix players without permission to modify inventories inserting items 2016-03-01 12:22:26 -05:00
Jikoo
2d7522554c Use AnyChest when an ocelot is on a chest.
Closes #2
2016-03-01 12:09:29 -05:00
Jikoo
131f874329 Added offhand slot display and manipulation 2016-03-01 11:44:38 -05:00
Jikoo
a623af5119 1.9.0 2016-03-01 00:52:57 -05:00
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
19 changed files with 178 additions and 696 deletions

View File

@@ -26,14 +26,17 @@ import org.bukkit.permissions.Permissible;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; 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.internal.IAnySilentChest; import com.lishid.openinv.internal.IAnySilentChest;
import com.lishid.openinv.internal.IInventoryAccess; import com.lishid.openinv.internal.IInventoryAccess;
import com.lishid.openinv.internal.IPlayerDataManager; 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.internal.InternalAccessor; import com.lishid.openinv.internal.InternalAccessor;
import com.lishid.openinv.utils.UpdateManager;
/** /**
* Open other player's inventory * Open other player's inventory
@@ -46,14 +49,13 @@ public class OpenInv extends JavaPlugin {
public static HashMap<String, ISpecialPlayerInventory> inventories = new HashMap<String, ISpecialPlayerInventory>(); public static HashMap<String, ISpecialPlayerInventory> inventories = new HashMap<String, ISpecialPlayerInventory>();
public static HashMap<String, ISpecialEnderChest> enderChests = new HashMap<String, ISpecialEnderChest>(); public static HashMap<String, ISpecialEnderChest> enderChests = new HashMap<String, ISpecialEnderChest>();
private UpdateManager updater = new UpdateManager();
public static OpenInv mainPlugin; public static OpenInv mainPlugin;
public static IPlayerDataManager playerLoader; public static IPlayerDataManager playerLoader;
public static IInventoryAccess inventoryAccess; public static IInventoryAccess inventoryAccess;
public static IAnySilentChest anySilentChest; public static IAnySilentChest anySilentChest;
@Override
public void onEnable() { public void onEnable() {
// Get plugin manager // Get plugin manager
PluginManager pm = getServer().getPluginManager(); PluginManager pm = getServer().getPluginManager();
@@ -74,29 +76,22 @@ public class OpenInv extends JavaPlugin {
mainPlugin = this; mainPlugin = this;
FileConfiguration config = getConfig(); FileConfiguration config = getConfig();
config.set("CheckForUpdates", config.getBoolean("CheckForUpdates", true));
config.set("NotifySilentChest", config.getBoolean("NotifySilentChest", true)); config.set("NotifySilentChest", config.getBoolean("NotifySilentChest", true));
config.set("NotifyAnyChest", config.getBoolean("NotifyAnyChest", true)); config.set("NotifyAnyChest", config.getBoolean("NotifyAnyChest", true));
config.set("ItemOpenInvItemID", config.getInt("ItemOpenInvItemID", 280));
config.addDefault("ItemOpenInvItemID", 280);
config.addDefault("CheckForUpdates", true);
config.addDefault("NotifySilentChest", true); config.addDefault("NotifySilentChest", true);
config.addDefault("NotifyAnyChest", true); config.addDefault("NotifyAnyChest", true);
config.options().copyDefaults(true); config.options().copyDefaults(true);
saveConfig(); saveConfig();
pm.registerEvents(new OpenInvPlayerListener(), this); pm.registerEvents(new OpenInvPlayerListener(), this);
pm.registerEvents(new OpenInvEntityListener(), this);
pm.registerEvents(new OpenInvInventoryListener(), this); pm.registerEvents(new OpenInvInventoryListener(), this);
getCommand("openinv").setExecutor(new OpenInvPluginCommand(this)); getCommand("openinv").setExecutor(new OpenInvPluginCommand(this));
getCommand("searchinv").setExecutor(new SearchInvPluginCommand()); getCommand("searchinv").setExecutor(new SearchInvPluginCommand());
getCommand("toggleopeninv").setExecutor(new ToggleOpenInvPluginCommand());
getCommand("silentchest").setExecutor(new SilentChestPluginCommand(this)); getCommand("silentchest").setExecutor(new SilentChestPluginCommand(this));
getCommand("anychest").setExecutor(new AnyChestPluginCommand(this)); getCommand("anychest").setExecutor(new AnyChestPluginCommand(this));
getCommand("openender").setExecutor(new OpenEnderPluginCommand(this)); getCommand("openender").setExecutor(new OpenEnderPluginCommand(this));
updater.Initialize(this, getFile());
} }
public static boolean NotifySilentChest() { public static boolean NotifySilentChest() {

View File

@@ -1,52 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* 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
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
public class OpenInvEntityListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST)
public void onEntityDamage(EntityDamageEvent event) {
if (event instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent evt = (EntityDamageByEntityEvent) event;
Entity attacker = evt.getDamager();
Entity defender = evt.getEntity();
if (!(attacker instanceof Player) || !(defender instanceof Player)) {
return;
}
Player player = (Player) attacker;
if (!(player.getItemInHand().getType().getId() == OpenInv.GetItemOpenInvItem()) || (!OpenInv.GetPlayerItemOpenInvStatus(player.getName())) || !OpenInv.hasPermission(player, "OpenInv.openinv")) {
return;
}
Player target = (Player) defender;
player.performCommand("openinv " + target.getName());
evt.setDamage(0);
evt.setCancelled(true);
}
}
}

View File

@@ -20,6 +20,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
public class OpenInvInventoryListener implements Listener { public class OpenInvInventoryListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
@@ -32,4 +33,11 @@ public class OpenInvInventoryListener implements Listener {
} }
// } // }
} }
@EventHandler(priority = EventPriority.NORMAL)
public void onInventoryDrag(InventoryDragEvent event) {
if (!OpenInv.inventoryAccess.check(event.getInventory(), event.getWhoClicked())) {
event.setCancelled(true);
}
}
} }

View File

@@ -121,13 +121,5 @@ public class OpenInvPlayerListener implements Listener {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (!(player.getItemInHand().getType().getId() == OpenInv.GetItemOpenInvItem()) || (!OpenInv.GetPlayerItemOpenInvStatus(player.getName())) || !OpenInv.hasPermission(player, Permissions.PERM_OPENINV)) {
return;
}
player.performCommand("openinv");
}
} }
} }

View File

@@ -23,22 +23,18 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv; import com.lishid.openinv.OpenInv;
import com.lishid.openinv.Permissions;
public class AnyChestPluginCommand implements CommandExecutor { public class AnyChestPluginCommand implements CommandExecutor {
public AnyChestPluginCommand(OpenInv plugin) { public AnyChestPluginCommand(OpenInv plugin) {
} }
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, 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 (!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.length > 0) {
if (args[0].equalsIgnoreCase("check")) { if (args[0].equalsIgnoreCase("check")) {

View File

@@ -43,17 +43,12 @@ public class OpenEnderPluginCommand implements CommandExecutor {
} }
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, 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 (!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("?")) { if (args.length > 0 && args[0].equalsIgnoreCase("?")) {
OpenInv.ShowHelp((Player) sender); OpenInv.ShowHelp((Player) sender);
return true; return true;
@@ -79,7 +74,6 @@ public class OpenEnderPluginCommand implements CommandExecutor {
name = args[0]; name = args[0];
} }
sender.sendMessage(ChatColor.GREEN + "Starting inventory lookup.");
final UUID senderID = player.getUniqueId(); final UUID senderID = player.getUniqueId();
new BukkitRunnable() { new BukkitRunnable() {
@Override @Override

View File

@@ -43,15 +43,11 @@ public class OpenInvPluginCommand implements CommandExecutor {
} }
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, 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 (!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("?")) { if (args.length > 0 && args[0].equalsIgnoreCase("?")) {
OpenInv.ShowHelp((Player) sender); OpenInv.ShowHelp((Player) sender);

View File

@@ -24,22 +24,13 @@ 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;
import com.lishid.openinv.Permissions;
public class SearchInvPluginCommand implements CommandExecutor { public class SearchInvPluginCommand implements CommandExecutor {
public SearchInvPluginCommand() { public SearchInvPluginCommand() {
} }
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { 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 = ""; String PlayerList = "";
Material material = null; Material material = null;

View File

@@ -23,22 +23,18 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv; import com.lishid.openinv.OpenInv;
import com.lishid.openinv.Permissions;
public class SilentChestPluginCommand implements CommandExecutor { public class SilentChestPluginCommand implements CommandExecutor {
public SilentChestPluginCommand(OpenInv plugin) { public SilentChestPluginCommand(OpenInv plugin) {
} }
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, 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 (!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.length > 0) {
if (args[0].equalsIgnoreCase("check")) { if (args[0].equalsIgnoreCase("check")) {

View File

@@ -1,60 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* 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
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.commands;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
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 ToggleOpenInvPluginCommand implements CommandExecutor {
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) {
if (args[0].equalsIgnoreCase("check")) {
if (OpenInv.GetPlayerItemOpenInvStatus(player.getName()))
player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.GetItemOpenInvItem()).toString() + " is ON.");
else
player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.GetItemOpenInvItem()).toString() + " is OFF.");
}
}
if (OpenInv.GetPlayerItemOpenInvStatus(player.getName())) {
OpenInv.SetPlayerItemOpenInvStatus(player.getName(), false);
player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.GetItemOpenInvItem()).toString() + " is OFF.");
}
else {
OpenInv.SetPlayerItemOpenInvStatus(player.getName(), true);
player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.GetItemOpenInvItem()).toString() + " is ON.");
}
return true;
}
}

View File

@@ -14,7 +14,7 @@
* 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.v1_8_R2; package com.lishid.openinv.internal.v1_9_R1;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -23,45 +23,73 @@ import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.IAnySilentChest; import com.lishid.openinv.internal.IAnySilentChest;
//Volatile //Volatile
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
import net.minecraft.server.v1_8_R2.Block; import net.minecraft.server.v1_9_R1.AxisAlignedBB;
import net.minecraft.server.v1_8_R2.BlockPosition; import net.minecraft.server.v1_9_R1.Block;
import net.minecraft.server.v1_8_R2.EntityPlayer; import net.minecraft.server.v1_9_R1.BlockPosition;
import net.minecraft.server.v1_8_R2.IInventory; import net.minecraft.server.v1_9_R1.Entity;
import net.minecraft.server.v1_8_R2.ITileInventory; import net.minecraft.server.v1_9_R1.EntityOcelot;
import net.minecraft.server.v1_8_R2.InventoryLargeChest; import net.minecraft.server.v1_9_R1.EntityPlayer;
import net.minecraft.server.v1_8_R2.PacketPlayOutOpenWindow; import net.minecraft.server.v1_9_R1.IInventory;
import net.minecraft.server.v1_8_R2.TileEntityChest; import net.minecraft.server.v1_9_R1.ITileInventory;
import net.minecraft.server.v1_8_R2.World; import net.minecraft.server.v1_9_R1.InventoryLargeChest;
import net.minecraft.server.v1_9_R1.PacketPlayOutOpenWindow;
import net.minecraft.server.v1_9_R1.TileEntityChest;
import net.minecraft.server.v1_9_R1.World;
public class AnySilentChest implements IAnySilentChest { public class AnySilentChest implements IAnySilentChest {
@Override @Override
public boolean IsAnyChestNeeded(Player p, int x, int y, int z) { public boolean IsAnyChestNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle(); EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world; World world = player.world;
// If block on top // If block or ocelot on top
if (world.getType(new BlockPosition(x, y + 1, z)).getBlock().c()) if (world.getType(new BlockPosition(x, y + 1, z)).l() || hasOcelotOnTop(world, x, y, z))
return true; return true;
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock()); int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
// If block next to chest is chest and has a block on top // If block next to chest is chest and has a block or ocelot on top
if ((Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x - 1, y + 1, z)).getBlock().c())) if (isBlockedChest(world, id, x - 1, y, z))
return true; return true;
if ((Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x + 1, y + 1, z)).getBlock().c())) if (isBlockedChest(world, id, x + 1, y, z))
return true; return true;
if ((Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z - 1)).getBlock().c())) if (isBlockedChest(world, id, x, y, z - 1))
return true; return true;
if ((Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z + 1)).getBlock().c())) if (isBlockedChest(world, id, x, y, z + 1))
return true; return true;
return false; return false;
} }
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
BlockPosition position = new BlockPosition(x, y, z);
if (Block.getId(world.getType(position).getBlock()) != id) {
return false;
}
if (world.getType(position).l()) {
return true;
}
return hasOcelotOnTop(world, x, y, z);
}
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
for (Entity localEntity : world.a(EntityOcelot.class,
new AxisAlignedBB(x, y + 1, z, x + 1, y + 2, z + 1))) {
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
if (localEntityOcelot.isSitting()) {
return true;
}
}
return false;
}
@Override @Override
public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) { public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
EntityPlayer player = ((CraftPlayer) p).getHandle(); EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world; World world = player.world;
Object chest = world.getTileEntity(new BlockPosition(x, y, z)); Object chest = world.getTileEntity(new BlockPosition(x, y, z));
@@ -71,15 +99,15 @@ public class AnySilentChest implements IAnySilentChest {
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock()); int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
if (!anychest) { if (!anychest) {
if (world.getType(new BlockPosition(x, y + 1, z)).getBlock().c()) if (world.getType(new BlockPosition(x, y + 1, z)).l())
return true; return true;
if ((Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x - 1, y + 1, z)).getBlock().c())) if ((Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x - 1, y + 1, z)).l()))
return true; return true;
if ((Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x + 1, y + 1, z)).getBlock().c())) if ((Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x + 1, y + 1, z)).l()))
return true; return true;
if ((Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z - 1)).getBlock().c())) if ((Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z - 1)).l()))
return true; return true;
if ((Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z + 1)).getBlock().c())) if ((Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z + 1)).l()))
return true; return true;
} }

View File

@@ -14,7 +14,7 @@
* 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.v1_8_R2; package com.lishid.openinv.internal.v1_9_R1;
import java.lang.reflect.Field; import java.lang.reflect.Field;
@@ -25,14 +25,14 @@ import com.lishid.openinv.OpenInv;
import com.lishid.openinv.Permissions; import com.lishid.openinv.Permissions;
import com.lishid.openinv.internal.IInventoryAccess; import com.lishid.openinv.internal.IInventoryAccess;
import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftInventory;
//Volatile //Volatile
import net.minecraft.server.v1_8_R2.IInventory; import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftInventory;
import net.minecraft.server.v1_9_R1.IInventory;
public class InventoryAccess implements IInventoryAccess { public class InventoryAccess implements IInventoryAccess {
@Override @Override
public boolean check(Inventory inventory, HumanEntity player) { public boolean check(Inventory inventory, HumanEntity player) {
IInventory inv = grabInventory(inventory); IInventory inv = grabInventory(inventory);
if (inv instanceof SpecialPlayerInventory) { if (inv instanceof SpecialPlayerInventory) {

View File

@@ -14,7 +14,7 @@
* 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.v1_8_R2; package com.lishid.openinv.internal.v1_9_R1;
import java.io.File; import java.io.File;
import java.util.UUID; import java.util.UUID;
@@ -27,16 +27,16 @@ import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.IPlayerDataManager; import com.lishid.openinv.internal.IPlayerDataManager;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import org.bukkit.craftbukkit.v1_8_R2.CraftServer;
import net.minecraft.server.v1_8_R2.EntityPlayer;
//Volatile //Volatile
import net.minecraft.server.v1_8_R2.MinecraftServer; import org.bukkit.craftbukkit.v1_9_R1.CraftServer;
import net.minecraft.server.v1_8_R2.PlayerInteractManager;
import net.minecraft.server.v1_9_R1.EntityPlayer;
import net.minecraft.server.v1_9_R1.MinecraftServer;
import net.minecraft.server.v1_9_R1.PlayerInteractManager;
public class PlayerDataManager implements IPlayerDataManager { public class PlayerDataManager implements IPlayerDataManager {
@Override @Override
public Player loadPlayer(String name) { public Player loadPlayer(String name) {
try { try {
UUID uuid = matchUser(name); UUID uuid = matchUser(name);
if (uuid == null) { if (uuid == null) {
@@ -110,7 +110,7 @@ public class PlayerDataManager implements IPlayerDataManager {
*/ */
@Override @Override
public Player loadPlayer(UUID uuid) { public Player loadPlayer(UUID uuid) {
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid); OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
if (player == null || !player.hasPlayedBefore()) { if (player == null || !player.hasPlayedBefore()) {
return null; return null;
} }

View File

@@ -14,12 +14,12 @@
* 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.v1_8_R2; package com.lishid.openinv.internal.v1_9_R1;
//Volatile //Volatile
import net.minecraft.server.v1_8_R2.ContainerChest; import net.minecraft.server.v1_9_R1.ContainerChest;
import net.minecraft.server.v1_8_R2.EntityHuman; import net.minecraft.server.v1_9_R1.EntityHuman;
import net.minecraft.server.v1_8_R2.IInventory; import net.minecraft.server.v1_9_R1.IInventory;
public class SilentContainerChest extends ContainerChest { public class SilentContainerChest extends ContainerChest {
public IInventory inv; public IInventory inv;

View File

@@ -14,7 +14,7 @@
* 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.v1_8_R2; package com.lishid.openinv.internal.v1_9_R1;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
@@ -28,16 +28,16 @@ import org.bukkit.inventory.InventoryHolder;
import com.lishid.openinv.OpenInv; import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialEnderChest; import com.lishid.openinv.internal.ISpecialEnderChest;
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftInventory;
//Volatile //Volatile
import net.minecraft.server.v1_8_R2.EntityHuman; import org.bukkit.craftbukkit.v1_9_R1.entity.CraftHumanEntity;
import net.minecraft.server.v1_8_R2.IInventory; import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
import net.minecraft.server.v1_8_R2.InventoryEnderChest; import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftInventory;
import net.minecraft.server.v1_8_R2.InventorySubcontainer;
import net.minecraft.server.v1_8_R2.ItemStack; import net.minecraft.server.v1_9_R1.EntityHuman;
import net.minecraft.server.v1_9_R1.IInventory;
import net.minecraft.server.v1_9_R1.InventoryEnderChest;
import net.minecraft.server.v1_9_R1.InventorySubcontainer;
import net.minecraft.server.v1_9_R1.ItemStack;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
public List<HumanEntity> transaction = new ArrayList<HumanEntity>(); public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
@@ -57,12 +57,12 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
} }
@Override @Override
public Inventory getBukkitInventory() { public Inventory getBukkitInventory() {
return inventory; return inventory;
} }
@Override @Override
public void InventoryRemovalCheck() { public void InventoryRemovalCheck() {
owner.saveData(); owner.saveData();
if (transaction.isEmpty() && !playerOnline) { if (transaction.isEmpty() && !playerOnline) {
OpenInv.enderChests.remove(owner.getName().toLowerCase()); OpenInv.enderChests.remove(owner.getName().toLowerCase());
@@ -70,7 +70,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
} }
@Override @Override
public void PlayerGoOnline(Player p) { public void PlayerGoOnline(Player p) {
if (!playerOnline) { if (!playerOnline) {
try { try {
InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest(); InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest();
@@ -85,48 +85,48 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
} }
@Override @Override
public void PlayerGoOffline() { public void PlayerGoOffline() {
playerOnline = false; playerOnline = false;
} }
@Override @Override
public ItemStack[] getContents() { public ItemStack[] getContents() {
return this.items; return this.items;
} }
@Override @Override
public void onOpen(CraftHumanEntity who) { public void onOpen(CraftHumanEntity who) {
transaction.add(who); transaction.add(who);
} }
@Override @Override
public void onClose(CraftHumanEntity who) { public void onClose(CraftHumanEntity who) {
transaction.remove(who); transaction.remove(who);
this.InventoryRemovalCheck(); this.InventoryRemovalCheck();
} }
@Override @Override
public List<HumanEntity> getViewers() { public List<HumanEntity> getViewers() {
return transaction; return transaction;
} }
@Override @Override
public InventoryHolder getOwner() { public InventoryHolder getOwner() {
return this.owner; return this.owner;
} }
@Override @Override
public void setMaxStackSize(int size) { public void setMaxStackSize(int size) {
maxStack = size; maxStack = size;
} }
@Override @Override
public int getMaxStackSize() { public int getMaxStackSize() {
return maxStack; return maxStack;
} }
@Override @Override
public boolean a(EntityHuman entityhuman) { public boolean a(EntityHuman entityhuman) {
return true; return true;
} }
@@ -139,7 +139,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
} }
@Override @Override
public void update() { public void update() {
enderChest.update(); enderChest.update();
} }
} }

View File

@@ -14,7 +14,10 @@
* 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.v1_8_R2; package com.lishid.openinv.internal.v1_9_R1;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
@@ -23,13 +26,13 @@ import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialPlayerInventory; import com.lishid.openinv.internal.ISpecialPlayerInventory;
//Volatile //Volatile
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v1_9_R1.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftInventory;
import net.minecraft.server.v1_8_R2.EntityHuman; import net.minecraft.server.v1_9_R1.EntityHuman;
import net.minecraft.server.v1_8_R2.ItemStack; import net.minecraft.server.v1_9_R1.ItemStack;
import net.minecraft.server.v1_8_R2.PlayerInventory; import net.minecraft.server.v1_9_R1.PlayerInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
CraftPlayer owner; CraftPlayer owner;
@@ -41,11 +44,30 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
super(((CraftPlayer) p).getHandle()); super(((CraftPlayer) p).getHandle());
this.owner = ((CraftPlayer) p); this.owner = ((CraftPlayer) p);
this.playerOnline = online; this.playerOnline = online;
this.items = player.inventory.items; setItemArrays(this, player.inventory.items, player.inventory.armor, player.inventory.extraSlots);
this.armor = player.inventory.armor;
OpenInv.inventories.put(owner.getName().toLowerCase(), this); OpenInv.inventories.put(owner.getName().toLowerCase(), this);
} }
private void setItemArrays(PlayerInventory inventory, ItemStack[] items, ItemStack[] armor,
ItemStack[] extraSlots) {
try {
Field field = inventory.getClass().getField("items");
Field modifiers = Field.class.getDeclaredField("modifiers");
modifiers.setAccessible(true);
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(inventory, items);
field = inventory.getClass().getField("armor");
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(inventory, armor);
field = inventory.getClass().getField("extraSlots");
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException
| IllegalAccessException e) {
// Unable to set final fields to item arrays, we're screwed. Noisily fail.
e.printStackTrace();
}
}
@Override @Override
public Inventory getBukkitInventory() { public Inventory getBukkitInventory() {
return inventory; return inventory;
@@ -63,8 +85,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
public void PlayerGoOnline(Player player) { public void PlayerGoOnline(Player player) {
if (!playerOnline) { if (!playerOnline) {
CraftPlayer p = (CraftPlayer) player; CraftPlayer p = (CraftPlayer) player;
p.getHandle().inventory.items = this.items; setItemArrays(p.getHandle().inventory, items, armor, extraSlots);
p.getHandle().inventory.armor = this.armor;
p.saveData(); p.saveData();
playerOnline = true; playerOnline = true;
} }
@@ -109,12 +130,19 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
if (i >= is.length) { if (i >= is.length) {
i -= is.length; i -= is.length;
is = this.extra; is = this.extraSlots;
} }
else if (is == this.armor) { else if (is == this.armor) {
i = getReversedArmorSlotNum(i); i = getReversedArmorSlotNum(i);
} }
if (i >= is.length) {
i -= is.length;
is = this.extra;
}
// extraSlots is, for now, just an array with length 1. No need for special handling.
return is[i]; return is[i];
} }
@@ -132,12 +160,17 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
if (i >= is.length) { if (i >= is.length) {
i -= is.length; i -= is.length;
is = this.extra; is = this.extraSlots;
} }
else if (is == this.armor) { else if (is == this.armor) {
i = getReversedArmorSlotNum(i); i = getReversedArmorSlotNum(i);
} }
if (i >= is.length) {
i -= is.length;
is = this.extra;
}
if (is[i] != null) { if (is[i] != null) {
ItemStack itemstack; ItemStack itemstack;
@@ -147,7 +180,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
return itemstack; return itemstack;
} }
else { else {
itemstack = is[i].a(j); itemstack = is[i].cloneAndSubtract(j);
if (is[i].count == 0) { if (is[i].count == 0) {
is[i] = null; is[i] = null;
} }
@@ -174,12 +207,17 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
if (i >= is.length) { if (i >= is.length) {
i -= is.length; i -= is.length;
is = this.extra; is = this.extraSlots;
} }
else if (is == this.armor) { else if (is == this.armor) {
i = getReversedArmorSlotNum(i); i = getReversedArmorSlotNum(i);
} }
if (i >= is.length) {
i -= is.length;
is = this.extra;
}
if (is[i] != null) { if (is[i] != null) {
ItemStack itemstack = is[i]; ItemStack itemstack = is[i];
@@ -205,12 +243,17 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
if (i >= is.length) { if (i >= is.length) {
i -= is.length; i -= is.length;
is = this.extra; is = this.extraSlots;
} }
else if (is == this.armor) { else if (is == this.armor) {
i = getReversedArmorSlotNum(i); i = getReversedArmorSlotNum(i);
} }
if (i >= is.length) {
i -= is.length;
is = this.extra;
}
// Effects // Effects
if (is == this.extra) { if (is == this.extra) {
owner.getHandle().drop(itemstack, true); owner.getHandle().drop(itemstack, true);

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