diff --git a/worldguard-legacy/src/main/java/com/sk89q/worldguard/protection/flags/FlagContext.java b/worldguard-legacy/src/main/java/com/sk89q/worldguard/protection/flags/FlagContext.java index e48d1dad..57dc1530 100644 --- a/worldguard-legacy/src/main/java/com/sk89q/worldguard/protection/flags/FlagContext.java +++ b/worldguard-legacy/src/main/java/com/sk89q/worldguard/protection/flags/FlagContext.java @@ -22,6 +22,7 @@ import com.google.common.collect.Maps; import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -156,8 +157,17 @@ public FlagContextBuilder setObject(String key, Object value) { return this; } + protected boolean tryAddToMap(String key, Object value) { + if (map.containsKey(key)) return false; + this.map.put(key, value); + return true; + } + public FlagContext build() { + Bukkit.getServer().getPluginManager().callEvent(new FlagContextCreateEvent(this)); + return new FlagContext(sender, input, map); } } + } diff --git a/worldguard-legacy/src/main/java/com/sk89q/worldguard/protection/flags/FlagContextCreateEvent.java b/worldguard-legacy/src/main/java/com/sk89q/worldguard/protection/flags/FlagContextCreateEvent.java new file mode 100644 index 00000000..2c2cf561 --- /dev/null +++ b/worldguard-legacy/src/main/java/com/sk89q/worldguard/protection/flags/FlagContextCreateEvent.java @@ -0,0 +1,56 @@ +/* + * WorldGuard, a suite of tools for Minecraft + * Copyright (C) sk89q + * Copyright (C) WorldGuard team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldguard.protection.flags; + +import com.sk89q.worldguard.protection.flags.FlagContext.FlagContextBuilder; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class FlagContextCreateEvent extends Event { + + private FlagContextBuilder builder; + + public FlagContextCreateEvent(FlagContextBuilder builder) { + this.builder = builder; + } + + /** + * Add an object to the flag context with the given key. Keys must be unique. + * + * @param key a unique string to identify the object + * @param value the object to store in the context + * @return true if added successfully, false if the key was already used + */ + public boolean addObject(String key, Object value) { + return builder.tryAddToMap(key, value); + } + + private static final HandlerList handlers = new HandlerList(); + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + +}