1
0
mirror of https://github.com/nkomarn/harbor.git synced 2024-12-19 23:08:58 +01:00

Harbor 1.5 release candidate!

This commit is contained in:
BuildTools 2019-05-29 16:02:16 -07:00
parent 5b39d2c920
commit 36d4a6a8bc
11 changed files with 69 additions and 47 deletions

View File

@ -18,9 +18,11 @@ values:
# Lower this value for relatively slow servers # Lower this value for relatively slow servers
clock: 1 clock: 1
# Percent of players that need to sleep to skip night (must be between 0 to 100) # Percent of players that need to sleep to skip night (must be between 0 to 100)
percent: 50 percent: 35
# Time that it takes to be considered AFK (in minutes) # Time that it takes to be considered AFK (in minutes)
timeout: 10 timeout: 15
# Time to wait before skipping the night (in seconds)
delay: 3
features: features:
# Toggle night skipping feature. Configure amount of players needed to skip above (percent) # Toggle night skipping feature. Configure amount of players needed to skip above (percent)
@ -30,13 +32,13 @@ features:
# Toggle the spawning of phantoms # Toggle the spawning of phantoms
phantoms: false phantoms: false
# Toggle exclusion of operators/players with permission "harbor.bypass" from sleep count # Toggle exclusion of operators/players with permission "harbor.bypass" from sleep count
bypass: false bypass: true
# Toggle exclusion of players in creative and spectator mode # Toggle exclusion of players in creative and spectator mode
ignore: true ignore: true
# Prevent all players from entering a bed # Prevent all players from entering a bed
block: false block: false
# Display a title message in the morning and when going to bed # Detect AFK players and remove them from the sleep count
title: true afk: true
# Displays a notification when a new update is released # Displays a notification when a new update is released
notifier: true notifier: true
@ -50,13 +52,13 @@ messages:
- "&eAhhh, finally morning." - "&eAhhh, finally morning."
- "&eArghh, it's so bright outside." - "&eArghh, it's so bright outside."
# Display which player went to bed # Display which player went to bed
sleeping: "&e[player] is now sleeping ([sleeping]/[online]. [needed] more needed to skip)." sleeping: "&e[player] is now sleeping ([sleeping]/[online], [needed] more needed to skip)."
# Display when a player left their bed # Display when a player left their bed
left: "&e[player] got out of bed ([sleeping]/[online]. [needed] more needed to skip)." left: "&e[player] got out of bed ([sleeping]/[online], [needed] more needed to skip)."
# Shown when a player tries to sleep and sleeping is blocked # Shown when a player tries to sleep and sleeping is blocked
blocked: "&cSleeping is disabled." blocked: "&cSleeping is disabled."
# Sent to player when they sleep with "harbor.bypass" permission # Sent to player when they sleep with "harbor.bypass" permission
bypass: "&eYou've been excluded from the sleep count." bypass: "&eYou're excluded from the needed count. However, you have been added to the sleep count."
# Shown when a player goes AFK # Shown when a player goes AFK
afk: "&7[player] has gone AFK." afk: "&7[player] has gone AFK."
# Shown when a player comes back after being AFK # Shown when a player comes back after being AFK
@ -71,6 +73,8 @@ messages:
# Shown when a player tries to sleep and sleeping is blocked # Shown when a player tries to sleep and sleeping is blocked
blocked: "&cSleeping is disabled." blocked: "&cSleeping is disabled."
title: title:
# Enable/Disable title messages
title: true
morning: morning:
top: "&6Good morning!" top: "&6Good morning!"
bottom: "&7Ah, such wonderful weather." bottom: "&7Ah, such wonderful weather."
@ -103,4 +107,4 @@ gui:
# Spooky controls (don't change) # Spooky controls (don't change)
version: 1.5 version: 1.5
debug: true debug: false

View File

@ -121,7 +121,7 @@
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<directory>/home/nkomarn/Documents/Spigot Servers/1.14.1/plugins/</directory> <directory>/home/nkomarn/Documents/Spigot Servers/1.14.2/plugins/</directory>
<sourceDirectory>${basedir}/src/</sourceDirectory> <sourceDirectory>${basedir}/src/</sourceDirectory>
<resources> <resources>
<resource> <resource>

View File

@ -54,12 +54,12 @@ public class BedEnter implements Listener {
.replace("[player]", p.getName()) .replace("[player]", p.getName())
.replace("[needed]", String.valueOf(util.getNeeded(w)))); .replace("[needed]", String.valueOf(util.getNeeded(w))));
} }
if (config.getBoolean("features.title")) { if (config.getBoolean("messages.title.title")) {
util.sendTitle(p, config.getString("messages.title.sleeping.top"), config.getString("messages.title.sleeping.bottom")); util.sendTitle(p, config.getString("messages.title.sleeping.top"), config.getString("messages.title.sleeping.bottom"));
} }
// Skip night if possible // Skip night if possible
util.skip(w); if (!Util.skipping) util.skip(w);
} }
else if (config.getString("messages.chat.bypass").length() != 0) p.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.chat.bypass"))); else if (config.getString("messages.chat.bypass").length() != 0) p.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.chat.bypass")));
} }

