mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-16 23:55:23 +01:00
Support accessing the item attribute of the context with match-item and update-item.
This commit is contained in:
parent
cbcc524798
commit
2d9a28b0e6
@ -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
|
||||
@ -65,13 +65,19 @@ public void setPatterns(List<MaterialPattern> patterns) {
|
||||
|
||||
@Override
|
||||
public boolean matches(BukkitContext context) {
|
||||
Entity entity = entityResolver.resolve(context);
|
||||
|
||||
if (entity == null) {
|
||||
return false;
|
||||
ItemStack item;
|
||||
|
||||
if (entityResolver == null) {
|
||||
item = context.getItem();
|
||||
} else {
|
||||
Entity entity = entityResolver.resolve(context);
|
||||
|
||||
if (entity == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
item = itemResolver.resolve(entity).get();
|
||||
}
|
||||
|
||||
ItemStack item = itemResolver.resolve(entity).get();
|
||||
|
||||
if (item == null) {
|
||||
return false;
|
||||
|
@ -45,10 +45,16 @@ public ItemCriteriaLoader(RuleListsManager manager) {
|
||||
|
||||
@Override
|
||||
public ItemCriteria read(ConfigurationNode node) throws DefinitionException {
|
||||
ItemStackSlotResolver resolver = manager.getResolvers()
|
||||
.get(ItemStackSlotResolver.class, node.getString("item", ItemStackSlotResolver.DEFAULT));
|
||||
EntityResolver entityResolver = manager.getResolvers()
|
||||
.get(EntityResolver.class, node.getString("entity", EntityResolver.DEFAULT));
|
||||
String entity = node.getString("entity");
|
||||
EntityResolver entityResolver = null;
|
||||
ItemStackSlotResolver resolver = null;
|
||||
|
||||
if (entity != null) {
|
||||
entityResolver = manager.getResolvers()
|
||||
.get(EntityResolver.class, entity);
|
||||
resolver = manager.getResolvers()
|
||||
.get(ItemStackSlotResolver.class, node.getString("item", ItemStackSlotResolver.DEFAULT));
|
||||
}
|
||||
|
||||
// has-data
|
||||
Boolean hasData = null;
|
||||
@ -67,7 +73,6 @@ public ItemCriteria read(ConfigurationNode node) throws DefinitionException {
|
||||
criteria.setPatterns(patterns);
|
||||
criteria.setDataCheck(hasData);
|
||||
|
||||
|
||||
RuleListUtils.warnUnknown(node, LoggerUtils.getLogger(getClass()),
|
||||
"item", "entity", "has-data", "material");
|
||||
|
||||
|
@ -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
|
||||
@ -57,16 +57,28 @@ public void setNewData(short newData) {
|
||||
|
||||
@Override
|
||||
public void apply(BukkitContext context) {
|
||||
Entity entity = entityResolver.resolve(context);
|
||||
ItemStackSlot slot = itemResolver.resolve(entity);
|
||||
ItemStack item = slot.get();
|
||||
ItemStackSlot slot = null;
|
||||
ItemStack item;
|
||||
|
||||
boolean updated = false;
|
||||
if (entityResolver == null) {
|
||||
item = context.getItem();
|
||||
} else {
|
||||
Entity entity = entityResolver.resolve(context);
|
||||
|
||||
if (entity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
slot = itemResolver.resolve(entity);
|
||||
item = slot.get();
|
||||
}
|
||||
|
||||
if (item == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean updated = false;
|
||||
|
||||
if (destroy) {
|
||||
item = null;
|
||||
updated = true;
|
||||
@ -75,7 +87,7 @@ public void apply(BukkitContext context) {
|
||||
updated = true;
|
||||
}
|
||||
|
||||
if (updated) {
|
||||
if (updated && slot != null) {
|
||||
slot.update(item);
|
||||
}
|
||||
}
|
||||
|
@ -37,10 +37,16 @@ public UpdateItemActionLoader(RuleListsManager manager) {
|
||||
|
||||
@Override
|
||||
public UpdateItemAction read(ConfigurationNode node) throws DefinitionException {
|
||||
ItemStackSlotResolver resolver = manager.getResolvers()
|
||||
.get(ItemStackSlotResolver.class, node.getString("item", ItemStackSlotResolver.DEFAULT));
|
||||
EntityResolver entityResolver = manager.getResolvers()
|
||||
.get(EntityResolver.class, node.getString("entity", EntityResolver.DEFAULT));
|
||||
String entity = node.getString("entity");
|
||||
EntityResolver entityResolver = null;
|
||||
ItemStackSlotResolver resolver = null;
|
||||
|
||||
if (entity != null) {
|
||||
entityResolver = manager.getResolvers()
|
||||
.get(EntityResolver.class, entity);
|
||||
resolver = manager.getResolvers()
|
||||
.get(ItemStackSlotResolver.class, node.getString("item", ItemStackSlotResolver.DEFAULT));
|
||||
}
|
||||
|
||||
boolean destroy = node.getBoolean("destroy", false);
|
||||
short newData = (short) node.getInt("set-data", -1);
|
||||
|
Loading…
Reference in New Issue
Block a user