Skip to content

Commit bc1a0d7

Browse files
committed
1.10 and below compatibility(?) and fix for items with vanishing curse
1 parent afb911b commit bc1a0d7

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package to.us.tf.DeathSpectating;
2+
3+
import org.bukkit.Bukkit;
4+
5+
/**
6+
* Created on 2/27/2017.
7+
*
8+
* @author RoboMWM
9+
*/
10+
public class CompatUtil
11+
{
12+
public static boolean isNewer()
13+
{
14+
String version = Bukkit.getBukkitVersion();
15+
version = version.substring(2);
16+
version = version.substring(0, version.indexOf("."));
17+
int versionNumber;
18+
try
19+
{
20+
versionNumber = Integer.valueOf(version);
21+
}
22+
catch (Exception e)
23+
{
24+
Bukkit.getLogger().warning("[DeathSpectating] Was not able to determine bukkit version.");
25+
return false;
26+
}
27+
return versionNumber > 11;
28+
}
29+
}

src/main/java/to/us/tf/DeathSpectating/DeathSpectating.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public boolean startDeathSpectating(Player player)
162162
//Compile a list of null-free/air-free items to drop
163163
for (ItemStack itemStack : player.getInventory().getContents())
164164
{
165-
if (itemStack != null && itemStack.getType() != Material.AIR && itemStack.containsEnchantment(Enchantment.VANISHING_CURSE))
165+
if (itemStack != null && itemStack.getType() != Material.AIR && !itemStack.containsEnchantment(Enchantment.VANISHING_CURSE))
166166
itemsToDrop.add(itemStack);
167167
}
168168
}

src/main/java/to/us/tf/DeathSpectating/listeners/DamageListener.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.bukkit.event.entity.EntityDamageEvent;
1010
import org.bukkit.inventory.Inventory;
1111
import org.bukkit.inventory.PlayerInventory;
12+
import to.us.tf.DeathSpectating.CompatUtil;
1213
import to.us.tf.DeathSpectating.DeathSpectating;
1314

1415
/**
@@ -41,8 +42,16 @@ void onPlayerBasicallyWouldBeDead(EntityDamageEvent event)
4142

4243
//Ignore if player is holding a totem of undying
4344
PlayerInventory inventory = player.getInventory();
44-
if (inventory.getItemInMainHand().getType() == Material.TOTEM || inventory.getItemInOffHand().getType() == Material.TOTEM)
45-
return;
45+
try
46+
{
47+
if (inventory.getItemInMainHand().getType() == Material.TOTEM || inventory.getItemInOffHand().getType() == Material.TOTEM)
48+
return;
49+
}
50+
catch (Exception e) //1.10 and lower "compatibility"
51+
{
52+
if (CompatUtil.isNewer()) return;
53+
else throw e;
54+
}
4655

4756
//Ignore if this is probably the result of the Essentials suicide command
4857
//Essentials will perform Player#setHealth(0), which does not fire a damage event, but does kill the player. This will lead to a double death message.
@@ -51,6 +60,7 @@ void onPlayerBasicallyWouldBeDead(EntityDamageEvent event)
5160
return;
5261

5362
player.setLastDamageCause(event);
63+
//TODO: fire EntityResurrectEvent
5464

5565
/*Put player in death spectating mode*/
5666
if (instance.startDeathSpectating(player))

0 commit comments

Comments
 (0)