Skip to content

Commit

Permalink
various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
UpcraftLP committed Jan 3, 2024
1 parent 52143a2 commit e52d1a7
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.loading.FMLPaths;
import org.slf4j.Logger;

@Mod(TribesMain.MOD_ID)
Expand All @@ -27,12 +26,8 @@ public TribesMain() {
IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus();

// register configs
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, Config.client_config);
ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, Config.server_config);

// load configs
Config.loadConfig(Config.client_config, FMLPaths.CONFIGDIR.get().resolve(MOD_ID + "-client.toml").toString());
Config.loadConfig(Config.server_config, FMLPaths.CONFIGDIR.get().resolve(MOD_ID + "-server.toml").toString());
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, Config.client_config, "tribes-client.toml");
ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, Config.server_config, "tribes-server.toml");

// register
ItemInit.ITEMS.register(eventBus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import net.minecraft.commands.Commands;
import net.minecraft.world.entity.player.Player;

import java.util.Arrays;
import java.util.stream.Collectors;

public class AutobanCommands {
public static ArgumentBuilder<CommandSourceStack, ?> register() {
return Commands.literal("autoban")
Expand Down Expand Up @@ -73,7 +76,7 @@ public static int handleRankSettings(CommandContext<CommandSourceStack> source)

Member.Rank rank = Member.Rank.fromString(rankName);
if (rank == null) {
source.getSource().sendFailure(TribeError.INVALID_RANK.getText());
source.getSource().sendFailure(TribeError.INVALID_RANK.getTextWithArgs(Arrays.stream(Member.Rank.values()).map(Member.Rank::getSerializedName).collect(Collectors.joining(", "))));
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import io.github.lukegrahamlandry.tribes.tribe_data.TribeError;
import io.github.lukegrahamlandry.tribes.tribe_data.TribeSuccessType;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.world.entity.player.Player;
Expand All @@ -22,7 +21,6 @@ public class ConfirmCommand {
}

public static void add(Player player, IConfirmAction action) {
player.displayClientMessage(TribeSuccessType.MUST_CONFIRM.getBlueText(), false);
CONFIRM_ACTIONS.put(player.getUUID(), action);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.github.lukegrahamlandry.tribes.config.TribesConfig;
import io.github.lukegrahamlandry.tribes.init.BannerInit;
import io.github.lukegrahamlandry.tribes.tribe_data.*;
import net.minecraft.Util;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.nbt.CompoundTag;
Expand Down Expand Up @@ -64,6 +65,7 @@ private static int handleChoose(CommandContext<CommandSourceStack> source) throw
long hoursToWait = Instant.now().until(lastChange.plus(TribesConfig.daysBetweenDeityChanges(), ChronoUnit.DAYS), ChronoUnit.HOURS);
source.getSource().sendFailure(TribeError.WAIT_HOURS.getTextWithArgs(hoursToWait));
} else {
player.sendMessage(TribeSuccessType.MUST_CONFIRM.getBlueText(), Util.NIL_UUID);
ConfirmCommand.add(player, () -> {
tribe.setDeityInfo(new DeityInfo(deity.key, Instant.now()));
source.getSource().sendSuccess(TribeSuccessType.CHOOSE_DEITY.getText(deity.displayName), true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.github.lukegrahamlandry.tribes.tribe_data.TribeHelper;
import io.github.lukegrahamlandry.tribes.tribe_data.TribeSuccessType;
import io.github.lukegrahamlandry.tribes.tribe_data.TribesManager;
import net.minecraft.Util;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.TextColor;
Expand Down Expand Up @@ -45,6 +46,7 @@ public static int handleSelect(CommandContext<CommandSourceStack> ctx) throws Co
return 0;
}

player.sendMessage(TribeSuccessType.MUST_CONFIRM.getBlueText(), Util.NIL_UUID);
ConfirmCommand.add(player, () -> {
if (tribe.selectHemisphere(player, result.value()).success()) {
TribeHelper.broadcastMessage(tribe, TribeSuccessType.CHOOSE_HEMISPHERE, player, ctx.getSource().getServer(), side);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import io.github.lukegrahamlandry.tribes.tribe_data.TribeError;
import io.github.lukegrahamlandry.tribes.tribe_data.TribeSuccessType;
import io.github.lukegrahamlandry.tribes.tribe_data.TribesManager;
import net.minecraft.Util;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.world.entity.player.Player;
import net.minecraft.server.level.ServerPlayer;

public class LeaveTribeCommand {
public static ArgumentBuilder<CommandSourceStack, ?> register() {
Expand All @@ -20,10 +21,11 @@ public class LeaveTribeCommand {
}

public static int handleLeave(CommandContext<CommandSourceStack> source) throws CommandSyntaxException {
Player player = source.getSource().getPlayerOrException();
ServerPlayer player = source.getSource().getPlayerOrException();

Tribe tribe = TribesManager.getTribeOf(player.getUUID());
if (tribe != null) {
player.sendMessage(TribeSuccessType.MUST_CONFIRM.getBlueText(), Util.NIL_UUID);
ConfirmCommand.add(player, () -> {
TribesManager.leaveTribe(player);
source.getSource().sendSuccess(TribeSuccessType.YOU_LEFT.getText(), true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
import io.github.lukegrahamlandry.tribes.api.tribe.Member;
import io.github.lukegrahamlandry.tribes.commands.util.OfflinePlayerArgumentType;
import io.github.lukegrahamlandry.tribes.tribe_data.*;
import net.minecraft.Util;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.entity.player.Player;
import net.minecraft.server.level.ServerPlayer;

import java.util.UUID;

Expand All @@ -25,7 +26,7 @@ public class PromotePlayerCommand {
}

public static int handle(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
Player playerRunning = context.getSource().getPlayerOrException();
ServerPlayer playerRunning = context.getSource().getPlayerOrException();
UUID playerTarget = OfflinePlayerArgumentType.getOfflinePlayer(context, "player");
MinecraftServer server = context.getSource().getServer();

Expand All @@ -44,8 +45,9 @@ public static int handle(CommandContext<CommandSourceStack> context) throws Comm
return 0;
}

context.getSource().sendSuccess(new TextComponent("make " + OfflinePlayerArgumentType.getPlayerName(playerTarget) + " the leader of your tribe?"), true);
playerRunning.sendMessage(new TextComponent("make " + OfflinePlayerArgumentType.getPlayerName(playerTarget) + " the leader of your tribe?"), Util.NIL_UUID);

playerRunning.sendMessage(TribeSuccessType.MUST_CONFIRM.getBlueText(), Util.NIL_UUID);
ConfirmCommand.add(playerRunning, () -> {
var result = tribe.promotePlayer(playerRunning.getUUID(), playerTarget);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ private OfflinePlayerArgumentType() {
@Override
public OfflinePlayerArgumentType.Data parse(StringReader reader) throws CommandSyntaxException {
String nameOrId = reader.readUnquotedString();

var onlinePlayer = Optional.ofNullable(server).map(s -> s.getPlayerList().getPlayerByName(nameOrId));
if (onlinePlayer.isPresent()) {
return new Data(onlinePlayer.get().getUUID());
}

try {
return new Data(UUIDTypeAdapter.fromString(nameOrId));
} catch (IllegalArgumentException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.github.lukegrahamlandry.tribes.tribe_data.TribeError;
import io.github.lukegrahamlandry.tribes.tribe_data.TribeSuccessType;
import io.github.lukegrahamlandry.tribes.tribe_data.TribesManager;
import net.minecraft.Util;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraftforge.network.NetworkEvent;

Expand All @@ -16,24 +17,26 @@ public PacketLeaveTribe(FriendlyByteBuf buf) {

}

public void encode(FriendlyByteBuf buf){
public void encode(FriendlyByteBuf buf) {

}

public PacketLeaveTribe(){
public PacketLeaveTribe() {

}

public void handle(Supplier<NetworkEvent.Context> ctx){
public void handle(Supplier<NetworkEvent.Context> ctx) {
var player = ctx.get().getSender();
ctx.get().enqueueWork(() -> {
Tribe tribe = TribesManager.getTribeOf(ctx.get().getSender().getUUID());
if (tribe != null){
ConfirmCommand.add(ctx.get().getSender(), () -> {
TribesManager.leaveTribe(ctx.get().getSender());
ctx.get().getSender().sendMessage(TribeSuccessType.YOU_LEFT.getText(), ctx.get().getSender().getUUID());
Tribe tribe = TribesManager.getTribeOf(player.getUUID());
if (tribe != null) {
player.sendMessage(TribeSuccessType.MUST_CONFIRM.getBlueText(), Util.NIL_UUID);
ConfirmCommand.add(player, () -> {
TribesManager.leaveTribe(player);
player.sendMessage(TribeSuccessType.YOU_LEFT.getText(), Util.NIL_UUID);
});
} else {
ctx.get().getSender().sendMessage(TribeError.YOU_NOT_IN_TRIBE.getText(), ctx.get().getSender().getUUID());
player.sendMessage(TribeError.YOU_NOT_IN_TRIBE.getText(), Util.NIL_UUID);
}
});
ctx.get().setPacketHandled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public TribeResult<ChunkPos> unclaimChunk(ChunkPos chunk, UUID player) {

public TribeResult<Hemisphere> validateSelectHemi(Player player, String side) {
var runRank = this.getRankOf(player.getUUID());
if (runRank.compareTo(TribesConfig.rankToChooseHemisphere()) < 0) return TribeResult.error(TribeError.RANK_TOO_LOW);
if (runRank.compareTo(TribesConfig.rankToChooseHemisphere()) <= 0) return TribeResult.error(TribeError.RANK_TOO_LOW);
if (this.getTribeTier() < TribesConfig.getMinTierToSelectHemi()) return TribeResult.error(TribeError.WEAK_TRIBE);
if (this.hemisphereAccess != Hemisphere.NONE) return TribeResult.error(TribeError.ALREADY_HAVE_HEMISPHERE);
if (TribesConfig.getHemisphereDirection() == HemisphereDirection.NORTH_SOUTH) {
Expand All @@ -391,7 +391,7 @@ public TribeResult<Hemisphere> validateSelectHemi(Player player, String side) {

public TribeResult<Hemisphere> selectHemisphere(Player player, Hemisphere hemisphere) {
var runRank = this.getRankOf(player.getUUID());
if (runRank.compareTo(TribesConfig.rankToChooseHemisphere()) < 0) return TribeResult.error(TribeError.RANK_TOO_LOW);
if (runRank.compareTo(TribesConfig.rankToChooseHemisphere()) <= 0) return TribeResult.error(TribeError.RANK_TOO_LOW);
if (this.getTribeTier() < TribesConfig.getMinTierToSelectHemi()) return TribeResult.error(TribeError.WEAK_TRIBE);
if (this.hemisphereAccess != Hemisphere.NONE) return TribeResult.error(TribeError.ALREADY_HAVE_HEMISPHERE);
this.hemisphereAccess = hemisphere;
Expand Down
18 changes: 9 additions & 9 deletions src/main/resources/assets/tribes/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"error.tribes.in_tribe": "You are already in a tribe.",
"error.tribes.name_too_long": "That name is too long.",
"error.tribes.invalid_tribe": "Invalid Tribe.",
"error.tribes.rank_too_low": "Your rank in your tribe is too low",
"error.tribes.rank_too_low": "Your rank in your tribe is too low.",
"error.tribes.you_not_in_tribe": "You are not in a tribe.",
"error.tribes.in_other_tribe": "That player is already in a tribe.",
"error.tribes.banned": "Banned from tribe.",
Expand All @@ -33,11 +33,11 @@
"error.tribes.arg_player": "Specify a player to ban.",
"error.tribes.arg_deity": "Specify a deity.",
"error.tribes.arg_missing": "Missing an argument.",
"error.tribes.invalid_rank": "That is not a valid rank. Options: [member, officer, vice leader, leader]",
"error.tribes.invalid_rank": "That is not a valid rank. Options: [%s]",
"error.tribes.not_private": "Your tribe is not private.",
"error.tribes.is_private": "That tribe is private. Cannot be joined without an invitation.",
"error.tribes.event_cancelled": "Another mod prohibited this action.",
"error.tribes.player_not_found": "No player found matching %s",
"error.tribes.player_not_found": "No player found matching '%s'.",
"success.tribes.made_tribe": "The tribe %s has been created.",
"success.tribes.ally_tribe": "The tribe %s is now your ally.",
"success.tribes.enemy_tribe": "The tribe %s is now your enemy.",
Expand All @@ -47,7 +47,7 @@
"success.tribes.ban_player": "The player %s has been banned from your tribe.",
"success.tribes.unban_player": "The player %s has been unbanned from your tribe.",
"success.tribes.count_tribe": "The tribe %s has %d members (tier %d).",
"success.tribes.delete_tribe": "Your tribe has been deleted",
"success.tribes.delete_tribe": "Your tribe has been deleted.",
"success.tribes.choose_deity": "Your tribe now follows %s.",
"success.tribes.describe_deity": "%s is the %s of %s.",
"success.tribes.make_holy_banner": "The banner has been inscribed with your holy symbol.",
Expand All @@ -59,7 +59,7 @@
"success.tribes.you_joined": "You have joined the tribe %s.",
"success.tribes.someone_joined": "%s has joined your tribe!",
"success.tribes.set_initials": "Your tribe initials are now %s.",
"success.tribes.which_tribe": "%s is in the tribe %s",
"success.tribes.which_tribe": "%s is in the tribe %s.",
"success.tribes.which_no_tribe": "%s is not in a tribe.",
"success.tribes.must_confirm": "Type \"/tribe confirm\" to follow that deity.",
"success.tribes.autoban_numbers": "Your tribe will autoban people who die %d times within %d RL days.",
Expand All @@ -68,11 +68,11 @@
"success.tribes.choose_hemi": "Your tribe has chosen the %s hemisphere.",
"success.tribes.ban_for_deaths": "The player %s has been banned from your tribe for dying too often.",
"success.tribes.alert_join": "use the '/tribe join' command to join a tribe!",
"success.tribes.alert_effects": "Use ''/tribe effects'' to select your tribe's strength & weaknesses.",
"success.tribes.alert_vice_leader": "Use ''/tribe promote PlayerNameHere'' to promote a member to an officer, and again to promote an officer to vice leader. If you leave your tribe, the vice leader will inherit your tribe. There can be any number of members and officers but only 1 vice leader.",
"success.tribes.alert_deity": "Use ''/tribe deity list'' to see a list of deities to you can follow. Then use ''/tribe deity choose DeityNameHere''.",
"success.tribes.alert_effects": "Use \"/tribe effects\" to select your tribe's strength & weaknesses.",
"success.tribes.alert_vice_leader": "Use \"/tribe promote PlayerNameHere\" to promote a member to an officer, and again to promote an officer to vice leader. If you leave your tribe, the vice leader will inherit your tribe. There can be any number of members and officers but only 1 vice leader.",
"success.tribes.alert_deity": "Use \"/tribe deity list\" to see a list of deities to you can follow. Then use \"/tribe deity choose DeityNameHere\".",
"success.tribes.no_bans": "%s has not been banned from any tribes.",
"success.tribes.list_bans": "%s has been banned from: %s",
"success.tribes.list_bans": "%s has been banned from: %s.",
"success.tribes.invite_sent": "%s has been invited to your tribe.",
"success.tribes.invite_removed": "Any invites of %s to your tribe have been revoked.",
"success.tribes.now_private": "Your tribe is now private. Players cannot join without an invitation.",
Expand Down

0 comments on commit e52d1a7

Please sign in to comment.