1
0
mirror of https://github.com/nkomarn/harbor.git synced 2025-03-27 05:49:24 +01:00

📋 Add some more messages back and reformat config

This commit is contained in:
Mykyta 2019-09-19 21:18:45 -07:00
parent 8cb28d96be
commit a2b254afd9
No known key found for this signature in database
GPG Key ID: C147E30C19EA3570
6 changed files with 73 additions and 94 deletions
pom.xml
src/main
java/xyz/nkomarn/Harbor
resources

16
pom.xml
View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>xyz.nkomarn</groupId>
<artifactId>Harbor</artifactId>
<version>1.5.4</version>
<version>1.6</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -20,10 +20,6 @@
<id>ess-repo</id>
<url>https://ci.ender.zone/plugin/repository/everything/</url>
</repository>
<repository>
<id>cavetale-repo</id>
<url>https://cavetale.com/jenkins/plugin/repository/everything/</url>
</repository>
</repositories>
<dependencies>
@ -39,16 +35,6 @@
<version>2.17.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry</artifactId>
<version>1.7.27</version>
</dependency>
<dependency>
<groupId>com.rylinaux</groupId>
<artifactId>PlugMan</artifactId>
<version>2.1.5</version>
</dependency>
</dependencies>
<build>

View File

@ -12,7 +12,6 @@ public class Harbor extends JavaPlugin {
public static Harbor instance;
public static String version = "1.6";
public static boolean debug = false;
public static Essentials essentials;
public void onEnable() {

View File

@ -10,6 +10,8 @@ import xyz.nkomarn.Harbor.util.Config;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
public class Checker implements Runnable {
@ -31,15 +33,12 @@ public class Checker implements Runnable {
// Send actionbar notification
if (getSleeping(world).size() > 0 && getNeeded(world) > 0) {
for (Player player : world.getPlayers()) {
sendActionBar(player, Config.getString("messages.actionbar.sleeping")
.replace("[sleeping]", String.valueOf(sleeping))
.replace("[online]", String.valueOf(world.getPlayers().size()))
.replace("[needed]", String.valueOf(needed)));
sendActionBar(player, Config.getString("messages.actionbar.sleeping"));
}
}
// Check if world is applicable for skipping
if (getNeeded(world) == 0 && getSleeping(world).size() > 0) {
if (Config.getBoolean("features.skip") && getNeeded(world) == 0 && getSleeping(world).size() > 0) {
// Rapidly accelerate time until it's day
skippingWorlds.add(world);
@ -50,8 +49,14 @@ public class Checker implements Runnable {
}
private void sendActionBar(Player player, String message) {
World world = player.getWorld();
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(
ChatColor.translateAlternateColorCodes('&', message)));
ChatColor.translateAlternateColorCodes('&', message
.replace("[sleeping]", String.valueOf(getSleeping(world)))
.replace("[players]", String.valueOf(world.getPlayers().size()))
.replace("[needed]", String.valueOf(getSkipAmount(world)))
.replace("[more]", String.valueOf(getNeeded(world))))));
}
private List<Player> getSleeping(World world) {
@ -62,15 +67,19 @@ public class Checker implements Runnable {
return sleeping;
}
private int getSkipAmount(World world) {
return (int) (getPlayers(world) * (Config.getDouble("values.percent") / 100));
}
private int getPlayers(World world) {
return Math.max(0, world.getPlayers().size() - getExcluded(world).size());
}
private int getNeeded(World world) {
try {
return Math.max(0, (int) Math.ceil((world.getPlayers().size()
- getExcluded(world).size()) * (Config.getDouble("values.percent") / 100)
- getSleeping(world).size()));}
catch (NullPointerException e) {
if (Harbor.debug) e.printStackTrace();
return 0;
}
return Math.max(0, (int) Math.ceil((getPlayers(world))
* (Config.getDouble("values.percent") / 100)
- getSleeping(world).size()));
}
private ArrayList<Player> getExcluded(World w) {
@ -94,6 +103,19 @@ public class Checker implements Runnable {
return s;
}
private String randomMessage(String list) {
List<String> messages = Config.getList(list);
Random random = new Random();
int index = random.nextInt(messages.size());
return ChatColor.translateAlternateColorCodes('&', messages.get(index));
}
private void sendChatMessage(String message) {
if (!Config.getBoolean("messages.chat.chat")) return;
if (message.length() < 1) return;
Bukkit.broadcastMessage(message);
}
private void accelerateNight(World world) {
Bukkit.broadcastMessage("Harbor - Accelerating time.");
@ -106,16 +128,24 @@ public class Checker implements Runnable {
world.setTime(time + 60);
}
else {
Bukkit.broadcastMessage("Harbor - Stopped time change (" + time + ").");
// Announce night skip and clear queue
sendChatMessage("messages.chat.skipped");
skippingWorlds.remove(world);
// Reset sleep statistic if phantoms are disabled TODO move out of here
// Reset sleep statistic if phantoms are disabled
if (!Config.getBoolean("features.phantoms")) {
for (Player player : world.getPlayers()) {
player.setStatistic(Statistic.TIME_SINCE_REST, 0);
}
}
// Clear weather
if (Config.getBoolean("features.weather")) {
world.setStorm(false);
world.setThundering(false);
}
this.cancel();
}
}

View File

@ -12,7 +12,7 @@ public class Config {
* @param e Exception generated from reading configuration
*/
private static void error(Exception e) {
if (Harbor.debug) e.printStackTrace();
e.printStackTrace();
}
/**
@ -24,7 +24,8 @@ public class Config {
return Harbor.instance.getConfig().getBoolean(location);
}
catch (Exception e) {
error(e); return false;
error(e);
return false;
}
}

View File

@ -1,6 +1,5 @@
package xyz.nkomarn.Harbor.util;
import com.rylinaux.plugman.util.PluginUtil;
import org.bukkit.Bukkit;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.plugin.InvalidDescriptionException;
@ -60,10 +59,7 @@ public class Updater {
// If Plugman is loaded, hot reload the plugin
if (Bukkit.getServer().getPluginManager().isPluginEnabled("PlugMan")) {
Bukkit.getServer().broadcastMessage("Using plugman");
PluginUtil.disable(Harbor.instance);
Files.copy(inputStream, Paths.get(jarFile.toURI()), StandardCopyOption.REPLACE_EXISTING);
PluginUtil.load("Harbor");
Bukkit.getServer().broadcastMessage("Boom done and updated");
}

View File

@ -1,9 +1,4 @@
# _
# /\ /\__ _ _ __| |__ ___ _ __
# / /_/ / _` | '__| '_ \ / _ \| '__|
# / __ / (_| | | | |_) | (_) | |
# \/ /_/ \__,_|_| |_.__/ \___/|_|
#
# Harbor - A Sleep Enhancement Plugin!
# An open-source project by Mykyta (TechToolbox)
# https://harbor.nkomarn.xyz
#
@ -14,71 +9,43 @@
# GitHub URL: https://github.com/nkomarn/Harbor/issues
values:
# How often to run the clock task (used to detect sleep, AFK players, time actionbar, etc.)
# Lower this value for relatively slow servers
timer: 2
# Percent of players that need to sleep to skip night (must be between 0 to 100)
percent: 100
timer: 2 # How often to run the clock task (used to detect sleep, AFK players, time actionbar, etc.)
percent: 100 # Percent of players that need to sleep to skip night (must be between 0 to 100)
features:
# Toggle night skipping feature. Configure amount of players needed to skip above (percent)
skip: true
# Clear weather when skipping night
weather: true
# Reset the sleep statistic (practically disables phantom spawns - false = no phantoms)
phantoms: false
# Toggle exclusion of operators/players with permission "harbor.bypass" from sleep count
bypass: true
# Toggle exclusion of players in creative and spectator mode
ignore: true
# Detect AFK players and remove them from the sleep count (Essentials/API used for detection)
afk: true
# Displays a notification when a new update is released
notifier: true
skip: true # Toggle night skipping feature. Configure amount of players needed to skip above (percent)
weather: true # Clear weather when skipping night
phantoms: false # Reset the sleep statistic (practically disables phantom spawns - false = no phantoms)
bypass: true # Toggle exclusion of operators/players with permission "harbor.bypass" from sleep count
ignore: true # Toggle exclusion of players in creative and spectator mode
afk: true # Detect AFK players and remove them from the sleep count (Essentials/API used for detection)
notifier: true # Displays a notification when a new update is released
messages:
chat:
# Toggle chat messages
chat: true
# "Night skipped" chat messages
skipped:
chat: true # Toggle chat messages
skipped: # Night skipped chat messages
- "&eThe night has been skipped."
- "&eAhhh, finally morning."
- "&eArghh, it's so bright outside."
# Display which player went to bed
sleeping: "&e[player] is now sleeping ([sleeping]/[online], [needed] more needed to skip)."
# Display when a player left their bed
left: "&e[player] got out of bed ([sleeping]/[online], [needed] more needed to skip)."
# Sent to player when they sleep with "harbor.bypass" permission
bypass: "&eYou've been excluded from the sleep count."
sleeping: "&e[player] is now sleeping ([sleeping]/[online], [needed] more needed to skip)." # Display which player went to bed
left: "&e[player] got out of bed ([sleeping]/[online], [needed] more needed to skip)." # Display when a player left their bed
actionbar:
# Enable/Disable actionbar message
actionbar: true
# Shown when some players are in bed
sleeping: "&e[sleeping] out of [online] players are sleeping ([needed] more needed to skip)."
# Shown when all players are in bed
everyone: "&eEveryone is sleeping. Sweet dreams!"
actionbar: true # Enable/disable actionbar messages
sleeping: "&e[sleeping] out of [needed] players are sleeping ([more] more needed to skip)." # Shown when some players are in bed
everyone: "&eEveryone is sleeping. Sweet dreams!" # Shown when all players are in bed
miscellaneous:
# Prefix for Harbor command/miscellaneous messages
prefix: "&8&l(&6&lHarbor&8&l)&r "
# Display server version in console
running: "&7Running on version [version]."
# Harbor reload message
reloaded: "&7Reloaded Harbor."
reloaderror: "&7Error reloading Harbor."
# Sent when player doesn't have permissions to run command
permission: "&7Insufficient permissions."
# Sent when command argument isn't recognized
unrecognized: "&7Unrecognized command."
prefix: "&8&l(&6&lHarbor&8&l)&r " # Prefix for Harbor command/miscellaneous messages
permission: "&7Insufficient permissions." # Sent when player doesn't have permissions to run command
unrecognized: "&7Unrecognized command." # Sent when command argument isn't recognized
blacklist:
blacklist: # Blacklist for worlds (Harbor will be disabled in these worlds)
- "world_nether"
- "world_the_end"
gui:
# Title for menu that shows when a player executes /sleeping
sleeping: "Sleeping Players | Page [page]"
sleeping: "Sleeping Players | Page [page]" # Title for menu that shows when a player executes /sleeping
# Spooky controls (don't change)
version: 1.5.4
version: 1.6
debug: false