mirror of
https://github.com/nkomarn/harbor.git
synced 2024-12-24 01:07:34 +01:00
🥇 Release candidate!
This commit is contained in:
parent
eeb98044ad
commit
510fd352c6
@ -51,7 +51,6 @@ public class HarborCommand implements CommandExecutor {
|
|||||||
boolean updateAvailable;
|
boolean updateAvailable;
|
||||||
try {
|
try {
|
||||||
updateAvailable = Updater.check().get();
|
updateAvailable = Updater.check().get();
|
||||||
System.out.println(updateAvailable);
|
|
||||||
} catch (ExecutionException | InterruptedException e) {
|
} catch (ExecutionException | InterruptedException e) {
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', prefix + "&7Failed to check for a "
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', prefix + "&7Failed to check for a "
|
||||||
+ "new update. Check console for full log."));
|
+ "new update. Check console for full log."));
|
||||||
|
@ -1,40 +1,41 @@
|
|||||||
package xyz.nkomarn.Harbor.listener;
|
package xyz.nkomarn.Harbor.listener;
|
||||||
|
|
||||||
import org.bukkit.World;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
|
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||||
|
import net.md_5.bungee.api.chat.HoverEvent;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerBedEnterEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerBedLeaveEvent;
|
import xyz.nkomarn.Harbor.util.Config;
|
||||||
import xyz.nkomarn.Harbor.task.Checker;
|
import xyz.nkomarn.Harbor.util.Updater;
|
||||||
import xyz.nkomarn.Harbor.util.Messages;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
public class PlayerListener implements Listener {
|
public class PlayerListener implements Listener {
|
||||||
|
|
||||||
// TODO Not sure if I will include this in final release
|
@EventHandler
|
||||||
|
public void onJoin(PlayerJoinEvent e) {
|
||||||
|
if (!e.getPlayer().hasPermission("harbor.admin") || !Config.getBoolean("features.notifier")) return;
|
||||||
|
|
||||||
/*@EventHandler(priority = EventPriority.HIGH)
|
// Check for updates
|
||||||
public void onBedEnter(final PlayerBedEnterEvent event) {
|
boolean updateAvailable = false;
|
||||||
if (event.getBedEnterResult() != PlayerBedEnterEvent.BedEnterResult.OK) {
|
try {
|
||||||
return;
|
updateAvailable = Updater.check().get();
|
||||||
|
} catch (InterruptedException | ExecutionException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean success = false; // 1.13 API change makes this necessary
|
if (updateAvailable) {
|
||||||
try {if (event.getBedEnterResult() == PlayerBedEnterEvent.BedEnterResult.OK) success = true;}
|
TextComponent updateMessage = new TextComponent(ChatColor.translateAlternateColorCodes('&',
|
||||||
catch (NoSuchMethodError nme) {success = true;}
|
Config.getString("messages.miscellaneous.prefix")
|
||||||
|
+ "&7Hey there, Harbor " + Updater.latest + " is now out!"
|
||||||
if (success) {
|
+ " Click this message to upgrade automatically."));
|
||||||
final World world = event.getPlayer().getWorld();
|
updateMessage.setColor(ChatColor.GRAY);
|
||||||
|
updateMessage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||||
|
new ComponentBuilder("§a§l↑ §7Click to update Harbor now!").create()));
|
||||||
|
updateMessage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/harbor update"));
|
||||||
|
e.getPlayer().spigot().sendMessage(updateMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@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, 0)) {
|
|
||||||
Message.sendChatMessage(world, "messages.chat.left", event.getPlayer().getDisplayName(), 0);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package xyz.nkomarn.Harbor.task;
|
package xyz.nkomarn.Harbor.task;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Statistic;
|
import org.bukkit.Statistic;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
@ -10,7 +9,7 @@ import xyz.nkomarn.Harbor.util.Messages;
|
|||||||
public class AccelerateNightTask extends BukkitRunnable {
|
public class AccelerateNightTask extends BukkitRunnable {
|
||||||
private final World world;
|
private final World world;
|
||||||
|
|
||||||
public AccelerateNightTask(final World world) {
|
AccelerateNightTask(final World world) {
|
||||||
this.world = world;
|
this.world = world;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,21 +31,16 @@ public class Checker implements Runnable {
|
|||||||
final int sleeping = getSleeping(world).size();
|
final int sleeping = getSleeping(world).size();
|
||||||
final int needed = getNeeded(world);
|
final int needed = getNeeded(world);
|
||||||
|
|
||||||
// Send actionbar/bossbar sleeping notification
|
// Send actionbar sleeping notification
|
||||||
if (sleeping > 0 && needed > 0) {
|
if (sleeping > 0 && needed > 0) {
|
||||||
if (Config.getBoolean("messages.actionbar.actionbar")) {
|
world.getPlayers().forEach(player -> Messages.sendActionBarMessage(player,
|
||||||
world.getPlayers().forEach(player -> Messages.sendActionBarMessage(player,
|
Config.getString("messages.actionbar.sleeping")));
|
||||||
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) {
|
} else if (needed == 0 && sleeping > 0) {
|
||||||
world.getPlayers().forEach(player -> Messages.sendActionBarMessage(player,
|
world.getPlayers().forEach(player -> Messages.sendActionBarMessage(player,
|
||||||
Config.getString("messages.actionbar.everyone")));
|
Config.getString("messages.actionbar.everyone")));
|
||||||
skippingWorlds.add(world);
|
skippingWorlds.add(world);
|
||||||
new AccelerateNightTask(world).runTaskTimer(Harbor.instance, 0L, 1);
|
new AccelerateNightTask(world).runTaskTimer(Harbor.instance, 0L, 1);
|
||||||
|
Messages.sendRandomChatMessage(world, "messages.chat.accelerateNight");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,12 +2,8 @@ package xyz.nkomarn.Harbor.util;
|
|||||||
|
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.World;
|
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 org.bukkit.entity.Player;
|
||||||
import xyz.nkomarn.Harbor.task.Checker;
|
import xyz.nkomarn.Harbor.task.Checker;
|
||||||
|
|
||||||
@ -23,33 +19,17 @@ public class Messages {
|
|||||||
sendWorldChatMessage(world, messages.get(index));
|
sendWorldChatMessage(world, messages.get(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void sendPlayerChatMessage(final Player player, final String message) {
|
|
||||||
if (message.length() < 1) return;
|
|
||||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void sendWorldChatMessage(final World world, final String message) {
|
private static void sendWorldChatMessage(final World world, final String message) {
|
||||||
if (message.length() < 1) return;
|
if (!Config.getBoolean("messages.chat.chat") || message.length() < 1) return;
|
||||||
world.getPlayers().forEach(player -> player.sendMessage(ChatColor.translateAlternateColorCodes('&', message)));
|
world.getPlayers().forEach(player -> player.sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||||
|
prepareMessage(world, message))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendActionBarMessage(final Player player, final String message) {
|
public static void sendActionBarMessage(final Player player, final String message) {
|
||||||
final World world = player.getWorld();
|
final World world = player.getWorld();
|
||||||
if (message.length() < 1) return;
|
if (!Config.getBoolean("messages.actionbar.actionbar") || message.length() < 1) return;
|
||||||
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(
|
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(
|
||||||
ChatColor.translateAlternateColorCodes('&', message
|
prepareMessage(world, 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))))));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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) {
|
private static String prepareMessage(final World world, final String message) {
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
package xyz.nkomarn.Harbor.util;
|
package xyz.nkomarn.Harbor.util;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import xyz.nkomarn.Harbor.Harbor;
|
import xyz.nkomarn.Harbor.Harbor;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
@ -32,7 +29,6 @@ public class Updater {
|
|||||||
InputStream inputStream = request.getInputStream();
|
InputStream inputStream = request.getInputStream();
|
||||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
|
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
|
||||||
latest = bufferedReader.lines().collect(Collectors.joining(System.lineSeparator()));
|
latest = bufferedReader.lines().collect(Collectors.joining(System.lineSeparator()));
|
||||||
System.out.println(latest); // TODO REMOVE
|
|
||||||
future.complete(!Harbor.version.equals(latest));
|
future.complete(!Harbor.version.equals(latest));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
future.complete(false);
|
future.complete(false);
|
||||||
@ -53,10 +49,9 @@ public class Updater {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
URL downloadURL = new URL("http://aqua.api.spiget.org/v2/resources/60088/download");
|
URL downloadURL = new URL("http://aqua.api.spiget.org/v2/resources/60088/download");
|
||||||
// TODO File jarFile = new File("plugins" + File.separator + jarName);
|
|
||||||
File updatedJarFile = new File("plugins" + File.separator + "update"
|
File updatedJarFile = new File("plugins" + File.separator + "update"
|
||||||
+ File.separator + jarName);
|
+ File.separator + jarName);
|
||||||
updatedJarFile.mkdirs();
|
updatedJarFile.mkdirs(); // TODO don't ignore result
|
||||||
InputStream inputStream = downloadURL.openStream();
|
InputStream inputStream = downloadURL.openStream();
|
||||||
Files.copy(inputStream, Paths.get(updatedJarFile.toURI()), StandardCopyOption.REPLACE_EXISTING);
|
Files.copy(inputStream, Paths.get(updatedJarFile.toURI()), StandardCopyOption.REPLACE_EXISTING);
|
||||||
future.complete("Updated Harbor. Changes will take effect after a server reload/reboot.");
|
future.complete("Updated Harbor. Changes will take effect after a server reload/reboot.");
|
||||||
@ -67,43 +62,4 @@ public class Updater {
|
|||||||
});
|
});
|
||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actually update the Harbor JAR
|
|
||||||
/*public static boolean upgrade() {
|
|
||||||
Harbor.instance.getLogger().log(Level.INFO, "Downloading Harbor version " + latest + ".");
|
|
||||||
|
|
||||||
try {
|
|
||||||
String jar = new File(Updater.class.getProtectionDomain().getCodeSource()
|
|
||||||
.getLocation().getPath()).getName();
|
|
||||||
|
|
||||||
URL url = new URL("http://aqua.api.spiget.org/v2/resources/60088/download");
|
|
||||||
File jarFile = new File("plugins" + File.separator + jar);
|
|
||||||
InputStream inputStream = url.openStream();
|
|
||||||
|
|
||||||
// If Plugman is loaded, hot reload the plugin
|
|
||||||
if (Bukkit.getServer().getPluginManager().isPluginEnabled("PlugMan")) {
|
|
||||||
Bukkit.getServer().broadcastMessage("Using plugman");
|
|
||||||
Files.copy(inputStream, Paths.get(jarFile.toURI()), StandardCopyOption.REPLACE_EXISTING);
|
|
||||||
|
|
||||||
Bukkit.getServer().broadcastMessage("Boom done and updated");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unload plugin and copy new JAR
|
|
||||||
//Bukkit.getServer().getPluginManager().disablePlugin(Harbor.instance);
|
|
||||||
//URLClassLoader classLoader = (URLClassLoader) Harbor.instance.getClass().getClassLoader();
|
|
||||||
//classLoader.close();
|
|
||||||
//System.gc();
|
|
||||||
|
|
||||||
//Files.copy(inputStream, Paths.get(jarFile.toURI()), StandardCopyOption.REPLACE_EXISTING);
|
|
||||||
|
|
||||||
// Load the new version
|
|
||||||
//Bukkit.getServer().getPluginManager().loadPlugin(jarFile);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -31,15 +31,13 @@ messages:
|
|||||||
- "&eArghh, it's so bright outside."
|
- "&eArghh, it's so bright outside."
|
||||||
sleeping: "&e[player] is now sleeping ([sleeping]/[needed], [more] more needed to skip)." # Display which player went to 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
|
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.
|
accelerateNight: # Display when the night is being accelerated.
|
||||||
|
- "&eAccelerating the night."
|
||||||
|
- "&eRapidly approaching daytime."
|
||||||
actionbar:
|
actionbar:
|
||||||
actionbar: true # Enable/disable actionbar 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
|
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
|
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:
|
miscellaneous:
|
||||||
prefix: "&8&l(&6&lHarbor&8&l)&r " # Prefix for Harbor command/miscellaneous messages
|
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
|
permission: "&7Insufficient permissions." # Sent when player doesn't have permissions to run command
|
||||||
@ -49,9 +47,6 @@ blacklist: # Blacklist for worlds (Harbor will be disabled in these worlds)
|
|||||||
- "world_nether"
|
- "world_nether"
|
||||||
- "world_the_end"
|
- "world_the_end"
|
||||||
|
|
||||||
gui:
|
|
||||||
sleeping: "Sleeping Players | Page [page]" # Title for menu that shows when a player executes /sleeping
|
|
||||||
|
|
||||||
# Spooky controls (don't change)
|
# Spooky controls (don't change)
|
||||||
version: 1.6
|
version: 1.6
|
||||||
debug: false
|
debug: false
|
||||||
|
@ -11,9 +11,6 @@ commands:
|
|||||||
harbor:
|
harbor:
|
||||||
description: "Base command for Harbor!"
|
description: "Base command for Harbor!"
|
||||||
usage: "/harbor {subcommand}"
|
usage: "/harbor {subcommand}"
|
||||||
sleeping:
|
|
||||||
description: "Display a list of the currently sleeping players."
|
|
||||||
usage: "/sleeping"
|
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
harbor.bypass:
|
harbor.bypass:
|
||||||
|
Loading…
Reference in New Issue
Block a user