mirror of
https://github.com/Oth3r/Sit.git
synced 2025-09-19 16:03:22 +02:00
otterlib language system
This commit is contained in:
parent
c8902c5138
commit
85cc76a022
9 changed files with 69 additions and 172 deletions
16
src/main/java/one/oth3r/sit/utl/Chat.java
Normal file
16
src/main/java/one/oth3r/sit/utl/Chat.java
Normal file
|
@ -0,0 +1,16 @@
|
|||
package one.oth3r.sit.utl;
|
||||
|
||||
import one.oth3r.otterlib.chat.CTxT;
|
||||
import one.oth3r.sit.file.FileData;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class Chat {
|
||||
public static CTxT tag() {
|
||||
return new CTxT("Sit!").btn(true).color(Color.decode("#c400ff")).append(" ");
|
||||
}
|
||||
|
||||
public static CTxT lang(String key, Object... args) {
|
||||
return FileData.getLangReader().dynamicTranslatable(key, args);
|
||||
}
|
||||
}
|
|
@ -23,7 +23,6 @@ import net.minecraft.util.ActionResult;
|
|||
import one.oth3r.sit.SitClient;
|
||||
import one.oth3r.sit.command.SitCommand;
|
||||
import one.oth3r.sit.file.FileData;
|
||||
import one.oth3r.sit.file.LangReader;
|
||||
import one.oth3r.sit.file.SittingConfig;
|
||||
import one.oth3r.sit.packet.SitPayloads;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
@ -78,7 +77,7 @@ public class Events {
|
|||
player.networkHandler.sendCommand("sit");
|
||||
} else {
|
||||
// unsupported server message if not in a Sit! server
|
||||
player.sendMessage(Utl.lang("sit!.chat.unsupported")
|
||||
player.sendMessage(Chat.lang("sit!.chat.unsupported")
|
||||
.color(Color.RED).b(), true);
|
||||
}
|
||||
}
|
||||
|
@ -104,7 +103,7 @@ public class Events {
|
|||
ServerPlayNetworking.send(context.player(),new SitPayloads.ResponsePayload(SitPayloads.ResponsePayload.VERSION));
|
||||
|
||||
// log the receiving of the packet from the player
|
||||
Data.LOGGER.info(Utl.lang("sit!.console.player_settings",context.player().getName().getString()).toString());
|
||||
Data.LOGGER.info(Chat.lang("sit!.console.player_settings",context.player().getName().getString()).toString());
|
||||
})));
|
||||
}
|
||||
|
||||
|
@ -114,7 +113,7 @@ public class Events {
|
|||
// only update when needed
|
||||
if (!Data.isSupportedServer()) {
|
||||
Data.setSupportedServer(true);
|
||||
Data.LOGGER.info(Utl.lang("sit!.console.connected",payload.value()).toString());
|
||||
Data.LOGGER.info(Chat.lang("sit!.console.connected",payload.value()).toString());
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
@ -172,7 +171,6 @@ public class Events {
|
|||
private static void serverLifecycle() {
|
||||
ServerLifecycleEvents.SERVER_STARTED.register(s -> {
|
||||
Data.setServer(s);
|
||||
LangReader.loadLanguageFile();
|
||||
|
||||
// right click on block event
|
||||
UseBlockCallback.EVENT.register((pl, world, hand, hitResult) -> {
|
||||
|
|
|
@ -201,7 +201,6 @@ public class Logic {
|
|||
public static void reload() {
|
||||
FileData.loadFiles();
|
||||
FileData.saveFiles();
|
||||
LangReader.loadLanguageFile();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -228,11 +227,11 @@ public class Logic {
|
|||
Formatting messageColor = config.getEnabled()?Formatting.GREEN:Formatting.RED;
|
||||
|
||||
// send the player the actionbar message
|
||||
return Utl.lang("sit!.chat.toggle_sit",
|
||||
Utl.lang(messageKey).color(config.getEnabled()? Color.GREEN : Color.RED)).b();
|
||||
return Chat.lang("sit!.chat.toggle_sit",
|
||||
Chat.lang(messageKey).color(config.getEnabled()? Color.GREEN : Color.RED)).b();
|
||||
} else {
|
||||
// unsupported server message if not in a Sit! server
|
||||
return Utl.lang("sit!.chat.unsupported")
|
||||
return Chat.lang("sit!.chat.unsupported")
|
||||
.color(Color.RED).b();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -281,35 +281,14 @@ public class Utl {
|
|||
|
||||
// send a message if needed
|
||||
if (message) {
|
||||
player.sendMessage(messageTag()
|
||||
.append(lang("sit!.chat.purged",lang("sit!.chat.purged.total",count).color(Color.gray).b()).color(Color.GREEN)).b());
|
||||
player.sendMessage(Chat.tag()
|
||||
.append(Chat.lang("sit!.chat.purged",
|
||||
Chat.lang("sit!.chat.purged.total",count).color(Color.gray).b()
|
||||
).color(Color.GREEN)).b());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static CTxT messageTag() {
|
||||
return new CTxT("Sit!").btn(true).color(Color.decode("#c400ff")).append(" ");
|
||||
}
|
||||
|
||||
/**
|
||||
* gets a MutableText using the language key, if on server, using the custom lang reader
|
||||
*/
|
||||
public static CTxT lang(String key, Object... args) {
|
||||
if (Data.isClient()) {
|
||||
// we have to first convert all the CTxT's to the built version because minecraft lang reader doesn't know how to process it
|
||||
// make a array with the same size of the args
|
||||
Object[] fixedArgs = new Object[args.length];
|
||||
// for every arg, build & add if CTxT or just add if not
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
if (args[i] instanceof CTxT) fixedArgs[i] = ((CTxT) args[i]).b();
|
||||
else fixedArgs[i] = args[i];
|
||||
}
|
||||
// return the translated text
|
||||
return new CTxT(Text.translatable(key,fixedArgs));
|
||||
}
|
||||
else return LangReader.of(key, args).getTxT();
|
||||
}
|
||||
|
||||
/**
|
||||
* sends the settings packets to the server, if client & in game
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue