Upgraded message util.
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
30
.idea/jarRepositories.xml
generated
Normal file
30
.idea/jarRepositories.xml
generated
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="MavenRepo" />
|
||||
<option name="name" value="MavenRepo" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="papermc-repo" />
|
||||
<option name="name" value="papermc-repo" />
|
||||
<option name="url" value="https://repo.papermc.io/repository/maven-public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="sonatype" />
|
||||
<option name="name" value="sonatype" />
|
||||
<option name="url" value="https://oss.sonatype.org/content/groups/public/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
||||
1
.idea/modules.xml
generated
1
.idea/modules.xml
generated
@@ -3,6 +3,7 @@
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/ArmorSMP.main.iml" filepath="$PROJECT_DIR$/.idea/modules/ArmorSMP.main.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/me.trouper.ArmorSMP.main.iml" filepath="$PROJECT_DIR$/.idea/modules/me.trouper.ArmorSMP.main.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
4
.idea/modules/ArmorSMP.main.iml
generated
4
.idea/modules/ArmorSMP.main.iml
generated
@@ -11,4 +11,8 @@
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
14
.idea/modules/me.trouper.ArmorSMP.main.iml
generated
Normal file
14
.idea/modules/me.trouper.ArmorSMP.main.iml
generated
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="minecraft" name="Minecraft">
|
||||
<configuration>
|
||||
<autoDetectTypes>
|
||||
<platformType>PAPER</platformType>
|
||||
<platformType>ADVENTURE</platformType>
|
||||
</autoDetectTypes>
|
||||
<projectReimportVersion>1</projectReimportVersion>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
</module>
|
||||
124
.idea/uiDesigner.xml
generated
Normal file
124
.idea/uiDesigner.xml
generated
Normal file
@@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
||||
Binary file not shown.
BIN
libs/PDK-1.4.0.jar
Normal file
BIN
libs/PDK-1.4.0.jar
Normal file
Binary file not shown.
@@ -8,26 +8,58 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Config implements JsonSerializable<Config> {
|
||||
|
||||
public String mainColor = "�ff00";
|
||||
public String prefix = "&9ArmorSMP> &7";
|
||||
public String pluginName = "ArmorSMP";
|
||||
|
||||
|
||||
@Override
|
||||
public File getFile() {
|
||||
return ArmorSMP.getInstance().getManager().io.CONFIG_FILE;
|
||||
}
|
||||
|
||||
public boolean fancyAlerts = true;
|
||||
|
||||
public boolean maceCraftingeEnabled = true;
|
||||
|
||||
public String mainColor = "�ff00";
|
||||
public String prefix = "&9ArmorSMP> &7";
|
||||
public String pluginName = "ArmorSMP";
|
||||
public boolean fancyAlerts = true;
|
||||
|
||||
public Tips tips = new Tips();
|
||||
public class Tips {
|
||||
public boolean tipsEnabled = true;
|
||||
public List<String> tipList = Arrays.asList(
|
||||
"Tips1",
|
||||
"Tips2",
|
||||
"Tips3"
|
||||
"Kill players to obtain Armor Upgraders and progress through armor tiers!",
|
||||
"Right-click an Armor Upgrader to upgrade your armor to the next tier!",
|
||||
"When you die, you'll drop an Armor Upgrader and be downgraded one tier.",
|
||||
"Enchants stay when upgrading armor, but are lost when downgrading after death.",
|
||||
"Armor cannot be crafted, removed, dropped, or moved in your inventory!",
|
||||
"Found armor in the world cannot be equipped - you must use the upgrade system.",
|
||||
"Craft Armor Upgraders using diamond blocks, ominous keys, and enchanted golden apples!",
|
||||
"Netherite armor and tools are special event rewards with powerful abilities!",
|
||||
"The Dragon Egg grants a special Netherite Chestplate with the Bad Breath ability!",
|
||||
"Bad Breath summons damaging dragon breath for 7 seconds with a 50-second cooldown.",
|
||||
"Netherite Helmet grants 5 extra hearts and permanent Fire Resistance!",
|
||||
"Use Back Up ability (Netherite Leggings) to create a protective shield for 10 seconds.",
|
||||
"Dash forward 10 blocks with Netherite Boots' ability (30-second cooldown).",
|
||||
"Netherite Sword's Go Wild gives 7 seconds of Strength 2 for massive damage!",
|
||||
"Activate Rampage with Netherite Axe for 5 seconds of Haste 6 attacks!",
|
||||
"Trust players to prevent your abilities from affecting them with /trust commands.",
|
||||
"The Mace is a powerful weapon that can only be crafted once when enabled!",
|
||||
"Netherite items cannot be stored in containers - they must be kept in your inventory.",
|
||||
"Losing Netherite items makes you lose their abilities - be careful when dropping them!",
|
||||
"Use /armorsmp commands to manage armor tiers and special items (OPs only).",
|
||||
"Higher armor tiers provide better protection and more powerful abilities!",
|
||||
"Strategize with teammates - trusted players won't be affected by your abilities!",
|
||||
"The Dragon Egg holder becomes a high-value target - protect your Netherite Chestplate!",
|
||||
"Combine abilities for powerful combos - Dash in then use Go Wild for surprise attacks!",
|
||||
"Manage your cooldowns wisely - abilities are powerful but have long wait times.",
|
||||
"Upgrade through all tiers: None → Leather → Chainmail → Gold → Iron → Diamond!",
|
||||
"Players with no armor (naked) don't drop Armor Upgraders when killed.",
|
||||
"Your armor progress is saved even when you log out or the server restarts!",
|
||||
"Netherite tools have both combat utility and special abilities - use them wisely!",
|
||||
"The Mace's Wind Burst can knock enemies away while you maintain Speed 1!",
|
||||
"Ominous Keys are valuable - save them for crafting Armor Upgraders!",
|
||||
"Higher tier armor makes you a bigger target - balance protection with strategy!",
|
||||
"Use terrain to your advantage while abilities are on cooldown!",
|
||||
"Team up to take down players with Netherite gear and share the upgrades!",
|
||||
"The End and Nether can be disabled by admins to focus on overworld PvP!"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package me.trouper.armorsmp.server.commands;
|
||||
|
||||
import io.github.itzispyder.pdk.commands.Args;
|
||||
import io.github.itzispyder.pdk.commands.CommandRegistry;
|
||||
import io.github.itzispyder.pdk.commands.CustomCommand;
|
||||
import io.github.itzispyder.pdk.commands.Permission;
|
||||
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
|
||||
import me.trouper.armorsmp.utils.Text;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandRegistry(value = "armorsmp_give", permission = @Permission("armorsmp.give"))
|
||||
public class GiveCommand implements CustomCommand {
|
||||
|
||||
@Override
|
||||
public void dispatchCommand(CommandSender commandSender, Command command, String label, Args args) {
|
||||
String target = args.get(0).toString();
|
||||
Player t = Bukkit.getPlayer(target);
|
||||
if (t == null) {
|
||||
Text.sendError((Player) commandSender);
|
||||
return;
|
||||
}
|
||||
switch (label) {
|
||||
case "neth_axe" -> {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispatchCompletions(CommandSender commandSender, Command command, String label, CompletionBuilder completionBuilder) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package me.trouper.armorsmp.server.commands;
|
||||
|
||||
import io.github.itzispyder.pdk.commands.Args;
|
||||
import io.github.itzispyder.pdk.commands.CustomCommand;
|
||||
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class MaceToggleCommand implements CustomCommand {
|
||||
@Override
|
||||
public void dispatchCommand(CommandSender commandSender, Command command, String s, Args args) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispatchCompletions(CommandSender commandSender, Command command, String s, CompletionBuilder completionBuilder) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package me.trouper.armorsmp.server.events;
|
||||
|
||||
import io.github.itzispyder.pdk.events.CustomListener;
|
||||
import me.trouper.armorsmp.utils.Text;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.inventory.CraftItemEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class CraftEvent implements CustomListener {
|
||||
|
||||
@EventHandler
|
||||
public void onCraft(CraftItemEvent e) {
|
||||
final ItemStack result = e.getRecipe().getResult();
|
||||
final String name = result.getType().name();
|
||||
final Player p = (Player) e.getWhoClicked();
|
||||
|
||||
if (!name.contains("HELMET")
|
||||
&& !name.contains("CHESTPLATE")
|
||||
&& !name.contains("LEGGINGS")
|
||||
&& !name.contains("BOOTS")
|
||||
&& !name.contains("NETHERITE_AXE")
|
||||
&& !name.contains("NETHERITE_SWORD")
|
||||
&& !name.contains("NETHERITE_SHOVEL")
|
||||
&& !name.contains("NETHERITE_HOE")
|
||||
&& !name.contains("NETHERITE_PICKAXE")
|
||||
) return;
|
||||
|
||||
e.setCancelled(true);
|
||||
p.closeInventory();
|
||||
Text.sendWarning(p,"You are not allowed to craft {0}.",name);
|
||||
}
|
||||
}
|
||||
@@ -2,16 +2,15 @@ package me.trouper.armorsmp.utils;
|
||||
|
||||
import io.github.itzispyder.pdk.utils.misc.Randomizer;
|
||||
import me.trouper.armorsmp.ArmorSMP;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -24,41 +23,27 @@ public class Text {
|
||||
public static Component color(String msg) {
|
||||
return LegacyComponentSerializer.legacyAmpersand().deserialize(msg);
|
||||
}
|
||||
|
||||
public static String getActiveFormatting(String text) {
|
||||
final Pattern pattern = Pattern.compile("&[0-9a-fk-or]");
|
||||
final Matcher matcher = pattern.matcher(text);
|
||||
|
||||
String lastColor = "";
|
||||
Set<Character> activeFormats = new HashSet<>();
|
||||
|
||||
while (matcher.find()) {
|
||||
String code = matcher.group();
|
||||
char identifier = code.charAt(1);
|
||||
|
||||
if (identifier >= '0' && identifier <= '9' || identifier >= 'a' && identifier <= 'f') {
|
||||
lastColor = code;
|
||||
activeFormats.clear();
|
||||
} else if (identifier >= 'k' && identifier <= 'o') {
|
||||
activeFormats.add(identifier);
|
||||
} else if (identifier == 'r') {
|
||||
lastColor = "";
|
||||
activeFormats.clear();
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder result = new StringBuilder(lastColor);
|
||||
for (char format : activeFormats) {
|
||||
result.append("&").append(format);
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
|
||||
public static void sendWarning(Player player,String warning, Object... args) {
|
||||
sendMessage(Pallet.WARNING,player,warning,false,args);
|
||||
}
|
||||
|
||||
public static void sendError(Player player, String error, Object... args) {
|
||||
sendMessage(Pallet.ERROR,player,error,false,args);
|
||||
}
|
||||
|
||||
public static void sendMessage(Player player, String text, boolean allowTip, Object... args) {
|
||||
sendMessage(Pallet.NEUTRAL,player,text,allowTip,args);
|
||||
}
|
||||
|
||||
public static void sendMessage(Pallet pallet, Player player, String text, boolean allowTip, Object... args) {
|
||||
text = formatArgs(pallet,text,args);
|
||||
sendMessage(player,text,allowTip);
|
||||
}
|
||||
|
||||
public static void sendMessage(Player player, String text, boolean allowTip) {
|
||||
Component message = getMessage(text,allowTip && ArmorSMP.getInstance().getManager().io.config.tips.tipsEnabled && !ArmorSMP.getInstance().getManager().io.storage.userData.tipsDisabled.contains(player.getUniqueId().toString()));
|
||||
allowTip = allowTip && ArmorSMP.getInstance().getManager().io.config.tips.tipsEnabled && !ArmorSMP.getInstance().getManager().io.storage.userData.tipsDisabled.contains(player.getUniqueId().toString());
|
||||
Component message = getMessage(text,allowTip);
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
@@ -70,7 +55,38 @@ public class Text {
|
||||
}
|
||||
}
|
||||
|
||||
public static String formatArgs(Pallet pallet, String format, Object... args) {
|
||||
Component message = Component.empty();
|
||||
Pattern pattern = Pattern.compile("\\{(\\d+)}");
|
||||
Matcher matcher = pattern.matcher(format);
|
||||
int lastIndex = 0;
|
||||
|
||||
while (matcher.find()) {
|
||||
String prefix = format.substring(lastIndex, matcher.start());
|
||||
if (!prefix.isEmpty()) {
|
||||
message = message.append(Component.text(prefix).color(pallet.mainText));
|
||||
}
|
||||
|
||||
int argIndex = Integer.parseInt(matcher.group(1));
|
||||
TextColor argColor = getArgColor(pallet, argIndex);
|
||||
|
||||
if (argIndex >= 0 && argIndex < args.length) {
|
||||
String argText = args[argIndex].toString();
|
||||
message = message.append(Component.text(argText).color(argColor));
|
||||
} else {
|
||||
message = message.append(Component.text(matcher.group()).color(pallet.mainText));
|
||||
}
|
||||
|
||||
lastIndex = matcher.end();
|
||||
}
|
||||
|
||||
String suffix = format.substring(lastIndex);
|
||||
if (!suffix.isEmpty()) {
|
||||
message = message.append(Component.text(suffix).color(pallet.mainText));
|
||||
}
|
||||
|
||||
return LegacyComponentSerializer.legacyAmpersand().serialize(message);
|
||||
}
|
||||
|
||||
public static Component formatFancyMessage(String text,boolean addTip) {
|
||||
Component message = Component.empty().appendNewline();
|
||||
@@ -139,6 +155,87 @@ public class Text {
|
||||
return lines;
|
||||
}
|
||||
|
||||
public static String getActiveFormatting(String text) {
|
||||
final Pattern pattern = Pattern.compile("&[0-9a-fk-or]");
|
||||
final Matcher matcher = pattern.matcher(text);
|
||||
|
||||
String lastColor = "";
|
||||
Set<Character> activeFormats = new HashSet<>();
|
||||
|
||||
while (matcher.find()) {
|
||||
String code = matcher.group();
|
||||
char identifier = code.charAt(1);
|
||||
|
||||
if (identifier >= '0' && identifier <= '9' || identifier >= 'a' && identifier <= 'f') {
|
||||
lastColor = code;
|
||||
activeFormats.clear();
|
||||
} else if (identifier >= 'k' && identifier <= 'o') {
|
||||
activeFormats.add(identifier);
|
||||
} else if (identifier == 'r') {
|
||||
lastColor = "";
|
||||
activeFormats.clear();
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder result = new StringBuilder(lastColor);
|
||||
for (char format : activeFormats) {
|
||||
result.append("&").append(format);
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private static TextColor getArgColor(Pallet pallet, int argIndex) {
|
||||
return switch (argIndex) {
|
||||
case 1 -> pallet.arg2;
|
||||
case 2 -> pallet.arg3;
|
||||
default -> pallet.argDefault;
|
||||
};
|
||||
}
|
||||
|
||||
public enum Pallet {
|
||||
ERROR(
|
||||
NamedTextColor.RED,
|
||||
NamedTextColor.YELLOW,
|
||||
NamedTextColor.GOLD,
|
||||
NamedTextColor.DARK_RED
|
||||
),
|
||||
WARNING(
|
||||
NamedTextColor.YELLOW,
|
||||
NamedTextColor.GOLD,
|
||||
NamedTextColor.RED,
|
||||
NamedTextColor.DARK_RED
|
||||
),
|
||||
INFO(
|
||||
NamedTextColor.GRAY,
|
||||
NamedTextColor.WHITE,
|
||||
NamedTextColor.AQUA,
|
||||
NamedTextColor.DARK_AQUA
|
||||
),
|
||||
SUCCESS(
|
||||
NamedTextColor.GREEN,
|
||||
NamedTextColor.DARK_GREEN,
|
||||
NamedTextColor.YELLOW,
|
||||
NamedTextColor.GOLD
|
||||
),
|
||||
NEUTRAL(
|
||||
NamedTextColor.GRAY,
|
||||
NamedTextColor.WHITE,
|
||||
NamedTextColor.DARK_AQUA,
|
||||
NamedTextColor.BLUE
|
||||
);
|
||||
|
||||
private final TextColor mainText;
|
||||
private final TextColor argDefault;
|
||||
private final TextColor arg2;
|
||||
private final TextColor arg3;
|
||||
|
||||
Pallet(TextColor mainText, TextColor argDefault, TextColor arg2, TextColor arg3) {
|
||||
this.mainText = mainText;
|
||||
this.argDefault = argDefault;
|
||||
this.arg2 = arg2;
|
||||
this.arg3 = arg3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user