More fixes and improvements - continued

This commit is contained in:
ShadowRanger 2015-06-24 19:19:45 +10:00
parent 2f1fd87435
commit 471b631838
15 changed files with 156 additions and 146 deletions

View file

@ -61,9 +61,11 @@ public class ConfigUpdater {
configFile.delete();
}
plugin.getLogger().info("[Config] Backup of old config.yml file created.");
// Get the old config settings
int itemOpenInvItemId = config.getInt("ItemOpenInvItemID", 280);
boolean checkForUpdates = config.getBoolean("CheckForUpdates", true);
// boolean checkForUpdates = config.getBoolean("CheckForUpdates", true);
boolean notifySilentChest = config.getBoolean("NotifySilentChest", true);
boolean notifyAnyChest = config.getBoolean("NotifyAnyChest", true);
@ -92,10 +94,10 @@ public class ConfigUpdater {
plugin.saveDefaultConfig();
plugin.reloadConfig();
config = plugin.getConfig(); // Refresh the referenced config
config = plugin.getConfig(); // Refresh the referenced plugin config
config.set("config-version", "2");
config.set("check-for-updates", checkForUpdates);
config.set("config-version", 2);
// config.set("check-for-updates", checkForUpdates);
config.set("items.open-inv", getMaterialById(itemOpenInvItemId).toString());
config.set("notify.any-chest", notifyAnyChest);
config.set("notify.silent-chest", notifySilentChest);
@ -132,17 +134,20 @@ public class ConfigUpdater {
return null;
}
int total = keys.size();
int converted = 0;
for (String playerName : keys) {
UUID uuid = UUIDUtil.getUUIDOf(playerName);
if (uuid != null) {
boolean toggled = section.getBoolean(playerName + ".toggle", false);
toggles.put(uuid, toggled);
}
else {
plugin.getLogger().warning("Failed to retrieve UUID of player: " + playerName);
converted++;
}
}
plugin.getLogger().info("[Config] Converted (" + converted + "/" + total + ") " + sectionName + " toggle player usernames to UUIDs.");
return toggles;
}

View file

