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;
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));
}
}

View file

@ -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");
}

View file

@ -6,13 +6,13 @@ import java.util.HashMap;
import org.bukkit.plugin.java.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(){
registerCommands();
getServer().getPluginManager().registerEvents(new DeathListener(this), this);
}
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();
int currentTimeInt = (int) (currentTime/1000);
System.out.println(currentTime);
System.out.println(currentTimeInt);
System.out.println(Long.parseLong("1472003809703"));