Implement DeniedMessageEvent

Partially addresses #57
This commit is contained in:
RoboMWM 2017-01-04 13:17:59 -08:00
parent 9e4db8fb3e
commit 0d26d6c65b
3 changed files with 63 additions and 2 deletions

View File

@ -58,7 +58,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.11-R0.1-SNAPSHOT</version>
<version>1.11.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!--Worldguard dependency-->

View File

@ -26,6 +26,7 @@ import java.util.regex.Pattern;
import me.ryanhamshire.GriefPrevention.events.ClaimDeletedEvent;
import me.ryanhamshire.GriefPrevention.events.DeniedMessageEvent;
import org.bukkit.*;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
@ -41,6 +42,8 @@ import com.google.common.io.Files;
//singleton class which manages all GriefPrevention data (except for config options)
public abstract class DataStore
{
private GriefPrevention instance;
//in-memory cache for player data
protected ConcurrentHashMap<UUID, PlayerData> playerNameToPlayerDataMap = new ConcurrentHashMap<UUID, PlayerData>();
@ -1682,8 +1685,11 @@ public abstract class DataStore
String param = args[i];
message = message.replace("{" + i + "}", param);
}
DeniedMessageEvent event = new DeniedMessageEvent(messageID, message);
Bukkit.getPluginManager().callEvent(event);
return message;
return event.getMessage();
}
//used in updating the data schema from 0 to 1.

View File

@ -0,0 +1,55 @@
package me.ryanhamshire.GriefPrevention.events;
import me.ryanhamshire.GriefPrevention.Messages;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import javax.annotation.Nonnull;
/**
* Called when GP is retrieving the denial message to send to the player when canceling an action
*
* @author RoboMWM
* Created 1/4/2017.
*/
public class DeniedMessageEvent extends Event
{
// Custom Event Requirements
private static final HandlerList handlers = new HandlerList();
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
private String message;
private Messages messageID;
public DeniedMessageEvent(Messages messageID, String message)
{
this.message = message;
this.messageID = messageID;
}
public Messages getMessageID()
{
return this.messageID;
}
public String getMessage()
{
return this.message;
}
/**
* Sets the message to print to the player.
* @param message Cannot be null. Set to an empty string if you wish for no message to be printed.
*/
public void setMessage(@Nonnull String message)
{
this.message = message;
}
}