Skip to content

Commit

Permalink
Stonecutter autoreformat, updating gradle.properties, fix ServerComma…
Browse files Browse the repository at this point in the history
…ndManager, fix en_us translation, logging methods placed in a separate class "PatLogger" (hehe)
  • Loading branch information
nikita51bot committed Nov 27, 2024
1 parent a8e229a commit 0735f3a
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 101 deletions.
46 changes: 46 additions & 0 deletions src/main/java/net/lopymine/patpat/PatLogger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package net.lopymine.patpat;

//? >=1.17 {
import org.slf4j.*;
//?}

public class PatLogger {

//? >=1.17 {
private final Logger logger;
//?} else {
/*private final String name;
*///?}

public PatLogger(String name){
//? >=1.17 {
logger = LoggerFactory.getLogger(name);
//?} else {
/*this.name = name;
*///?}
}

public void info(String text, Object... args) {
//? >=1.17 {
logger.info(text, args);
//?} else {
/*System.out.println("[%s/INFO] ".formatted(name) + text.replace("{}", "%s").formatted(args));
*///?}
}

public void warn(String text, Object... args) {
//? >=1.17 {
logger.warn(text, args);
//?} else {
/*System.out.println("[%s/WARN] ".formatted(name) + text.replace("{}", "%s").formatted(args));
*///?}
}

public void error(String text, Object... args) {
//? >=1.17 {
logger.error(text, args);
//?} else {
/*System.out.println("[%s/ERROR] ".formatted(name) + text.replace("{}", "%s").formatted(args));
*///?}
}
}
40 changes: 3 additions & 37 deletions src/main/java/net/lopymine/patpat/PatPat.java
Original file line number Diff line number Diff line change
@@ -1,63 +1,29 @@
package net.lopymine.patpat;

import lombok.Getter;
import net.minecraft.text.MutableText;

import net.fabricmc.api.ModInitializer;

import net.lopymine.patpat.config.server.PatPatServerConfig;
import net.lopymine.patpat.manager.PatPatConfigManager;
import net.lopymine.patpat.manager.server.*;
import net.lopymine.patpat.utils.TextUtils;

//? >=1.17 {
import org.slf4j.*;
//?}

public class PatPat implements ModInitializer {

public static final String MOD_VERSION = /*$ mod_version*/ "1.0.1";
public static final String MOD_NAME = /*$ mod_name*/ "PatPat";
public static final String MOD_ID = /*$ mod_id*/ "patpat";
//? >=1.17
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_NAME);

public static final PatLogger LOGGER = new PatLogger(MOD_NAME);
@Getter
private static PatPatServerConfig config = PatPatServerConfig.getInstance();

public static void info(String text, Object... args) {
//? >=1.17 {
LOGGER.info(text, args);
//?} else {
/*System.out.println("[%s/INFO].formatted(MOD_NAME) " + text.replace("{}", "%s").formatted(args));
*///?}
}

public static void warn(String text, Object... args) {
//? >=1.17 {
LOGGER.warn(text, args);
//?} else {
/*System.out.println("[%s/WARN].formatted(MOD_NAME) " + text.replace("{}", "%s").formatted(args));
*///?}
}

public static void error(String text, Object... args) {
//? >=1.17 {
LOGGER.error(text, args);
//?} else {
/*System.out.println("[%s/ERROR] ".formatted(MOD_NAME) + text.replace("{}", "%s").formatted(args));
*///?}
}

public static MutableText text(String path, Object... args) {
return TextUtils.translatable(String.format("%s.%s", MOD_ID, path), args);
}

