Skip to content

Commit 4e9141d

Browse files
committed
v1.1.3
- More "compatibility" with older versions - Extra debug information for the ENTITY_KILLED_BY statistic
1 parent 3363c00 commit 4e9141d

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>to.us.tf</groupId>
88
<artifactId>DeathSpectating</artifactId>
9-
<version>1.1.1</version>
9+
<version>1.1.3</version>
1010
<properties>
1111
<maven.compiler.source>1.8</maven.compiler.source>
1212
<maven.compiler.target>1.8</maven.compiler.target>

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,17 @@
99
*/
1010
public class CompatUtil
1111
{
12+
private static Integer serverVersion = null;
13+
private static int currentVersion = 11;
1214
public static boolean isNewer()
1315
{
16+
return getVersion() > currentVersion;
17+
}
18+
19+
public static int getVersion()
20+
{
21+
if (serverVersion != null)
22+
return serverVersion;
1423
String version = Bukkit.getBukkitVersion();
1524
version = version.substring(2);
1625
version = version.substring(0, version.indexOf("."));
@@ -22,8 +31,14 @@ public static boolean isNewer()
2231
catch (Exception e)
2332
{
2433
Bukkit.getLogger().warning("[DeathSpectating] Was not able to determine bukkit version.");
25-
return false;
34+
return -1;
2635
}
27-
return versionNumber > 11;
36+
serverVersion = versionNumber;
37+
return versionNumber;
38+
}
39+
40+
public static boolean isOlder(int version)
41+
{
42+
return getVersion() < version;
2843
}
2944
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public void onEnable()
4949
getServer().getPluginManager().registerEvents(this, this);
5050
getServer().getPluginManager().registerEvents(new DamageListener(this), this);
5151
getServer().getPluginManager().registerEvents(new MiscListeners(this), this);
52-
getServer().getPluginManager().registerEvents(new Titles(this, configManager), this);
52+
if (!CompatUtil.isOlder(11)) //TODO: register in class, not in main(?)
53+
getServer().getPluginManager().registerEvents(new Titles(this, configManager), this);
5354
}
5455

5556
public ConfigManager getConfigManager()
@@ -246,6 +247,13 @@ public boolean startDeathSpectating(Player player)
246247
player.incrementStatistic(Statistic.ENTITY_KILLED_BY, killer.getType());
247248
}
248249
catch (IllegalArgumentException e) {} // "The supplied EntityType does not have a corresponding statistic"
250+
catch (NullPointerException e)
251+
{
252+
getLogger().warning("NPE: Was unable to increment ENTITY_KILLED_BY statistic.");
253+
getLogger().info("If you wish to report this, please include the information below:");
254+
getLogger().info("Killer was " + killer.toString());
255+
getLogger().info("Player was " + player.toString());
256+
}
249257
}
250258

251259
//Increment _killer's_ PLAYER_KILLS

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@ void onPlayerBasicallyWouldBeDead(EntityDamageEvent event)
4747
if (inventory.getItemInMainHand().getType() == Material.TOTEM || inventory.getItemInOffHand().getType() == Material.TOTEM)
4848
return;
4949
}
50-
catch (Exception e) //1.10 and lower "compatibility"
50+
catch (NoSuchFieldError | NoSuchMethodError e) //TOTEM (not in 1.10 and below) //getItemInMainHand, etc. (not in 1.8 and below)
5151
{
52-
if (CompatUtil.isNewer()) return;
53-
else throw e;
52+
if (CompatUtil.isNewer()) throw e;
5453
}
5554

5655
//Ignore if this is probably the result of the Essentials suicide command

0 commit comments

Comments
 (0)