mirror of
https://github.com/nkomarn/harbor.git
synced 2024-12-19 23:08:58 +01:00
Update notifier message on join!
This commit is contained in:
parent
cf4e586677
commit
d2431bd56d
@ -61,7 +61,7 @@ messages:
|
||||
# Shown when a player tries to sleep and sleeping is blocked
|
||||
blocked: "&cSleeping is disabled."
|
||||
miscellaneous:
|
||||
# Prefix for Harbor command messages
|
||||
# Prefix for Harbor command/miscellaneous messages
|
||||
prefix: "&8&l(&6&lHarbor&8&l) "
|
||||
# Display server version in console
|
||||
running: "&7Running on version [version]."
|
||||
@ -72,7 +72,7 @@ messages:
|
||||
reloadError: "&7Error reloading Harbor."
|
||||
# Sent when player doesn't have permissions to run command
|
||||
permission: "&7Insufficient permissions."
|
||||
|
||||
|
||||
# Version identifier (do not change)
|
||||
version: 1.5
|
||||
debug: true
|
||||
|
@ -1,7 +0,0 @@
|
||||
package mykyta.Harbor.Actionbar;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface Actionbar {
|
||||
public void sendActionbar(Player player, String message);
|
||||
}
|
23
src/main/java/mykyta/Harbor/Events/PlayerJoin.java
Normal file
23
src/main/java/mykyta/Harbor/Events/PlayerJoin.java
Normal file
@ -0,0 +1,23 @@
|
||||
package mykyta.Harbor.Events;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
import mykyta.Harbor.Config;
|
||||
import mykyta.Harbor.Updater;
|
||||
import mykyta.Harbor.Util;
|
||||
|
||||
public class PlayerJoin implements Listener {
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Updater updater = new Updater();
|
||||
Config config = new Config();
|
||||
Util util = new Util();
|
||||
|
||||
String json = "[{\"text\":\"[prefix]§7Hey there, Harbor [version] was released! \"},{\"text\":\"§7§oClick §7§ome §7§oto §7§oupdate!\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/harbor update\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"§a§l↑ §7Update Harbor.\"}}]";
|
||||
if (event.getPlayer().isOp() && updater.check()) util.sendJSONMessage(event.getPlayer(), json.replace("[version]", updater.getLatest()).replace("[prefix]", config.getString("messages.miscellaneous.prefix")).replace("&", "§"));
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mykyta.Harbor.Events.BedEnter;
|
||||
import mykyta.Harbor.Events.BedLeave;
|
||||
import mykyta.Harbor.Events.PlayerJoin;
|
||||
|
||||
public class Harbor extends JavaPlugin {
|
||||
private Logger log = Bukkit.getLogger();
|
||||
@ -19,6 +20,7 @@ public class Harbor extends JavaPlugin {
|
||||
saveDefaultConfig();
|
||||
Bukkit.getPluginManager().registerEvents(new BedEnter(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new BedLeave(), this);
|
||||
if (config.getBoolean("features.notifier")) Bukkit.getPluginManager().registerEvents(new PlayerJoin(), this);
|
||||
util.setupNMS();
|
||||
|
||||
// Check for updates
|
||||
|
8
src/main/java/mykyta/Harbor/NMS/NMS.java
Normal file
8
src/main/java/mykyta/Harbor/NMS/NMS.java
Normal file
@ -0,0 +1,8 @@
|
||||
package mykyta.Harbor.NMS;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface NMS {
|
||||
public void sendActionbar(Player player, String message);
|
||||
public void sendJSONMessage(Player player, String json);
|
||||
}
|
@ -1,17 +1,26 @@
|
||||
package mykyta.Harbor.Actionbar;
|
||||
package mykyta.Harbor.NMS;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.minecraft.server.v1_13_R2.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_13_R2.PacketPlayOutChat;
|
||||
import net.minecraft.server.v1_13_R2.PacketPlayOutTitle;
|
||||
import net.minecraft.server.v1_13_R2.IChatBaseComponent.ChatSerializer;
|
||||
|
||||
public class Actionbar_1_13_R2 implements Actionbar {
|
||||
public class NMS_1_13_R2 implements NMS {
|
||||
@Override
|
||||
public void sendActionbar(Player player, String message) {
|
||||
IChatBaseComponent titleComponent = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
|
||||
PacketPlayOutTitle titlePacket = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.ACTIONBAR, titleComponent);
|
||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(titlePacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendJSONMessage(Player player, String json) {
|
||||
IChatBaseComponent component = ChatSerializer.a(json);
|
||||
PacketPlayOutChat packet = new PacketPlayOutChat(component);
|
||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
||||
}
|
||||
}
|
@ -13,6 +13,8 @@ import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
public class Updater {
|
||||
private String latest = "";
|
||||
|
||||
/**
|
||||
* Checks for an update using the Spiget API
|
||||
* @see https://spiget.org/
|
||||
@ -44,32 +46,21 @@ public class Updater {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
System.out.println("Running an outdated version! Latest is " + releases.get(releases.size() - 1));
|
||||
latest = releases.get(releases.size() - 1);
|
||||
System.out.println("Running an outdated version! Latest is " + latest);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
int current = Integer.parseInt(String.valueOf(util.version).replace(".", ""));
|
||||
int latest = releases.get(releases.size() - 1);
|
||||
System.out.println("Current version: " + current);
|
||||
System.out.println("Latest release: " + latest);
|
||||
if (util.version < latest) {
|
||||
System.out.println("Update available! Version " + String.valueOf(latest));
|
||||
return true;
|
||||
}
|
||||
else if (util.version < latest) {
|
||||
System.out.println("Hmm... you're using some sort of time travel technology (your version is newer than the latest release). Welp, at least you don't have updates to worry about any time soon.");
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
System.out.println("Using the latest version.");
|
||||
return false;
|
||||
} */
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.out.println("Failed to check for updates.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the latest version number
|
||||
*/
|
||||
public String getLatest() {
|
||||
return latest;
|
||||
}
|
||||
}
|
@ -8,16 +8,16 @@ import org.bukkit.GameMode;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mykyta.Harbor.Actionbar.Actionbar;
|
||||
import mykyta.Harbor.Actionbar.Actionbar_1_13_R2;
|
||||
import mykyta.Harbor.NMS.NMS;
|
||||
import mykyta.Harbor.NMS.NMS_1_13_R2;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
public class Util {
|
||||
public static HashMap<World, Integer> sleeping = new HashMap<World, Integer>();
|
||||
public String version = "1.5";
|
||||
public String version = "1.4.2";
|
||||
public static boolean debug = false;
|
||||
private Logger log = Bukkit.getLogger();
|
||||
private static Actionbar actionbar;
|
||||
private static NMS nms;
|
||||
Config config = new Config();
|
||||
|
||||
/**
|
||||
@ -33,7 +33,7 @@ public class Util {
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix") + config.getString("messages.miscellaneous.running").replace("[version]", version)));
|
||||
|
||||
if (version.equals("v1_13_R2")) {
|
||||
actionbar = new Actionbar_1_13_R2();
|
||||
nms = new NMS_1_13_R2();
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ public class Util {
|
||||
* @param message Actionbar message with color codes
|
||||
*/
|
||||
public void sendActionbar(Player player, String message) {
|
||||
actionbar.sendActionbar(player, message);
|
||||
nms.sendActionbar(player, message);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -88,7 +88,7 @@ public class Util {
|
||||
*/
|
||||
public void sendActionbar(Player player, String message, World world) {
|
||||
Config config = new Config();
|
||||
actionbar.sendActionbar(player, message
|
||||
nms.sendActionbar(player, message
|
||||
.replace("[sleeping]", String.valueOf(sleeping.get(world)))
|
||||
//TODO add bypassers functionaliyt .replace("[online]", String.valueOf(world.getPlayers().size() - bypassers.size()))
|
||||
// .replace("[needed]", String.valueOf(Math.max(0, Math.round(world.getPlayers().size() * Float.parseFloat(plugin.getConfig().getString("values.percent")) - bypassers.size() - ((Integer)worlds.get(world)).intValue())))));
|
||||
@ -96,6 +96,15 @@ public class Util {
|
||||
.replace("[needed]", String.valueOf(Math.max(0, Math.round(world.getPlayers().size() * Float.parseFloat(config.getString("values.percent")) - (sleeping.get(world)).intValue())))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a custom JSON message to selected player
|
||||
* @param player Player to send message to
|
||||
* @param JSON Message in JSON format
|
||||
*/
|
||||
public void sendJSONMessage(Player player, String JSON) {
|
||||
nms.sendJSONMessage(player, JSON);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if player is in survival mode
|
||||
* @param player Target player
|
||||
|
Loading…
Reference in New Issue
Block a user