Skip to content

Commit

Permalink
Player will remain in their location during an addon reconfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrptonaught committed Apr 9, 2024
1 parent 823542f commit 7514af3
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.kyrptonaught.serverutils.dimensionLoader.CustomDimHolder;
import net.kyrptonaught.serverutils.dimensionLoader.DimensionLoaderMod;
import net.kyrptonaught.serverutils.discordBridge.MessageSender;
import net.kyrptonaught.serverutils.playerJoinLocation.PlayerJoinLocationMod;
import net.kyrptonaught.serverutils.playerlockdown.PlayerLockdownMod;
import net.kyrptonaught.serverutils.switchableresourcepacks.ResourcePackConfig;
import net.kyrptonaught.serverutils.switchableresourcepacks.SwitchableResourcepacksMod;
Expand Down Expand Up @@ -81,6 +82,7 @@ public static void reloadAddonFiles(MinecraftServer server) {
List<ServerPlayerEntity> players = server.getPlayerManager().getPlayerList();
for (int i = players.size() - 1; i >= 0; i--) {
CMDHelper.executeAs(players.get(i), RECONFIG_FUNCTION);
PlayerJoinLocationMod.excludePlayer(players.get(i));
players.get(i).networkHandler.reconfigure();
}
}
Expand All @@ -92,7 +94,7 @@ public static void onEnterReconfig(ServerConfigurationNetworkHandler handler, Se
handler.endConfiguration();
}

public static List<BattleMapAddon> getAllBattleMaps(){
public static List<BattleMapAddon> getAllBattleMaps() {
return BATTLE_MAPS.values().stream().sorted(Comparator.comparing((battleMapAddon -> battleMapAddon.addon_id.getPath()))).toList();
}

Expand Down Expand Up @@ -154,7 +156,7 @@ private static void battlePrepare(LoadedBattleMapInstance instance, Collection<S
if (sizedConfig.world_border_coords_1 != null && sizedConfig.world_border_coords_2 != null)
CustomWorldBorderMod.getCustomWorldBorderManager(world).setCustomWorldBorder(world, parseBlockPos(sizedConfig.world_border_coords_1), parseBlockPos(sizedConfig.world_border_coords_2));
else
CustomWorldBorderMod.getCustomWorldBorderManager(world).setCustomWorldBorder(world, new BlockPos(-10000,-10000,-10000), new BlockPos(10000,10000,10000));
CustomWorldBorderMod.getCustomWorldBorderManager(world).setCustomWorldBorder(world, new BlockPos(-10000, -10000, -10000), new BlockPos(10000, 10000, 10000));

ChestTrackerMod.reset(world.getServer());
for (String pos : sizedConfig.chest_tracker_coords) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
import net.minecraft.util.Identifier;
import net.minecraft.world.dimension.DimensionType;

import java.nio.file.*;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.Enumeration;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@
import net.minecraft.util.Identifier;
import net.minecraft.world.storage.ChunkStreamVersion;

import java.io.*;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.stream.Stream;

public class Converter {
Expand Down Expand Up @@ -344,7 +350,7 @@ private static List<NbtCompound> readMCAFile(Path file) throws IOException {
raf.seek(4096 + i * 4);
int timestamp = raf.readInt();

raf.seek(4096 * offset + 4); //+4: skip data size
raf.seek(4096L * offset + 4); //+4: skip data size

byte compressionTypeByte = raf.readByte(); //0 - none, 1 - GZIP, 2 deflate - assuming deflate
chunks.add(NbtIo.readCompound(new DataInputStream(ChunkStreamVersion.DEFLATE.wrap(new FileInputStream(raf.getFD())))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;

import java.util.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.function.BiConsumer;

public class Votebook {
Expand Down Expand Up @@ -220,10 +223,10 @@ private static void generateMapPages(List<BattleMapAddon> lemmods) {
mapText.add(Text.empty());

MutableText backBtn = backButton("mapPack_" + config.addon_pack);
if(config.addon_pack.equals("base_base"))
if (config.addon_pack.equals("base_base"))
backBtn = backButton("baseMaps");

mapText.add(voteButton(config.addon_id).append(" ").append(backBtn.append(" ").append(withOpenCmd(bracketTrans("lem.generic.more"), "map_player_rp_settings", "index,0,"+ config.addon_id.toString()))));
mapText.add(voteButton(config.addon_id).append(" ").append(backBtn.append(" ").append(withOpenCmd(bracketTrans("lem.generic.more"), "map_player_rp_settings", "index,0," + config.addon_id.toString()))));

bookLibrary.put("map_" + config.addon_id, createBasicPage().addPage(mapText.toArray(Text[]::new)));
}
Expand Down Expand Up @@ -284,7 +287,7 @@ private static void generateMapExtras(DynamicData data, BookPage bookPage) {
Text requiredHeader = withHover(dashTrans("lem.mapdecider.menu.requiredpacks"), trimName(addon.getNameText(), 20));
if (addon.required_packs == null || addon.required_packs.packs.isEmpty()) {
splitAcrossPages(bookPage, 1, List.of(Text.translatable("gui.none")), requiredHeader, "map_" + addon.addon_id, true, (rpOption, index, pageText) -> {
pageText.add(colored(rpOption,Formatting.DARK_GRAY));
pageText.add(colored(rpOption, Formatting.DARK_GRAY));
});
} else {
splitAcrossPages(bookPage, 10, addon.required_packs.packs, requiredHeader, "map_" + addon.addon_id, true, (rpOption, index, pageText) -> {
Expand All @@ -296,7 +299,7 @@ private static void generateMapExtras(DynamicData data, BookPage bookPage) {
Text optionalHeader = withHover(dashTrans("lem.mapdecider.menu.optionalpacks"), trimName(addon.getNameText(), 20));
if (addon.optional_packs == null || addon.optional_packs.packs.isEmpty()) {
splitAcrossPages(bookPage, 1, List.of(Text.translatable("gui.none")), optionalHeader, "map_" + addon.addon_id, false, (rpOption, index, pageText) -> {
pageText.add(colored(rpOption,Formatting.DARK_GRAY));
pageText.add(colored(rpOption, Formatting.DARK_GRAY));
});
} else {
splitAcrossPages(bookPage, 8, addon.optional_packs.packs, optionalHeader, "map_" + addon.addon_id, false, (rpOption, index, pageText) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public class FormatToMC {

public static Text parseMessage(Message discordMessage, MutableText prefix, boolean isAdmin) {
if(isAdmin && discordMessage.getContentRaw().startsWith("$PARSE="))
if (isAdmin && discordMessage.getContentRaw().startsWith("$PARSE="))
return parseAdminTextJson(discordMessage, prefix);

HashMap<String, String> replacementURLs = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public class PlayerManagerMixin {

@Redirect(method = "onPlayerConnect", at = @At(target = "Lnet/minecraft/world/dimension/DimensionType;worldFromDimensionNbt(Lcom/mojang/serialization/Dynamic;)Lcom/mojang/serialization/DataResult;", value = "INVOKE"))
public DataResult<RegistryKey<World>> forceSpawnLocation(Dynamic<?> nbt, ClientConnection connection, ServerPlayerEntity player) {
if (PlayerJoinLocationMod.ENABLED) {
if (PlayerJoinLocationMod.ENABLED && !PlayerJoinLocationMod.isExcludedPlayer(player)) {
PlayerJoinLocationMod.removePlayer(player);
PlayerJoinLocationConfig config = ServerUtilsMod.playerJoinLocationMod.getConfig();
player.setPos(config.posX, config.posY, config.posZ);
return DataResult.success(World.OVERWORLD);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
import net.kyrptonaught.serverutils.ModuleWConfig;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;

import java.util.HashSet;
import java.util.UUID;

public class PlayerJoinLocationMod extends ModuleWConfig<PlayerJoinLocationConfig> {
public static boolean ENABLED = false;

private static final HashSet<UUID> EXCLUDED_PLAYERS = new HashSet<>();

@Override
public void registerCommands(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(CommandManager.literal("playerJoinLocation")
Expand All @@ -20,6 +26,18 @@ public void registerCommands(CommandDispatcher<ServerCommandSource> dispatcher)
}))));
}

public static void excludePlayer(ServerPlayerEntity player) {
EXCLUDED_PLAYERS.add(player.getUuid());
}

public static void removePlayer(ServerPlayerEntity player) {
EXCLUDED_PLAYERS.remove(player.getUuid());
}

public static boolean isExcludedPlayer(ServerPlayerEntity player) {
return EXCLUDED_PLAYERS.contains(player.getUuid());
}

@Override
public PlayerJoinLocationConfig createDefaultConfig() {
return new PlayerJoinLocationConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static void onPlayerConnect(ServerPlayNetworkHandler handler, PacketSende
setFabricClient(handler.player, true);
}

public static void onPlayerDisconnect(ServerPlayNetworkHandler handler, MinecraftServer server){
public static void onPlayerDisconnect(ServerPlayNetworkHandler handler, MinecraftServer server) {
queuedPlayerData.remove(((ServerCommonNetworkHandlerAccessor) handler).getConnection());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package net.kyrptonaught.serverutils.takeEverything;

import net.minecraft.block.SkullBlock;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.Equipment;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.*;
import net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.screen.PlayerScreenHandler;
Expand Down Expand Up @@ -65,6 +63,11 @@ public static boolean isBetter(ItemStack og, ItemStack newStack) {
if (og.isOf(Items.ELYTRA))
return false;

if (newStack.getItem() instanceof VerticallyAttachableBlockItem newBlock && og.getItem() instanceof VerticallyAttachableBlockItem ogBlock) {
if (newBlock.getBlock() instanceof SkullBlock && ogBlock.getBlock() instanceof SkullBlock)
return false;
}

if (og.getItem() instanceof ArmorItem && newStack.getItem() instanceof ArmorItem)
return ((ArmorItem) newStack.getItem()).getProtection() > ((ArmorItem) og.getItem()).getProtection();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public static void trySendWelcomeMessage(MinecraftServer server, ServerPlayerEnt
playerMsgSent.add(player.getUuid());
}


@Override
public WelcomeMessageConfig createDefaultConfig() {
return new WelcomeMessageConfig();
Expand Down

0 comments on commit 7514af3

Please sign in to comment.