Added orealert_mute and griefalert_mute (#11)

Tweaks based on feedback

+ Combined mute commands into one command "alertmute"
+ By default, both mutes are set.
+ Grief and Ore strikes are now tracked even if a player has alerts muted

Added orealert_mute and griefalert_mute

+ Allows alerts generated by a user to be muted for a duration
+ Added PluginAPI as a dependency
+ Bumped version
+ Solves #8

Co-authored-by: Joey Hines <joey@ahines.net>
Reviewed-on: https://git.etztech.xyz/Minecraft/MineAlert/pulls/11
Reviewed-by: Etzelia <etzelia@hotmail.com>
master
Joey Hines 2020-09-14 06:08:15 +02:00 committed by Etzelia
parent f27eb90f82
commit d9e916e7b2
8 changed files with 161 additions and 6 deletions

View File

@ -3,7 +3,7 @@
<groupId>xyz.etztech</groupId>
<artifactId>MineAlert</artifactId>
<!-- Version is used in plugin.yml -->
<version>0.0.3</version>
<version>0.0.4</version>
<packaging>jar</packaging>
<!-- Plugin Information -->
@ -44,7 +44,11 @@
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>xyz.etztech</groupId>
<artifactId>plugin-api</artifactId>
<version>1.0.8</version>
</dependency>
</dependencies>
<repositories>

View File

@ -10,6 +10,9 @@ public enum Lang {
UNKNOWN_COMMAND("This command wasn't recognized.", Color.ERROR),
PLUGIN_RELOADED("MineAlert reloaded.", Color.INFO),
WEBHOOK_FAILED("Could not send webhook.", Color.ERROR),
PLAYER_NOT_FOUND("Could not find the player specified.", Color.ERROR),
DURATION_PARSE_ERROR("Error parsing time format.", Color.ERROR),
ALERT_MUTE("%s's alerts have been muted.", Color.PRIMARY),
ORE_ALERT("%s has found %d %s veins.", Color.DEFAULT),

View File

@ -2,6 +2,7 @@ package xyz.etztech.minealert;
import org.bukkit.plugin.java.JavaPlugin;
import xyz.etztech.minealert.commands.AlertMute;
import xyz.etztech.minealert.commands.MainCommand;
import xyz.etztech.minealert.listeners.GriefAlertListener;
import xyz.etztech.minealert.listeners.OreAlertListener;
@ -22,6 +23,7 @@ public class MineAlert extends JavaPlugin {
new MainCommand(this);
new GriefAlertListener(this);
new OreAlertListener(this);
new AlertMute(this);
}
}

View File

@ -0,0 +1,31 @@
package xyz.etztech.minealert;
import org.bukkit.entity.Player;
import org.bukkit.metadata.FixedMetadataValue;
public enum MuteType {
OREALERT_MUTE("MineAlert.OreAlert"),
GRIEFALERT_MUTE("MineAlert.GriefAlert");
private final String metadataValue;
MuteType(String s) {
this.metadataValue = s;
}
public String getMetadataValue() {
return metadataValue;
}
public void setMuteStatus(Player player, MineAlert plugin) {
player.setMetadata(getMetadataValue(), new FixedMetadataValue(plugin, getMetadataValue()));
}
public void removeMuteStatus(Player player, MineAlert plugin) {
player.removeMetadata(getMetadataValue(), plugin);
}
public boolean hasMuteStatus(Player player, MineAlert plugin) {
return player.hasMetadata(this.getMetadataValue());
}
}

View File

@ -0,0 +1,98 @@
package xyz.etztech.minealert.commands;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import xyz.etztech.minealert.Color;
import xyz.etztech.minealert.Lang;
import xyz.etztech.minealert.MineAlert;
import xyz.etztech.core.command.TickDuration;
import xyz.etztech.minealert.MuteType;
import java.util.LinkedList;
import java.util.List;
public class AlertMute implements CommandExecutor {
MineAlert plugin;
public AlertMute(MineAlert plugin) {
this.plugin = plugin;
this.plugin.getCommand("alertmute").setExecutor(this);
}
@Override
public boolean onCommand(CommandSender commandSender, Command command, String commandPassed, String[] args) {
if (!commandSender.hasPermission("minealert.alert_mute")) {
Lang.NO_PERMISSION.sms(commandSender);
return true;
}
if (args.length == 0) {
BaseComponent[] message = new ComponentBuilder()
.color(Color.INFO.getChatColor())
.append("/")
.append(commandPassed)
.append(" <player> <duration> [ore|grief]")
.create();
commandSender.spigot().sendMessage(message);
}
else {
Player player = commandSender.getServer().getPlayer(args[0]);
if (player == null) {
Lang.PLAYER_NOT_FOUND.sms(commandSender);
return true;
}
TickDuration duration;
try {
duration = TickDuration.parse(args[1]);
}
catch (Exception e) {
Lang.DURATION_PARSE_ERROR.sms(commandSender);
return true;
}
List<MuteType> mutes = new LinkedList<>();
if (args.length == 3) {
switch (args[2].toLowerCase()) {
case "ore":
mutes.add(MuteType.OREALERT_MUTE);
break;
case "grief":
mutes.add(MuteType.GRIEFALERT_MUTE);
break;
default:
Lang.UNKNOWN_COMMAND.sms(commandSender);
return true;
}
}
else {
mutes.add(MuteType.GRIEFALERT_MUTE);
mutes.add(MuteType.OREALERT_MUTE);
}
for (MuteType mute: mutes) {
mute.setMuteStatus(player, plugin);
}
Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
@Override
public void run() {
for (MuteType mute: mutes) {
mute.removeMuteStatus(player, plugin);
}
}
}, duration.toTicks());
Lang.ALERT_MUTE.sms(commandSender, player.getName());
}
return true;
}
}

