Skip to content

Commit

Permalink
Fix 1.8.8 compatibility issues and general code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Wright committed Jun 1, 2022
1 parent 77b35fb commit 2efa446
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 34 deletions.
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.evancolewright</groupId>
<artifactId>headdrops</artifactId>
<version>1.5.4</version>
<version>1.5.5</version>
<packaging>jar</packaging>

<name>HeadDrops</name>
Expand All @@ -24,16 +24,16 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>9</source>
<target>9</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<outputDirectory>C:\\Users\\evanc\\Desktop\\Minecraft Server\\plugins</outputDirectory>
<outputDirectory>C:\\Users\\evanc\\Desktop\\1.13+ Minecraft Server\\plugins</outputDirectory>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -91,7 +91,7 @@
<version>1.18.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- NBPApi -->
<!-- NBP-API -->
<dependency>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ public final class HeadDropsAPI
*/
public static boolean isPlayerHead(ItemStack itemStack)
{
if (itemStack == null) return false;
if (itemStack.getType() == Material.AIR) return false;
NBTItem nbtItem = new NBTItem(itemStack);
if (!nbtItem.hasNBTData() || !nbtItem.hasCustomNbtData())
return false;
return nbtItem.getUUID("HeadDrops_Owner") != null;
return nbtItem.getString("HeadDrops_Owner") != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void loadCache()
{
File headLocationsFile = new File(this.plugin.getDataFolder() + File.separator + "data", "headLocations.json");
if (!headLocationsFile.exists())
return;
return; // Needed for first run of the plugin before the data file is created.
try (Reader reader = new FileReader(headLocationsFile))
{
this.headLocationCache = new ArrayList<>(Arrays.asList(this.gson.fromJson(reader, PlayerHeadData[].class)));
Expand All @@ -73,7 +73,7 @@ public void saveCache()
}

/**
* Adapter class to JSON serialize / deserialize {@link Location} objects.
* Adapter class to serialize / deserialize {@link Location} objects to/from JSOn.
*
* @author Evan Wright
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public static PlayerHeadData fromPlacedHead(ItemStack itemStack, Location locati
{
NBTItem item = new NBTItem(itemStack);
ItemMeta itemMeta = itemStack.getItemMeta();
return new PlayerHeadData(item.getUUID(
"HeadDrops_Owner"),
return new PlayerHeadData(UUID.fromString(item.getString(
"HeadDrops_Owner")),
itemMeta.getDisplayName(),
itemMeta.getLore(),
location
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,17 @@ public final class HeadUtils
{
public static ItemStack createPlayerHead(UUID playerUUID, Player killer, String displayName, List<String> lore)
{
ItemStack playerHead;
try
{
playerHead = new ItemStack(Material.getMaterial("PLAYER_HEAD"), 1);
} catch(IllegalArgumentException | NullPointerException exception)
{
playerHead = new ItemStack(Material.getMaterial("SKULL_ITEM"), 1, (short) 3);
}
ItemStack playerHead = getVersionIndependentHead();
SkullMeta skullMeta = (SkullMeta) playerHead.getItemMeta();
skullMeta.setOwner(Bukkit.getOfflinePlayer(playerUUID).getName());
skullMeta.setDisplayName(replacePlaceHolders(displayName, playerUUID, killer));
skullMeta.setLore(lore.stream().map(s -> replacePlaceHolders(s, playerUUID, killer)).collect(Collectors.toList()));
skullMeta.setLore(lore.stream()
.map(s -> replacePlaceHolders(s, playerUUID, killer))
.collect(Collectors.toList()));
playerHead.setItemMeta(skullMeta);

NBTItem headNBT = new NBTItem(playerHead);
headNBT.setUUID("HeadDrops_Owner", playerUUID);
headNBT.setString("HeadDrops_Owner", playerUUID.toString());

return headNBT.getItem();
}
Expand All @@ -60,4 +55,12 @@ else if (!murderWeapon.hasItemMeta() || murderWeapon.getItemMeta().getDisplayNam

return string;
}

private static ItemStack getVersionIndependentHead()
{
Material material = Material.getMaterial("PLAYER_HEAD");
if (material == null)
return new ItemStack(Material.getMaterial("SKULL_ITEM"), 1, (byte) 3);
return new ItemStack(material);
}
}
30 changes: 17 additions & 13 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
#
# ██╗ ██╗███████╗ █████╗ ██████╗ ██████╗ ██████╗ ██████╗ ██████╗ ███████╗
# ██║ ██║██╔════╝██╔══██╗██╔══██╗██╔══██╗██╔══██╗██╔═══██╗██╔══██╗██╔════╝
# ███████║█████╗ ███████║██║ ██║██║ ██║██████╔╝██║ ██║██████╔╝███████╗
# ██╔══██║██╔══╝ ██╔══██║██║ ██║██║ ██║██╔══██╗██║ ██║██╔═══╝ ╚════██║
# ██║ ██║███████╗██║ ██║██████╔╝██████╔╝██║ ██║╚██████╔╝██║ ███████║
# ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚══════╝
#
# Version: 1.5.4
#
# Thank you for downloading my plugin! If you have any issues or would like to request a feature,
# please open an issue on my GitHub repository (https://github.com/evancolewright/HeadDrops)
# and choose the correct template.
# ============================================================================= #
# #
# #
# ██╗ ██╗███████╗ █████╗ ██████╗ ██████╗ ██████╗ ██████╗ ██████╗ ███████╗ #
# ██║ ██║██╔════╝██╔══██╗██╔══██╗██╔══██╗██╔══██╗██╔═══██╗██╔══██╗██╔════╝ #
# ███████║█████╗ ███████║██║ ██║██║ ██║██████╔╝██║ ██║██████╔╝███████╗ #
# ██╔══██║██╔══╝ ██╔══██║██║ ██║██║ ██║██╔══██╗██║ ██║██╔═══╝ ╚════██║ #
# ██║ ██║███████╗██║ ██║██████╔╝██████╔╝██║ ██║╚██████╔╝██║ ███████║ #
# ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚══════╝ #
# #
# #
# Source Code: https://github.com/evancolewright/HeadDrops #
# Bug Reports: https://github.com/evancolewright/HeadDrops/issues #
# #
# VERSION 1.5.5 #
# ============================================================================= #


# If enabled, the head of a slain player will be added to the killer's inventory rather than dropping on the ground
transport_to_killer_inventory: false
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ version: ${project.version}
main: com.github.evancolewright.headdrops.HeadDropsPlugin
authors: [ evancolewright ]
description: A simple plugin that causes players to drop their heads.
website: evancolewright.github.io
website: evancolewright.github.io
api-version: 1.13

0 comments on commit 2efa446

Please sign in to comment.