Skip to content

Commit

Permalink
Merge pull request #1874 from mcmonkey4eva/master
Browse files Browse the repository at this point in the history
PR for spigot updates a lot
  • Loading branch information
mcmonkey4eva committed Jan 6, 2019
2 parents 85e4b77 + cf9177b commit f965d96
Show file tree
Hide file tree
Showing 17 changed files with 148 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.aufdemrand.denizen.nms.util.jnbt.Tag;
import org.bukkit.Location;
import org.bukkit.block.Biome;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
Expand Down Expand Up @@ -68,6 +69,10 @@ public static JavaPlugin getJavaPlugin() {
return javaPlugin;
}

public String getNmsMappingsCode() {
return null;
}

public abstract Sidebar createSidebar(Player player);

public abstract BlockLight createBlockLight(Location location, int lightLevel, long ticks);
Expand Down Expand Up @@ -140,4 +145,12 @@ public static Vector fixOffset(Vector offset, double yaw, double pitch) {
public void forceAttachMove(Entity a, Entity b, Vector offset, boolean matchRotation) {
throw new RuntimeException("Unsupported forceAttachMove!");
}

public Boolean getSwitchState(Block b) {
return null;
}

public boolean setSwitchState(Location interactLocation, boolean state) {
return false;
}
}
14 changes: 13 additions & 1 deletion plugin/src/main/java/net/aufdemrand/denizen/Denizen.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.craftbukkit.v1_13_R2.util.CraftMagicNumbers;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.java.JavaPlugin;
Expand Down Expand Up @@ -337,13 +338,24 @@ public NotableManager notableManager() {
public void onEnable() {
if (!NMSHandler.initialize(this)) {
getLogger().warning("-------------------------------------");
getLogger().warning("Denizen is not compatible with this Spigot version! Deactivating Denizen!");
getLogger().warning("This build of Denizen is not compatible with this Spigot version! Deactivating Denizen!");
getLogger().warning("-------------------------------------");
getServer().getPluginManager().disablePlugin(this);
startedSuccessful = false;
return;
}

String mappingsCode = NMSHandler.getInstance().getNmsMappingsCode();
if (mappingsCode != null) {
if (!((CraftMagicNumbers) CraftMagicNumbers.INSTANCE).getMappingsVersion().equals(mappingsCode)) {
getLogger().warning("-------------------------------------");
getLogger().warning("This build of Denizen was built for a different Spigot revision! This may potentially cause issues."
+ " If you are experiencing trouble, update Denizen and Spigot both to latest builds!"
+ " If this message appears with both Denizen and Spigot fully up-to-date, contact the Denizen team (via GitHub, Spigot, or Discord) to request an update be built.");
getLogger().warning("-------------------------------------");
}
}

if (NMSHandler.getVersion().isAtMost(NMSVersion.v1_11_R1)) { // TODO: 1.12 update
logInterceptor = new LogInterceptor();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,13 @@ public void onDespawn() {
* Makes the NPC sit
*/
public void sit() {
if (!npc.isSpawned() || npc.getEntity().getType() != EntityType.PLAYER) {
if (!npc.isSpawned()) {
return;
}

DenizenAPI.getDenizenNPC(npc).action("sit", null);

chairLocation = npc.getEntity().getLocation().clone();
sitInternal();
sit(npc.getEntity().getLocation());
}

private void sitInternal() {
Expand Down Expand Up @@ -120,10 +119,6 @@ private void standInternal() {
public void sitInternal(Location location) {
DenizenAPI.getDenizenNPC(npc).action("sit", null);

if (npc.getEntity().getType() != EntityType.PLAYER) {
return;
}

/*
* Teleport NPC to the location before
* sending the sit packet to the clients.
Expand Down
33 changes: 28 additions & 5 deletions plugin/src/main/java/net/aufdemrand/denizen/objects/dItem.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package net.aufdemrand.denizen.objects;

import net.aufdemrand.denizen.nms.NMSHandler;
import net.aufdemrand.denizen.nms.NMSVersion;
import net.aufdemrand.denizen.objects.notable.NotableManager;
import net.aufdemrand.denizen.objects.properties.item.*;
import net.aufdemrand.denizen.scripts.containers.core.BookScriptContainer;
import net.aufdemrand.denizen.scripts.containers.core.ItemScriptContainer;
import net.aufdemrand.denizen.scripts.containers.core.ItemScriptHelper;
import net.aufdemrand.denizen.tags.BukkitTagContext;
import net.aufdemrand.denizen.utilities.MaterialCompat;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.objects.*;
import net.aufdemrand.denizencore.objects.notable.Notable;
Expand All @@ -17,11 +19,13 @@
import net.aufdemrand.denizencore.tags.Attribute;
import net.aufdemrand.denizencore.tags.TagContext;
import net.aufdemrand.denizencore.utilities.CoreUtilities;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Item;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -143,7 +147,7 @@ else if (ScriptRegistry.containsScript(m.group(1), BookScriptContainer.class)) {

if (aH.matchesInteger(material)) {
if (!nope) {
dB.echoError("Material ID and data magic number support is deprecated and WILL be removed in a future release.");
dB.echoError("Material ID and data magic number support is deprecated and WILL be removed in a future release. For item input of '" + string + "'.");
}
stack = new dItem(Integer.valueOf(material));
}
Expand Down Expand Up @@ -225,20 +229,39 @@ public dItem(Material material) {

@Deprecated
public dItem(int itemId) {
this(new ItemStack(dMaterial.getLegacyMaterial(itemId)));
this(MaterialCompat.updateItem(itemId));
}

private static ItemStack fixQty(ItemStack item, int qty) {
item.setAmount(qty);
return item;
}

@Deprecated
public dItem(int itemId, int qty) {
this(new ItemStack(dMaterial.getLegacyMaterial(itemId), qty));
this(fixQty(MaterialCompat.updateItem(itemId), qty));
}

public dItem(Material material, int qty) {
this(new ItemStack(material, qty));
}

public dItem(dMaterial material, int qty) {
this(new ItemStack(material.getMaterial(), qty, (short) 0, material.getData()));
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13_R2)) {
this.item = new ItemStack(material.getMaterial(), qty);
}
else {
this.item = new ItemStack(material.getMaterial(), qty, (short) 0, material.getData());
}
}

public dItem(MaterialData data) {
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13_R2) && item.getType().isLegacy()) {
this.item = new ItemStack(Bukkit.getUnsafe().fromLegacy(data));
}
else {
this.item = data.toItemStack();
}
}

public dItem(ItemStack item) {
Expand Down Expand Up @@ -530,7 +553,7 @@ else if (isItemscript()) {
}

// Else, return the material name
else if ((item.getDurability() >= 16 || item.getDurability() < 0) && item.getType() != Material.AIR) {
else if (NMSHandler.getVersion().isAtMost(NMSVersion.v1_12_R1) && (item.getDurability() >= 16 || item.getDurability() < 0) && item.getType() != Material.AIR) {
return "i@" + getMaterial().realName() + "," + item.getDurability() + PropertyParser.getPropertiesString(this);
}
return "i@" + getMaterial().identify().replace("m@", "") + PropertyParser.getPropertiesString(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1409,9 +1409,7 @@ else if (attribute.startsWith("surface_blocks")
Location l = getBlock().getLocation().clone().add(x, y, z);
if (!materials.isEmpty()) {
for (dMaterial material : materials) {
if (material.matchesMaterialData(getBlock()
.getLocation().clone().add(x, y, z).getBlock().getType().getNewData(getBlock()
.getLocation().clone().add(x, y, z).getBlock().getData()))) {
if (material.matchesBlock(getBlock().getLocation().clone().add(x, y, z).getBlock())) {
if (l.clone().add(0, 1, 0).getBlock().getType() == Material.AIR
&& l.clone().add(0, 2, 0).getBlock().getType() == Material.AIR
&& l.getBlock().getType() != Material.AIR) {
Expand Down
16 changes: 12 additions & 4 deletions plugin/src/main/java/net/aufdemrand/denizen/objects/dMaterial.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.aufdemrand.denizencore.utilities.CoreUtilities;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.material.MaterialData;

import java.lang.reflect.Field;
Expand Down Expand Up @@ -742,6 +743,13 @@ public boolean equals(Object object) {
}
}

public boolean matchesBlock(Block b) {
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13_R2)) {
return getMaterial() == b.getType();
}
return matchesMaterialData(b.getType().getNewData(b.getData()));
}


///////////////
// Constructors
Expand Down Expand Up @@ -859,7 +867,7 @@ public String identify() {
if (forcedIdentity != null) {
return "m@" + forcedIdentityLow;
}
if (getData() != null && getData() > 0) {
if (NMSHandler.getVersion().isAtMost(NMSVersion.v1_12_R1) && getData() != null && getData() > 0) {
return "m@" + CoreUtilities.toLowerCase(material.name()) + "," + getData();
}
return "m@" + CoreUtilities.toLowerCase(material.name());
Expand All @@ -869,7 +877,7 @@ public String identifyFull() {
if (forcedIdentity != null) {
return "m@" + forcedIdentityLow + (getData() != null ? "," + getData() : "");
}
if (getData() != null && getData() > 0) {
if (NMSHandler.getVersion().isAtMost(NMSVersion.v1_12_R1) && getData() != null && getData() > 0) {
return "m@" + CoreUtilities.toLowerCase(material.name()) + "," + getData();
}
return "m@" + CoreUtilities.toLowerCase(material.name());
Expand All @@ -887,7 +895,7 @@ public String identifyNoIdentifier() {
if (forcedIdentity != null) {
return forcedIdentityLow;
}
if (getData() != null && getData() > 0) {
if (NMSHandler.getVersion().isAtMost(NMSVersion.v1_12_R1) && getData() != null && getData() > 0) {
return CoreUtilities.toLowerCase(material.name()) + "," + getData();
}
return CoreUtilities.toLowerCase(material.name());
Expand All @@ -904,7 +912,7 @@ public String identifyFullNoIdentifier() {
if (forcedIdentity != null) {
return forcedIdentityLow + (getData() != null ? "," + getData() : "");
}
if (getData() != null && getData() > 0) {
if (NMSHandler.getVersion().isAtMost(NMSVersion.v1_12_R1) && getData() != null && getData() > 0) {
return CoreUtilities.toLowerCase(material.name()) + "," + getData();
}
return CoreUtilities.toLowerCase(material.name());
Expand Down
3 changes: 3 additions & 0 deletions plugin/src/main/java/net/aufdemrand/denizen/objects/dNPC.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ public static dNPC valueOf(String string, TagContext context) {
else {
for (NPC test : CitizensAPI.getNPCRegistry()) {
if (test.getName().equalsIgnoreCase(string)) {
if (context == null || context.debug) {
dB.echoError("Warning: loading NPC by name - use the ID instead! NPC named '" + test.getName() + "' has ID: " + test.getId());
}
return new dNPC(test);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ static dPlayer valueOfInternal(String string, boolean announce) {
// Match as a player name
if (playerNames.containsKey(CoreUtilities.toLowerCase(string))) {
OfflinePlayer player = Bukkit.getOfflinePlayer(playerNames.get(CoreUtilities.toLowerCase(string)));
if (announce) {
dB.echoError("Warning: loading player by name - use the UUID instead (or use tag server.match_player)! Player named '" + player.getName() + "' has UUID: " + player.getUniqueId());
}
return new dPlayer(player);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public dItem getItem() {
}
else {
return new dItem(((Enderman) item.getBukkitEntity())
.getCarriedMaterial().toItemStack());
.getCarriedMaterial());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,6 @@ public void adjust(Mechanism mechanism) {
dB.echoError("Invalid potion effect type '" + data[0] + "'");
return;
}
if (type == null) {
dB.echoError("Invalid potion effect type '" + data[0] + "'");
return;
}
if (!data1.isInt()) {
dB.echoError("Cannot apply effect '" + data[0] + "': '" + data[1] + "' is not a valid integer!");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,16 @@ public void execute(final ScriptEntry scriptEntry) throws CommandExecutionExcept
fis.close();
}
catch (Exception e) {
dB.echoError(e);
dB.echoError("Failed to load yaml file: " + e);
return;
}
if (yamls.containsKey(id)) {
yamls.remove(id);
}
if (yamlConfiguration != null) {
yamls.put(id, yamlConfiguration);
if (yamlConfiguration == null) {
yamlConfiguration = new YamlConfiguration();
}
yamls.put(id, yamlConfiguration);
break;

case UNLOAD:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ else if (!scriptEntry.hasObject("unlimit_stack_size")
scriptEntry.addObject("unlimit_stack_size", new Element(true));
}
else if (!scriptEntry.hasObject("items")
&& !scriptEntry.hasObject("type")) {
&& !scriptEntry.hasObject("type")
&& (arg.matchesArgumentList(dItem.class) || arg.startsWith("item:"))) {
scriptEntry.addObject("items", dList.valueOf(arg.raw_value.startsWith("item:") ?
arg.raw_value.substring("item:".length()) : arg.raw_value).filter(dItem.class, scriptEntry));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.data.Openable;
import org.bukkit.block.data.Powerable;
import org.bukkit.entity.Player;

import java.util.Map;
Expand Down Expand Up @@ -106,13 +104,9 @@ public void run() {
}

public static boolean switchState(Block b) {
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13_R2)) {
if (b.getBlockData() instanceof Openable) {
return ((Openable) b.getBlockData()).isOpen();
}
else if (b.getBlockData() instanceof Powerable) {
return ((Powerable) b.getBlockData()).isPowered(); // TODO: is this valid for levers?
}
Boolean switchState = NMSHandler.getInstance().getSwitchState(b);
if (switchState != null) {
return switchState;
}
//return (b.getData() & 0x8) > 0;
Material type = b.getType();
Expand Down Expand Up @@ -154,18 +148,7 @@ public void switchBlock(ScriptEntry scriptEntry, Location interactLocation, Swit
switchState.equals(SwitchState.TOGGLE)) {

if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13_R2)) {
if (interactLocation.getBlock().getBlockData() instanceof Openable) {
Openable newState = ((Openable) interactLocation.getBlock().getBlockData());
newState.setOpen(!currentState);
interactLocation.getBlock().setBlockData(newState, true);
interactLocation.getBlock().getState().update(true, true);
}
else if (interactLocation.getBlock().getBlockData() instanceof Powerable) {
Powerable newState = ((Powerable) interactLocation.getBlock().getBlockData());
newState.setPowered(!currentState);
interactLocation.getBlock().setBlockData(newState, true);
interactLocation.getBlock().getState().update(true, true);
}
NMSHandler.getInstance().setSwitchState(interactLocation, !currentState);
}
else {
try {
Expand Down
Loading

0 comments on commit f965d96

Please sign in to comment.