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