File tree Expand file tree Collapse file tree 4 files changed +29
-7
lines changed
src/main/java/to/us/tf/DeathSpectating Expand file tree Collapse file tree 4 files changed +29
-7
lines changed Original file line number Diff line number Diff line change 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>
Original file line number Diff line number Diff line change 99 */
1010public 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}
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments