Redesigned how RuleLists were compiled and created to be less roundabout.

This commit is contained in:
sk89q 2012-11-10 21:29:00 -08:00
parent 579143a5dd
commit dc1f3f54b1
20 changed files with 397 additions and 307 deletions

View File

@ -5,11 +5,11 @@
* Copyright (c) the 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
* terms of the GNU Lesser General Public License as published by the Free Software
* (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
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
@ -19,22 +19,57 @@
package com.sk89q.rulelists;
/**
* An object that can learn rules and possibly implement them. Attachments can be
* analogous to events that occur in the game. An attachment, for example, would be
* a block break event.
* An attachment is analogous to an event.
*/
public interface Attachment {
public final class Attachment {
private static int NEXT_ID = 0;
private final int id;
private final String alias;
/**
* Learn a rule.
* Create a new attachment with the given alias. The alias is used in rule list
* files.
*
* @param rule rule
* @param alias alias name
*/
public void learn(Rule<?> rule);
public Attachment(String alias) {
this.alias = alias;
// No internal ID
id = -1;
}
/**
* Forget all previously learned rules.
* Create a new attachment with the given alias. The alias is used in rule list
* files.
*
* @param alias alias name
* @param isInternal true to assign this attachment a standard internal ID
*/
public void forgetRules();
Attachment(String alias, boolean isInternal) {
this.alias = alias;
id = isInternal ? NEXT_ID++ : -1;
}
/**
* Get the internal ID.
*
* @return ID number, possibly -1 for no internal ID
*/
int getId() {
return id;
}
/**
* Get the alias used inside rule list files.
*
* @return alias
*/
public String getAlias() {
return alias;
}
}

View File

@ -5,11 +5,11 @@
* Copyright (c) the 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
* terms of the GNU Lesser General Public License as published by the Free Software
* (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
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
@ -19,44 +19,59 @@
package com.sk89q.rulelists;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import com.sk89q.rebar.config.Loader;
import com.sk89q.rebar.config.LoaderBuilderException;
/**
* Manages known attachment points.
*
* @see Attachment
* A database of valid attachments.
*/
public class AttachmentManager {
public final class AttachmentManager implements Loader<Attachment> {
private final Map<String, Attachment> attachments = new HashMap<String, Attachment>();
private Set<Attachment> attachments = new HashSet<Attachment>();
private Map<String, Attachment> aliasMap = new HashMap<String, Attachment>();
/**
* Register an {@link Attachment}.
*
* @param name name of the attachment (used in a rule's 'when' clause) (case insensitive)
* @param attachment attachment
*/
public void register(String name, Attachment attachment) {
attachments.put(name.toLowerCase(), attachment);
public AttachmentManager() {
}
/**
* Get an attachment.
* Register an attachment.
*
* @param name name of the attachment (case insensitive)
* @return attachment
* @param attachment the attachment
*/
public Attachment get(String name) {
return attachments.get(name.toLowerCase());
}
/**
* Forget all the rules in the registered attachments.
*/
public void forgetRules() {
for (Attachment attachment : attachments.values()) {
attachment.forgetRules();
public synchronized void register(Attachment attachment) {
if (attachments.contains(attachment)
|| aliasMap.containsKey(attachment.getAlias().toLowerCase())) {
throw new IllegalArgumentException("Attachment '" + attachment + "' already registered.");
}
attachments.add(attachment);
aliasMap.put(attachment.getAlias().toLowerCase(), attachment);
}
/**
* Get an attachment by its alias.
*
* @param alias alias, case in-sensitive
* @return an attachment or null
*/
public synchronized Attachment lookup(String alias) {
return aliasMap.get(alias.toLowerCase());
}
@Override
public Attachment read(Object value) throws LoaderBuilderException {
String id = String.valueOf(value);
Attachment attachment = lookup(id);
if (attachment == null) {
throw new LoaderBuilderException("Unknown RuleList attachment: " + id);
}
return attachment;
}
}

View File

@ -0,0 +1,80 @@
// $Id$
/*
* This file is a part of WorldGuard.
* Copyright (c) sk89q <http://www.sk89q.com>
* Copyright (c) the 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
* (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
* GNU 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.rulelists;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
/**
* Contains names of standard attachments.
*/
public final class DefaultAttachments {
public final static Attachment BLOCK_BREAK = new Attachment("block-break", true);
public final static Attachment BLOCK_PLACE = new Attachment("block-place", true);
public final static Attachment BLOCK_SPREAD = new Attachment("block-spread", true);
public final static Attachment BLOCK_PHYSICS = new Attachment("block-physics", true);
public final static Attachment BLOCK_INTERACT = new Attachment("block-interact", true);
public final static Attachment BLOCK_FADE = new Attachment("block-fade", true);
public final static Attachment BLOCK_FORM = new Attachment("block-form", true);
public final static Attachment PLAYER_JOIN = new Attachment("player-join", true);
public final static Attachment PLAYER_RESPAWN = new Attachment("player-respawn", true);
public final static Attachment PLAYER_QUIT = new Attachment("player-quit", true);
public final static Attachment ENTITY_EXPLODE = new Attachment("entity-explode", true);
public final static Attachment ENTITY_DAMAGE = new Attachment("entity-damage", true);
public final static Attachment ENTITY_DEATH = new Attachment("entity-death", true);
public final static Attachment ENTITY_IGNITE = new Attachment("entity-ignite", true);
public final static Attachment ENTITY_SPAWN = new Attachment("entity-spawn", true);
public final static Attachment ENTITY_STRIKE = new Attachment("entity-strike", true);
public final static Attachment ENTITY_INTERACT = new Attachment("entity-interact", true);
public final static Attachment CHAT = new Attachment("chat", true);
public final static Attachment ITEM_DROP = new Attachment("item-drop", true);
public final static Attachment ITEM_PICKUP = new Attachment("item-pickup", true);
public final static Attachment ITEM_USE = new Attachment("item-use", true);
public final static Attachment WEATHER_PHENOMENON = new Attachment("weather-phenomenon", true);
public final static Attachment WEATHER_TRANSITION = new Attachment("weather-transition", true);
public final static Attachment WORLD_LOAD = new Attachment("world-load", true);
public final static Attachment WORLD_UNLOAD = new Attachment("world-unload", true);
public final static Attachment WORLD_SAVE = new Attachment("world-save", true);
private DefaultAttachments() {
}
/**
* Register the attachments in this class with the given manager.
*
* @param manager the manager
*/
public static void registerWith(AttachmentManager manager) {
for (Field field : DefaultAttachments.class.getFields()) {
if (Modifier.isStatic(field.getModifiers())
&& Attachment.class.isAssignableFrom(field.getType())) {
try {
manager.register((Attachment) field.get(null));
} catch (IllegalArgumentException e) {
throw new RuntimeException("Failed to register default attachment", e);
} catch (IllegalAccessException e) {
throw new RuntimeException("Failed to register default attachment", e);
}
}
}
}
}

View File

@ -1,90 +0,0 @@
// $Id$
/*
* This file is a part of WorldGuard.
* Copyright (c) sk89q <http://www.sk89q.com>
* Copyright (c) the 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
* (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
* GNU 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.rulelists;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
/**
* Contains names of standard attachments.
*/
public enum KnownAttachment {
BLOCK_BREAK("block-break"),
BLOCK_PLACE("block-place"),
BLOCK_SPREAD("block-spread"),
BLOCK_PHYSICS("block-physics"),
BLOCK_INTERACT("block-interact"),
BLOCK_FADE("block-fade"),
BLOCK_FORM("block-form"),
PLAYER_JOIN("player-join"),
PLAYER_RESPAWN("player-respawn"),
PLAYER_QUIT("player-quit"),
ENTITY_EXPLODE("entity-explode"),
ENTITY_DAMAGE("entity-damage"),
ENTITY_DEATH("entity-death"),
ENTITY_IGNITE("entity-ignite"),
ENTITY_SPAWN("entity-spawn"),
ENTITY_STRIKE("entity-strike"),
ENTITY_INTERACT("entity-interact"),
CHAT("chat"),
ITEM_DROP("item-drop"),
ITEM_PICKUP("item-pickup"),
ITEM_USE("item-use"),
WEATHER_PHENOMENON("weather-phenomenon"),
WEATHER_TRANSITION("weather-transition"),
WORLD_LOAD("world-load"),
WORLD_UNLOAD("world-unload"),
WORLD_SAVE("world-save");
private final static Map<String, KnownAttachment> ids = new HashMap<String, KnownAttachment>();
static {
for (KnownAttachment attachment : EnumSet.allOf(KnownAttachment.class)) {
ids.put(attachment.getId().toLowerCase(), attachment);
}
}
private final String id;
KnownAttachment(String id) {
this.id = id;
}
/**
* Get the attachment's string ID.
*
* @return string ID
*/
public String getId() {
return id;
}
/**
* Get an attachment from a given string ID. Not case sensitive.
*
* @param id string ID
* @return attachment name
*/
public static KnownAttachment fromId(String id) {
return ids.get(id.toLowerCase());
}
}

View File

@ -1,52 +0,0 @@
// $Id$
/*
* This file is a part of WorldGuard.
* Copyright (c) sk89q <http://www.sk89q.com>
* Copyright (c) the 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
* (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
* GNU 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.rulelists;
import java.util.EnumMap;
import java.util.Map;
/**
* Holds known attachment rule sets for every {@link KnownAttachment}.
*/
public class KnownAttachmentRules {
private Map<KnownAttachment, RuleSet> ruleSets =
new EnumMap<KnownAttachment, RuleSet>(KnownAttachment.class);
/**
* Build a new instance, with every attachment having an empty {@link RuleSet}
* defined for it.
*/
public KnownAttachmentRules() {
for (KnownAttachment attachment : KnownAttachment.values()) {
ruleSets.put(attachment, new RuleSet());
}
}
/**
* Get a rule set for a given attachment.
*
* @param attachment the attachment
* @return the rule set
*/
public RuleSet get(KnownAttachment attachment) {
return ruleSets.get(attachment);
}
}

View File

@ -5,11 +5,11 @@
* Copyright (c) the 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
* terms of the GNU Lesser General Public License as published by the Free Software
* (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
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
@ -21,36 +21,36 @@
import java.util.List;
/**
* A pair of attachment/event names a rule.
* A pair of attachments and a rule.
*/
public class RuleEntry {
private final List<String> attachmentNames;
private final List<Attachment> attachments;
private final Rule<?> rule;
/**
* Construct the rule entry with the list of attachment names and rules.
*
* @param attachmentNames attachment names
* Construct the rule entry with the list of attachments and rules.
*
* @param attachments attachment names
* @param rule rules
*/
public RuleEntry(List<String> attachmentNames, Rule<?> rule) {
this.attachmentNames = attachmentNames;
public RuleEntry(List<Attachment> attachments, Rule<?> rule) {
this.attachments = attachments;
this.rule = rule;
}
/**
* Get the list of attachment names.
*
* @return attachment names
* Get the list of attachments.
*
* @return attachment
*/
public List<String> getAttachmentNames() {
return attachmentNames;
public List<Attachment> getAttachments() {
return attachments;
}
/**
* Get the rule.
*
*
* @return rule
*/
public Rule<?> getRule() {

View File

@ -18,7 +18,6 @@
package com.sk89q.rulelists;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
@ -34,8 +33,10 @@
public class RuleEntryLoader extends AbstractNodeLoader<RuleEntry> {
public static final String INLINE = "_";
private static Logger logger = LoggerUtils.getLogger(RuleEntryLoader.class, "[WorldGuard] RuleList: ");
private static final Logger logger = LoggerUtils.getLogger(RuleEntryLoader.class);
private final AttachmentManager attachmentManager;
private final DefinitionLoader<Criteria<?>> criteriaLoader;
private final DefinitionLoader<Action<?>> actionLoader;
@ -45,6 +46,7 @@ public class RuleEntryLoader extends AbstractNodeLoader<RuleEntry> {
* @param ruleListsManager the action lists manager
*/
public RuleEntryLoader(RuleListsManager ruleListsManager) {
attachmentManager = ruleListsManager.getAttachments();
criteriaLoader = new DefinitionLoader<Criteria<?>>(ruleListsManager.getCriterion(), true);
actionLoader = new DefinitionLoader<Action<?>>(ruleListsManager.getActions(), false);
}
@ -56,7 +58,7 @@ public RuleEntry read(ConfigurationNode node) {
return null;
}
List<String> when = node.getStringList("when", new ArrayList<String>());
List<Attachment> when = node.listOf("when", attachmentManager);
// Check to see if the rule has any events defined
if (when.size() == 0) {
@ -150,12 +152,12 @@ public T read(ConfigurationNode node) {
}
// No class defined!
logger.warning("EventListeners: Missing '?' parameter in definition " +
logger.warning("RuleList: Missing '?' parameter in definition " +
"(to define what kind of criteria/action it is)");
return null;
} catch (DefinitionException e) {
logger.warning("EventListeners: Invalid definition " +
logger.warning("RuleList: Invalid definition " +
"identified by type '" + id + "': " + e.getMessage());
// Throw an exception in strict mode

View File

@ -0,0 +1,83 @@
// $Id$
/*
* This file is a part of WorldGuard.
* Copyright (c) sk89q <http://www.sk89q.com>
* Copyright (c) the 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
* (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
* GNU 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.rulelists;
import java.util.HashMap;
import java.util.Map;
/**
* Holds all the rules.
*/
public class RuleList {
private Map<Attachment, RuleSet> collections = new HashMap<Attachment, RuleSet>();
/**
* Build a new instance.
*/
public RuleList() {
}
/**
* Get a rule set for a given attachment. A rule set is guaranteed to be
* returned for all given attachments.
*
* @param attachment the attachment
* @return the rule set
*/
public synchronized RuleSet get(Attachment attachment) {
RuleSet collection = collections.get(attachment);
if (collection == null) {
collection = new RuleSet();
collections.put(attachment, collection);
}
return collection;
}
/**
* Register a rule with this rule list.
*
* @param entry entry
*/
public void learn(RuleEntry entry) {
Rule<?> rule = entry.getRule();
for (Attachment attachment : entry.getAttachments()) {
learn(attachment, rule);
}
}
/**
* Register a rule with this rule list.
*
* @param attachment the attachment for the rule
* @param rule the rule itself
*/
public void learn(Attachment attachment, Rule<?> rule) {
get(attachment).learn(rule);
}
/**
* Forget all rules.
*/
public void clear() {
collections.clear();
}
}

View File

@ -5,11 +5,11 @@
* Copyright (c) the 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
* terms of the GNU Lesser General Public License as published by the Free Software
* (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
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
@ -41,7 +41,7 @@ public AttachmentManager getAttachments() {
/**
* Get the criterion manager.
*
* @return criteron manager
* @return criterion manager
*/
public DefinitionManager<Criteria<?>> getCriterion() {
return criterion;

View File

@ -5,11 +5,11 @@
* Copyright (c) the 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
* terms of the GNU Lesser General Public License as published by the Free Software
* (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
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
@ -18,43 +18,75 @@
package com.sk89q.rulelists;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
public class RuleSet implements Attachment {
/**
* Holds a collection of rules that can be applied to a context.
*
* @see RuleList
*/
public class RuleSet {
private List<Rule<?>> rules = new LinkedList<Rule<?>>();
@Override
public void learn(Rule<?> rule) {
RuleSet() {
}
/**
* Add the given rule to this set.
*
* @param rule the rule
*/
public synchronized void learn(Rule<?> rule) {
rules.add(rule);
}
@Override
public void forgetRules() {
/**
* Forget all rules.
*/
public synchronized void clear() {
rules.clear();
}
public boolean hasRules() {
/**
* Return whether this set has rules.
*
* @return true if there are rules
*/
public synchronized boolean hasRules() {
return rules.size() > 0;
}
public List<Rule<?>> getRules() {
return rules;
/**
* Get the list of rules. The returned list cannot be modified.
*
* @return rule list
*/
public synchronized List<Rule<?>> getRules() {
return Collections.unmodifiableList(rules);
}
/**
* Apply this rule set onto the given context. Only one thread should call
* this method at a given time.
*
* @param context the context
* @return true if the event has been cancelled
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public boolean process(Context context) {
if (context.isCancelled()) {
return true; // Ignore cancelled events for now
}
for (Rule rule : rules) {
if (rule.matches(context)) {
rule.apply(context);
}
}
return context.isCancelled();
}

View File

@ -35,8 +35,7 @@
import com.sk89q.rebar.config.ConfigurationNode;
import com.sk89q.rebar.config.YamlConfigurationFile;
import com.sk89q.rebar.util.LoggerUtils;
import com.sk89q.rulelists.KnownAttachment;
import com.sk89q.rulelists.KnownAttachmentRules;
import com.sk89q.rulelists.RuleList;
import com.sk89q.rulelists.RuleEntry;
import com.sk89q.rulelists.RuleEntryLoader;
import com.sk89q.rulelists.RuleTemplateEntryLoader;
@ -61,7 +60,7 @@ public class WorldConfiguration {
private final String worldName;
private Blacklist blacklist;
private KnownAttachmentRules ruleList = new KnownAttachmentRules();
private RuleList ruleList = new RuleList();
private ChestProtection chestProtection = new SignChestProtection();
private SpongeApplicator spongeApplicator = null;
@ -113,6 +112,7 @@ private void load() {
loadConfig();
// Load rule lists
ruleList.clear();
loadBuiltInRules();
loadUserRules();
loadBlacklist();
@ -204,7 +204,7 @@ private void loadBuiltInRules() {
for (List<RuleEntry> entries : plugin.getBuiltInRules().listOf("", loader)) {
for (RuleEntry entry : entries) {
learnRule(entry);
ruleList.learn(entry);
}
}
} catch (IOException e) {
@ -227,7 +227,7 @@ private void loadUserRules() {
rulesConfig.load();
for (RuleEntry entry : rulesConfig.listOf(ConfigurationNode.ROOT, entryLoader)) {
learnRule(entry);
ruleList.learn(entry);
}
} catch (IOException e) {
logger.log(Level.SEVERE, "Failed to load " + rulesFile.getAbsolutePath(), e);
@ -360,23 +360,7 @@ public int getMaxRegionCount(Player player) {
return max;
}
public KnownAttachmentRules getRuleList() {
public RuleList getRuleList() {
return ruleList;
}
/**
* Register a rule with this rule list.
*
* @param entry entry
*/
public void learnRule(RuleEntry entry) {
for (String name : entry.getAttachmentNames()) {
KnownAttachment attachment = KnownAttachment.fromId(name);
if (attachment != null) {
ruleList.get(attachment).learn(entry.getRule());
} else {
logger.warning("Don't know what the RuleList event '" + name + "' is");
}
}
}
}

View File

@ -43,7 +43,7 @@
import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.block.SignChangeEvent;
import com.sk89q.rulelists.KnownAttachment;
import com.sk89q.rulelists.DefaultAttachments;
import com.sk89q.rulelists.RuleSet;
import com.sk89q.worldedit.blocks.BlockID;
@ -82,7 +82,7 @@ public void onBlockDamage(BlockDamageEvent event) {
// handle them a bit separately
if (blockDamaged.getTypeId() == BlockID.CAKE_BLOCK) {
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_INTERACT);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.BLOCK_INTERACT);
BukkitContext context = new BukkitContext(plugin, event);
context.setSourceEntity(player);
context.setTargetBlock(event.getBlock().getState());
@ -102,7 +102,7 @@ public void onBlockBreak(BlockBreakEvent event) {
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_BREAK);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.BLOCK_BREAK);
BukkitContext context = new BukkitContext(plugin, event);
context.setSourceEntity(player);
context.setTargetBlock(event.getBlock().getState());
@ -142,7 +142,7 @@ public void onBlockFromTo(BlockFromToEvent event) {
}
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_SPREAD);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.BLOCK_SPREAD);
BukkitContext context = new BukkitContext(plugin, event);
context.setSourceBlock(event.getBlock().getState());
context.setTargetBlock(event.getToBlock().getState());
@ -176,7 +176,7 @@ public void onBlockIgnite(BlockIgniteEvent event) {
switch (event.getCause()) {
case FLINT_AND_STEEL:
// Consider flint and steel as an item use
rules = wcfg.getRuleList().get(KnownAttachment.ITEM_USE);
rules = wcfg.getRuleList().get(DefaultAttachments.ITEM_USE);
context = new BukkitContext(plugin, event);
context.setSourceEntity(event.getPlayer());
context.setTargetBlock(event.getBlock().getState());
@ -195,7 +195,7 @@ public void onBlockIgnite(BlockIgniteEvent event) {
case LAVA:
case SPREAD:
// Consider everything else as a block spread
rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_SPREAD);
rules = wcfg.getRuleList().get(DefaultAttachments.BLOCK_SPREAD);
context = new BukkitContext(plugin, event);
context.setTargetBlock(event.getBlock().getState());
@ -217,7 +217,7 @@ public void onBlockIgnite(BlockIgniteEvent event) {
case FIREBALL:
case LIGHTNING:
// Consider everything else as a block spread
rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_PLACE);
rules = wcfg.getRuleList().get(DefaultAttachments.BLOCK_PLACE);
context = new BukkitContext(plugin, event);
context.setTargetBlock(event.getBlock().getState());
@ -249,7 +249,7 @@ public void onBlockBurn(BlockBurnEvent event) {
}
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_BREAK);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.BLOCK_BREAK);
BukkitContext context = new BukkitContext(plugin, event);
BlockState virtualFireState = event.getBlock().getState();
virtualFireState.setType(Material.FIRE);
@ -269,7 +269,7 @@ public void onBlockPhysics(BlockPhysicsEvent event) {
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_PHYSICS);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.BLOCK_PHYSICS);
BukkitContext context = new BukkitContext(plugin, event);
context.setTargetBlock(event.getBlock().getState());
if (rules.process(context)) {
@ -305,7 +305,7 @@ public void onBlockPlace(BlockPlaceEvent event) {
}
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_PLACE);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.BLOCK_PLACE);
BukkitContext context = new BukkitContext(plugin, event);
context.setTargetBlock(event.getBlock().getState());
context.setPlacedBlock(event.getBlockReplacedState());
@ -378,7 +378,7 @@ public void onSignChange(SignChangeEvent event) {
}
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_INTERACT);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.BLOCK_INTERACT);
BukkitContext context = new BukkitContext(plugin, event);
context.setTargetBlock(event.getBlock().getState());
if (rules.process(context)) {
@ -393,7 +393,7 @@ public void onLeavesDecay(LeavesDecayEvent event) {
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_FADE);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.BLOCK_FADE);
BukkitContext context = new BukkitContext(plugin, event);
context.setTargetBlock(event.getBlock().getState());
if (rules.process(context)) {
@ -408,7 +408,7 @@ public void onBlockForm(BlockFormEvent event) {
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_FORM);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.BLOCK_FORM);
BukkitContext context = new BukkitContext(plugin, event);
context.setTargetBlock(event.getBlock().getState());
context.setPlacedBlock(event.getNewState());
@ -424,7 +424,7 @@ public void onBlockSpread(BlockSpreadEvent event) {
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_SPREAD);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.BLOCK_SPREAD);
BukkitContext context = new BukkitContext(plugin, event);
context.setSourceBlock(event.getSource().getState());
context.setTargetBlock(event.getBlock().getState());
@ -441,7 +441,7 @@ public void onBlockFade(BlockFadeEvent event) {
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_FADE);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.BLOCK_FADE);
BukkitContext context = new BukkitContext(plugin, event);
context.setTargetBlock(event.getBlock().getState());
context.setPlacedBlock(event.getNewState());
@ -457,7 +457,7 @@ public void onBlockDispense(BlockDispenseEvent event) {
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ITEM_DROP);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ITEM_DROP);
BukkitContext context = new BukkitContext(plugin, event);
context.setSourceBlock(event.getBlock().getState());
context.setItem(event.getItem());

View File

@ -44,7 +44,7 @@
import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.event.entity.PigZapEvent;
import org.bukkit.event.entity.PotionSplashEvent;
import com.sk89q.rulelists.KnownAttachment;
import com.sk89q.rulelists.DefaultAttachments;
import com.sk89q.rulelists.RuleSet;
import com.sk89q.worldguard.protection.GlobalRegionManager;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
@ -78,7 +78,7 @@ public void onEntityInteract(EntityInteractEvent event) {
WorldConfiguration wcfg = cfg.get(event.getEntity().getWorld());
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_INTERACT);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.BLOCK_INTERACT);
BukkitContext context = new BukkitContext(plugin, event);
context.setSourceEntity(event.getEntity());
context.setTargetBlock(event.getBlock().getState());
@ -96,7 +96,7 @@ public void onEntityDeath(EntityDeathEvent event) {
/* --- No short-circuit returns below this line --- */
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ENTITY_DEATH);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ENTITY_DEATH);
BukkitContext context = new BukkitContext(plugin, event);
context.setTargetEntity(event.getEntity());
@ -121,7 +121,7 @@ public void onEntityDamage(EntityDamageEvent event) {
// Redirect damage done by an entity
if (event instanceof EntityDamageByEntityEvent) {
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ENTITY_DAMAGE);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ENTITY_DAMAGE);
BukkitContext context = new BukkitContext(plugin, event);
context.setSourceEntity(((EntityDamageByEntityEvent) event).getDamager());
context.setTargetEntity(event.getEntity());
@ -133,7 +133,7 @@ public void onEntityDamage(EntityDamageEvent event) {
// Redirect damage done by blocks
} else if (event instanceof EntityDamageByBlockEvent) {
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ENTITY_DAMAGE);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ENTITY_DAMAGE);
BukkitContext context = new BukkitContext(plugin, event);
Block damager = ((EntityDamageByBlockEvent) event).getDamager();
if (damager != null) { // Should NOT be null!
@ -148,7 +148,7 @@ public void onEntityDamage(EntityDamageEvent event) {
// Other damage
} else {
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ENTITY_DAMAGE);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ENTITY_DAMAGE);
BukkitContext context = new BukkitContext(plugin, event);
context.setTargetEntity(event.getEntity());
if (rules.process(context)) {
@ -166,7 +166,7 @@ public void onEntityCombust(EntityCombustEvent event) {
WorldConfiguration wcfg = cfg.get(entity.getWorld());
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ENTITY_IGNITE);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ENTITY_IGNITE);
BukkitContext context = new BukkitContext(plugin, event);
context.setTargetEntity(entity);
if (rules.process(context)) {
@ -183,7 +183,7 @@ public void onEntityExplode(EntityExplodeEvent event) {
WorldConfiguration wcfg = cfg.get(world);
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ENTITY_EXPLODE);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ENTITY_EXPLODE);
BukkitContext context = new BukkitContext(plugin, event);
context.setTargetEntity(event.getEntity());
if (rules.process(context)) {
@ -198,7 +198,7 @@ public void onEntityExplode(EntityExplodeEvent event) {
while (iter.hasNext()) {
Block block = iter.next();
rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_BREAK);
rules = wcfg.getRuleList().get(DefaultAttachments.BLOCK_BREAK);
context = new BukkitContext(plugin, event);
context.setSourceEntity(event.getEntity());
context.setTargetBlock(block.getState());
@ -215,7 +215,7 @@ public void onExplosionPrime(ExplosionPrimeEvent event) {
WorldConfiguration wcfg = cfg.get(event.getEntity().getWorld());
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ENTITY_EXPLODE);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ENTITY_EXPLODE);
BukkitContext context = new BukkitContext(plugin, event);
context.setTargetEntity(event.getEntity());
if (rules.process(context)) {
@ -230,7 +230,7 @@ public void onCreatureSpawn(CreatureSpawnEvent event) {
WorldConfiguration wcfg = cfg.get(event.getEntity().getWorld());
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ENTITY_SPAWN);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ENTITY_SPAWN);
BukkitContext context = new BukkitContext(plugin, event);
context.setTargetEntity(event.getEntity());
if (rules.process(context)) {
@ -245,7 +245,7 @@ public void onPigZap(PigZapEvent event) {
WorldConfiguration wcfg = cfg.get(event.getEntity().getWorld());
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ENTITY_STRIKE);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ENTITY_STRIKE);
BukkitContext context = new BukkitContext(plugin, event);
context.setTargetEntity(event.getEntity());
if (rules.process(context)) {
@ -260,7 +260,7 @@ public void onCreeperPower(CreeperPowerEvent event) {
WorldConfiguration wcfg = cfg.get(event.getEntity().getWorld());
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ENTITY_STRIKE);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ENTITY_STRIKE);
BukkitContext context = new BukkitContext(plugin, event);
context.setTargetEntity(event.getEntity());
if (rules.process(context)) {
@ -278,7 +278,7 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) {
// RuleLists
RuleSet rules = wcfg.getRuleList().get(event.getTo() == Material.AIR ?
KnownAttachment.BLOCK_BREAK : KnownAttachment.BLOCK_PLACE);
DefaultAttachments.BLOCK_BREAK : DefaultAttachments.BLOCK_PLACE);
BukkitContext context = new BukkitContext(plugin, event);
context.setSourceEntity(entity);
BlockState newState = event.getBlock().getState(); // This event is lame

View File

@ -28,7 +28,7 @@
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.hanging.HangingPlaceEvent;
import com.sk89q.rulelists.KnownAttachment;
import com.sk89q.rulelists.DefaultAttachments;
import com.sk89q.rulelists.RuleSet;
/**
@ -63,7 +63,7 @@ public void onHangingingBreak(HangingBreakEvent event) {
WorldConfiguration wcfg = cfg.get(world);
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ENTITY_DAMAGE);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ENTITY_DAMAGE);
BukkitContext context = new BukkitContext(plugin, event);
if (event instanceof HangingBreakByEntityEvent) {
context.setSourceEntity(((HangingBreakByEntityEvent) event).getRemover());
@ -84,7 +84,7 @@ public void onHangingPlace(HangingPlaceEvent event) {
WorldConfiguration wcfg = cfg.get(world);
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ENTITY_SPAWN);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ENTITY_SPAWN);
BukkitContext context = new BukkitContext(plugin, event);
context.setSourceEntity(event.getPlayer());
context.setTargetEntity(event.getEntity());

View File

@ -28,7 +28,7 @@
import org.bukkit.event.painting.PaintingBreakByEntityEvent;
import org.bukkit.event.painting.PaintingBreakEvent;
import org.bukkit.event.painting.PaintingPlaceEvent;
import com.sk89q.rulelists.KnownAttachment;
import com.sk89q.rulelists.DefaultAttachments;
import com.sk89q.rulelists.RuleSet;
/**
@ -65,7 +65,7 @@ public void onPaintingBreak(PaintingBreakEvent event) {
WorldConfiguration wcfg = cfg.get(world);
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ENTITY_DAMAGE);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ENTITY_DAMAGE);
BukkitContext context = new BukkitContext(plugin, event);
if (event instanceof PaintingBreakByEntityEvent) {
context.setSourceEntity(((PaintingBreakByEntityEvent) event).getRemover());
@ -86,7 +86,7 @@ public void onPaintingPlace(PaintingPlaceEvent event) {
WorldConfiguration wcfg = cfg.get(world);
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ENTITY_SPAWN);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ENTITY_SPAWN);
BukkitContext context = new BukkitContext(plugin, event);
context.setSourceEntity(event.getPlayer());
context.setTargetEntity(event.getPainting());

View File

@ -42,7 +42,7 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.PluginManager;
import com.sk89q.rulelists.KnownAttachment;
import com.sk89q.rulelists.DefaultAttachments;
import com.sk89q.rulelists.RuleSet;
/**
@ -96,7 +96,7 @@ public void onPlayerJoin(PlayerJoinEvent event) {
}
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.PLAYER_JOIN);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.PLAYER_JOIN);
BukkitContext context = new BukkitContext(plugin, event);
context.setTargetEntity(player);
rules.process(context);
@ -108,7 +108,7 @@ public void onPlayerChat(AsyncPlayerChatEvent event) {
WorldConfiguration wcfg = plugin.getGlobalStateManager().get(player.getWorld());
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.CHAT);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.CHAT);
BukkitContext context = new BukkitContext(plugin, event);
context.setSourceEntity(event.getPlayer());
context.setMessage(event.getMessage());
@ -159,7 +159,7 @@ public void onPlayerQuit(PlayerQuitEvent event) {
/* --- No short-circuit returns below this line --- */
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.PLAYER_QUIT);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.PLAYER_QUIT);
BukkitContext context = new BukkitContext(plugin, event);
context.setSourceEntity(player);
rules.process(context);
@ -185,7 +185,7 @@ public void onPlayerInteract(PlayerInteractEvent event) {
// Send one for the block
Block block = event.getClickedBlock();
if (block != null) {
rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_INTERACT);
rules = wcfg.getRuleList().get(DefaultAttachments.BLOCK_INTERACT);
context = new BukkitContext(plugin, event);
context.setSourceEntity(player);
context.setTargetBlock(event.getClickedBlock().getState());
@ -197,7 +197,7 @@ public void onPlayerInteract(PlayerInteractEvent event) {
// Send one for the item in the end
ItemStack heldItem = event.getPlayer().getItemInHand();
if (heldItem != null) {
rules = wcfg.getRuleList().get(KnownAttachment.ITEM_USE);
rules = wcfg.getRuleList().get(DefaultAttachments.ITEM_USE);
context = new BukkitContext(plugin, event);
context.setSourceEntity(event.getPlayer());
context.setItem(heldItem);
@ -214,7 +214,7 @@ public void onPlayerDropItem(PlayerDropItemEvent event) {
Player player = event.getPlayer();
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ITEM_DROP);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ITEM_DROP);
BukkitContext context = new BukkitContext(plugin, event);
context.setSourceEntity(player);
context.setItem(event.getItemDrop().getItemStack());
@ -230,7 +230,7 @@ public void onPlayerPickupItem(PlayerPickupItemEvent event) {
WorldConfiguration wcfg = cfg.get(event.getPlayer().getWorld());
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ITEM_PICKUP);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ITEM_PICKUP);
BukkitContext context = new BukkitContext(plugin, event);
context.setSourceEntity(event.getPlayer());
context.setItem(event.getItem().getItemStack());
@ -250,7 +250,7 @@ public void onPlayerDeath(PlayerDeathEvent event) {
/* --- No short-circuit returns below this line --- */
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ENTITY_DEATH);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ENTITY_DEATH);
BukkitContext context = new BukkitContext(plugin, event);
context.setTargetEntity(player);
rules.process(context);
@ -265,7 +265,7 @@ public void onPlayerBucketFill(PlayerBucketFillEvent event) {
WorldConfiguration wcfg = cfg.get(world);
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ITEM_USE);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ITEM_USE);
BukkitContext context = new BukkitContext(plugin, event);
context.setSourceEntity(event.getPlayer());
context.setItem(event.getItemStack());
@ -284,7 +284,7 @@ public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
WorldConfiguration wcfg = cfg.get(world);
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ITEM_USE);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ITEM_USE);
BukkitContext context = new BukkitContext(plugin, event);
context.setSourceEntity(event.getPlayer());
context.setItem(event.getItemStack());
@ -304,7 +304,7 @@ public void onPlayerRespawn(PlayerRespawnEvent event) {
/* --- No short-circuit returns below this line --- */
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.PLAYER_RESPAWN);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.PLAYER_RESPAWN);
BukkitContext context = new BukkitContext(plugin, event);
context.setSourceEntity(event.getPlayer());
rules.process(context);
@ -318,7 +318,7 @@ public void onPlayerBedEnter(PlayerBedEnterEvent event) {
WorldConfiguration wcfg = cfg.get(player.getWorld());
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_INTERACT);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.BLOCK_INTERACT);
BukkitContext context = new BukkitContext(plugin, event);
context.setSourceEntity(player);
context.setTargetBlock(event.getBed().getState());

View File

@ -60,6 +60,7 @@
import com.sk89q.rebar.config.YamlConfigurationResource;
import com.sk89q.rulelists.Action;
import com.sk89q.rulelists.Criteria;
import com.sk89q.rulelists.DefaultAttachments;
import com.sk89q.rulelists.DefinitionManager;
import com.sk89q.rulelists.ResolverManager;
import com.sk89q.rulelists.RuleListsManager;
@ -317,10 +318,8 @@ public RegionQueryCache getRegionCache() {
* Get the built-in rules.
*
* @return built-in rules
* @throws ConfigurationException
* on config error
* @throws IOException
* on I/O exception
* @throws ConfigurationException on config error
* @throws IOException on I/O exception
*/
public YamlConfiguration getBuiltInRules() throws IOException, ConfigurationException {
YamlConfiguration rules = new YamlConfigurationResource(getClass(),
@ -333,6 +332,8 @@ public YamlConfiguration getBuiltInRules() throws IOException, ConfigurationExce
* Register RuleList resolvers, criterion, and actions.
*/
private void registerRuleList() {
DefaultAttachments.registerWith(ruleListsManager.getAttachments());
// Subject resolvers
ResolverManager resolvers = ruleListsManager.getResolvers();

View File

@ -10,7 +10,7 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.vehicle.VehicleDestroyEvent;
import com.sk89q.rulelists.KnownAttachment;
import com.sk89q.rulelists.DefaultAttachments;
import com.sk89q.rulelists.RuleSet;
/**
@ -45,7 +45,7 @@ public void onVehicleDestroy(VehicleDestroyEvent event) {
WorldConfiguration wcfg = cfg.get(vehicle.getWorld());
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ENTITY_DAMAGE);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ENTITY_DAMAGE);
BukkitContext context = new BukkitContext(plugin, event);
context.setSourceEntity(destroyer);
context.setTargetEntity(vehicle);

View File

@ -26,7 +26,7 @@
import org.bukkit.event.weather.ThunderChangeEvent;
import org.bukkit.event.weather.WeatherChangeEvent;
import com.sk89q.rulelists.KnownAttachment;
import com.sk89q.rulelists.DefaultAttachments;
import com.sk89q.rulelists.RuleSet;
/**
@ -58,7 +58,7 @@ public void onWeatherChange(WeatherChangeEvent event) {
WorldConfiguration wcfg = cfg.get(event.getWorld());
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.WEATHER_TRANSITION);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.WEATHER_TRANSITION);
BukkitContext context = new BukkitContext(plugin, event);
if (rules.process(context)) {
event.setCancelled(true);
@ -72,7 +72,7 @@ public void onThunderChange(ThunderChangeEvent event) {
WorldConfiguration wcfg = cfg.get(event.getWorld());
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.WEATHER_TRANSITION);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.WEATHER_TRANSITION);
BukkitContext context = new BukkitContext(plugin, event);
if (rules.process(context)) {
event.setCancelled(true);
@ -88,7 +88,7 @@ public void onLightningStrike(LightningStrikeEvent event) {
WorldConfiguration wcfg = cfg.get(event.getWorld());
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.WEATHER_PHENOMENON);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.WEATHER_PHENOMENON);
BukkitContext context = new BukkitContext(plugin, event);
context.setTargetBlock(loc.getBlock().getState());
if (rules.process(context)) {

View File

@ -11,7 +11,7 @@
import org.bukkit.event.world.WorldSaveEvent;
import org.bukkit.event.world.WorldUnloadEvent;
import com.sk89q.rulelists.KnownAttachment;
import com.sk89q.rulelists.DefaultAttachments;
import com.sk89q.rulelists.RuleSet;
/**
@ -45,7 +45,7 @@ public void onWorldLoad(WorldLoadEvent event) {
/* --- No short-circuit returns below this line --- */
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.WORLD_LOAD);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.WORLD_LOAD);
BukkitContext context = new BukkitContext(plugin, event);
rules.process(context);
}
@ -56,7 +56,7 @@ public void onWorldLoad(WorldUnloadEvent event) {
WorldConfiguration wcfg = cfg.get(event.getWorld());
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.WORLD_UNLOAD);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.WORLD_UNLOAD);
BukkitContext context = new BukkitContext(plugin, event);
if (rules.process(context)) {
event.setCancelled(true);
@ -72,7 +72,7 @@ public void onWorldSave(WorldSaveEvent event) {
/* --- No short-circuit returns below this line --- */
// RuleLists
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.WORLD_SAVE);
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.WORLD_SAVE);
BukkitContext context = new BukkitContext(plugin, event);
rules.process(context);
}