[factions-banking] Fixed faction block to be correct faction on first place. Added faction tiers.
Some checks are pending
build / build (21) (push) Waiting to run

This commit is contained in:
Jkibbels 2025-01-20 00:20:18 -05:00
parent fa5bc741ec
commit 0ed8838de0
12 changed files with 139 additions and 41 deletions

View File

@ -47,7 +47,7 @@ public class FactionBeacon extends AbstractNode {
@Override @Override
public void RegisterCallbacks() { public void RegisterCallbacks() {
System.out.println("REGISTER CALLBACKS FOR FACTION BEACON CALLED"); System.out.println("REGISTER CALLBACKS FOR FACTION BEACON CALLED");
PlayerInBaseCallback.EVENT.register((player, world, power) -> { PlayerInBaseCallback.EVENT.register((player, world, power, factionTier) -> {
// Make sure player can fly while inside the border. We don't ever want to run this more than once! // Make sure player can fly while inside the border. We don't ever want to run this more than once!
// player.sendMessage(Text.of("Applying effects")); // player.sendMessage(Text.of("Applying effects"));
ApplyEffects((ServerPlayerEntity) player); ApplyEffects((ServerPlayerEntity) player);

View File

@ -78,7 +78,7 @@ public class FactionFlight extends AbstractNode {
@Override @Override
public void RegisterCallbacks() { public void RegisterCallbacks() {
PlayerEnteredBaseCallback.EVENT.register((player, world, power) -> { PlayerEnteredBaseCallback.EVENT.register((player, world, power, factionTier) -> {
player.sendMessage(Text.of("Faction flight enabled")); player.sendMessage(Text.of("Faction flight enabled"));
canFly = true; canFly = true;
ServerPlayerEntity serverPlayer = (ServerPlayerEntity) player; ServerPlayerEntity serverPlayer = (ServerPlayerEntity) player;
@ -88,7 +88,9 @@ public class FactionFlight extends AbstractNode {
return ActionResult.PASS; return ActionResult.PASS;
}); });
PlayerInBaseCallback.EVENT.register((player, world, power) -> { PlayerInBaseCallback.EVENT.register((player, world, power, factionTier) -> {
System.out.println("Faction power is " + power);
System.out.println("Faction tier is " + factionTier.name());
// Make sure player can fly while inside the border. We don't ever want to run this more than once! // Make sure player can fly while inside the border. We don't ever want to run this more than once!
if (!canFly && !loginInBaseToggle) { if (!canFly && !loginInBaseToggle) {
player.sendMessage(Text.of("Faction flight enabled")); player.sendMessage(Text.of("Faction flight enabled"));
@ -100,7 +102,7 @@ public class FactionFlight extends AbstractNode {
return ActionResult.PASS; return ActionResult.PASS;
}); });
PlayerCommandFlightCallback.EVENT.register((player, world, power) -> { PlayerCommandFlightCallback.EVENT.register((player, world, power, factionTier) -> {
ServerPlayerEntity serverPlayer = (ServerPlayerEntity) player; ServerPlayerEntity serverPlayer = (ServerPlayerEntity) player;
Boolean isFlying = TurnOnFlight(serverPlayer); Boolean isFlying = TurnOnFlight(serverPlayer);
// This is a toggle command; so first we get if the player is flying // This is a toggle command; so first we get if the player is flying
@ -124,7 +126,7 @@ public class FactionFlight extends AbstractNode {
return ActionResult.PASS; return ActionResult.PASS;
}); });
PlayerExitedBaseCallback.EVENT.register((player, world, power) -> { PlayerExitedBaseCallback.EVENT.register((player, world, power, factionTier) -> {
Timer timer = new Timer(); Timer timer = new Timer();
canFly = false; canFly = false;
player.sendMessage(Text.of("You left the faction's perimeter! Flight will disable in 5 seconds...")); player.sendMessage(Text.of("You left the faction's perimeter! Flight will disable in 5 seconds..."));

View File

@ -2,7 +2,6 @@ package jesse.keeblarcraft.Commands;
import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.context.CommandContext;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -11,7 +10,6 @@ import java.util.Map.Entry;
import static java.util.Map.entry; import static java.util.Map.entry;
import jesse.keeblarcraft.BankMgr.BankAccountType;
import jesse.keeblarcraft.BankMgr.BankManager; import jesse.keeblarcraft.BankMgr.BankManager;
import jesse.keeblarcraft.BankMgr.IndividualAccount; import jesse.keeblarcraft.BankMgr.IndividualAccount;
import jesse.keeblarcraft.BankMgr.IndividualBank; import jesse.keeblarcraft.BankMgr.IndividualBank;
@ -20,7 +18,6 @@ import jesse.keeblarcraft.ChatStuff.ChatFormatting.COLOR_CODE;
import jesse.keeblarcraft.ChatStuff.ChatMsg; import jesse.keeblarcraft.ChatStuff.ChatMsg;
import jesse.keeblarcraft.ConfigMgr.ConfigManager; import jesse.keeblarcraft.ConfigMgr.ConfigManager;
import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;

View File

@ -8,11 +8,13 @@ import com.mojang.brigadier.context.CommandContext;
import jesse.keeblarcraft.FactionMgr.FactionManager; import jesse.keeblarcraft.FactionMgr.FactionManager;
import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerCommandFlightCallback; import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerCommandFlightCallback;
import jesse.keeblarcraft.FactionMgr.FactionTier.FactionTierEnum;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.minecraft.command.argument.EntityArgumentType; import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
@ -32,6 +34,9 @@ public class FactionCommands {
var promote = CommandManager.literal("promote").build(); var promote = CommandManager.literal("promote").build();
var demote = CommandManager.literal("demote").build(); var demote = CommandManager.literal("demote").build();
var kick = CommandManager.literal("kick").build(); var kick = CommandManager.literal("kick").build();
var set = CommandManager.literal("set").build();
var get = CommandManager.literal("get").build();
var power = CommandManager.literal("power").build();
var info = CommandManager.literal("info") var info = CommandManager.literal("info")
.executes(context -> GetFactionInformation(context.getSource().getPlayer())) .executes(context -> GetFactionInformation(context.getSource().getPlayer()))
.build(); .build();
@ -69,6 +74,15 @@ public class FactionCommands {
.executes(context -> InvitePlayerToFaction(context, EntityArgumentType.getPlayer(context, "target_name"))) .executes(context -> InvitePlayerToFaction(context, EntityArgumentType.getPlayer(context, "target_name")))
.build(); .build();
var setPower = CommandManager.literal("power").build();
var setPowerAmnt = CommandManager.argument("power_amount", IntegerArgumentType.integer()).build();
var setPowerName = CommandManager.argument("set_power_name", StringArgumentType.string())
.executes(context -> SetFactionPower(context.getSource().getPlayer(), StringArgumentType.getString(context, "set_power_name"), IntegerArgumentType.getInteger(context, "power_amount")))
.build();
var getPowerName = CommandManager.argument("get_power_name", StringArgumentType.string())
.executes(context -> GetFactionPower(context.getSource().getPlayer(), StringArgumentType.getString(context, "get_power_name"))).build();
var leaveFaction = CommandManager.literal("leave").executes(context -> LeaveFaction(context) var leaveFaction = CommandManager.literal("leave").executes(context -> LeaveFaction(context)
).build(); ).build();
@ -90,6 +104,15 @@ public class FactionCommands {
factionNode.addChild(info); factionNode.addChild(info);
factionNode.addChild(invite); factionNode.addChild(invite);
factionNode.addChild(fly); factionNode.addChild(fly);
factionNode.addChild(set);
factionNode.addChild(get);
get.addChild(power);
power.addChild(getPowerName);
set.addChild(setPower);
setPower.addChild(setPowerAmnt);
setPowerAmnt.addChild(setPowerName);
promote.addChild(promoteName); promote.addChild(promoteName);
demote.addChild(demoteName); demote.addChild(demoteName);
@ -125,13 +148,26 @@ public class FactionCommands {
private int ForwardFlightCallback(CommandContext<ServerCommandSource> context) { private int ForwardFlightCallback(CommandContext<ServerCommandSource> context) {
if (context.getSource().isExecutedByPlayer()) { if (context.getSource().isExecutedByPlayer()) {
ActionResult result = PlayerCommandFlightCallback.EVENT.invoker().interact(context.getSource().getPlayer(), context.getSource().getWorld(), FactionManager.GetInstance().GetFactionPower(context.getSource().getPlayer())); ServerPlayerEntity player = context.getSource().getPlayer();
ServerWorld world = context.getSource().getWorld();
Integer fPower = FactionManager.GetInstance().GetFactionPower(player);
FactionTierEnum fTier = FactionManager.GetInstance().GetFactionTier(FactionManager.GetInstance().GetFactionOfPlayer(player.getUuidAsString()));
ActionResult result = PlayerCommandFlightCallback.EVENT.invoker().interact(player, world, fPower, fTier);
} }
return 0; return 0;
} }
public int SetFactionPower(ServerPlayerEntity caller, String faction, Integer amount) { public int SetFactionPower(ServerPlayerEntity caller, String faction, Integer amount) {
FactionManager.GetInstance().SetFactionPower(caller, faction, amount); Boolean success = FactionManager.GetInstance().SetFactionPower(caller, faction, amount);
if (success) {
caller.sendMessage(Text.of("Successfully set the faction " + faction + " power to " + amount));
} else {
caller.sendMessage(Text.of("This is an operator only command!"));
}
return 0; return 0;
} }
@ -140,6 +176,12 @@ public class FactionCommands {
return 0; return 0;
} }
public int GetFactionPower(ServerPlayerEntity player, String factionName) {
Integer amnt = FactionManager.GetInstance().GetFactionPower(factionName);
player.sendMessage(Text.of("[" + factionName + " - POWER]:" + amnt));
return 0;
}
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
/// @fn CreateFaction /// @fn CreateFaction
/// ///
@ -236,13 +278,6 @@ public class FactionCommands {
return retValue; return retValue;
} }
// admin only
private int SetFactionPower() {
int retValue = -1;
return retValue;
}
private int DeclareFactionEvent() { private int DeclareFactionEvent() {
int retValue = -1; int retValue = -1;

View File

@ -8,6 +8,7 @@ import jesse.keeblarcraft.FactionMgr.FactionManager;
import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerEnteredBaseCallback; import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerEnteredBaseCallback;
import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerExitedBaseCallback; import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerExitedBaseCallback;
import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerInBaseCallback; import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerInBaseCallback;
import jesse.keeblarcraft.FactionMgr.FactionTier.FactionTierEnum;
import jesse.keeblarcraft.GuiMgr.FactionBlockScreenHandler; import jesse.keeblarcraft.GuiMgr.FactionBlockScreenHandler;
import jesse.keeblarcraft.world.ImplementedInventory; import jesse.keeblarcraft.world.ImplementedInventory;
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory; import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory;
@ -37,6 +38,7 @@ public class FactionBlockEntity extends BlockEntity implements ExtendedScreenHan
private static final int OFFENSE_SLOT_TWO = 3; private static final int OFFENSE_SLOT_TWO = 3;
private String faction; // Faction this block belongs to private String faction; // Faction this block belongs to
private static int factionPower = 0; private static int factionPower = 0;
private FactionTierEnum factionTier = FactionTierEnum.TIER_INVALID;
Boolean stopMobSpawn = true; Boolean stopMobSpawn = true;
Boolean hasBuildFlight = true; Boolean hasBuildFlight = true;
Boolean hasSuperBeacon = true; Boolean hasSuperBeacon = true;
@ -49,6 +51,10 @@ public class FactionBlockEntity extends BlockEntity implements ExtendedScreenHan
this.faction = faction; this.faction = faction;
} }
public void SetFaction(String faction) {
this.faction = faction;
}
public FactionBlockEntity(BlockPos pos, BlockState state) { public FactionBlockEntity(BlockPos pos, BlockState state) {
super(BlockEntityRegistration.FACTION_BLOCK_ENTITY, pos, state); super(BlockEntityRegistration.FACTION_BLOCK_ENTITY, pos, state);
this.propertyDelegate = new PropertyDelegate() { this.propertyDelegate = new PropertyDelegate() {
@ -134,6 +140,7 @@ public class FactionBlockEntity extends BlockEntity implements ExtendedScreenHan
} }
factionPower = FactionManager.GetInstance().GetFactionPower(faction); factionPower = FactionManager.GetInstance().GetFactionPower(faction);
factionTier = FactionManager.GetInstance().GetFactionTier(faction);
// TODO: Optimize this block so that when it is placed the placers UUID is related to a faction and only pull from a list of those players not the entire server // TODO: Optimize this block so that when it is placed the placers UUID is related to a faction and only pull from a list of those players not the entire server
for (PlayerEntity player : world.getPlayers()) { for (PlayerEntity player : world.getPlayers()) {
@ -144,13 +151,13 @@ public class FactionBlockEntity extends BlockEntity implements ExtendedScreenHan
System.out.println("FACTION IS " + faction); System.out.println("FACTION IS " + faction);
if (!playersInRadius.contains(player.getUuidAsString())) { if (!playersInRadius.contains(player.getUuidAsString())) {
playersInRadius.add(player.getUuidAsString()); playersInRadius.add(player.getUuidAsString());
ActionResult result = PlayerEnteredBaseCallback.EVENT.invoker().interact(player, world, factionPower); ActionResult result = PlayerEnteredBaseCallback.EVENT.invoker().interact(player, world, factionPower, factionTier);
} }
// Invoke the flight attribute on this player // Invoke the flight attribute on this player
if (hasBuildFlight) { if (hasBuildFlight) {
AttributeMgr.ApplyAttribute(player.getUuidAsString(), "faction_flight"); AttributeMgr.ApplyAttribute(player.getUuidAsString(), "faction_flight");
ActionResult result = PlayerInBaseCallback.EVENT.invoker().interact(player, world, factionPower); ActionResult result = PlayerInBaseCallback.EVENT.invoker().interact(player, world, factionPower, factionTier);
} }
if (hasSuperBeacon) { if (hasSuperBeacon) {
@ -159,7 +166,7 @@ public class FactionBlockEntity extends BlockEntity implements ExtendedScreenHan
} }
} else if (!isPlayerInFactionRadius && playersInRadius.contains(player.getUuidAsString())) { } else if (!isPlayerInFactionRadius && playersInRadius.contains(player.getUuidAsString())) {
playersInRadius.remove(player.getUuidAsString()); playersInRadius.remove(player.getUuidAsString());
ActionResult result = PlayerExitedBaseCallback.EVENT.invoker().interact(player, world, factionPower); ActionResult result = PlayerExitedBaseCallback.EVENT.invoker().interact(player, world, factionPower, factionTier);
} }
} }

View File

@ -51,13 +51,20 @@ public class FactionBaseBlock extends BlockWithEntity implements BlockEntityProv
ServerPlayerEntity player = (ServerPlayerEntity) placer; ServerPlayerEntity player = (ServerPlayerEntity) placer;
String fac = FactionManager.GetInstance().GetFactionOfPlayer(player.getUuidAsString()); String fac = FactionManager.GetInstance().GetFactionOfPlayer(player.getUuidAsString());
FactionBlockEntity bEntity = (FactionBlockEntity) world.getBlockEntity(pos);
// Update block entity
if (bEntity != null) {
bEntity.SetFaction(fac);
}
// An empty string implies NO faction; only do things if it is NOT empty // An empty string implies NO faction; only do things if it is NOT empty
if (!fac.equals("")) { if (!fac.equals("")) {
faction = fac; faction = fac;
player.sendMessage(Text.of("This block now belongs to the " + faction + " faction.")); player.sendMessage(Text.of("This block now belongs to the " + faction + " faction."));
} else { } else {
player.sendMessage(Text.of("You do not appear to be in a faction, and thus this block cannot be placed!")); player.sendMessage(Text.of("You do not appear to be in a faction, and thus this block cannot be placed!"));
world.removeBlock(pos, false); world.removeBlock(pos, true);
} }
} }
} }

View File

@ -1,5 +1,6 @@
package jesse.keeblarcraft.FactionMgr.Callbacks; package jesse.keeblarcraft.FactionMgr.Callbacks;
import jesse.keeblarcraft.FactionMgr.FactionTier.FactionTierEnum;
import net.fabricmc.fabric.api.event.Event; import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory; import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
@ -8,9 +9,9 @@ import net.minecraft.world.World;
public interface PlayerCommandFlightCallback { public interface PlayerCommandFlightCallback {
Event<PlayerCommandFlightCallback> EVENT = EventFactory.createArrayBacked(PlayerCommandFlightCallback.class, Event<PlayerCommandFlightCallback> EVENT = EventFactory.createArrayBacked(PlayerCommandFlightCallback.class,
(listeners) -> (player, world, power) -> { (listeners) -> (player, world, power, factionTier) -> {
for (PlayerCommandFlightCallback listener : listeners) { for (PlayerCommandFlightCallback listener : listeners) {
ActionResult result = listener.interact(player, world, power); ActionResult result = listener.interact(player, world, power, factionTier);
if (result != ActionResult.PASS) { if (result != ActionResult.PASS) {
return result; return result;
@ -20,5 +21,5 @@ public interface PlayerCommandFlightCallback {
return ActionResult.PASS; return ActionResult.PASS;
}); });
ActionResult interact(PlayerEntity player, World world, Integer factionPower); ActionResult interact(PlayerEntity player, World world, Integer factionPower, FactionTierEnum factionTier);
} }

View File

@ -1,5 +1,6 @@
package jesse.keeblarcraft.FactionMgr.Callbacks; package jesse.keeblarcraft.FactionMgr.Callbacks;
import jesse.keeblarcraft.FactionMgr.FactionTier.FactionTierEnum;
import net.fabricmc.fabric.api.event.Event; import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory; import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
@ -8,9 +9,9 @@ import net.minecraft.world.World;
public interface PlayerEnteredBaseCallback { public interface PlayerEnteredBaseCallback {
Event<PlayerEnteredBaseCallback> EVENT = EventFactory.createArrayBacked(PlayerEnteredBaseCallback.class, Event<PlayerEnteredBaseCallback> EVENT = EventFactory.createArrayBacked(PlayerEnteredBaseCallback.class,
(listeners) -> (player, world, power) -> { (listeners) -> (player, world, power, factionTier) -> {
for (PlayerEnteredBaseCallback listener : listeners) { for (PlayerEnteredBaseCallback listener : listeners) {
ActionResult result = listener.interact(player, world, power); ActionResult result = listener.interact(player, world, power, factionTier);
if (result != ActionResult.PASS) { if (result != ActionResult.PASS) {
return result; return result;
@ -20,5 +21,5 @@ public interface PlayerEnteredBaseCallback {
return ActionResult.PASS; return ActionResult.PASS;
}); });
ActionResult interact(PlayerEntity player, World world, Integer factionPower); ActionResult interact(PlayerEntity player, World world, Integer factionPower, FactionTierEnum factionTier);
} }

View File

@ -1,5 +1,6 @@
package jesse.keeblarcraft.FactionMgr.Callbacks; package jesse.keeblarcraft.FactionMgr.Callbacks;
import jesse.keeblarcraft.FactionMgr.FactionTier.FactionTierEnum;
import net.fabricmc.fabric.api.event.Event; import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory; import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
@ -8,9 +9,9 @@ import net.minecraft.world.World;
public interface PlayerExitedBaseCallback { public interface PlayerExitedBaseCallback {
Event<PlayerExitedBaseCallback> EVENT = EventFactory.createArrayBacked(PlayerExitedBaseCallback.class, Event<PlayerExitedBaseCallback> EVENT = EventFactory.createArrayBacked(PlayerExitedBaseCallback.class,
(listeners) -> (player, world, power) -> { (listeners) -> (player, world, power, factionTier) -> {
for (PlayerExitedBaseCallback listener : listeners) { for (PlayerExitedBaseCallback listener : listeners) {
ActionResult result = listener.interact(player, world, power); ActionResult result = listener.interact(player, world, power, factionTier);
if (result != ActionResult.PASS) { if (result != ActionResult.PASS) {
return result; return result;
@ -20,5 +21,5 @@ public interface PlayerExitedBaseCallback {
return ActionResult.PASS; return ActionResult.PASS;
}); });
ActionResult interact(PlayerEntity player, World world, Integer factionPower); ActionResult interact(PlayerEntity player, World world, Integer factionPower, FactionTierEnum factionTier);
} }

View File

@ -1,5 +1,6 @@
package jesse.keeblarcraft.FactionMgr.Callbacks; package jesse.keeblarcraft.FactionMgr.Callbacks;
import jesse.keeblarcraft.FactionMgr.FactionTier.FactionTierEnum;
import net.fabricmc.fabric.api.event.Event; import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory; import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
@ -8,9 +9,9 @@ import net.minecraft.world.World;
public interface PlayerInBaseCallback { public interface PlayerInBaseCallback {
Event<PlayerInBaseCallback> EVENT = EventFactory.createArrayBacked(PlayerInBaseCallback.class, Event<PlayerInBaseCallback> EVENT = EventFactory.createArrayBacked(PlayerInBaseCallback.class,
(listeners) -> (player, world, power) -> { (listeners) -> (player, world, power, factionTier) -> {
for (PlayerInBaseCallback listener : listeners) { for (PlayerInBaseCallback listener : listeners) {
ActionResult result = listener.interact(player, world, power); ActionResult result = listener.interact(player, world, power, factionTier);
if (result != ActionResult.PASS) { if (result != ActionResult.PASS) {
return result; return result;
@ -20,5 +21,5 @@ public interface PlayerInBaseCallback {
return ActionResult.PASS; return ActionResult.PASS;
}); });
ActionResult interact(PlayerEntity player, World world, Integer factionPower); ActionResult interact(PlayerEntity player, World world, Integer factionPower, FactionTierEnum factionTier);
} }

View File

@ -12,10 +12,9 @@ package jesse.keeblarcraft.FactionMgr;
import java.util.List; import java.util.List;
import jesse.keeblarcraft.ConfigMgr.ConfigManager; import jesse.keeblarcraft.ConfigMgr.ConfigManager;
import jesse.keeblarcraft.FactionMgr.FactionTier.FactionTierEnum;
import jesse.keeblarcraft.MailSystem.MailMgr; import jesse.keeblarcraft.MailSystem.MailMgr;
import jesse.keeblarcraft.Keeblarcraft; import jesse.keeblarcraft.Keeblarcraft;
import jesse.keeblarcraft.ChatStuff.ChatMsg;
import jesse.keeblarcraft.Utils.CustomExceptions.FILE_WRITE_EXCEPTION;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text; import net.minecraft.text.Text;
@ -75,6 +74,8 @@ public class FactionManager {
factionConfig.factions = new FactionConfig(); factionConfig.factions = new FactionConfig();
FlashConfig(); FlashConfig();
} }
FactionTier.InitializeFactionTiers();
} }
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@ -118,10 +119,10 @@ public class FactionManager {
String facOfPlayer = factionConfig.factions.FindFactionOfPlayer(creator.getUuidAsString()); String facOfPlayer = factionConfig.factions.FindFactionOfPlayer(creator.getUuidAsString());
if (facOfPlayer == "") { if (facOfPlayer == "") {
creator.sendMessage(Text.of("Your display name: " + creator.getDisplayName().toString())); // creator.sendMessage(Text.of("Your display name: " + creator.getDisplayName().toString()));
creator.sendMessage(Text.of("Your name: " + creator.getName())); // creator.sendMessage(Text.of("Your name: " + creator.getName()));
creator.sendMessage(Text.of("Your custom name: " + creator.getCustomName())); // creator.sendMessage(Text.of("Your custom name: " + creator.getCustomName()));
creator.sendMessage(Text.of("Your entity name: " + creator.getEntityName())); // creator.sendMessage(Text.of("Your entity name: " + creator.getEntityName()));
success = factionConfig.factions.CreateFaction(factionName, creator.getUuidAsString(), creator.getEntityName()); success = factionConfig.factions.CreateFaction(factionName, creator.getUuidAsString(), creator.getEntityName());
if (!success) { if (!success) {
@ -196,8 +197,9 @@ public class FactionManager {
} }
if (success) { if (success) {
String mailMsg = "You receive a faction invite from " + caller.getEntityName() + "! You can join with /faction join " + playerFaction; String mailMsg = "You received a faction invite from " + caller.getEntityName() + "! You can join with /faction join " + playerFaction;
MailMgr.GetInstance().SendMail(inviteeUuid, mailMsg); MailMgr.GetInstance().SendMail(inviteeUuid, mailMsg);
FlashConfig();
} }
return success; return success;
} }
@ -206,7 +208,8 @@ public class FactionManager {
Boolean success = false; Boolean success = false;
if (caller.hasPermissionLevel(4)) { if (caller.hasPermissionLevel(4)) {
factionConfig.factions.SetPower(factionName, amount); success = factionConfig.factions.SetPower(factionName, amount);
FlashConfig();
} else { } else {
caller.sendMessage(Text.of("You do not have permission to use this command")); caller.sendMessage(Text.of("You do not have permission to use this command"));
} }
@ -222,6 +225,10 @@ public class FactionManager {
return fPower; return fPower;
} }
public FactionTierEnum GetFactionTier(String factionName) {
return FactionTier.GetFactionTier(factionConfig.factions.GetPower(factionName));
}
public Integer GetFactionPower(ServerPlayerEntity caller) { public Integer GetFactionPower(ServerPlayerEntity caller) {
Integer amount = 0; Integer amount = 0;

View File

@ -0,0 +1,39 @@
package jesse.keeblarcraft.FactionMgr;
import com.google.common.collect.Range;
import com.google.common.collect.RangeMap;
import com.google.common.collect.TreeRangeMap;
public class FactionTier {
public static enum FactionTierEnum {
TIER_INVALID,
TIER_I,
TIER_II,
TIER_III,
TIER_IV,
TIER_V,
TIER_VI
}
private static RangeMap<Integer, FactionTierEnum> factionTiers = TreeRangeMap.create();
public static void InitializeFactionTiers() {
factionTiers.put(Range.closed(0, 29), FactionTierEnum.TIER_I);
factionTiers.put(Range.closed(30, 74), FactionTierEnum.TIER_II);
factionTiers.put(Range.closed(75, 99), FactionTierEnum.TIER_III);
factionTiers.put(Range.closed(100, 149), FactionTierEnum.TIER_IV);
factionTiers.put(Range.closed(150, 999), FactionTierEnum.TIER_V);
factionTiers.put(Range.closed(1000, Integer.MAX_VALUE), FactionTierEnum.TIER_VI);
}
// Make sure you initialize tiers by calling the above function first!
public static FactionTierEnum GetFactionTier(Integer value) {
FactionTierEnum tier = factionTiers.get(value);
if (tier == null) {
tier = FactionTierEnum.TIER_INVALID;
}
return tier;
}
}