mirror of
https://github.com/nkomarn/harbor.git
synced 2025-03-11 06:00:51 +01:00
Hopefully fix messages
This commit is contained in:
parent
1ae113328d
commit
ca00415213
@ -1,23 +1,24 @@
|
||||
package xyz.nkomarn.Harbor.command;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import xyz.nkomarn.Harbor.Harbor;
|
||||
import xyz.nkomarn.Harbor.util.Updater;
|
||||
|
||||
public class HarborCommand implements CommandExecutor {
|
||||
|
||||
int changeTimeTask = 0;
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final CommandSender commandSender, final Command command, final String s, final String[] strings) {
|
||||
final Player player = (Player) commandSender;
|
||||
final World world = player.getWorld();
|
||||
|
||||
//Updater.check();
|
||||
//Updater.upgrade();
|
||||
|
||||
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")) {
|
||||
Harbor.instance.reloadConfig();
|
||||
sender.sendMessage("§1[Harbor]: §2 Reloaded");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void checkForUpdate() {
|
||||
Updater.check();
|
||||
Updater.upgrade();
|
||||
}
|
||||
}
|
||||
|
@ -17,21 +17,23 @@ public class PlayerListener implements Listener {
|
||||
return;
|
||||
}
|
||||
final World world = event.getPlayer().getWorld();
|
||||
if (morePlayerNeeded(world)) {
|
||||
Message.SendChatMessage(world, "messages.chat.sleeping");
|
||||
Message.SendActionbarMessage(world, "messages.actionbar.sleeping");
|
||||
if (morePlayerNeeded(world, 1)) {
|
||||
Message.SendChatMessage(world, "messages.chat.sleeping", event.getPlayer().getDisplayName(), 1);
|
||||
Message.SendActionbarMessage(world, "messages.actionbar.sleeping", event.getPlayer().getDisplayName(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onBedLeave(final PlayerBedLeaveEvent event) {
|
||||
final World world = event.getPlayer().getWorld();
|
||||
if (Checker.isNight(world) && !Checker.skippingWorlds.contains(world) && morePlayerNeeded(world)) {
|
||||
Message.SendChatMessage(world, "messages.chat.left");
|
||||
if (Checker.isNight(world) && !Checker.skippingWorlds.contains(world) && morePlayerNeeded(world, 0)) {
|
||||
Message.SendChatMessage(world, "messages.chat.left", event.getPlayer().getDisplayName(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean morePlayerNeeded(final World world) {
|
||||
return Checker.getSleeping(world) > 0 && Checker.getNeeded(world) > 0;
|
||||
private boolean morePlayerNeeded(final World world, final int change) {
|
||||
final int sleeping = Checker.getSleeping(world) + change;
|
||||
final int needed = Checker.getNeeded(world) - change;
|
||||
return sleeping > 0 && needed > 0;
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ public class Checker implements Runnable {
|
||||
}
|
||||
|
||||
public static int getSleeping(final World world) {
|
||||
return (int) world.getPlayers().stream().filter(Player::isSleeping).count();
|
||||
return world.getPlayers().stream().filter(Player::isSleeping).collect(toList()).size();
|
||||
}
|
||||
|
||||
public static int getNeeded(final World world) {
|
||||
|
@ -12,13 +12,13 @@ import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class Message {
|
||||
public static void SendChatMessage(final World world, final String messageLocation) {
|
||||
sendChatMessage(prepareMessageWithParams(Config.getString(messageLocation), world));
|
||||
public static void SendChatMessage(final World world, final String messageLocation, final String playerName, final int change) {
|
||||
sendChatMessage(prepareMessageWithParams(Config.getString(messageLocation), world, playerName, change));
|
||||
}
|
||||
|
||||
public static void SendActionbarMessage(final World world, final String messageLocation) {
|
||||
public static void SendActionbarMessage(final World world, final String messageLocation, final String playerName, final int change) {
|
||||
if (Config.getBoolean("messages.actionbar.actionbar")) {
|
||||
final String message = prepareMessageWithParams(Config.getString(messageLocation), world);
|
||||
final String message = prepareMessageWithParams(Config.getString(messageLocation), world, playerName, change);
|
||||
world.getPlayers().forEach(p -> sendActionbarMessage(p, message));
|
||||
}
|
||||
}
|
||||
@ -43,11 +43,11 @@ public class Message {
|
||||
return (int) Math.ceil(Checker.getPlayers(world) * (Config.getDouble("values.percent") / 100));
|
||||
}
|
||||
|
||||
private static String prepareMessageWithParams(final String message, final World world) {
|
||||
private static String prepareMessageWithParams(final String message, final World world, final String playerName, final int change) {
|
||||
return ChatColor.translateAlternateColorCodes('&', message
|
||||
.replace("[sleeping]", String.valueOf(Checker.getSleeping(world)))
|
||||
.replace("[players]", String.valueOf(world.getPlayers().size()))
|
||||
.replace("[sleeping]", String.valueOf(Checker.getSleeping(world) + change))
|
||||
.replace("[needed]", String.valueOf(getSkipAmount(world)))
|
||||
.replace("[more]", String.valueOf(Checker.getNeeded(world))));
|
||||
.replace("[more]", String.valueOf(Checker.getNeeded(world) - change))
|
||||
.replace("[player]", playerName));
|
||||
}
|
||||
}
|
||||
|
@ -28,8 +28,8 @@ messages:
|
||||
- "&eThe night has been skipped."
|
||||
- "&eAhhh, finally morning."
|
||||
- "&eArghh, it's so bright outside."
|
||||
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
|
||||
sleeping: "&e[player] is now sleeping ([sleeping]/[needed], [more] more needed to skip)." # Display which player went to bed
|
||||
left: "&e[player] got out of bed ([sleeping]/[needed], [more] more needed to skip)." # Display when a player left their bed
|
||||
accelerateNight: "Harbor - Accelerating time." # Display when the night get accelerated.
|
||||
actionbar:
|
||||
actionbar: true # Enable/disable actionbar messages
|
||||
|
Loading…
Reference in New Issue
Block a user