Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adventure Chat Integration [EXPERIMENT] #4971

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ allprojects {
dependencies {
shadow group: 'io.papermc', name: 'paperlib', version: '1.0.8'
shadow group: 'org.bstats', name: 'bstats-bukkit', version: '3.0.2'
shadow group: 'net.kyori', name: 'adventure-text-serializer-bungeecord', version: '4.3.0'
shadow group: 'net.kyori', name: 'adventure-text-minimessage', version: '4.14.0'
shadow group: 'net.kyori', name: 'adventure-platform-bukkit', version: '4.3.0'
shadow group: 'net.kyori', name: 'adventure-text-serializer-plain', version: '4.14.0'

implementation group: 'io.papermc.paper', name: 'paper-api', version: '1.20.1-R0.1-SNAPSHOT'
implementation group: 'org.eclipse.jdt', name: 'org.eclipse.jdt.annotation', version: '2.2.700'
Expand Down Expand Up @@ -85,14 +87,9 @@ tasks.withType(ShadowJar) {
configurations = [
project.configurations.shadow
]
dependencies {
include(dependency('io.papermc:paperlib'))
include(dependency('org.bstats:bstats-bukkit'))
include(dependency('org.bstats:bstats-base'))
include(dependency('net.kyori:adventure-text-serializer-bungeecord'))
}
relocate 'io.papermc.lib', 'ch.njol.skript.paperlib'
relocate 'org.bstats', 'ch.njol.skript.bstats'
relocate 'net.kyori', 'org.skriptlang.kyori'
manifest {
attributes(
'Name': 'ch/njol/skript',
Expand Down
57 changes: 38 additions & 19 deletions src/main/java/ch/njol/skript/Skript.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@
import java.util.zip.ZipException;
import java.util.zip.ZipFile;

import ch.njol.skript.lang.Section;
import ch.njol.skript.localization.LanguageChangeListener;
import org.skriptlang.skript.bukkit.chat.ChatModule;
import org.skriptlang.skript.bukkit.chat.util.ComponentHandler;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SimplePie;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -104,7 +110,6 @@
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.ExpressionInfo;
import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.lang.Section;
import ch.njol.skript.lang.SkriptEvent;
import ch.njol.skript.lang.SkriptEventInfo;
import ch.njol.skript.lang.Statement;
Expand Down Expand Up @@ -542,6 +547,7 @@ public void onEnable() {
try {
getAddonInstance().loadClasses("ch.njol.skript",
"conditions", "effects", "events", "expressions", "entity", "sections", "structures");
new ChatModule().register(getAddonInstance()); // TODO remove eventually
} catch (final Exception e) {
exception(e, "Could not load required .class files: " + e.getLocalizedMessage());
setEnabled(false);
Expand Down Expand Up @@ -1843,43 +1849,56 @@ static void logEx(final String... lines) {
SkriptLogger.LOGGER.severe(EXCEPTION_PREFIX + line);
}

private static final Message SKRIPT_PREFIX_MESSAGE = new Message("skript.prefix");
private static Component SKRIPT_PREFIX_COMPONENT;
private static String SKRIPT_PREFIX;

static {
SKRIPT_PREFIX = "<grey>[<gold>Skript<grey>]<reset> ";
SKRIPT_PREFIX_COMPONENT = ComponentHandler.parse(SKRIPT_PREFIX);
Language.addListener(() -> {
String prefix = Language.get_("skript.prefix");
if (prefix != null) {
SKRIPT_PREFIX = prefix;
SKRIPT_PREFIX_COMPONENT = ComponentHandler.parse(SKRIPT_PREFIX);
}
});
}

public static String getSkriptPrefix() {
return SKRIPT_PREFIX_MESSAGE.getValueOrDefault("<grey>[<gold>Skript<grey>] <reset>");
return SKRIPT_PREFIX;
}

public static void info(final CommandSender sender, final String info) {
sender.sendMessage(Utils.replaceEnglishChatStyles(getSkriptPrefix() + info));
public static void info(CommandSender sender, String info) {
ComponentHandler.audienceFrom(sender).sendMessage(SKRIPT_PREFIX_COMPONENT.append(ComponentHandler.parse(info)));
}

/**
* @param message
* @param permission
* @see #adminBroadcast(String)
*/
public static void broadcast(final String message, final String permission) {
Bukkit.broadcast(Utils.replaceEnglishChatStyles(getSkriptPrefix() + message), permission);
public static void broadcast(String message, String permission) {
Bukkit.broadcast(getSkriptPrefix() + ComponentHandler.toLegacyString(message, false), permission);
}
public static void adminBroadcast(final String message) {
broadcast(message, "skript.admin");

public static void adminBroadcast(String message) {
Bukkit.broadcast(getSkriptPrefix() + ComponentHandler.toLegacyString(message, false), "skript.admin");
}

/**
* Similar to {@link #info(CommandSender, String)} but no [Skript] prefix is added.
*
* @param sender
* @param info
*/
public static void message(final CommandSender sender, final String info) {
sender.sendMessage(Utils.replaceEnglishChatStyles(info));
public static void message(CommandSender sender, String info) {
ComponentHandler.audienceFrom(sender).sendMessage(ComponentHandler.parse(info));
}
public static void error(final CommandSender sender, final String error) {
sender.sendMessage(Utils.replaceEnglishChatStyles(getSkriptPrefix() + ChatColor.DARK_RED + error));

public static void error(CommandSender sender, String error) {
ComponentHandler.audienceFrom(sender).sendMessage(SKRIPT_PREFIX_COMPONENT.append(ComponentHandler.parse(error).color(NamedTextColor.DARK_RED)));
}

/**
* Gets the updater instance currently used by Skript.
* @return SkriptUpdater instance.
Expand All @@ -1888,5 +1907,5 @@ public static void error(final CommandSender sender, final String error) {
public SkriptUpdater getUpdater() {
return updater;
}

}
4 changes: 2 additions & 2 deletions src/main/java/ch/njol/skript/classes/data/JavaClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
import ch.njol.skript.localization.Message;
import ch.njol.skript.localization.RegexMessage;
import ch.njol.skript.registrations.Classes;
import ch.njol.skript.util.Utils;
import ch.njol.util.StringUtils;
import ch.njol.yggdrasil.Fields;
import org.skriptlang.skript.bukkit.chat.util.ComponentHandler;
import org.eclipse.jdt.annotation.Nullable;

import java.util.regex.Pattern;
Expand Down Expand Up @@ -573,7 +573,7 @@ public String parse(String s, ParseContext context) {
case SCRIPT:
case EVENT:
if (VariableString.isQuotedCorrectly(s, true))
return Utils.replaceChatStyles("" + s.substring(1, s.length() - 1).replace("\"\"", "\""));
return ComponentHandler.toLegacyString("" + s.substring(1, s.length() - 1).replace("\"\"", "\""), false);
return null;
case COMMAND:
return s;
Expand Down
45 changes: 17 additions & 28 deletions src/main/java/ch/njol/skript/command/ScriptCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import java.util.Set;
import java.util.UUID;

import org.skriptlang.skript.bukkit.chat.util.ComponentHandler;
import net.kyori.adventure.text.Component;
import ch.njol.skript.ScriptLoader;
import ch.njol.skript.config.SectionNode;
import org.skriptlang.skript.lang.script.Script;
Expand Down Expand Up @@ -71,9 +73,6 @@
import ch.njol.skript.util.Date;
import ch.njol.skript.util.EmptyStacktraceException;
import ch.njol.skript.util.Timespan;
import ch.njol.skript.util.Utils;
import ch.njol.skript.util.chat.BungeeConverter;
import ch.njol.skript.util.chat.MessageComponent;
import ch.njol.skript.variables.Variables;
import ch.njol.util.StringUtils;
import ch.njol.util.Validate;
Expand All @@ -93,15 +92,15 @@ public class ScriptCommand implements TabExecutor {
private List<String> activeAliases;
private String permission;
private final VariableString permissionMessage;
private final String description;
private final Component description;
private final String prefix;
@Nullable
private final Timespan cooldown;
private final Expression<String> cooldownMessage;
private final String cooldownBypass;
@Nullable
private final Expression<String> cooldownStorage;
final String usage;
private final Component usage;

private final Trigger trigger;

Expand Down Expand Up @@ -179,8 +178,8 @@ public ScriptCommand(
this.aliases = aliases;
activeAliases = new ArrayList<>(aliases);

this.description = Utils.replaceEnglishChatStyles(description);
this.usage = Utils.replaceEnglishChatStyles(usage);
this.description = ComponentHandler.parse(description);
this.usage = ComponentHandler.parse(usage);

this.executableBy = executableBy;

Expand All @@ -190,24 +189,20 @@ public ScriptCommand(
trigger = new Trigger(script, "command /" + name, new SimpleEvent(), ScriptLoader.loadItems(node));
trigger.setLineNumber(node.getLine());

bukkitCommand = setupBukkitCommand();
}

private PluginCommand setupBukkitCommand() {
try {
final Constructor<PluginCommand> c = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class);
Constructor<PluginCommand> c = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class);
c.setAccessible(true);
final PluginCommand bukkitCommand = c.newInstance(name, Skript.getInstance());
bukkitCommand.setAliases(aliases);
PluginCommand bukkitCommand = c.newInstance(name, Skript.getInstance());
bukkitCommand.setAliases(this.aliases);
bukkitCommand.setDescription(description);
bukkitCommand.setLabel(label);
bukkitCommand.setPermission(permission);
bukkitCommand.setLabel(this.label);
bukkitCommand.setPermission(this.permission);
// We can only set the message if it's simple (doesn't contains expressions)
if (permissionMessage.isSimple())
bukkitCommand.setPermissionMessage(permissionMessage.toString(null));
if (this.permissionMessage.isSimple())
bukkitCommand.setPermissionMessage(this.permissionMessage.toString(null));
bukkitCommand.setUsage(usage);
bukkitCommand.setExecutor(this);
return bukkitCommand;
this.bukkitCommand = bukkitCommand;
} catch (final Exception e) {
Skript.outdatedError(e);
throw new EmptyStacktraceException();
Expand Down Expand Up @@ -238,13 +233,7 @@ public boolean execute(final CommandSender sender, final String commandLabel, fi
final ScriptCommandEvent event = new ScriptCommandEvent(ScriptCommand.this, sender, commandLabel, rest);

if (!permission.isEmpty() && !sender.hasPermission(permission)) {
if (sender instanceof Player) {
List<MessageComponent> components =
permissionMessage.getMessageComponents(event);
((Player) sender).spigot().sendMessage(BungeeConverter.convert(components));
} else {
sender.sendMessage(permissionMessage.getSingle(event));
}
ComponentHandler.audienceFrom(sender).sendMessage(ComponentHandler.parseFromSingleExpression(event, permissionMessage));
return false;
}

Expand Down Expand Up @@ -318,8 +307,8 @@ boolean execute2(final ScriptCommandEvent event, final CommandSender sender, fin
}

public void sendHelp(final CommandSender sender) {
if (!description.isEmpty())
sender.sendMessage(description);
if (!Component.IS_NOT_EMPTY.test(description))
ComponentHandler.audienceFrom(sender).sendMessage(description);
sender.sendMessage(ChatColor.GOLD + "Usage" + ChatColor.RESET + ": " + usage);
}

Expand Down
78 changes: 0 additions & 78 deletions src/main/java/ch/njol/skript/effects/EffActionBar.java

This file was deleted.

Loading