From 134b395ac8166351605621d916458fc0029ba366 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Wed, 31 Aug 2016 18:41:49 -0400 Subject: [PATCH] testcommit --- src/alisolarflare/RandomTP.java | 1 - src/iie/DeathListener.java | 46 +++++++++++++++++++++---------- src/iie/HelloWorld.java | 5 ++++ src/iie/HelloWorldPlugin.java | 32 +++++++++++++++------ src/iie/publicstaticvoidmain.java | 38 ------------------------- 5 files changed, 60 insertions(+), 62 deletions(-) delete mode 100644 src/iie/publicstaticvoidmain.java diff --git a/src/alisolarflare/RandomTP.java b/src/alisolarflare/RandomTP.java index f9c1016..046aae0 100644 --- a/src/alisolarflare/RandomTP.java +++ b/src/alisolarflare/RandomTP.java @@ -5,7 +5,6 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.entity.Player; - public class RandomTP{ private int conflictX; diff --git a/src/iie/DeathListener.java b/src/iie/DeathListener.java index 0c65131..cec2892 100644 --- a/src/iie/DeathListener.java +++ b/src/iie/DeathListener.java @@ -8,8 +8,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.player.PlayerLoginEvent; -import org.bukkit.scoreboard.Score; +import org.bukkit.event.player.PlayerJoinEvent; public class DeathListener implements Listener { @@ -33,8 +32,18 @@ public class DeathListener implements Listener { if (Objects.equals(worldString, "hardcore")){ HelloWorldPlugin.deathMap.put(playerString, timeString); + + + if (HelloWorldPlugin.hardcoreTimeDead == null){ + player.sendMessage("Objective hardcoreTimeDead was null"); + }else if (HelloWorldPlugin.hardcoreTimeDead.getScore(playerString) == null){ + HelloWorldPlugin.hardcoreTimeDead.getScore(playerString).setScore(0); + player.sendMessage("Score for hardcoreTimeDead was null, set to " + String.valueOf(HelloWorldPlugin.hardcoreTimeDead.getScore(playerString).getScore())); + } + HelloWorldPlugin.hardcoreTimeDead.getScore(playerString).setScore((int) (System.currentTimeMillis()/1000)); + //player.sendMessage(HelloWorldPlugin.deathMap.toString()); //player.sendMessage("Key saved: " + playerString); //player.sendMessage("Data saved: " + HelloWorldPlugin.deathMap.get(playerString)); @@ -43,32 +52,39 @@ public class DeathListener implements Listener { } @EventHandler(priority = EventPriority.MONITOR) - public void onPlayerLogin(PlayerLoginEvent loginEvent){ + public void onPlayerJoin(PlayerJoinEvent JoinEvent){ - Player player = loginEvent.getPlayer(); + Player player = JoinEvent.getPlayer(); String playerString = (String) player.getName(); - Score score = null; player.sendMessage(playerString + " has joined"); - try{ - score = HelloWorldPlugin.hardcoreTimeDead.getScore(playerString); - player.sendMessage("hardcoreTimeDead = " + String.valueOf(score.getScore())); - }catch(IllegalArgumentException e){ - score.setScore(0); - player.sendMessage("hardcoreTimeDead = " + String.valueOf(score.getScore())); + if (HelloWorldPlugin.hardcoreTimeDead.getScore(playerString) != null){ + HelloWorldPlugin.deathMap.put(playerString, String.valueOf((HelloWorldPlugin.hardcoreTimeDead.getScore(playerString).getScore()) * 1000)); + player.sendMessage("getScore(playerString) was not null"); + }else{ + HelloWorldPlugin.hardcoreTimeDead.getScore(playerString).setScore(0); + HelloWorldPlugin.deathMap.put(playerString, String.valueOf(HelloWorldPlugin.hardcoreTimeDead.getScore(playerString).getScore())); } + + //try{ + // HelloWorldPlugin.hardcoreTimeDead.getScore(playerString); + // player.sendMessage("try"); + //}catch(IllegalArgumentException e){ + // HelloWorldPlugin.hardcoreTimeDead.getScore(playerString).setScore(1); + // player.sendMessage("catch"); + //}finally{ + // HelloWorldPlugin.deathMap.put(playerString, String.valueOf((HelloWorldPlugin.hardcoreTimeDead.getScore(playerString).getScore()) * 1000)); + // player.sendMessage("finally"); + //} + - if (HelloWorldPlugin.deathMap.get(playerString) == null && score.getScore() != 0){ - HelloWorldPlugin.deathMap.put(playerString, String.valueOf((score.getScore()) * 1000)); - player.sendMessage(HelloWorldPlugin.deathMap.get(playerString)); - } } diff --git a/src/iie/HelloWorld.java b/src/iie/HelloWorld.java index 8e3d5e4..b479e65 100644 --- a/src/iie/HelloWorld.java +++ b/src/iie/HelloWorld.java @@ -54,7 +54,12 @@ public class HelloWorld implements CommandExecutor { sender.sendMessage("you are dead for the next " + (86400000 - (currentTime - deathTime) ) /3600000 + " hours"); } + + + sender.sendMessage("Your hardcoreTimeDead score is " + String.valueOf(HelloWorldPlugin.hardcoreTimeDead.getScore(playername).getScore())); + + }else{ sender.sendMessage("You must be a player to use this command!"); } diff --git a/src/iie/HelloWorldPlugin.java b/src/iie/HelloWorldPlugin.java index 13e6cfc..1d7ae4c 100644 --- a/src/iie/HelloWorldPlugin.java +++ b/src/iie/HelloWorldPlugin.java @@ -16,23 +16,39 @@ public class HelloWorldPlugin extends JavaPlugin { public static AbstractMap deathMap = new HashMap(); public void onEnable(){ - registerCommands(); - getServer().getPluginManager().registerEvents(new DeathListener(this), this); - board = Bukkit.getServer().getScoreboardManager().getMainScoreboard(); try{ board.getObjective("hardcoreTimeDead"); - }catch (IllegalArgumentException e){ - hardcoreTimeDead = board.registerNewObjective("hardcoreTimeDead", "dummy"); - }finally{ - hardcoreTimeDead = board.getObjective("hardcoreTimeDead"); - } + }catch (NullPointerException e){ + hardcoreTimeDead = board.registerNewObjective("hardcoreTimeDead", "dummy"); + }finally{ + hardcoreTimeDead = board.getObjective("hardcoreTimeDead"); + } + board = Bukkit.getServer().getScoreboardManager().getMainScoreboard(); + if (board.getObjective("hardcoreTimeDead") != null){ + hardcoreTimeDead = board.getObjective("hardcoreTimeDead"); + }else{ + hardcoreTimeDead = board.registerNewObjective("hardcoreTimeDead", "dummy"); + + } + + registerCommands(); + getServer().getPluginManager().registerEvents(new DeathListener(this), this); + } public void registerCommands(){ getCommand("HelloWorld").setExecutor(new HelloWorld(this)); } } + +//try{ +// board.getObjective("hardcoreTimeDead"); +//}catch (IllegalArgumentException e){ +// hardcoreTimeDead = board.registerNewObjective("hardcoreTimeDead", "dummy"); +//}finally{ +// hardcoreTimeDead = board.getObjective("hardcoreTimeDead"); +//} \ No newline at end of file diff --git a/src/iie/publicstaticvoidmain.java b/src/iie/publicstaticvoidmain.java deleted file mode 100644 index 8be7eba..0000000 --- a/src/iie/publicstaticvoidmain.java +++ /dev/null @@ -1,38 +0,0 @@ -package iie; - -import java.util.AbstractMap; -import java.util.HashMap; - -public class publicstaticvoidmain { - - public static void main(String[] args){ - System.out.println("Hello World!"); - - int test = (int) (System.currentTimeMillis()/1000); - System.out.println(test); - - long currentTime = System.currentTimeMillis(); - int currentTimeInt = (int) (currentTime/1000); - - System.out.println(currentTime + " current time"); - System.out.println(currentTimeInt); - - - System.out.println(Long.parseLong("1472003809703")); - - AbstractMap deathMap = new HashMap(); - deathMap.put("test", "1472003809703"); - long deathTime = Long.parseLong(deathMap.get("test")); - System.out.println(deathMap.get("test")); - System.out.println(deathTime + " is a number"); - - System.out.println(deathMap.get("other")); - System.out.println("you are dead for the next " + ((86400000 - (currentTime - deathTime))/3600000) + " hours"); - - - - - - - } -}