1
0
mirror of https://github.com/nkomarn/harbor.git synced 2024-12-18 22:37:36 +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>
<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="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.3/Spigot.jar"/>
<classpathentry kind="lib" path="T:/Test Server/1.8.8/Spigot.jar"/>

View File

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

View File

@ -1,5 +1,5 @@
name: Harbor
version: 1.4
version: 1.4.2
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!
author: TechToolbox

View File

@ -4,56 +4,128 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
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.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerBedEnterEvent.BedEnterResult;
import techtoolbox.Harbor.Main;
public class BedEnterEvent implements Listener {
@EventHandler
String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerBedEnterEvent(PlayerBedEnterEvent event) {
Main.bypassers.clear();
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
if (player.hasPermission("harbor.bypass")) {
Main.bypassers.add(player.getName());
// 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();
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));
}
}
}
if (!event.getPlayer().hasPermission("harbor.bypass")) {
Main.worlds.put(event.getPlayer().getWorld(), Integer.valueOf((Main.worlds.get(event.getPlayer().getWorld())).intValue() + 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()))))));
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());
}
}
}
// 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);
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);
}
// Weather clear feature
if (Main.plugin.getConfig().getBoolean("features.clearWeather")) {
event.getPlayer().getWorld().setStorm(false);
event.getPlayer().getWorld().setThundering(false);
}
// 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()))))));
}
// 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")));
}
// 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")));
}
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));
// 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.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerBedLeaveEvent;
import techtoolbox.Harbor.Main;
public class BedLeaveEvent implements Listener {
@EventHandler
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerBedLeave(PlayerBedLeaveEvent event) {
Main.bypassers.clear();
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
if (player.hasPermission("harbor.bypass")) {
Main.bypassers.add(player.getName());
}
}
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")) {
Main.worlds.put(event.getPlayer().getWorld(), Integer.valueOf((Main.worlds.get(event.getPlayer().getWorld())).intValue() - 1));

View File

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

View File

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

View File

@ -7,7 +7,10 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
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.PlayerBedEnterEvent;
import org.bukkit.plugin.java.JavaPlugin;
import techtoolbox.Harbor.Actionbar.Actionbar;
@ -27,7 +30,7 @@ import techtoolbox.Harbor.Listeners.QuitEvent;
public class Main extends JavaPlugin implements Listener {
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 ArrayList<String> bypassers = new ArrayList<String>();
public static Actionbar actionbar;
@ -41,20 +44,11 @@ public class Main extends JavaPlugin implements Listener {
Bukkit.getPluginManager().registerEvents(new BedEnterEvent(), 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
for (int i = 0; Bukkit.getServer().getWorlds().size() > i; i++) {
worlds.put(Bukkit.getServer().getWorlds().get(i), Integer.valueOf(0));
if (getConfig().getBoolean("features.bypass")) {
for (int i = 0; Bukkit.getServer().getWorlds().size() > i; i++) {
worlds.put(Bukkit.getServer().getWorlds().get(i), Integer.valueOf(0));
}
}
// Start actionbar message check
@ -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)));
// Actionbar
if (version.equals("v1_8_R1")) {
actionbar = new Actionbar_1_8_R1();
}else if (version.equals("v1_8_R2")) {