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:
parent
5b39d2c920
commit
36d4a6a8bc
22
config.yml
22
config.yml
@ -18,9 +18,11 @@ values:
|
||||
# Lower this value for relatively slow servers
|
||||
clock: 1
|
||||
# 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)
|
||||
timeout: 10
|
||||
timeout: 15
|
||||
# Time to wait before skipping the night (in seconds)
|
||||
delay: 3
|
||||
|
||||
features:
|
||||
# Toggle night skipping feature. Configure amount of players needed to skip above (percent)
|
||||
@ -30,13 +32,13 @@ features:
|
||||
# Toggle the spawning of phantoms
|
||||
phantoms: false
|
||||
# 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
|
||||
ignore: true
|
||||
# Prevent all players from entering a bed
|
||||
block: false
|
||||
# Display a title message in the morning and when going to bed
|
||||
title: true
|
||||
# Detect AFK players and remove them from the sleep count
|
||||
afk: true
|
||||
# Displays a notification when a new update is released
|
||||
notifier: true
|
||||
|
||||
@ -50,13 +52,13 @@ messages:
|
||||
- "&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)."
|
||||
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)."
|
||||
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
|
||||
blocked: "&cSleeping is disabled."
|
||||
# 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
|
||||
afk: "&7[player] has gone 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
|
||||
blocked: "&cSleeping is disabled."
|
||||
title:
|
||||
# Enable/Disable title messages
|
||||
title: true
|
||||
morning:
|
||||
top: "&6Good morning!"
|
||||
bottom: "&7Ah, such wonderful weather."
|
||||
@ -103,4 +107,4 @@ gui:
|
||||
|
||||
# Spooky controls (don't change)
|
||||
version: 1.5
|
||||
debug: true
|
||||
debug: false
|
||||
|
2
pom.xml
2
pom.xml
@ -121,7 +121,7 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<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>
|
||||
<resources>
|
||||
<resource>
|
||||
|
@ -54,12 +54,12 @@ public class BedEnter implements Listener {
|
||||
.replace("[player]", p.getName())
|
||||
.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"));
|
||||
}
|
||||
|
||||
// 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")));
|
||||
}
|
||||
|
@ -14,19 +14,19 @@ public class GUIEvent implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onClick(InventoryClickEvent event) {
|
||||
util.updateActivity((Player) event.getWhoClicked());
|
||||
if (event.getInventory().getHolder() != null && event.getInventory().getHolder() instanceof GUIHolder) {
|
||||
GUIType t = ((GUIHolder) event.getInventory().getHolder()).getType();
|
||||
if (t.equals(GUIType.SLEEPING)) event.setCancelled(true);
|
||||
}
|
||||
util.updateActivity((Player) event.getWhoClicked());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDrag(InventoryDragEvent event) {
|
||||
util.updateActivity((Player) event.getWhoClicked());
|
||||
if (event.getInventory().getHolder() != null && event.getInventory().getHolder() instanceof GUIHolder) {
|
||||
GUIType t = ((GUIHolder) event.getInventory().getHolder()).getType();
|
||||
if (t.equals(GUIType.SLEEPING)) event.setCancelled(true);
|
||||
}
|
||||
util.updateActivity((Player) event.getWhoClicked());
|
||||
}
|
||||
}
|
@ -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 (!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());
|
||||
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."));
|
||||
}
|
||||
}
|
@ -19,7 +19,7 @@ public class PlayerLeave implements Listener {
|
||||
new java.util.TimerTask() {
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
},
|
||||
|
@ -13,7 +13,7 @@ public class GUIHolder implements InventoryHolder {
|
||||
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
return inv; // Required by InvetoryHolder
|
||||
return inv; // Required by InventoryHolder
|
||||
}
|
||||
|
||||
public GUIType getType() {
|
||||
|
@ -53,6 +53,8 @@ public class Harbor extends JavaPlugin {
|
||||
Updater updater = new Updater();
|
||||
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() {
|
||||
|
@ -14,16 +14,16 @@ public class Task implements Runnable {
|
||||
public void run() {
|
||||
try {
|
||||
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"));
|
||||
});
|
||||
if (util.getSleeping(w) > 0 && util.getNeeded(w) == 0) {
|
||||
if (util.getSleeping(w) > 0 && util.getNeeded(w) == 0 && !Util.skipping) {
|
||||
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);});}
|
||||
else if (util.getSleeping(w) == util.getNeeded(w)) {w.getPlayers().forEach(p -> {util.sendActionbar(p, config.getString("messages.actionbar.everyone"), 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) && 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 (Util.sleeping.get(w).contains(p)) {
|
||||
Util.activity.put(p, System.currentTimeMillis());
|
||||
@ -32,7 +32,7 @@ public class Task implements Runnable {
|
||||
if (!Util.afk.contains(p)) {
|
||||
Util.afk.add(p);
|
||||
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())));
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ public class Updater {
|
||||
return false;
|
||||
}
|
||||
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;
|
||||
}
|
||||
else {
|
||||
|
@ -32,6 +32,8 @@ public class Util {
|
||||
public final String version = "1.5";
|
||||
public static boolean enabled = true;
|
||||
public static boolean debug = false;
|
||||
public static boolean unreleased = true;
|
||||
public static boolean skipping = false;
|
||||
private static NMS nms;
|
||||
Config config = new Config();
|
||||
|
||||
@ -100,6 +102,7 @@ public class Util {
|
||||
*/
|
||||
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()) * (config.getDouble("values.percent") / 100) - this.getSleeping(w)));}
|
||||
catch (NullPointerException e) {return 0;}
|
||||
}
|
||||
|
||||
@ -129,7 +132,7 @@ public class Util {
|
||||
* @param player Target player
|
||||
*/
|
||||
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.bypass")) if (p.hasPermission("harbor.bypass")) state = true; else state = false;
|
||||
if (afk.contains(p)) state = true;
|
||||
@ -142,7 +145,7 @@ public class Util {
|
||||
* @param message Actionbar message with color codes
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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("[online]", String.valueOf(this.getOnline(w)))
|
||||
.replace("[needed]", String.valueOf(this.getNeeded(w))));
|
||||
@ -192,6 +195,12 @@ public class Util {
|
||||
*/
|
||||
public void skip(World w) {
|
||||
if (config.getBoolean("features.skip") && Math.max(0, this.getNeeded(w) - this.getExcluded(w).size()) == 0) {
|
||||
skipping = true;
|
||||
|
||||
new java.util.Timer().schedule (
|
||||
new java.util.TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
w.setTime(1000L);
|
||||
|
||||
// Set weather to clear
|
||||
@ -207,11 +216,16 @@ public class Util {
|
||||
int n = r.nextInt(msgs.size());
|
||||
Bukkit.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', msgs.get(n)));
|
||||
}
|
||||
if (config.getBoolean("features.title")) {
|
||||
if (config.getBoolean("messages.title.title")) {
|
||||
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)) {
|
||||
afk.remove(p);
|
||||
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());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user