1
0
mirror of https://github.com/nkomarn/harbor.git synced 2024-12-20 23:37:45 +01:00

Update 1.4.2: Hotfix for 1.13.2

This commit is contained in:
Mykyta Komarn 2018-12-17 17:42:30 -08:00
parent 78f920eabe
commit 5523cdc0ff
8 changed files with 147 additions and 69 deletions

View File

@ -2,6 +2,7 @@
<classpath> <classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="T:/Test Server/1.13.2/Spigot.jar"/>
<classpathentry kind="lib" path="T:/Test Server/1.8/Spigot.jar"/> <classpathentry kind="lib" path="T:/Test Server/1.8/Spigot.jar"/>
<classpathentry kind="lib" path="T:/Test Server/1.8.3/Spigot.jar"/> <classpathentry kind="lib" path="T:/Test Server/1.8.3/Spigot.jar"/>
<classpathentry kind="lib" path="T:/Test Server/1.8.8/Spigot.jar"/> <classpathentry kind="lib" path="T:/Test Server/1.8.8/Spigot.jar"/>

View File

@ -24,6 +24,8 @@ features:
skipNight: true skipNight: true
# Clear weather when skipping night # Clear weather when skipping night
clearWeather: true clearWeather: true
# Toggle exclusion of operators/players with permission "harbor.bypass" from sleep count
bypass: false
# Display debug information in console # Display debug information in console
debug: false debug: false
@ -58,4 +60,4 @@ messages:
permission: "&7Insufficient permissions." permission: "&7Insufficient permissions."
# Version identifier (do not change) # Version identifier (do not change)
version: 1.4 version: 1.4.2

View File

@ -1,5 +1,5 @@
name: Harbor name: Harbor
version: 1.4 version: 1.4.2
main: techtoolbox.Harbor.Main main: techtoolbox.Harbor.Main
description: Ahoy, matey! Harbor is a Spigot plugin that redefines how sleep works in your server, making it easier for all the online players to get in bed quick and skip through the night! description: Ahoy, matey! Harbor is a Spigot plugin that redefines how sleep works in your server, making it easier for all the online players to get in bed quick and skip through the night!
author: TechToolbox author: TechToolbox

View File

