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
|
||||
|
||||
# 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.
|
||||
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();
|
||||
|
|
|
@ -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)
|
||||
.replace("USERNAME", username)
|
||||
.replace("MESSAGE", sanitizedMessage);
|
||||
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) {
|
||||
|
|
|
@ -52,16 +52,24 @@ public class Players extends Listener {
|
|||
}
|
||||
|
||||
public void packetReceived (PlayerRemoveS2CPacket packet) {
|
||||
for (UUID uuid : packet.profileIds()) {
|
||||
removePlayer(uuid);
|
||||
try {
|
||||
for (UUID uuid : packet.profileIds()) {
|
||||
removePlayer(uuid);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public final MutablePlayerListEntry getEntry (UUID uuid) {
|
||||
for (MutablePlayerListEntry candidate : list) {
|
||||
if (candidate.profile().getId().equals(uuid)) {
|
||||
return candidate;
|
||||
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) {
|
||||
final MutablePlayerListEntry duplicate = getEntry(newEntry);
|
||||
if (duplicate != null) list.remove(duplicate);
|
||||
try {
|
||||
final MutablePlayerListEntry duplicate = getEntry(newEntry);
|
||||
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) {
|
||||
final MutablePlayerListEntry target = getEntry(newEntry);
|
||||
if (target == null) return;
|
||||
try {
|
||||
final MutablePlayerListEntry target = getEntry(newEntry);
|
||||
if (target == null) return;
|
||||
|
||||
target.gamemode(newEntry.gameMode());
|
||||
target.gamemode(newEntry.gameMode());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateLatency (PlayerListS2CPacket.Entry newEntry) {
|
||||
|
@ -120,27 +136,31 @@ public class Players extends Listener {
|
|||
}
|
||||
|
||||
private void removePlayer (UUID uuid) {
|
||||
final MutablePlayerListEntry target = getEntry(uuid);
|
||||
if (target == null) return;
|
||||
try {
|
||||
final MutablePlayerListEntry target = getEntry(uuid);
|
||||
if (target == null) return;
|
||||
|
||||
final CompletableFuture<CommandSuggestionsS2CPacket> future = TabComplete.INSTANCE.complete("/scoreboard players add ");
|
||||
final CompletableFuture<CommandSuggestionsS2CPacket> future = TabComplete.INSTANCE.complete("/scoreboard players add ");
|
||||
|
||||
if (future == null) return;
|
||||
if (future == null) return;
|
||||
|
||||
future.thenApply(packet -> {
|
||||
final Suggestions matches = packet.getSuggestions();
|
||||
final String username = target.profile().getName();
|
||||
future.thenApply(packet -> {
|
||||
final Suggestions matches = packet.getSuggestions();
|
||||
final String username = target.profile().getName();
|
||||
|
||||
for (int i = 0; i < matches.getList().size(); i++) {
|
||||
final Suggestion suggestion = matches.getList().get(i);
|
||||
for (int i = 0; i < matches.getList().size(); i++) {
|
||||
final Suggestion suggestion = matches.getList().get(i);
|
||||
|
||||
final Message tooltip = suggestion.getTooltip();
|
||||
if (tooltip != null || !suggestion.getText().equals(username)) continue;
|
||||
final Message tooltip = suggestion.getTooltip();
|
||||
if (tooltip != null || !suggestion.getText().equals(username)) continue;
|
||||
return packet;
|
||||
}
|
||||
|
||||
list.remove(target);
|
||||
return packet;
|
||||
}
|
||||
|
||||
list.remove(target);
|
||||
return packet;
|
||||
});
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue