Skip to content

Commit

Permalink
some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
4drian3d committed Oct 9, 2021
1 parent 3cc6bae commit 9ab0e40
Show file tree
Hide file tree
Showing 32 changed files with 236 additions and 247 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import net.kyori.adventure.bossbar.BossBar;
import net.kyori.adventure.text.minimessage.MiniMessage;

public record BossBarUtils(ConfigUtils config, MiniMessage mm) {
public record BossBarUtils(MiniMessage mm) {
/**
* Based on the argument given in the command,
* it will return the color of the specified bossbar.
Expand Down Expand Up @@ -48,31 +48,31 @@ public boolean regularBossbarArgs(int length, Audience sender) {
return switch (length) {
case 0 -> {
sender.sendMessage(
config.getPrefix().append(mm.parse(
ConfigUtils.getPrefix().append(mm.parse(
cManager.getConfig().getOrDefault(
"messages.bossbar.without-argument",
"<red>You need to enter the time, color and message arguments.</red>"))));
yield false;
}
case 1 -> {
sender.sendMessage(
config.getPrefix().append(mm.parse(
ConfigUtils.getPrefix().append(mm.parse(
cManager.getConfig().getOrDefault(
"messages.bossbar.only-time",
"<gray>You must enter the color and the message arguments.</gray>"))));
yield false;
}
case 2 -> {
sender.sendMessage(
config.getPrefix().append(mm.parse(
ConfigUtils.getPrefix().append(mm.parse(
cManager.getConfig().getOrDefault(
"messages.bossbar.overlay-missing",
"<gray>You must enter the overlay and the message arguments.</gray>"))));
yield false;
}
case 3 -> {
sender.sendMessage(
config.getPrefix().append(mm.parse(
ConfigUtils.getPrefix().append(mm.parse(
cManager.getConfig().getOrDefault(
"messages.bossbar.without-message",
"<gray>You need to enter the message to announce.</gray>"))));
Expand All @@ -87,39 +87,39 @@ public boolean sendBossbarArgs(int length, Audience sender) {
return switch (length) {
case 0 -> {
sender.sendMessage(
config.getPrefix().append(mm.parse(
ConfigUtils.getPrefix().append(mm.parse(
cManager.getConfig().getOrDefault(
"messages.bossbar.without-argument",
"<red>You need to enter the time, color and message arguments.</red>"))));
yield false;
}
case 1 -> {
sender.sendMessage(
config.getPrefix().append(mm.parse(
ConfigUtils.getPrefix().append(mm.parse(
cManager.getConfig().getOrDefault(
"messages.bossbar.only-player",
"<gray>You must enter the message to be sent after the player's name.</gray>"))));
yield false;
}
case 2 -> {
sender.sendMessage(
config.getPrefix().append(mm.parse(
ConfigUtils.getPrefix().append(mm.parse(
cManager.getConfig().getOrDefault(
"messages.bossbar.only-time",
"<gray>You must enter the color, overlay and the message arguments.</gray>"))));
yield false;
}
case 3 -> {
sender.sendMessage(
config.getPrefix().append(mm.parse(
ConfigUtils.getPrefix().append(mm.parse(
cManager.getConfig().getOrDefault(
"messages.bossbar.overlay-missing",
"<gray>You must enter the overlay and the message arguments.</gray>"))));
yield false;
}
case 4 -> {
sender.sendMessage(
config.getPrefix().append(mm.parse(
ConfigUtils.getPrefix().append(mm.parse(
cManager.getConfig().getOrDefault(
"messages.bossbar.without-message",
"<gray>You need to enter the message to announce.</gray>"))));
Expand All @@ -134,39 +134,39 @@ public boolean proxyBossbarArgs(int length, Audience sender) {
return switch (length) {
case 0 -> {
sender.sendMessage(
config.getPrefix().append(mm.parse(
ConfigUtils.getPrefix().append(mm.parse(
cManager.getConfig().getOrDefault(
"messages.bossbar.without-argument",
"<red>You need to enter the time, color and message arguments.</red>"))));
yield false;
}
case 1 -> {
sender.sendMessage(
config.getPrefix().append(mm.parse(
ConfigUtils.getPrefix().append(mm.parse(
cManager.getConfig().getOrDefault(
"messages.general.no-server-provided",
"<red>No server provided to send the message</red>"))));
yield false;
}
case 2 -> {
sender.sendMessage(
config.getPrefix().append(mm.parse(
ConfigUtils.getPrefix().append(mm.parse(
cManager.getConfig().getOrDefault(
"messages.bossbar.only-time",
"<gray>You must enter the color, overlay and the message arguments.</gray>"))));
yield false;
}
case 3 -> {
sender.sendMessage(
config.getPrefix().append(mm.parse(
ConfigUtils.getPrefix().append(mm.parse(
cManager.getConfig().getOrDefault(
"messages.bossbar.overlay-missing",
"<gray>You must enter the overlay and the message arguments.</gray>"))));
yield false;
}
case 4 -> {
sender.sendMessage(
config.getPrefix().append(mm.parse(
ConfigUtils.getPrefix().append(mm.parse(
cManager.getConfig().getOrDefault(
"messages.bossbar.without-message",
"<gray>You need to enter the message to announce.</gray>"))));
Expand All @@ -180,7 +180,7 @@ public float validBossbarNumber(String number, Audience sender){
try {
return Integer.parseInt(number);
} catch (Exception e){
sender.sendMessage(config.getPrefix().append(
sender.sendMessage(ConfigUtils.getPrefix().append(
mm.parse("<dark_red>This is not a valid number")));
return 0.1f;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import net.kyori.adventure.text.minimessage.MiniMessage;

public class ConfigUtils {
private Yaml config = new ConfigManager().getConfig();
private MiniMessage mm = MiniMessage.miniMessage();
private static Yaml config = new ConfigManager().getConfig();
private static MiniMessage mm = MiniMessage.miniMessage();

public Component getPrefix(){
public static Component getPrefix(){
if (config.getOrDefault("messages.prefix.enabled", true)) {
return mm.parse(config.getOrDefault(
"messages.prefix.line",
Expand All @@ -23,109 +23,109 @@ public Component getPrefix(){
TITLE CONFIGURATION
-----------------------------*/

public void sendTitleError(Audience sender){
public static void sendTitleError(Audience sender){
sender.sendMessage(getPrefix().append(mm.parse(
config.getOrDefault(
"messages.title.error",
"<dark_red>An error occurred while sending the title. Be sure to use the ';' to separate the title and the subtitle.</dark_red>"))));
}

public void sendNoArgumentMessage(Audience sender) {
public static void sendNoArgumentMessage(Audience sender) {
sender.sendMessage(getPrefix().append(mm.parse(
config.getOrDefault(
"messages.title.without-argument",
"<red>You need to enter the title and subtitle arguments.</red>"))));
}

public void noTitlePlayerArgumentProvided(Audience sender){
public static void noTitlePlayerArgumentProvided(Audience sender){
sender.sendMessage(getPrefix().append(mm.parse(
config.getOrDefault(
"messages.title.only-player",
"<gray>You must enter the title and subtitle after the player's name to send the message correctly.</gray>"))));
}

public String getTitleSound(){
public static String getTitleSound(){
return config.getOrDefault(
"sounds.title.sound-id",
"entity.experience_orb.pickup");
}

public boolean isTitleSoundEnabled(){
public static boolean isTitleSoundEnabled(){
return config.getOrDefault("sounds.title.enabled", true);
}

public float getTitleSoundVolume(){
public static float getTitleSoundVolume(){
return config.getOrDefault("sounds.title.volume", 10);
}

public float getTitleSoundPitch(){
public static float getTitleSoundPitch(){
return config.getOrDefault("sounds.title.pitch", 2);
}

/*-----------------------------
ACTIONBAR CONFIGURATION
-----------------------------*/

public void noActionbarArgumentProvided(Audience sender){
public static void noActionbarArgumentProvided(Audience sender){
sender.sendMessage(
getPrefix().append(mm.parse(
config.getOrDefault(
"messages.actionbar.without-argument",
"<red>You need to enter the message to announce.</red>"))));
}

public void noActionbarPlayerArgumentProvided(Audience sender){
public static void noActionbarPlayerArgumentProvided(Audience sender){
sender.sendMessage(
getPrefix().append(mm.parse(
config.getOrDefault(
"messages.actionbar.only-player",
"<gray>You must enter the message to be sent after the player's name.</gray>"))));
}

public String getActionbarSound(){
public static String getActionbarSound(){
return config.getOrDefault(
"sounds.actionbar.sound-id",
"entity.experience_orb.pickup");
}

public boolean isActionbarSoundEnabled(){
public static boolean isActionbarSoundEnabled(){
return config.getOrDefault("sounds.actionbar.enabled", true);
}

public float getActionbarSoundVolume(){
public static float getActionbarSoundVolume(){
return config.getOrDefault("sounds.actionbar.volume", 10);
}

public float getActionbarSoundPitch(){
public static float getActionbarSoundPitch(){
return config.getOrDefault("sounds.actionbar.pitch", 2);
}

/*-----------------------------
BOSSBAR CONFIGURATION
-----------------------------*/

public String getBossbarSound(){
public static String getBossbarSound(){
return config.getOrDefault(
"sounds.bossbar.sound-id",
"entity.experience_orb.pickup");
}

public boolean isBossbarSoundEnabled(){
public static boolean isBossbarSoundEnabled(){
return config.getOrDefault("sounds.bossbar.enabled", true);
}

public float getBossbarSoundVolume(){
public static float getBossbarSoundVolume(){
return config.getOrDefault("sounds.bossbar.volume", 10);
}

public float getBossbarSoundPitch(){
public static float getBossbarSoundPitch(){
return config.getOrDefault("sounds.bossbar.pitch", 2);
}

/*
GENERAL CONFIGURATION
*/
public void sendConfirmation(ComponentType type, Audience sender){
public static void sendConfirmation(ComponentType type, Audience sender){
sender.sendMessage(getPrefix().append(mm.parse(switch(type){
case BOSSBAR -> config.getOrDefault(
"messages.bossbar.successfully",
Expand All @@ -139,7 +139,7 @@ public void sendConfirmation(ComponentType type, Audience sender){
})));
}

public void playPaperSound(ComponentType type, Audience audience){
public static void playPaperSound(ComponentType type, Audience audience){
SoundUtil sUtils = new SoundUtil();
switch(type){
case TITLE -> {
Expand Down Expand Up @@ -172,51 +172,51 @@ public void playPaperSound(ComponentType type, Audience audience){
}
}

public void reloadMessage(Audience sender){
public static void reloadMessage(Audience sender){
sender.sendMessage(mm.parse(
config.getOrDefault(
"messages.general.reload-config",
"<green>Config Reloaded</green>")));
}

public void invalidCommand(Audience sender){
public static void invalidCommand(Audience sender){
sender.sendMessage(getPrefix().append(mm.parse(
config.getOrDefault(
"messages.general.invalid-command",
"<red>Unknown Command</red>"))));
}

public void helpPrefix(Audience sender){
public static void helpPrefix(Audience sender){
sender.sendMessage(mm.parse(
config.getOrDefault(
"messages.general.help-message",
"<white>Available Commands:</white>")));
}

public void playerNotFoundMessage(Audience sender){
public static void playerNotFoundMessage(Audience sender){
sender.sendMessage(getPrefix().append(mm.parse(
config.getOrDefault(
"messages.general.player-not-found",
"<red>Player not found</red>"))));
}

public void onlyPlayerExecute(Audience sender){
public static void onlyPlayerExecute(Audience sender){
sender.sendMessage(getPrefix().append(mm.parse(
config.getOrDefault(
"messages.general.no-console",
"<red>The console cannot execute this command</red>")
)));
}

public void noServerArgumentProvided(Audience sender){
public static void noServerArgumentProvided(Audience sender){
sender.sendMessage(getPrefix().append(mm.parse(
config.getOrDefault(
"messages.general.no-server-provided",
"<red>No server provided to send the message</red>")
)));
}

public void noServerFound(Audience sender){
public static void noServerFound(Audience sender){
sender.sendMessage(getPrefix().append(mm.parse(
config.getOrDefault(
"messages.general.server-not-found",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class GeneralUtils {
* @param args Arguments of the command
* @return The arguments of a command in string form
*/
public String getCommandString(String[] args){
public static String getCommandString(String[] args){
// Concatenate the arguments provided by the command sent.
StringBuilder commandString = new StringBuilder();
for (String argument : args) {
Expand All @@ -22,7 +22,7 @@ public String getCommandString(String[] args){
* @param since Specific position from which the string is to be formed
* @return The command arguments from a specified position converted to String
*/
public String getCommandString(String[] args, int since){
public static String getCommandString(String[] args, int since){
// Concatenate the arguments provided by the command sent.
StringBuilder commandString = new StringBuilder();
for (int i = since; i < args.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public String[] getTitleAndSubtitle(String string, Audience sender) {
// it will catch the error in the console and send an error message to the sender.
} catch (Exception e) {
// Send an error message to the sender using the command
new ConfigUtils().sendTitleError(sender);
ConfigUtils.sendTitleError(sender);
return null;
}
}
Expand Down
Loading

0 comments on commit 9ab0e40

Please sign in to comment.