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

View File

@ -2,7 +2,7 @@ name: Brewery
version: 1.2 version: 1.2
main: com.dre.brewery.P main: com.dre.brewery.P
authors: [Milan Albrecht, Frank Baumann] authors: [Milan Albrecht, Frank Baumann]
softdepend: [LWC] softdepend: [LWC, LogBlock]
commands: commands:
brewery: brewery:
description: Command for Administration description: Command for Administration

17
pom.xml
View File

@ -94,6 +94,15 @@
</snapshots> </snapshots>
</repository> </repository>
<repository>
<id>lb-repo</id>
<url>http://junction.at/repo/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
<repository> <repository>
<id>Plugin Metrics</id> <id>Plugin Metrics</id>
<url>http://repo.mcstats.org/content/repositories/public</url> <url>http://repo.mcstats.org/content/repositories/public</url>
@ -133,6 +142,14 @@
<type>jar</type> <type>jar</type>
</dependency> </dependency>
<dependency>
<groupId>de.diddiz</groupId>
<artifactId>logblock</artifactId>
<version>LATEST</version>
<scope>compile</scope>
<type>jar</type>
</dependency>
<dependency> <dependency>
<groupId>org.mcstats</groupId> <groupId>org.mcstats</groupId>
<artifactId>metrics</artifactId> <artifactId>metrics</artifactId>

View File

