Skip to content

Commit

Permalink
catch and patch legacy items for we_brush_info, fixes #239
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Dec 13, 2018
1 parent 62ce1e0 commit 59ffe09
Showing 1 changed file with 12 additions and 2 deletions.
Expand Up @@ -12,6 +12,8 @@
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.world.item.ItemType;
import net.aufdemrand.denizen.nms.NMSHandler;
import net.aufdemrand.denizen.nms.NMSVersion;
import net.aufdemrand.denizen.objects.dCuboid;
import net.aufdemrand.denizen.objects.dItem;
import net.aufdemrand.denizen.objects.dPlayer;
Expand All @@ -20,6 +22,7 @@
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.tags.Attribute;
import net.aufdemrand.denizencore.utilities.CoreUtilities;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
Expand All @@ -46,6 +49,13 @@ private WorldEditPlayerExtension(dPlayer player) {

Player player = null;

public static Material deLegacy(Material mat) {
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13_R2) && mat.isLegacy()) {
return Bukkit.getUnsafe().fromLegacy(mat);
}
return mat;
}

@Override
public String getAttribute(Attribute attribute) {

Expand All @@ -64,11 +74,11 @@ public String getAttribute(Attribute attribute) {
WorldEditPlugin worldEdit = Support.getPlugin(WorldEditSupport.class);
ItemType itemType;
if (attribute.hasContext(1)) {
itemType = BukkitAdapter.asItemType(dItem.valueOf(attribute.getContext(1)).getMaterial().getMaterial());
itemType = BukkitAdapter.asItemType(deLegacy(dItem.valueOf(attribute.getContext(1)).getMaterial().getMaterial()));
}
else {
ItemStack itm = player.getEquipment().getItemInMainHand();
itemType = BukkitAdapter.asItemType(itm == null ? Material.AIR : itm.getType());
itemType = BukkitAdapter.asItemType(deLegacy(itm == null ? Material.AIR : itm.getType()));
}
try {
BrushTool brush = worldEdit.getSession(player).getBrushTool(itemType);
Expand Down

0 comments on commit 59ffe09

Please sign in to comment.