View File

@ -14,19 +14,19 @@ public class GUIEvent implements Listener {
@EventHandler @EventHandler
public void onClick(InventoryClickEvent event) { public void onClick(InventoryClickEvent event) {
util.updateActivity((Player) event.getWhoClicked());
if (event.getInventory().getHolder() != null && event.getInventory().getHolder() instanceof GUIHolder) { if (event.getInventory().getHolder() != null && event.getInventory().getHolder() instanceof GUIHolder) {
GUIType t = ((GUIHolder) event.getInventory().getHolder()).getType(); GUIType t = ((GUIHolder) event.getInventory().getHolder()).getType();
if (t.equals(GUIType.SLEEPING)) event.setCancelled(true); if (t.equals(GUIType.SLEEPING)) event.setCancelled(true);
} }
util.updateActivity((Player) event.getWhoClicked());
} }
@EventHandler @EventHandler
public void onDrag(InventoryDragEvent event) { public void onDrag(InventoryDragEvent event) {
util.updateActivity((Player) event.getWhoClicked());
if (event.getInventory().getHolder() != null && event.getInventory().getHolder() instanceof GUIHolder) { if (event.getInventory().getHolder() != null && event.getInventory().getHolder() instanceof GUIHolder) {
GUIType t = ((GUIHolder) event.getInventory().getHolder()).getType(); GUIType t = ((GUIHolder) event.getInventory().getHolder()).getType();
if (t.equals(GUIType.SLEEPING)) event.setCancelled(true); if (t.equals(GUIType.SLEEPING)) event.setCancelled(true);
} }
util.updateActivity((Player) event.getWhoClicked());
} }
} }

View File

@ -20,5 +20,7 @@ public class PlayerJoin implements Listener {
if (event.getPlayer().isOp() && updater.check() && config.getBoolean("features.notifier")) util.sendJSONMessage(event.getPlayer(), json.replace("[version]", updater.getLatest()).replace("[prefix]", config.getString("messages.miscellaneous.prefix")).replace("&", "§")); if (event.getPlayer().isOp() && updater.check() && config.getBoolean("features.notifier")) util.sendJSONMessage(event.getPlayer(), json.replace("[version]", updater.getLatest()).replace("[prefix]", config.getString("messages.miscellaneous.prefix")).replace("&", "§"));
if (!config.getVersion().equals(util.version)) event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix") + "&7The configuration is &nout of date!&7 This server is currently using configuration &oversion " + config.getVersion() + "&7, but the latest configuration is &oversion " + util.version + "&7. Make sure you update the configuration to ensure correct functionality of the plugin.")); if (!config.getVersion().equals(util.version)) event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix") + "&7The configuration is &nout of date!&7 This server is currently using configuration &oversion " + config.getVersion() + "&7, but the latest configuration is &oversion " + util.version + "&7. Make sure you update the configuration to ensure correct functionality of the plugin."));
Util.activity.put(event.getPlayer(), System.currentTimeMillis()); Util.activity.put(event.getPlayer(), System.currentTimeMillis());
if (event.getPlayer().isOp() && Util.unreleased) event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix") + "&cThis Harbor version is a prerelease. Not everything is guaranteed to work correctly, but the plugin should at least be stable. "
+ "If you encounter an issue, please create an issue on GitHub: &c&ohttps://github.com/nkomarn/Harbor/issues&c."));
} }
} }

View File

@ -19,7 +19,7 @@ public class PlayerLeave implements Listener {
new java.util.TimerTask() { new java.util.TimerTask() {
@Override @Override
public void run() { public void run() {
if (w.getPlayers().size() > 0 && Math.max(0, util.getNeeded(w) - util.getExcluded(w).size()) == 0) util.skip(w); if (w.getPlayers().size() > 0 && Math.max(0, util.getNeeded(w) - util.getExcluded(w).size()) == 0 && !Util.skipping) util.skip(w);
Util.activity.remove(p); Util.activity.remove(p);
} }
}, },

View File

@ -13,10 +13,10 @@ public class GUIHolder implements InventoryHolder {
@Override @Override
public Inventory getInventory() { public Inventory getInventory() {
return inv; // Required by InvetoryHolder return inv; // Required by InventoryHolder
} }
public GUIType getType() { public GUIType getType() {
return type; return type;
} }
} }

View File

