testcommit

This commit is contained in:
BuildTools 2016-08-31 18:41:49 -04:00
parent d060bd118a
commit 134b395ac8
5 changed files with 60 additions and 62 deletions

View file

@ -5,7 +5,6 @@ import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class RandomTP{ public class RandomTP{
private int conflictX; private int conflictX;

View file

@ -8,8 +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.PlayerLoginEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.scoreboard.Score;
public class DeathListener implements Listener { public class DeathListener implements Listener {
@ -33,8 +32,18 @@ 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);
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)); HelloWorldPlugin.hardcoreTimeDead.getScore(playerString).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);
//player.sendMessage("Data saved: " + HelloWorldPlugin.deathMap.get(playerString)); //player.sendMessage("Data saved: " + HelloWorldPlugin.deathMap.get(playerString));
@ -43,32 +52,39 @@ public class DeathListener implements Listener {
} }
@EventHandler(priority = EventPriority.MONITOR) @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(); String playerString = (String) player.getName();
Score score = null;
player.sendMessage(playerString + " has joined"); player.sendMessage(playerString + " has joined");
try{ if (HelloWorldPlugin.hardcoreTimeDead.getScore(playerString) != null){
score = HelloWorldPlugin.hardcoreTimeDead.getScore(playerString); HelloWorldPlugin.deathMap.put(playerString, String.valueOf((HelloWorldPlugin.hardcoreTimeDead.getScore(playerString).getScore()) * 1000));
player.sendMessage("hardcoreTimeDead = " + String.valueOf(score.getScore())); player.sendMessage("getScore(playerString) was not null");
}catch(IllegalArgumentException e){ }else{
score.setScore(0); HelloWorldPlugin.hardcoreTimeDead.getScore(playerString).setScore(0);
player.sendMessage("hardcoreTimeDead = " + String.valueOf(score.getScore())); HelloWorldPlugin.deathMap.put(playerString, String.valueOf(HelloWorldPlugin.hardcoreTimeDead.getScore(playerString).getScore()));
} }
if (HelloWorldPlugin.deathMap.get(playerString) == null && score.getScore() != 0){ //try{
HelloWorldPlugin.deathMap.put(playerString, String.valueOf((score.getScore()) * 1000)); // HelloWorldPlugin.hardcoreTimeDead.getScore(playerString);
player.sendMessage(HelloWorldPlugin.deathMap.get(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");
//}
} }

View file

@ -55,6 +55,11 @@ public class HelloWorld implements CommandExecutor {
} }
sender.sendMessage("Your hardcoreTimeDead score is " + String.valueOf(HelloWorldPlugin.hardcoreTimeDead.getScore(playername).getScore()));
}else{ }else{
sender.sendMessage("You must be a player to use this command!"); sender.sendMessage("You must be a player to use this command!");
} }

View file

@ -16,19 +16,27 @@ public class HelloWorldPlugin extends JavaPlugin {
public static 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();
getServer().getPluginManager().registerEvents(new DeathListener(this), this);
try{
board.getObjective("hardcoreTimeDead");
}catch (NullPointerException e){
hardcoreTimeDead = board.registerNewObjective("hardcoreTimeDead", "dummy");
}finally{
hardcoreTimeDead = board.getObjective("hardcoreTimeDead");
}
board = Bukkit.getServer().getScoreboardManager().getMainScoreboard(); board = Bukkit.getServer().getScoreboardManager().getMainScoreboard();
try{ if (board.getObjective("hardcoreTimeDead") != null){
board.getObjective("hardcoreTimeDead");
}catch (IllegalArgumentException e){
hardcoreTimeDead = board.registerNewObjective("hardcoreTimeDead", "dummy");
}finally{
hardcoreTimeDead = board.getObjective("hardcoreTimeDead"); hardcoreTimeDead = board.getObjective("hardcoreTimeDead");
}else{
hardcoreTimeDead = board.registerNewObjective("hardcoreTimeDead", "dummy");
} }
registerCommands();
getServer().getPluginManager().registerEvents(new DeathListener(this), this);
} }
public void registerCommands(){ public void registerCommands(){
@ -36,3 +44,11 @@ public class HelloWorldPlugin extends JavaPlugin {
} }
} }
//try{
// board.getObjective("hardcoreTimeDead");
//}catch (IllegalArgumentException e){
// hardcoreTimeDead = board.registerNewObjective("hardcoreTimeDead", "dummy");
//}finally{
// hardcoreTimeDead = board.getObjective("hardcoreTimeDead");
//}

View file

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