From 5eed40ddb61b37b413f4244594c6c4523eaca4cc Mon Sep 17 00:00:00 2001 From: BuildTools Date: Wed, 31 Aug 2016 13:59:31 -0400 Subject: [PATCH] More fixes --- src/iie/DeathListener.java | 16 ++++++++++------ src/iie/HelloWorldPlugin.java | 14 ++++++++++++-- src/iie/publicstaticvoidmain.java | 18 +++++------------- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/iie/DeathListener.java b/src/iie/DeathListener.java index 36aa3c1..0c65131 100644 --- a/src/iie/DeathListener.java +++ b/src/iie/DeathListener.java @@ -8,7 +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.PlayerJoinEvent; +import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.scoreboard.Score; public class DeathListener implements Listener { @@ -33,8 +33,7 @@ public class DeathListener implements Listener { if (Objects.equals(worldString, "hardcore")){ HelloWorldPlugin.deathMap.put(playerString, timeString); - Score score = HelloWorldPlugin.hardcoreTimeDead.getScore(playerString); - score.setScore((int) (System.currentTimeMillis()/1000)); + HelloWorldPlugin.hardcoreTimeDead.getScore(playerString).setScore((int) (System.currentTimeMillis()/1000)); //player.sendMessage(HelloWorldPlugin.deathMap.toString()); //player.sendMessage("Key saved: " + playerString); @@ -44,26 +43,31 @@ public class DeathListener implements Listener { } @EventHandler(priority = EventPriority.MONITOR) - public void onPlayerLogin(PlayerJoinEvent joinEvent){ + public void onPlayerLogin(PlayerLoginEvent loginEvent){ - Player player = joinEvent.getPlayer(); + Player player = loginEvent.getPlayer(); String playerString = (String) player.getName(); Score score = null; + player.sendMessage(playerString + " has joined"); + try{ score = HelloWorldPlugin.hardcoreTimeDead.getScore(playerString); - }catch(IllegalArgumentException throwable){ + player.sendMessage("hardcoreTimeDead = " + String.valueOf(score.getScore())); + }catch(IllegalArgumentException e){ score.setScore(0); + player.sendMessage("hardcoreTimeDead = " + String.valueOf(score.getScore())); } 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/HelloWorldPlugin.java b/src/iie/HelloWorldPlugin.java index 382729e..13e6cfc 100644 --- a/src/iie/HelloWorldPlugin.java +++ b/src/iie/HelloWorldPlugin.java @@ -18,8 +18,18 @@ public class HelloWorldPlugin extends JavaPlugin { public void onEnable(){ registerCommands(); getServer().getPluginManager().registerEvents(new DeathListener(this), this); - board = Bukkit.getServer().getScoreboardManager().getMainScoreboard(); - hardcoreTimeDead = board.registerNewObjective("hardcoreTimeDead", "dummy"); + + + board = Bukkit.getServer().getScoreboardManager().getMainScoreboard(); + try{ + board.getObjective("hardcoreTimeDead"); + }catch (IllegalArgumentException e){ + hardcoreTimeDead = board.registerNewObjective("hardcoreTimeDead", "dummy"); + }finally{ + hardcoreTimeDead = board.getObjective("hardcoreTimeDead"); + } + + } public void registerCommands(){ getCommand("HelloWorld").setExecutor(new HelloWorld(this)); diff --git a/src/iie/publicstaticvoidmain.java b/src/iie/publicstaticvoidmain.java index 65074d0..8be7eba 100644 --- a/src/iie/publicstaticvoidmain.java +++ b/src/iie/publicstaticvoidmain.java @@ -8,18 +8,8 @@ public class publicstaticvoidmain { public static void main(String[] args){ System.out.println("Hello World!"); - int test = 1234; - String testString = Integer.toString(test); - int test2 = Integer.parseInt(testString); - System.out.println(test2); - - if (test == 1234){ - test = 12345; - } - - test = (int) (System.currentTimeMillis()/1000); - System.out.println(test); - + int test = (int) (System.currentTimeMillis()/1000); + System.out.println(test); long currentTime = System.currentTimeMillis(); int currentTimeInt = (int) (currentTime/1000); @@ -37,7 +27,9 @@ public class publicstaticvoidmain { 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"); + System.out.println("you are dead for the next " + ((86400000 - (currentTime - deathTime))/3600000) + " hours"); + +