More fixes
This commit is contained in:
parent
a566c95087
commit
5eed40ddb6
3 changed files with 27 additions and 21 deletions
|
@ -8,7 +8,7 @@ import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
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;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerLoginEvent;
|
||||||
import org.bukkit.scoreboard.Score;
|
import org.bukkit.scoreboard.Score;
|
||||||
|
|
||||||
public class DeathListener implements Listener {
|
public class DeathListener implements Listener {
|
||||||
|
@ -33,8 +33,7 @@ public class DeathListener implements Listener {
|
||||||
|
|
||||||
if (Objects.equals(worldString, "hardcore")){
|
if (Objects.equals(worldString, "hardcore")){
|
||||||
HelloWorldPlugin.deathMap.put(playerString, timeString);
|
HelloWorldPlugin.deathMap.put(playerString, timeString);
|
||||||
Score score = HelloWorldPlugin.hardcoreTimeDead.getScore(playerString);
|
HelloWorldPlugin.hardcoreTimeDead.getScore(playerString).setScore((int) (System.currentTimeMillis()/1000));
|
||||||
score.setScore((int) (System.currentTimeMillis()/1000));
|
|
||||||
|
|
||||||
//player.sendMessage(HelloWorldPlugin.deathMap.toString());
|
//player.sendMessage(HelloWorldPlugin.deathMap.toString());
|
||||||
//player.sendMessage("Key saved: " + playerString);
|
//player.sendMessage("Key saved: " + playerString);
|
||||||
|
@ -44,26 +43,31 @@ public class DeathListener implements Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@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();
|
String playerString = (String) player.getName();
|
||||||
Score score = null;
|
Score score = null;
|
||||||
|
|
||||||
|
player.sendMessage(playerString + " has joined");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
score = HelloWorldPlugin.hardcoreTimeDead.getScore(playerString);
|
score = HelloWorldPlugin.hardcoreTimeDead.getScore(playerString);
|
||||||
}catch(IllegalArgumentException throwable){
|
player.sendMessage("hardcoreTimeDead = " + String.valueOf(score.getScore()));
|
||||||
|
}catch(IllegalArgumentException e){
|
||||||
score.setScore(0);
|
score.setScore(0);
|
||||||
|
player.sendMessage("hardcoreTimeDead = " + String.valueOf(score.getScore()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (HelloWorldPlugin.deathMap.get(playerString) == null && score.getScore() != 0){
|
if (HelloWorldPlugin.deathMap.get(playerString) == null && score.getScore() != 0){
|
||||||
HelloWorldPlugin.deathMap.put(playerString, String.valueOf((score.getScore()) * 1000));
|
HelloWorldPlugin.deathMap.put(playerString, String.valueOf((score.getScore()) * 1000));
|
||||||
|
player.sendMessage(HelloWorldPlugin.deathMap.get(playerString));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,18 @@ public class HelloWorldPlugin extends JavaPlugin {
|
||||||
public void onEnable(){
|
public void onEnable(){
|
||||||
registerCommands();
|
registerCommands();
|
||||||
getServer().getPluginManager().registerEvents(new DeathListener(this), this);
|
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(){
|
public void registerCommands(){
|
||||||
getCommand("HelloWorld").setExecutor(new HelloWorld(this));
|
getCommand("HelloWorld").setExecutor(new HelloWorld(this));
|
||||||
|
|
|
@ -8,18 +8,8 @@ public class publicstaticvoidmain {
|
||||||
public static void main(String[] args){
|
public static void main(String[] args){
|
||||||
System.out.println("Hello World!");
|
System.out.println("Hello World!");
|
||||||
|
|
||||||
int test = 1234;
|
int test = (int) (System.currentTimeMillis()/1000);
|
||||||
String testString = Integer.toString(test);
|
System.out.println(test);
|
||||||
int test2 = Integer.parseInt(testString);
|
|
||||||
System.out.println(test2);
|
|
||||||
|
|
||||||
if (test == 1234){
|
|
||||||
test = 12345;
|
|
||||||
}
|
|
||||||
|
|
||||||
test = (int) (System.currentTimeMillis()/1000);
|
|
||||||
System.out.println(test);
|
|
||||||
|
|
||||||
|
|
||||||
long currentTime = System.currentTimeMillis();
|
long currentTime = System.currentTimeMillis();
|
||||||
int currentTimeInt = (int) (currentTime/1000);
|
int currentTimeInt = (int) (currentTime/1000);
|
||||||
|
@ -37,7 +27,9 @@ public class publicstaticvoidmain {
|
||||||
System.out.println(deathTime + " is a number");
|
System.out.println(deathTime + " is a number");
|
||||||
|
|
||||||
System.out.println(deathMap.get("other"));
|
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");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue