mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-12-02 07:23:36 +01:00
Allow FlagContext to be added to by plugins.
This commit is contained in:
parent
bbb79526b2
commit
ab55137f59
@ -22,6 +22,7 @@
|
|||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.sk89q.minecraft.util.commands.CommandException;
|
import com.sk89q.minecraft.util.commands.CommandException;
|
||||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -156,8 +157,17 @@ public FlagContextBuilder setObject(String key, Object value) {
|
|||||||
return this;
|
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() {
|
public FlagContext build() {
|
||||||
|
Bukkit.getServer().getPluginManager().callEvent(new FlagContextCreateEvent(this));
|
||||||
|
|
||||||
return new FlagContext(sender, input, map);
|
return new FlagContext(sender, input, map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* WorldGuard, a suite of tools for Minecraft
|
||||||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user