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

⚒️ Replace color char in debug statements #4630

Merged
Merged
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
7 changes: 4 additions & 3 deletions src/main/java/ch/njol/skript/ScriptLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import ch.njol.skript.sections.SecLoop;
import ch.njol.skript.util.Date;
import ch.njol.skript.util.ExceptionUtils;
import ch.njol.skript.util.SkriptColor;
import ch.njol.skript.util.Task;
import ch.njol.skript.variables.TypeHints;
import ch.njol.skript.variables.Variables;
Expand Down Expand Up @@ -741,7 +742,7 @@ private static ScriptInfo loadScript(@Nullable Config config) {
continue;

if (Skript.debug() || node.debug())
Skript.debug(event + " (" + parsedEvent.getSecond().toString(null, true) + "):");
Skript.debug(SkriptColor.replaceColorChar(event + " (" + parsedEvent.getSecond().toString(null, true) + "):"));

Class<? extends Event>[] eventClasses = parsedEvent.getSecond().getEventClasses();
if (eventClasses == null)
Expand Down Expand Up @@ -1115,7 +1116,7 @@ public static ArrayList<TriggerItem> loadItems(SectionNode node) {
continue;

if (Skript.debug() || n.debug())
Skript.debug(getParser().getIndentation() + stmt.toString(null, true));
Skript.debug(SkriptColor.replaceColorChar(getParser().getIndentation() + stmt.toString(null, true)));

items.add(stmt);
} else if (n instanceof SectionNode) {
Expand All @@ -1129,7 +1130,7 @@ public static ArrayList<TriggerItem> loadItems(SectionNode node) {
continue;

if (Skript.debug() || n.debug())
Skript.debug(getParser().getIndentation() + section.toString(null, true));
Skript.debug(SkriptColor.replaceColorChar(getParser().getIndentation() + section.toString(null, true)));

items.add(section);

Expand Down
13 changes: 7 additions & 6 deletions src/main/java/ch/njol/skript/command/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import ch.njol.skript.util.SkriptColor;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
Expand Down Expand Up @@ -282,27 +283,27 @@ static boolean handleEffectCommand(final CommandSender sender, String command) {
log.clear(); // ignore warnings and stuff
log.printLog();
if (!effectCommand.isCancelled()) {
sender.sendMessage(ChatColor.GRAY + "executing '" + ChatColor.stripColor(command) + "'");
sender.sendMessage(ChatColor.GRAY + "executing '" + SkriptColor.replaceColorChar(command) + "'");
if (SkriptConfig.logPlayerCommands.value() && !(sender instanceof ConsoleCommandSender))
Skript.info(sender.getName() + " issued effect command: " + command);
Skript.info(sender.getName() + " issued effect command: " + SkriptColor.replaceColorChar(command));
TriggerItem.walk(effect, effectCommand);
Variables.removeLocals(effectCommand);
} else {
sender.sendMessage(ChatColor.RED + "your effect command '" + ChatColor.stripColor(command) + "' was cancelled.");
sender.sendMessage(ChatColor.RED + "your effect command '" + SkriptColor.replaceColorChar(command) + "' was cancelled.");
}
} else {
if (sender == Bukkit.getConsoleSender()) // log as SEVERE instead of INFO like printErrors below
SkriptLogger.LOGGER.severe("Error in: " + ChatColor.stripColor(command));
SkriptLogger.LOGGER.severe("Error in: " + SkriptColor.replaceColorChar(command));
else
sender.sendMessage(ChatColor.RED + "Error in: " + ChatColor.GRAY + ChatColor.stripColor(command));
sender.sendMessage(ChatColor.RED + "Error in: " + ChatColor.GRAY + SkriptColor.replaceColorChar(command));
log.printErrors(sender, "(No specific information is available)");
}
} finally {
log.stop();
}
return true;
} catch (final Exception e) {
Skript.exception(e, "Unexpected error while executing effect command '" + command + "' by '" + sender.getName() + "'");
Skript.exception(e, "Unexpected error while executing effect command '" + SkriptColor.replaceColorChar(command) + "' by '" + sender.getName() + "'");
sender.sendMessage(ChatColor.RED + "An internal error occurred while executing this effect. Please refer to the server log for details.");
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/ch/njol/skript/lang/TriggerItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.io.File;

import ch.njol.skript.util.SkriptColor;
import org.bukkit.event.Event;
import org.eclipse.jdt.annotation.Nullable;

Expand Down Expand Up @@ -124,7 +125,7 @@ public String getIndentation() {
protected final void debug(final Event e, final boolean run) {
if (!Skript.debug())
return;
Skript.debug(getIndentation() + (run ? "" : "-") + toString(e, true));
Skript.debug(SkriptColor.replaceColorChar(getIndentation() + (run ? "" : "-") + toString(e, true)));
}

@Override
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/ch/njol/skript/util/SkriptColor.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;

import org.bukkit.ChatColor;
import org.bukkit.DyeColor;
Expand Down Expand Up @@ -62,7 +63,7 @@ public enum SkriptColor implements Color {

DARK_PURPLE(DyeColor.PURPLE, ChatColor.DARK_PURPLE),
LIGHT_PURPLE(DyeColor.MAGENTA, ChatColor.LIGHT_PURPLE);

private final static Map<String, SkriptColor> names = new HashMap<>();
private final static Set<SkriptColor> colors = new HashSet<>();
private final static String LANGUAGE_NODE = "colors";
Expand Down Expand Up @@ -219,7 +220,18 @@ public static SkriptColor fromWoolData(short data) {
}
return null;
}


/**
* Replace chat color character '§' with '&'
* This is an alternative method to {@link ChatColor#stripColor(String)}
* But does not strip the color code.
* @param s string to replace chat color character of.
* @return String with replaced chat color character
*/
public static String replaceColorChar(String s) {
return s.replace('\u00A7', '&');
}

@Override
public String toString() {
return adjective == null ? "" + name() : adjective.toString(-1, 0);
Expand Down