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HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH THIS TOOK ME AGES well mabe chomens moment but fabric is gay mabe btw am i gay!??!/1?! probably not but mabe mabe chipmunk is trans.,,.,.,.,. am i trans?!/1?!/?! mabe mabe probably no too., well ok bye luv you <3
This commit is contained in:
parent
ea460eed12
commit
b4ac35b28d
8 changed files with 50 additions and 156 deletions
|
@ -44,7 +44,7 @@ public class ChipmunkMod implements ModInitializer {
|
|||
final File file = CONFIG_FILE;
|
||||
|
||||
if (!file.exists()) {
|
||||
InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("default_config.json");
|
||||
InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("assets/chipmunkmod/default_config.json");
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
package land.chipmunk.chipmunkmod.command;
|
||||
|
||||
import land.chipmunk.chipmunkmod.util.ComponentUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import com.mojang.brigadier.Message;
|
||||
import lombok.Getter;
|
||||
|
||||
public class ComponentMessage implements Message {
|
||||
@Getter private final Component component;
|
||||
|
||||
private ComponentMessage (Component component) {
|
||||
this.component = component;
|
||||
}
|
||||
|
||||
public static ComponentMessage wrap (Component component) {
|
||||
return new ComponentMessage(component);
|
||||
}
|
||||
|
||||
public String getString () {
|
||||
return ComponentUtilities.stringify(component);
|
||||
}
|
||||
|
||||
public String toString () {
|
||||
return component.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package land.chipmunk.chipmunkmod.command;
|
||||
|
||||
import com.mojang.brigadier.Message;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
public class TextMessage implements Message {
|
||||
@Getter private final Text text;
|
||||
|
||||
private TextMessage(Text text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public static TextMessage wrap (Text text) {
|
||||
return new TextMessage(text);
|
||||
}
|
||||
|
||||
public String getString () {
|
||||
return text.getString();
|
||||
}
|
||||
|
||||
public String toString () {
|
||||
return text.toString();
|
||||
}
|
||||
}
|
|
@ -1,22 +1,23 @@
|
|||
package land.chipmunk.chipmunkmod.command.arguments;
|
||||
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import land.chipmunk.chipmunkmod.command.ComponentMessage;
|
||||
import java.util.Collection;
|
||||
import java.util.Arrays;
|
||||
import java.net.URL;
|
||||
import land.chipmunk.chipmunkmod.command.TextMessage;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
public class LocationArgumentType implements ArgumentType<Object> {
|
||||
private static final Collection<String> EXAMPLES = Arrays.<String>asList("songs/amogus.mid", "images/cat.jpg", "videos/badapple.mp4");
|
||||
|
||||
private static final SimpleCommandExceptionType OOB_FILEPATH = new SimpleCommandExceptionType(ComponentMessage.wrap(Component.translatable("The specified file path is outside of the allowed directory")));
|
||||
private static final SimpleCommandExceptionType OOB_FILEPATH = new SimpleCommandExceptionType(TextMessage.wrap(Text.translatable("The specified file path is outside of the allowed directory")));
|
||||
|
||||
private boolean allowsUrls = false;
|
||||
private boolean allowsPaths = false;
|
||||
|
@ -51,7 +52,7 @@ public class LocationArgumentType implements ArgumentType<Object> {
|
|||
try {
|
||||
return new URL(sb.toString());
|
||||
} catch (MalformedURLException exception) {
|
||||
throw new SimpleCommandExceptionType(ComponentMessage.wrap(Component.text(exception.getMessage()))).create();
|
||||
throw new SimpleCommandExceptionType(TextMessage.wrap(Text.literal(exception.getMessage()))).create();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import com.mojang.brigadier.context.CommandContext;
|
|||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||
import land.chipmunk.chipmunkmod.command.CommandManager;
|
||||
import land.chipmunk.chipmunkmod.command.ComponentMessage;
|
||||
import land.chipmunk.chipmunkmod.command.TextMessage;
|
||||
import land.chipmunk.chipmunkmod.modules.SongPlayer;
|
||||
import land.chipmunk.chipmunkmod.song.Song;
|
||||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
|
||||
|
@ -34,9 +34,9 @@ import static land.chipmunk.chipmunkmod.command.arguments.LocationArgumentType.*
|
|||
import static land.chipmunk.chipmunkmod.command.arguments.TimestampArgumentType.timestamp;
|
||||
|
||||
public class MusicCommand {
|
||||
private static SimpleCommandExceptionType NO_SONG_IS_CURRENTLY_PLAYING = new SimpleCommandExceptionType(ComponentMessage.wrap(Component.translatable("No song is currently playing")));
|
||||
private static SimpleCommandExceptionType OOB_TIMESTAMP = new SimpleCommandExceptionType(ComponentMessage.wrap(Component.translatable("Invalid timestamp for the current song")));
|
||||
private static SimpleCommandExceptionType DIRECTORY_DOES_NOT_EXIST = new SimpleCommandExceptionType(ComponentMessage.wrap(Component.translatable("The specified directory does not exist")));
|
||||
private static final SimpleCommandExceptionType NO_SONG_IS_CURRENTLY_PLAYING = new SimpleCommandExceptionType(TextMessage.wrap(Text.translatable("No song is currently playing")));
|
||||
private static final SimpleCommandExceptionType OOB_TIMESTAMP = new SimpleCommandExceptionType(TextMessage.wrap(Text.translatable("Invalid timestamp for the current song")));
|
||||
private static final SimpleCommandExceptionType DIRECTORY_DOES_NOT_EXIST = new SimpleCommandExceptionType(TextMessage.wrap(Text.translatable("The specified directory does not exist")));
|
||||
|
||||
public static void register (CommandDispatcher<FabricClientCommandSource> dispatcher) {
|
||||
final MusicCommand instance = new MusicCommand();
|
||||
|
@ -196,8 +196,8 @@ public class MusicCommand {
|
|||
}
|
||||
|
||||
final ArrayList<Component> mergedList = new ArrayList<>();
|
||||
for (Component component : directories) mergedList.add(component);
|
||||
for (Component component : files) mergedList.add(component);
|
||||
mergedList.addAll(directories);
|
||||
mergedList.addAll(files);
|
||||
final Component component = Component.translatable("Songs - %s", Component.join(JoinConfiguration.separator(Component.space()), mergedList)).color(NamedTextColor.GREEN);
|
||||
|
||||
MinecraftClient.getInstance().player.sendMessage(component);
|
||||
|
|
|
@ -1,24 +1,23 @@
|
|||
package land.chipmunk.chipmunkmod.song;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import lombok.Getter;
|
||||
import land.chipmunk.chipmunkmod.util.ComponentUtilities;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
public class SongLoaderException extends Exception {
|
||||
@Getter private final Component message;
|
||||
@Getter private final Text message;
|
||||
|
||||
public SongLoaderException (Component message) {
|
||||
public SongLoaderException (Text message) {
|
||||
super();
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public SongLoaderException (Component message, Throwable cause) {
|
||||
public SongLoaderException (Text message, Throwable cause) {
|
||||
super(null, cause);
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage () {
|
||||
return ComponentUtilities.stringify(message);
|
||||
return message.getString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,9 +2,9 @@ package land.chipmunk.chipmunkmod.song;
|
|||
|
||||
import land.chipmunk.chipmunkmod.modules.SongPlayer;
|
||||
import land.chipmunk.chipmunkmod.util.DownloadUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Files;
|
||||
|
@ -41,7 +41,7 @@ public class SongLoaderThread extends Thread {
|
|||
name = songPath.getName();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
exception = new SongLoaderException(Component.text(e.getMessage()), e);
|
||||
exception = new SongLoaderException(Text.literal(e.getMessage()), e);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ public class SongLoaderThread extends Thread {
|
|||
}
|
||||
|
||||
if (song == null) {
|
||||
exception = new SongLoaderException(Component.translatable("Invalid song format"));
|
||||
exception = new SongLoaderException(Text.translatable("Invalid song format"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,105 +0,0 @@
|
|||
package land.chipmunk.chipmunkmod.util;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.TranslatableComponent;
|
||||
import net.kyori.adventure.text.SelectorComponent;
|
||||
import net.kyori.adventure.text.KeybindComponent;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ComponentUtilities {
|
||||
private static final Map<String, String> language = loadJsonStringMap("language.json");
|
||||
private static final Map<String, String> keybinds = loadJsonStringMap("keybinds.json");
|
||||
|
||||
public static final Pattern ARG_PATTERN = Pattern.compile("%(?:(\\d+)\\$)?(s|%)");
|
||||
|
||||
private ComponentUtilities () {
|
||||
}
|
||||
|
||||
private static Map<String, String> loadJsonStringMap (String name) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
|
||||
InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream(name);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||
JsonObject json = JsonParser.parseReader(reader).getAsJsonObject();
|
||||
|
||||
for (Map.Entry<String, JsonElement> entry : json.entrySet()) {
|
||||
map.put(entry.getKey(), json.get(entry.getKey()).getAsString());
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
private static String getOrReturnKey (Map<String, String> map, String key) {
|
||||
return map.containsKey(key) ? map.get(key) : key;
|
||||
}
|
||||
|
||||
public static String stringify (Component message) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append(stringifyPartially(message));
|
||||
|
||||
for (Component child : message.children()) builder.append(stringify(child));
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static String stringifyPartially (Component message) {
|
||||
if (message instanceof TextComponent) return stringifyPartially((TextComponent) message);
|
||||
if (message instanceof TranslatableComponent) return stringifyPartially((TranslatableComponent) message);
|
||||
if (message instanceof SelectorComponent) return stringifyPartially((SelectorComponent) message);
|
||||
if (message instanceof KeybindComponent) return stringifyPartially((KeybindComponent) message);
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String stringifyPartially (TextComponent message) {
|
||||
return message.content();
|
||||
}
|
||||
|
||||
public static String stringifyPartially (TranslatableComponent message) {
|
||||
String format = getOrReturnKey(language, message.key());
|
||||
|
||||
// totallynotskidded™️ from HBot (and changed a bit)
|
||||
Matcher matcher = ARG_PATTERN.matcher(format);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
int i = 0;
|
||||
while (matcher.find()) {
|
||||
if (matcher.group().equals("%%")) {
|
||||
matcher.appendReplacement(sb, "%");
|
||||
} else {
|
||||
String idxStr = matcher.group(1);
|
||||
int idx = idxStr == null ? i++ : (Integer.parseInt(idxStr) - 1);
|
||||
if (idx >= 0 && idx < message.args().size()) {
|
||||
matcher.appendReplacement(sb, Matcher.quoteReplacement( stringify(message.args().get(idx)) ));
|
||||
} else {
|
||||
matcher.appendReplacement(sb, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
matcher.appendTail(sb);
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String stringifyPartially (SelectorComponent message) {
|
||||
return message.pattern(); // * Client-side selector components are equivalent to text ones, and do NOT list entities.
|
||||
}
|
||||
|
||||
public static String stringifyPartially (KeybindComponent message) {
|
||||
String keybind = message.keybind();
|
||||
Component component = keybinds.containsKey(keybind) ? Component.translatable(keybind) : Component.text(keybind); // TODO: Fix some keys like `key.keyboard.a`
|
||||
return stringifyPartially(component);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue