mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-15 22:23:42 +01:00
Merge branch 'mc1.15/security-patches' of https://github.com/pau101/Create into mc1.15/security-patches
This commit is contained in:
commit
0c5e67e347
7 changed files with 186 additions and 127 deletions
|
@ -0,0 +1,59 @@
|
|||
package com.simibubi.create.content.schematics;
|
||||
|
||||
import com.mojang.datafixers.Dynamic;
|
||||
import com.mojang.datafixers.types.DynamicOps;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IWorldReader;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.gen.feature.template.IStructureProcessorType;
|
||||
import net.minecraft.world.gen.feature.template.PlacementSettings;
|
||||
import net.minecraft.world.gen.feature.template.StructureProcessor;
|
||||
import net.minecraft.world.gen.feature.template.Template;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Optional;
|
||||
|
||||
public class SchematicProcessor extends StructureProcessor {
|
||||
public static final SchematicProcessor INSTANCE = new SchematicProcessor();
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Template.BlockInfo process(IWorldReader world, BlockPos pos, Template.BlockInfo rawInfo, Template.BlockInfo info, PlacementSettings settings, @Nullable Template template) {
|
||||
if (info.nbt != null) {
|
||||
TileEntity te = info.state.createTileEntity(world);
|
||||
if (te != null && te.onlyOpsCanSetNbt()) {
|
||||
return new Template.BlockInfo(info.pos, info.state, null);
|
||||
}
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Template.EntityInfo processEntity(IWorldReader world, BlockPos pos, Template.EntityInfo rawInfo, Template.EntityInfo info, PlacementSettings settings, Template template) {
|
||||
return EntityType.readEntityType(info.nbt)
|
||||
.flatMap(type -> {
|
||||
if (world instanceof World) {
|
||||
Entity e = type.create((World) world);
|
||||
if (e != null && !e.ignoreItemEntityData()) {
|
||||
return Optional.of(info);
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
})
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IStructureProcessorType getType() {
|
||||
return dynamic -> INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> Dynamic<T> serialize0(DynamicOps<T> ops) {
|
||||
return new Dynamic<>(ops, ops.emptyMap());
|
||||
}
|
||||
}
|
|
@ -91,10 +91,8 @@ public class ServerSchematicLoader {
|
|||
}
|
||||
|
||||
public void handleNewUpload(ServerPlayerEntity player, String schematic, long size, BlockPos pos) {
|
||||
String playerPath = getSchematicPath() + "/" + player.getName()
|
||||
.getFormattedText();
|
||||
String playerSchematicId = player.getName()
|
||||
.getFormattedText() + "/" + schematic;
|
||||
String playerPath = getSchematicPath() + "/" + player.getGameProfile().getName();
|
||||
String playerSchematicId = player.getGameProfile().getName() + "/" + schematic;
|
||||
FilesHelper.createFolderIfMissing(playerPath);
|
||||
|
||||
// Unsupported Format
|
||||
|
@ -103,6 +101,14 @@ public class ServerSchematicLoader {
|
|||
return;
|
||||
}
|
||||
|
||||
Path playerSchematicsPath = Paths.get(getSchematicPath(), player.getGameProfile().getName()).toAbsolutePath();
|
||||
|
||||
Path uploadPath = playerSchematicsPath.resolve(schematic).normalize();
|
||||
if (!uploadPath.startsWith(playerSchematicsPath)) {
|
||||
Create.logger.warn("Attempted Schematic Upload with directory escape: {}", playerSchematicId);
|
||||
return;
|
||||
}
|
||||
|
||||
// Too big
|
||||
if (!validateSchematicSizeOnServer(player, size))
|
||||
return;
|
||||
|
@ -118,11 +124,15 @@ public class ServerSchematicLoader {
|
|||
return;
|
||||
|
||||
// Delete schematic with same name
|
||||
Files.deleteIfExists(Paths.get(getSchematicPath(), playerSchematicId));
|
||||
Files.deleteIfExists(uploadPath);
|
||||
|
||||
// Too many Schematics
|
||||
Stream<Path> list = Files.list(Paths.get(playerPath));
|
||||
if (list.count() >= getConfig().maxSchematics.get()) {
|
||||
long count;
|
||||
try (Stream<Path> list = Files.list(Paths.get(playerPath))) {
|
||||
count = list.count();
|
||||
}
|
||||
|
||||
if (count >= getConfig().maxSchematics.get()) {
|
||||
Stream<Path> list2 = Files.list(Paths.get(playerPath));
|
||||
Optional<Path> lastFilePath = list2.filter(f -> !Files.isDirectory(f))
|
||||
.min(Comparator.comparingLong(f -> f.toFile()
|
||||
|
@ -132,11 +142,9 @@ public class ServerSchematicLoader {
|
|||
Files.deleteIfExists(lastFilePath.get());
|
||||
}
|
||||
}
|
||||
list.close();
|
||||
|
||||
// Open Stream
|
||||
OutputStream writer =
|
||||
Files.newOutputStream(Paths.get(getSchematicPath(), playerSchematicId), StandardOpenOption.CREATE_NEW);
|
||||
OutputStream writer = Files.newOutputStream(uploadPath);
|
||||
activeUploads.put(playerSchematicId, new SchematicUploadEntry(writer, size, player.getServerWorld(), pos));
|
||||
|
||||
// Notify Tile Entity
|
||||
|
@ -165,8 +173,7 @@ public class ServerSchematicLoader {
|
|||
}
|
||||
|
||||
public void handleWriteRequest(ServerPlayerEntity player, String schematic, byte[] data) {
|
||||
String playerSchematicId = player.getName()
|
||||
.getFormattedText() + "/" + schematic;
|
||||
String playerSchematicId = player.getGameProfile().getName() + "/" + schematic;
|
||||
|
||||
if (activeUploads.containsKey(playerSchematicId)) {
|
||||
SchematicUploadEntry entry = activeUploads.get(playerSchematicId);
|
||||
|
@ -236,8 +243,7 @@ public class ServerSchematicLoader {
|
|||
}
|
||||
|
||||
public void handleFinishedUpload(ServerPlayerEntity player, String schematic) {
|
||||
String playerSchematicId = player.getName()
|
||||
.getFormattedText() + "/" + schematic;
|
||||
String playerSchematicId = player.getGameProfile().getName() + "/" + schematic;
|
||||
|
||||
if (activeUploads.containsKey(playerSchematicId)) {
|
||||
try {
|
||||
|
@ -258,8 +264,7 @@ public class ServerSchematicLoader {
|
|||
if (table == null)
|
||||
return;
|
||||
table.finishUpload();
|
||||
table.inventory.setStackInSlot(1, SchematicItem.create(schematic, player.getName()
|
||||
.getFormattedText()));
|
||||
table.inventory.setStackInSlot(1, SchematicItem.create(schematic, player.getGameProfile().getName()));
|
||||
|
||||
} catch (IOException e) {
|
||||
Create.logger.error("Exception Thrown when finishing Upload: " + playerSchematicId);
|
||||
|
@ -270,15 +275,21 @@ public class ServerSchematicLoader {
|
|||
|
||||
public void handleInstantSchematic(ServerPlayerEntity player, String schematic, World world, BlockPos pos,
|
||||
BlockPos bounds) {
|
||||
String playerPath = getSchematicPath() + "/" + player.getName()
|
||||
.getFormattedText();
|
||||
String playerSchematicId = player.getName()
|
||||
.getFormattedText() + "/" + schematic;
|
||||
String playerPath = getSchematicPath() + "/" + player.getGameProfile().getName();
|
||||
String playerSchematicId = player.getGameProfile().getName() + "/" + schematic;
|
||||
FilesHelper.createFolderIfMissing(playerPath);
|
||||
|
||||
// Unsupported Format
|
||||
if (!schematic.endsWith(".nbt")) {
|
||||
Create.logger.warn("Attempted Schematic Upload with non-supported Format: " + playerSchematicId);
|
||||
Create.logger.warn("Attempted Schematic Upload with non-supported Format: {}", playerSchematicId);
|
||||
return;
|
||||
}
|
||||
|
||||
Path schematicPath = Paths.get(getSchematicPath()).toAbsolutePath();
|
||||
|
||||
Path path = schematicPath.resolve(playerSchematicId).normalize();
|
||||
if (!path.startsWith(schematicPath)) {
|
||||
Create.logger.warn("Attempted Schematic Upload with directory escape: {}", playerSchematicId);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -288,12 +299,15 @@ public class ServerSchematicLoader {
|
|||
|
||||
try {
|
||||
// Delete schematic with same name
|
||||
Path path = Paths.get(getSchematicPath(), playerSchematicId);
|
||||
Files.deleteIfExists(path);
|
||||
|
||||
// Too many Schematics
|
||||
Stream<Path> list = Files.list(Paths.get(playerPath));
|
||||
if (list.count() >= getConfig().maxSchematics.get()) {
|
||||
long count;
|
||||
try (Stream<Path> list = Files.list(Paths.get(playerPath))) {
|
||||
count = list.count();
|
||||
}
|
||||
|
||||
if (count >= getConfig().maxSchematics.get()) {
|
||||
Stream<Path> list2 = Files.list(Paths.get(playerPath));
|
||||
Optional<Path> lastFilePath = list2.filter(f -> !Files.isDirectory(f))
|
||||
.min(Comparator.comparingLong(f -> f.toFile()
|
||||
|
@ -302,24 +316,17 @@ public class ServerSchematicLoader {
|
|||
if (lastFilePath.isPresent())
|
||||
Files.deleteIfExists(lastFilePath.get());
|
||||
}
|
||||
list.close();
|
||||
|
||||
Template t = new Template();
|
||||
t.takeBlocksFromWorld(world, pos, bounds, true, Blocks.AIR);
|
||||
|
||||
OutputStream outputStream = null;
|
||||
try {
|
||||
outputStream = Files.newOutputStream(path, StandardOpenOption.CREATE);
|
||||
try (OutputStream outputStream = Files.newOutputStream(path)) {
|
||||
CompoundNBT nbttagcompound = t.writeToNBT(new CompoundNBT());
|
||||
CompressedStreamTools.writeCompressed(nbttagcompound, outputStream);
|
||||
player.setHeldItem(Hand.MAIN_HAND, SchematicItem.create(schematic, player.getName()
|
||||
.getFormattedText()));
|
||||
player.setHeldItem(Hand.MAIN_HAND, SchematicItem.create(schematic, player.getGameProfile().getName()));
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (outputStream != null)
|
||||
IOUtils.closeQuietly(outputStream);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Create.logger.error("Exception Thrown in direct Schematic Upload: " + playerSchematicId);
|
||||
|
|
|
@ -422,8 +422,7 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen<Schematica
|
|||
}
|
||||
|
||||
protected void sendOptionUpdate(Option option, boolean set) {
|
||||
AllPackets.channel.sendToServer(ConfigureSchematicannonPacket.setOption(container.getTileEntity()
|
||||
.getPos(), option, set));
|
||||
AllPackets.channel.sendToServer(new ConfigureSchematicannonPacket(option, set));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,17 +1,22 @@
|
|||
package com.simibubi.create.content.schematics.item;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.List;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.simibubi.create.AllItems;
|
||||
import com.simibubi.create.content.schematics.SchematicProcessor;
|
||||
import com.simibubi.create.content.schematics.client.SchematicEditScreen;
|
||||
import com.simibubi.create.foundation.gui.ScreenOpener;
|
||||
import com.simibubi.create.foundation.utility.Lang;
|
||||
|
@ -24,6 +29,7 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTSizeTracker;
|
||||
import net.minecraft.nbt.NBTUtil;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
|
@ -45,6 +51,8 @@ import net.minecraftforge.fml.common.thread.SidedThreadGroups;
|
|||
|
||||
public class SchematicItem extends Item {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
public SchematicItem(Properties properties) {
|
||||
super(properties.maxStackSize(1));
|
||||
}
|
||||
|
@ -94,6 +102,7 @@ public class SchematicItem extends Item {
|
|||
PlacementSettings settings = new PlacementSettings();
|
||||
settings.setRotation(Rotation.valueOf(tag.getString("Rotation")));
|
||||
settings.setMirror(Mirror.valueOf(tag.getString("Mirror")));
|
||||
settings.addProcessor(SchematicProcessor.INSTANCE);
|
||||
return settings;
|
||||
}
|
||||
|
||||
|
@ -104,25 +113,30 @@ public class SchematicItem extends Item {
|
|||
String schematic = blueprint.getTag()
|
||||
.getString("File");
|
||||
|
||||
String filepath = "";
|
||||
if (!schematic.endsWith(".nbt"))
|
||||
return t;
|
||||
|
||||
if (Thread.currentThread()
|
||||
.getThreadGroup() == SidedThreadGroups.SERVER)
|
||||
filepath = "schematics/uploaded/" + owner + "/" + schematic;
|
||||
else
|
||||
filepath = "schematics/" + schematic;
|
||||
Path dir;
|
||||
Path file;
|
||||
|
||||
InputStream stream = null;
|
||||
try {
|
||||
stream = Files.newInputStream(Paths.get(filepath), StandardOpenOption.READ);
|
||||
CompoundNBT nbt = CompressedStreamTools.readCompressed(stream);
|
||||
if (Thread.currentThread().getThreadGroup() == SidedThreadGroups.SERVER) {
|
||||
dir = Paths.get("schematics", "uploaded").toAbsolutePath();
|
||||
file = Paths.get(owner, schematic);
|
||||
} else {
|
||||
dir = Paths.get("schematics").toAbsolutePath();
|
||||
file = Paths.get(schematic);
|
||||
}
|
||||
|
||||
Path path = dir.resolve(file).normalize();
|
||||
if (!path.startsWith(dir))
|
||||
return t;
|
||||
|
||||
try (DataInputStream stream = new DataInputStream(new BufferedInputStream(
|
||||
new GZIPInputStream(Files.newInputStream(path, StandardOpenOption.READ))))) {
|
||||
CompoundNBT nbt = CompressedStreamTools.read(stream, new NBTSizeTracker(0x20000000L));
|
||||
t.read(nbt);
|
||||
|
||||
} catch (IOException e) {
|
||||
// Player/Server doesnt have schematic saved
|
||||
} finally {
|
||||
if (stream != null)
|
||||
IOUtils.closeQuietly(stream);
|
||||
LOGGER.warn("Failed to read schematic", e);
|
||||
}
|
||||
|
||||
return t;
|
||||
|
|
|
@ -2,15 +2,13 @@ package com.simibubi.create.content.schematics.packet;
|
|||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.content.schematics.block.SchematicannonContainer;
|
||||
import com.simibubi.create.content.schematics.block.SchematicannonTileEntity;
|
||||
import com.simibubi.create.content.schematics.block.SchematicannonTileEntity.State;
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.network.NetworkEvent.Context;
|
||||
|
||||
public class ConfigureSchematicannonPacket extends SimplePacketBase {
|
||||
|
@ -21,45 +19,28 @@ public class ConfigureSchematicannonPacket extends SimplePacketBase {
|
|||
|
||||
private Option option;
|
||||
private boolean set;
|
||||
private BlockPos pos;
|
||||
|
||||
public static ConfigureSchematicannonPacket setOption(BlockPos pos, Option option, boolean set) {
|
||||
ConfigureSchematicannonPacket packet = new ConfigureSchematicannonPacket(pos);
|
||||
packet.option = option;
|
||||
packet.set = set;
|
||||
return packet;
|
||||
}
|
||||
|
||||
public ConfigureSchematicannonPacket(BlockPos pos) {
|
||||
this.pos = pos;
|
||||
public ConfigureSchematicannonPacket(Option option, boolean set) {
|
||||
this.option = option;
|
||||
this.set = set;
|
||||
}
|
||||
|
||||
public ConfigureSchematicannonPacket(PacketBuffer buffer) {
|
||||
pos = buffer.readBlockPos();
|
||||
option = Option.values()[buffer.readInt()];
|
||||
set = buffer.readBoolean();
|
||||
this(buffer.readEnumValue(Option.class), buffer.readBoolean());
|
||||
}
|
||||
|
||||
public void write(PacketBuffer buffer) {
|
||||
buffer.writeBlockPos(pos);
|
||||
buffer.writeInt(option.ordinal());
|
||||
buffer.writeEnumValue(option);
|
||||
buffer.writeBoolean(set);
|
||||
}
|
||||
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get().enqueueWork(() -> {
|
||||
ServerPlayerEntity player = context.get().getSender();
|
||||
if (player == null)
|
||||
return;
|
||||
World world = player.world;
|
||||
if (world == null || !world.isBlockPresent(pos))
|
||||
if (player == null || !(player.openContainer instanceof SchematicannonContainer))
|
||||
return;
|
||||
|
||||
TileEntity tileEntity = world.getTileEntity(pos);
|
||||
if (!(tileEntity instanceof SchematicannonTileEntity))
|
||||
return;
|
||||
|
||||
SchematicannonTileEntity te = (SchematicannonTileEntity) tileEntity;
|
||||
SchematicannonTileEntity te = ((SchematicannonContainer) player.openContainer).getTileEntity();
|
||||
switch (option) {
|
||||
case DONT_REPLACE:
|
||||
case REPLACE_ANY:
|
||||
|
|
|
@ -38,47 +38,51 @@ import net.minecraft.network.PacketBuffer;
|
|||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.network.NetworkDirection;
|
||||
import net.minecraftforge.fml.network.NetworkEvent.Context;
|
||||
import net.minecraftforge.fml.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.network.PacketDistributor;
|
||||
import net.minecraftforge.fml.network.PacketDistributor.TargetPoint;
|
||||
import net.minecraftforge.fml.network.simple.SimpleChannel;
|
||||
|
||||
import static net.minecraftforge.fml.network.NetworkDirection.PLAY_TO_SERVER;
|
||||
import static net.minecraftforge.fml.network.NetworkDirection.PLAY_TO_CLIENT;
|
||||
|
||||
public enum AllPackets {
|
||||
|
||||
// Client to Server
|
||||
NBT(NbtPacket.class, NbtPacket::new),
|
||||
CONFIGURE_SCHEMATICANNON(ConfigureSchematicannonPacket.class, ConfigureSchematicannonPacket::new),
|
||||
CONFIGURE_FLEXCRATE(ConfigureFlexcratePacket.class, ConfigureFlexcratePacket::new),
|
||||
CONFIGURE_STOCKSWITCH(ConfigureStockswitchPacket.class, ConfigureStockswitchPacket::new),
|
||||
CONFIGURE_SEQUENCER(ConfigureSequencedGearshiftPacket.class, ConfigureSequencedGearshiftPacket::new),
|
||||
PLACE_SCHEMATIC(SchematicPlacePacket.class, SchematicPlacePacket::new),
|
||||
UPLOAD_SCHEMATIC(SchematicUploadPacket.class, SchematicUploadPacket::new),
|
||||
CONFIGURE_FILTER(FilterScreenPacket.class, FilterScreenPacket::new),
|
||||
CONFIGURE_FILTERING_AMOUNT(FilteringCountUpdatePacket.class, FilteringCountUpdatePacket::new),
|
||||
CONFIGURE_SCROLLABLE(ScrollValueUpdatePacket.class, ScrollValueUpdatePacket::new),
|
||||
EXTENDO_INTERACT(ExtendoGripInteractionPacket.class, ExtendoGripInteractionPacket::new),
|
||||
CONTRAPTION_INTERACT(ContraptionInteractionPacket.class, ContraptionInteractionPacket::new),
|
||||
CLIENT_MOTION(ClientMotionPacket.class, ClientMotionPacket::new),
|
||||
PLACE_ARM(ArmPlacementPacket.class, ArmPlacementPacket::new),
|
||||
MINECART_COUPLING_CREATION(CouplingCreationPacket.class, CouplingCreationPacket::new),
|
||||
INSTANT_SCHEMATIC(InstantSchematicPacket.class, InstantSchematicPacket::new),
|
||||
SYNC_SCHEMATIC(SchematicSyncPacket.class, SchematicSyncPacket::new),
|
||||
LEFT_CLICK(LeftClickPacket.class, LeftClickPacket::new),
|
||||
NBT(NbtPacket.class, NbtPacket::new, PLAY_TO_SERVER),
|
||||
CONFIGURE_SCHEMATICANNON(ConfigureSchematicannonPacket.class, ConfigureSchematicannonPacket::new, PLAY_TO_SERVER),
|
||||
CONFIGURE_FLEXCRATE(ConfigureFlexcratePacket.class, ConfigureFlexcratePacket::new, PLAY_TO_SERVER),
|
||||
CONFIGURE_STOCKSWITCH(ConfigureStockswitchPacket.class, ConfigureStockswitchPacket::new, PLAY_TO_SERVER),
|
||||
CONFIGURE_SEQUENCER(ConfigureSequencedGearshiftPacket.class, ConfigureSequencedGearshiftPacket::new, PLAY_TO_SERVER),
|
||||
PLACE_SCHEMATIC(SchematicPlacePacket.class, SchematicPlacePacket::new, PLAY_TO_SERVER),
|
||||
UPLOAD_SCHEMATIC(SchematicUploadPacket.class, SchematicUploadPacket::new, PLAY_TO_SERVER),
|
||||
CONFIGURE_FILTER(FilterScreenPacket.class, FilterScreenPacket::new, PLAY_TO_SERVER),
|
||||
CONFIGURE_FILTERING_AMOUNT(FilteringCountUpdatePacket.class, FilteringCountUpdatePacket::new, PLAY_TO_SERVER),
|
||||
CONFIGURE_SCROLLABLE(ScrollValueUpdatePacket.class, ScrollValueUpdatePacket::new, PLAY_TO_SERVER),
|
||||
EXTENDO_INTERACT(ExtendoGripInteractionPacket.class, ExtendoGripInteractionPacket::new, PLAY_TO_SERVER),
|
||||
CONTRAPTION_INTERACT(ContraptionInteractionPacket.class, ContraptionInteractionPacket::new, PLAY_TO_SERVER),
|
||||
CLIENT_MOTION(ClientMotionPacket.class, ClientMotionPacket::new, PLAY_TO_SERVER),
|
||||
PLACE_ARM(ArmPlacementPacket.class, ArmPlacementPacket::new, PLAY_TO_SERVER),
|
||||
MINECART_COUPLING_CREATION(CouplingCreationPacket.class, CouplingCreationPacket::new, PLAY_TO_SERVER),
|
||||
INSTANT_SCHEMATIC(InstantSchematicPacket.class, InstantSchematicPacket::new, PLAY_TO_SERVER),
|
||||
SYNC_SCHEMATIC(SchematicSyncPacket.class, SchematicSyncPacket::new, PLAY_TO_SERVER),
|
||||
LEFT_CLICK(LeftClickPacket.class, LeftClickPacket::new, PLAY_TO_SERVER),
|
||||
|
||||
// Server to Client
|
||||
SYMMETRY_EFFECT(SymmetryEffectPacket.class, SymmetryEffectPacket::new),
|
||||
SERVER_SPEED(ServerSpeedProvider.Packet.class, ServerSpeedProvider.Packet::new),
|
||||
BEAM_EFFECT(ZapperBeamPacket.class, ZapperBeamPacket::new),
|
||||
CONFIGURE_CONFIG(ConfigureConfigPacket.class, ConfigureConfigPacket::new),
|
||||
CONTRAPTION_STALL(ContraptionStallPacket.class, ContraptionStallPacket::new),
|
||||
CONTRAPTION_DISASSEMBLE(ContraptionDisassemblyPacket.class, ContraptionDisassemblyPacket::new),
|
||||
GLUE_EFFECT(GlueEffectPacket.class, GlueEffectPacket::new),
|
||||
CONTRAPTION_SEAT_MAPPING(ContraptionSeatMappingPacket.class, ContraptionSeatMappingPacket::new),
|
||||
LIMBSWING_UPDATE(LimbSwingUpdatePacket.class, LimbSwingUpdatePacket::new),
|
||||
MINECART_CONTROLLER(MinecartControllerUpdatePacket.class, MinecartControllerUpdatePacket::new),
|
||||
FLUID_SPLASH(FluidSplashPacket.class, FluidSplashPacket::new),
|
||||
CONTRAPTION_FLUID(ContraptionFluidPacket.class, ContraptionFluidPacket::new),
|
||||
SYMMETRY_EFFECT(SymmetryEffectPacket.class, SymmetryEffectPacket::new, PLAY_TO_CLIENT),
|
||||
SERVER_SPEED(ServerSpeedProvider.Packet.class, ServerSpeedProvider.Packet::new, PLAY_TO_CLIENT),
|
||||
BEAM_EFFECT(ZapperBeamPacket.class, ZapperBeamPacket::new, PLAY_TO_CLIENT),
|
||||
CONFIGURE_CONFIG(ConfigureConfigPacket.class, ConfigureConfigPacket::new, PLAY_TO_CLIENT),
|
||||
CONTRAPTION_STALL(ContraptionStallPacket.class, ContraptionStallPacket::new, PLAY_TO_CLIENT),
|
||||
CONTRAPTION_DISASSEMBLE(ContraptionDisassemblyPacket.class, ContraptionDisassemblyPacket::new, PLAY_TO_CLIENT),
|
||||
GLUE_EFFECT(GlueEffectPacket.class, GlueEffectPacket::new, PLAY_TO_CLIENT),
|
||||
CONTRAPTION_SEAT_MAPPING(ContraptionSeatMappingPacket.class, ContraptionSeatMappingPacket::new, PLAY_TO_CLIENT),
|
||||
LIMBSWING_UPDATE(LimbSwingUpdatePacket.class, LimbSwingUpdatePacket::new, PLAY_TO_CLIENT),
|
||||
MINECART_CONTROLLER(MinecartControllerUpdatePacket.class, MinecartControllerUpdatePacket::new, PLAY_TO_CLIENT),
|
||||
FLUID_SPLASH(FluidSplashPacket.class, FluidSplashPacket::new, PLAY_TO_CLIENT),
|
||||
CONTRAPTION_FLUID(ContraptionFluidPacket.class, ContraptionFluidPacket::new, PLAY_TO_CLIENT),
|
||||
|
||||
;
|
||||
|
||||
|
@ -88,14 +92,14 @@ public enum AllPackets {
|
|||
|
||||
private LoadedPacket<?> packet;
|
||||
|
||||
private <T extends SimplePacketBase> AllPackets(Class<T> type, Function<PacketBuffer, T> factory) {
|
||||
packet = new LoadedPacket<>(type, factory);
|
||||
private <T extends SimplePacketBase> AllPackets(Class<T> type, Function<PacketBuffer, T> factory, NetworkDirection direction) {
|
||||
packet = new LoadedPacket<>(type, factory, direction);
|
||||
}
|
||||
|
||||
public static void registerPackets() {
|
||||
channel = NetworkRegistry.ChannelBuilder.named(CHANNEL_NAME)
|
||||
.serverAcceptedVersions(s -> true)
|
||||
.clientAcceptedVersions(s -> true)
|
||||
.serverAcceptedVersions(NETWORK_VERSION::equals)
|
||||
.clientAcceptedVersions(NETWORK_VERSION::equals)
|
||||
.networkProtocolVersion(() -> NETWORK_VERSION)
|
||||
.simpleChannel();
|
||||
for (AllPackets packet : values())
|
||||
|
@ -115,16 +119,18 @@ public enum AllPackets {
|
|||
Function<PacketBuffer, T> decoder;
|
||||
BiConsumer<T, Supplier<Context>> handler;
|
||||
Class<T> type;
|
||||
NetworkDirection direction;
|
||||
|
||||
private LoadedPacket(Class<T> type, Function<PacketBuffer, T> factory) {
|
||||
private LoadedPacket(Class<T> type, Function<PacketBuffer, T> factory, NetworkDirection direction) {
|
||||
encoder = T::write;
|
||||
decoder = factory;
|
||||
handler = T::handle;
|
||||
this.type = type;
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
private void register() {
|
||||
channel.messageBuilder(type, index++)
|
||||
channel.messageBuilder(type, index++, direction)
|
||||
.encoder(encoder)
|
||||
.decoder(decoder)
|
||||
.consumer(handler)
|
||||
|
|
|
@ -21,17 +21,10 @@ import net.minecraft.nbt.CompoundNBT;
|
|||
public class FilesHelper {
|
||||
|
||||
public static void createFolderIfMissing(String name) {
|
||||
Path path = Paths.get(name);
|
||||
if (path.getParent() != null)
|
||||
createFolderIfMissing(path.getParent()
|
||||
.toString());
|
||||
|
||||
if (!Files.isDirectory(path)) {
|
||||
try {
|
||||
Files.createDirectory(path);
|
||||
Files.createDirectories(Paths.get(name));
|
||||
} catch (IOException e) {
|
||||
Create.logger.warn("Could not create Folder: " + name);
|
||||
}
|
||||
Create.logger.warn("Could not create Folder: {}", name);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue