Skip to content

Commit

Permalink
Make message system more modular
Browse files Browse the repository at this point in the history
  • Loading branch information
Vyladence committed May 5, 2023
1 parent 9d6bb6a commit f270d2e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group = 'org'
version = '1.0'
version = '1.1'

repositories {
mavenCentral()
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/simplelinks/commands/LinksCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.bukkit.command.*;
import org.bukkit.entity.Player;

import org.simplelinks.util.ChatFormat;
import org.simplelinks.util.PlayerSend;

public class LinksCommand implements CommandExecutor {

Expand All @@ -14,7 +14,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St

if (sender instanceof Player player) {
for (String line : lines) {
player.sendMessage(ChatFormat.format(line));
PlayerSend.message(player, line);
}
} else {
System.out.println("This command can only run in-game!");
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/simplelinks/commands/ReloadConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import org.bukkit.command.*;
import org.bukkit.entity.Player;
import org.simplelinks.util.ChatFormat;
import org.simplelinks.util.PlayerSend;

public class ReloadConfig implements CommandExecutor {
@Override
Expand All @@ -17,15 +17,15 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
SimpleLinks.getPlugin(SimpleLinks.class).reloadConfig();

if (sender instanceof Player player) {
player.sendMessage(ChatFormat.format("&8[&dSimpleLinks&8] &fConfig Reloaded!"));
PlayerSend.message(player, "&8[&dSimpleLinks&8] &fConfig Reloaded!");
} else {
System.out.println("Config Reloaded!");
}
} else {
// Unknown Command fallback

if (sender instanceof Player player) {
player.sendMessage(ChatFormat.format("&8[&dSimpleLinks&8] &cUnknown subcommand!"));
PlayerSend.message(player, "&8[&dSimpleLinks&8] &cUnknown subcommand!");
} else {
System.out.println("Unknown Subcommand!");
}
Expand All @@ -35,7 +35,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
String version = SimpleLinks.getPlugin(SimpleLinks.class).getDescription().getVersion();

if (sender instanceof Player player) {
player.sendMessage(ChatFormat.format("&8[&dSimpleLinks&8] &fRunning &fLinksPlugin &av" + version));
PlayerSend.message(player, "&8[&dSimpleLinks&8] &fRunning &fLinksPlugin &av" + version);
} else {
System.out.println("Running SimpleLinks v" + version);
}
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/org/simplelinks/util/ChatFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@
import org.bukkit.ChatColor;

public class ChatFormat {
public static String format (String message) {
String formattedHex = ConvertHex.convert(message);
return ChatColor.translateAlternateColorCodes('&', formattedHex);
}

}
12 changes: 12 additions & 0 deletions src/main/java/org/simplelinks/util/PlayerSend.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.simplelinks.util;

import org.bukkit.ChatColor;
import org.bukkit.entity.Player;

public class PlayerSend {
public static void message (Player player, String message) {
String formattedHex = ConvertHex.convert(message);
String formattedYAML = ChatColor.translateAlternateColorCodes('&', formattedHex);
player.sendMessage(formattedYAML);
}
}

0 comments on commit f270d2e

Please sign in to comment.