Skip to content

Commit

Permalink
Add command to convert maps
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrptonaught committed Apr 8, 2024
1 parent 28c7ba1 commit fea33e9
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import eu.pb4.sgui.virtual.book.BookScreenHandler;
import net.kyrptonaught.serverutils.customMapLoader.converter.Converter;
import net.kyrptonaught.serverutils.customMapLoader.voting.HostOptions;
import net.kyrptonaught.serverutils.customMapLoader.voting.Votebook;
import net.kyrptonaught.serverutils.customMapLoader.voting.Voter;
Expand All @@ -29,7 +30,7 @@ public static void registerCommands(CommandDispatcher<ServerCommandSource> dispa
cmd.then(CommandManager.literal("voting")
.then(CommandManager.literal("openBook")
.executes(context -> {
Votebook.generateBookLibrary(CustomMapLoaderMod.getAllBattleMaps());
//Votebook.generateBookLibrary(CustomMapLoaderMod.getAllBattleMaps());
Votebook.getPage(context.getSource().getPlayer(), "title", null).open();
return 1;
}))
Expand All @@ -55,7 +56,7 @@ public static void registerCommands(CommandDispatcher<ServerCommandSource> dispa
String[] args = StringArgumentType.getString(context, "arg").split(",");

Votebook.getPage(context.getSource().getPlayer(), page, args).open();
if("index".equals(args[0]) && context.getSource().getPlayer().currentScreenHandler instanceof BookScreenHandler screen)
if ("index".equals(args[0]) && context.getSource().getPlayer().currentScreenHandler instanceof BookScreenHandler screen)
screen.getGui().setPage(Integer.parseInt(args[1]));

return 1;
Expand All @@ -68,7 +69,7 @@ public static void registerCommands(CommandDispatcher<ServerCommandSource> dispa
String[] args = StringArgumentType.getString(context, "arg").split(",");

Votebook.getPage(context.getSource().getPlayer(), page, args).open();
if("index".equals(args[0]) && context.getSource().getPlayer().currentScreenHandler instanceof BookScreenHandler screen)
if ("index".equals(args[0]) && context.getSource().getPlayer().currentScreenHandler instanceof BookScreenHandler screen)
screen.getGui().setPage(Integer.parseInt(args[1]));

return List.of();
Expand All @@ -83,10 +84,10 @@ public static void registerCommands(CommandDispatcher<ServerCommandSource> dispa
return List.of();
})))))
.then(CommandManager.literal("vote")
.then(CommandManager.argument("map", IdentifierArgumentType.identifier())
.then(CommandManager.argument("mapName", IdentifierArgumentType.identifier())
.executes(context -> {
ServerPlayerEntity player = context.getSource().getPlayer();
Identifier map = IdentifierArgumentType.getIdentifier(context, "map");
Identifier map = IdentifierArgumentType.getIdentifier(context, "mapName");

Voter.voteFor(context.getSource().getServer(), player, map);
return 1;
Expand Down Expand Up @@ -276,6 +277,24 @@ public static void registerCommands(CommandDispatcher<ServerCommandSource> dispa
CustomMapLoaderMod.teleportToLobby(id, players, null);
return 1;
})))));
/*
cmd.then(CommandManager.literal("reload")
.executes(context -> {
CustomMapLoaderMod.BATTLE_MAPS.clear();
CustomMapLoaderMod.LOBBY_MAPS.clear();
IO.discoverAddons(context.getSource().getServer());
Votebook.generateBookLibrary(CustomMapLoaderMod.getAllBattleMaps());
return 1;
}));
*/

cmd.then(CommandManager.literal("convert")
.executes(context -> {
Converter.ConvertAll();
return 1;
}));

dispatcher.register(cmd);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,18 @@ public static void battleLoad(MinecraftServer server, Identifier addon, Identifi
});

server.getPlayerManager().broadcast(Text.literal("Loading map: ").append(config.getNameText()), false);
MessageSender.sendGameMessageWMentions(Text.literal("Loading map: ").append(config.getNameText()));
MessageSender.sendGameMessageWMentions(Text.literal("Loading map ").append(config.getNameText()));
}

private static void battlePrepare(LoadedBattleMapInstance instance, Collection<ServerPlayerEntity> players) {
ServerWorld world = instance.getWorld();
BattleMapAddon.MapSizeConfig sizedConfig = instance.getSizedAddon();
ParsedPlayerCoords centerPos = parseVec3D(sizedConfig.center_coords);

CustomWorldBorderMod.getCustomWorldBorderManager(world).setCustomWorldBorder(world, parseBlockPos(sizedConfig.world_border_coords_1), parseBlockPos(sizedConfig.world_border_coords_2));
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));

ChestTrackerMod.reset(world.getServer());
for (String pos : sizedConfig.chest_tracker_coords) {
Expand Down
Loading

0 comments on commit fea33e9

Please sign in to comment.