@ -4,23 +4,40 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerBedEnterEvent; import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerBedEnterEvent.BedEnterResult;
import techtoolbox.Harbor.Main; import techtoolbox.Harbor.Main;
public class BedEnterEvent implements Listener { public class BedEnterEvent implements Listener {
@EventHandler
String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerBedEnterEvent(PlayerBedEnterEvent event) { public void onPlayerBedEnterEvent(PlayerBedEnterEvent event) {
// TEMPORARY SOLUTION FOR 1.13.2: CHECK IF BEDENTERRESULT WORKS, IF NOT THEN RUN 1.13.1 CODE
try {
if (event.getBedEnterResult() == BedEnterResult.OK) {
Main.bypassers.clear(); Main.bypassers.clear();
if (Main.plugin.getConfig().getBoolean("features.bypass")) {
for (Player player : Bukkit.getServer().getOnlinePlayers()) { for (Player player : Bukkit.getServer().getOnlinePlayers()) {
if (player.hasPermission("harbor.bypass")) { if (player.hasPermission("harbor.bypass")) {
Main.bypassers.add(player.getName()); Main.bypassers.add(player.getName());
} }
} }
}
if (!event.getPlayer().hasPermission("harbor.bypass")) { if (!event.getPlayer().hasPermission("harbor.bypass")) {
try {
Main.worlds.put(event.getPlayer().getWorld(), Integer.valueOf((Main.worlds.get(event.getPlayer().getWorld())).intValue() + 1)); Main.worlds.put(event.getPlayer().getWorld(), Integer.valueOf((Main.worlds.get(event.getPlayer().getWorld())).intValue() + 1));
}
catch (Exception exception) {
// Create value if it doesn't exist already
Main.worlds.put(event.getPlayer().getWorld(), 1);
}
// Chat messages // Chat messages
if (Main.plugin.getConfig().getBoolean("messages.chat.chat") && (Main.plugin.getConfig().getString("messages.chat.sleeping").length() != 0)) { if (Main.plugin.getConfig().getBoolean("messages.chat.chat") && (Main.plugin.getConfig().getString("messages.chat.sleeping").length() != 0)) {
@ -57,3 +74,58 @@ public class BedEnterEvent implements Listener {
} }
} }
} }
catch (NoSuchMethodError e){
Main.bypassers.clear();
if (Main.plugin.getConfig().getBoolean("features.bypass")) {
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
if (player.hasPermission("harbor.bypass")) {
Main.bypassers.add(player.getName());
}
}
}
if (!event.getPlayer().hasPermission("harbor.bypass")) {
try {
Main.worlds.put(event.getPlayer().getWorld(), Integer.valueOf((Main.worlds.get(event.getPlayer().getWorld())).intValue() + 1));
}
catch (Exception exception) {
// Create value if it doesn't exist already
Main.worlds.put(event.getPlayer().getWorld(), 1);
}
// Chat messages
if (Main.plugin.getConfig().getBoolean("messages.chat.chat") && (Main.plugin.getConfig().getString("messages.chat.sleeping").length() != 0)) {
Bukkit.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', Main.plugin.getConfig().getString("messages.chat.sleeping")
.replace("[sleeping]", String.valueOf(Main.worlds.get(event.getPlayer().getWorld())))
.replace("[online]", String.valueOf(event.getPlayer().getWorld().getPlayers().size() - Main.bypassers.size()))
.replace("[player]", event.getPlayer().getName())
.replace("[needed]", String.valueOf(Math.max(0, Math.round(event.getPlayer().getWorld().getPlayers().size() * Float.parseFloat(Main.plugin.getConfig().getString("values.percent")) - Main.bypassers.size() - (Main.worlds.get(event.getPlayer().getWorld())).intValue()))))));
}
// Skip night feature
if (Main.plugin.getConfig().getBoolean("features.skipNight") && ((Main.worlds.get(event.getPlayer().getWorld())).intValue() >= event.getPlayer().getWorld().getPlayers().size() * Float.parseFloat(Main.plugin.getConfig().getString("values.percent")) - Main.bypassers.size()) && (event.getPlayer().getWorld().getPlayers().size() > 1)) {
Bukkit.getServer().getWorld(event.getPlayer().getWorld().getName()).setTime(1000L);
// Weather clear feature
if (Main.plugin.getConfig().getBoolean("features.clearWeather")) {
event.getPlayer().getWorld().setStorm(false);
event.getPlayer().getWorld().setThundering(false);
}
// Night skipped message
if (Main.plugin.getConfig().getBoolean("messages.chat.chat") && (Main.plugin.getConfig().getString("messages.chat.skipped").length() != 0)) {
Bukkit.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', Main.plugin.getConfig().getString("messages.chat.skipped")));
}
}
}
else if (Main.plugin.getConfig().getString("messages.chat.bypass").length() != 0) {
event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', Main.plugin.getConfig().getString("messages.chat.bypass")));
}
// Reset value if below zero (plugin glitch)
if ((Main.worlds.get(event.getPlayer().getWorld())).intValue() < 0) {
Main.worlds.put(event.getPlayer().getWorld(), Integer.valueOf(0));
}
}
}
}

View File

