some updates yea

interesting stuff ,,.,.,.
This commit is contained in:
Chayapak 2023-05-04 13:16:20 +07:00
parent 16b8582732
commit 24f7e08e4c
4 changed files with 67 additions and 37 deletions

View file

@ -14,5 +14,5 @@ org.gradle.parallel=true
archives_base_name = chipmunkmod
# Dependencies
fabric_version=0.76.0+1.19.4
fabric_version=0.80.0+1.19.4

View file

@ -19,6 +19,8 @@ public class ChipmunkMod implements ModInitializer {
// That way, it's clear which mod wrote info, warnings, and errors.
public static final Logger LOGGER = LoggerFactory.getLogger("chipmunkmod");
public static Configuration CONFIG;
private static File CONFIG_DIR = new File("config");
private static File CONFIG_FILE = new File(CONFIG_DIR, "chipmunkmod.json");
@Override
public void onInitialize () {
@ -27,7 +29,6 @@ public class ChipmunkMod implements ModInitializer {
// Proceed with mild caution.
try {
new File("config").mkdirs(); // TODO: Clean this up
CONFIG = loadConfig();
} catch (IOException exception) {
throw new RuntimeException("Could not load the config", exception);
@ -36,12 +37,14 @@ public class ChipmunkMod implements ModInitializer {
LOGGER.info("Hello Fabric world!");
}
public static Configuration loadConfig () throws IOException {
private static Configuration loadConfig () throws IOException {
CONFIG_DIR.mkdirs();
final Gson gson = new Gson();
final File file = new File("config/chipmunkmod.json");
final File file = CONFIG_FILE;
if (!file.exists()) {
InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("assets/chipmunkmod/default_config.json");
InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("default_config.json");
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
final StringBuilder sb = new StringBuilder();

View file

@ -45,11 +45,18 @@ public class CustomChat {
final String prefix = GsonComponentSerializer.gson().serialize(Component.join(JoinConfiguration.separator(Component.empty()), displayNameComponent.children().get(0)));
final String displayName = GsonComponentSerializer.gson().serialize(Component.join(JoinConfiguration.separator(Component.empty()), displayNameComponent.children().get(1)));
final String sanitizedFormat = format
.replace("{\"text\":\"PREFIX\"}", prefix)
.replace("{\"text\":\"DISPLAYNAME\"}", displayName)
String sanitizedFormat;
try {
sanitizedFormat = format
.replace("\"PREFIX\"", prefix)
.replace("\"DISPLAYNAME\"", displayName)
.replace("USERNAME", username)
.replace("MESSAGE", sanitizedMessage);
} catch (Exception e) {
sanitizedFormat = format
.replace("USERNAME", username)
.replace("MESSAGE", sanitizedMessage);
}
CommandCore.INSTANCE.run("minecraft:tellraw @a " + sanitizedFormat);
} catch (Exception e) {

View file

@ -52,17 +52,25 @@ public class Players extends Listener {
}
public void packetReceived (PlayerRemoveS2CPacket packet) {
try {
for (UUID uuid : packet.profileIds()) {
removePlayer(uuid);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public final MutablePlayerListEntry getEntry (UUID uuid) {
try {
for (MutablePlayerListEntry candidate : list) {
if (candidate.profile().getId().equals(uuid)) {
return candidate;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@ -92,17 +100,25 @@ public class Players extends Listener {
}
private void addPlayer (PlayerListS2CPacket.Entry newEntry) {
try {
final MutablePlayerListEntry duplicate = getEntry(newEntry);
if (duplicate != null) list.remove(duplicate);
list.add(new MutablePlayerListEntry(newEntry));
} catch (Exception e) {
e.printStackTrace();
}
}
private void updateGamemode (PlayerListS2CPacket.Entry newEntry) {
try {
final MutablePlayerListEntry target = getEntry(newEntry);
if (target == null) return;
target.gamemode(newEntry.gameMode());
} catch (Exception e) {
e.printStackTrace();
}
}
private void updateLatency (PlayerListS2CPacket.Entry newEntry) {
@ -120,6 +136,7 @@ public class Players extends Listener {
}
private void removePlayer (UUID uuid) {
try {
final MutablePlayerListEntry target = getEntry(uuid);
if (target == null) return;
@ -142,5 +159,8 @@ public class Players extends Listener {
list.remove(target);
return packet;
});
} catch (Exception e) {
e.printStackTrace();
}
}
}