@ -31,6 +31,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import com.lishid.openinv.commands.AnyChestCommand;
import com.lishid.openinv.commands.OpenEnderCommand;
import com.lishid.openinv.commands.OpenInvCommand;
import com.lishid.openinv.commands.SearchEnderCommand;
import com.lishid.openinv.commands.SearchInvCommand;
import com.lishid.openinv.commands.SilentChestCommand;
import com.lishid.openinv.commands.ToggleOpenInvCommand;
@ -63,7 +64,7 @@ public class OpenInv extends JavaPlugin {
// Plugin
mainPlugin = this;
// Config
// Config Updater
ConfigUpdater configUpdater = new ConfigUpdater(this);
configUpdater.checkForUpdates();
@ -90,11 +91,12 @@ public class OpenInv extends JavaPlugin {
private void registerCommands() {
getCommand("openinv").setExecutor(new OpenInvCommand(this));
getCommand("searchinv").setExecutor(new SearchInvCommand());
getCommand("toggleopeninv").setExecutor(new ToggleOpenInvCommand());
getCommand("silentchest").setExecutor(new SilentChestCommand());
getCommand("anychest").setExecutor(new AnyChestCommand());
getCommand("openender").setExecutor(new OpenEnderCommand(this));
getCommand("searchinv").setExecutor(new SearchInvCommand());
getCommand("searchender").setExecutor(new SearchEnderCommand());
getCommand("toggleopeninv").setExecutor(new ToggleOpenInvCommand());
getCommand("anychest").setExecutor(new AnyChestCommand());
getCommand("silentchest").setExecutor(new SilentChestCommand());
}
public static PlayerDataManager getPlayerLoader() {
@ -109,21 +111,19 @@ public class OpenInv extends JavaPlugin {
return anySilentChest;
}
/*
public static Object getFromConfig(String data, Object defaultValue) {
Object val = mainPlugin.getConfig().get(data);
public static Object getFromConfig(String path, Object defaultValue) {
Object val = mainPlugin.getConfig().get(path);
if (val == null) {
mainPlugin.getConfig().set(data, defaultValue);
mainPlugin.getConfig().set(path, defaultValue);
return defaultValue;
}
else {
return val;
}
}
*/
public static void saveToConfig(String data, Object value) {
mainPlugin.getConfig().set(data, value);
public static void saveToConfig(String path, Object value) {
mainPlugin.getConfig().set(path, value);
mainPlugin.saveConfig();
}
@ -174,48 +174,41 @@ public class OpenInv extends JavaPlugin {
saveToConfig("toggles.silent-chest." + player.getUniqueId(), status);
}
/**
* Logs a given message to console.
*
* @param text the text to log
*/
public static void log(String text) {
mainPlugin.getLogger().info("[OpenInv] " + text);
}
/**
* Logs an error to console.
*
* @param e the throwable error to log
*/
public static void log(Throwable e) {
mainPlugin.getLogger().severe("[OpenInv] " + e.toString());
e.printStackTrace();
}
/**
* Sends a specified message to a given CommandSender with the OpenInv prefix.
*
* @param sender the CommandSender to message
* @param message the message to send to the player
*/
public static void sendMessage(CommandSender sender, String message) {
sender.sendMessage(ChatColor.AQUA + "[OpenInv] " + ChatColor.WHITE + message);
}
public static void showHelp(Player player) {
player.sendMessage(ChatColor.GREEN + "/openinv <player> - Open a player's inventory");
player.sendMessage(ChatColor.GREEN + "/openinv <player> - Open a player's inventory.");
player.sendMessage(ChatColor.GREEN + " (aliases: oi, inv, open)");
player.sendMessage(ChatColor.GREEN + "/openender <player> - Open a player's ender chest");
player.sendMessage(ChatColor.GREEN + " (aliases: oe, enderchest)");
player.sendMessage(ChatColor.GREEN + "/toggleopeninv - Toggle item openinv function");
player.sendMessage(ChatColor.GREEN + " (aliases: toi, toggleoi, toggleinv)");
player.sendMessage(ChatColor.GREEN + "/searchinv <item> [minAmount] - ");
player.sendMessage(ChatColor.GREEN + "/openender <player> - Open a player's ender chest.");
player.sendMessage(ChatColor.GREEN + " (aliases: oe)");
player.sendMessage(ChatColor.GREEN + "/searchinv <item> [minAmount] -");
player.sendMessage(ChatColor.GREEN + " Search and list players having a specific item.");
player.sendMessage(ChatColor.GREEN + " (aliases: si, search)");
player.sendMessage(ChatColor.GREEN + "/anychest - Toggle anychest function");
player.sendMessage(ChatColor.GREEN + " (aliases: si)");
player.sendMessage(ChatColor.GREEN + "/searchender <item> [minAmount] -");
player.sendMessage(ChatColor.GREEN + " Search and list players having a specific item.");
player.sendMessage(ChatColor.GREEN + " (aliases: se)");
player.sendMessage(ChatColor.GREEN + "/toggleopeninv - Toggle the item openinv function.");
player.sendMessage(ChatColor.GREEN + " (aliases: toi, toggleoi, toggleinv)");
player.sendMessage(ChatColor.GREEN + "/anychest - Toggle the any chest function.");
player.sendMessage(ChatColor.GREEN + " (aliases: ac)");
player.sendMessage(ChatColor.GREEN + "/silentchest - Toggle silent chest function");
player.sendMessage(ChatColor.GREEN + "/silentchest - Toggle the silent chest function.");
player.sendMessage(ChatColor.GREEN + " (aliases: sc, silent)");
}

View file

@ -62,7 +62,6 @@ public class OpenEnderCommand implements CommandExecutor {
// History management
UUID history = openEnderHistory.get(player.getUniqueId());
if (history == null) {
history = player.getUniqueId();
openEnderHistory.put(player.getUniqueId(), history);

View file

@ -61,7 +61,6 @@ public class OpenInvCommand implements CommandExecutor {
// History management
UUID history = openInvHistory.get(player.getUniqueId());
if (history == null) {
history = player.getUniqueId();
openInvHistory.put(player.getUniqueId(), history);

View file

@ -16,7 +16,7 @@ public class SearchEnderCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (command.getName().equalsIgnoreCase("searchinv")) {
if (command.getName().equalsIgnoreCase("searchender")) {
if (sender instanceof Player) {
if (!OpenInv.hasPermission(sender, Permissions.PERM_SEARCH)) {
sender.sendMessage(ChatColor.RED + "You do not have permission to search player ender chests.");
@ -28,7 +28,7 @@ public class SearchEnderCommand implements CommandExecutor {
int count = 1;
if (args.length >= 1) {
String[] gData = null;
String[] gData;
gData = args[0].split(":");
material = Material.matchMaterial(gData[0]);
}
@ -50,14 +50,14 @@ public class SearchEnderCommand implements CommandExecutor {
StringBuilder sb = new StringBuilder();
for (Player onlinePlayer : Bukkit.getServer().getOnlinePlayers()) {
if (onlinePlayer.getInventory().contains(material, count)) {
if (onlinePlayer.getEnderChest().contains(material, count)) {
sb.append(onlinePlayer.getName());
sb.append(" ");
}
}
String playerList = sb.toString();
sender.sendMessage("Players with the item " + material.toString() + ": " + playerList);
sender.sendMessage("Players with the item " + ChatColor.GRAY + material.toString() + ChatColor.RESET + " in their ender chest: " + playerList);
return true;
}

View file

@ -42,7 +42,7 @@ public class SearchInvCommand implements CommandExecutor {
int count = 1;
if (args.length >= 1) {
String[] gData = null;
String[] gData;
gData = args[0].split(":");
material = Material.matchMaterial(gData[0]);
}
@ -71,7 +71,7 @@ public class SearchInvCommand implements CommandExecutor {
}
String playerList = sb.toString();
sender.sendMessage("Players with the item " + material.toString() + ": " + playerList);
sender.sendMessage("Players with the item " + ChatColor.GRAY + material.toString() + ChatColor.RESET + " in their inventory: " + playerList);
return true;
}

View file

@ -22,7 +22,7 @@ import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
//Volatile
// Volatile
import net.minecraft.server.v1_8_R3.*;
import org.bukkit.craftbukkit.v1_8_R3.entity.*;
@ -125,7 +125,7 @@ public class AnySilentChest {
if (silentChest) {
tileInventory = new SilentInventory(tileInventory);
if (OpenInv.notifySilentChest()) {
p.sendMessage("You are opening a chest silently.");
OpenInv.sendMessage(p, "You are opening a chest silently.");
}
returnValue = false;
}
@ -133,7 +133,7 @@ public class AnySilentChest {
player.openContainer(tileInventory);
if (anyChest && OpenInv.notifyAnyChest()) {
p.sendMessage("You are opening a blocked chest.");
OpenInv.sendMessage(p, "You are opening a blocked chest.");
}
return returnValue;

View file

@ -24,7 +24,7 @@ import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.Permissions;
//Volatile
// Volatile
import net.minecraft.server.v1_8_R3.*;
import org.bukkit.craftbukkit.v1_8_R3.inventory.*;
@ -53,7 +53,7 @@ public class InventoryAccess {
return ((CraftInventory) inventory).getInventory();
}
//Use reflection to find the inventory
// Use reflection to find the inventory
Class<? extends Inventory> clazz = inventory.getClass();
IInventory result = null;
for(Field f : clazz.getDeclaredFields()) {

View file

@ -25,7 +25,7 @@ import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
import com.mojang.authlib.GameProfile;
//Volatile
// Volatile
import net.minecraft.server.v1_8_R3.*;
import org.bukkit.craftbukkit.v1_8_R3.*;

View file

@ -16,7 +16,7 @@
package com.lishid.openinv.internal;
//Volatile
// Volatile
import net.minecraft.server.v1_8_R3.*;
public class SilentContainerChest extends ContainerChest {
@ -25,7 +25,7 @@ public class SilentContainerChest extends ContainerChest {
public SilentContainerChest(IInventory i1, IInventory i2, EntityHuman human) {
super(i1, i2, human);
inv = i2;
// close signal
// Close signal
inv.closeContainer(human);
}

View file

@ -6,7 +6,7 @@ import org.bukkit.craftbukkit.v1_8_R3.entity.CraftHumanEntity;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.InventoryHolder;
//Volatile
// Volatile
import net.minecraft.server.v1_8_R3.*;
public class SilentInventory implements ITileInventory {
@ -73,12 +73,12 @@ public class SilentInventory implements ITileInventory {
@Override
public void startOpen(EntityHuman entityHuman) {
//Don't do anything
// Don't do anything
}
@Override
public void closeContainer(EntityHuman entityHuman) {
//Don't do anything
// Don't do anything
}
@Override
@ -153,7 +153,7 @@ public class SilentInventory implements ITileInventory {
@Override
public Container createContainer(PlayerInventory playerInventory, EntityHuman entityHuman) {
//Don't let the chest itself create the container.
// Don't let the chest itself create the container.
return new ContainerChest(playerInventory, this, entityHuman);
}

View file

@ -22,8 +22,9 @@ import org.bukkit.inventory.InventoryHolder;
import com.lishid.openinv.OpenInv;
//Volatile
// Volatile
import net.minecraft.server.v1_8_R3.*;
import org.bukkit.craftbukkit.v1_8_R3.entity.*;
import org.bukkit.craftbukkit.v1_8_R3.inventory.*;
@ -31,17 +32,17 @@ public class SpecialEnderChest extends InventorySubcontainer {
private final CraftInventory inventory = new CraftInventory(this);
private final InventoryEnderChest enderChest;
private final CraftPlayer owner;
private boolean playerOnline = false;
private boolean playerOnline;
public SpecialEnderChest(Player p, Boolean online) {
public SpecialEnderChest(Player p, boolean online) {
this(p, ((CraftPlayer) p).getHandle().getEnderChest(), online);
}
public SpecialEnderChest(Player p, InventoryEnderChest enderchest, boolean online) {
super(enderchest.getName(), enderchest.hasCustomName(), enderchest.getSize());
public SpecialEnderChest(Player p, InventoryEnderChest enderChest, boolean online) {
super(enderChest.getName(), enderChest.hasCustomName(), enderChest.getSize());
this.owner = (CraftPlayer) p;
this.enderChest = enderchest;
this.items = enderChest.getContents();
this.enderChest = enderChest;
this.items = this.enderChest.getContents();
this.playerOnline = online;
OpenInv.enderChests.put(owner.getUniqueId(), this);
}

View file

@ -21,8 +21,9 @@ import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
//Volatile
// Volatile
import net.minecraft.server.v1_8_R3.*;
import org.bukkit.craftbukkit.v1_8_R3.entity.*;
import org.bukkit.craftbukkit.v1_8_R3.inventory.*;
@ -30,7 +31,7 @@ public class SpecialPlayerInventory extends PlayerInventory {
private final CraftInventory inventory = new CraftInventory(this);
private final ItemStack[] extra = new ItemStack[5];
private final CraftPlayer owner;
private boolean playerOnline = false;
private boolean playerOnline;
public SpecialPlayerInventory(Player p, boolean online) {
super(((CraftPlayer) p).getHandle());

View file

@ -67,7 +67,7 @@ public class OpenInvPlayerListener implements Listener {
}
}
@EventHandler(priority = EventPriority.MONITOR)
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
@ -76,70 +76,76 @@ public class OpenInvPlayerListener implements Listener {
}
Action action = event.getAction();
if (action == Action.RIGHT_CLICK_BLOCK && event.useInteractedBlock() == Result.DENY) {
return;
}
Block block = event.getClickedBlock();
if (action == Action.RIGHT_CLICK_BLOCK && block.getType() == Material.ENDER_CHEST) {
if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && OpenInv.getPlayerSilentChestStatus(player)) {
event.setCancelled(true);
player.openInventory(player.getEnderChest());
}
}
if (action == Action.RIGHT_CLICK_BLOCK && block.getState() instanceof Chest) {
boolean silentChest = false;
boolean anyChest = false;
int x = block.getX();
int y = block.getY();
int z = block.getZ();
if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && OpenInv.getPlayerSilentChestStatus(player)) {
silentChest = true;
}
if (OpenInv.hasPermission(player, Permissions.PERM_ANYCHEST) && OpenInv.getPlayerAnyChestStatus(player)) {
try {
anyChest = OpenInv.getAnySilentChest().isAnyChestNeeded(player, x, y, z);
switch (action) {
case RIGHT_CLICK_BLOCK:
if (event.useInteractedBlock() == Result.DENY) {
return;
}
catch (Exception e) {
player.sendMessage(ChatColor.RED + "Error while executing openinv. Unsupported CraftBukkit.");
e.printStackTrace();
// Ender Chests
if (block.getType() == Material.ENDER_CHEST) {
if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && OpenInv.getPlayerSilentChestStatus(player)) {
event.setCancelled(true);
player.openInventory(player.getEnderChest());
return;
}
}
}
// If the anychest or silentchest is active
if (anyChest || silentChest) {
if (!OpenInv.getAnySilentChest().activateChest(player, anyChest, silentChest, x, y, z)) {
event.setCancelled(true);
// Chests
if (block.getState() instanceof Chest) {
boolean silentChest = false;
boolean anyChest = false;
int x = block.getX();
int y = block.getY();
int z = block.getZ();
if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && OpenInv.getPlayerSilentChestStatus(player)) {
silentChest = true;
}
if (OpenInv.hasPermission(player, Permissions.PERM_ANYCHEST) && OpenInv.getPlayerAnyChestStatus(player)) {
try {
anyChest = OpenInv.getAnySilentChest().isAnyChestNeeded(player, x, y, z);
}
catch (Exception e) {
player.sendMessage(ChatColor.RED + "Error while executing openinv. Unsupported CraftBukkit.");
e.printStackTrace();
}
}
// If the anyChest or silentChest is active
if (anyChest || silentChest) {
if (!OpenInv.getAnySilentChest().activateChest(player, anyChest, silentChest, x, y, z)) {
event.setCancelled(true);
}
}
return;
}
}
}
if (action == Action.RIGHT_CLICK_BLOCK && block.getState() instanceof Sign) {
try {
Sign sign = ((Sign) block.getState());
if (OpenInv.hasPermission(player, Permissions.PERM_OPENINV) && sign.getLine(0).equalsIgnoreCase("[openinv]")) {
String text = sign.getLine(1).trim() + sign.getLine(2).trim() + sign.getLine(3).trim();
player.performCommand("openinv " + text);
// Signs
if (block.getState() instanceof Sign) {
try {
Sign sign = ((Sign) block.getState());
if (OpenInv.hasPermission(player, Permissions.PERM_OPENINV) && sign.getLine(0).equalsIgnoreCase("[openinv]")) {
String text = sign.getLine(1).trim() + sign.getLine(2).trim() + sign.getLine(3).trim();
player.performCommand("openinv " + text);
}
}
catch (Exception e) {
player.sendMessage("Internal Error.");
e.printStackTrace();
}
return;
}
case RIGHT_CLICK_AIR:
// OpenInv item
if (player.getItemInHand().getType() == OpenInv.getOpenInvItem() && OpenInv.getPlayerItemOpenInvStatus(player) && OpenInv.hasPermission(player, Permissions.PERM_OPENINV)) {
player.performCommand("openinv");
}
}
catch (Exception ex) {
player.sendMessage("Internal Error.");
ex.printStackTrace();
}
}
if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) {
if (!(player.getItemInHand().getType() == OpenInv.getOpenInvItem()) || (!OpenInv.getPlayerItemOpenInvStatus(player)) || !OpenInv.hasPermission(player, Permissions.PERM_OPENINV)) {
return;
}
player.performCommand("openinv");
}
}
}

View file

@ -7,32 +7,38 @@ description: >
commands:
openinv:
aliases: [oi, inv, open]
description: Open a player's inventory
description: Open a player's inventory.
usage: |
/<command> - Open last person's inventory
/<command> <Player> - Open a player's inventory
/<command> - Opens last person's inventory.
/<command> <player> - Opens a player's inventory.
openender:
aliases: [oe]
description: Opens the enderchest of a player
description: Opens a player's ender chest.
usage: |
/<command> <Player> - Opens a player's enderchest
/<command> - Opens last person's ender chest.
/<command> <player> - Opens a player's ender chest.
searchinv:
aliases: [si]
description: Search and list players having a specific item
description: Searches and lists players that have a specific item in their inventory.
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.
searchender:
aliases: [se]
description: Searches and lists players that have a specific item in their ender chest.
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
description: Toggles the 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.
usage: |
/<command> [Check] - Checks whether silent chest is enabled
/<command> [check] - Checks whether item openinv is enabled.
anychest:
aliases: [ac]
description: Toggle anychest function, which allows opening of blocked chests.
description: Toggles the any chest function, which allows opening of blocked chests.
usage: |
/<command> [Check] - Checks whether anychest is enabled
/<command> [check] - Checks whether any chest is enabled.
silentchest:
aliases: [sc, silent]
description: Toggles the silent chest function, which hides the animation of a chest when opened or closed, and suppresses the sound.
usage: |
/<command> [check] - Checks whether silent chest is enabled.