@ -3,20 +3,24 @@ package techtoolbox.Harbor.Listeners;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerBedLeaveEvent; import org.bukkit.event.player.PlayerBedLeaveEvent;
import techtoolbox.Harbor.Main; import techtoolbox.Harbor.Main;
public class BedLeaveEvent implements Listener { public class BedLeaveEvent implements Listener {
@EventHandler
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerBedLeave(PlayerBedLeaveEvent event) { public void onPlayerBedLeave(PlayerBedLeaveEvent event) {
Main.bypassers.clear(); Main.bypassers.clear();
if (Main.plugin.getConfig().getBoolean("features.bypass")) {
for (Player player : Bukkit.getServer().getOnlinePlayers()) { for (Player player : Bukkit.getServer().getOnlinePlayers()) {
if (player.hasPermission("harbor.bypass")) { if (player.hasPermission("harbor.bypass")) {
Main.bypassers.add(player.getName()); Main.bypassers.add(player.getName());
} }
} }
}
if (!event.getPlayer().hasPermission("harbor.bypass")) { if (!event.getPlayer().hasPermission("harbor.bypass")) {
Main.worlds.put(event.getPlayer().getWorld(), Integer.valueOf((Main.worlds.get(event.getPlayer().getWorld())).intValue() - 1)); Main.worlds.put(event.getPlayer().getWorld(), Integer.valueOf((Main.worlds.get(event.getPlayer().getWorld())).intValue() - 1));

View File

@ -12,6 +12,7 @@ public class JoinEvent implements Listener {
@EventHandler @EventHandler
public void onPlayerJoin(PlayerJoinEvent event) { public void onPlayerJoin(PlayerJoinEvent event) {
Main.bypassers.clear(); Main.bypassers.clear();
if (Main.plugin.getConfig().getBoolean("features.bypass")) {
for (Player player : Bukkit.getServer().getOnlinePlayers()) { for (Player player : Bukkit.getServer().getOnlinePlayers()) {
if (player.hasPermission("harbor.bypass")) { if (player.hasPermission("harbor.bypass")) {
Main.bypassers.add(player.getName()); Main.bypassers.add(player.getName());
@ -19,3 +20,4 @@ public class JoinEvent implements Listener {
} }
} }
} }
}

View File

@ -12,6 +12,7 @@ public class QuitEvent implements Listener{
@EventHandler @EventHandler
public void onPlayerQuit(PlayerQuitEvent event) { public void onPlayerQuit(PlayerQuitEvent event) {
Main.bypassers.clear(); Main.bypassers.clear();
if (Main.plugin.getConfig().getBoolean("features.bypass")) {
for (Player player : Bukkit.getServer().getOnlinePlayers()) { for (Player player : Bukkit.getServer().getOnlinePlayers()) {
if (player.hasPermission("harbor.bypass")) { if (player.hasPermission("harbor.bypass")) {
Main.bypassers.add(player.getName()); Main.bypassers.add(player.getName());
@ -19,3 +20,4 @@ public class QuitEvent implements Listener{
} }
} }
} }
}

View File

@ -7,7 +7,10 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import techtoolbox.Harbor.Actionbar.Actionbar; import techtoolbox.Harbor.Actionbar.Actionbar;
@ -27,7 +30,7 @@ import techtoolbox.Harbor.Listeners.QuitEvent;
public class Main extends JavaPlugin implements Listener { public class Main extends JavaPlugin implements Listener {
public static Main plugin; public static Main plugin;
public static String version = "1.4"; public static String version = "1.4.2";
public static HashMap<World, Integer> worlds = new HashMap<World, Integer>(); public static HashMap<World, Integer> worlds = new HashMap<World, Integer>();
public static ArrayList<String> bypassers = new ArrayList<String>(); public static ArrayList<String> bypassers = new ArrayList<String>();
public static Actionbar actionbar; public static Actionbar actionbar;
@ -41,21 +44,12 @@ public class Main extends JavaPlugin implements Listener {
Bukkit.getPluginManager().registerEvents(new BedEnterEvent(), this); Bukkit.getPluginManager().registerEvents(new BedEnterEvent(), this);
Bukkit.getPluginManager().registerEvents(new BedLeaveEvent(), this); Bukkit.getPluginManager().registerEvents(new BedLeaveEvent(), this);
// Detect old configuration version
try {
if (Float.valueOf(getConfig().getString("version")) > Float.valueOf(version)) {
Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("messages.miscellaneous.prefix") + "&7Configuration version is incompatible. Running Harbor version " + version + " while the configuration version is " + getConfig().getString("version") + "."));
}
}
catch (Exception e) {
// Config older than version 1.4
Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("messages.miscellaneous.prefix") + "&7Incompatible configuration. Delete the current configuration to generate a valid one."));
}
// Fill up worlds list // Fill up worlds list
if (getConfig().getBoolean("features.bypass")) {
for (int i = 0; Bukkit.getServer().getWorlds().size() > i; i++) { for (int i = 0; Bukkit.getServer().getWorlds().size() > i; i++) {
worlds.put(Bukkit.getServer().getWorlds().get(i), Integer.valueOf(0)); worlds.put(Bukkit.getServer().getWorlds().get(i), Integer.valueOf(0));
} }
}
// Start actionbar message check // Start actionbar message check
if (getConfig().getBoolean("messages.actionbar.actionbar")) { if (getConfig().getBoolean("messages.actionbar.actionbar")) {
@ -113,6 +107,7 @@ public class Main extends JavaPlugin implements Listener {
Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("messages.miscellaneous.prefix") + plugin.getConfig().getString("messages.miscellaneous.running").replace("[version]", version))); Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("messages.miscellaneous.prefix") + plugin.getConfig().getString("messages.miscellaneous.running").replace("[version]", version)));
// Actionbar
if (version.equals("v1_8_R1")) { if (version.equals("v1_8_R1")) {
actionbar = new Actionbar_1_8_R1(); actionbar = new Actionbar_1_8_R1();
}else if (version.equals("v1_8_R2")) { }else if (version.equals("v1_8_R2")) {