mirror of
https://github.com/nkomarn/harbor.git
synced 2024-12-19 14:57:38 +01:00
🥇 Release candidate!
This commit is contained in:
parent
eeb98044ad
commit
510fd352c6
@ -51,7 +51,6 @@ public class HarborCommand implements CommandExecutor {
|
||||
boolean updateAvailable;
|
||||
try {
|
||||
updateAvailable = Updater.check().get();
|
||||
System.out.println(updateAvailable);
|
||||
} catch (ExecutionException | InterruptedException e) {
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', prefix + "&7Failed to check for a "
|
||||
+ "new update. Check console for full log."));
|
||||
|
@ -1,40 +1,41 @@
|
||||
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.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerBedEnterEvent;
|
||||
import org.bukkit.event.player.PlayerBedLeaveEvent;
|
||||
import xyz.nkomarn.Harbor.task.Checker;
|
||||
import xyz.nkomarn.Harbor.util.Messages;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import xyz.nkomarn.Harbor.util.Config;
|
||||
import xyz.nkomarn.Harbor.util.Updater;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
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)
|
||||
public void onBedEnter(final PlayerBedEnterEvent event) {
|
||||
if (event.getBedEnterResult() != PlayerBedEnterEvent.BedEnterResult.OK) {
|
||||
return;
|
||||
// Check for updates
|
||||
boolean updateAvailable = false;
|
||||
try {
|
||||
updateAvailable = Updater.check().get();
|
||||
} catch (InterruptedException | ExecutionException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
if (updateAvailable) {
|
||||
TextComponent updateMessage = new TextComponent(ChatColor.translateAlternateColorCodes('&',
|
||||
Config.getString("messages.miscellaneous.prefix")
|
||||
+ "&7Hey there, Harbor " + Updater.latest + " is now out!"
|
||||
+ " Click this message to upgrade automatically."));
|
||||
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;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
@ -10,7 +9,7 @@ import xyz.nkomarn.Harbor.util.Messages;
|
||||
public class AccelerateNightTask extends BukkitRunnable {
|
||||
private final World world;
|
||||
|
||||
public AccelerateNightTask(final World world) {
|
||||
AccelerateNightTask(final World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
|
@ -31,21 +31,16 @@ public class Checker implements Runnable {
|
||||
final int sleeping = getSleeping(world).size();
|
||||
final int needed = getNeeded(world);
|
||||
|
||||
// Send actionbar/bossbar sleeping notification
|
||||
// Send actionbar 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")));
|
||||
}
|
||||
world.getPlayers().forEach(player -> Messages.sendActionBarMessage(player,
|
||||
Config.getString("messages.actionbar.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);
|
||||
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.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;
|
||||
|
||||
@ -23,33 +19,17 @@ public class Messages {
|
||||
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) {
|
||||
if (message.length() < 1) return;
|
||||
world.getPlayers().forEach(player -> player.sendMessage(ChatColor.translateAlternateColorCodes('&', message)));
|
||||
if (!Config.getBoolean("messages.chat.chat") || message.length() < 1) return;
|
||||
world.getPlayers().forEach(player -> player.sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||
prepareMessage(world, message))));
|
||||
}
|
||||
|
||||
public static void sendActionBarMessage(final Player player, final String message) {
|
||||
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(
|
||||
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))))));
|
||||
}
|
||||
|
||||
// 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);
|
||||
prepareMessage(world, message)));
|
||||
}
|
||||
|
||||
private static String prepareMessage(final World world, final String message) {
|
||||
|
@ -1,10 +1,7 @@
|
||||
package xyz.nkomarn.Harbor.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import xyz.nkomarn.Harbor.Harbor;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.file.Files;
|
||||
@ -32,7 +29,6 @@ public class Updater {
|
||||
InputStream inputStream = request.getInputStream();
|
||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
latest = bufferedReader.lines().collect(Collectors.joining(System.lineSeparator()));
|
||||
System.out.println(latest); // TODO REMOVE
|
||||
future.complete(!Harbor.version.equals(latest));
|
||||
} catch (IOException e) {
|
||||
future.complete(false);
|
||||
@ -53,10 +49,9 @@ public class Updater {
|
||||
|
||||
try {
|
||||
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.separator + jarName);
|
||||
updatedJarFile.mkdirs();
|
||||
updatedJarFile.mkdirs(); // TODO don't ignore result
|
||||
InputStream inputStream = downloadURL.openStream();
|
||||
Files.copy(inputStream, Paths.get(updatedJarFile.toURI()), StandardCopyOption.REPLACE_EXISTING);
|
||||
future.complete("Updated Harbor. Changes will take effect after a server reload/reboot.");
|
||||
@ -67,43 +62,4 @@ public class Updater {
|
||||
});
|
||||
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."
|
||||
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.
|
||||
accelerateNight: # Display when the night is being accelerated.
|
||||
- "&eAccelerating the night."
|
||||
- "&eRapidly approaching daytime."
|
||||
actionbar:
|
||||
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
|
||||
@ -49,9 +47,6 @@ blacklist: # Blacklist for worlds (Harbor will be disabled in these worlds)
|
||||
- "world_nether"
|
||||
- "world_the_end"
|
||||
|
||||
gui:
|
||||
sleeping: "Sleeping Players | Page [page]" # Title for menu that shows when a player executes /sleeping
|
||||
|
||||
# Spooky controls (don't change)
|
||||
version: 1.6
|
||||
debug: false
|
||||
|
@ -11,9 +11,6 @@ commands:
|
||||
harbor:
|
||||
description: "Base command for Harbor!"
|
||||
usage: "/harbor {subcommand}"
|
||||
sleeping:
|
||||
description: "Display a list of the currently sleeping players."
|
||||
usage: "/sleeping"
|
||||
|
||||
permissions:
|
||||
harbor.bypass:
|
||||
|
Loading…
Reference in New Issue
Block a user