changed command to "hardcore"
removed debug messages, removed usage of hashmap to rely entirely on scoreboard,
This commit is contained in:
parent
134b395ac8
commit
7c82d7879a
5 changed files with 66 additions and 112 deletions
|
@ -2,5 +2,5 @@
|
|||
version: 1.0.0
|
||||
name: HelloWorldPlugin
|
||||
commands:
|
||||
HelloWorld:
|
||||
description: Command that says Hello World!
|
||||
hardcore:
|
||||
description: Command that teleports you to hardcore world
|
|
@ -8,7 +8,6 @@ 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.PlayerJoinEvent;
|
||||
|
||||
public class DeathListener implements Listener {
|
||||
|
||||
|
@ -20,72 +19,18 @@ public class DeathListener implements Listener {
|
|||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onHardcoreDeath(PlayerDeathEvent deathEvent){
|
||||
|
||||
String timeString = String.valueOf(System.currentTimeMillis());
|
||||
int currentTime = (int) ((System.currentTimeMillis())/1000); //divided by 1000 to fit within Integer range
|
||||
Player player = deathEvent.getEntity();
|
||||
String playerString = (String) player.getName();
|
||||
String playername = (String) player.getName();
|
||||
Location location = player.getLocation();
|
||||
String worldString = (String) location.getWorld().getName();
|
||||
|
||||
//player.sendMessage(timeString);
|
||||
//player.sendMessage(playerString);
|
||||
//player.sendMessage(worldString);
|
||||
|
||||
if (Objects.equals(worldString, "hardcore")){
|
||||
HelloWorldPlugin.deathMap.put(playerString, timeString);
|
||||
|
||||
if (HelloWorldPlugin.hardcoreTimeDead.getScore(playername) == null) //null check
|
||||
HelloWorldPlugin.hardcoreTimeDead.getScore(playername).setScore(0); //convert null to 0
|
||||
|
||||
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));
|
||||
HelloWorldPlugin.hardcoreTimeDead.getScore(playername).setScore(currentTime);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerJoin(PlayerJoinEvent JoinEvent){
|
||||
|
||||
|
||||
|
||||
Player player = JoinEvent.getPlayer();
|
||||
String playerString = (String) player.getName();
|
||||
|
||||
player.sendMessage(playerString + " has joined");
|
||||
|
||||
|
||||
|
||||
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");
|
||||
//}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package iie;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
|
@ -23,52 +24,43 @@ public class HelloWorld implements CommandExecutor {
|
|||
|
||||
if (sender instanceof Player){
|
||||
|
||||
long currentTime = System.currentTimeMillis();
|
||||
Player player = (Player) sender;
|
||||
String playername = sender.getName();
|
||||
long deathTime = 0;
|
||||
//sender.sendMessage("Playername: " + playername);
|
||||
//sender.sendMessage("Data Imported: " + HelloWorldPlugin.deathMap.get(playername));
|
||||
|
||||
if (HelloWorldPlugin.deathMap.get(playername) != null){
|
||||
deathTime = Long.parseLong(HelloWorldPlugin.deathMap.get(playername));
|
||||
//sender.sendMessage("DeathTime: " + deathTime);
|
||||
}else{
|
||||
sender.sendMessage("You have never died in hardcore");
|
||||
Player player = (Player) sender;
|
||||
World hardcoreWorld = player.getServer().getWorld("hardcore");
|
||||
Location location = new Location(hardcoreWorld, 1280, 71, -179);
|
||||
player.teleport(location);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (currentTime - deathTime >= 86400000 && deathTime != 0){
|
||||
sender.sendMessage("You died " + (86400000 - (currentTime - deathTime) ) /3600000 + " hours ago. Ready to give it another shot?");
|
||||
Player player = (Player) sender;
|
||||
World hardcoreWorld = player.getServer().getWorld("hardcore");
|
||||
Location location = new Location(hardcoreWorld, 1280, 71, -179);
|
||||
World hardcoreWorld = player.getServer().getWorld("hardcore");
|
||||
Location location = new Location(hardcoreWorld, 1280, 71, -179);
|
||||
|
||||
int currentTime = (int) ((System.currentTimeMillis())/1000);
|
||||
int deathTime = 0;
|
||||
|
||||
if (HelloWorldPlugin.hardcoreTimeDead.getScore(playername) != null) //null check - if score exists
|
||||
deathTime = HelloWorldPlugin.hardcoreTimeDead.getScore(playername).getScore(); //set deathTime to that score
|
||||
|
||||
|
||||
|
||||
|
||||
if (currentTime - deathTime >= 86400 && deathTime != 0){
|
||||
sender.sendMessage("You died " + (86400 - (currentTime - deathTime)) /3600 + " hours ago. Ready to give it another shot?");
|
||||
player.teleport(location);
|
||||
// player.getWorld().playSound(player.getLocation(), Sound.AMBIENT_CAVE,0,0); I don't think this works, fix later
|
||||
}else if(deathTime == 0){
|
||||
sender.sendMessage("good luck");
|
||||
sender.sendMessage("You have never died in hardcore. Good luck!");
|
||||
player.teleport(location);
|
||||
// player.getWorld().playSound(player.getLocation(), Sound.AMBIENT_CAVE,0,0); I don't think this works, fix later
|
||||
}else{
|
||||
sender.sendMessage("you are dead for the next " + (86400000 - (currentTime - deathTime) ) /3600000 + " hours");
|
||||
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
|
||||
// replace sound with some other sound
|
||||
}
|
||||
|
||||
|
||||
|
||||
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!");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,37 +18,21 @@ public class HelloWorldPlugin extends JavaPlugin {
|
|||
public void onEnable(){
|
||||
|
||||
|
||||
try{
|
||||
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 JoinListener(this), this);
|
||||
getServer().getPluginManager().registerEvents(new DeathListener(this), this);
|
||||
|
||||
|
||||
}
|
||||
public void registerCommands(){
|
||||
getCommand("HelloWorld").setExecutor(new HelloWorld(this));
|
||||
getCommand("hardcore").setExecutor(new HelloWorld(this));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//try{
|
||||
// board.getObjective("hardcoreTimeDead");
|
||||
//}catch (IllegalArgumentException e){
|
||||
// hardcoreTimeDead = board.registerNewObjective("hardcoreTimeDead", "dummy");
|
||||
//}finally{
|
||||
// hardcoreTimeDead = board.getObjective("hardcoreTimeDead");
|
||||
//}
|
33
src/iie/JoinListener.java
Normal file
33
src/iie/JoinListener.java
Normal file
|
@ -0,0 +1,33 @@
|
|||
package iie;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class JoinListener implements Listener {
|
||||
|
||||
HelloWorldPlugin plugin;
|
||||
public JoinListener(HelloWorldPlugin plugin){
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerJoin(PlayerJoinEvent JoinEvent){
|
||||
|
||||
|
||||
Player player = JoinEvent.getPlayer();
|
||||
String playername = (String) player.getName();
|
||||
|
||||
|
||||
if (HelloWorldPlugin.hardcoreTimeDead.getScore(playername) == null) //null check
|
||||
HelloWorldPlugin.hardcoreTimeDead.getScore(playername).setScore(0); //convert null to 0
|
||||
|
||||
|
||||
//HelloWorldPlugin.deathMap.put(playername, String.valueOf(HelloWorldPlugin.hardcoreTimeDead.getScore(playername).getScore()));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue