Skip to content

Commit

Permalink
Merge pull request #1878 from mcmonkey4eva/master
Browse files Browse the repository at this point in the history
pull request for wow 1.13 issues fixing doing happening
  • Loading branch information
mcmonkey4eva committed Jan 16, 2019
2 parents f965d96 + 8c40fce commit 990c362
Show file tree
Hide file tree
Showing 18 changed files with 405 additions and 522 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ public boolean applyDetermination(ScriptContainer container, String determinatio

@Override
public ScriptEntryData getScriptEntryData() {
return new BukkitScriptEntryData(entity.isPlayer() ? dEntity.getPlayerFrom(event.getEntity()) : null,
entity.isCitizensNPC() ? dEntity.getNPCFrom(event.getEntity()) : null);
return new BukkitScriptEntryData(entity != null && entity.isPlayer() ? dEntity.getPlayerFrom(event.getEntity()) : null,
entity != null && entity.isCitizensNPC() ? dEntity.getNPCFrom(event.getEntity()) : null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,11 @@ public String run(Attribute attribute, dObject object) {
int x = heightMap[0];
for (int i : heightMap) {
if (Math.abs(x - i) > tolerance) {
return Element.FALSE.getAttribute(attribute.fulfill(1));
return new Element(false).getAttribute(attribute.fulfill(1));
}
}

return Element.TRUE.getAttribute(attribute.fulfill(1));
return new Element(true).getAttribute(attribute.fulfill(1));
}
});

Expand Down
32 changes: 8 additions & 24 deletions plugin/src/main/java/net/aufdemrand/denizen/objects/dEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2061,14 +2061,8 @@ else if (mtr.angle == BlockFace.EAST) {
// Returns whether the entity is leashed.
// -->
if (attribute.startsWith("leashed") || attribute.startsWith("is_leashed")) {
if (isLivingEntity()) {
return new Element(getLivingEntity().isLeashed())
.getAttribute(attribute.fulfill(1));
}
else {
return Element.FALSE
.getAttribute(attribute.fulfill(1));
}
return new Element(isLivingEntity() && getLivingEntity().isLeashed())
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
Expand Down Expand Up @@ -2103,14 +2097,8 @@ else if (mtr.angle == BlockFace.EAST) {
// Returns whether the entity will not be removed completely when far away from players.
// -->
if (attribute.startsWith("persistent") || attribute.startsWith("is_persistent")) {
if (isLivingEntity()) {
return new Element(!getLivingEntity().getRemoveWhenFarAway())
.getAttribute(attribute.fulfill(1));
}
else {
return Element.FALSE
.getAttribute(attribute.fulfill(1));
}
return new Element(isLivingEntity() && !getLivingEntity().getRemoveWhenFarAway())
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
Expand Down Expand Up @@ -2355,12 +2343,8 @@ && getBukkitEntity() instanceof Item) {
// Returns whether the entity is a mob (Not a player or NPC).
// -->
if (attribute.startsWith("is_mob")) {
if (!isPlayer() && !isNPC()) {
return Element.TRUE.getAttribute(attribute.fulfill(1));
}
else {
return Element.FALSE.getAttribute(attribute.fulfill(1));
}
return new Element(!isPlayer() && !isNPC() && isLivingEntity())
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
Expand Down Expand Up @@ -2695,10 +2679,10 @@ && getBukkitEntity() instanceof Item) {
PotionEffectType effectType = PotionEffectType.getByName(attribute.getContext(1));
for (PotionEffect effect : helper.getCustomEffects()) {
if (effect.getType().equals(effectType)) {
return Element.TRUE.getAttribute(attribute.fulfill(1));
return new Element(true).getAttribute(attribute.fulfill(1));
}
}
return Element.FALSE.getAttribute(attribute.fulfill(1));
return new Element(false).getAttribute(attribute.fulfill(1));
}

return new Element(helper.hasCustomEffects())
Expand Down
51 changes: 38 additions & 13 deletions plugin/src/main/java/net/aufdemrand/denizen/objects/dInventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,13 @@
import net.citizensnpcs.api.CitizensAPI;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Nameable;
import org.bukkit.block.BlockState;
import org.bukkit.block.DoubleChest;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.CraftingInventory;
import org.bukkit.inventory.HorseInventory;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.*;
import org.bukkit.inventory.meta.BookMeta;

import java.util.*;
Expand Down Expand Up @@ -87,7 +83,7 @@ public static dInventory mirrorBukkitInventory(Inventory inventory) {
public final static int maxSlots = 54;

// All of the inventory id types we use
public final static String[] idTypes = {"npc", "player", "enderchest", "workbench", "entity", "location", "generic"};
public final static String[] idTypes = {"npc", "player", "crafting", "enderchest", "workbench", "entity", "location", "generic"};


/////////////////////
Expand Down Expand Up @@ -245,6 +241,16 @@ else if (type.equals("npc")) {
return dNPC.valueOf(holder).getDenizenInventory();
}
}
else if (type.equals("crafting")) {
if (dPlayer.matches(holder)) {
dPlayer holderPlayer = dPlayer.valueOf(holder);
Inventory opened = holderPlayer.getPlayerEntity().getOpenInventory().getTopInventory();
if (opened instanceof CraftingInventory) {
return new dInventory(opened);
}
return dPlayer.valueOf(holder).getInventory();
}
}
else if (type.equals("player")) {
if (dPlayer.matches(holder)) {
return dPlayer.valueOf(holder).getInventory();
Expand Down Expand Up @@ -426,7 +432,16 @@ public void setInventory(Inventory inventory, dPlayer player) {
}

public void setTitle(String title) {
if (!(getIdType().equals("generic") || getIdType().equals("script")) || title == null) {
if (title == null) {
return;
}
if (getIdType().equals("location")) {
dLocation location = dLocation.valueOf(getIdHolder());
if (location.getBlock().getBlockData() instanceof Nameable) {
((Nameable) location.getBlock().getBlockData()).setCustomName(title);
}
}
if (!(getIdType().equals("generic") || getIdType().equals("script"))) {
return;
}
if (inventory != null && inventory.getTitle().equals(title)) {
Expand Down Expand Up @@ -569,6 +584,9 @@ else if (holder instanceof Player) {
idHolder = (dNPC.fromEntity((Player) holder)).identify();
return;
}
if (inventory.getType() == InventoryType.CRAFTING) {
idType = "crafting";
}
if (inventory.getType() == InventoryType.ENDER_CHEST) {
idType = "enderchest";
}
Expand Down Expand Up @@ -631,6 +649,13 @@ public dInventory setIdentifiers(String type, String holder) {
return this;
}

/**
* Generally shouldn't be used.
*/
public void setIdType(String type) {
idType = type;
}

public String getIdType() {
return idType == null ? "" : idType;
}
Expand Down Expand Up @@ -1775,11 +1800,11 @@ else if (item != null && item.hasItemMeta() && item.getItemMeta().hasDisplayName
if (!contains.isEmpty()) {
for (dItem item : contains) {
if (containsItem(item, qty)) {
return Element.TRUE.getAttribute(attribute.fulfill(attribs));
return new Element(true).getAttribute(attribute.fulfill(attribs));
}
}
}
return Element.FALSE.getAttribute(attribute.fulfill(attribs));
return new Element(false).getAttribute(attribute.fulfill(attribs));
}

// <--[tag]
Expand Down Expand Up @@ -1811,12 +1836,12 @@ else if (item != null && item.hasItemMeta() && item.getItemMeta().hasDisplayName
if (contains.size() == list.size()) {
for (dItem item : contains) {
if (!containsItem(item, qty)) {
return Element.FALSE.getAttribute(attribute.fulfill(attribs));
return new Element(false).getAttribute(attribute.fulfill(attribs));
}
}
return Element.TRUE.getAttribute(attribute.fulfill(attribs));
return new Element(true).getAttribute(attribute.fulfill(attribs));
}
return Element.FALSE.getAttribute(attribute.fulfill(attribs));
return new Element(false).getAttribute(attribute.fulfill(attribs));
}

// <--[tag]
Expand Down
11 changes: 5 additions & 6 deletions plugin/src/main/java/net/aufdemrand/denizen/objects/dItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,9 @@ public String getScriptName() {
}

public dMaterial getMaterial() {
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13_R2)) {
return dMaterial.getMaterialFrom(getItemStack().getType());
}
return dMaterial.getMaterialFrom(getItemStack().getType(), getItemStack().getData().getData());
}

Expand Down Expand Up @@ -583,16 +586,12 @@ else if (isItemscript()) {
return "i@" + identifyMaterial().replace("m@", "");
}


// Special-case that essentially fetches the material of the items and uses its 'identify()' method
public String identifyMaterial() {
return dMaterial.getMaterialFrom(item.getType(), item.getData().getData()).identifySimple();
return getMaterial().identifySimple();
}


// Special-case that essentially fetches the material of the items and uses its 'identify()' method
public String identifyMaterialNoIdentifier() {
return dMaterial.getMaterialFrom(item.getType(), item.getData().getData()).identifySimpleNoIdentifier();
return getMaterial().identifySimpleNoIdentifier();
}

public String identifyNoIdentifier() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Attachable;
import org.bukkit.material.Directional;
import org.bukkit.material.MaterialData;
import org.bukkit.util.BlockIterator;
import org.bukkit.util.Vector;
Expand Down Expand Up @@ -517,6 +518,23 @@ public String getAttribute(Attribute attribute) {
// BLOCK ATTRIBUTES
/////////////////

// <--[tag]
// @attribute <l@location.block_facing>
// @returns dLocation
// @description
// Returns the relative location vector of where this block is facing.
// Only works for block types that have directionality (such as signs, chests, stairs, etc.).
// This can return for example "1,0,0" to mean the block is facing towards the positive X axis.
// You can use <some_block_location.add[<some_block_location.block_facing>]> to get the block directly in front of this block (based on its facing direction).
// -->
if (attribute.matches("block_facing")) {
if (getBlock().getBlockData() instanceof Directional) {
Vector facing = ((Directional) getBlock().getBlockData()).getFacing().getDirection();
return new dLocation(getWorld(), facing.getX(), facing.getY(), facing.getZ())
.getAttribute(attribute.fulfill(1));
}
}

// <--[tag]
// @attribute <l@location.above>
// @returns dLocation
Expand Down Expand Up @@ -546,7 +564,7 @@ public String getAttribute(Attribute attribute) {
// Returns the location of the block this location is on,
// i.e. returns a location without decimals or direction.
// -->
if (attribute.startsWith("block")) {
if (attribute.matches("block")) {
return new dLocation(getWorld(), getBlockX(), getBlockY(), getBlockZ())
.getAttribute(attribute.fulfill(1));
}
Expand Down
25 changes: 12 additions & 13 deletions plugin/src/main/java/net/aufdemrand/denizen/objects/dMaterial.java
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,9 @@ public static dMaterial registerVariety(dMaterial material) {

// Called on startup
public static void _initialize() {
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13_R2)) {
return;
}
for (dMaterials material : dMaterials.values()) {
try {
Field field = dMaterial.class.getField(material.name());
Expand Down Expand Up @@ -596,8 +599,11 @@ public static dMaterial getMaterialFrom(Material material, int data) {
return material_varieties.get(material).get(data);
}
}
if (material.isBlock()) {
material = NMSHandler.getInstance().getBlockHelper().getBlockData(material, (byte) data).getMaterial();
if (data != 0 && NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13_R2)) {
// upvert old data valued materials
if (material.isBlock()) {
material = NMSHandler.getInstance().getBlockHelper().getBlockData(material, (byte) data).getMaterial();
}
}
// Forcible upvert.
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13_R2)) {
Expand Down Expand Up @@ -717,10 +723,6 @@ public static dMaterial quickOfNamed(String string) {
* @return true if matched, otherwise false
*/
public static boolean matches(String arg) {
arg = arg.toUpperCase();
if (arg.startsWith("m@")) {
return true;
}
if (valueOf(arg, noDebugContext) != null) {
return true;
}
Expand Down Expand Up @@ -1140,18 +1142,14 @@ public String run(Attribute attribute, dObject object) {
// @description
// Returns true if the material is a variety of the specified material.
// Example: <m@red_wool.is_made_of[m@wool]> will return true.
// Invalid for 1.13+ servers.
// -->
registerTag("is_made_of", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
dMaterial compared = dMaterial.valueOf(attribute.getContext(1));
if (compared == null) {
return Element.FALSE.getAttribute(attribute.fulfill(1));
}
else {
return new Element(((dMaterial) object).material == compared.getMaterial())
.getAttribute(attribute.fulfill(1));
}
return new Element(compared != null && ((dMaterial) object).material == compared.getMaterial())
.getAttribute(attribute.fulfill(1));
}
});

Expand All @@ -1161,6 +1159,7 @@ public String run(Attribute attribute, dObject object) {
// @description
// Returns the bukkit Material enum value. For example: <m@birch_sapling.bukkit_enum>
// will return 'sapling'
// Unneeded for 1.13+ servers.
// -->
registerTag("bukkit_enum", new TagRunnable() {
@Override
Expand Down
6 changes: 3 additions & 3 deletions plugin/src/main/java/net/aufdemrand/denizen/objects/dNPC.java
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ public String getAttribute(Attribute attribute) {

// Defined in dEntity
if (attribute.startsWith("is_npc")) {
return Element.TRUE.getAttribute(attribute.fulfill(1));
return new Element(true).getAttribute(attribute.fulfill(1));
}

// Defined in dEntity
Expand Down Expand Up @@ -549,7 +549,7 @@ public String getAttribute(Attribute attribute) {
if (attribute.startsWith("has_trigger")
&& attribute.hasContext(1)) {
if (!getCitizen().hasTrait(TriggerTrait.class)) {
return Element.FALSE.getAttribute(attribute.fulfill(1));
return new Element(false).getAttribute(attribute.fulfill(1));
}
TriggerTrait trait = getCitizen().getTrait(TriggerTrait.class);
return new Element(trait.hasTrigger(attribute.getContext(1)))
Expand Down Expand Up @@ -873,7 +873,7 @@ && getCitizen().getTrait(ConstantsTrait.class).getConstant(attribute.getContext(
lookclose = lookclose.substring(10, lookclose.length() - 1);
return new Element(Boolean.valueOf(lookclose)).getAttribute(attribute.fulfill(1));
}
return Element.FALSE.getAttribute(attribute.fulfill(1));
return new Element(false).getAttribute(attribute.fulfill(1));
}

// <--[tag]
Expand Down
Loading

0 comments on commit 990c362

Please sign in to comment.