@ -53,6 +53,8 @@ public class Harbor extends JavaPlugin {
Updater updater = new Updater(); Updater updater = new Updater();
updater.check(); updater.check();
} }
if (Util.unreleased) Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("messages.miscellaneous.prefix") + "&cThis Harbor version is a prerelease. Not everything is guaranteed to work correctly, but the plugin should at least be stable. "
+ "If you encounter an issue, please create an issue on GitHub: &c&ohttps://github.com/nkomarn/Harbor/issues&c."));
} }
public void onDisable() { public void onDisable() {

View File

@ -14,16 +14,16 @@ public class Task implements Runnable {
public void run() { public void run() {
try { try {
Bukkit.getServer().getWorlds().forEach(w -> { Bukkit.getServer().getWorlds().forEach(w -> {
if (w.getTime() >= 12516 && w.getTime() <= 12537 && config.getBoolean("features.title")) w.getPlayers().forEach(p -> { if (w.getTime() >= 12516 && w.getTime() <= 12535 && config.getBoolean("messages.title.title")) w.getPlayers().forEach(p -> {
util.sendTitle(p, config.getString("messages.title.evening.top"), config.getString("messages.title.evening.bottom")); util.sendTitle(p, config.getString("messages.title.evening.top"), config.getString("messages.title.evening.bottom"));
}); });
if (util.getSleeping(w) > 0 && util.getNeeded(w) == 0) { if (util.getSleeping(w) > 0 && util.getNeeded(w) == 0 && !Util.skipping) {
util.skip(w); util.skip(w);
} }
if (util.getSleeping(w) > 0 && util.getSleeping(w) < w.getPlayers().size()) {w.getPlayers().forEach(p -> {util.sendActionbar(p, config.getString("messages.actionbar.sleeping"), w);});} if (util.getSleeping(w) > 0 && util.getSleeping(w) < util.getNeeded(w)) {w.getPlayers().forEach(p -> {util.sendActionbar(p, config.getString("messages.actionbar.sleeping"), w);});}
else if (util.getSleeping(w) == util.getNeeded(w)) {w.getPlayers().forEach(p -> {util.sendActionbar(p, config.getString("messages.actionbar.everyone"), w);});} else if (util.getSleeping(w) == util.getNeeded(w) && util.getSleeping(w) > 0) {w.getPlayers().forEach(p -> {util.sendActionbar(p, config.getString("messages.actionbar.everyone"), w);});}
w.getPlayers().forEach(p -> { if (config.getBoolean("features.afk")) w.getPlayers().forEach(p -> {
if (TimeUnit.MILLISECONDS.toMinutes(System.currentTimeMillis() - Util.activity.get(p)) >= config.getInteger("values.timeout")) { if (TimeUnit.MILLISECONDS.toMinutes(System.currentTimeMillis() - Util.activity.get(p)) >= config.getInteger("values.timeout")) {
if (Util.sleeping.get(w).contains(p)) { if (Util.sleeping.get(w).contains(p)) {
Util.activity.put(p, System.currentTimeMillis()); Util.activity.put(p, System.currentTimeMillis());
@ -32,7 +32,7 @@ public class Task implements Runnable {
if (!Util.afk.contains(p)) { if (!Util.afk.contains(p)) {
Util.afk.add(p); Util.afk.add(p);
p.setPlayerListName(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.afkprefix") + p.getName())); p.setPlayerListName(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.afkprefix") + p.getName()));
Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.chat.afk") if (config.getString("messages.chat.afk").length() > 0) Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.chat.afk")
.replace("[player]", p.getName()))); .replace("[player]", p.getName())));
} }
} }

View File

@ -53,7 +53,7 @@ public class Updater {
return false; return false;
} }
else if (!releases.contains(util.version)) { else if (!releases.contains(util.version)) {
if (config.getBoolean("features.notifier")) c.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix")) + "You have a version of Harbor that is newer than the latest available version. Great work!"); if (config.getBoolean("features.notifier")) c.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix")) + "Running an unreleased version of Harbor.");
return false; return false;
} }
else { else {

View File

@ -32,6 +32,8 @@ public class Util {
public final String version = "1.5"; public final String version = "1.5";
public static boolean enabled = true; public static boolean enabled = true;
public static boolean debug = false; public static boolean debug = false;
public static boolean unreleased = true;
public static boolean skipping = false;
private static NMS nms; private static NMS nms;
Config config = new Config(); Config config = new Config();
@ -100,6 +102,7 @@ public class Util {
*/ */
public int getNeeded(World w) { public int getNeeded(World w) {
try {return Math.max(0, (int) Math.ceil((w.getPlayers().size() - getExcluded(w).size()) * (config.getDouble("values.percent") / 100) - this.getSleeping(w)));} try {return Math.max(0, (int) Math.ceil((w.getPlayers().size() - getExcluded(w).size()) * (config.getDouble("values.percent") / 100) - this.getSleeping(w)));}
//try {return Math.max(0, (int) Math.ceil((w.getPlayers().size()) * (config.getDouble("values.percent") / 100) - this.getSleeping(w)));}
catch (NullPointerException e) {return 0;} catch (NullPointerException e) {return 0;}
} }
@ -129,7 +132,7 @@ public class Util {
* @param player Target player * @param player Target player
*/ */
public boolean isExcluded(Player p) { public boolean isExcluded(Player p) {
boolean state = true; boolean state = false;
if (config.getBoolean("features.ignore")) if (p.getGameMode() == GameMode.SURVIVAL) state = false; else state = true; if (config.getBoolean("features.ignore")) if (p.getGameMode() == GameMode.SURVIVAL) state = false; else state = true;
if (config.getBoolean("features.bypass")) if (p.hasPermission("harbor.bypass")) state = true; else state = false; if (config.getBoolean("features.bypass")) if (p.hasPermission("harbor.bypass")) state = true; else state = false;
if (afk.contains(p)) state = true; if (afk.contains(p)) state = true;
@ -142,7 +145,7 @@ public class Util {
* @param message Actionbar message with color codes * @param message Actionbar message with color codes
*/ */
public void sendActionbar(Player player, String message) { public void sendActionbar(Player player, String message) {
nms.sendActionbar(player, message); if (config.getBoolean("messages.actionbar.actionbar")) nms.sendActionbar(player, message);
} }
/** /**
@ -153,7 +156,7 @@ public class Util {
* @param world World to fetch information for * @param world World to fetch information for
*/ */
public void sendActionbar(Player p, String message, World w) { public void sendActionbar(Player p, String message, World w) {
nms.sendActionbar(p, message if (config.getBoolean("messages.actionbar.actionbar")) nms.sendActionbar(p, message
.replace("[sleeping]", String.valueOf(this.getSleeping(w))) .replace("[sleeping]", String.valueOf(this.getSleeping(w)))
.replace("[online]", String.valueOf(this.getOnline(w))) .replace("[online]", String.valueOf(this.getOnline(w)))
.replace("[needed]", String.valueOf(this.getNeeded(w)))); .replace("[needed]", String.valueOf(this.getNeeded(w))));
@ -192,26 +195,37 @@ public class Util {
*/ */
public void skip(World w) { public void skip(World w) {
if (config.getBoolean("features.skip") && Math.max(0, this.getNeeded(w) - this.getExcluded(w).size()) == 0) { if (config.getBoolean("features.skip") && Math.max(0, this.getNeeded(w) - this.getExcluded(w).size()) == 0) {
w.setTime(1000L); skipping = true;
new java.util.Timer().schedule (
new java.util.TimerTask() {
@Override
public void run() {
w.setTime(1000L);
// Set weather to clear // Set weather to clear
if (config.getBoolean("features.weather")) { if (config.getBoolean("features.weather")) {
w.setStorm(false); w.setStorm(false);
w.setThundering(false); w.setThundering(false);
} }
// Display messages // Display messages
if (config.getBoolean("messages.chat.chat") && (config.getString("messages.chat.skipped").length() != 0)) { if (config.getBoolean("messages.chat.chat") && (config.getString("messages.chat.skipped").length() != 0)) {
List<String> msgs = config.getList("messages.chat.skipped"); List<String> msgs = config.getList("messages.chat.skipped");
Random r = new Random(); Random r = new Random();
int n = r.nextInt(msgs.size()); int n = r.nextInt(msgs.size());
Bukkit.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', msgs.get(n))); Bukkit.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', msgs.get(n)));
} }
if (config.getBoolean("features.title")) { if (config.getBoolean("messages.title.title")) {
w.getPlayers().forEach(p -> { w.getPlayers().forEach(p -> {
this.sendTitle(p, config.getString("messages.title.morning.top"), config.getString("messages.title.morning.bottom")); sendTitle(p, config.getString("messages.title.morning.top"), config.getString("messages.title.morning.bottom"));
}); });
} }
skipping = false;
}
},
1000 * config.getInteger("values.delay")
);
} }
} }
@ -223,7 +237,7 @@ public class Util {
if (afk.contains(p)) { if (afk.contains(p)) {
afk.remove(p); afk.remove(p);
p.setPlayerListName(ChatColor.translateAlternateColorCodes('&', p.getName())); p.setPlayerListName(ChatColor.translateAlternateColorCodes('&', p.getName()));
Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.chat.unafk").replace("[player]", p.getName()))); if (config.getString("messages.chat.unafk").length() > 0) Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.chat.unafk").replace("[player]", p.getName())));
} }
activity.put(p, System.currentTimeMillis()); activity.put(p, System.currentTimeMillis());
} }