@Override
public void onInitialize() {
PatPat.config = PatPatServerConfig.getInstance();
PatPatConfigManager.onInitialize();
PatPatServerCommandManager.register();
PatPatServerPacketManager.register();
info("PatPat Initialized");
PatPat.LOGGER.info("PatPat Initialized");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import java.util.UUID;

//? <=1.20.1 {
/*import net.minecraft.network.PacketByteBuf;*/
//?}
/*import net.minecraft.network.PacketByteBuf;
*///?}

public class ReplayModCompat {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ public static PatPatServerConfig getInstance() {
private static @NotNull PatPatServerConfig create() {
PatPatServerConfig config = new PatPatServerConfig();
try (FileWriter writer = new FileWriter(CONFIG_FILE, StandardCharsets.UTF_8)) {
String json = GSON.toJson(CODEC.encode(config, JsonOps.INSTANCE, JsonOps.INSTANCE.empty())/*? if >=1.20.5 {*/.getOrThrow());/*?} else*//*.getOrThrow(false, PatPat::error));*/
String json = GSON.toJson(CODEC.encode(config, JsonOps.INSTANCE, JsonOps.INSTANCE.empty())/*? if >=1.20.5 {*/.getOrThrow());/*?} else*//*.getOrThrow(false, PatPat.LOGGER::error));*/
writer.write(json);
} catch (Exception e) {
PatPat.error("Failed to create config", e);
PatPat.LOGGER.error("Failed to create config", e);
}
return config;
}
Expand All @@ -62,20 +62,20 @@ private static PatPatServerConfig read() {
}

try (FileReader reader = new FileReader(CONFIG_FILE, StandardCharsets.UTF_8)) {
return CODEC.decode(JsonOps.INSTANCE, /*? <=1.17.1 {*//*new JsonParser().parse(reader)*//*?} else {*/JsonParser.parseReader(reader)/*?}*/)/*? if >=1.20.5 {*/.getOrThrow()/*?} else {*//*.getOrThrow(false, PatPat::error)*//*?}*/.getFirst();
return CODEC.decode(JsonOps.INSTANCE, /*? <=1.17.1 {*//*new JsonParser().parse(reader)*//*?} else {*/JsonParser.parseReader(reader)/*?}*/)/*? if >=1.20.5 {*/.getOrThrow()/*?} else {*//*.getOrThrow(false, PatPat.LOGGER::error)*//*?}*/.getFirst();
} catch (Exception e) {
PatPat.error("Failed to read config", e);
PatPat.LOGGER.error("Failed to read config", e);
}
return PatPatServerConfig.create();
}

public void save() {
CompletableFuture.runAsync(() -> {
try (FileWriter writer = new FileWriter(CONFIG_FILE, StandardCharsets.UTF_8)) {
String json = GSON.toJson(CODEC.encode(this, JsonOps.INSTANCE, JsonOps.INSTANCE.empty())/*? if >=1.20.5 {*/.getOrThrow());/*?} else*//*.getOrThrow(false, PatPat::error));*/
String json = GSON.toJson(CODEC.encode(this, JsonOps.INSTANCE, JsonOps.INSTANCE.empty())/*? if >=1.20.5 {*/.getOrThrow());/*?} else*//*.getOrThrow(false, PatPat.LOGGER::error));*/
writer.write(json);
} catch (Exception e) {
PatPat.error("Failed to save config", e);
PatPat.LOGGER.error("Failed to save config", e);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static void onInitialize() {
return;
}
if (file.mkdirs()) {
PatPat.info("Successfully created PatPat config folder");
PatPat.LOGGER.info("Successfully created PatPat config folder");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static void register() {
}
*///?}
dispatcher.register(literal("patpat")
.requires((context) -> context.hasPermissionLevel(2))
.requires(context -> context.hasPermissionLevel(2))
.then(literal("list")
.then(literal("set")
.then(argument("mode", StringArgumentType.word())
Expand Down Expand Up @@ -88,9 +88,9 @@ private static int onListChange(CommandContext<ServerCommandSource> context, boo

context.getSource().sendFeedback(/*? >=1.20 {*/() -> PATPAT_ID.copy().append(text)/*?} else {*//*PATPAT_ID.copy().append(text)*//*?}*/, true);
if (success) {
PatPat.info(text.asString());
PatPat.LOGGER.info(text.asString());
} else {
PatPat.info(text.asString());
PatPat.LOGGER.warn(text.asString());
}
}

Expand Down Expand Up @@ -119,9 +119,9 @@ private static int onSetListMode(CommandContext<ServerCommandSource> context) {
Text text = builder.build();
context.getSource().sendFeedback(/*? >=1.20 {*/() -> PATPAT_ID.copy().append(text)/*?} else {*//*PATPAT_ID.copy().append(text)*//*?}*/, true);
if (success) {
PatPat.info(text.asString());
PatPat.LOGGER.info(text.asString());
} else {
PatPat.info(text.asString());
PatPat.LOGGER.warn(text.asString());
}
return success ? Command.SINGLE_SUCCESS : 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
import net.fabricmc.fabric.api.networking.v1.*;

import net.lopymine.patpat.PatPat;
import net.lopymine.patpat.client.PatPatClient;
import net.lopymine.patpat.config.resourcepack.ListMode;
import net.lopymine.patpat.config.server.PatPatServerConfig;
import net.lopymine.patpat.packet.*;

//? <=1.19.3 {
/*import net.minecraft.network.PacketByteBuf;*/
//?}
/*import net.minecraft.network.PacketByteBuf;
*///?}

public class PatPatServerPacketManager {

Expand Down Expand Up @@ -45,7 +44,7 @@ public static void register() {
return;
}
if (entity.isInvisible()) {
PatPat.warn("Received packet from client, {} patted {}, but patted entity is invisible! This shouldn't happens because it should checks at client-side!", sender.getName(), entity.getName());
PatPat.LOGGER.warn("Received packet from client, {} patted {}, but patted entity is invisible! This shouldn't happens because it should checks at client-side!", sender.getName(), entity.getName());
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ private void render(EntityRenderState state, MatrixStack matrices, VertexConsume
//?}
PatPatClientConfig config = PatPatClient.getConfig();
if (!config.isModEnabled()) {
return/*? <1.21.2 {*//* bl*//*?}*/;
return/*? <1.21.2 {*/ /*bl*//*?}*/;
}
//? >=1.21.2 {
EntityRenderStateWithParent stateWithParent = (EntityRenderStateWithParent) state;
Entity entity = stateWithParent.patPat$getEntity();
float tickDelta = stateWithParent.patPat$getTickDelta();
//?}
if (!(entity instanceof LivingEntity livingEntity)) {
return/*? <1.21.2 {*//* bl*//*?}*/;
return/*? <1.21.2 {*/ /*bl*//*?}*/;
}
PatEntity patEntity = PatPatClientManager.getPatEntity(livingEntity);
if (patEntity == null) {
return/*? <1.21.2 {*//* bl*//*?}*/;
return/*? <1.21.2 {*/ /*bl*//*?}*/;
}

//? <=1.20.4 {
Expand Down
Loading

0 comments on commit 0735f3a

Please sign in to comment.