mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-30 10:51:20 +01:00
Fixed DeathDowngrading MiniMessage format support
This commit is contained in:
parent
e0d7a54522
commit
1eb8bde5d4
@ -13,7 +13,7 @@ import net.Indyuce.mmoitems.api.player.inventory.EquippedItem;
|
||||
import net.Indyuce.mmoitems.api.player.inventory.InventoryUpdateHandler;
|
||||
import net.Indyuce.mmoitems.api.util.message.Message;
|
||||
import net.Indyuce.mmoitems.stat.data.UpgradeData;
|
||||
import net.Indyuce.mmoitems.stat.type.NameData;
|
||||
import net.Indyuce.mmoitems.util.MMOUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -243,8 +243,7 @@ public class DeathDowngrading {
|
||||
bakedItem.setItemMeta(dur.toItem().getItemMeta());}
|
||||
|
||||
// Send downgrading message
|
||||
Message.DEATH_DOWNGRADING.format(ChatColor.RED, "#item#", (mmo.getData(ItemStats.NAME) instanceof NameData) ? mmo.getData(ItemStats.NAME).toString() : SilentNumbers.getItemName(bakedItem, false))
|
||||
.send(player);
|
||||
Message.DEATH_DOWNGRADING.format(ChatColor.RED, "#item#", MMOUtils.getDisplayName(mmo.getNBT().getItem())).send(player);
|
||||
|
||||
// Uuuuh
|
||||
return bakedItem;
|
||||
|
@ -0,0 +1,81 @@
|
||||
package net.Indyuce.mmoitems.api.util.message;
|
||||
|
||||
import io.lumine.mythic.lib.MythicLib;
|
||||
import io.lumine.mythic.lib.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import io.lumine.mythic.lib.api.util.LegacyComponent;
|
||||
import net.Indyuce.mmocore.api.player.PlayerActivity;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class FormattedMessage {
|
||||
private final boolean actionBar;
|
||||
|
||||
@NotNull
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* Used to block empty messages from spamming the chat. Also used to apply
|
||||
* a default color code to the message and be able to select which
|
||||
* messages are displayed on the action bar and which go to chat.
|
||||
*
|
||||
* @param message Unformatted message
|
||||
*/
|
||||
public FormattedMessage(Message message) {
|
||||
this.message = message.getUpdated();
|
||||
this.actionBar = MMOItems.plugin.getConfig().getBoolean("action-bar-display." + message.getActionBarConfigPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used by external plugins. This can be useful to
|
||||
* apply that 60 tick action bar timeout when using MMOCore
|
||||
*
|
||||
* @param message Messages with color codes applied.
|
||||
* @param actionBar Should the message be displayed on the action bar
|
||||
*/
|
||||
public FormattedMessage(String message, boolean actionBar) {
|
||||
this.message = message;
|
||||
this.actionBar = actionBar;
|
||||
}
|
||||
|
||||
public FormattedMessage format(ChatColor prefix, String... toReplace) {
|
||||
|
||||
// Compatibility with #send(Player)
|
||||
if (message.isEmpty())
|
||||
return this;
|
||||
|
||||
message = prefix + message;
|
||||
for (int j = 0; j < toReplace.length; j += 2)
|
||||
message = message.replace(toReplace[j], toReplace[j + 1]);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Either sends to action bar or to chat if it's not empty.
|
||||
* Supports MiniMessage since 6.8.3 snapshots
|
||||
*
|
||||
* @param player Player receiving the message
|
||||
*/
|
||||
public void send(Player player) {
|
||||
if (message.isEmpty())
|
||||
return;
|
||||
|
||||
final String jsonMessage = GsonComponentSerializer.gson().serialize(LegacyComponent.simpleParse(message));
|
||||
|
||||
if (actionBar) {
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("MMOCore"))
|
||||
PlayerData.get(player).setLastActivity(PlayerActivity.ACTION_BAR_MESSAGE);
|
||||
|
||||
MythicLib.plugin.getVersion().getWrapper().sendActionBar(player, jsonMessage);
|
||||
} else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return message;
|
||||
}
|
||||
}
|
@ -103,11 +103,12 @@ public enum Message {
|
||||
return actionBarConfigPath;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String formatRaw(ChatColor prefix, String... toReplace) {
|
||||
return format(prefix, toReplace).toString();
|
||||
}
|
||||
|
||||
public PlayerMessage format(ChatColor prefix, String... toReplace) {
|
||||
return new PlayerMessage(this).format(prefix, toReplace);
|
||||
public FormattedMessage format(ChatColor prefix, String... toReplace) {
|
||||
return new FormattedMessage(this).format(prefix, toReplace);
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
package net.Indyuce.mmoitems.api.util.message;
|
||||
|
||||
import io.lumine.mythic.lib.MythicLib;
|
||||
import net.Indyuce.mmocore.api.player.PlayerActivity;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PlayerMessage {
|
||||
private final boolean actionBar;
|
||||
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* Used to block empty messages from spamming the chat. Also used to apply
|
||||
* a default color code to the message and be able to select which
|
||||
* messages are displayed on the action bar and which go to chat.
|
||||
*
|
||||
* @param message Unformatted message
|
||||
*/
|
||||
public PlayerMessage(Message message) {
|
||||
this.message = message.getUpdated();
|
||||
this.actionBar = MMOItems.plugin.getConfig().getBoolean("action-bar-display." + message.getActionBarConfigPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used by external plugins. This can be useful to
|
||||
* apply that 60 tick action bar timeout when using MMOCore
|
||||
*
|
||||
* @param message Messages with color codes applied.
|
||||
* @param actionBar Should the message be displayed on the action bar
|
||||
*/
|
||||
public PlayerMessage(String message, boolean actionBar) {
|
||||
this.message = message;
|
||||
this.actionBar = actionBar;
|
||||
}
|
||||
|
||||
public PlayerMessage format(ChatColor prefix, String... toReplace) {
|
||||
message = prefix + message;
|
||||
for (int j = 0; j < toReplace.length; j += 2)
|
||||
message = message.replace(toReplace[j], toReplace[j + 1]);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Either sends to action bar or to chat if it's not empty
|
||||
*
|
||||
* @param player Player to send message to
|
||||
*/
|
||||
public void send(Player player) {
|
||||
if (ChatColor.stripColor(message).isEmpty())
|
||||
return;
|
||||
|
||||
if (actionBar) {
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("MMOCore"))
|
||||
PlayerData.get(player).setLastActivity(PlayerActivity.ACTION_BAR_MESSAGE);
|
||||
|
||||
MythicLib.plugin.getVersion().getWrapper().sendActionBar(player, message);
|
||||
} else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return message;
|
||||
}
|
||||
}
|
@ -5,13 +5,13 @@ import io.lumine.mythic.lib.adventure.text.Component;
|
||||
import io.lumine.mythic.lib.api.item.NBTItem;
|
||||
import io.lumine.mythic.lib.api.util.LegacyComponent;
|
||||
import io.lumine.mythic.lib.api.util.ui.SilentNumbers;
|
||||
import net.Indyuce.mmoitems.util.MMOUtils;
|
||||
import net.Indyuce.mmoitems.api.crafting.ingredient.CheckedIngredient;
|
||||
import net.Indyuce.mmoitems.api.crafting.recipe.CheckedRecipe;
|
||||
import net.Indyuce.mmoitems.api.crafting.recipe.CraftingRecipe;
|
||||
import net.Indyuce.mmoitems.api.crafting.recipe.UpgradingRecipe;
|
||||
import net.Indyuce.mmoitems.api.item.util.ConfigItems;
|
||||
import net.Indyuce.mmoitems.api.util.message.Message;
|
||||
import net.Indyuce.mmoitems.util.MMOUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@ -46,7 +46,7 @@ public class CraftingStationPreview extends PluginInventory {
|
||||
public Inventory getInventory() {
|
||||
|
||||
// Create inventory of a nice size (5x6)
|
||||
Inventory inv = Bukkit.createInventory(this, 45, MythicLib.plugin.getPlaceholderParser().parse(getPlayer(), Message.RECIPE_PREVIEW.formatRaw(ChatColor.RESET)));
|
||||
Inventory inv = Bukkit.createInventory(this, 45, MythicLib.plugin.getPlaceholderParser().parse(getPlayer(), Message.RECIPE_PREVIEW.format(ChatColor.RESET).toString()));
|
||||
ingredients.clear();
|
||||
|
||||
// Include each ingredient
|
||||
|
Loading…
Reference in New Issue
Block a user