testcommit
This commit is contained in:
parent
172c1224f8
commit
20861eb67b
5 changed files with 60 additions and 62 deletions
|
@ -5,7 +5,6 @@ import org.bukkit.Material;
|
|||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
public class RandomTP{
|
||||
|
||||
private int conflictX;
|
||||
|
|
|
@ -8,8 +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.PlayerLoginEvent;
|
||||
import org.bukkit.scoreboard.Score;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class DeathListener implements Listener {
|
||||
|
||||
|
@ -33,8 +32,18 @@ public class DeathListener implements Listener {
|
|||
|
||||
if (Objects.equals(worldString, "hardcore")){
|
||||
HelloWorldPlugin.deathMap.put(playerString, timeString);
|
||||
|
||||
|
||||
if (HelloWorldPlugin.hardcoreTimeDead == null){
|
||||
player.sendMessage("Objective hardcoreTimeDead was null");
|
||||
}else if (HelloWorldPlugin.hardcoreTimeDead.getScore(playerString) == null){
|
||||
HelloWorldPlugin.hardcoreTimeDead.getScore(playerString).setScore(0);
|
||||
player.sendMessage("Score for hardcoreTimeDead was null, set to " + String.valueOf(HelloWorldPlugin.hardcoreTimeDead.getScore(playerString).getScore()));
|
||||
}
|
||||
|
||||
HelloWorldPlugin.hardcoreTimeDead.getScore(playerString).setScore((int) (System.currentTimeMillis()/1000));
|
||||
|
||||
|
||||
//player.sendMessage(HelloWorldPlugin.deathMap.toString());
|
||||
//player.sendMessage("Key saved: " + playerString);
|
||||
//player.sendMessage("Data saved: " + HelloWorldPlugin.deathMap.get(playerString));
|
||||
|
@ -43,32 +52,39 @@ public class DeathListener implements Listener {
|
|||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerLogin(PlayerLoginEvent loginEvent){
|
||||
public void onPlayerJoin(PlayerJoinEvent JoinEvent){
|
||||
|
||||
|
||||
|
||||
Player player = loginEvent.getPlayer();
|
||||
Player player = JoinEvent.getPlayer();
|
||||
String playerString = (String) player.getName();
|
||||
Score score = null;
|
||||
|
||||
player.sendMessage(playerString + " has joined");
|
||||
|
||||
|
||||
|
||||
try{
|
||||
score = HelloWorldPlugin.hardcoreTimeDead.getScore(playerString);
|
||||
player.sendMessage("hardcoreTimeDead = " + String.valueOf(score.getScore()));
|
||||
}catch(IllegalArgumentException e){
|
||||
score.setScore(0);
|
||||
player.sendMessage("hardcoreTimeDead = " + String.valueOf(score.getScore()));
|
||||
if (HelloWorldPlugin.hardcoreTimeDead.getScore(playerString) != null){
|
||||
HelloWorldPlugin.deathMap.put(playerString, String.valueOf((HelloWorldPlugin.hardcoreTimeDead.getScore(playerString).getScore()) * 1000));
|
||||
player.sendMessage("getScore(playerString) was not null");
|
||||
}else{
|
||||
HelloWorldPlugin.hardcoreTimeDead.getScore(playerString).setScore(0);
|
||||
HelloWorldPlugin.deathMap.put(playerString, String.valueOf(HelloWorldPlugin.hardcoreTimeDead.getScore(playerString).getScore()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
//try{
|
||||
// HelloWorldPlugin.hardcoreTimeDead.getScore(playerString);
|
||||
// player.sendMessage("try");
|
||||
//}catch(IllegalArgumentException e){
|
||||
// HelloWorldPlugin.hardcoreTimeDead.getScore(playerString).setScore(1);
|
||||
// player.sendMessage("catch");
|
||||
//}finally{
|
||||
// HelloWorldPlugin.deathMap.put(playerString, String.valueOf((HelloWorldPlugin.hardcoreTimeDead.getScore(playerString).getScore()) * 1000));
|
||||
// player.sendMessage("finally");
|
||||
//}
|
||||
|
||||
|
||||
if (HelloWorldPlugin.deathMap.get(playerString) == null && score.getScore() != 0){
|
||||
HelloWorldPlugin.deathMap.put(playerString, String.valueOf((score.getScore()) * 1000));
|
||||
player.sendMessage(HelloWorldPlugin.deathMap.get(playerString));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,12 @@ public class HelloWorld implements CommandExecutor {
|
|||
sender.sendMessage("you are dead for the next " + (86400000 - (currentTime - deathTime) ) /3600000 + " hours");
|
||||
}
|
||||
|
||||
|
||||
|
||||
sender.sendMessage("Your hardcoreTimeDead score is " + String.valueOf(HelloWorldPlugin.hardcoreTimeDead.getScore(playername).getScore()));
|
||||
|
||||
|
||||
|
||||
}else{
|
||||
sender.sendMessage("You must be a player to use this command!");
|
||||
}
|
||||
|
|
|
@ -16,23 +16,39 @@ public class HelloWorldPlugin extends JavaPlugin {
|
|||
public static AbstractMap<String,String> deathMap = new HashMap<String,String>();
|
||||
|
||||
public void onEnable(){
|
||||
registerCommands();
|
||||
getServer().getPluginManager().registerEvents(new DeathListener(this), this);
|
||||
|
||||
|
||||
board = Bukkit.getServer().getScoreboardManager().getMainScoreboard();
|
||||
try{
|
||||
board.getObjective("hardcoreTimeDead");
|
||||
}catch (IllegalArgumentException e){
|
||||
hardcoreTimeDead = board.registerNewObjective("hardcoreTimeDead", "dummy");
|
||||
}finally{
|
||||
hardcoreTimeDead = board.getObjective("hardcoreTimeDead");
|
||||
}
|
||||
}catch (NullPointerException e){
|
||||
hardcoreTimeDead = board.registerNewObjective("hardcoreTimeDead", "dummy");
|
||||
}finally{
|
||||
hardcoreTimeDead = board.getObjective("hardcoreTimeDead");
|
||||
}
|
||||
|
||||
|
||||
board = Bukkit.getServer().getScoreboardManager().getMainScoreboard();
|
||||
if (board.getObjective("hardcoreTimeDead") != null){
|
||||
hardcoreTimeDead = board.getObjective("hardcoreTimeDead");
|
||||
}else{
|
||||
hardcoreTimeDead = board.registerNewObjective("hardcoreTimeDead", "dummy");
|
||||
|
||||
}
|
||||
|
||||
registerCommands();
|
||||
getServer().getPluginManager().registerEvents(new DeathListener(this), this);
|
||||
|
||||
}
|
||||
public void registerCommands(){
|
||||
getCommand("HelloWorld").setExecutor(new HelloWorld(this));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//try{
|
||||
// board.getObjective("hardcoreTimeDead");
|
||||
//}catch (IllegalArgumentException e){
|
||||
// hardcoreTimeDead = board.registerNewObjective("hardcoreTimeDead", "dummy");
|
||||
//}finally{
|
||||
// hardcoreTimeDead = board.getObjective("hardcoreTimeDead");
|
||||
//}
|
|
@ -1,38 +0,0 @@
|
|||
package iie;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class publicstaticvoidmain {
|
||||
|
||||
public static void main(String[] args){
|
||||
System.out.println("Hello World!");
|
||||
|
||||
int test = (int) (System.currentTimeMillis()/1000);
|
||||
System.out.println(test);
|
||||
|
||||
long currentTime = System.currentTimeMillis();
|
||||
int currentTimeInt = (int) (currentTime/1000);
|
||||
|
||||
System.out.println(currentTime + " current time");
|
||||
System.out.println(currentTimeInt);
|
||||
|
||||
|
||||
System.out.println(Long.parseLong("1472003809703"));
|
||||
|
||||
AbstractMap<String,String> deathMap = new HashMap<String,String>();
|
||||
deathMap.put("test", "1472003809703");
|
||||
long deathTime = Long.parseLong(deathMap.get("test"));
|
||||
System.out.println(deathMap.get("test"));
|
||||
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");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue