Skip to content

Commit

Permalink
remove isLegacy()
Browse files Browse the repository at this point in the history
  • Loading branch information
ryderbelserion committed Sep 5, 2024
1 parent 7c92f4b commit 501b8ab
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 210 deletions.
7 changes: 0 additions & 7 deletions src/main/java/com/badbones69/crazycrates/CrazyCrates.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import com.badbones69.crazycrates.api.objects.other.Server;
import com.badbones69.crazycrates.api.utils.MiscUtils;
import com.badbones69.crazycrates.commands.CommandManager;
import com.badbones69.crazycrates.config.ConfigManager;
import com.badbones69.crazycrates.config.impl.ConfigKeys;
import com.badbones69.crazycrates.listeners.BrokeLocationsListener;
import com.badbones69.crazycrates.listeners.CrateControlListener;
import com.badbones69.crazycrates.listeners.MiscListener;
Expand Down Expand Up @@ -188,9 +186,4 @@ public void onDisable() {
public @NotNull final Timer getTimer() {
return this.timer;
}

@Override
public final boolean isLegacy() {
return !ConfigManager.getConfig().getProperty(ConfigKeys.minimessage_toggle);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,9 @@ public InventoryBuilder(@NotNull final Player player, @NotNull final String titl
this.title = title;
this.size = size;

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

if (this.plugin.isLegacy()) {
this.inventory = this.server.createInventory(this, this.size, ItemUtil.color(inventoryTitle));
} else {
this.inventory = this.server.createInventory(this, this.size, AdvUtil.parse(inventoryTitle));
}
this.inventory = this.server.createInventory(this, this.size, AdvUtil.parse(inventoryTitle));
}

public InventoryBuilder(@NotNull final Player player, @NotNull final String title, final int size, @NotNull final Crate crate) {
Expand All @@ -74,13 +70,9 @@ public InventoryBuilder(@NotNull final Player player, @NotNull final String titl

this.crate = crate;

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

if (this.plugin.isLegacy()) {
this.inventory = this.server.createInventory(this, this.size, ItemUtil.color(inventoryTitle));
} else {
this.inventory = this.server.createInventory(this, this.size, AdvUtil.parse(inventoryTitle));
}
this.inventory = this.server.createInventory(this, this.size, AdvUtil.parse(inventoryTitle));
}

public InventoryBuilder(@NotNull final Player player, @NotNull final String title, final int size, final int page, @NotNull final Crate crate) {
Expand All @@ -91,13 +83,9 @@ public InventoryBuilder(@NotNull final Player player, @NotNull final String titl

this.crate = crate;

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

if (this.plugin.isLegacy()) {
this.inventory = this.server.createInventory(this, this.size, ItemUtil.color(inventoryTitle));
} else {
this.inventory = this.server.createInventory(this, this.size, AdvUtil.parse(inventoryTitle));
}
this.inventory = this.server.createInventory(this, this.size, AdvUtil.parse(inventoryTitle));
}

public InventoryBuilder(@NotNull final Player player, @NotNull final String title, final int size, @NotNull final Crate crate, @NotNull final List<Tier> tiers) {
Expand All @@ -108,13 +96,9 @@ public InventoryBuilder(@NotNull final Player player, @NotNull final String titl
this.crate = crate;
this.tiers = tiers;

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

if (this.plugin.isLegacy()) {
this.inventory = this.server.createInventory(this, this.size, ItemUtil.color(inventoryTitle));
} else {
this.inventory = this.server.createInventory(this, this.size, AdvUtil.parse(inventoryTitle));
}
this.inventory = this.server.createInventory(this, this.size, AdvUtil.parse(inventoryTitle));
}

public InventoryBuilder() {}
Expand All @@ -127,7 +111,7 @@ public boolean overrideMenu() {

if (!commands.isEmpty()) {
commands.forEach(value -> {
String command = value.replaceAll("%player%", quoteReplacement(this.player.getName())).replaceAll("%crate%", quoteReplacement(this.crate.getFileName()));
final String command = value.replaceAll("%player%", quoteReplacement(this.player.getName())).replaceAll("%crate%", quoteReplacement(this.crate.getFileName()));

MiscUtils.sendCommand(command);
});
Expand Down Expand Up @@ -197,10 +181,6 @@ public final boolean contains(@NotNull final String message) {
}

public void sendTitleChange() {
if (this.plugin.isLegacy()) {
return;
}

ServerPlayer entityPlayer = (ServerPlayer) ((CraftHumanEntity) getView().getPlayer()).getHandle();
int containerId = entityPlayer.containerMenu.containerId;
MenuType<?> windowType = CraftContainer.getNotchInventoryType(getView().getTopInventory());
Expand Down
48 changes: 9 additions & 39 deletions src/main/java/com/badbones69/crazycrates/api/enums/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,8 @@ public void sendActionBar(final CommandSender sender, final String placeholder,

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

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

Expand All @@ -198,14 +192,8 @@ public void sendActionBar(final CommandSender sender, final Map<String, String>

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

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

Expand All @@ -214,14 +202,8 @@ public void sendActionBar(final CommandSender sender) {

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

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

Expand All @@ -230,35 +212,23 @@ public void sendRichMessage(final CommandSender sender, final String placeholder

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

if (this.plugin.isLegacy()) {
sender.sendMessage(ItemUtil.color(msg));
} else {
sender.sendRichMessage(msg);
}
sender.sendRichMessage(msg);
}

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

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

if (this.plugin.isLegacy()) {
sender.sendMessage(ItemUtil.color(msg));
} else {
sender.sendRichMessage(msg);
}
sender.sendRichMessage(msg);
}

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

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

if (this.plugin.isLegacy()) {
sender.sendMessage(ItemUtil.color(msg));
} else {
sender.sendRichMessage(msg);
}
sender.sendRichMessage(msg);
}

private @NotNull String parse(@NotNull final CommandSender sender, @NotNull final Map<String, String> placeholders) {
Expand Down
67 changes: 10 additions & 57 deletions src/main/java/com/badbones69/crazycrates/api/objects/Crate.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import net.kyori.adventure.sound.Sound;
import org.bukkit.Color;
import org.bukkit.Particle;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.Nullable;
import org.bukkit.configuration.ConfigurationSection;
Expand All @@ -35,11 +33,9 @@
import com.badbones69.crazycrates.api.utils.MiscUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;

@SuppressWarnings("deprecation")
public class Crate {

private ItemBuilder previewTierBorderItem;
Expand Down Expand Up @@ -70,8 +66,6 @@ public class Crate {
private int previewChestLines;
private int newPlayerKeys;

private List<ItemStack> itemStacks;

private List<Tier> tiers;
private CrateHologram hologram;

Expand Down Expand Up @@ -646,67 +640,26 @@ private void setItem(@Nullable final ItemStack itemStack, @NotNull final String

final String tiers = getPath(prizeName, "Tiers");

final boolean useOldEditor = ConfigManager.getConfig().getProperty(ConfigKeys.item_editor_toggle);

if (!section.contains(prizeName)) {
section.set(getPath(prizeName, "MaxRange"), 100);
}

if (useOldEditor && !this.plugin.isLegacy()) {
final List<ItemStack> editorItems = new ArrayList<>();

if (section.contains(prizeName + ".Editor-Items")) {
final List<?> editors = section.getList(prizeName + ".Editor-Items");

if (editors != null) {
editors.forEach(item -> editorItems.add((ItemStack) item));
}
}

editorItems.add(itemStack);

List<String> enchantments = new ArrayList<>();

for (Map.Entry<Enchantment, Integer> enchantment : itemStack.getEnchantments().entrySet()) {
enchantments.add(enchantment.getKey().getKey().getKey() + ":" + enchantment.getValue());
}

if (!enchantments.isEmpty()) section.set(getPath(prizeName, "DisplayEnchantments"), enchantments);
String toBase64 = ItemUtil.toBase64(itemStack);

if (itemStack.hasItemMeta()) {
final ItemMeta itemMeta = itemStack.getItemMeta();
section.set(getPath(prizeName, "DisplayData"), toBase64);

if (itemMeta.hasDisplayName()) {
section.set(getPath(prizeName, "DisplayName"), itemMeta.getDisplayName());
}
final String items = getPath(prizeName, "Items");

if (itemMeta.hasLore()) {
section.set(getPath(prizeName, "DisplayLore"), itemMeta.getLore());
}
}
if (section.contains(items)) {
final List<String> list = section.getStringList(items);

section.set(getPath(prizeName, "DisplayItem"), itemStack.getType().getKey().getKey());
section.set(getPath(prizeName, "DisplayAmount"), itemStack.getAmount());
list.add("Data:" + toBase64);

section.set(getPath(prizeName, "Editor-Items"), editorItems);
section.set(items, list);
} else {
String toBase64 = ItemUtil.toBase64(itemStack);

section.set(getPath(prizeName, "DisplayData"), toBase64);

final String items = getPath(prizeName, "Items");

if (section.contains(items)) {
final List<String> list = section.getStringList(items);

list.add("Data:" + toBase64);

section.set(items, list);
} else {
section.set(items, new ArrayList<>() {{
add("Data:" + toBase64);
}});
}
section.set(items, new ArrayList<>() {{
add("Data:" + toBase64);
}});
}

section.set(getPath(prizeName, "Chance"), chance);
Expand Down
23 changes: 0 additions & 23 deletions src/main/java/com/badbones69/crazycrates/api/objects/Prize.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,10 @@ public Prize(@NotNull final String prizeName, @NotNull final String sectionName,
* @return the name of the prize.
*/
public @NotNull final String getPrizeName() {
if (this.plugin.isLegacy()) {
return this.prizeName.isEmpty() ? "" : this.prizeName;
}

return this.prizeName.isEmpty() ? "<lang:" + this.displayItem.getType().getItemTranslationKey() + ">" : this.prizeName;
}

public @NotNull final String getStrippedName() {
if (this.plugin.isLegacy()) {
return ChatColor.stripColor(getPrizeName());
}

return PlainTextComponentSerializer.plainText().serialize(AdvUtil.parse(getPrizeName()));
}

Expand Down Expand Up @@ -284,21 +276,6 @@ public void broadcast(final Crate crate) {
final String prizeName = getPrizeName();
final String strippedName = getStrippedName();

if (this.plugin.isLegacy()) {
this.plugin.getServer().getOnlinePlayers().forEach(player -> {
if (!this.broadcastPermission.isEmpty() && player.hasPermission(this.broadcastPermission)) return;

this.broadcastMessages.forEach(message -> player.sendMessage(ItemUtil.color(message, new HashMap<>() {{
put("%player%", player.getName());
put("%crate%", fancyName);
put("%reward%", prizeName);
put("%reward_stripped%", strippedName);
}}, player)));
});

return;
}

this.plugin.getServer().getOnlinePlayers().forEach(player -> {
if (!this.broadcastPermission.isEmpty() && player.hasPermission(this.broadcastPermission)) return;

Expand Down
24 changes: 4 additions & 20 deletions src/main/java/com/badbones69/crazycrates/api/utils/MsgUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,9 @@ public static void sendMessage(CommandSender commandSender, @NotNull final Strin
if (sendPrefix) {
final String msg = message.replaceAll("%prefix%", quoteReplacement(prefix)).replaceAll("%Prefix%", quoteReplacement(prefix));

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

return;
Expand All @@ -43,17 +35,9 @@ public static void sendMessage(CommandSender commandSender, @NotNull final Strin
if (sendPrefix) {
final String msg = message.replaceAll("%prefix%", quoteReplacement(prefix)).replaceAll("%Prefix%", quoteReplacement(prefix));

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

Expand Down
Loading

0 comments on commit 501b8ab

Please sign in to comment.