Get restrictions module "compiling" on 1.13
This commit is contained in:
@@ -1,28 +1,33 @@
|
|||||||
package com.replaymod.restrictions;
|
// I don't think this sees sufficient use to justify updating.
|
||||||
|
// Especially because it's non-trivial with forge's network changes.
|
||||||
import com.replaymod.core.SettingsRegistry;
|
// PRs welcome. Ping me if you actually used this.
|
||||||
import com.replaymod.core.utils.Restrictions;
|
|
||||||
import io.netty.buffer.Unpooled;
|
|
||||||
import io.netty.channel.ChannelDuplexHandler;
|
|
||||||
import io.netty.channel.ChannelFutureListener;
|
|
||||||
import io.netty.channel.ChannelHandler;
|
|
||||||
import net.minecraft.network.PacketBuffer;
|
|
||||||
import net.minecraftforge.common.config.Configuration;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
|
//#if MC<11300
|
||||||
|
//$$ package com.replaymod.restrictions;
|
||||||
|
//$$
|
||||||
|
//$$ import com.replaymod.core.SettingsRegistry;
|
||||||
|
//$$ import com.replaymod.core.utils.Restrictions;
|
||||||
|
//$$ import io.netty.buffer.Unpooled;
|
||||||
|
//$$ import io.netty.channel.ChannelDuplexHandler;
|
||||||
|
//$$ import io.netty.channel.ChannelFutureListener;
|
||||||
|
//$$ import io.netty.channel.ChannelHandler;
|
||||||
|
//$$ import net.minecraft.network.PacketBuffer;
|
||||||
|
//$$ import net.minecraftforge.common.config.Configuration;
|
||||||
|
//$$ import org.apache.logging.log4j.Logger;
|
||||||
|
//$$
|
||||||
//#if MC>=10800
|
//#if MC>=10800
|
||||||
import net.minecraftforge.fml.common.Mod;
|
//$$ import net.minecraftforge.fml.common.Mod;
|
||||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
//$$ import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||||
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
//$$ import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
//$$ import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||||
import net.minecraftforge.fml.common.eventhandler.EventBus;
|
//$$ import net.minecraftforge.fml.common.eventhandler.EventBus;
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
//$$ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
|
//$$ import net.minecraftforge.fml.common.gameevent.PlayerEvent;
|
||||||
import net.minecraftforge.fml.common.network.FMLEmbeddedChannel;
|
//$$ import net.minecraftforge.fml.common.network.FMLEmbeddedChannel;
|
||||||
import net.minecraftforge.fml.common.network.FMLOutboundHandler;
|
//$$ import net.minecraftforge.fml.common.network.FMLOutboundHandler;
|
||||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
//$$ import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||||
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket;
|
//$$ import net.minecraftforge.fml.common.network.internal.FMLProxyPacket;
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
//$$ import net.minecraftforge.fml.relauncher.Side;
|
||||||
//#else
|
//#else
|
||||||
//$$ import cpw.mods.fml.common.FMLCommonHandler;
|
//$$ import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
//$$ import cpw.mods.fml.common.Mod;
|
//$$ import cpw.mods.fml.common.Mod;
|
||||||
@@ -38,81 +43,82 @@ import net.minecraftforge.fml.relauncher.Side;
|
|||||||
//$$ import cpw.mods.fml.common.network.internal.FMLProxyPacket;
|
//$$ import cpw.mods.fml.common.network.internal.FMLProxyPacket;
|
||||||
//$$ import cpw.mods.fml.relauncher.Side;
|
//$$ import cpw.mods.fml.relauncher.Side;
|
||||||
//#endif
|
//#endif
|
||||||
|
//$$
|
||||||
import java.io.IOException;
|
//$$ import java.io.IOException;
|
||||||
import java.util.HashMap;
|
//$$ import java.util.HashMap;
|
||||||
import java.util.Map;
|
//$$ import java.util.Map;
|
||||||
|
//$$
|
||||||
import static com.replaymod.core.versions.MCVer.*;
|
//$$ import static com.replaymod.core.versions.MCVer.*;
|
||||||
|
//$$
|
||||||
@Mod(modid = ReplayModRestrictions.MOD_ID,
|
//$$ @Mod(modid = ReplayModRestrictions.MOD_ID,
|
||||||
version = "@MOD_VERSION@",
|
//$$ version = "@MOD_VERSION@",
|
||||||
acceptedMinecraftVersions = "@MC_VERSION@",
|
//$$ acceptedMinecraftVersions = "@MC_VERSION@",
|
||||||
acceptableRemoteVersions = "*",
|
//$$ acceptableRemoteVersions = "*",
|
||||||
//#if MC>=10800
|
//#if MC>=10800
|
||||||
serverSideOnly = true,
|
//$$ serverSideOnly = true,
|
||||||
//#endif
|
//#endif
|
||||||
useMetadata = true)
|
//$$ useMetadata = true)
|
||||||
public class ReplayModRestrictions {
|
//$$ public class ReplayModRestrictions {
|
||||||
public static final String MOD_ID = "replaymod-restrictions";
|
//$$ public static final String MOD_ID = "replaymod-restrictions";
|
||||||
|
//$$
|
||||||
public static Logger LOGGER;
|
//$$ public static Logger LOGGER;
|
||||||
|
//$$
|
||||||
private final SettingsRegistry settingsRegistry = new SettingsRegistry();
|
//$$ private final SettingsRegistry settingsRegistry = new SettingsRegistry();
|
||||||
private FMLEmbeddedChannel channel;
|
//$$ private FMLEmbeddedChannel channel;
|
||||||
|
//$$
|
||||||
@Mod.EventHandler
|
//$$ @Mod.EventHandler
|
||||||
public void preInit(FMLPreInitializationEvent event) {
|
//$$ public void preInit(FMLPreInitializationEvent event) {
|
||||||
LOGGER = event.getModLog();
|
//$$ LOGGER = event.getModLog();
|
||||||
|
//$$
|
||||||
Configuration config = new Configuration(event.getSuggestedConfigurationFile());
|
//$$ Configuration config = new Configuration(event.getSuggestedConfigurationFile());
|
||||||
config.load();
|
//$$ config.load();
|
||||||
settingsRegistry.setConfiguration(config);
|
//$$ settingsRegistry.setConfiguration(config);
|
||||||
|
//$$
|
||||||
settingsRegistry.register(Setting.class);
|
//$$ settingsRegistry.register(Setting.class);
|
||||||
}
|
//$$ }
|
||||||
|
//$$
|
||||||
@Mod.EventHandler
|
//$$ @Mod.EventHandler
|
||||||
public void init(FMLInitializationEvent event) {
|
//$$ public void init(FMLInitializationEvent event) {
|
||||||
//#if MC<=10710
|
//#if MC<=10710
|
||||||
//$$ if (FMLCommonHandler.instance().getSide() == Side.CLIENT) return;
|
//$$ if (FMLCommonHandler.instance().getSide() == Side.CLIENT) return;
|
||||||
//#endif
|
//#endif
|
||||||
EventBus bus = FML_BUS;
|
//$$ EventBus bus = FML_BUS;
|
||||||
bus.register(this);
|
//$$ bus.register(this);
|
||||||
|
//$$
|
||||||
channel = NetworkRegistry.INSTANCE.newChannel(Restrictions.PLUGIN_CHANNEL, new RestrictionsChannelHandler()).get(Side.SERVER);
|
//$$ channel = NetworkRegistry.INSTANCE.newChannel(Restrictions.PLUGIN_CHANNEL, new RestrictionsChannelHandler()).get(Side.SERVER);
|
||||||
}
|
//$$ }
|
||||||
|
//$$
|
||||||
@Mod.EventHandler
|
//$$ @Mod.EventHandler
|
||||||
public void postInit(FMLPostInitializationEvent event) throws IOException {
|
//$$ public void postInit(FMLPostInitializationEvent event) throws IOException {
|
||||||
settingsRegistry.save(); // Save default values to disk
|
//$$ settingsRegistry.save(); // Save default values to disk
|
||||||
}
|
//$$ }
|
||||||
|
//$$
|
||||||
@ChannelHandler.Sharable
|
//$$ @ChannelHandler.Sharable
|
||||||
private static class RestrictionsChannelHandler extends ChannelDuplexHandler {}
|
//$$ private static class RestrictionsChannelHandler extends ChannelDuplexHandler {}
|
||||||
|
//$$
|
||||||
@SubscribeEvent
|
//$$ @SubscribeEvent
|
||||||
public void onUserJoin(PlayerEvent.PlayerLoggedInEvent event) {
|
//$$ public void onUserJoin(PlayerEvent.PlayerLoggedInEvent event) {
|
||||||
Map<String, byte[]> restrictions = new HashMap<>();
|
//$$ Map<String, byte[]> restrictions = new HashMap<>();
|
||||||
if (settingsRegistry.get(Setting.NO_XRAY)) restrictions.put("no_xray", new byte[0]);
|
//$$ if (settingsRegistry.get(Setting.NO_XRAY)) restrictions.put("no_xray", new byte[0]);
|
||||||
if (settingsRegistry.get(Setting.NO_NOCLIP)) restrictions.put("no_noclip", new byte[0]);
|
//$$ if (settingsRegistry.get(Setting.NO_NOCLIP)) restrictions.put("no_noclip", new byte[0]);
|
||||||
if (settingsRegistry.get(Setting.ONLY_FIRST_PERSON)) restrictions.put("only_first_person", new byte[0]);
|
//$$ if (settingsRegistry.get(Setting.ONLY_FIRST_PERSON)) restrictions.put("only_first_person", new byte[0]);
|
||||||
if (settingsRegistry.get(Setting.ONLY_RECORDING_PLAYER)) restrictions.put("only_recording_player", new byte[0]);
|
//$$ if (settingsRegistry.get(Setting.ONLY_RECORDING_PLAYER)) restrictions.put("only_recording_player", new byte[0]);
|
||||||
if (settingsRegistry.get(Setting.HIDE_COORDINATES)) restrictions.put("hide_coordinates", new byte[0]);
|
//$$ if (settingsRegistry.get(Setting.HIDE_COORDINATES)) restrictions.put("hide_coordinates", new byte[0]);
|
||||||
|
//$$
|
||||||
PacketBuffer buf = new PacketBuffer(Unpooled.buffer());
|
//$$ PacketBuffer buf = new PacketBuffer(Unpooled.buffer());
|
||||||
for (Map.Entry<String, byte[]> e : restrictions.entrySet()) {
|
//$$ for (Map.Entry<String, byte[]> e : restrictions.entrySet()) {
|
||||||
byte[] bytes = e.getKey().getBytes();
|
//$$ byte[] bytes = e.getKey().getBytes();
|
||||||
buf.writeByte(bytes.length);
|
//$$ buf.writeByte(bytes.length);
|
||||||
buf.writeBytes(bytes);
|
//$$ buf.writeBytes(bytes);
|
||||||
buf.writeByte(1);
|
//$$ buf.writeByte(1);
|
||||||
buf.writeBytes(e.getValue());
|
//$$ buf.writeBytes(e.getValue());
|
||||||
}
|
//$$ }
|
||||||
|
//$$
|
||||||
FMLProxyPacket packet = new FMLProxyPacket(buf, Restrictions.PLUGIN_CHANNEL);
|
//$$ FMLProxyPacket packet = new FMLProxyPacket(buf, Restrictions.PLUGIN_CHANNEL);
|
||||||
|
//$$
|
||||||
channel.attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER);
|
//$$ channel.attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER);
|
||||||
channel.attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(event.player);
|
//$$ channel.attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(event.player);
|
||||||
channel.writeAndFlush(packet).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
|
//$$ channel.writeAndFlush(packet).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
|
||||||
}
|
//$$ }
|
||||||
}
|
//$$ }
|
||||||
|
//#endif
|
||||||
|
|||||||
@@ -279,13 +279,6 @@ if (project.name != 'core') {
|
|||||||
minecraft.accessTransformers << file('../../src/main/resources/META-INF/replaymod_at.cfg')
|
minecraft.accessTransformers << file('../../src/main/resources/META-INF/replaymod_at.cfg')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sourceSets {
|
|
||||||
main {
|
|
||||||
java {
|
|
||||||
exclude 'com/replaymod/restrictions'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
task configureRelocation() {
|
task configureRelocation() {
|
||||||
dependsOn tasks.jar
|
dependsOn tasks.jar
|
||||||
|
|||||||
Reference in New Issue
Block a user