Browse Source

handled NullPointerException

mastercake10 7 years ago
parent
commit
fd243a75d2
1 changed files with 18 additions and 14 deletions
  1. 18 14
      TimeIsMoney2/src/de/Linus122/TimeIsMoney/Main.java

+ 18 - 14
TimeIsMoney2/src/de/Linus122/TimeIsMoney/Main.java

@@ -102,21 +102,25 @@ public class Main extends JavaPlugin{
 		final int seconds = getConfig().getInt("give_money_every_second");
 		Bukkit.getScheduler().runTaskTimerAsynchronously(this, new Runnable(){
 			public void run(){
-				for(Player p : Bukkit.getOnlinePlayers()){
-					if(disabledWorlds.contains(p.getWorld().getName())) continue;
-					if(!boundIPs.containsKey(p.getAddress().getHostName())){
-						boundIPs.put(p.getAddress().getHostName(), p.getUniqueId());
-					}
-					if(onlineSeconds.containsKey(p.getUniqueId())){
-						
-						onlineSeconds.put(p.getUniqueId(), onlineSeconds.get(p.getUniqueId()) + 1);
-					}else{
-						onlineSeconds.put(p.getUniqueId(), 1);
-					}
-					if(onlineSeconds.get(p.getUniqueId()) > seconds){
-						pay(p);
-						onlineSeconds.remove(p.getUniqueId());
+				try{
+					for(Player p : Bukkit.getOnlinePlayers()){
+						if(disabledWorlds.contains(p.getWorld().getName())) continue;
+						if(!boundIPs.containsKey(p.getAddress().getHostName())){
+							boundIPs.put(p.getAddress().getHostName(), p.getUniqueId());
+						}
+						if(onlineSeconds.containsKey(p.getUniqueId())){
+							
+							onlineSeconds.put(p.getUniqueId(), onlineSeconds.get(p.getUniqueId()) + 1);
+						}else{
+							onlineSeconds.put(p.getUniqueId(), 1);
+						}
+						if(onlineSeconds.get(p.getUniqueId()) > seconds){
+							pay(p);
+							onlineSeconds.remove(p.getUniqueId());
+						}
 					}
+				}catch(NullPointerException e){
+					// 
 				}
 			}
 		}, 20L, 20L);