Update src/net/ardakaz/griefalert/GriefAlert.java
This commit is contained in:
parent
3bc045e799
commit
594523fb38
@ -15,6 +15,8 @@ import org.bukkit.event.block.BlockBreakEvent;
|
|||||||
import org.bukkit.event.inventory.InventoryAction;
|
import org.bukkit.event.inventory.InventoryAction;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.event.inventory.InventoryType;
|
import org.bukkit.event.inventory.InventoryType;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
@ -32,10 +34,12 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
|||||||
private String lastAlert;
|
private String lastAlert;
|
||||||
|
|
||||||
private Set<Material> EXCLUDED_BLOCKS;
|
private Set<Material> EXCLUDED_BLOCKS;
|
||||||
private Set<InventoryType> VALID_CONTAINERS;
|
private Set<InventoryType> VALID_CONTAINERS;
|
||||||
private String MAP_LINK;
|
private String MAP_LINK;
|
||||||
private Boolean ALLOW_STEALING;
|
private Boolean ALLOW_STEALING;
|
||||||
|
|
||||||
|
private AlertsLogic alertsLogic;
|
||||||
|
|
||||||
// Init GriefAlert
|
// Init GriefAlert
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
@ -59,20 +63,47 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
|||||||
ALLOW_STEALING = getConfig().getBoolean("allow-stealing");
|
ALLOW_STEALING = getConfig().getBoolean("allow-stealing");
|
||||||
|
|
||||||
getLogger().info("GriefAlert has been enabled.");
|
getLogger().info("GriefAlert has been enabled.");
|
||||||
|
|
||||||
|
// Initialize AlertsLogic and register commands
|
||||||
|
alertsLogic = new AlertsLogic(this);
|
||||||
|
getCommand("disablelocation").setExecutor(this);
|
||||||
|
getCommand("enablelocation").setExecutor(this);
|
||||||
|
getCommand("clearlocations").setExecutor(this);
|
||||||
|
getCommand("checklocation").setExecutor(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
if (alertsLogic != null) {
|
||||||
|
alertsLogic.close();
|
||||||
|
}
|
||||||
getLogger().info("GriefAlert has been disabled.");
|
getLogger().info("GriefAlert has been disabled.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
String cmd = command.getName().toLowerCase();
|
||||||
|
switch (cmd) {
|
||||||
|
case "disablelocation":
|
||||||
|
return alertsLogic.handleDisableLocation(sender, args);
|
||||||
|
case "enablelocation":
|
||||||
|
return alertsLogic.handleEnableLocation(sender, args);
|
||||||
|
case "clearlocations":
|
||||||
|
return alertsLogic.handleClearLocations(sender, args);
|
||||||
|
case "checklocation":
|
||||||
|
return alertsLogic.handleCheckLocation(sender, args);
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler (ignoreCancelled = true)
|
@EventHandler (ignoreCancelled = true)
|
||||||
// Block break alerts
|
// Block break alerts
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
// Exclusion list
|
// Exclusion list
|
||||||
if (EXCLUDED_BLOCKS.contains(event.getBlock().getType())) {
|
if (EXCLUDED_BLOCKS.contains(event.getBlock().getType())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Event parser
|
// Event parser
|
||||||
String playerName = event.getPlayer().getName();
|
String playerName = event.getPlayer().getName();
|
||||||
@ -82,6 +113,11 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
|||||||
int z = event.getBlock().getZ();
|
int z = event.getBlock().getZ();
|
||||||
String worldName = event.getBlock().getWorld().getName();
|
String worldName = event.getBlock().getWorld().getName();
|
||||||
|
|
||||||
|
// Check if alerts are disabled for this location
|
||||||
|
if (alertsLogic != null && alertsLogic.isLocationSaved(x, y, z, worldName)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if grief
|
// Check if grief
|
||||||
String target = inspectBlock(event.getBlock(), event.getPlayer());
|
String target = inspectBlock(event.getBlock(), event.getPlayer());
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
@ -94,12 +130,12 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
|||||||
// Stealing alerts
|
// Stealing alerts
|
||||||
@EventHandler (ignoreCancelled = true)
|
@EventHandler (ignoreCancelled = true)
|
||||||
public void onInventoryClick(InventoryClickEvent event) {
|
public void onInventoryClick(InventoryClickEvent event) {
|
||||||
if (ALLOW_STEALING) {
|
if (ALLOW_STEALING) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
boolean stealing;
|
boolean stealing;
|
||||||
|
|
||||||
// Event parser for inv
|
// Event parser for inv
|
||||||
if (!(event.getWhoClicked() instanceof Player)) return;
|
if (!(event.getWhoClicked() instanceof Player)) return;
|
||||||
Player player = (Player) event.getWhoClicked();
|
Player player = (Player) event.getWhoClicked();
|
||||||
Inventory inventory = event.getInventory();
|
Inventory inventory = event.getInventory();
|
||||||
@ -107,13 +143,22 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
|||||||
ItemStack item = event.getCurrentItem();
|
ItemStack item = event.getCurrentItem();
|
||||||
|
|
||||||
if (item == null || inventory.getLocation() == null || item.getType() == Material.AIR) {
|
if (item == null || inventory.getLocation() == null || item.getType() == Material.AIR) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exclusion list
|
// Exclusion list
|
||||||
if (!VALID_CONTAINERS.contains(inventory.getType())) {
|
if (!VALID_CONTAINERS.contains(inventory.getType())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if alerts are disabled for this location
|
||||||
|
int x = inventory.getLocation().getBlockX();
|
||||||
|
int y = inventory.getLocation().getBlockY();
|
||||||
|
int z = inventory.getLocation().getBlockZ();
|
||||||
|
String worldName = inventory.getLocation().getWorld().getName();
|
||||||
|
if (alertsLogic != null && alertsLogic.isLocationSaved(x, y, z, worldName)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Inv actions (needs fixing)
|
// Inv actions (needs fixing)
|
||||||
InventoryAction action = event.getAction();
|
InventoryAction action = event.getAction();
|
||||||
@ -123,30 +168,27 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
|||||||
stealing = true;
|
stealing = true;
|
||||||
} else if (action == InventoryAction.PLACE_ALL || action == InventoryAction.PLACE_SOME ||
|
} else if (action == InventoryAction.PLACE_ALL || action == InventoryAction.PLACE_SOME ||
|
||||||
action == InventoryAction.PLACE_ONE || (action == InventoryAction.MOVE_TO_OTHER_INVENTORY && clickedInventory != inventory)) {
|
action == InventoryAction.PLACE_ONE || (action == InventoryAction.MOVE_TO_OTHER_INVENTORY && clickedInventory != inventory)) {
|
||||||
stealing = false;
|
stealing = false;
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Event parser for container + check if grief
|
// Event parser for container + check if grief
|
||||||
String target = inspectBlock(inventory.getLocation().getBlock(), player);
|
String target = inspectBlock(inventory.getLocation().getBlock(), player);
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
String playerName = player.getName();
|
String playerName = player.getName();
|
||||||
String itemName = item.getType().toString();
|
String itemName = item.getType().toString();
|
||||||
int amount = item.getAmount();
|
int amount = item.getAmount();
|
||||||
int x = inventory.getLocation().getBlockX();
|
// x, y, z, worldName already defined above
|
||||||
int y = inventory.getLocation().getBlockY();
|
|
||||||
int z = inventory.getLocation().getBlockZ();
|
|
||||||
String worldName = inventory.getLocation().getWorld().getName();
|
|
||||||
|
|
||||||
if (stealing) {
|
if (stealing) {
|
||||||
// Stealing
|
// Stealing
|
||||||
String message = ChatColor.GRAY + playerName + " took " + amount + " " + itemName + " from " + target + "'s container at " + x + " " + y + " " + z + getHumanWorldName(worldName);
|
String message = ChatColor.GRAY + playerName + " took " + amount + " " + itemName + " from " + target + "'s container at " + x + " " + y + " " + z + getHumanWorldName(worldName);
|
||||||
alert(message, playerName, "[Map Link](" + MAP_LINK + "/?worldname=" + worldName + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", target);
|
alert(message, playerName, "[Map Link](" + MAP_LINK + "/?worldname=" + worldName + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", target);
|
||||||
} else {
|
} else {
|
||||||
// Putting back
|
// Putting back
|
||||||
String message = ChatColor.GRAY + playerName + " put " + amount + " " + itemName + " into " + target + "'s container at " + x + " " + y + " " + z + getHumanWorldName(worldName);
|
String message = ChatColor.GRAY + playerName + " put " + amount + " " + itemName + " into " + target + "'s container at " + x + " " + y + " " + z + getHumanWorldName(worldName);
|
||||||
alert(message, playerName, "[Map Link](" + MAP_LINK + "/?worldname=" + worldName + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", target);
|
alert(message, playerName, "[Map Link](" + MAP_LINK + "/?worldname=" + worldName + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user