1
0
mirror of https://github.com/nkomarn/harbor.git synced 2024-12-19 14:57:38 +01:00

🎺 Added back in some of the command functions

This commit is contained in:
Mykyta 2019-11-05 08:05:44 -08:00
parent 021ea69d73
commit 9f06cecd2c
No known key found for this signature in database
GPG Key ID: C147E30C19EA3570
10 changed files with 87 additions and 24 deletions

View File

@ -25,7 +25,7 @@
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<artifactId>spigot</artifactId>
<version>1.14.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

View File

@ -30,6 +30,7 @@ public class Harbor extends JavaPlugin {
new Metrics(this);
// Essentials hook
essentials = (Essentials) Bukkit.getServer().getPluginManager().getPlugin("Essentials");
essentials = (Essentials) Bukkit.getServer().getPluginManager()
.getPlugin("Essentials");
}
}

View File

@ -1,20 +1,52 @@
package xyz.nkomarn.Harbor.command;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import xyz.nkomarn.Harbor.Harbor;
import xyz.nkomarn.Harbor.util.Config;
import xyz.nkomarn.Harbor.util.Updater;
public class HarborCommand implements CommandExecutor {
@Override
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
if (args.length == 1 && "reload".equalsIgnoreCase(args[0]) && sender.hasPermission("harbor.reload")) {
final String prefix = Config.getString("messages.miscellaneous.prefix");
if (args.length < 1) {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', prefix + "&7Harbor version "
+ Harbor.version + " by TechToolbox (@nkomarn)."));
return true;
}
if (!sender.hasPermission("harbor.admin")) {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', prefix
+ Config.getString("messages.miscellaneous.permission")));
return true;
}
else if (args[0].equalsIgnoreCase("reload")) {
Harbor.instance.reloadConfig();
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', prefix
+ "&7Reloaded configuration."));
return true;
}
else if (args[0].equalsIgnoreCase("update")) {
if (Updater.check()) {
// TODO
}
}
// Otherwise, send unrecognized argument messages
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', prefix
+ Config.getString("messages.miscellaneous.unrecognized")));
return true;
/*if (args.length == 1 && "reload".equalsIgnoreCase(args[0]) && sender.hasPermission("harbor.reload")) {
Harbor.instance.reloadConfig();
sender.sendMessage("§1[Harbor]: §2 Reloaded");
}
return true;
}*/
}
private void checkForUpdate() {

View File

@ -11,7 +11,7 @@ import xyz.nkomarn.Harbor.util.Messages;
public class PlayerListener implements Listener {
// Not sure if I will include this in final release
// TODO Not sure if I will include this in final release
/*@EventHandler(priority = EventPriority.HIGH)
public void onBedEnter(final PlayerBedEnterEvent event) {

View File

@ -19,8 +19,6 @@ public class AccelerateNightTask extends BukkitRunnable {
final long time = world.getTime();
if (!(time >= 450 && time <= 1000)) {
world.setTime(time + Config.getInteger("values.interval"));
world.getPlayers().forEach(player -> Messages.sendActionBarMessage(player,
ChatColor.GREEN + "Current world time: " + time));
} else {
// Announce night skip and clear queue
Messages.sendRandomChatMessage(world, "messages.chat.skipped");
@ -28,7 +26,8 @@ public class AccelerateNightTask extends BukkitRunnable {
// Reset sleep statistic if phantoms are disabled
if (!Config.getBoolean("features.phantoms")) {
world.getPlayers().forEach(player -> player.setStatistic(Statistic.TIME_SINCE_REST, 0));
world.getPlayers().forEach(player ->
player.setStatistic(Statistic.TIME_SINCE_REST, 0));
}
// Clear weather

View File

@ -31,15 +31,21 @@ public class Checker implements Runnable {
final int sleeping = getSleeping(world).size();
final int needed = getNeeded(world);
// Send actionbar sleeping notification
if (sleeping > 0 && needed > 0 && Config.getBoolean("messages.actionbar.actionbar")) {
world.getPlayers().forEach(player -> Messages.sendActionBarMessage(player,
Config.getString("messages.actionbar.sleeping")));
// Send actionbar/bossbar sleeping notification
if (sleeping > 0 && needed > 0) {
if (Config.getBoolean("messages.actionbar.actionbar")) {
world.getPlayers().forEach(player -> Messages.sendActionBarMessage(player,
Config.getString("messages.actionbar.sleeping")));
}
if (Config.getBoolean("messages.bossbar.bossbar")) {
world.getPlayers().forEach(player -> Messages.sendBossbar(player,
Config.getString("messages.bossbar.sleeping")));
}
} else if (needed == 0 && sleeping > 0) {
world.getPlayers().forEach(player -> Messages.sendActionBarMessage(player,
Config.getString("messages.actionbar.everyone")));
skippingWorlds.add(world);
new AccelerateNightTask(world).runTaskTimer(Harbor.instance, 0L, 1);
skippingWorlds.add(world);
new AccelerateNightTask(world).runTaskTimer(Harbor.instance, 0L, 1);
}
}
@ -79,7 +85,7 @@ public class Checker implements Runnable {
return world.getPlayers().stream().filter(Checker::isExcluded).collect(toList());
}
public static boolean isExcluded(final Player p) {
private static boolean isExcluded(final Player p) {
final boolean excludedByGameMode = Config.getBoolean("features.ignore") && p.getGameMode() != GameMode.SURVIVAL;
final boolean excludedByPermission = Config.getBoolean("features.bypass") && p.hasPermission("harbor.bypass");
final boolean excludedByAfk = Harbor.essentials != null && Harbor.essentials.getUser(p).isAfk(); // Essentials AFK detection

View File

@ -2,8 +2,12 @@ package xyz.nkomarn.Harbor.util;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarStyle;
import org.bukkit.boss.BossBar;
import org.bukkit.entity.Player;
import xyz.nkomarn.Harbor.task.Checker;
@ -14,7 +18,7 @@ public class Messages {
public static void sendRandomChatMessage(final World world, final String messageList) {
final List<String> messages = Config.getList(messageList);
final int index = new Random().nextInt(messages.size());
final int index = new Random().nextInt(Math.max(0, messages.size()));
sendWorldChatMessage(world, messages.get(index));
}
@ -36,4 +40,19 @@ public class Messages {
.replace("[more]", String.valueOf(Checker.getNeeded(world))))));
}
// TODO redo it the correct way
public static void sendBossbar(final Player player, final String message) {
final World world = player.getWorld();
BossBar bossBar = Bukkit.createBossBar(prepareMessage(world, message), BarColor.BLUE, BarStyle.SOLID);
bossBar.addPlayer(player);
bossBar.setProgress((Checker.getSleeping(world).size() / Checker.getSkipAmount(world)) * 100);
}
private static String prepareMessage(final World world, final String message) {
return ChatColor.translateAlternateColorCodes('&', message
.replace("[sleeping]", String.valueOf(Checker.getSleeping(world).size()))
.replace("[players]", String.valueOf(Checker.getPlayers(world)))
.replace("[needed]", String.valueOf(Checker.getSkipAmount(world)))
.replace("[more]", String.valueOf(Checker.getNeeded(world))));
}
}

View File

@ -29,11 +29,7 @@ public class Updater {
latest = reader.lines().collect(Collectors.joining(System.lineSeparator()));
System.out.println(latest);
if (Harbor.version.equals(latest)) return false;
return true;
return !Harbor.version.equals(latest);
} catch (IOException e) {
e.printStackTrace();
return false;

View File

@ -9,7 +9,7 @@
# GitHub URL: https://github.com/nkomarn/Harbor/issues
values:
timer: 2 # How often to run the clock task (used to detect sleep, AFK players, time actionbar, etc.)
timer: 2 # How often (in seconds) 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)
interval: 60 # Time skip interval that is added when the night get accelerated.
@ -36,6 +36,10 @@ messages:
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
bossbar:
bossbar: true
sleeping: "&f&l[sleeping] out of [needed] players are sleeping." # Shown when some players are in bed
left: "&f&lEveryone is sleeping. Sweet dreams!" # Shown when all players are in bed
miscellaneous:
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

View File

@ -13,4 +13,10 @@ commands:
usage: "/harbor {subcommand}"
sleeping:
description: "Display a list of the currently sleeping players."
usage: "/sleeping"
usage: "/sleeping"
permissions:
harbor.bypass:
default: false
harbor.admin:
default: op