From 786b806dae5bfa8421e2526a91fe0fd635a94cf5 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Thu, 25 Aug 2016 18:07:42 -0400 Subject: [PATCH] some fixes for DeathListener to (this) or not to (this) --- src/iie/DeathListener.java | 17 ++++++++-------- src/iie/HelloWorld.java | 33 ++++++++++++------------------- src/iie/HelloWorldPlugin.java | 4 ++-- src/iie/publicstaticvoidmain.java | 3 +++ 4 files changed, 26 insertions(+), 31 deletions(-) diff --git a/src/iie/DeathListener.java b/src/iie/DeathListener.java index 67f8611..4b605af 100644 --- a/src/iie/DeathListener.java +++ b/src/iie/DeathListener.java @@ -1,11 +1,11 @@ package iie; -import java.time.Clock; -import java.time.LocalDateTime; +import java.util.Objects; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.PlayerDeathEvent; @@ -16,12 +16,11 @@ public class DeathListener implements Listener { this.plugin = plugin; } - @EventHandler + @EventHandler(priority = EventPriority.MONITOR) public void onHardcoreDeath(PlayerDeathEvent deathEvent){ - LocalDateTime currentTime = LocalDateTime.now(Clock.systemUTC()); - String timeString = currentTime.toString(); + String timeString = String.valueOf(System.currentTimeMillis()); Player player = deathEvent.getEntity(); String playerString = (String) player.getName(); Location location = player.getLocation(); @@ -31,12 +30,12 @@ public class DeathListener implements Listener { player.sendMessage(playerString); player.sendMessage(worldString); - if (worldString == "hardcore"){ - plugin.deathMap.put(playerString, timeString); - player.sendMessage(plugin.deathMap.toString()); + if (Objects.equals(worldString, "hardcore")){ + HelloWorldPlugin.deathMap.put(playerString, timeString); + player.sendMessage(HelloWorldPlugin.deathMap.toString()); player.sendMessage("Key saved: " + playerString); - player.sendMessage("Data saved: " + plugin.deathMap.get(playerString)); + player.sendMessage("Data saved: " + HelloWorldPlugin.deathMap.get(playerString)); } } diff --git a/src/iie/HelloWorld.java b/src/iie/HelloWorld.java index f57cfec..c092825 100644 --- a/src/iie/HelloWorld.java +++ b/src/iie/HelloWorld.java @@ -9,34 +9,27 @@ import org.bukkit.entity.Player; public class HelloWorld implements CommandExecutor { - HelloWorldPlugin plugin; - public HelloWorld(HelloWorldPlugin plugin){ - this.plugin = plugin; - } + //HelloWorldPlugin plugin; + //public HelloWorld(HelloWorldPlugin plugin){ + // this.plugin = plugin; + //} @Override public boolean onCommand(CommandSender sender, Command label, String command, String[] args) { - // TODO Auto-generated method stub - - - - - //sender.sendMessage("WELL, AT LEAST THIS WORKS"); if (sender instanceof Player){ - //sender.sendMessage("sender IS instanceof Player"); + long currentTime = System.currentTimeMillis(); String playername = sender.getName(); long deathTime = 0; - sender.sendMessage("Playername: " + playername); - sender.sendMessage("Data Imported: " + plugin.deathMap.get(playername)); - - if (plugin.deathMap.get(playername) != null){ - deathTime = Long.parseLong(plugin.deathMap.get(playername)); + sender.sendMessage("Data Imported: " + HelloWorldPlugin.deathMap.get(playername)); + + if (HelloWorldPlugin.deathMap.get(playername) != null){ + deathTime = Long.parseLong(HelloWorldPlugin.deathMap.get(playername)); sender.sendMessage("DeathTime: " + deathTime); }else{ sender.sendMessage("you have never died in hardcore"); @@ -46,17 +39,17 @@ public class HelloWorld implements CommandExecutor { player.teleport(location); } - //sender.sendMessage(playername); - //sender.sendMessage(String.valueOf(deathTime)); - //sender.sendMessage(String.valueOf(currentTime)); + if (currentTime - deathTime >= 86400000 && deathTime != 0){ sender.sendMessage((86400000 - (currentTime - deathTime) ) /3600000 + " hours have passed since you died in hardcore last"); Player player = (Player) sender; World hardcoreWorld = player.getServer().getWorld("hardcore"); Location location = new Location(hardcoreWorld, 1280, 71, -179); player.teleport(location); - }else{ + }else if(deathTime == 0){ + sender.sendMessage("good luck"); + }else{ sender.sendMessage("you are dead for the next " + (86400000 - (currentTime - deathTime) ) /3600000 + " hours"); } diff --git a/src/iie/HelloWorldPlugin.java b/src/iie/HelloWorldPlugin.java index f96ed78..17e779c 100644 --- a/src/iie/HelloWorldPlugin.java +++ b/src/iie/HelloWorldPlugin.java @@ -6,13 +6,13 @@ import java.util.HashMap; import org.bukkit.plugin.java.JavaPlugin; public class HelloWorldPlugin extends JavaPlugin { - public AbstractMap deathMap = new HashMap(); + public static AbstractMap deathMap = new HashMap(); public void onEnable(){ registerCommands(); getServer().getPluginManager().registerEvents(new DeathListener(this), this); } public void registerCommands(){ - getCommand("HelloWorld").setExecutor(new HelloWorld(this)); + getCommand("HelloWorld").setExecutor(new HelloWorld(/*this*/)); } } diff --git a/src/iie/publicstaticvoidmain.java b/src/iie/publicstaticvoidmain.java index 5c4a587..aa38426 100644 --- a/src/iie/publicstaticvoidmain.java +++ b/src/iie/publicstaticvoidmain.java @@ -21,8 +21,11 @@ public class publicstaticvoidmain { long currentTime = System.currentTimeMillis(); + int currentTimeInt = (int) (currentTime/1000); System.out.println(currentTime); + System.out.println(currentTimeInt); + System.out.println(Long.parseLong("1472003809703"));