Skip to content

Commit

Permalink
v1.1.3
Browse files Browse the repository at this point in the history
- More "compatibility" with older versions
- Extra debug information for the ENTITY_KILLED_BY statistic
  • Loading branch information
RoboMWM committed Mar 1, 2017
1 parent 3363c00 commit 4e9141d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>to.us.tf</groupId>
<artifactId>DeathSpectating</artifactId>
<version>1.1.1</version>
<version>1.1.3</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/to/us/tf/DeathSpectating/CompatUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,17 @@
*/
public class CompatUtil
{
private static Integer serverVersion = null;
private static int currentVersion = 11;
public static boolean isNewer()
{
return getVersion() > currentVersion;
}

public static int getVersion()
{
if (serverVersion != null)
return serverVersion;
String version = Bukkit.getBukkitVersion();
version = version.substring(2);
version = version.substring(0, version.indexOf("."));
Expand All @@ -22,8 +31,14 @@ public static boolean isNewer()
catch (Exception e)
{
Bukkit.getLogger().warning("[DeathSpectating] Was not able to determine bukkit version.");
return false;
return -1;
}
return versionNumber > 11;
serverVersion = versionNumber;
return versionNumber;
}

public static boolean isOlder(int version)
{
return getVersion() < version;
}
}
10 changes: 9 additions & 1 deletion src/main/java/to/us/tf/DeathSpectating/DeathSpectating.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public void onEnable()
getServer().getPluginManager().registerEvents(this, this);
getServer().getPluginManager().registerEvents(new DamageListener(this), this);
getServer().getPluginManager().registerEvents(new MiscListeners(this), this);
getServer().getPluginManager().registerEvents(new Titles(this, configManager), this);
if (!CompatUtil.isOlder(11)) //TODO: register in class, not in main(?)
getServer().getPluginManager().registerEvents(new Titles(this, configManager), this);
}

public ConfigManager getConfigManager()
Expand Down Expand Up @@ -246,6 +247,13 @@ public boolean startDeathSpectating(Player player)
player.incrementStatistic(Statistic.ENTITY_KILLED_BY, killer.getType());
}
catch (IllegalArgumentException e) {} // "The supplied EntityType does not have a corresponding statistic"
catch (NullPointerException e)
{
getLogger().warning("NPE: Was unable to increment ENTITY_KILLED_BY statistic.");
getLogger().info("If you wish to report this, please include the information below:");
getLogger().info("Killer was " + killer.toString());
getLogger().info("Player was " + player.toString());
}
}

//Increment _killer's_ PLAYER_KILLS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ void onPlayerBasicallyWouldBeDead(EntityDamageEvent event)
if (inventory.getItemInMainHand().getType() == Material.TOTEM || inventory.getItemInOffHand().getType() == Material.TOTEM)
return;
}
catch (Exception e) //1.10 and lower "compatibility"
catch (NoSuchFieldError | NoSuchMethodError e) //TOTEM (not in 1.10 and below) //getItemInMainHand, etc. (not in 1.8 and below)
{
if (CompatUtil.isNewer()) return;
else throw e;
if (CompatUtil.isNewer()) throw e;
}

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

0 comments on commit 4e9141d

Please sign in to comment.