Skip to content

Commit

Permalink
even more and more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperdefined committed Apr 11, 2023
1 parent ce12bab commit 181c3d9
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 70 deletions.
10 changes: 3 additions & 7 deletions hypermotd-paper/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@
<pattern>lol.hyper.githubreleaseapi</pattern>
<shadedPattern>lol.hyper.hypermotd.updater</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.commons.io</pattern>
<shadedPattern>lol.hyper.hypermotd.commonsio</shadedPattern>
</relocation>
<relocation>
<pattern>net.kyori</pattern>
<shadedPattern>lol.hyper.hypermotd.adventure</shadedPattern>
Expand Down Expand Up @@ -112,9 +108,9 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-minimessage</artifactId>
<version>4.13.1</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
14 changes: 10 additions & 4 deletions hypermotd-paper/src/main/java/lol/hyper/hypermotd/MOTDPaper.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.apache.commons.io.FilenameUtils;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
Expand Down Expand Up @@ -79,8 +78,7 @@ public void loadConfig(File file) {
bufferedImage = null;
return;
}
if (!(FilenameUtils.getExtension(iconFile.getName()).equalsIgnoreCase("jpg")
|| FilenameUtils.getExtension(iconFile.getName()).equalsIgnoreCase("png"))) {
if (!checkIcon(iconFile)) {
logger.warning("Unsupported file extension for server icon! You must use either JPG or PNG only.");
bufferedImage = null;
return;
Expand All @@ -98,7 +96,7 @@ public void loadConfig(File file) {
}

public BukkitAudiences getAdventure() {
if(this.adventure == null) {
if (this.adventure == null) {
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
}
return this.adventure;
Expand All @@ -112,4 +110,12 @@ public Component getMessage(String path) {
}
return miniMessage.deserialize(message);
}

private boolean checkIcon(File file) {
String fileName = file.getName();
int dotIndex = fileName.lastIndexOf('.');
String extension = dotIndex > 0 ? fileName.substring(dotIndex + 1) : null;
if (extension == null) return false;
return extension.equalsIgnoreCase("png") || extension.equalsIgnoreCase("jpg");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@

public class CommandReload implements CommandExecutor {

private final MOTDPaper motd;
private final MOTDPaper motdPaper;

public CommandReload(MOTDPaper motd) {
this.motd = motd;
public CommandReload(MOTDPaper motdPaper) {
this.motdPaper = motdPaper;
}

@Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
if (commandSender.hasPermission("hypermotd.reload")) {
motd.loadConfig(motd.configFile);
motd.getAdventure().sender(commandSender).sendMessage(Component.text("Config reloaded!").color(NamedTextColor.GREEN));
motdPaper.loadConfig(motdPaper.configFile);
motdPaper.getAdventure().sender(commandSender).sendMessage(Component.text("Config reloaded!").color(NamedTextColor.GREEN));
} else {
motd.getAdventure().sender(commandSender).sendMessage(Component.text("You do not have permission for this command.").color(NamedTextColor.RED));
motdPaper.getAdventure().sender(commandSender).sendMessage(Component.text("You do not have permission for this command.").color(NamedTextColor.RED));
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,32 @@

public class PingEvent implements Listener {

private final MOTDPaper motd;
private final MOTDPaper motdPaper;

public PingEvent(MOTDPaper motd) {
this.motd = motd;
public PingEvent(MOTDPaper motdPaper) {
this.motdPaper = motdPaper;
}

@EventHandler
public void onPing(PaperServerListPingEvent event) {
if (motd.config.getString("type").equalsIgnoreCase("fixed")) {
Component formattedMOTD = motd.getMessage("fixed-motd");
if (motdPaper.config.getString("type").equalsIgnoreCase("fixed")) {
Component formattedMOTD = motdPaper.getMessage("fixed-motd");
event.motd(formattedMOTD);
}

if (motd.config.getString("type").equalsIgnoreCase("random")) {
if (motdPaper.config.getString("type").equalsIgnoreCase("random")) {
int randomNum = ThreadLocalRandom.current()
.nextInt(0, motd.config.getStringList("random-motd").size());
Component randomMOTD = motd.miniMessage.deserialize(motd.config.getStringList("random-motd").get(randomNum));
.nextInt(0, motdPaper.config.getStringList("random-motd").size());
Component randomMOTD = motdPaper.miniMessage.deserialize(motdPaper.config.getStringList("random-motd").get(randomNum));
event.motd(randomMOTD);
}

if (motd.config.getBoolean("use-custom-icon") && motd.bufferedImage != null) {
if (motdPaper.config.getBoolean("use-custom-icon") && motdPaper.bufferedImage != null) {
CachedServerIcon icon;
try {
icon = Bukkit.loadServerIcon(motd.bufferedImage);
icon = Bukkit.loadServerIcon(motdPaper.bufferedImage);
} catch (Exception exception) {
motd.logger.severe("Unable to load server icon!");
motdPaper.logger.severe("Unable to load server icon!");
exception.printStackTrace();
return;
}
Expand Down
10 changes: 0 additions & 10 deletions hypermotd-velocity/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@
<pattern>lol.hyper.githubreleaseapi</pattern>
<shadedPattern>lol.hyper.hypermotd.updater</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.commons.io</pattern>
<shadedPattern>lol.hyper.hypermotd.commonsio</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
Expand All @@ -105,12 +101,6 @@
<version>3.1.2-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>lol.hyper</groupId>
<artifactId>github-release-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.apache.commons.io.FilenameUtils;
import org.slf4j.Logger;

import javax.imageio.ImageIO;
Expand Down Expand Up @@ -119,8 +118,7 @@ public void loadConfig(File file) {
bufferedImage = null;
return;
}
if (!(FilenameUtils.getExtension(iconFile.getName()).equalsIgnoreCase("jpg")
|| FilenameUtils.getExtension(iconFile.getName()).equalsIgnoreCase("png"))) {
if (!checkIcon(iconFile)) {
logger.warn("Unsupported file extension for server icon! You must use either JPG or PNG only.");
bufferedImage = null;
return;
Expand All @@ -147,4 +145,12 @@ public Component getMessage(String path) {
}
return miniMessage.deserialize(message);
}

private boolean checkIcon(File file) {
String fileName = file.getName();
int dotIndex = fileName.lastIndexOf('.');
String extension = dotIndex > 0 ? fileName.substring(dotIndex + 1) : null;
if (extension == null) return false;
return extension.equalsIgnoreCase("png") || extension.equalsIgnoreCase("jpg");
}
}
10 changes: 0 additions & 10 deletions hypermotd-waterfall/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@
<pattern>lol.hyper.githubreleaseapi</pattern>
<shadedPattern>lol.hyper.hypermotd.updater</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.commons.io</pattern>
<shadedPattern>lol.hyper.hypermotd.commonsio</shadedPattern>
</relocation>
<relocation>
<pattern>net.kyori</pattern>
<shadedPattern>lol.hyper.hypermotd.adventure</shadedPattern>
Expand Down Expand Up @@ -111,12 +107,6 @@
<version>1.19-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-minimessage</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration;
import org.apache.commons.io.FilenameUtils;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
Expand Down Expand Up @@ -100,8 +99,7 @@ public void loadConfig(File file) {
bufferedImage = null;
return;
}
if (!(FilenameUtils.getExtension(iconFile.getName()).equalsIgnoreCase("jpg")
|| FilenameUtils.getExtension(iconFile.getName()).equalsIgnoreCase("png"))) {
if (!checkIcon(iconFile)) {
logger.warning("Unsupported file extension for server icon! You must use either JPG or PNG only.");
bufferedImage = null;
return;
Expand Down Expand Up @@ -134,4 +132,12 @@ public BungeeAudiences getAdventure() {
}
return this.adventure;
}

private boolean checkIcon(File file) {
String fileName = file.getName();
int dotIndex = fileName.lastIndexOf('.');
String extension = dotIndex > 0 ? fileName.substring(dotIndex + 1) : null;
if (extension == null) return false;
return extension.equalsIgnoreCase("png") || extension.equalsIgnoreCase("jpg");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@

public class CommandReload extends Command {

private final MOTDWaterfall motd;
private final MOTDWaterfall motdWaterfall;

public CommandReload(String name, MOTDWaterfall motd) {
public CommandReload(String name, MOTDWaterfall motdWaterfall) {
super(name);
this.motd = motd;
this.motdWaterfall = motdWaterfall;
}

@Override
public void execute(CommandSender sender, String[] args) {
if (sender.hasPermission("hypermotd.reload")) {
motd.loadConfig(motd.configFile);
motd.getAdventure().sender(sender).sendMessage(Component.text("Config reloaded!").color(NamedTextColor.GREEN));
motdWaterfall.loadConfig(motdWaterfall.configFile);
motdWaterfall.getAdventure().sender(sender).sendMessage(Component.text("Config reloaded!").color(NamedTextColor.GREEN));
} else {
motd.getAdventure().sender(sender).sendMessage(Component.text("You do not have permission for this command.").color(NamedTextColor.RED));
motdWaterfall.getAdventure().sender(sender).sendMessage(Component.text("You do not have permission for this command.").color(NamedTextColor.RED));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,32 @@

public class PingEvent implements Listener {

private final MOTDWaterfall motd;
private final MOTDWaterfall motdWaterfall;

public PingEvent(MOTDWaterfall motd) {
this.motd = motd;
public PingEvent(MOTDWaterfall motdWaterfall) {
this.motdWaterfall = motdWaterfall;
}

@EventHandler
public void onPing(ProxyPingEvent event) {
ServerPing response = event.getResponse();

if (motd.config.getString("type").equalsIgnoreCase("fixed")) {
Component formattedMOTD = motd.getMessage("fixed-motd");
if (motdWaterfall.config.getString("type").equalsIgnoreCase("fixed")) {
Component formattedMOTD = motdWaterfall.getMessage("fixed-motd");
BaseComponent finalMOTD = new TextComponent(BungeeComponentSerializer.get().serialize(formattedMOTD));
response.setDescriptionComponent(finalMOTD);
}

if (motd.config.getString("type").equalsIgnoreCase("random")) {
if (motdWaterfall.config.getString("type").equalsIgnoreCase("random")) {
int randomNum = ThreadLocalRandom.current()
.nextInt(0, motd.config.getStringList("random-motd").size());
Component randomMOTD = motd.miniMessage.deserialize(motd.config.getStringList("random-motd").get(randomNum));
.nextInt(0, motdWaterfall.config.getStringList("random-motd").size());
Component randomMOTD = motdWaterfall.miniMessage.deserialize(motdWaterfall.config.getStringList("random-motd").get(randomNum));
BaseComponent finalMOTD = new TextComponent(BungeeComponentSerializer.get().serialize(randomMOTD));
response.setDescriptionComponent(finalMOTD);
}

if (motd.config.getBoolean("use-custom-icon") && motd.bufferedImage != null) {
response.setFavicon(Favicon.create(motd.bufferedImage));
if (motdWaterfall.config.getBoolean("use-custom-icon") && motdWaterfall.bufferedImage != null) {
response.setFavicon(Favicon.create(motdWaterfall.bufferedImage));
}
}
}

0 comments on commit 181c3d9

Please sign in to comment.