Skip to content

Commit

Permalink
Fix lobby tp failing if no winner.
Browse files Browse the repository at this point in the history
Add ability to specify slot for votebook.
Suppress error if addon does not provide a datapack.
  • Loading branch information
kyrptonaught committed Jun 26, 2024
1 parent c7410f6 commit 616d364
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/main/java/net/kyrptonaught/serverutils/FileHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ public static String readFile(Path filePath) {
return null;
}

public static boolean exists(Path filePath) {
return Files.exists(filePath);
}

public static String fixPathSeparator(String name) {
return name.replaceAll("\\\\", "/");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.BoolArgumentType;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import eu.pb4.sgui.virtual.book.BookScreenHandler;
Expand Down Expand Up @@ -30,17 +31,22 @@ public static void registerCommands(CommandDispatcher<ServerCommandSource> dispa
cmd.then(CommandManager.literal("voting")
.then(CommandManager.literal("openBook")
.executes(context -> {
//Votebook.generateBookLibrary(CustomMapLoaderMod.getAllBattleMaps());
Votebook.getPage(context.getSource().getPlayer(), "title", null).open();
return 1;
}))
.then(CommandManager.literal("giveBook")
.executes(context -> {
//Votebook.generateBookLibrary(CustomMapLoaderMod.getAllBattleMaps());
ServerPlayerEntity player = context.getSource().getPlayer();
player.giveItemStack(Votebook.getPage(player, "title", null).getBook());
return 1;
}))
})
.then(CommandManager.argument("slot", IntegerArgumentType.integer(0, 100))
.executes(context -> {
int slot = IntegerArgumentType.getInteger(context, "slot");
ServerPlayerEntity player = context.getSource().getPlayer();
player.getInventory().setStack(slot, Votebook.getPage(player, "title", null).getBook());
return 1;
})))
.then(CommandManager.literal("showBookPage")
.then(CommandManager.argument("page", StringArgumentType.string())
.executes(context -> {
Expand Down Expand Up @@ -264,8 +270,13 @@ public static void registerCommands(CommandDispatcher<ServerCommandSource> dispa
.then(CommandManager.argument("winner", EntityArgumentType.player())
.executes(context -> {
Identifier id = IdentifierArgumentType.getIdentifier(context, "dimID");
Collection<ServerPlayerEntity> players = EntityArgumentType.getPlayers(context, "players");
ServerPlayerEntity winner = EntityArgumentType.getPlayer(context, "winner");
Collection<ServerPlayerEntity> players = EntityArgumentType.getOptionalPlayers(context, "players");
Collection<ServerPlayerEntity> winners = EntityArgumentType.getOptionalPlayers(context, "winner");

ServerPlayerEntity winner = null;
if (!winners.isEmpty()) {
winner = winners.iterator().next();
}

CustomMapLoaderMod.teleportToLobby(id, players, winner);
return 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.kyrptonaught.serverutils.customMapLoader.addons;

import net.kyrptonaught.serverutils.FileHelper;
import net.minecraft.resource.*;
import net.minecraft.resource.fs.ResourceFileSystem;
import net.minecraft.text.Text;
Expand All @@ -24,7 +25,8 @@ public class AddonResourcePackProvider implements ResourcePackProvider {
private final HashMap<Identifier, Path> loadedAddons = new HashMap<>();

public void loadAddon(Identifier id, Path path) {
loadedAddons.put(id, path.resolve("datapack"));
if (FileHelper.exists(path.resolve("datapack")))
loadedAddons.put(id, path.resolve("datapack"));
}

public void unloadAddon(Identifier id) {
Expand Down

0 comments on commit 616d364

Please sign in to comment.