Committing conflicting changes
This commit is contained in:
parent
0dd474ce86
commit
1b166ae455
4 changed files with 73 additions and 27 deletions
|
@ -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.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));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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<String, String> deathMap = new HashMap<String, String>();
|
||||
public static Objective hardcoreInvite;
|
||||
public static AbstractMap<String,String> deathMap = new HashMap<String,String>();
|
||||
|
||||
public void onEnable(){
|
||||
|
||||
public void onEnable() {
|
||||
registerCommands();
|
||||
getServer().getPluginManager().registerEvents(new DeathListener(this), this);
|
||||
board = Bukkit.getServer().getScoreboardManager().getMainScoreboard();
|
||||
if (board.getObjective("hardcoreTimeDead") == null)
|
||||
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");
|
||||
}
|
||||
|
||||
public void registerCommands() {
|
||||
getCommand("HelloWorld").setExecutor(new HelloWorld(this));
|
||||
getCommand("debugRTP").setExecutor(new RandomTP(this));
|
||||
registerCommands();
|
||||
getServer().getPluginManager().registerEvents(new JoinListener(this), this);
|
||||
getServer().getPluginManager().registerEvents(new DeathListener(this), this);
|
||||
|
||||
|
||||
}
|
||||
public void registerCommands(){
|
||||
getCommand("hardcore").setExecutor(new HelloWorld(this));
|
||||
}
|
||||
|
||||
}
|
|
@ -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()));
|
||||
|
|
Loading…
Reference in a new issue