From f1034a986f6f230be295bf1b38c0a8224fa442e5 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 12 Sep 2016 00:05:07 -0400 Subject: [PATCH] Cloning things in --- .DS_Store | Bin 0 -> 6148 bytes README.md | 2 +- bin/.DS_Store | Bin 0 -> 6148 bytes config.yml | 0 plugin.yml | 10 + src/.DS_Store | Bin 0 -> 6148 bytes src/alisolarflare/RandomTP.java | 183 ++++++++++++++++++ src/alisolarflare/listeners/CompassLobby.java | 26 +++ .../ConflictCompassCraftingListener.java | 74 +++++++ .../listeners/DiamondArmorBlocker.java | 51 +++++ src/iie/DeathListener.java | 43 ++++ src/iie/HelloWorld.java | 75 +++++++ src/iie/HelloWorldPlugin.java | 43 ++++ src/iie/JoinListener.java | 52 +++++ 14 files changed, 558 insertions(+), 1 deletion(-) create mode 100644 .DS_Store create mode 100644 bin/.DS_Store create mode 100644 config.yml create mode 100644 plugin.yml create mode 100644 src/.DS_Store create mode 100644 src/alisolarflare/RandomTP.java create mode 100644 src/alisolarflare/listeners/CompassLobby.java create mode 100644 src/alisolarflare/listeners/ConflictCompassCraftingListener.java create mode 100644 src/alisolarflare/listeners/DiamondArmorBlocker.java create mode 100644 src/iie/DeathListener.java create mode 100644 src/iie/HelloWorld.java create mode 100644 src/iie/HelloWorldPlugin.java create mode 100644 src/iie/JoinListener.java diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..62bc7eb2a52d0a16e12cfb72c70fcece6246dfc7 GIT binary patch literal 6148 zcmeHKu}%Xq47Irql~_75W@hWe8db*^^am>LBtYW0iqbuQ#fLEP1cezu`Kk*)|K zTS}f2$M)q(m&8QGt9`#DS`g7(8jzt>1k+X1nJQl|5mP#Jv z3JC^+fnXpQ2nJ3uAa^!oer_0jFc1s`1K$kbd`QxO*|8Yv(IK6d0D?1_RuLVw1bmWX zb}WWs5n*!`G*|W#gUwy$ldsE;#n9Y|z4&0y{8hZLW|#O$mlJ2h=!1b^V9G#a!v*gD zYx!lWMgG(!M!`TZ@Xr|FS-WmmvMIk?e{2tTZIZT;2En=lMMU(;BR~c?M=sQ8_5@wl XWyfNOD417w!FUKLA<+c`zresJ@X9>o literal 0 HcmV?d00001 diff --git a/README.md b/README.md index fc92d39..07a08c2 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ # unconflicted-Hardcore -committing my local code as-is to a new repository +committing my local code as-is to a new repository \ No newline at end of file diff --git a/bin/.DS_Store b/bin/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..4e5679eae8c9aef33e490e016ef93edb83223ffa GIT binary patch literal 6148 zcmeHKJ5Iwu5S<|@BGE)tlzWBTU=^7Y|xUr|X-hJ-qHj-rny&{J7+FeS2YN|1>_WI*EY_Pys4H1*iZOu%2zUxDI5b0#tws zd@EqzhXOaOi9?`&IuLvW0NQW78}5CU02WICYvK@y3`~Ox465dcp+QH!WL-@h0)sA^ z!-wXRH76AHr{nzM<)Sr^kqS_Oa|LFxTw4FXgI}2c&q-WS0V?pX6wrCIY1Vk9?5&fR wvtC=^Tlklu*2@vR6$8B$V_~iMc2rmF9{V+M2y{B~P6zTwz;vNefxl4T6EnsoY5)KL literal 0 HcmV?d00001 diff --git a/config.yml b/config.yml new file mode 100644 index 0000000..e69de29 diff --git a/plugin.yml b/plugin.yml new file mode 100644 index 0000000..d8927be --- /dev/null +++ b/plugin.yml @@ -0,0 +1,10 @@ + main: iie.HelloWorldPlugin + version: 1.0.0 + name: HelloWorldPlugin + commands: + hardcore: + description: Command that teleports you to hardcore world + HelloWorld: + description: Command that says Hello World! + debugRTP: + description: Command that randomly teleports someone inside the hardcore world \ No newline at end of file diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..4e5679eae8c9aef33e490e016ef93edb83223ffa GIT binary patch literal 6148 zcmeHKJ5Iwu5S<|@BGE)tlzWBTU=^7Y|xUr|X-hJ-qHj-rny&{J7+FeS2YN|1>_WI*EY_Pys4H1*iZOu%2zUxDI5b0#tws zd@EqzhXOaOi9?`&IuLvW0NQW78}5CU02WICYvK@y3`~Ox465dcp+QH!WL-@h0)sA^ z!-wXRH76AHr{nzM<)Sr^kqS_Oa|LFxTw4FXgI}2c&q-WS0V?pX6wrCIY1Vk9?5&fR wvtC=^Tlklu*2@vR6$8B$V_~iMc2rmF9{V+M2y{B~P6zTwz;vNefxl4T6EnsoY5)KL literal 0 HcmV?d00001 diff --git a/src/alisolarflare/RandomTP.java b/src/alisolarflare/RandomTP.java new file mode 100644 index 0000000..d92800c --- /dev/null +++ b/src/alisolarflare/RandomTP.java @@ -0,0 +1,183 @@ +package alisolarflare; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import iie.HelloWorldPlugin; + +public class RandomTP implements CommandExecutor{ + + private int conflictX; + private int conflictZ; + private int conflictRadius = 70; + private boolean northUsed; + private boolean southUsed; + private boolean eastUsed; + private boolean westUsed; + @SuppressWarnings("unused") + private HelloWorldPlugin helloWorldPlugin; + public RandomTP(HelloWorldPlugin helloWorldPlugin) { + this.helloWorldPlugin = helloWorldPlugin; + } + + //every 4 players who use it will be teleported near each other. + //ex. iie > 1200, ali -> 1210, byz -> 1190, charles -> 1195, wind -> 300, zan -> 310, etc + public void conflictRtp(Player player, World world, Location minLocation, Location maxLocation){ + //INIT - xDifference, xAverage + int xdifference = minLocation.getBlockX() - maxLocation.getBlockX(); + int xAverage = (int) Math.floor(minLocation.getBlockX() + maxLocation.getBlockX() / 2); + + //INIT - zDifference, zAverage + int zdifference = minLocation.getBlockX() - maxLocation.getBlockY(); + int zAverage = (int) Math.floor(minLocation.getBlockZ() + maxLocation.getBlockZ()); + + //CHECK - Reset Cycle + if ((northUsed || southUsed || eastUsed || westUsed) == false){ + + //Tries 20 times to find a location + for(int i = 0; i < 20; i ++){ + + //INIT - attemptedX, attemptedZ + int attemptedX = (int) Math.floor((Math.random()-0.5)*xdifference) + xAverage; + int attemptedZ = (int) Math.floor((Math.random()-0.5)*zdifference) + zAverage; + + int cr = conflictRadius; + + + //CHECKS - if ground is safe + boolean groundIsSafe = world.getHighestBlockAt(attemptedX, attemptedZ).getType() != Material.WATER; + boolean northIsSafe = world.getHighestBlockAt(attemptedX, attemptedZ-cr).getType() != Material.WATER; + boolean eastIsSafe = world.getHighestBlockAt(attemptedX+cr, attemptedZ).getType() != Material.WATER; + boolean southIsSafe = world.getHighestBlockAt(attemptedX, attemptedZ+cr).getType() != Material.WATER; + boolean westIsSafe = world.getHighestBlockAt(attemptedX-cr, attemptedZ).getType() != Material.WATER; + + //TRANSFER - data to class + if (groundIsSafe && (northIsSafe || southIsSafe || eastIsSafe || westIsSafe)){ + + northUsed = northIsSafe; + eastUsed = eastIsSafe; + westUsed = westIsSafe; + southUsed = southIsSafe; + conflictX = attemptedX; + conflictZ = attemptedZ; + + player.teleport(world.getHighestBlockAt(attemptedX, attemptedZ).getLocation()); + break; + } + } + } + + String dir = "north"; + //CHOOSES A RANDOM DIRECTION + for(int i = 0; i < 1000; i++){ + double randomDirection = Math.random(); + if (randomDirection < 0.25){ + if(northUsed){ + northUsed = true; + dir = "north"; + break; + } + }else if(randomDirection < 0.50){ + if(eastUsed){ + eastUsed = true; + dir = "east"; + break; + } + }else if(randomDirection < 0.75){ + if(southUsed){ + southUsed = true; + dir = "south"; + break; + } + }else{ + if(westUsed){ + westUsed = true; + dir = "west"; + break; + } + + } + } + + + //TELEPORT - teleports player to the conflict point + switch(dir){ + case "north": + northUsed = false; + player.teleport(world.getHighestBlockAt(conflictX, conflictZ - conflictRadius).getLocation()); + break; + case "east": + eastUsed = false; + player.teleport(world.getHighestBlockAt(conflictX + conflictRadius, conflictZ).getLocation()); + break; + case "south": + southUsed = false; + player.teleport(world.getHighestBlockAt(conflictX, conflictZ + conflictRadius).getLocation()); + break; + case "west": + westUsed = false; + player.teleport(world.getHighestBlockAt(conflictX - conflictRadius, conflictZ).getLocation()); + break; + default: + player.teleport(world.getHighestBlockAt(conflictX, conflictZ).getLocation()); + break; + } + } + + //Randomly teleports a player, into the hardcore world + public void rtp(Player player, World world, Location minLocation, Location maxLocation){ + player.sendMessage("TELEPORT INITIATED"); + player.sendMessage("minLocation: " + minLocation.toString()); + player.sendMessage("maxLocation: " + maxLocation.toString()); + player.sendMessage("world : " + world.toString()); + player.sendMessage("player : " + player.toString()); + + //INIT - xDifference, xAverage + int xdifference = minLocation.getBlockX() - maxLocation.getBlockX(); + int xAverage = (int) Math.floor(minLocation.getBlockX() + maxLocation.getBlockX() / 2); + + //INIT - zDifference, zAverage + int zdifference = minLocation.getBlockX() - maxLocation.getBlockY(); + int zAverage = (int) Math.floor(minLocation.getBlockZ() + maxLocation.getBlockZ()); + player.sendMessage("Averages : " + xAverage + "|" + zAverage); + //TELEPORTS - Tries 20 times to find a location + for(int i = 0; i < 20; i ++){ + + //INIT - attemptedX, attemptedZ + int attemptedX = (int) Math.floor((Math.random()-0.5)*xdifference) + xAverage; + int attemptedZ = (int) Math.floor((Math.random()-0.5)*zdifference) + zAverage; + player.sendMessage("TAKE " + i + " : " + attemptedX + ", "+ attemptedZ); + //CHECKS - if ground is safe + boolean groundisSafe = world.getHighestBlockAt(attemptedX, attemptedZ).getType() != Material.WATER; + if (groundisSafe){ + player.sendMessage("SAFE GROUND, TELEPORTING"); + player.teleport(world.getHighestBlockAt(attemptedX, attemptedZ).getLocation()); + return; + } + + //player.teleport(arg0) + } + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if(!(sender instanceof Player)){ + sender.sendMessage("You must be a Player to use this command!"); + sender.sendMessage(sender.toString()); + return false; + } + Player player = (Player) sender; + if(player.getWorld().getName() != "hardcore"){ + sender.sendMessage("You must be in the hardcore world to use this command!"); + sender.sendMessage("Current World: " + player.getWorld().getName()); + return false; + } + rtp(player, player.getWorld(), new Location(player.getWorld(), 644, 65, -944), new Location(player.getWorld(), 1700, 65, 464)); + return false; + } +} diff --git a/src/alisolarflare/listeners/CompassLobby.java b/src/alisolarflare/listeners/CompassLobby.java new file mode 100644 index 0000000..a07f676 --- /dev/null +++ b/src/alisolarflare/listeners/CompassLobby.java @@ -0,0 +1,26 @@ +package alisolarflare.listeners; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + + +public class CompassLobby implements Listener{ + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event){ + openGUI(event.getPlayer()); + } + public void openGUI(Player p){ + //format: null, size of inventory (must be divisible by 9), "GUI name" + Inventory inv = Bukkit.createInventory(null, 9, "GUI Name"); + inv.setItem(0, new ItemStack(Material.GRASS)); + inv.setItem(1, new ItemStack(Material.IRON_SWORD)); + inv.setItem(8, new ItemStack(Material.BARRIER)); + p.openInventory(inv); + } +} diff --git a/src/alisolarflare/listeners/ConflictCompassCraftingListener.java b/src/alisolarflare/listeners/ConflictCompassCraftingListener.java new file mode 100644 index 0000000..ab26daf --- /dev/null +++ b/src/alisolarflare/listeners/ConflictCompassCraftingListener.java @@ -0,0 +1,74 @@ +package alisolarflare.listeners; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.CraftItemEvent; +import org.bukkit.inventory.ItemStack; + +public class ConflictCompassCraftingListener implements Listener{ + public static void main(String[] args){ + String nulltest = null; + if(nulltest == null){ + System.out.println("NUUUUULL"); + } + } + + @EventHandler + public boolean onConflictCompassCraft(CraftItemEvent event){ + //SANITATION - HARDCORE + if(event.getWhoClicked().getWorld().getName() != "hardcore") + return false; + + + //INIT - targetItem + ItemStack targetItem = event.getRecipe().getResult(); + + //SANITATION - NOT COMPASS + if(targetItem.getType() != Material.COMPASS) + return false; + + + event.setCancelled(true); + //GIVE - chainmail chestplate + event.getWhoClicked().getInventory().addItem(generateConflictCompass(event.getWhoClicked())); + //PLAY - cave sound + event.getWhoClicked().getWorld().playSound(event.getWhoClicked().getLocation(), Sound.AMBIENT_CAVE,0,0); + return false; + } + + private ItemStack generateConflictCompass(HumanEntity crafter) { + ItemStack conflictCompass = new ItemStack(Material.COMPASS); + conflictCompass.addUnsafeEnchantment(Enchantment.DURABILITY, 1); + List loreString = new ArrayList(); + loreString.add("The needle is tipped with the scent of"); + + loreString.add(nearestPlayerName(crafter)); + conflictCompass.getItemMeta().setLore(loreString); + return null; + } + + private String nearestPlayerName(HumanEntity crafter) { + Player nearestPlayer = null; + for(Player player: crafter.getWorld().getPlayers()){ + if (player.getUniqueId() == crafter.getUniqueId()){ + //SKIP CODE + }if (nearestPlayer == null){ + nearestPlayer = player; + }else if (nearestPlayer.getLocation().distance(crafter.getLocation()) > player.getLocation().distance(crafter.getLocation())){ + nearestPlayer = player; + } + } + if(nearestPlayer == null) + return "METAL"; + + return nearestPlayer.toString(); + } +} diff --git a/src/alisolarflare/listeners/DiamondArmorBlocker.java b/src/alisolarflare/listeners/DiamondArmorBlocker.java new file mode 100644 index 0000000..277dd36 --- /dev/null +++ b/src/alisolarflare/listeners/DiamondArmorBlocker.java @@ -0,0 +1,51 @@ +package alisolarflare.listeners; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.CraftItemEvent; +import org.bukkit.inventory.ItemStack; + +public class DiamondArmorBlocker implements Listener{ + public static List blockedItems = Arrays.asList(Material.DIAMOND_BOOTS, Material.DIAMOND_CHESTPLATE, Material.DIAMOND_LEGGINGS, Material.DIAMOND_HELMET); + @EventHandler + public boolean onArmorSmith(CraftItemEvent event){ + //SANITATION - hardcore + if(event.getWhoClicked().getWorld().getName() != "hardcore"){ + return false; + } + + //INIT - inventory, targetItem + ItemStack targetItem = event.getRecipe().getResult(); + + //REPLACE - Diamond Chestplate > Chainmail Chestplate + if (blockedItems.contains(targetItem.getType())){ + event.setCancelled(true); + //GIVE - chainmail chestplate + event.getWhoClicked().getInventory().addItem(failArmor(targetItem.getType())); + //PLAY - cave sound + event.getWhoClicked().getWorld().playSound(event.getWhoClicked().getLocation(), Sound.AMBIENT_CAVE,0,0); + event.getWhoClicked().getWorld().playSound(event.getWhoClicked().getLocation(), Sound.ENTITY_ITEM_BREAK,0,0); + } + return false; + + + } + public ItemStack failArmor(Material material){ + ItemStack failArmor = new ItemStack(material); + failArmor.addEnchantment(Enchantment.THORNS, 1); + + //INIT - Chainmail's lore + List loreString = new ArrayList(); + loreString.add("This world is forever dangerous."); + loreString.add("There is no protection here."); + failArmor.getItemMeta().setLore(loreString); + return failArmor; + } +} diff --git a/src/iie/DeathListener.java b/src/iie/DeathListener.java new file mode 100644 index 0000000..ea67603 --- /dev/null +++ b/src/iie/DeathListener.java @@ -0,0 +1,43 @@ +package iie; + +import java.util.Objects; + +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.PlayerDeathEvent; + +public class DeathListener implements Listener { + + HelloWorldPlugin plugin; + public DeathListener(HelloWorldPlugin plugin){ + this.plugin = plugin; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onHardcoreDeath(PlayerDeathEvent deathEvent){ + + int currentTime = (int) ((System.currentTimeMillis())/1000); //divided by 1000 to fit within Integer range + Player player = deathEvent.getEntity(); + String playername = (String) player.getName(); + 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")){ + + 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 new file mode 100644 index 0000000..9e331cb --- /dev/null +++ b/src/iie/HelloWorld.java @@ -0,0 +1,75 @@ +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; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + + +public class HelloWorld implements CommandExecutor { + + HelloWorldPlugin plugin; + public HelloWorld(HelloWorldPlugin plugin){ + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command label, String command, String[] args) { + + + + + if (sender instanceof Player){ + + 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); + + 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 " + ((currentTime - deathTime) /3600) + " hours ago. Good luck, " + playername + "."); + player.teleport(location); + player.getWorld().playSound(player.getLocation(), Sound.AMBIENT_CAVE,1F,1F); + }else if(deathTime == 0){ + sender.sendMessage("You have never died, good luck"); + player.teleport(location); + 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,1F,1F); + // replace sound with some other sound + } + + + + }else{ + sender.sendMessage("You must be a player to use this command!"); + } + + + + return false; + } + +} diff --git a/src/iie/HelloWorldPlugin.java b/src/iie/HelloWorldPlugin.java new file mode 100644 index 0000000..a3a1995 --- /dev/null +++ b/src/iie/HelloWorldPlugin.java @@ -0,0 +1,43 @@ +package iie; + +import java.util.AbstractMap; +import java.util.HashMap; + +import org.bukkit.Bukkit; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Scoreboard; + + +public class HelloWorldPlugin extends JavaPlugin { + + public static Scoreboard board; + public static Objective hardcoreTimeDead; + 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)); + } + +} \ No newline at end of file diff --git a/src/iie/JoinListener.java b/src/iie/JoinListener.java new file mode 100644 index 0000000..5bf6b1b --- /dev/null +++ b/src/iie/JoinListener.java @@ -0,0 +1,52 @@ +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.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())); + + + } + +}