mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 16:27:47 +00:00
A few tweaks to things. Make the mods command a bit better, make the
IndexedMessageCodec actually log which network channel it got back packets on. Also, improve the custom directorymodlocator with actual custom names, finally, allow up to 99 log rollovers, up from 7 default (this means a repeatedly crashing server is less likely to roll out the log of the first crash). Signed-off-by: cpw <cpw+github@weeksfamily.ca>
This commit is contained in:
8 files changed
+37
-15
No files matched your search
@@ -209,7 +209,7 @@ public class ModList
|
||||
modFiles.stream().map(ModFileInfo::getFile).forEach(fileConsumer);
|
||||
}
|
||||
|
||||
private <T> Stream<T> applyForEachModFile(Function<ModFile, T> function) {
|
||||
public <T> Stream<T> applyForEachModFile(Function<ModFile, T> function) {
|
||||
return modFiles.stream().map(ModFileInfo::getFile).map(function);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,11 +23,13 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap;
|
||||
import it.unimi.dsi.fastutil.shorts.Short2ObjectArrayMap;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
import net.minecraftforge.fml.network.NetworkInstance;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.Marker;
|
||||
import org.apache.logging.log4j.MarkerManager;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
@@ -39,6 +41,14 @@ public class IndexedMessageCodec
|
||||
private static final Marker SIMPLENET = MarkerManager.getMarker("SIMPLENET");
|
||||
private final Short2ObjectArrayMap<MessageHandler<?>> indicies = new Short2ObjectArrayMap<>();
|
||||
private final Object2ObjectArrayMap<Class<?>, MessageHandler<?>> types = new Object2ObjectArrayMap<>();
|
||||
private final NetworkInstance networkInstance;
|
||||
|
||||
public IndexedMessageCodec() {
|
||||
this(null);
|
||||
}
|
||||
public IndexedMessageCodec(final NetworkInstance instance) {
|
||||
this.networkInstance = instance;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <MSG> MessageHandler<MSG> findMessageType(final MSG msgToReply) {
|
||||
@@ -127,7 +137,7 @@ public class IndexedMessageCodec
|
||||
@SuppressWarnings("unchecked")
|
||||
MessageHandler<MSG> messageHandler = (MessageHandler<MSG>)types.get(message.getClass());
|
||||
if (messageHandler == null) {
|
||||
LOGGER.error(SIMPLENET, "Received invalid message {}", message.getClass().getName());
|
||||
LOGGER.error(SIMPLENET, "Received invalid message {} on channel {}", message.getClass().getName(), Optional.ofNullable(networkInstance).map(NetworkInstance::getChannelName).map(Objects::toString).orElse("MISSING CHANNEL"));
|
||||
throw new IllegalArgumentException("Invalid message "+message.getClass().getName());
|
||||
}
|
||||
return tryEncode(target, message, messageHandler);
|
||||
@@ -135,13 +145,13 @@ public class IndexedMessageCodec
|
||||
|
||||
void consume(PacketBuffer payload, int payloadIndex, Supplier<NetworkEvent.Context> context) {
|
||||
if (payload == null) {
|
||||
LOGGER.error(SIMPLENET, "Received empty payload");
|
||||
LOGGER.error(SIMPLENET, "Received empty payload on channel {}", Optional.ofNullable(networkInstance).map(NetworkInstance::getChannelName).map(Objects::toString).orElse("MISSING CHANNEL"));
|
||||
return;
|
||||
}
|
||||
short discriminator = payload.readUnsignedByte();
|
||||
final MessageHandler<?> messageHandler = indicies.get(discriminator);
|
||||
if (messageHandler == null) {
|
||||
LOGGER.error(SIMPLENET, "Received invalid discriminator byte {}", discriminator);
|
||||
LOGGER.error(SIMPLENET, "Received invalid discriminator byte {} on channel {}", discriminator, Optional.ofNullable(networkInstance).map(NetworkInstance::getChannelName).map(Objects::toString).orElse("MISSING CHANNEL"));
|
||||
return;
|
||||
}
|
||||
tryDecode(payload, context, payloadIndex, messageHandler);
|
||||
|
||||
@@ -51,7 +51,7 @@ public class SimpleChannel
|
||||
|
||||
private SimpleChannel(NetworkInstance instance, Optional<Consumer<NetworkEvent.ChannelRegistrationChangeEvent>> registryChangeNotify) {
|
||||
this.instance = instance;
|
||||
this.indexedCodec = new IndexedMessageCodec();
|
||||
this.indexedCodec = new IndexedMessageCodec(instance);
|
||||
this.loginPackets = new ArrayList<>();
|
||||
instance.addListener(this::networkEventListener);
|
||||
instance.addGatherListener(this::networkLoginGather);
|
||||
|
||||
@@ -24,6 +24,7 @@ import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.command.Commands;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.ModFileInfo;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.ModInfo;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
@@ -35,9 +36,15 @@ public class CommandModList {
|
||||
.requires(cs->cs.hasPermissionLevel(0)) //permission
|
||||
.executes(ctx -> {
|
||||
ctx.getSource().sendFeedback(new TranslationTextComponent("commands.forge.mods.list",
|
||||
ModList.get().applyForEachModContainer(
|
||||
mc->String.format("%s:%s(%s)", mc.getModId(), mc.getModInfo().getVersion().toString(), mc.getCurrentState())).
|
||||
collect(Collectors.joining(","))),
|
||||
ModList.get().applyForEachModFile(modFile ->
|
||||
// locator - filename : firstmod (version) - numberofmods\n
|
||||
String.format("%s %s : %s (%s) - %d",
|
||||
modFile.getLocator().name().replace(' ', '_'),
|
||||
modFile.getFileName(),
|
||||
modFile.getModInfos().get(0).getModId(),
|
||||
modFile.getModInfos().get(0).getVersion(),
|
||||
modFile.getModInfos().size())).
|
||||
collect(Collectors.joining("\n• ","• ", ""))),
|
||||
true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user