forked from ChomeNS/chipmunkmod
some updates yea
interesting stuff ,,.,.,.
This commit is contained in:
parent
16b8582732
commit
24f7e08e4c
4 changed files with 67 additions and 37 deletions
|
@ -14,5 +14,5 @@ org.gradle.parallel=true
|
||||||
archives_base_name = chipmunkmod
|
archives_base_name = chipmunkmod
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
fabric_version=0.76.0+1.19.4
|
fabric_version=0.80.0+1.19.4
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,8 @@ public class ChipmunkMod implements ModInitializer {
|
||||||
// That way, it's clear which mod wrote info, warnings, and errors.
|
// That way, it's clear which mod wrote info, warnings, and errors.
|
||||||
public static final Logger LOGGER = LoggerFactory.getLogger("chipmunkmod");
|
public static final Logger LOGGER = LoggerFactory.getLogger("chipmunkmod");
|
||||||
public static Configuration CONFIG;
|
public static Configuration CONFIG;
|
||||||
|
private static File CONFIG_DIR = new File("config");
|
||||||
|
private static File CONFIG_FILE = new File(CONFIG_DIR, "chipmunkmod.json");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize () {
|
public void onInitialize () {
|
||||||
|
@ -27,7 +29,6 @@ public class ChipmunkMod implements ModInitializer {
|
||||||
// Proceed with mild caution.
|
// Proceed with mild caution.
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new File("config").mkdirs(); // TODO: Clean this up
|
|
||||||
CONFIG = loadConfig();
|
CONFIG = loadConfig();
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
throw new RuntimeException("Could not load the config", exception);
|
throw new RuntimeException("Could not load the config", exception);
|
||||||
|
@ -36,12 +37,14 @@ public class ChipmunkMod implements ModInitializer {
|
||||||
LOGGER.info("Hello Fabric world!");
|
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 Gson gson = new Gson();
|
||||||
final File file = new File("config/chipmunkmod.json");
|
final File file = CONFIG_FILE;
|
||||||
|
|
||||||
if (!file.exists()) {
|
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));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||||
|
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
|
|
|
@ -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 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 displayName = GsonComponentSerializer.gson().serialize(Component.join(JoinConfiguration.separator(Component.empty()), displayNameComponent.children().get(1)));
|
||||||
|
|
||||||
final String sanitizedFormat = format
|
String sanitizedFormat;
|
||||||
.replace("{\"text\":\"PREFIX\"}", prefix)
|
try {
|
||||||
.replace("{\"text\":\"DISPLAYNAME\"}", displayName)
|
sanitizedFormat = format
|
||||||
|
.replace("\"PREFIX\"", prefix)
|
||||||
|
.replace("\"DISPLAYNAME\"", displayName)
|
||||||
.replace("USERNAME", username)
|
.replace("USERNAME", username)
|
||||||
.replace("MESSAGE", sanitizedMessage);
|
.replace("MESSAGE", sanitizedMessage);
|
||||||
|
} catch (Exception e) {
|
||||||
|
sanitizedFormat = format
|
||||||
|
.replace("USERNAME", username)
|
||||||
|
.replace("MESSAGE", sanitizedMessage);
|
||||||
|
}
|
||||||
|
|
||||||
CommandCore.INSTANCE.run("minecraft:tellraw @a " + sanitizedFormat);
|
CommandCore.INSTANCE.run("minecraft:tellraw @a " + sanitizedFormat);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -52,17 +52,25 @@ public class Players extends Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void packetReceived (PlayerRemoveS2CPacket packet) {
|
public void packetReceived (PlayerRemoveS2CPacket packet) {
|
||||||
|
try {
|
||||||
for (UUID uuid : packet.profileIds()) {
|
for (UUID uuid : packet.profileIds()) {
|
||||||
removePlayer(uuid);
|
removePlayer(uuid);
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final MutablePlayerListEntry getEntry (UUID uuid) {
|
public final MutablePlayerListEntry getEntry (UUID uuid) {
|
||||||
|
try {
|
||||||
for (MutablePlayerListEntry candidate : list) {
|
for (MutablePlayerListEntry candidate : list) {
|
||||||
if (candidate.profile().getId().equals(uuid)) {
|
if (candidate.profile().getId().equals(uuid)) {
|
||||||
return candidate;
|
return candidate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -92,17 +100,25 @@ public class Players extends Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addPlayer (PlayerListS2CPacket.Entry newEntry) {
|
private void addPlayer (PlayerListS2CPacket.Entry newEntry) {
|
||||||
|
try {
|
||||||
final MutablePlayerListEntry duplicate = getEntry(newEntry);
|
final MutablePlayerListEntry duplicate = getEntry(newEntry);
|
||||||
if (duplicate != null) list.remove(duplicate);
|
if (duplicate != null) list.remove(duplicate);
|
||||||
|
|
||||||
list.add(new MutablePlayerListEntry(newEntry));
|
list.add(new MutablePlayerListEntry(newEntry));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateGamemode (PlayerListS2CPacket.Entry newEntry) {
|
private void updateGamemode (PlayerListS2CPacket.Entry newEntry) {
|
||||||
|
try {
|
||||||
final MutablePlayerListEntry target = getEntry(newEntry);
|
final MutablePlayerListEntry target = getEntry(newEntry);
|
||||||
if (target == null) return;
|
if (target == null) return;
|
||||||
|
|
||||||
target.gamemode(newEntry.gameMode());
|
target.gamemode(newEntry.gameMode());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateLatency (PlayerListS2CPacket.Entry newEntry) {
|
private void updateLatency (PlayerListS2CPacket.Entry newEntry) {
|
||||||
|
@ -120,6 +136,7 @@ public class Players extends Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removePlayer (UUID uuid) {
|
private void removePlayer (UUID uuid) {
|
||||||
|
try {
|
||||||
final MutablePlayerListEntry target = getEntry(uuid);
|
final MutablePlayerListEntry target = getEntry(uuid);
|
||||||
if (target == null) return;
|
if (target == null) return;
|
||||||
|
|
||||||
|
@ -142,5 +159,8 @@ public class Players extends Listener {
|
||||||
list.remove(target);
|
list.remove(target);
|
||||||
return packet;
|
return packet;
|
||||||
});
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue