Skip to content

Commit

Permalink
Update for 1.13 and 1.14 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanWolf committed Jul 22, 2019
1 parent 26a43d3 commit 0cb626b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

# 2.0

- 1.14 and 1.13 compatibility

# 1.8

- Race compatibility
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<dependency>
<groupId>com.elmakers.mine.bukkit</groupId>
<artifactId>CompatibilityLib</artifactId>
<version>1.9-1.12.1-2-SNAPSHOT</version>
<version>1.9-1.14-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.Plugin;

import java.net.MalformedURLException;
import java.net.URL;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -58,6 +59,7 @@ public class HotbarController {
private int skillInventoryRows;
private MaterialAndData defaultSkillIcon;
private String defaultDisabledIconURL;
private MaterialAndData skullMaterial;

private Map<UUID, SkillSelector> selectors = new HashMap<>();

Expand Down Expand Up @@ -140,7 +142,17 @@ public ItemStack createSkillItem(SkillDescription skill, Player player) {
}

if (iconURL != null && !iconURL.isEmpty()) {
item = InventoryUtils.getURLSkull(iconURL);
try {
MaterialAndData skullMaterial = getSkullMaterial();
if (skullMaterial == null) {
getLogger().warning("Unable to find a skull material to use for icons");
} else {
item = new ItemStack(skullMaterial.getMaterial(), 1, skullMaterial.getData());
InventoryUtils.setSkullURLAndName(item, new URL(iconURL), "MHF_Question", UUID.randomUUID());
}
} catch (MalformedURLException e) {
getLogger().warning("Invalid URL: " + iconURL);
}
} else {
item = icon.createItemStack();
}
Expand Down Expand Up @@ -174,6 +186,23 @@ public ItemStack createSkillItem(SkillDescription skill, Player player) {
return item;
}

protected MaterialAndData getSkullMaterial() {
if (skullMaterial == null) {
try {
skullMaterial = new MaterialAndData(Material.SKULL_ITEM, (short)3);
getLogger().info("Using legacy skull item");
} catch (Exception not14) {
try {
skullMaterial = new MaterialAndData(Material.valueOf("PLAYER_HEAD"), (short)0);
getLogger().info("Using modern skull item");
} catch (Exception ex) {

}
}
}
return skullMaterial;
}

protected Skill getSkill(String key) {
if (skills == null) return null;
return skills.getSkill(key);
Expand Down

0 comments on commit 0cb626b

Please sign in to comment.