Skip to content

Commit

Permalink
Small code edit
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyUltra committed Jul 17, 2022
1 parent 08dd3b4 commit 0a63f52
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static void changeMaxPlayers(int maxPlayers) {
Bungee.getInstance().getBungeeMOTDManager().setMaxPlayers(maxPlayers);
}

public static void changeHoverList(List<String> list) {
public static void changeHoverBox(List<String> list) {
Bungee.getInstance().getBungeeMOTDManager().setHoverBox(list);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import me.flyultra.forestMotd.spigot.Spigot;

import java.util.List;

public class SpigotForestMOTDAPI {

public static void reloadData() {
Expand All @@ -20,5 +22,9 @@ public static void changeMaxPlayers(int maxPlayers) {
Spigot.getInstance().getMotdManager().setMaxPlayers(maxPlayers);
}

public static void changeHoverBox(List<String> hoverBox) {
Spigot.getInstance().getMotdManager().setHoverBox(hoverBox);
}


}
7 changes: 5 additions & 2 deletions src/main/java/me/flyultra/forestMotd/bungee/Bungee.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.flyultra.forestMotd.bungee;


import com.tchristofferson.configupdater.ConfigUpdater;
import lombok.SneakyThrows;
import me.flyultra.forestMotd.bungee.command.BungeeMOTDCommand;
import me.flyultra.forestMotd.bungee.controller.BungeeMOTDController;
Expand Down Expand Up @@ -95,9 +96,12 @@ public void listeners() {
public void faviconSetup(String faviconName) {
try {
favicon = Favicon.create(ImageIO.read(new File(faviconName)));
if (favicon == null) {
getLogger().warning("Icon cant be loaded! (Wrong input)");
return;
}
} catch (IOException e) {
e.printStackTrace();
getLogger().warning("Icon cant be loaded! (Wrong input name)");
}
}

Expand All @@ -115,7 +119,6 @@ public void createNewYamlFiles(String... fileNameData) {

for (String fileName : fileNameData) {
File file = new File(Bungee.getInstance().getDataFolder(), fileName + ".yml");

if (!file.exists()) {
try (InputStream in = Bungee.getInstance().getResourceAsStream(fileName + ".yml")) {
Files.copy(in, file.toPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ public BungeeMOTDListener() {
@EventHandler
public void onBungeePing(ProxyPingEvent e) {
ServerPing ping = e.getResponse();
ping.setDescription(Utils.colorizeBungee(bungee.getBungeeMOTDManager().getMotdText().replace(":n:", "\n")));
ping.setDescription(Utils.colorizeBungee(bungee.getBungeeMOTDManager().getMotdText()
.replace(":n:", "\n")
.replace("%online%", String.valueOf(ProxyServer.getInstance().getOnlineCount()))
.replace("%online%", ProxyServer.getInstance().getVersion())
.replace("%configPlayersMax%", String.valueOf(bungee.getBungeeMOTDManager().getMaxPlayers()))
.replace("%defaultMax%", String.valueOf(ProxyServer.getInstance().getConfig().getPlayerLimit()))));
ping.setPlayers(new ServerPing.Players(bungee.getBungeeMOTDManager().getMaxPlayers(), ProxyServer.getInstance().getOnlineCount(), null));
ping.setFavicon(bungee.getFavicon());

Expand All @@ -35,7 +40,12 @@ public ServerPing.PlayerInfo[] getHoverBoxProfiles() {
int l = bungee.getBungeeMOTDManager().getHoverBox().size();
ServerPing.PlayerInfo[] lines = new ServerPing.PlayerInfo[l];
for (int i = 0; i < l; i++) {
lines[i] = new ServerPing.PlayerInfo(Utils.colorizeBungee(bungee.getBungeeMOTDManager().getHoverBox().get(i)), new UUID(0L, 0L));
lines[i] = new ServerPing.PlayerInfo(Utils.colorizeBungee(bungee.getBungeeMOTDManager().getHoverBox().get(i)
.replace(":n:", "\n")
.replace("%online%", String.valueOf(ProxyServer.getInstance().getOnlineCount()))
.replace("%online%", ProxyServer.getInstance().getVersion())
.replace("%configPlayersMax%", String.valueOf(bungee.getBungeeMOTDManager().getMaxPlayers()))
.replace("%defaultMax%", String.valueOf(ProxyServer.getInstance().getConfig().getPlayerLimit()))), new UUID(0L, 0L));
}
return lines;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public void setHoverBox(List<String> hoverBoxL) {

}


public int getMaxPlayers() {
if (maxPlayers == -1) {
return ProxyServer.getInstance().getConfig().getPlayerLimit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import me.flyultra.forestMotd.spigot.Spigot;
import me.flyultra.forestMotd.utils.Utils;
import net.md_5.bungee.api.ProxyServer;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand All @@ -30,14 +31,25 @@ public MOTDListener() {
@EventHandler
public void onPing(ServerListPingEvent e) {

e.setMotd(Utils.colorize(spigot.getMotdManager().getMotdText().replace(":n:", "\n")));
e.setMotd(Utils.colorize(spigot.getMotdManager().getMotdText()
.replace(":n:", "\n")
.replace("%online%", String.valueOf(spigot.getServer().getOnlinePlayers().size()))
.replace("%version%", spigot.getServer().getBukkitVersion())
.replace("%defaultMax%", String.valueOf(spigot.getServer().getMaxPlayers()))
.replace("%configPlayersMax%", String.valueOf(spigot.getMotdManager().getMaxPlayers()))));

e.setMaxPlayers(spigot.getMotdManager().getMaxPlayers());
try {
File icon = new File(spigot.getMotdManager().getIconName());
if (!icon.exists()) {
spigot.getLogger().warning("Icon cant be loaded! (Wrong input)");
return;
}
e.setServerIcon(Bukkit.loadServerIcon(new File(spigot.getMotdManager().getIconName())));
} catch (Exception ex) {
ex.printStackTrace();
}
if (spigot.getMotdManager().getHoverBox().size() != 0) {
if (spigot.getMotdManager().getHoverBox().size() != 0 && Bukkit.getServer().getPluginManager().getPlugin("ProtocolLib") != null) {
List<WrappedGameProfile> lines = getHoverBoxData();
ProtocolManager pm = ProtocolLibrary.getProtocolManager();

Expand All @@ -48,14 +60,20 @@ public void onPacketSending(PacketEvent event) {
event.getPacket().getServerPings().read(0).setPlayers(lines);
}
});
return;
}
}

public List<WrappedGameProfile> getHoverBoxData() {
List<WrappedGameProfile> lines = new ArrayList<WrappedGameProfile>();
for (int i = 0; i < spigot.getMotdManager().getHoverBox().size(); i++) {
lines.add(new WrappedGameProfile(String.valueOf(i), Utils.colorize(spigot.getMotdManager().getHoverBox().get(i))));
lines.add(new WrappedGameProfile(String.valueOf(i), Utils.colorize(spigot.getMotdManager().getHoverBox().get(i)
.replace(":n:", "\n")
.replace("%online%", String.valueOf(spigot.getServer().getOnlinePlayers().size()))
.replace("%version%", spigot.getServer().getBukkitVersion())
.replace("%defaultMax%", String.valueOf(spigot.getServer().getMaxPlayers()))
.replace("%configPlayersMax%", String.valueOf(spigot.getMotdManager().getMaxPlayers())))

));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public void setMotdText(String motdTextS) {
spigot.saveConfig();
}

public void setHoverBox(List<String> hoverBoxL) {
hoverBox = hoverBoxL;
spigot.getConfig().set(ConfigOptions.MOTD_HOVER_BOX, hoverBoxL);
spigot.saveConfig();
}

public int getMaxPlayers() {
if (maxPlayers == -1) {
Expand All @@ -66,6 +71,9 @@ public String getMotdText() {
}

public List<String> getHoverBox() {
if (hoverBox == null || hoverBox.size() == 0) {
spigot.getLogger().warning("Hover box is null!");
}
return hoverBox;
}
}
24 changes: 17 additions & 7 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
#
# ForestMOTD v1.0.1
#
# If you find bug or you have an idea for an adjustment, please contact us on
# | If you find bug or you have an idea for an adjustment, please contact us on
# https://discord.com/invite/2PpdrfxhD4
#
# | %online% - Return number of players on server
# | %defaultMax% - Default server max server player size
# | %version% - Server version
# | %configPlayersMax% - Config player max number
#
# | Permission = forestMOTD.admin
#

#
# MOTD data
# MOTD
#
# Use ":n:" to do second line
# "maxPlayers: -1" This will set default server number
# | Use ":n:" to do second line
# "maxPlayers: -1" - This will set default server number
#
motd:
maxPlayers: 69
iconName: "icon.png"
# | 64x64 size icon
iconName: "server-icon.png"
text: "{#30FF5A>}&lForest{#7DFFC2<}&f&lMOTD:n:&rBest server in the Universe!"
# Only for Bungee :/
#
# | If you want to use hover box on spigot, download ProtocolLib! (5.0.0+)
#
hoverBox:
- "&c❤ &a&lForest&7&lTech &c❤"
- " "
- " &aPlugins with &c❤"
- " "

#
# Messages
# | Messages
#
message:
noPerm: "{#malachite>}&lForest{#bluestone<}&f&lMOTD &7You don't have sufficient permissions..."
Expand Down

0 comments on commit 0a63f52

Please sign in to comment.