Skip to content

Commit

Permalink
add a config option to switch between action bar and chat messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ryderbelserion committed Jul 25, 2024
1 parent d73f716 commit 9704677
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/main/java/com/badbones69/crazycrates/api/enums/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,34 @@ public String getMessage(@NotNull final CommandSender sender, @NotNull final Str
public String getMessage(@NotNull final CommandSender sender, @NotNull final Map<String, String> placeholders) {
return parse(sender, placeholders).replaceAll("\\{prefix}", this.config.getProperty(ConfigKeys.command_prefix));
}

public void sendMessage(final CommandSender sender, final String placeholder, final String replacement) {
final State state = this.config.getProperty(ConfigKeys.message_state);

switch (state) {
case send_message -> sendRichMessage(sender, placeholder, replacement);
case send_actionbar -> sendActionBar(sender, placeholder, replacement);
}
}

public void sendMessage(final CommandSender sender, final Map<String, String> placeholders) {
final State state = this.config.getProperty(ConfigKeys.message_state);

switch (state) {
case send_message -> sendRichMessage(sender, placeholders);
case send_actionbar -> sendActionBar(sender, placeholders);
}
}

public void sendMessage(final CommandSender sender) {
final State state = this.config.getProperty(ConfigKeys.message_state);

switch (state) {
case send_message -> sendRichMessage(sender);
case send_actionbar -> sendActionBar(sender);
}
}

public void sendActionBar(final CommandSender sender, final String placeholder, final String replacement) {
final String msg = getMessage(sender, placeholder, replacement);

Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/badbones69/crazycrates/api/enums/State.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.badbones69.crazycrates.api.enums;

public enum State {

send_message("send_message"),
send_actionbar("send_actionbar");

private final String name;

State(String name) {
this.name = name;
}

public String getName() {
return this.name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
import ch.jalu.configme.SettingsHolder;
import ch.jalu.configme.configurationdata.CommentsConfiguration;
import ch.jalu.configme.properties.Property;
import com.badbones69.crazycrates.api.enums.State;

import java.util.Collections;
import java.util.List;

import static ch.jalu.configme.properties.PropertyInitializer.newBeanProperty;
import static ch.jalu.configme.properties.PropertyInitializer.newListProperty;
import static ch.jalu.configme.properties.PropertyInitializer.newProperty;

Expand Down Expand Up @@ -64,6 +68,15 @@ public void registerComments(CommentsConfiguration conf) {
@Comment("This option will let you test a different way of picking random numbers. If you have any issues, You can set it back to false.")
public static final Property<Boolean> use_different_random = newProperty("root.use-different-random", false);

@Comment({
"This option will tell the plugin to send all messages as action bars or messages in chat.",
"",
"send_message -> sends messages in chat.",
"send_actionbar -> sends messages in actionbar.",
""
})
public static final Property<State> message_state = newBeanProperty(State.class, "root.message-state", State.send_message);

//@Comment({
// "Sends anonymous statistics about how the plugin is used to bstats.org.",
// "bstats is a service for plugin developers to find out how the plugin being used,",
Expand Down

0 comments on commit 9704677

Please sign in to comment.