@ -16,6 +16,7 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import com.dre.brewery.integration.LWCBarrel; import com.dre.brewery.integration.LWCBarrel;
import com.dre.brewery.integration.LogBlockBarrel;
import com.dre.brewery.integration.WGBarrel; import com.dre.brewery.integration.WGBarrel;
import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.ArrayUtils;
@ -74,7 +75,7 @@ public class Barrel {
if (woodsloc == null && stairsloc == null) { if (woodsloc == null && stairsloc == null) {
Block broken = getBrokenBlock(true); Block broken = getBrokenBlock(true);
if (broken != null) { if (broken != null) {
remove(broken); remove(broken, null);
return; return;
} }
} }
@ -89,7 +90,8 @@ public class Barrel {
broken = barrel.getBrokenBlock(false); broken = barrel.getBrokenBlock(false);
if (broken != null) { if (broken != null) {
// remove the barrel if it was destroyed // remove the barrel if it was destroyed
barrel.remove(broken); barrel.willDestroy();
barrel.remove(broken, null);
continue; continue;
} else { } else {
// Dont check this barrel again, its enough to check it once after every restart // Dont check this barrel again, its enough to check it once after every restart
@ -131,7 +133,12 @@ public class Barrel {
return true; return true;
} }
// Ask for permission to destroy barrel, remove protection if has
public boolean hasPermsDestroy(Player player) { public boolean hasPermsDestroy(Player player) {
if (player == null) {
willDestroy();
return true;
}
if (P.p.hasLWC) { if (P.p.hasLWC) {
return LWCBarrel.checkDestroy(player, this); return LWCBarrel.checkDestroy(player, this);
} }
@ -139,6 +146,13 @@ public class Barrel {
return true; return true;
} }
// If something other than the Player is destroying the barrel, inform protection plugins
public void willDestroy() {
if (P.p.hasLWC) {
LWCBarrel.remove(this);
}
}
// player opens the barrel // player opens the barrel
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void open(Player player) { public void open(Player player) {
@ -173,6 +187,10 @@ public class Barrel {
} }
// reset barreltime, potions have new age // reset barreltime, potions have new age
time = 0; time = 0;
if (P.p.hasLB) {
LogBlockBarrel.openBarrel(player, inventory, spigot.getLocation());
}
player.openInventory(inventory); player.openInventory(inventory);
} }
@ -339,12 +357,15 @@ public class Barrel {
} }
// removes a barrel, throwing included potions to the ground // removes a barrel, throwing included potions to the ground
public void remove(Block broken) { public void remove(Block broken, Player breaker) {
if (inventory != null) { if (inventory != null) {
for (HumanEntity human : inventory.getViewers()) { for (HumanEntity human : inventory.getViewers()) {
human.closeInventory(); human.closeInventory();
} }
ItemStack[] items = inventory.getContents(); ItemStack[] items = inventory.getContents();
if (P.p.hasLB && breaker != null) {
LogBlockBarrel.breakBarrel(breaker.getName(), items, spigot.getLocation());
}
for (ItemStack item : items) { for (ItemStack item : items) {
if (item != null) { if (item != null) {
Brew brew = Brew.get(item); Brew brew = Brew.get(item);

View File

@ -13,6 +13,8 @@ import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import com.dre.brewery.integration.LogBlockBarrel;
import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -35,6 +37,7 @@ public class P extends JavaPlugin {
// Third Party Enabled // Third Party Enabled
public boolean hasLWC; public boolean hasLWC;
public boolean hasLB;
// Listeners // Listeners
public BlockListener blockListener; public BlockListener blockListener;
@ -51,9 +54,6 @@ public class P extends JavaPlugin {
public void onEnable() { public void onEnable() {
p = this; p = this;
// Check Third Party
hasLWC = getServer().getPluginManager().isPluginEnabled("LWC");
readConfig(); readConfig();
readData(); readData();
@ -125,6 +125,9 @@ public class P extends JavaPlugin {
BIngredients.cookedNames.clear(); BIngredients.cookedNames.clear();
Words.words.clear(); Words.words.clear();
BPlayer.drainItems.clear(); BPlayer.drainItems.clear();
if (hasLB) {
LogBlockBarrel.clear();
}
// load the Config // load the Config
readConfig(); readConfig();
@ -164,6 +167,9 @@ public class P extends JavaPlugin {
} }
public void readConfig() { public void readConfig() {
// Check Third Party
hasLWC = getServer().getPluginManager().isPluginEnabled("LWC");
hasLB = getServer().getPluginManager().isPluginEnabled("LogBlock");
File file = new File(p.getDataFolder(), "config.yml"); File file = new File(p.getDataFolder(), "config.yml");
if (!file.exists()) { if (!file.exists()) {
@ -572,7 +578,7 @@ public class P extends JavaPlugin {
} }
} }
// Returns true if the Block can be destroyed by the Player // Returns true if the Block can be destroyed by the Player or something else (null)
public boolean blockDestroy(Block block, Player player) { public boolean blockDestroy(Block block, Player player) {
switch (block.getType()) { switch (block.getType()) {
case CAULDRON: case CAULDRON:
@ -585,7 +591,7 @@ public class P extends JavaPlugin {
Barrel barrel = Barrel.getBySpigot(block); Barrel barrel = Barrel.getBySpigot(block);
if (barrel != null) { if (barrel != null) {
if (barrel.hasPermsDestroy(player)) { if (barrel.hasPermsDestroy(player)) {
barrel.remove(null); barrel.remove(null, player);
return true; return true;
} else { } else {
return false; return false;
@ -599,7 +605,7 @@ public class P extends JavaPlugin {
if (barrel2 != null) { if (barrel2 != null) {
if (!barrel2.isLarge()) { if (!barrel2.isLarge()) {
if (barrel2.hasPermsDestroy(player)) { if (barrel2.hasPermsDestroy(player)) {
barrel2.remove(null); barrel2.remove(null, player);
return true; return true;
} else { } else {
return false; return false;
@ -619,7 +625,7 @@ public class P extends JavaPlugin {
Barrel barrel3 = Barrel.getByWood(block); Barrel barrel3 = Barrel.getByWood(block);
if (barrel3 != null) { if (barrel3 != null) {
if (barrel3.hasPermsDestroy(player)) { if (barrel3.hasPermsDestroy(player)) {
barrel3.remove(block); barrel3.remove(block, player);
} else { } else {
return false; return false;
} }

View File

@ -77,18 +77,26 @@ public class LWCBarrel {
return true; 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 // Returns true if the block that exploded should not be removed
public static boolean blockExplosion(Barrel barrel, Block block) { public static boolean blockExplosion(Barrel barrel, Block block) {
Protection protection = LWC.getInstance().findProtection(barrel.getSignOfSpigot()); Protection protection = LWC.getInstance().findProtection(barrel.getSignOfSpigot());
if (protection == null) { if (protection == null) {
barrel.remove(block); barrel.remove(block, null);
return false; return false;
} }
if (protection.hasFlag(Flag.Type.ALLOWEXPLOSIONS)) { if (protection.hasFlag(Flag.Type.ALLOWEXPLOSIONS)) {
protection.remove(); protection.remove();
barrel.remove(block); barrel.remove(block, null);
return false; return false;
} }
return true; return true;

View File

@ -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();
}
}

View File

@ -4,6 +4,7 @@ import org.bukkit.block.Block;
import org.bukkit.event.EventHandler; 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.block.BlockBurnEvent;
import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.block.SignChangeEvent;
@ -43,6 +44,11 @@ public class BlockListener implements Listener {
} }
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockBurn(BlockBurnEvent event) {
P.p.blockDestroy(event.getBlock(), null);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPistonRetract(BlockPistonRetractEvent event) { public void onPistonRetract(BlockPistonRetractEvent event) {
if (event.isSticky()) { if (event.isSticky()) {

View File

@ -6,6 +6,7 @@ import org.bukkit.block.Block;
import org.bukkit.event.EventHandler; 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.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.ItemDespawnEvent; import org.bukkit.event.entity.ItemDespawnEvent;
import org.bukkit.event.entity.EntityCombustEvent; import org.bukkit.event.entity.EntityCombustEvent;
@ -48,19 +49,32 @@ public class EntityListener implements Listener {
public void onExplode(EntityExplodeEvent event) { public void onExplode(EntityExplodeEvent event) {
ListIterator<Block> iter = event.blockList().listIterator(); ListIterator<Block> iter = event.blockList().listIterator();
Barrel barrel = null; Barrel barrel = null;
boolean removedBarrel = false;
while (iter.hasNext()) { while (iter.hasNext()) {
Block block = iter.next(); Block block = iter.next();
if (barrel == null || !barrel.hasBlock(block)) { if (barrel == null || !barrel.hasBlock(block)) {
barrel = Barrel.get(block); barrel = Barrel.get(block);
removedBarrel = false;
} }
if (!removedBarrel) {
if (barrel != null) { if (barrel != null) {
if (P.p.hasLWC) { if (P.p.hasLWC) {
if (LWCBarrel.blockExplosion(barrel, block)) { if (LWCBarrel.blockExplosion(barrel, block)) {
iter.remove(); iter.remove();
} else {
removedBarrel = true;
}
} }
} }
} }
} }
} }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockChange(EntityChangeBlockEvent event) {
if (Barrel.get(event.getBlock()) != null) {
event.setCancelled(true);
}
}
} }

View File

@ -5,6 +5,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.inventory.BrewEvent; import org.bukkit.event.inventory.BrewEvent;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryPickupItemEvent; import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.BrewerInventory; import org.bukkit.inventory.BrewerInventory;
@ -14,6 +15,7 @@ import org.bukkit.Material;
import com.dre.brewery.Brew; import com.dre.brewery.Brew;
import com.dre.brewery.P; import com.dre.brewery.P;
import com.dre.brewery.integration.LogBlockBarrel;
public class InventoryListener implements Listener { public class InventoryListener implements Listener {
@ -52,7 +54,7 @@ public class InventoryListener implements Listener {
} }
// convert to non colored Lore when taking out of Barrel/Brewer // convert to non colored Lore when taking out of Barrel/Brewer
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent event) { public void onInventoryClick(InventoryClickEvent event) {
if (event.getInventory().getType() == InventoryType.BREWING) { if (event.getInventory().getType() == InventoryType.BREWING) {
if (event.getSlot() > 2) { if (event.getSlot() > 2) {
@ -90,4 +92,15 @@ public class InventoryListener implements Listener {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@EventHandler
public void onInventoryClose(InventoryCloseEvent event) {
if (P.p.hasLB) {
if (event.getInventory().getType() == InventoryType.CHEST) {
if (event.getInventory().getTitle().equals(P.p.languageReader.get("Etc_Barrel"))) {
LogBlockBarrel.closeBarrel(event.getPlayer(), event.getInventory());
}
}
}
}
} }