Skip to content
Open
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
47 changes: 18 additions & 29 deletions src/main/java/dev/intensed/fallback/api/LoggerAPI.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,28 @@
package dev.intensed.fallback.api;

import net.minecraft.network.chat.Component;
import net.minecraft.server.MinecraftServer;

public final class LoggerAPI {
public final class LoggerAPI{
private static MinecraftServer server;

private LoggerAPI() {
private LoggerAPI(){}
public static void initialize(MinecraftServer minecraftServer){server=minecraftServer;}
public static void info(String author,String message){
if(author==null||message==null)return;
LoggerAPI.send(Component.literal(("["+DateAPI.time()+"] ")).withStyle(style->style.withColor(5476815)).append(Component.literal("[main/INFO] ").withStyle(style->style.withColor(6919485)).append(Component.literal(("(" + author + ") ")).withStyle(style->style.withColor(4759714)).append(Component.literal(message).withStyle(style->style.withColor(12369603))))));
}

public static void initialize(MinecraftServer minecraftServer) {
server = minecraftServer;
public static void success(String author,String message){
if(author==null||message==null)return;
LoggerAPI.send(Component.literal(("["+DateAPI.time()+"] ")).withStyle(style->style.withColor(5476815)).append(Component.literal("[main/SUCCESS] ").withStyle(style->style.withColor(6919485)).append(Component.literal(("("+author+") ")).withStyle(style->style.withColor(4759714)).append(Component.literal(message).withStyle(style->style.withColor(12369603))))));
}

public static void info(String author, String message) {
LoggerAPI.send(Component.literal(("[" + DateAPI.time() + "] ")).withStyle(style -> style.withColor(5476815)).append(Component.literal("[main/INFO] ").withStyle(style -> style.withColor(6919485)).append(Component.literal(("(" + author + ") ")).withStyle(style -> style.withColor(4759714)).append(Component.literal(message).withStyle(style -> style.withColor(12369603))))));
public static void warn(String author,String message){
if(author==null||message==null)return;
LoggerAPI.send(Component.literal(("["+DateAPI.time()+"] ")).withStyle(style->style.withColor(5476815)).append(Component.literal("[main/WARN] ").withStyle(style->style.withColor(10586927)).append(Component.literal(("("+author+") ")).withStyle(style->style.withColor(4759714)).append(Component.literal(message).withStyle(style->style.withColor(12369603))))));
}

public static void success(String author, String message) {
LoggerAPI.send(Component.literal(("[" + DateAPI.time() + "] ")).withStyle(style -> style.withColor(5476815)).append(Component.literal("[main/SUCCESS] ").withStyle(style -> style.withColor(6919485)).append(Component.literal(("(" + author + ") ")).withStyle(style -> style.withColor(4759714)).append(Component.literal(message).withStyle(style -> style.withColor(12369603))))));
public static void error(String author,String message){
if(author==null||message==null)return;
LoggerAPI.send(Component.literal(("["+DateAPI.time()+"] ")).withStyle(style->style.withColor(5476815)).append(Component.literal("[main/ERROR] ").withStyle(style->style.withColor(14572886)).append(Component.literal(("("+author+") ")).withStyle(style->style.withColor(4759714)).append(Component.literal(message).withStyle(style->style.withColor(12369603))))));
}

public static void warn(String author, String message) {
LoggerAPI.send(Component.literal(("[" + DateAPI.time() + "] ")).withStyle(style -> style.withColor(5476815)).append(Component.literal("[main/WARN] ").withStyle(style -> style.withColor(10586927)).append(Component.literal(("(" + author + ") ")).withStyle(style -> style.withColor(4759714)).append(Component.literal(message).withStyle(style -> style.withColor(12369603))))));
}

public static void error(String author, String message) {
LoggerAPI.send(Component.literal(("[" + DateAPI.time() + "] ")).withStyle(style -> style.withColor(5476815)).append(Component.literal("[main/ERROR] ").withStyle(style -> style.withColor(14572886)).append(Component.literal(("(" + author + ") ")).withStyle(style -> style.withColor(4759714)).append(Component.literal(message).withStyle(style -> style.withColor(12369603))))));
}

private static void send(Component message) {
if (server == null) {
return;
}
server.getPlayerList().broadcastSystemMessage(message, false);
private static void send(Component message){
if(message==null||server==null)return;
server.getPlayerList().broadcastSystemMessage(message,false);
}
}

32 changes: 12 additions & 20 deletions src/main/java/dev/intensed/fallback/api/RandomDialogAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,26 @@ public static int execute(CommandSourceStack source, int from, int to, String pr
available.add(number);
}
if (available.isEmpty()) {
source.sendFailure(Component.literal(("No unused dialogs are available for " + prefix + ".")));
source.sendFailure(Component.literal(("No unused dialogs are available for "+prefix+".")));
return 0;
}
int selected = available.get(ThreadLocalRandom.current().nextInt(available.size()));
scoreName = RandomDialogAPI.getScoreName(prefix, selected);
int selected=available.get(ThreadLocalRandom.current().nextInt(available.size()));
scoreName=RandomDialogAPI.getScoreName(prefix, selected);
if(scoreName==null)return 0; // you can put smth else here if you want to handle null differently; this exists cuz i noticed your code would just have a heart attack and explode if scoreName was null so i added this to prevent that ^w^
scoreboard.getOrCreatePlayerScore(ScoreHolder.forNameOnly(scoreName), objective).set(1);
String command = "dialog show " + player + " " + prefix + ":" + selected;
String command="dialog show "+player+" "+prefix+":"+selected;
server.getCommands().performPrefixedCommand(source, command);
return 1;
}

private static String getScoreName(String prefix, int number) {
return prefix + ":" + number;
private static String getScoreName(String prefix,int number){
return prefix+":"+number;
}

public static List<Integer> parseBlocked(String input) {
String[] values;
ArrayList<Integer> blocked = new ArrayList<Integer>();
if (input == null || input.isBlank()) {
return blocked;
}
for (String value : values = input.split(",")) {
try {
blocked.add(Integer.parseInt(value.trim()));
}
catch (NumberFormatException numberFormatException) {
// empty catch block
}
ArrayList<Integer> blocked=new ArrayList<>();
if(input==null||input.isBlank())return blocked;
for(String value:input.split(",")){
try{blocked.add(Integer.parseInt(value.trim()));}
catch(NumberFormatException ignored){/*empty catch block*/}
}
return blocked;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package dev.intensed.fallback.client;

import org.jspecify.annotations.NonNull;
import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;

public class FallbackDataGenerator
implements DataGeneratorEntrypoint {
public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) {
FabricDataGenerator.Pack pack = fabricDataGenerator.createPack();
implements DataGeneratorEntrypoint{
public void onInitializeDataGenerator(@NonNull FabricDataGenerator fabricDataGenerator){
FabricDataGenerator.Pack pack=fabricDataGenerator.createPack();
}
}