Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
3549431fbc | ||
|
17b0cb6efe | ||
|
2d7522554c | ||
|
131f874329 | ||
|
a623af5119 | ||
|
8f17bd0237 | ||
|
20fb61705d | ||
|
c0f513177a | ||
|
b3a3947b03 | ||
|
c7bab7d451 | ||
|
4058463f7f |
@@ -26,14 +26,17 @@ 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.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 +49,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,29 +76,22 @@ 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));
|
||||
config.addDefault("ItemOpenInvItemID", 280);
|
||||
config.addDefault("CheckForUpdates", true);
|
||||
config.addDefault("NotifySilentChest", true);
|
||||
config.addDefault("NotifyAnyChest", true);
|
||||
config.options().copyDefaults(true);
|
||||
saveConfig();
|
||||
|
||||
pm.registerEvents(new OpenInvPlayerListener(), this);
|
||||
pm.registerEvents(new OpenInvEntityListener(), this);
|
||||
pm.registerEvents(new OpenInvInventoryListener(), this);
|
||||
|
||||
getCommand("openinv").setExecutor(new OpenInvPluginCommand(this));
|
||||
getCommand("searchinv").setExecutor(new SearchInvPluginCommand());
|
||||
getCommand("toggleopeninv").setExecutor(new ToggleOpenInvPluginCommand());
|
||||
getCommand("silentchest").setExecutor(new SilentChestPluginCommand(this));
|
||||
getCommand("anychest").setExecutor(new AnyChestPluginCommand(this));
|
||||
getCommand("openender").setExecutor(new OpenEnderPluginCommand(this));
|
||||
|
||||
updater.Initialize(this, getFile());
|
||||
}
|
||||
|
||||
public static boolean NotifySilentChest() {
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -20,6 +20,7 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||
|
||||
public class OpenInvInventoryListener implements Listener {
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -121,13 +121,5 @@ public class OpenInvPlayerListener implements Listener {
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
@@ -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")) {
|
||||
|
@@ -17,6 +17,7 @@
|
||||
package com.lishid.openinv.commands;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -41,17 +42,13 @@ 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;
|
||||
@@ -77,11 +74,15 @@ public class OpenEnderPluginCommand implements CommandExecutor {
|
||||
name = args[0];
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.GREEN + "Starting inventory lookup.");
|
||||
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;
|
||||
|
@@ -17,6 +17,7 @@
|
||||
package com.lishid.openinv.commands;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -41,15 +42,12 @@ 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);
|
||||
@@ -76,11 +74,15 @@ public class OpenInvPluginCommand implements CommandExecutor {
|
||||
name = args[0];
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.GREEN + "Starting inventory lookup.");
|
||||
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;
|
||||
|
@@ -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;
|
||||
|
@@ -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")) {
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -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_9_R1;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -22,59 +22,92 @@ 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_9_R1.entity.CraftPlayer;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_8_R1.entity.*;
|
||||
import net.minecraft.server.v1_9_R1.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_9_R1.Block;
|
||||
import net.minecraft.server.v1_9_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_9_R1.Entity;
|
||||
import net.minecraft.server.v1_9_R1.EntityOcelot;
|
||||
import net.minecraft.server.v1_9_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_9_R1.IInventory;
|
||||
import net.minecraft.server.v1_9_R1.ITileInventory;
|
||||
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 {
|
||||
@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();
|
||||
World world = player.world;
|
||||
// If block on top
|
||||
if (world.getType(new BlockPosition(x, y + 1, z)).getBlock().c())
|
||||
// If block or ocelot on top
|
||||
if (world.getType(new BlockPosition(x, y + 1, z)).l() || hasOcelotOnTop(world, x, y, z))
|
||||
return true;
|
||||
|
||||
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.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x - 1, y + 1, z)).getBlock().c()))
|
||||
// If block next to chest is chest and has a block or ocelot on top
|
||||
if (isBlockedChest(world, id, x - 1, y, z))
|
||||
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;
|
||||
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;
|
||||
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 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
|
||||
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;
|
||||
|
||||
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
||||
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
@@ -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_9_R1;
|
||||
|
||||
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_9_R1.inventory.CraftInventory;
|
||||
|
||||
import net.minecraft.server.v1_9_R1.IInventory;
|
||||
|
||||
public class InventoryAccess implements IInventoryAccess {
|
||||
@Override
|
||||
public boolean check(Inventory inventory, HumanEntity player) {
|
||||
IInventory inv = grabInventory(inventory);
|
||||
|
@@ -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_9_R1;
|
||||
|
||||
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_9_R1.CraftServer;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_8_R1.*;
|
||||
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 {
|
||||
@Override
|
||||
public Player loadPlayer(String name) {
|
||||
try {
|
||||
UUID uuid = matchUser(name);
|
||||
@@ -107,7 +110,7 @@ public class PlayerDataManager implements IPlayerDataManager {
|
||||
*/
|
||||
@Override
|
||||
public Player loadPlayer(UUID uuid) {
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
|
||||
if (player == null || !player.hasPlayedBefore()) {
|
||||
return null;
|
||||
}
|
@@ -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_9_R1;
|
||||
|
||||
//Volatile
|
||||
import net.minecraft.server.v1_8_R1.*;
|
||||
import net.minecraft.server.v1_9_R1.ContainerChest;
|
||||
import net.minecraft.server.v1_9_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_9_R1.IInventory;
|
||||
|
||||
public class SilentContainerChest extends ContainerChest {
|
||||
public IInventory inv;
|
@@ -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_9_R1;
|
||||
|
||||
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_9_R1.entity.CraftHumanEntity;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftInventory;
|
||||
|
||||
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 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();
|
||||
}
|
@@ -14,7 +14,10 @@
|
||||
* 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_9_R1;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
@@ -23,25 +26,48 @@ 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_9_R1.entity.CraftHumanEntity;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftInventory;
|
||||
|
||||
import net.minecraft.server.v1_9_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_9_R1.ItemStack;
|
||||
import net.minecraft.server.v1_9_R1.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());
|
||||
this.owner = ((CraftPlayer) p);
|
||||
this.playerOnline = online;
|
||||
this.items = player.inventory.items;
|
||||
this.armor = player.inventory.armor;
|
||||
setItemArrays(this, player.inventory.items, player.inventory.armor, player.inventory.extraSlots);
|
||||
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
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
@@ -59,8 +85,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
|
||||
public void PlayerGoOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
CraftPlayer p = (CraftPlayer) player;
|
||||
p.getHandle().inventory.items = this.items;
|
||||
p.getHandle().inventory.armor = this.armor;
|
||||
setItemArrays(p.getHandle().inventory, items, armor, extraSlots);
|
||||
p.saveData();
|
||||
playerOnline = true;
|
||||
}
|
||||
@@ -105,12 +130,19 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
is = this.extraSlots;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
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];
|
||||
}
|
||||
|
||||
@@ -128,12 +160,17 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
is = this.extraSlots;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack;
|
||||
|
||||
@@ -143,7 +180,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;
|
||||
}
|
||||
@@ -170,12 +207,17 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
is = this.extraSlots;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack = is[i];
|
||||
|
||||
@@ -201,12 +243,17 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
is = this.extraSlots;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
|
||||
// Effects
|
||||
if (is == this.extra) {
|
||||
owner.getHandle().drop(itemstack, true);
|
@@ -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
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -1,38 +1,39 @@
|
||||
name: OpenInv
|
||||
main: com.lishid.openinv.OpenInv
|
||||
version: 2.2.6
|
||||
version: 2.3.0
|
||||
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
|
||||
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
|
||||
|
Reference in New Issue
Block a user