LogBlock ChestAccess logging Support

This commit is contained in:
Sn0wStorm
2014-04-09 00:35:08 +02:00
parent 1c6fe6cc33
commit 13abf2475c
9 changed files with 180 additions and 18 deletions
+10 -2
View File
@@ -77,18 +77,26 @@ public class LWCBarrel {
return true;
}
// If a Barrel is destroyed without player
public static void remove(Barrel barrel) {
Protection protection = LWC.getInstance().findProtection(barrel.getSignOfSpigot());
if (protection != null) {
protection.remove();
}
}
// Returns true if the block that exploded should not be removed
public static boolean blockExplosion(Barrel barrel, Block block) {
Protection protection = LWC.getInstance().findProtection(barrel.getSignOfSpigot());
if (protection == null) {
barrel.remove(block);
barrel.remove(block, null);
return false;
}
if (protection.hasFlag(Flag.Type.ALLOWEXPLOSIONS)) {
protection.remove();
barrel.remove(block);
barrel.remove(block, null);
return false;
}
return true;
@@ -0,0 +1,77 @@
package com.dre.brewery.integration;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import de.diddiz.LogBlock.Consumer;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import static de.diddiz.LogBlock.config.Config.isLogging;
import static de.diddiz.util.BukkitUtils.compareInventories;
import static de.diddiz.util.BukkitUtils.compressInventory;
import static de.diddiz.util.BukkitUtils.rawData;
public class LogBlockBarrel {
private static final List<LogBlockBarrel> opened = new ArrayList<LogBlockBarrel>();
public static Consumer consumer = LogBlock.getInstance().getConsumer();
private HumanEntity player;
private ItemStack[] items;
private Location loc;
public LogBlockBarrel(HumanEntity player, ItemStack[] items, Location spigotLoc) {
this.player = player;
this.items = items;
this.loc = spigotLoc;
opened.add(this);
}
@SuppressWarnings("deprecation")
private void compareInv(final ItemStack[] after) {
final ItemStack[] diff = compareInventories(items, after);
for (final ItemStack item : diff) {
consumer.queueChestAccess(player.getName(), loc, loc.getWorld().getBlockTypeIdAt(loc), (short) item.getTypeId(), (short) item.getAmount(), rawData(item));
}
}
public static LogBlockBarrel get(HumanEntity player) {
for (LogBlockBarrel open : opened) {
if (open.player.equals(player)) {
return open;
}
}
return null;
}
public static void openBarrel(HumanEntity player, Inventory inv, Location spigotLoc) {
if (!isLogging(player.getWorld(), Logging.CHESTACCESS)) return;
new LogBlockBarrel(player, compressInventory(inv.getContents()), spigotLoc);
}
public static void closeBarrel(HumanEntity player, Inventory inv) {
if (!isLogging(player.getWorld(), Logging.CHESTACCESS)) return;
LogBlockBarrel open = get(player);
if (open != null) {
open.compareInv(compressInventory(inv.getContents()));
opened.remove(open);
}
}
@SuppressWarnings("deprecation")
public static void breakBarrel(String playerName, ItemStack[] contents, Location spigotLoc) {
if (!isLogging(spigotLoc.getWorld(), Logging.CHESTACCESS)) return;
final ItemStack[] items = compressInventory(contents);
for (final ItemStack item : items) {
consumer.queueChestAccess(playerName, spigotLoc, spigotLoc.getWorld().getBlockTypeIdAt(spigotLoc), (short) item.getTypeId(), (short) (item.getAmount() * -1), rawData(item));
}
}
public static void clear() {
opened.clear();
}
}