Skip to content

Commit

Permalink
add the toggle of all toggles.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryderbelserion committed Jul 27, 2024
1 parent 2cf887a commit d81038d
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 21 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ triumph-cmd = "2.0.0-ALPHA-10"
tirumph-gui = "3.1.7"
jetbrains = "24.1.0"
kyori = "4.17.0"
vital = "2.0.2"
vital = "2.1"

# Paper
paperweight = "1.7.1"
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/com/badbones69/crazycrates/CrazyCrates.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.badbones69.crazycrates;

import ch.jalu.configme.SettingsManager;
import com.badbones69.crazycrates.api.builders.types.CrateAdminMenu;
import com.badbones69.crazycrates.api.builders.types.CrateMainMenu;
import com.badbones69.crazycrates.api.builders.types.CratePreviewMenu;
Expand Down Expand Up @@ -61,12 +62,13 @@ public CrazyCrates() {

@Override
public void onEnable() {
this.paper = new VitalPaper(this);

this.instance = new Server(getDataFolder());
this.instance.apply();

this.paper.setLogging(ConfigManager.getConfig().getProperty(ConfigKeys.verbose_logging));
final SettingsManager config = ConfigManager.getConfig();

this.paper = new VitalPaper(this, config.getProperty(ConfigKeys.minimessage_toggle));
this.paper.setLogging(config.getProperty(ConfigKeys.verbose_logging));

this.fileManager = new FileManager();
this.fileManager.addFile("locations.yml").addFile("data.yml")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.badbones69.crazycrates.tasks.crates.CrateManager;
import com.ryderbelserion.vital.paper.enums.Support;
import com.ryderbelserion.vital.paper.util.AdvUtil;
import com.ryderbelserion.vital.paper.util.ItemUtil;
import net.kyori.adventure.text.serializer.json.JSONComponentSerializer;
import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket;
import net.minecraft.server.level.ServerPlayer;
Expand Down Expand Up @@ -60,7 +61,11 @@ public InventoryBuilder(@NotNull final Player player, @NotNull final String titl

String inventoryTitle = Support.placeholder_api.isEnabled() ? PlaceholderAPI.setPlaceholders(getPlayer(), this.title) : this.title;

this.inventory = this.server.createInventory(this, this.size, AdvUtil.parse(inventoryTitle));
if (ConfigManager.getConfig().getProperty(ConfigKeys.minimessage_toggle)) {
this.inventory = this.server.createInventory(this, this.size, AdvUtil.parse(inventoryTitle));
} else {
this.inventory = this.server.createInventory(this, this.size, ItemUtil.color(title));
}
}

public InventoryBuilder(@NotNull final Player player, @NotNull final String title, final int size, @NotNull final Crate crate) {
Expand All @@ -72,7 +77,11 @@ public InventoryBuilder(@NotNull final Player player, @NotNull final String titl

String inventoryTitle = Support.placeholder_api.isEnabled() ? PlaceholderAPI.setPlaceholders(getPlayer(), this.title) : this.title;

this.inventory = this.server.createInventory(this, this.size, AdvUtil.parse(inventoryTitle));
if (ConfigManager.getConfig().getProperty(ConfigKeys.minimessage_toggle)) {
this.inventory = this.server.createInventory(this, this.size, AdvUtil.parse(inventoryTitle));
} else {
this.inventory = this.server.createInventory(this, this.size, ItemUtil.color(title));
}
}

public InventoryBuilder(@NotNull final Player player, @NotNull final String title, final int size, final int page, @NotNull final Crate crate) {
Expand All @@ -85,7 +94,11 @@ public InventoryBuilder(@NotNull final Player player, @NotNull final String titl

String inventoryTitle = Support.placeholder_api.isEnabled() ? PlaceholderAPI.setPlaceholders(getPlayer(), this.title) : this.title;

this.inventory = this.server.createInventory(this, this.size, AdvUtil.parse(inventoryTitle));
if (ConfigManager.getConfig().getProperty(ConfigKeys.minimessage_toggle)) {
this.inventory = this.server.createInventory(this, this.size, AdvUtil.parse(inventoryTitle));
} else {
this.inventory = this.server.createInventory(this, this.size, ItemUtil.color(title));
}
}

public InventoryBuilder(@NotNull final Player player, @NotNull final String title, final int size, @NotNull final Crate crate, @NotNull final List<Tier> tiers) {
Expand All @@ -98,7 +111,11 @@ public InventoryBuilder(@NotNull final Player player, @NotNull final String titl

String inventoryTitle = Support.placeholder_api.isEnabled() ? PlaceholderAPI.setPlaceholders(getPlayer(), this.title) : this.title;

this.inventory = this.server.createInventory(this, this.size, AdvUtil.parse(inventoryTitle));
if (ConfigManager.getConfig().getProperty(ConfigKeys.minimessage_toggle)) {
this.inventory = this.server.createInventory(this, this.size, AdvUtil.parse(inventoryTitle));
} else {
this.inventory = this.server.createInventory(this, this.size, ItemUtil.color(title));
}
}

public InventoryBuilder() {}
Expand Down Expand Up @@ -177,6 +194,12 @@ public final boolean contains(@NotNull final String message) {
}

public void sendTitleChange() {
final SettingsManager config = ConfigManager.getConfig();

if (config.getProperty(ConfigKeys.minimessage_toggle)) {
return;
}

ServerPlayer entityPlayer = (ServerPlayer) ((CraftHumanEntity) getView().getPlayer()).getHandle();
int containerId = entityPlayer.containerMenu.containerId;
MenuType<?> windowType = CraftContainer.getNotchInventoryType(getView().getTopInventory());
Expand Down
57 changes: 50 additions & 7 deletions src/main/java/com/badbones69/crazycrates/api/enums/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import com.ryderbelserion.vital.core.util.StringUtil;
import com.ryderbelserion.vital.paper.enums.Support;
import com.ryderbelserion.vital.paper.util.AdvUtil;
import com.ryderbelserion.vital.paper.util.ItemUtil;
import net.md_5.bungee.api.ChatMessageType;
import org.apache.commons.lang.StringUtils;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.Nullable;
import com.badbones69.crazycrates.config.ConfigManager;
import com.badbones69.crazycrates.config.impl.messages.CommandKeys;
import com.badbones69.crazycrates.config.impl.messages.CrateKeys;
Expand Down Expand Up @@ -176,47 +177,89 @@ public void sendActionBar(final CommandSender sender, final String placeholder,

if (msg.isEmpty() || msg.isBlank()) return;

sender.sendActionBar(AdvUtil.parse(msg));
final boolean isAdventure = this.config.getProperty(ConfigKeys.minimessage_toggle);

if (isAdventure) {
sender.sendActionBar(AdvUtil.parse(msg));
} else {
if (sender instanceof Player player) {
player.sendActionBar(ItemUtil.color(msg));
}
}
}

public void sendActionBar(final CommandSender sender, final Map<String, String> placeholders) {
final String msg = getMessage(sender, placeholders);

if (msg.isEmpty() || msg.isBlank()) return;

sender.sendActionBar(AdvUtil.parse(msg));
final boolean isAdventure = this.config.getProperty(ConfigKeys.minimessage_toggle);

if (isAdventure) {
sender.sendActionBar(AdvUtil.parse(msg));
} else {
if (sender instanceof Player player) {
player.sendActionBar(ItemUtil.color(msg));
}
}
}

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

if (msg.isEmpty() || msg.isBlank()) return;

sender.sendActionBar(AdvUtil.parse(getMessage(sender)));
final boolean isAdventure = this.config.getProperty(ConfigKeys.minimessage_toggle);

if (isAdventure) {
sender.sendActionBar(AdvUtil.parse(msg));
} else {
if (sender instanceof Player player) {
player.sendActionBar(ItemUtil.color(msg));
}
}
}

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

if (msg.isEmpty() || msg.isBlank()) return;

sender.sendRichMessage(msg);
final boolean isAdventure = this.config.getProperty(ConfigKeys.minimessage_toggle);

if (isAdventure) {
sender.sendRichMessage(msg);
} else {
sender.sendMessage(ItemUtil.color(msg));
}
}

public void sendRichMessage(final CommandSender sender, final Map<String, String> placeholders) {
final String msg = getMessage(sender, placeholders);

if (msg.isEmpty() || msg.isBlank()) return;

sender.sendRichMessage(msg);
final boolean isAdventure = this.config.getProperty(ConfigKeys.minimessage_toggle);

if (isAdventure) {
sender.sendRichMessage(msg);
} else {
sender.sendMessage(ItemUtil.color(msg));
}
}

public void sendRichMessage(final CommandSender sender) {
final String msg = getMessage(sender);

if (msg.isEmpty() || msg.isBlank()) return;

sender.sendRichMessage(msg);
final boolean isAdventure = this.config.getProperty(ConfigKeys.minimessage_toggle);

if (isAdventure) {
sender.sendRichMessage(msg);
} else {
sender.sendMessage(ItemUtil.color(msg));
}
}

private @NotNull String parse(@NotNull final CommandSender sender, @NotNull final Map<String, String> placeholders) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import com.badbones69.crazycrates.api.enums.PersistentKeys;
import com.badbones69.crazycrates.api.utils.ItemUtils;
import com.badbones69.crazycrates.api.utils.MiscUtils;
import com.badbones69.crazycrates.config.ConfigManager;
import com.badbones69.crazycrates.config.impl.ConfigKeys;
import com.ryderbelserion.vital.paper.builders.items.ItemBuilder;
import com.ryderbelserion.vital.paper.util.AdvUtil;
import com.ryderbelserion.vital.paper.util.ItemUtil;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.EntityType;
Expand Down Expand Up @@ -99,7 +102,11 @@ public Prize(@NotNull final String prizeName, @NotNull final String sectionName,
}

public @NotNull final String getStrippedName() {
return PlainTextComponentSerializer.plainText().serialize(AdvUtil.parse(getPrizeName()));
if (ConfigManager.getConfig().getProperty(ConfigKeys.minimessage_toggle)) {
return PlainTextComponentSerializer.plainText().serialize(AdvUtil.parse(getPrizeName()));
}

return ChatColor.stripColor(getPrizeName());
}

/**
Expand Down
37 changes: 35 additions & 2 deletions src/main/java/com/badbones69/crazycrates/api/utils/MsgUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.badbones69.crazycrates.api.utils;

import com.ryderbelserion.vital.paper.util.ItemUtil;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
Expand All @@ -14,13 +15,45 @@ public static void sendMessage(CommandSender commandSender, @NotNull final Strin

String prefix = getPrefix();

final boolean isAdventure = ConfigManager.getConfig().getProperty(ConfigKeys.minimessage_toggle);

final boolean sendPrefix = !prefix.isEmpty() && prefixToggle;

if (commandSender instanceof Player player) {
if (!prefix.isEmpty() && prefixToggle) player.sendRichMessage(message.replaceAll("%prefix%", quoteReplacement(prefix)).replaceAll("%Prefix%", quoteReplacement(prefix))); else player.sendRichMessage(message);
if (sendPrefix) {
final String msg = message.replaceAll("%prefix%", quoteReplacement(prefix)).replaceAll("%Prefix%", quoteReplacement(prefix));

if (isAdventure) {
player.sendRichMessage(msg);
} else {
player.sendMessage(ItemUtil.color(msg));
}
} else {
if (isAdventure) {
player.sendRichMessage(message);
} else {
player.sendMessage(ItemUtil.color(message));
}
}

return;
}

if (!prefix.isEmpty() && prefixToggle) commandSender.sendRichMessage(message.replaceAll("%prefix%", quoteReplacement(prefix)).replaceAll("%Prefix%", quoteReplacement(prefix))); else commandSender.sendRichMessage(message);
if (sendPrefix) {
final String msg = message.replaceAll("%prefix%", quoteReplacement(prefix)).replaceAll("%Prefix%", quoteReplacement(prefix));

if (isAdventure) {
commandSender.sendRichMessage(msg);
} else {
commandSender.sendMessage(ItemUtil.color(msg));
}
} else {
if (isAdventure) {
commandSender.sendRichMessage(message);
} else {
commandSender.sendMessage(ItemUtil.color(message));
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.badbones69.crazycrates.commands.crates.types.admin;

import ch.jalu.configme.SettingsManager;
import com.badbones69.crazycrates.api.enums.Files;
import com.badbones69.crazycrates.api.enums.Messages;
import com.badbones69.crazycrates.commands.crates.types.BaseCommand;
Expand All @@ -20,7 +21,10 @@ public void reload(CommandSender sender) {

this.fileManager.reloadFiles().init();

this.plugin.getPaper().setLogging(ConfigManager.getConfig().getProperty(ConfigKeys.verbose_logging));
final SettingsManager config = ConfigManager.getConfig();

this.plugin.getPaper().setLogging(config.getProperty(ConfigKeys.verbose_logging));
this.plugin.getPaper().setAdventure(config.getProperty(ConfigKeys.minimessage_toggle));

final YamlConfiguration locations = Files.locations.getConfiguration();
final YamlConfiguration data = Files.data.getConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ 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 defines the type of color codes used in CrazyCrates",
"",
"true -> uses minimessage",
"false -> uses legacy color codes",
"",
"Note: inventory titles won't update during Cosmic Crate while this is false."
})
public static final Property<Boolean> minimessage_toggle = newProperty("root.use-minimessage", true);

@Comment({
"This option will tell the plugin to send all messages as action bars or messages in chat.",
"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.ryderbelserion.vital.paper.builders.items.ItemBuilder;
import com.ryderbelserion.vital.paper.enums.Support;
import com.ryderbelserion.vital.paper.util.AdvUtil;
import com.ryderbelserion.vital.paper.util.ItemUtil;
import me.clip.placeholderapi.PlaceholderAPI;
import net.kyori.adventure.sound.Sound;
import org.bukkit.configuration.file.FileConfiguration;
Expand Down Expand Up @@ -320,7 +321,11 @@ public void onMysteryBoxClick(InventoryClickEvent event) {
if (!broadcastMessage.isBlank()) {
String builder = Support.placeholder_api.isEnabled() ? PlaceholderAPI.setPlaceholders(player, broadcastMessage) : broadcastMessage;

this.plugin.getServer().broadcast(AdvUtil.parse(builder.replaceAll("%prefix%", MsgUtils.getPrefix()).replaceAll("%player%", player.getName())));
if (ConfigManager.getConfig().getProperty(ConfigKeys.minimessage_toggle)) {
this.plugin.getServer().broadcast(AdvUtil.parse(builder.replaceAll("%prefix%", MsgUtils.getPrefix()).replaceAll("%player%", player.getName())));
} else {
this.plugin.getServer().broadcastMessage(ItemUtil.color(builder.replaceAll("%prefix%", MsgUtils.getPrefix()).replaceAll("%player%", player.getName())));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.badbones69.crazycrates.listeners.crates;

import com.badbones69.crazycrates.CrazyCrates;
import com.badbones69.crazycrates.config.ConfigManager;
import com.badbones69.crazycrates.config.impl.ConfigKeys;
import com.badbones69.crazycrates.tasks.BukkitUserManager;
import com.badbones69.crazycrates.tasks.crates.CrateManager;
import com.badbones69.crazycrates.api.enums.Messages;
import com.badbones69.crazycrates.api.events.CrateOpenEvent;
import com.badbones69.crazycrates.api.objects.Crate;
import com.ryderbelserion.vital.paper.enums.Support;
import com.ryderbelserion.vital.paper.util.AdvUtil;
import com.ryderbelserion.vital.paper.util.ItemUtil;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -69,7 +72,11 @@ public void onCrateOpen(CrateOpenEvent event) {
if (!broadcastMessage.isBlank()) {
final String builder = Support.placeholder_api.isEnabled() ? PlaceholderAPI.setPlaceholders(player, broadcastMessage) : broadcastMessage;

this.plugin.getServer().broadcast(AdvUtil.parse(builder.replaceAll("%prefix%", MsgUtils.getPrefix()).replaceAll("%player%", player.getName())));
if (ConfigManager.getConfig().getProperty(ConfigKeys.minimessage_toggle)) {
this.plugin.getServer().broadcast(AdvUtil.parse(builder.replaceAll("%prefix%", MsgUtils.getPrefix()).replaceAll("%player%", player.getName())));
} else {
this.plugin.getServer().broadcastMessage(ItemUtil.color(builder.replaceAll("%prefix%", MsgUtils.getPrefix()).replaceAll("%player%", player.getName())));
}
}
}

Expand Down

0 comments on commit d81038d

Please sign in to comment.