From 1b166ae455e62e8358d2032cb2dc24ca86b60ce8 Mon Sep 17 00:00:00 2001 From: iie Date: Mon, 12 Sep 2016 06:05:00 +0200 Subject: [PATCH] Committing conflicting changes --- src/iie/DeathListener.java | 15 +++++++++---- src/iie/HelloWorld.java | 21 +++++++++++++----- src/iie/HelloWorldPlugin.java | 41 ++++++++++++++++++++++------------- src/iie/JoinListener.java | 23 ++++++++++++++++++-- 4 files changed, 73 insertions(+), 27 deletions(-) diff --git a/src/iie/DeathListener.java b/src/iie/DeathListener.java index 34a943f..ea67603 100644 --- a/src/iie/DeathListener.java +++ b/src/iie/DeathListener.java @@ -25,12 +25,19 @@ public class DeathListener implements Listener { Location location = player.getLocation(); String worldString = (String) location.getWorld().getName(); + //player.sendMessage("you died"); + //player.sendMessage("currentTime = " + String.valueOf(currentTime)); + //player.sendMessage("worldString = " + String.valueOf(worldString)); + if (Objects.equals(worldString, "hardcore")){ - - if (HelloWorldPlugin.hardcoreTimeDead.getScore(playername) == null) //null check - HelloWorldPlugin.hardcoreTimeDead.getScore(playername).setScore(0); //convert null to 0 - HelloWorldPlugin.hardcoreTimeDead.getScore(playername).setScore(currentTime); + HelloWorldPlugin.hardcoreTimeDead.getScore(playername).setScore(currentTime); + HelloWorldPlugin.hardcoreInvite.getScore(playername).setScore(0); + + //player.sendMessage("death detected"); + //player.sendMessage("hardcoreTimeDead score = " + String.valueOf(HelloWorldPlugin.hardcoreTimeDead.getScore(playername).getScore())); + //player.sendMessage("currentTime = " + String.valueOf(currentTime)); + } } } diff --git a/src/iie/HelloWorld.java b/src/iie/HelloWorld.java index be0e354..9e331cb 100644 --- a/src/iie/HelloWorld.java +++ b/src/iie/HelloWorld.java @@ -1,6 +1,10 @@ package iie; +import java.util.Objects; + +import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.Sound; import org.bukkit.World; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -26,6 +30,11 @@ public class HelloWorld implements CommandExecutor { Player player = (Player) sender; String playername = sender.getName(); + if (!Objects.equals(player.getScoreboard(), Bukkit.getScoreboardManager().getMainScoreboard())){ + player.sendMessage("not in your current circumstances"); + return false; + } + World hardcoreWorld = player.getServer().getWorld("hardcore"); Location location = new Location(hardcoreWorld, 1280, 71, -179); @@ -39,16 +48,16 @@ public class HelloWorld implements CommandExecutor { if (currentTime - deathTime >= 86400 && deathTime != 0){ - sender.sendMessage("You died " + (86400 - (currentTime - deathTime)) /3600 + " hours ago. Ready to give it another shot?"); + sender.sendMessage("You died " + ((currentTime - deathTime) /3600) + " hours ago. Good luck, " + playername + "."); player.teleport(location); - // player.getWorld().playSound(player.getLocation(), Sound.AMBIENT_CAVE,0,0); I don't think this works, fix later + player.getWorld().playSound(player.getLocation(), Sound.AMBIENT_CAVE,1F,1F); }else if(deathTime == 0){ - sender.sendMessage("You have never died in hardcore. Good luck!"); + sender.sendMessage("You have never died, good luck"); player.teleport(location); - // player.getWorld().playSound(player.getLocation(), Sound.AMBIENT_CAVE,0,0); I don't think this works, fix later + player.getWorld().playSound(player.getLocation(), Sound.AMBIENT_CAVE,1F,1F); }else{ - sender.sendMessage("you are dead for the next " + (86400 - (currentTime - deathTime) ) /3600 + " hours"); - // player.getWorld().playSound(player.getLocation(), Sound.AMBIENT_CAVE,0,0); I don't think this works, fix later + sender.sendMessage("you are dead for the next " + ((86400 - (currentTime - deathTime)) /3600) + " hours"); + player.getWorld().playSound(player.getLocation(), Sound.AMBIENT_CAVE,1F,1F); // replace sound with some other sound } diff --git a/src/iie/HelloWorldPlugin.java b/src/iie/HelloWorldPlugin.java index ed1e3b7..a3a1995 100644 --- a/src/iie/HelloWorldPlugin.java +++ b/src/iie/HelloWorldPlugin.java @@ -8,25 +8,36 @@ import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Scoreboard; -import alisolarflare.RandomTP; public class HelloWorldPlugin extends JavaPlugin { - + public static Scoreboard board; public static Objective hardcoreTimeDead; - public static AbstractMap deathMap = new HashMap(); - - public void onEnable() { - registerCommands(); - getServer().getPluginManager().registerEvents(new DeathListener(this), this); - board = Bukkit.getServer().getScoreboardManager().getMainScoreboard(); - if (board.getObjective("hardcoreTimeDead") == null) + public static Objective hardcoreInvite; + public static AbstractMap deathMap = new HashMap(); + + public void onEnable(){ + + board = Bukkit.getServer().getScoreboardManager().getMainScoreboard(); + if (board.getObjective("hardcoreTimeDead") != null){ //null check hardcoreTimeDead + hardcoreTimeDead = board.getObjective("hardcoreTimeDead"); + }else{ hardcoreTimeDead = board.registerNewObjective("hardcoreTimeDead", "dummy"); + } + if (board.getObjective("hardcoreInvite") != null){ //null check hardcoreInvite + hardcoreInvite = board.getObjective("hardcoreInvite"); + }else{ + hardcoreInvite = board.registerNewObjective("hardcoreInvite", "dummy"); + } + + registerCommands(); + getServer().getPluginManager().registerEvents(new JoinListener(this), this); + getServer().getPluginManager().registerEvents(new DeathListener(this), this); + + + } + public void registerCommands(){ + getCommand("hardcore").setExecutor(new HelloWorld(this)); } - public void registerCommands() { - getCommand("HelloWorld").setExecutor(new HelloWorld(this)); - getCommand("debugRTP").setExecutor(new RandomTP(this)); - } - -} +} \ No newline at end of file diff --git a/src/iie/JoinListener.java b/src/iie/JoinListener.java index 86512b1..5bf6b1b 100644 --- a/src/iie/JoinListener.java +++ b/src/iie/JoinListener.java @@ -21,8 +21,27 @@ public class JoinListener implements Listener { String playername = (String) player.getName(); - if (HelloWorldPlugin.hardcoreTimeDead.getScore(playername) == null) //null check - HelloWorldPlugin.hardcoreTimeDead.getScore(playername).setScore(0); //convert null to 0 + if (HelloWorldPlugin.hardcoreInvite.getScore(playername) == null){ //null check + HelloWorldPlugin.hardcoreInvite.getScore(playername).setScore(0); //convert null to 0 + } + if (HelloWorldPlugin.hardcoreTimeDead.getScore(playername) == null){ //null check + HelloWorldPlugin.hardcoreTimeDead.getScore(playername).setScore(0); //convert null to 0 + } + + int invite = HelloWorldPlugin.hardcoreInvite.getScore(playername).getScore(); + int deathTime = HelloWorldPlugin.hardcoreTimeDead.getScore(playername).getScore(); + int currentTime = (int) ((System.currentTimeMillis())/1000); + + + if (currentTime - deathTime >= 86400 && deathTime != 0 && invite == 0){ + player.sendMessage(playername + ", your death has lifted in Hardcore world. (You died " + String.valueOf((currentTime - deathTime) /3600) + " hours ago)"); + player.sendMessage("Are you ready to give life another shot?"); + HelloWorldPlugin.hardcoreInvite.getScore(playername).setScore(1); + }else if (currentTime - deathTime <= 86400){ + player.sendMessage(String.valueOf((86400 - (currentTime - deathTime)) /3600) + " hours of death remaining in hardcore"); + }else if (deathTime == 0){ + return; + } //HelloWorldPlugin.deathMap.put(playername, String.valueOf(HelloWorldPlugin.hardcoreTimeDead.getScore(playername).getScore()));