diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..e208459
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..530a010
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..6e73ec6
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,215 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1524137278600
+
+
+ 1524137278600
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/AdvanceRespawn.iml b/AdvanceRespawn.iml
new file mode 100644
index 0000000..3838f0d
--- /dev/null
+++ b/AdvanceRespawn.iml
@@ -0,0 +1,107 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/config.yml b/config.yml
index 0c9c492..689d914 100755
--- a/config.yml
+++ b/config.yml
@@ -26,8 +26,9 @@ Disabled_Worlds:
#-==={ Spectate Death }===-#
#when a player dies he will respawn in spectator mode until a set time
Spectate_Respawn: false
-Spectate_Respawn_For_Players_In_Creative: false
Spectate_Respawn_Length: 4
+Spectate_Respawn_Max_Fly_Distance: 100
+Spectate_Respawn_For_Players_In_Creative: false
Spectate_Respawn_Progress_Title: '&2Respawning...!'
Spectate_Respawn_Title_Line_1: '&cRespawned!'
Spectate_Respawn_Title_Line_2: '&aYou have respawned &2{blocks} &ablocks away'
diff --git a/plugin.yml b/plugin.yml
index 03d0293..cacaaa1 100755
--- a/plugin.yml
+++ b/plugin.yml
@@ -1,6 +1,6 @@
name: AdvanceRespawn
main: net.scyllamc.matan.respawn.Main
-version: 6.1.3
+version: 7.0.2
description: AdvanceRespawn
load: POSTWORLD
author: Matan Rak
diff --git a/src/net/scyllamc/matan/respawn/Commands.java b/src/net/scyllamc/matan/respawn/Commands.java
index 570fe55..2775923 100644
--- a/src/net/scyllamc/matan/respawn/Commands.java
+++ b/src/net/scyllamc/matan/respawn/Commands.java
@@ -7,7 +7,7 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
-public class PublicCommands implements CommandExecutor {
+public class Commands implements CommandExecutor {
public String prefix = ChatColor.DARK_GREEN + "Advance Respawn" + ChatColor.GRAY.toString() + " | ";
@@ -29,6 +29,14 @@ public boolean onCommand(CommandSender sender, Command command, String alias, St
return true;
}
+
+ if (args[0].equalsIgnoreCase("settings")) {
+
+ player.sendMessage(ChatColor.GREEN + " /AR Settings List " + ChatColor.GRAY + " | Lists all editable settings");
+ player.sendMessage(ChatColor.GREEN + " /AR Settings Edit {setting} {new_value}" + ChatColor.GRAY + " | Edit a specified setting");
+ }
+
+
if (args[0].equalsIgnoreCase("reload")) {
if (player.hasPermission("AdvanceRespawn.reload")) {
@@ -42,6 +50,7 @@ public boolean onCommand(CommandSender sender, Command command, String alias, St
}
}
+
if (args[0].equalsIgnoreCase("info")) {
String version = Bukkit.getPluginManager().getPlugin("AdvanceRespawn").getDescription().getVersion();
diff --git a/src/net/scyllamc/matan/respawn/Config.java b/src/net/scyllamc/matan/respawn/Config.java
index 95daea5..ff4c3f5 100644
--- a/src/net/scyllamc/matan/respawn/Config.java
+++ b/src/net/scyllamc/matan/respawn/Config.java
@@ -12,7 +12,6 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
-import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
@@ -31,8 +30,9 @@ public enum Config {
DISABLED_WORLDS(new ArrayList()),
SPECTATE_RESPAWN(false),
- SPECTATE_RESPAWN_FOR_PLAYERS_IN_CREATIVE(false),
SPECTATE_RESPAWN_LENGTH(4),
+ SPECTATE_RESPAWN_MAX_FLY_DISTANCE(100),
+ SPECTATE_RESPAWN_FOR_PLAYERS_IN_CREATIVE(false),
SPECTATE_RESPAWN_PROGRESS_TITLE("&2Respawning...!"),
SPECTATE_RESPAWN_TITLE_LINE_1("&cRespawned!"),
SPECTATE_RESPAWN_TITLE_LINE_2("&aYou have respawned &2%blocks% &ablocks away"),
@@ -54,17 +54,11 @@ public enum Config {
public static Plugin plugin = Main.plugin;
public static FileConfiguration config = plugin.getConfig();
-
-
+
+
@SuppressWarnings({ "resource", "unchecked" })
- public static void updateConfigVersion() {
-
- Bukkit.broadcastMessage("Updating config values");
-
- plugin.reloadConfig();
-
- final Map configValues = new HashMap(plugin.getConfig().getValues(true));
-
+ public static void saveConfig(Map configValues) {
+
File configFile = new File(plugin.getDataFolder(), "config.yml");
configFile.delete();
@@ -108,7 +102,13 @@ else if (savedEntry.getValue() instanceof String)
e.printStackTrace();
}
}
+
+ public static void updateConfigVersion() {
+ plugin.reloadConfig();
+ saveConfig(new HashMap(plugin.getConfig().getValues(true)));
+ }
+
private Object value;
@@ -118,6 +118,18 @@ else if (savedEntry.getValue() instanceof String)
}
+ public void updateValue(Object newValue) {
+
+ plugin.reloadConfig();
+ HashMap baseValues = new HashMap(plugin.getConfig().getValues(true));
+
+ if(baseValues.containsKey(toConfigString()))
+ baseValues.put(toConfigString(), newValue);
+
+ saveConfig(baseValues);
+ }
+
+
public String toConfigString() {
return Stream.of(this.toString().split("_")).map(entry -> Utilities.firstLetterCaps(entry)).collect(Collectors.joining("_"));
}
@@ -128,7 +140,6 @@ public String getStringValue() {
if (config.contains(this.toConfigString()))
return config.getString(this.toConfigString());
- Bukkit.broadcastMessage("BOOM : " + this.toConfigString());
updateConfigVersion();
return value.toString();
}
@@ -139,7 +150,6 @@ public int getIntValue() {
if (config.contains(this.toConfigString()))
return config.getInt(this.toConfigString());
- Bukkit.broadcastMessage("BOOM : " + this.toConfigString());
updateConfigVersion();
return (int) value;
}
@@ -150,7 +160,6 @@ public boolean getBoolenValue() {
if (config.contains(this.toConfigString()))
return config.getBoolean(this.toConfigString());
- Bukkit.broadcastMessage("BOOM : " + this.toConfigString());
updateConfigVersion();
return (boolean) value;
}
@@ -163,7 +172,6 @@ public ArrayList getArrayValue() {
if (config.contains(this.toConfigString()))
return (ArrayList) config.getList(this.toConfigString());
- Bukkit.broadcastMessage("BOOM : " + this.toConfigString());
updateConfigVersion();
return (ArrayList) value;
}
diff --git a/src/net/scyllamc/matan/respawn/Events.java b/src/net/scyllamc/matan/respawn/Events.java
index 449ef29..d9314b9 100644
--- a/src/net/scyllamc/matan/respawn/Events.java
+++ b/src/net/scyllamc/matan/respawn/Events.java
@@ -30,7 +30,12 @@ public void Death(PlayerDeathEvent event) {
if (Main.deathCauseCache.containsKey(player.getUniqueId()))
Main.deathCauseCache.remove(player.getUniqueId());
- deathLocations.put(player.getUniqueId(), player.getLocation());
+ Location deathLocation = player.getLocation();
+
+ if(deathLocation.getBlockY() <= 0)
+ deathLocation = deathLocation.getWorld().getHighestBlockAt(deathLocation).getLocation();
+
+ deathLocations.put(player.getUniqueId(), deathLocation);
deathEvents.put(player.getUniqueId(), event);
if (Config.AUTO_RESPAWN.getBoolenValue())
@@ -42,7 +47,6 @@ public void run() {
if (Config.USE_DEATH_MESSAGE.getBoolenValue())
event.setDeathMessage(Config.DEATH_MESSAGE.getFormattedValue(player, 0).replace("{reason}", Utilities.getDeathMessage(player)));
-
}
@@ -53,14 +57,15 @@ public void onPlayerRespawn(PlayerRespawnEvent event) {
Location respawnLocation = player.getWorld().getSpawnLocation();
Location deathLocation = player.getLocation();
+
+ if (deathLocations.containsKey(player.getUniqueId()))
+ deathLocation = deathLocations.get(player.getUniqueId());
+
int distance = (int) deathLocation.distance(respawnLocation);
if (Config.DISABLED_WORLDS.getArrayValue().contains(deathLocation.getWorld().getName()))
return;
- if (deathLocations.containsKey(player.getUniqueId()))
- deathLocation = deathLocations.get(player.getUniqueId());
-
if (Config.USE_RADIUS.getBoolenValue())
respawnLocation = Utilities.getRandomSpawnLocation(deathLocation);
@@ -70,11 +75,13 @@ public void onPlayerRespawn(PlayerRespawnEvent event) {
if (Config.SHOW_RESPAWN_TITLES.getBoolenValue() && Main.title != null)
Main.getTitle().sendTitle(player, 7, 15, 15, Config.RESPAWN_TITLE_LINE_1.getFormattedValue(player, distance), Config.RESPAWN_TITLE_LINE_2.getFormattedValue(player, distance));
- if (Config.SPECTATE_RESPAWN.getBoolenValue())
+ if (Config.SPECTATE_RESPAWN.getBoolenValue()) {
+ event.setRespawnLocation(deathLocation);
Utilities.deathSpectate(player, deathLocation, respawnLocation);
- else
- Utilities.runCommands(player);
+ return;
+ }
+ Utilities.runCommands(player);
event.setRespawnLocation(respawnLocation);
}
diff --git a/src/net/scyllamc/matan/respawn/Main.java b/src/net/scyllamc/matan/respawn/Main.java
index a3853cc..d030860 100755
--- a/src/net/scyllamc/matan/respawn/Main.java
+++ b/src/net/scyllamc/matan/respawn/Main.java
@@ -57,7 +57,7 @@ public void onEnable() {
Bukkit.getPluginManager().registerEvents(this, this);
Bukkit.getPluginManager().registerEvents(new Events(), this);
- getCommand("AdvanceRespawn").setExecutor(new PublicCommands());
+ getCommand("AdvanceRespawn").setExecutor(new Commands());
initializeProperties();
@@ -77,12 +77,10 @@ public void run() {
@Override
public void onDisable() {
- if (Bukkit.getPluginManager().isPluginEnabled("HolographicDisplays")) {
- for (com.gmail.filoghost.holographicdisplays.api.Hologram hologram : com.gmail.filoghost.holographicdisplays.api.HologramsAPI.getHolograms(Bukkit.getPluginManager().getPlugin("AdvanceRespawn"))) {
+ if (Bukkit.getPluginManager().isPluginEnabled("HolographicDisplays"))
+ for (com.gmail.filoghost.holographicdisplays.api.Hologram hologram : com.gmail.filoghost.holographicdisplays.api.HologramsAPI.getHolograms(Bukkit.getPluginManager().getPlugin("AdvanceRespawn")))
hologram.delete();
- }
- }
-
+
for (Entry entry : spectatorsGamemode.entrySet()) {
((HumanEntity) Bukkit.getOfflinePlayer(entry.getKey())).setGameMode(entry.getValue());
((HumanEntity) Bukkit.getOfflinePlayer(entry.getKey())).teleport(Events.deathLocations.get(entry.getKey()));
@@ -107,7 +105,6 @@ private static boolean loadTitle() {
try {
version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
-
} catch (ArrayIndexOutOfBoundsException whatVersionAreYouUsingException) {
return false;
}
diff --git a/src/net/scyllamc/matan/respawn/Utilities.java b/src/net/scyllamc/matan/respawn/Utilities.java
index ea78387..1ce9c09 100644
--- a/src/net/scyllamc/matan/respawn/Utilities.java
+++ b/src/net/scyllamc/matan/respawn/Utilities.java
@@ -48,25 +48,32 @@ public static String getDeathMessage(Player player) {
EntityDamageByEntityEvent combatEvent = (EntityDamageByEntityEvent) event.getEntity().getLastDamageCause();
Entity damager = combatEvent.getDamager();
- if (damager instanceof Projectile) {
-
- Projectile projectile = (Projectile) damager;
-
- if (projectile.getShooter() instanceof Player)
- if (projectile instanceof Arrow)
- cause = format(Main.casue_dictionary.getProperty("KILLED_BY_PLAYER_ARROW"), player).replace("{killer}", ((Player) damager).getName());
+ String property = "KILLED_BY_ENTITY";
+ String killerName = damager.getType().toString().toLowerCase();
+
+ if (damager instanceof Projectile)
+
+ if (((Projectile) damager).getShooter() instanceof Player)
+ if (damager instanceof Arrow)
+ property = "KILLED_BY_PLAYER_ARROW";
else
- cause = format(Main.casue_dictionary.getProperty("KILLED_BY_PLAYER_PROJECTILE"), player).replace("{killer}", ((Player) damager).getName());
+ property = "KILLED_BY_PLAYER_PROJECTILE";
else
- if (projectile instanceof Arrow)
- cause = format(Main.casue_dictionary.getProperty("KILLED_BY_ENTITY_ARROW"), player).replace("{killer}", damager.getType().toString().toLowerCase());
+ if (damager instanceof Arrow)
+ cause = "KILLED_BY_ENTITY_ARROW";
else
- cause = format(Main.casue_dictionary.getProperty("KILLED_BY_ENTITY_PROJECTILE"), player).replace("{killer}", damager.getType().toString().toLowerCase());
+ cause = "KILLED_BY_ENTITY_PROJECTILE";
- }else if (damager instanceof Player)
- cause = format(Main.casue_dictionary.getProperty("KILLED_BY_PLAYER"), player).replace("{killer}", ((Player) damager).getName());
- else
- cause = format(Main.casue_dictionary.getProperty("KILLED_BY_ENTITY"), player).replace("{killer}", damager.getType().toString().toLowerCase());
+ else if (damager instanceof Player)
+ property = "KILLED_BY_PLAYER";
+
+ if (property.contains("PLAYER"))
+ if (property.contains("ARROW") || property.contains("PROJECTILE"))
+ killerName = ((Entity) ((Projectile) damager).getShooter()).getName();
+ else
+ killerName = damager.getName();
+
+ cause = format(Main.casue_dictionary.getProperty(property), player).replace("{killer}", killerName);
}
Main.deathCauseCache.put(player.getUniqueId(), cause);
@@ -105,7 +112,7 @@ public static Location getTopBlock(Location loc) {
if (unspawnable.contains(loc.getBlock().getTypeId())) {
- while (unspawnable.contains(current.getBlock().getTypeId()))
+ while (unspawnable.contains(current.getBlock().getTypeId()) && current.getBlockY() > 0)
current = current.add(0, -1, 0);
@@ -198,7 +205,7 @@ public static void deathSpectate(Player player, Location deathLocation, Location
final Title title = Main.getTitle();
final GameMode gameMode = player.getGameMode();
- if (gameMode == GameMode.CREATIVE && !Config.SPECTATE_RESPAWN_FOR_PLAYERS_IN_CREATIVE.getBoolenValue())
+ if ((gameMode == GameMode.CREATIVE || gameMode == GameMode.SPECTATOR) && !Config.SPECTATE_RESPAWN_FOR_PLAYERS_IN_CREATIVE.getBoolenValue())
return;
int duration = Config.SPECTATE_RESPAWN_LENGTH.getIntValue();
@@ -206,12 +213,6 @@ public static void deathSpectate(Player player, Location deathLocation, Location
title.sendTitle(player, 14, 30, 30, Config.SPECTATE_RESPAWN_PROGRESS_TITLE.getFormattedValue(player, 0), ChatColor.RED + "" + duration);
Main.spectatorsGamemode.put(player.getUniqueId(), gameMode);
player.setGameMode(GameMode.SPECTATOR);
-
- Bukkit.getScheduler().scheduleSyncDelayedTask(Main.plugin, new Runnable() {
- public void run() {
- player.teleport(deathLocation);
- }
- }, 1L);
new BukkitRunnable() {
@@ -221,11 +222,15 @@ public void run() {
public void run() {
if (counter > 0) {
+
+ if(player.getLocation().getBlockY() < 0 || player.getWorld() != deathLocation.getWorld() || player.getLocation().distance(deathLocation) > Config.SPECTATE_RESPAWN_MAX_FLY_DISTANCE.getIntValue())
+ player.teleport(deathLocation);
+
title.sendTitle(player, 7, 15, 15, Config.SPECTATE_RESPAWN_PROGRESS_TITLE.getFormattedValue(player, 0), ChatColor.RED + "" + counter);
counter--;
- return;
+ return;
}
-
+
player.setGameMode(gameMode);
player.teleport(respawnLocation);
Main.spectatorsGamemode.remove(player.getUniqueId());
@@ -233,7 +238,6 @@ public void run() {
title.sendTitle(player, 7, 15, 15, Config.SPECTATE_RESPAWN_TITLE_LINE_1.getFormattedValue(player, distance), Config.SPECTATE_RESPAWN_TITLE_LINE_2.getFormattedValue(player, distance));
runCommands(player);
-
this.cancel();
}
}.runTaskTimer(Bukkit.getPluginManager().getPlugin("AdvanceRespawn"), 2, 20);