Skip to content

Commit

Permalink
preparations for 1.13: updating references to skulltype, item data, a…
Browse files Browse the repository at this point in the history
…nd deprecated methods
  • Loading branch information
crashdemons committed Sep 25, 2018
1 parent 1607b29 commit 48f9ad0
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
/bin
/dist
/manifest.mf
/*.bat

/world

Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>org.shininet.bukkit</groupId>
<artifactId>PlayerHeads</artifactId>
<packaging>jar</packaging>
<version>3.12</version>
<version>3.12.1</version>
<name>PlayerHeads</name>

<organization>
Expand Down Expand Up @@ -42,12 +42,12 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
<version>1.13.1-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
<version>1.13.1-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>fr.neatmonster</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.github.crashdemons.playerheads;

import java.util.HashMap;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack;

/**
*
* @author crash
*/
public enum VanillaSkullType {//deprecated in api, but we stll need to keep track of vanilla heads, and there is no method for checking isSkull or isHead in the api...
CREEPER(Material.CREEPER_HEAD,Material.CREEPER_WALL_HEAD),
DRAGON(Material.DRAGON_HEAD,Material.DRAGON_WALL_HEAD),
PLAYER(Material.PLAYER_HEAD,Material.PLAYER_WALL_HEAD),
SKELETON(Material.SKELETON_SKULL,Material.SKELETON_WALL_SKULL),
WITHER(Material.WITHER_SKELETON_SKULL,Material.WITHER_SKELETON_WALL_SKULL),
ZOMBIE(Material.ZOMBIE_HEAD,Material.ZOMBIE_WALL_HEAD);

private Material material;
private Material wallMaterial;

private static class Mappings{
public static HashMap<Material,VanillaSkullType> skullTypeByMaterial = new HashMap<>();
}

VanillaSkullType(Material mat, Material wallMat){
Mappings.skullTypeByMaterial.put(mat, this);
Mappings.skullTypeByMaterial.put(wallMat, this);
}

public Material getMaterial(){
return material;
}
public static VanillaSkullType fromMaterial(Material mat){
return Mappings.skullTypeByMaterial.get(mat);
}
public static Material toMaterial(VanillaSkullType type){
return type.getMaterial();
}
public static boolean hasMaterial(Material mat){
return Mappings.skullTypeByMaterial.containsKey(mat);
}
public static boolean hasItem(ItemStack stack){
return hasMaterial(stack.getType());
}
public static boolean hasBlock(Block block){
return hasMaterial(block.getType());
}
public static VanillaSkullType fromItem(ItemStack stack){
return fromMaterial(stack.getType() );
}
public static VanillaSkullType fromBlock(Block block){
return fromMaterial(block.getType() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package org.shininet.bukkit.playerheads;

import com.github.crashdemons.playerheads.VanillaSkullType;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -196,7 +197,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
return true;
}
ItemStack skullInput = ((Player) sender).getEquipment().getItemInMainHand();
if (skullInput.getType() != Material.SKULL_ITEM) {
if (!VanillaSkullType.hasItem(skullInput)) {
Tools.formatMsg(sender, Lang.BRACKET_LEFT + label + Lang.COLON + Lang.CMD_RENAME + Lang.BRACKET_RIGHT + Lang.SPACE + Lang.ERROR_NOT_A_HEAD);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package org.shininet.bukkit.playerheads;

import com.github.crashdemons.playerheads.VanillaSkullType;
import java.util.List;
import java.util.Random;

Expand Down Expand Up @@ -33,6 +34,7 @@
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager;
import org.bukkit.Bukkit;
import org.bukkit.GameRule;

/**
* @author meiskam
Expand Down Expand Up @@ -90,7 +92,7 @@ public void onEntityDeath(EntityDeathEvent event) {
return;
}

if (plugin.configFile.getBoolean("antideathchest") || Boolean.valueOf(player.getWorld().getGameRuleValue("keepInventory"))) {
if (plugin.configFile.getBoolean("antideathchest") || player.getWorld().getGameRuleValue(GameRule.KEEP_INVENTORY)) {
Location location = player.getLocation();
location.getWorld().dropItemNaturally(location, drop);
} else {
Expand Down Expand Up @@ -123,27 +125,27 @@ public void onEntityDeath(EntityDeathEvent event) {
}
}
} else if (entityType == EntityType.CREEPER) {
EntityDeathHelper(event, SkullType.CREEPER, plugin.configFile.getDouble("creeperdroprate") * lootingrate);
EntityDeathHelper(event, VanillaSkullType.CREEPER, plugin.configFile.getDouble("creeperdroprate") * lootingrate);
} else if (entityType == EntityType.ZOMBIE) {
EntityDeathHelper(event, SkullType.ZOMBIE, plugin.configFile.getDouble("zombiedroprate") * lootingrate);
} else if (entityType == EntityType.SKELETON) {
EntityDeathHelper(event, VanillaSkullType.ZOMBIE, plugin.configFile.getDouble("zombiedroprate") * lootingrate);
} else if (entityType == EntityType.SKELETON || entityType == EntityType.WITHER_SKELETON || entityType == EntityType.STRAY) {//I changed this because entitytype is now distinct for all types of skeleton
if (event.getEntity() instanceof Stray) {
EntityDeathHelper(event, CustomSkullType.STRAY, plugin.configFile.getDouble("straydroprate") * lootingrate);
} else if (event.getEntity() instanceof WitherSkeleton) {
if (plugin.configFile.getDouble("witherdroprate") < 0) {
return;
}
event.getDrops().removeIf(itemStack -> itemStack.getType() == Material.SKULL_ITEM);
EntityDeathHelper(event, SkullType.WITHER, plugin.configFile.getDouble("witherdroprate") * lootingrate);
event.getDrops().removeIf(itemStack -> itemStack.getType() == Material.WITHER_SKELETON_SKULL);
EntityDeathHelper(event, VanillaSkullType.WITHER, plugin.configFile.getDouble("witherdroprate") * lootingrate);
} else if (event.getEntity() instanceof Skeleton) {
EntityDeathHelper(event, SkullType.SKELETON, plugin.configFile.getDouble("skeletondroprate") * lootingrate);
EntityDeathHelper(event, VanillaSkullType.SKELETON, plugin.configFile.getDouble("skeletondroprate") * lootingrate);
}
} else if (entityType == EntityType.SLIME) {
if (((Slime) event.getEntity()).getSize() == 1) {
EntityDeathHelper(event, CustomSkullType.SLIME, plugin.configFile.getDouble("slimedroprate") * lootingrate);
}
} else if (entityType == EntityType.ENDER_DRAGON) {
EntityDeathHelper(event, SkullType.DRAGON, plugin.configFile.getDouble("enderdragondroprate") * lootingrate);
EntityDeathHelper(event, VanillaSkullType.DRAGON, plugin.configFile.getDouble("enderdragondroprate") * lootingrate);
} else {
try {
CustomSkullType customSkullType = CustomSkullType.valueOf(entityType.name());
Expand All @@ -166,8 +168,8 @@ private void EntityDeathHelper(EntityDeathEvent event, Enum<?> type, Double drop

ItemStack drop;

if (type instanceof SkullType) {
drop = Tools.Skull((SkullType) type);
if (type instanceof VanillaSkullType) {
drop = Tools.Skull((VanillaSkullType) type);
} else if (type instanceof CustomSkullType) {
drop = Tools.Skull((CustomSkullType) type);
} else {
Expand All @@ -193,10 +195,10 @@ private void EntityDeathHelper(EntityDeathEvent event, Enum<?> type, Double drop
public void onPlayerInteract(PlayerInteractEvent event) {
Block block = event.getClickedBlock();
Player player = event.getPlayer();
if (block != null && block.getType() == Material.SKULL) {
if (block != null && VanillaSkullType.hasBlock(block) ) {
Skull skullState = (Skull) block.getState();
if (player.hasPermission("playerheads.clickinfo")) {
switch (skullState.getSkullType()) {
switch (VanillaSkullType.fromBlock(block)) {
case PLAYER:
if (skullState.hasOwner()) {
String owner = skullState.getOwningPlayer().getName();
Expand Down Expand Up @@ -228,7 +230,7 @@ public void onPlayerInteract(PlayerInteractEvent event) {
Tools.formatMsg(player, Lang.CLICKINFO2, Tools.format(Lang.HEAD_ZOMBIE));
break;
}
} else if ((skullState.getSkullType() == SkullType.PLAYER) && (skullState.hasOwner())) {
} else if ((VanillaSkullType.fromBlock(block) == VanillaSkullType.PLAYER) && (skullState.hasOwner())) {
String owner = skullState.getOwningPlayer().toString();
CustomSkullType skullType = CustomSkullType.get(owner);
if ((skullType != null) && (!owner.equals(skullType.getOwner()))) {
Expand All @@ -246,7 +248,7 @@ public void onBlockBreak(BlockBreakEvent event) {
}
Block block = event.getBlock();
Player player = event.getPlayer();
if ((player.getGameMode() != GameMode.CREATIVE) && (block.getType() == Material.SKULL)) {
if ((player.getGameMode() != GameMode.CREATIVE) && VanillaSkullType.hasBlock(block)) {
Skull skull = (Skull) block.getState();
if (skull.hasOwner()) {
//String owner = ChatColor.stripColor(skull.getOwner()); //Unnecessary?
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/org/shininet/bukkit/playerheads/Tools.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

package org.shininet.bukkit.playerheads;

import com.github.crashdemons.playerheads.VanillaSkullType;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.SkullType;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -69,13 +69,13 @@ public static ItemStack Skull(String skullOwner, int quantity) {
}

if (skullOwnerLC.equals(Lang.HEAD_SPAWN_CREEPER)) {
return Skull(SkullType.CREEPER, quantity);
return Skull(VanillaSkullType.CREEPER, quantity);
} else if (skullOwnerLC.equals(Lang.HEAD_SPAWN_ZOMBIE)) {
return Skull(SkullType.ZOMBIE, quantity);
return Skull(VanillaSkullType.ZOMBIE, quantity);
} else if (skullOwnerLC.equals(Lang.HEAD_SPAWN_SKELETON)) {
return Skull(SkullType.SKELETON, quantity);
return Skull(VanillaSkullType.SKELETON, quantity);
} else if (skullOwnerLC.equals(Lang.HEAD_SPAWN_WITHER)) {
return Skull(SkullType.WITHER, quantity);
return Skull(VanillaSkullType.WITHER, quantity);
} else {
return Skull(skullOwner, null, quantity);
}
Expand All @@ -87,7 +87,7 @@ public static ItemStack Skull(String skullOwner, String displayName) {
}

public static ItemStack Skull(String skullOwner, String displayName, int quantity) {
ItemStack skull = new ItemStack(Material.SKULL_ITEM, quantity, (short) SkullType.PLAYER.ordinal());
ItemStack skull = new ItemStack(Material.PLAYER_HEAD, quantity);
SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
boolean shouldSet = false;
if ((skullOwner != null) && (!skullOwner.equals(""))) {
Expand All @@ -112,12 +112,12 @@ public static ItemStack Skull(CustomSkullType type, int quantity) {
return Skull(type.getOwner(), type.getDisplayName(), quantity);
}

public static ItemStack Skull(SkullType type) {
public static ItemStack Skull(VanillaSkullType type) {
return Skull(type, Config.defaultStackSize);
}

public static ItemStack Skull(SkullType type, int quantity) {
return new ItemStack(Material.SKULL_ITEM, quantity, (short) type.ordinal());
public static ItemStack Skull(VanillaSkullType type, int quantity) {
return new ItemStack(type.getMaterial(), quantity);
}

public static String format(String text, String... replacement) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ version: ${project.version}
description: Drops a player's head when s/he dies, also mob heads
authors: [meiskam, zand]

api-version: 1.13

main: org.shininet.bukkit.playerheads.PlayerHeads
database: false

Expand Down

0 comments on commit 48f9ad0

Please sign in to comment.