some fixes for DeathListener

to (this) or not to (this)
This commit is contained in:
BuildTools 2016-08-25 18:07:42 -04:00
parent 9073a6b220
commit 786b806dae
4 changed files with 26 additions and 31 deletions

View file

@ -1,11 +1,11 @@
package iie; package iie;
import java.time.Clock; import java.util.Objects;
import java.time.LocalDateTime;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.PlayerDeathEvent;
@ -16,12 +16,11 @@ public class DeathListener implements Listener {
this.plugin = plugin; this.plugin = plugin;
} }
@EventHandler @EventHandler(priority = EventPriority.MONITOR)
public void onHardcoreDeath(PlayerDeathEvent deathEvent){ public void onHardcoreDeath(PlayerDeathEvent deathEvent){
LocalDateTime currentTime = LocalDateTime.now(Clock.systemUTC()); String timeString = String.valueOf(System.currentTimeMillis());
String timeString = currentTime.toString();
Player player = deathEvent.getEntity(); Player player = deathEvent.getEntity();
String playerString = (String) player.getName(); String playerString = (String) player.getName();
Location location = player.getLocation(); Location location = player.getLocation();
@ -31,12 +30,12 @@ public class DeathListener implements Listener {
player.sendMessage(playerString); player.sendMessage(playerString);
player.sendMessage(worldString); player.sendMessage(worldString);
if (worldString == "hardcore"){ if (Objects.equals(worldString, "hardcore")){
plugin.deathMap.put(playerString, timeString); HelloWorldPlugin.deathMap.put(playerString, timeString);
player.sendMessage(plugin.deathMap.toString()); player.sendMessage(HelloWorldPlugin.deathMap.toString());
player.sendMessage("Key saved: " + playerString); player.sendMessage("Key saved: " + playerString);
player.sendMessage("Data saved: " + plugin.deathMap.get(playerString)); player.sendMessage("Data saved: " + HelloWorldPlugin.deathMap.get(playerString));
} }
} }

View file

@ -9,34 +9,27 @@ import org.bukkit.entity.Player;
public class HelloWorld implements CommandExecutor { public class HelloWorld implements CommandExecutor {
HelloWorldPlugin plugin; //HelloWorldPlugin plugin;
public HelloWorld(HelloWorldPlugin plugin){ //public HelloWorld(HelloWorldPlugin plugin){
this.plugin = plugin; // this.plugin = plugin;
} //}
@Override @Override
public boolean onCommand(CommandSender sender, Command label, String command, String[] args) { 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){ if (sender instanceof Player){
//sender.sendMessage("sender IS instanceof Player");
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
String playername = sender.getName(); String playername = sender.getName();
long deathTime = 0; long deathTime = 0;
sender.sendMessage("Playername: " + playername); sender.sendMessage("Playername: " + playername);
sender.sendMessage("Data Imported: " + plugin.deathMap.get(playername)); sender.sendMessage("Data Imported: " + HelloWorldPlugin.deathMap.get(playername));
if (plugin.deathMap.get(playername) != null){ if (HelloWorldPlugin.deathMap.get(playername) != null){
deathTime = Long.parseLong(plugin.deathMap.get(playername)); deathTime = Long.parseLong(HelloWorldPlugin.deathMap.get(playername));
sender.sendMessage("DeathTime: " + deathTime); sender.sendMessage("DeathTime: " + deathTime);
}else{ }else{
sender.sendMessage("you have never died in hardcore"); sender.sendMessage("you have never died in hardcore");
@ -46,9 +39,7 @@ public class HelloWorld implements CommandExecutor {
player.teleport(location); player.teleport(location);
} }
//sender.sendMessage(playername);
//sender.sendMessage(String.valueOf(deathTime));
//sender.sendMessage(String.valueOf(currentTime));
if (currentTime - deathTime >= 86400000 && deathTime != 0){ if (currentTime - deathTime >= 86400000 && deathTime != 0){
sender.sendMessage((86400000 - (currentTime - deathTime) ) /3600000 + " hours have passed since you died in hardcore last"); sender.sendMessage((86400000 - (currentTime - deathTime) ) /3600000 + " hours have passed since you died in hardcore last");
@ -56,6 +47,8 @@ public class HelloWorld implements CommandExecutor {
World hardcoreWorld = player.getServer().getWorld("hardcore"); World hardcoreWorld = player.getServer().getWorld("hardcore");
Location location = new Location(hardcoreWorld, 1280, 71, -179); Location location = new Location(hardcoreWorld, 1280, 71, -179);
player.teleport(location); player.teleport(location);
}else if(deathTime == 0){
sender.sendMessage("good luck");
}else{ }else{
sender.sendMessage("you are dead for the next " + (86400000 - (currentTime - deathTime) ) /3600000 + " hours"); sender.sendMessage("you are dead for the next " + (86400000 - (currentTime - deathTime) ) /3600000 + " hours");
} }

View file

@ -6,13 +6,13 @@ import java.util.HashMap;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
public class HelloWorldPlugin extends JavaPlugin { public class HelloWorldPlugin extends JavaPlugin {
public AbstractMap<String,String> deathMap = new HashMap<String,String>(); public static AbstractMap<String,String> deathMap = new HashMap<String,String>();
public void onEnable(){ public void onEnable(){
registerCommands(); registerCommands();
getServer().getPluginManager().registerEvents(new DeathListener(this), this); getServer().getPluginManager().registerEvents(new DeathListener(this), this);
} }
public void registerCommands(){ public void registerCommands(){
getCommand("HelloWorld").setExecutor(new HelloWorld(this)); getCommand("HelloWorld").setExecutor(new HelloWorld(/*this*/));
} }
} }

View file

@ -21,8 +21,11 @@ public class publicstaticvoidmain {
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
int currentTimeInt = (int) (currentTime/1000);
System.out.println(currentTime); System.out.println(currentTime);
System.out.println(currentTimeInt);
System.out.println(Long.parseLong("1472003809703")); System.out.println(Long.parseLong("1472003809703"));