Added Y-Level filters to alerts (#9)

Merge branch 'master' into alert_range

fixed_the_snake_case

Switch to camelCase

+ Too much not java programing

Added Y-Level filters to alerts

+ Useful to filter out fortuning or TNT used in Netherite Mining
+ Might be a good idea to expand this setting to be per world

Co-authored-by: Etzelia <etzelia@hotmail.com>
Co-authored-by: Joey Hines <joey@ahines.net>
Reviewed-on: https://git.etztech.xyz/Minecraft/MineAlert/pulls/9
Reviewed-by: Etzelia <etzelia@hotmail.com>
master
Joey Hines 2020-09-08 18:46:31 +02:00 committed by Etzelia
parent d03f54594a
commit f27eb90f82
3 changed files with 46 additions and 6 deletions

View File

@ -5,6 +5,7 @@ import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -43,9 +44,25 @@ public class GriefAlertListener implements Listener {
}
}
public void addAlert(String playerName, Lang lang) {
public void addAlert(String playerName, Location eventLocation, Lang lang) {
String alert = lang.getMessage(playerName);
purge();
int aboveY = this.plugin.getConfigIntFallback(
0,
"grief.above_y"
);
int belowY = this.plugin.getConfigIntFallback(
255,
"grief.below_y"
);
int eventYLevel = eventLocation.getBlockY();
if (eventYLevel > belowY || eventYLevel < aboveY) {
return;
}
List<Date> dates = map.getOrDefault(alert, new ArrayList<>());
dates.add(new Date());
map.put(alert, dates);
@ -113,22 +130,22 @@ public class GriefAlertListener implements Listener {
if (event.getPlayer() != null &&
(event.getCause() == BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL ||
event.getCause() == BlockIgniteEvent.IgniteCause.FIREBALL)) {
addAlert(event.getPlayer().getName(), Lang.IGNITE_ALERT);
addAlert(event.getPlayer().getName(), event.getBlock().getLocation(), Lang.IGNITE_ALERT);
}
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {
if(event.getBlockPlaced().getType() == Material.TNT) {
addAlert(event.getPlayer().getName(), Lang.TNT_ALERT);
addAlert(event.getPlayer().getName(), event.getBlock().getLocation(), Lang.TNT_ALERT);
}
}
@EventHandler
public void onBucketEmpty(PlayerBucketEmptyEvent event) {
if(event.getBucket() == Material.LAVA_BUCKET) {
addAlert(event.getPlayer().getName(), Lang.LAVA_ALERT);
addAlert(event.getPlayer().getName(), event.getBlock().getLocation(), Lang.LAVA_ALERT);
}
}
}
}

View File

@ -128,8 +128,23 @@ public class OreAlertListener implements Listener {
String.format("ore.blocks.%s.ping", blockKey),
"ore.ping"
);
int belowY = this.plugin.getConfigIntFallback(
255,
String.format("ore.blocks.%s.below_y", blockKey),
"ore.below_y"
);
int aboveY = this.plugin.getConfigIntFallback(
0,
String.format("ore.blocks.%s.above_y", blockKey),
"ore.above_y"
);
purge(map.getOrDefault(event.getPlayer().getUniqueId(), new ArrayList<>()).iterator());
int yLevel = event.location.getBlockY();
if (yLevel > belowY || yLevel < aboveY) {
return;
}
int strikes = 0;
for (BlockEvent e : map.getOrDefault(event.getPlayer().getUniqueId(), new ArrayList<>())) {
if (e.isParent() && e.getMaterial().name().equals(event.getMaterial().name())) {
@ -274,4 +289,4 @@ public class OreAlertListener implements Listener {
return time;
}
}
}
}

View File

@ -17,6 +17,10 @@ grief:
color: ''
# Override
url: ''
# y level upper limit
below_y: 255
# y level lower limit
above_y: 20
# OreAlert
ore:
@ -40,6 +44,10 @@ ore:
webhook: ''
# Override
url: ''
# y level upper limit
below_y: 20
# y level lower limit
above_y: 0
# Only blocks listed here will be monitored
# Each of the above notify settings can be overridden per-block if needed