Skip to content

Commit

Permalink
Switch to ModTools 2.0 format.
Browse files Browse the repository at this point in the history
Add support for loading lobbies.
  • Loading branch information
kyrptonaught committed Feb 1, 2024
1 parent d8336c1 commit 96daf58
Show file tree
Hide file tree
Showing 12 changed files with 361 additions and 209 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ dependencies {
shadow implementation("io.javalin:javalin:6.0.0")

//Apache Compress
shadow implementation("org.apache.commons:commons-compress:1.24.0")
shadow implementation("org.apache.commons:commons-compress:1.25.0")
}

loom {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ loader_version=0.15.6
fabric_version=0.95.4+1.20.4

# Mod Properties
mod_version=1.0.8b1-1.20.4
mod_version=1.0.8b2-1.20.4
maven_group=net.kyrptonaught
archives_base_name=ServerUtils

Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.command.argument.IdentifierArgumentType;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;

import java.util.Collection;
import java.util.List;

public class CustomMapLoaderCommands {
Expand All @@ -19,18 +21,18 @@ public static void registerCommands(CommandDispatcher<ServerCommandSource> dispa
cmd.then(CommandManager.literal("voting")
.then(CommandManager.literal("openBook")
.executes(context -> {
Votebook.generateBookLibrary(CustomMapLoaderMod.loadedMaps.values().stream().toList());
Votebook.generateBookLibrary(CustomMapLoaderMod.BATTLE_MAPS.values().stream().toList());
Votebook.openbook(context.getSource().getPlayer(), "title");
return 1;
}))
.then(CommandManager.literal("giveBook")
.executes(context -> {
Votebook.generateBookLibrary(CustomMapLoaderMod.loadedMaps.values().stream().toList());
Votebook.generateBookLibrary(CustomMapLoaderMod.BATTLE_MAPS.values().stream().toList());
Votebook.giveBook(context.getSource().getPlayer(), "title");
return 1;
}))
.then(CommandManager.literal("showBookPage")
.then(CommandManager.argument("page", StringArgumentType.word())
.then(CommandManager.argument("page", StringArgumentType.greedyString())
.executes(context -> {
String page = StringArgumentType.getString(context, "page");

Expand All @@ -41,19 +43,19 @@ public static void registerCommands(CommandDispatcher<ServerCommandSource> dispa
.fork(dispatcher.getRoot(), (context -> {
context.getChild().getCommand().run(context);

Votebook.generateBookLibrary(CustomMapLoaderMod.loadedMaps.values().stream().toList());
Votebook.generateBookLibrary(CustomMapLoaderMod.BATTLE_MAPS.values().stream().toList());
String page = StringArgumentType.getString(context, "page");
Votebook.openbook(context.getSource().getPlayer(), page);

return List.of();
})))))
.then(CommandManager.literal("vote")
.then(CommandManager.argument("map", StringArgumentType.word())
.then(CommandManager.argument("map", IdentifierArgumentType.identifier())
.executes(context -> {
ServerPlayerEntity player = context.getSource().getPlayer();
String map = StringArgumentType.getString(context, "map");
Identifier map = IdentifierArgumentType.getIdentifier(context, "map");

Voter.voteFor(context.getSource().getServer(), player, map, CustomMapLoaderMod.loadedMaps.get(map).getName());
Voter.voteFor(context.getSource().getServer(), player, map, CustomMapLoaderMod.BATTLE_MAPS.get(map).getNameText());
return 1;
})))
.then(CommandManager.literal("removeVote")
Expand All @@ -63,14 +65,15 @@ public static void registerCommands(CommandDispatcher<ServerCommandSource> dispa
}))
.then(CommandManager.literal("start")
.executes(context -> {
Voter.prepVote(context.getSource().getServer(), CustomMapLoaderMod.loadedMaps.values().stream().toList());
Voter.prepVote(context.getSource().getServer(), CustomMapLoaderMod.BATTLE_MAPS.values().stream().toList());
return 1;
}))
.then(CommandManager.literal("end")
.then(CommandManager.argument("dimID", IdentifierArgumentType.identifier())
.executes(context -> {
Identifier id = IdentifierArgumentType.getIdentifier(context, "dimID");
CustomMapLoaderMod.prepareLemmod(context.getSource().getServer(), id);
Identifier winner = Voter.endVote(context.getSource().getServer());
CustomMapLoaderMod.prepareBattleMap(context.getSource().getServer(), winner, id);
return 1;
}))));

Expand All @@ -84,7 +87,43 @@ public static void registerCommands(CommandDispatcher<ServerCommandSource> dispa
return 1;
})))));
}
cmd.then(CommandManager.literal("unload")
.then(CommandManager.argument("dimID", IdentifierArgumentType.identifier())
.executes(context -> {
Identifier id = IdentifierArgumentType.getIdentifier(context, "dimID");
CustomMapLoaderMod.unloadMap(context.getSource().getServer(), id);
return 1;
})));

cmd.then(CommandManager.literal("lobby")
.then(CommandManager.literal("load")
.then(CommandManager.argument("lobby", IdentifierArgumentType.identifier())
.then(CommandManager.argument("dimID", IdentifierArgumentType.identifier())
.executes(context -> {
Identifier id = IdentifierArgumentType.getIdentifier(context, "dimID");
Identifier lobbyID = IdentifierArgumentType.getIdentifier(context, "lobby");
CustomMapLoaderMod.prepareLobby(context.getSource().getServer(), lobbyID, id);
return 1;
}))))
.then(CommandManager.literal("tp")
.then(CommandManager.argument("dimID", IdentifierArgumentType.identifier())
.then(CommandManager.argument("players", EntityArgumentType.players())
.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");

CustomMapLoaderMod.teleportToLobby(id, players, winner);
return 1;
}))
.executes(context -> {
Identifier id = IdentifierArgumentType.getIdentifier(context, "dimID");
Collection<ServerPlayerEntity> players = EntityArgumentType.getPlayers(context, "players");

CustomMapLoaderMod.teleportToLobby(id, players, null);
return 1;
})))));
dispatcher.register(cmd);
}
}
Loading

0 comments on commit 96daf58

Please sign in to comment.