View File

@ -20,6 +20,7 @@ import xyz.etztech.embed.Embed;
import xyz.etztech.minealert.Color;
import xyz.etztech.minealert.Lang;
import xyz.etztech.minealert.MineAlert;
import xyz.etztech.minealert.MuteType;
import java.time.OffsetDateTime;
import java.util.*;
@ -44,7 +45,8 @@ public class GriefAlertListener implements Listener {
}
}
public void addAlert(String playerName, Location eventLocation, Lang lang) {
public void addAlert(Player player, Location eventLocation, Lang lang) {
String playerName = player.getName();
String alert = lang.getMessage(playerName);
purge();
@ -67,6 +69,10 @@ public class GriefAlertListener implements Listener {
dates.add(new Date());
map.put(alert, dates);
if (MuteType.GRIEFALERT_MUTE.hasMuteStatus(player, plugin)) {
return;
}
Color color = new Color(plugin.getConfigStringFallback(
"#FFA500",
"grief.color"
@ -130,21 +136,21 @@ 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(), event.getBlock().getLocation(), Lang.IGNITE_ALERT);
addAlert(event.getPlayer(), event.getBlock().getLocation(), Lang.IGNITE_ALERT);
}
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {
if(event.getBlockPlaced().getType() == Material.TNT) {
addAlert(event.getPlayer().getName(), event.getBlock().getLocation(), Lang.TNT_ALERT);
addAlert(event.getPlayer(), event.getBlock().getLocation(), Lang.TNT_ALERT);
}
}
@EventHandler
public void onBucketEmpty(PlayerBucketEmptyEvent event) {
if(event.getBucket() == Material.LAVA_BUCKET) {
addAlert(event.getPlayer().getName(), event.getBlock().getLocation(), Lang.LAVA_ALERT);
addAlert(event.getPlayer(), event.getBlock().getLocation(), Lang.LAVA_ALERT);
}
}

View File

@ -21,6 +21,7 @@ import xyz.etztech.embed.Embed;
import xyz.etztech.minealert.Color;
import xyz.etztech.minealert.Lang;
import xyz.etztech.minealert.MineAlert;
import xyz.etztech.minealert.MuteType;
import java.time.OffsetDateTime;
import java.util.*;
@ -145,6 +146,10 @@ public class OreAlertListener implements Listener {
return;
}
if (MuteType.GRIEFALERT_MUTE.hasMuteStatus(event.getPlayer(), plugin)) {
return;
}
int strikes = 0;
for (BlockEvent e : map.getOrDefault(event.getPlayer().getUniqueId(), new ArrayList<>())) {
if (e.isParent() && e.getMaterial().name().equals(event.getMaterial().name())) {

View File

@ -9,6 +9,9 @@ commands:
minealert:
aliases: ma
description: Base command
alertmute:
aliases: am
description: Mutes alerts from a user
permissions:
minealert.admin:
description: Ability to reload the plugin
@ -16,3 +19,6 @@ permissions:
minealert.alert:
description: Get alerts
default: op
minealert.alert_mute:
description: Ability to mute alerts
default: op