Upload files to "src/net/ardakaz/griefalert"
This commit is contained in:
parent
349a3d2c5f
commit
b034787328
@ -6,6 +6,7 @@ import net.coreprotect.CoreProtectAPI.ParseResult;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.Command;
|
||||
@ -16,6 +17,7 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
@ -328,32 +330,88 @@ public class GriefAlert extends JavaPlugin implements Listener, TabCompleter {
|
||||
ItemStack handItem = player.getInventory().getItemInMainHand();
|
||||
boolean handEmpty = handItem ==null || handItem.getType() == Material.AIR;
|
||||
boolean frameEmpty = itemInFrame ==null || itemInFrame.getType() == Material.AIR;
|
||||
String playerName = player.getName();
|
||||
|
||||
String action;
|
||||
if (handEmpty && !frameEmpty) {
|
||||
action = "took " + itemInFrame.getType();
|
||||
} else if (!handEmpty && frameEmpty) {
|
||||
if (!handEmpty && frameEmpty) {
|
||||
action = "added " + handItem.getType();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
|
||||
String message = ChatColor.GRAY + player.getName() + " " + action + " ItemFrame owned by " + target +
|
||||
" at " + x + " " + y + " " + z + " (" + worldName + ")";
|
||||
alert(message, player.getName(),
|
||||
"[Map Link](" + MAP_LINK + "/?worldname=" + worldName + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")",
|
||||
target, x, y, z, worldName);
|
||||
|
||||
String message = ChatColor.GRAY + playerName + " " + action + " an item to an item frame owned by " + target + " at " + x + " " + y + " " + z + getHumanWorldName(worldName);
|
||||
alert(message, playerName, "[Map Link](" + MAP_LINK + "/?worldname=" + worldName + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", target, x, y, z, worldName);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//breaking item frame item (uses a different event then placing an item)
|
||||
@EventHandler (ignoreCancelled = true)
|
||||
public void onItemFrameDamage(EntityDamageByEntityEvent event){
|
||||
if (!(event.getEntity() instanceof ItemFrame)) return;
|
||||
if (!(event.getDamager() instanceof Player)) return;
|
||||
|
||||
ItemFrame frame = (ItemFrame) event.getEntity();
|
||||
Player player = (Player) event.getDamager();
|
||||
ItemStack item = frame.getItem();
|
||||
String playerName = player.getName();
|
||||
|
||||
int x = frame.getLocation().getBlockX();
|
||||
int y = frame.getLocation().getBlockY();
|
||||
int z = frame.getLocation().getBlockZ();
|
||||
String worldName = frame.getWorld().getName();
|
||||
|
||||
if (isLocationIgnored(x, y, z, worldName)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
String target = inspectBlock(frame.getLocation().getBlock(), player);
|
||||
if (target == null || target.equals(player.getName())) return;
|
||||
|
||||
|
||||
if (item == null || item.getType() == Material.AIR) return;
|
||||
// At this point, the player is removing the item
|
||||
String action = "took " + item.getType();
|
||||
String message = ChatColor.GRAY + playerName + " " + action + " from item frame owned by " + target + " at " + x + " " + y + " " + z + getHumanWorldName(worldName);
|
||||
alert(message, playerName, "[Map Link](" + MAP_LINK + "/?worldname=" + worldName + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", target, x, y, z, worldName);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onItemFrameBreak(HangingBreakByEntityEvent event){
|
||||
if (!(event.getEntity() instanceof ItemFrame)) return;
|
||||
if (!(event.getRemover() instanceof Player)) return;
|
||||
|
||||
ItemFrame frame = (ItemFrame) event.getEntity();
|
||||
Player player = (Player) event.getRemover();
|
||||
String playerName = player.getName();
|
||||
|
||||
|
||||
Location loc = frame.getLocation();
|
||||
int x = loc.getBlockX();
|
||||
int y = loc.getBlockY();
|
||||
int z = loc.getBlockZ();
|
||||
String worldName = loc.getWorld().getName();
|
||||
|
||||
if (isLocationIgnored(x, y, z, worldName)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
String target = inspectBlock(loc.getBlock(), player);
|
||||
if (target ==null || target.equals(player.getName())) return;
|
||||
|
||||
String action = "broke an item frame";
|
||||
String message = ChatColor.GRAY + playerName + " " + action + " owned by " + target + " at " + x + " " + y + " " + z + getHumanWorldName(worldName);
|
||||
alert(message, playerName, "[Map Link](" + MAP_LINK + "/?worldname=" + worldName + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", target, x, y, z, worldName);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!command.getName().equalsIgnoreCase("griefalert")) return false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user