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

⚙ Starting to clean things up

This commit is contained in:
Mykyta 2019-10-10 07:06:45 -07:00
parent e525fca31c
commit 021ea69d73
No known key found for this signature in database
GPG Key ID: C147E30C19EA3570
7 changed files with 20 additions and 28 deletions

View File

@ -27,7 +27,7 @@ public class Harbor extends JavaPlugin {
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
// bStats
final Metrics metrics = new Metrics(this);
new Metrics(this);
// Essentials hook
essentials = (Essentials) Bukkit.getServer().getPluginManager().getPlugin("Essentials");

View File

@ -11,17 +11,21 @@ import xyz.nkomarn.Harbor.util.Messages;
public class PlayerListener implements Listener {
// Removed for testing
// Not sure if I will include this in final release
/*@EventHandler(priority = EventPriority.HIGH)
public void onBedEnter(final PlayerBedEnterEvent event) {
if (event.getBedEnterResult() != PlayerBedEnterEvent.BedEnterResult.OK) {
return;
}
final World world = event.getPlayer().getWorld();
if (morePlayerNeeded(world, 1)) {
Message.sendChatMessage(world, "messages.chat.sleeping", event.getPlayer().getDisplayName(), 1);
Message.sendActionbarMessage(world, "messages.actionbar.sleeping", event.getPlayer().getDisplayName(), 0);
boolean success = false; // 1.13 API change makes this necessary
try {if (event.getBedEnterResult() == PlayerBedEnterEvent.BedEnterResult.OK) success = true;}
catch (NoSuchMethodError nme) {success = true;}
if (success) {
final World world = event.getPlayer().getWorld();
}
}
@ -31,12 +35,6 @@ public class PlayerListener implements Listener {
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, final int change) {
final int sleeping = Checker.getSleeping(world) + change;
final int needed = Checker.getNeeded(world) - change;
return sleeping > 0 && needed > 0;
}*/
}

View File

@ -1,6 +1,5 @@
package xyz.nkomarn.Harbor.task;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Statistic;
import org.bukkit.World;
@ -24,8 +23,7 @@ public class AccelerateNightTask extends BukkitRunnable {
ChatColor.GREEN + "Current world time: " + time));
} else {
// Announce night skip and clear queue
Bukkit.getServer().broadcastMessage("Harbor - skipped");
// Message.sendRandomChatMessage(world, "messages.chat.skipped");
Messages.sendRandomChatMessage(world, "messages.chat.skipped");
Checker.skippingWorlds.remove(world);
// Reset sleep statistic if phantoms are disabled

View File

@ -38,12 +38,8 @@ public class Checker implements Runnable {
} else if (needed == 0 && sleeping > 0) {
world.getPlayers().forEach(player -> Messages.sendActionBarMessage(player,
Config.getString("messages.actionbar.everyone")));
}
// Check if world is applicable for skipping
if (needed == 0 && sleeping > 0) {
skippingWorlds.add(world);
new AccelerateNightTask(world).runTaskTimer(Harbor.instance, 0L, 1);
skippingWorlds.add(world);
new AccelerateNightTask(world).runTaskTimer(Harbor.instance, 0L, 1);
}
}

View File

@ -18,7 +18,7 @@ public class Config {
/**
* Fetches a string from the configuration
* if location is not found, <code>empty String</code> is returned
* if location is not found, <code>empty string</code> is returned
*
* @param location Configuration location of the string
*/

View File

@ -15,13 +15,17 @@ 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());
world.getPlayers().forEach(p -> sendChatMessage(p, messages.get(index)));
sendWorldChatMessage(world, messages.get(index));
}
private static void sendChatMessage(final Player player, final String message) {
private static void sendPlayerChatMessage(final Player player, final String message) {
player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
}
private static void sendWorldChatMessage(final World world, final String message) {
world.getPlayers().forEach(player -> player.sendMessage(ChatColor.translateAlternateColorCodes('&', message)));
}
public static void sendActionBarMessage(final Player player, final String message) {
final World world = player.getWorld();
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(

View File

@ -1,14 +1,10 @@
package xyz.nkomarn.Harbor.util;
import org.bukkit.Bukkit;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.plugin.InvalidDescriptionException;
import org.bukkit.plugin.InvalidPluginException;
import xyz.nkomarn.Harbor.Harbor;
import java.io.*;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLConnection;
import java.nio.file.Files;
import java.nio.file.Paths;