[factions-and-banking] Commenting out yesterdays mixins since they're example only but maintaining in source code since they may be used. Added configuration file stuff to maintain UUID and name to be persistant when players log off. Updated more faction stuff as well!

This commit is contained in:
Jkibbels 2024-12-23 23:20:39 -05:00
parent 79a4738bbc
commit 82ee25ee97
12 changed files with 418 additions and 125 deletions

View File

@ -9,9 +9,9 @@ import net.minecraft.client.network.ClientPlayerInteractionManager;
@Mixin(ClientPlayerInteractionManager.class) @Mixin(ClientPlayerInteractionManager.class)
public abstract class ClientPlayerInteractionManagerMixin { public abstract class ClientPlayerInteractionManagerMixin {
// This initial // This initial basically lets the player highlight the block at 10 blocks away. Does NOT let them break it, that is all handled in the new server mixin
@Inject(method = "getReachDistance()F", at = @At ("HEAD"), cancellable = true) // @Inject(method = "getReachDistance()F", at = @At ("HEAD"), cancellable = true)
public void getReachDistance(CallbackInfoReturnable<Float> cir) { // public void getReachDistance(CallbackInfoReturnable<Float> cir) {
cir.setReturnValue(10.0f); // cir.setReturnValue(10.0f);
} // }
} }

View File

@ -2,11 +2,13 @@ package jesse.keeblarcraft.Commands;
import java.util.List; import java.util.List;
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 com.mojang.brigadier.context.CommandContext;
import jesse.keeblarcraft.FactionMgr.FactionManager; import jesse.keeblarcraft.FactionMgr.FactionManager;
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.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;
@ -27,6 +29,11 @@ public class FactionCommands {
var disbandFaction = CommandManager.literal("disband").build(); var disbandFaction = CommandManager.literal("disband").build();
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 info = CommandManager.literal("info")
.executes(context -> GetFactionInformation(context.getSource().getPlayer()))
.build();
var invite = CommandManager.literal("invite").build();
// The below nodes are duplicates but are necessary to make the execute path jump correctly // The below nodes are duplicates but are necessary to make the execute path jump correctly
var createFactionName = CommandManager.argument("faction_name", StringArgumentType.greedyString()) var createFactionName = CommandManager.argument("faction_name", StringArgumentType.greedyString())
@ -45,10 +52,22 @@ public class FactionCommands {
) )
).build(); ).build();
var promoteName = CommandManager.argument("target_name", EntityArgumentType.player())
.executes(context -> PromotePlayerInFaction(context, EntityArgumentType.getPlayer(context, "target_name")))
.build();
var demoteName = CommandManager.argument("target_name", EntityArgumentType.player())
.executes(context -> DemotePlayerInFaction(context, EntityArgumentType.getPlayer(context, "target_name")))
.build();
var kickName = CommandManager.argument("target_name", EntityArgumentType.player())
.executes(context -> KickPlayerFromFaction(context, EntityArgumentType.getPlayer(context, "target_name")))
.build();
var inviteName = CommandManager.argument("target_name", EntityArgumentType.player())
.executes(context -> InvitePlayerToFaction(context, EntityArgumentType.getPlayer(context, "target_name")))
.build();
var leaveFaction = CommandManager.literal("leave").executes(context -> LeaveFaction(context) var leaveFaction = CommandManager.literal("leave").executes(context -> LeaveFaction(context)
).build(); ).build();
var listAll = CommandManager.literal("list") var listAll = CommandManager.literal("list")
.executes(context -> ListAllFactions(context.getSource().getPlayer())).build(); .executes(context -> ListAllFactions(context.getSource().getPlayer())).build();
@ -61,10 +80,52 @@ public class FactionCommands {
factionNode.addChild(createFaction); factionNode.addChild(createFaction);
factionNode.addChild(disbandFaction); factionNode.addChild(disbandFaction);
factionNode.addChild(leaveFaction); factionNode.addChild(leaveFaction);
factionNode.addChild(promote);
factionNode.addChild(demote);
factionNode.addChild(kick);
factionNode.addChild(info);
factionNode.addChild(invite);
promote.addChild(promoteName);
demote.addChild(demoteName);
kick.addChild(kickName);
invite.addChild(inviteName);
createFaction.addChild(createFactionName); createFaction.addChild(createFactionName);
disbandFaction.addChild(disbandFactionName); disbandFaction.addChild(disbandFactionName);
}); });
// I'll refactor the above one later! LOL
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
var factionNode = CommandManager.literal("faction").build();
var powerNode = CommandManager.literal("power")
.executes(context -> GetFactionPower(context.getSource().getPlayer()))
.build();
var setNode = CommandManager.literal("set").build();
var factionNameNode = CommandManager.argument("faction_name", StringArgumentType.string()).build();
var powerAmountNode = CommandManager.argument("power_amount", IntegerArgumentType.integer())
.executes(context -> SetFactionPower(context.getSource().getPlayer(), StringArgumentType.getString(context, "faction_name"), IntegerArgumentType.getInteger(context, "power_amount")))
.build();
dispatcher.getRoot().addChild(factionNode);
factionNode.addChild(powerNode);
powerNode.addChild(setNode);
setNode.addChild(factionNameNode);
setNode.addChild(powerAmountNode);
});
}
public int SetFactionPower(ServerPlayerEntity caller, String faction, Integer amount) {
FactionManager.GetInstance().SetFactionPower(caller, faction, amount);
return 0;
}
public int GetFactionPower(ServerPlayerEntity player) {
FactionManager.GetInstance().GetFactionPower(player);
return 0;
} }
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@ -109,10 +170,9 @@ public class FactionCommands {
return retValue; return retValue;
} }
private int AddPlayerToFaction() { private int InvitePlayerToFaction(CommandContext<ServerCommandSource> context, ServerPlayerEntity player) {
int retValue = -1; FactionManager.GetInstance().InvitePlayerToFaction(context.getSource().getPlayer(), player.getUuidAsString(), player.getEntityName());
return 0;
return retValue;
} }
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@ -130,22 +190,26 @@ public class FactionCommands {
return 0; return 0;
} }
private int KickPlayerFromFaction() { private int GetFactionInformation(ServerPlayerEntity player) {
return 0;
}
private int KickPlayerFromFaction(CommandContext<ServerCommandSource> context, ServerPlayerEntity player) {
int retValue = -1; int retValue = -1;
return retValue; return retValue;
} }
private int PromotePlayerInFaction() { private int PromotePlayerInFaction(CommandContext<ServerCommandSource> context, ServerPlayerEntity player) {
int retValue = -1; ServerPlayerEntity caller = context.getSource().getPlayer();
FactionManager.GetInstance().PromotePlayer(caller, player.getUuidAsString(), player.getEntityName());
return retValue; return 0;
} }
private int DemotePlayerInFaction() { private int DemotePlayerInFaction(CommandContext<ServerCommandSource> context, ServerPlayerEntity player) {
int retValue = -1; ServerPlayerEntity caller = context.getSource().getPlayer();
FactionManager.GetInstance().DemotePlayer(caller, player.getUuidAsString(), player.getEntityName());
return retValue; return 0;
} }
private int SetPlayerRoleInFaction() { private int SetPlayerRoleInFaction() {

View File

@ -0,0 +1,30 @@
package jesse.keeblarcraft.Commands;
import com.mojang.brigadier.arguments.StringArgumentType;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.network.ServerPlayerEntity;
public class MailCommands {
public void RegisterMailCommands() {
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
var mailRoot = CommandManager.literal("mail").build();
var sendNode = CommandManager.literal("send").build();
var playerName = CommandManager.argument("target_name", StringArgumentType.string()).build();
var message = CommandManager.argument("mail_msg", StringArgumentType.greedyString())
.executes(context -> SendMsg(context.getSource().getPlayer(), StringArgumentType.getString(context, "mail_msg")))
.build();
dispatcher.getRoot().addChild(mailRoot);
mailRoot.addChild(sendNode);
sendNode.addChild(playerName);
playerName.addChild(message);
});
}
private int SendMsg(ServerPlayerEntity source, String mail) {
return 0;
}
}

View File

@ -27,20 +27,20 @@ public class NoteCommands {
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
public NoteCommands() { public NoteCommands() {
// Check if directory exists // Check if directory exists
// if (notesConfig.DoesDirectoryExist(NOTES_GLOBAL_DIRECTORY) == false) { if (notesConfig.DoesDirectoryExist(NOTES_GLOBAL_DIRECTORY) == false) {
// // Attempt to create the directory // Attempt to create the directory
// try { try {
// if (notesConfig.CreateDirectory(NOTES_GLOBAL_DIRECTORY) == true) { if (notesConfig.CreateDirectory(NOTES_GLOBAL_DIRECTORY) == true) {
// System.out.println(ChatUtil.ColoredString("Created notes directory successfully!", CONSOLE_COLOR.BLUE)); //TODO: Success! System.out.println(ChatUtil.ColoredString("Created notes directory successfully!", CONSOLE_COLOR.BLUE)); //TODO: Success!
// } else { } else {
// System.out.println(ChatUtil.ColoredString("ERROR: Notes directory FAILED to create!! Either the directory already exists or we are missing permissions!", CONSOLE_COLOR.RED)); //TODO: Critical failure --not specfic enough to mark it as a red or blue System.out.println(ChatUtil.ColoredString("ERROR: Notes directory FAILED to create!! Either the directory already exists or we are missing permissions!", CONSOLE_COLOR.RED)); //TODO: Critical failure --not specfic enough to mark it as a red or blue
// } }
// } catch (DIRECTORY_CREATE_EXCEPTION e) { } catch (DIRECTORY_CREATE_EXCEPTION e) {
// System.out.println(ChatUtil.ColoredString("Directory creation failed", CONSOLE_COLOR.RED)); System.out.println(ChatUtil.ColoredString("Directory creation failed", CONSOLE_COLOR.RED));
// } }
// } else { } else {
// System.out.println(ChatUtil.ColoredString("Notes directory already exists. Skipping creation...", CONSOLE_COLOR.BLUE)); //TODO: Success! System.out.println(ChatUtil.ColoredString("Notes directory already exists. Skipping creation...", CONSOLE_COLOR.BLUE)); //TODO: Success!
// } }
} }
//TODO: Rework note commands upon story mode release //TODO: Rework note commands upon story mode release
@ -51,69 +51,69 @@ public class NoteCommands {
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
public void RegisterNoteCommands() { public void RegisterNoteCommands() {
// Command: "/addnote note goes here" // Command: "/addnote note goes here"
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
dispatcher.register(CommandManager.literal("addnote")
.then(CommandManager.argument("value", StringArgumentType.greedyString())
.executes(context -> AddNote(StringArgumentType.getString(context, "value"), context))));
});
// Command: "/delnote noteIdHere"
// CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { // CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
// dispatcher.register(CommandManager.literal("addnote") // dispatcher.register(CommandManager.literal("delnote")
// .then(CommandManager.argument("value", StringArgumentType.greedyString()) // .then(CommandManager.argument("value", StringArgumentType.greedyString())
// .executes(context -> AddNote(StringArgumentType.getString(context, "value"), context)))); // .executes(context -> AddNote(StringArgumentType.getString(context, "value"), context))));
// }); // });
// // Command: "/delnote noteIdHere" // Command: "/purgenotes"
// // CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
// // dispatcher.register(CommandManager.literal("delnote") dispatcher.register(CommandManager.literal("purgenotes")
// // .then(CommandManager.argument("value", StringArgumentType.greedyString()) .executes(context -> PurgeAllNotes(context)));
// // .executes(context -> AddNote(StringArgumentType.getString(context, "value"), context)))); });
// // });
// // Command: "/purgenotes" // Command: "/modifynote noteIdHere new_note_string_here"
// CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { // Alises: "/editnote"
// dispatcher.register(CommandManager.literal("purgenotes") CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
// .executes(context -> PurgeAllNotes(context))); final var mNote = dispatcher.register(CommandManager.literal("editnote")
// }); .then(CommandManager.argument("note_id", IntegerArgumentType.integer())
.then(CommandManager.argument("new_note", StringArgumentType.string())
.executes(context -> ModifyNote(
IntegerArgumentType.getInteger(context, "note_id"),
StringArgumentType.getString(context, "new_note"),
context)))));
// // Command: "/modifynote noteIdHere new_note_string_here" dispatcher.register(CommandManager.literal("editnote").redirect(mNote));
// // Alises: "/editnote" });
// CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
// final var mNote = dispatcher.register(CommandManager.literal("editnote")
// .then(CommandManager.argument("note_id", IntegerArgumentType.integer())
// .then(CommandManager.argument("new_note", StringArgumentType.string())
// .executes(context -> ModifyNote(
// IntegerArgumentType.getInteger(context, "note_id"),
// StringArgumentType.getString(context, "new_note"),
// context)))));
// dispatcher.register(CommandManager.literal("editnote").redirect(mNote)); // Command Root: "/delnote noteIdHere"
// }); // Aliases: "/rmnote", "/deletenote"
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
final var rootDeleteCmd = dispatcher.register(CommandManager.literal("delnote")
.then(CommandManager.argument("value", IntegerArgumentType.integer())
.executes(context -> DeleteNote(IntegerArgumentType.getInteger(context, "value"), context))));
// // Command Root: "/delnote noteIdHere" // Alias redirects
// // Aliases: "/rmnote", "/deletenote" dispatcher.register(CommandManager.literal("rmnote").redirect(rootDeleteCmd));
// CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { dispatcher.register(CommandManager.literal("deletenote").redirect(rootDeleteCmd));
// final var rootDeleteCmd = dispatcher.register(CommandManager.literal("delnote") });
// .then(CommandManager.argument("value", IntegerArgumentType.integer())
// .executes(context -> DeleteNote(IntegerArgumentType.getInteger(context, "value"), context))));
// // Alias redirects // Command Root: "/notegui"
// dispatcher.register(CommandManager.literal("rmnote").redirect(rootDeleteCmd)); CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
// dispatcher.register(CommandManager.literal("deletenote").redirect(rootDeleteCmd)); dispatcher.register(CommandManager.literal("notegui")
// }); .executes(context -> { OpenNoteGui(context);
return 0;
}));
});
// // Command Root: "/notegui" // Command Root: "/notelist"
// CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { // Aliases: "/listnotes"
// dispatcher.register(CommandManager.literal("notegui") CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
// .executes(context -> { OpenNoteGui(context); final var rootListNotes = dispatcher.register(CommandManager.literal("notelist")
// return 0; .executes(context -> { ListNotes(context);
// })); return 0;
// }); }));
// // Command Root: "/notelist" dispatcher.register(CommandManager.literal("listnotes").redirect(rootListNotes));
// // Aliases: "/listnotes" });
// CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
// final var rootListNotes = dispatcher.register(CommandManager.literal("notelist")
// .executes(context -> { ListNotes(context);
// return 0;
// }));
// dispatcher.register(CommandManager.literal("listnotes").redirect(rootListNotes));
// });
} }
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////

View File

@ -56,6 +56,7 @@ public class ConfigManager {
// Check 2: If the file does not exist, attempt to create it // Check 2: If the file does not exist, attempt to create it
if (ret == false) { if (ret == false) {
try { try {
file.mkdirs();
ret = file.createNewFile(); ret = file.createNewFile();
} catch (IOException e) { } catch (IOException e) {
// The file could not be created // The file could not be created

View File

@ -1,7 +1,10 @@
package jesse.keeblarcraft.EventMgr; package jesse.keeblarcraft.EventMgr;
import java.util.HashMap;
import jesse.keeblarcraft.AttributeMgr.AttributeMgr; import jesse.keeblarcraft.AttributeMgr.AttributeMgr;
import jesse.keeblarcraft.AttributeMgr.AttributeTree; import jesse.keeblarcraft.AttributeMgr.AttributeTree;
import jesse.keeblarcraft.ConfigMgr.ConfigManager;
import jesse.keeblarcraft.ConfigMgr.GeneralConfig; import jesse.keeblarcraft.ConfigMgr.GeneralConfig;
import jesse.keeblarcraft.Utils.DirectionalVec; import jesse.keeblarcraft.Utils.DirectionalVec;
import net.fabricmc.fabric.api.networking.v1.PacketSender; import net.fabricmc.fabric.api.networking.v1.PacketSender;
@ -13,6 +16,13 @@ import net.minecraft.text.Text;
public class PlayerJoinListener { public class PlayerJoinListener {
private static PlayerJoinListener static_inst; private static PlayerJoinListener static_inst;
ConfigManager config = new ConfigManager();
String CACHED_PLAYER_LOGIN_CONFIG = "misc/cached_uuids.json";
private class CachedUUIDConfig {
HashMap<String, String> cached_uuids = new HashMap<String, String>();
}
CachedUUIDConfig cachedPlayerConfig;
// Get the static instance for this class // Get the static instance for this class
public static PlayerJoinListener GetInstance() { public static PlayerJoinListener GetInstance() {
@ -22,6 +32,27 @@ public class PlayerJoinListener {
return static_inst; return static_inst;
} }
public PlayerJoinListener() {
Boolean existingFile = false;
cachedPlayerConfig = new CachedUUIDConfig();
try {
cachedPlayerConfig = config.GetJsonObjectFromFile(CACHED_PLAYER_LOGIN_CONFIG, CachedUUIDConfig.class);
existingFile = true;
} catch (Exception e) {
// intentionally empty
}
if (!existingFile) {
try {
config.CreateFile(CACHED_PLAYER_LOGIN_CONFIG);
FlashCachedConfig();
} catch (Exception e) {
System.out.println("Failed to parse or create cached uuid file");
}
}
}
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
/// @fn HandleServerJoinEvent /// @fn HandleServerJoinEvent
/// ///
@ -44,6 +75,7 @@ public class PlayerJoinListener {
// Handle first time joining events (world spawn teleport, MOTD, etc) // Handle first time joining events (world spawn teleport, MOTD, etc)
System.out.println("Running first time login stuff"); System.out.println("Running first time login stuff");
IsFirstTimeLogin(player, server); IsFirstTimeLogin(player, server);
CachePlayersUuid(player.getUuidAsString(), player.getEntityName());
} }
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@ -74,4 +106,29 @@ public class PlayerJoinListener {
} }
} }
} }
public String TryGetPlayerUuidByName(String name) {
String uuid = "";
if (cachedPlayerConfig != null && cachedPlayerConfig.cached_uuids.containsKey(name)) {
uuid = cachedPlayerConfig.cached_uuids.get(name);
}
return uuid;
}
private void CachePlayersUuid(String uuid, String entityName) {
if (cachedPlayerConfig.cached_uuids.containsKey(entityName)) {
return;
} else {
cachedPlayerConfig.cached_uuids.put(entityName, uuid);
FlashCachedConfig();
}
}
private void FlashCachedConfig() {
try {
config.WriteToJsonFile(CACHED_PLAYER_LOGIN_CONFIG, cachedPlayerConfig);
} catch (Exception e) {
System.out.println("Encountered exception in writing cached uuid file!");
}
}
} }

View File

@ -91,6 +91,26 @@ public class FactionConfig {
return success; return success;
} }
// It is assumed that the person calling this function has verified that the person
// can in fact set faction power. This is generally just an admin command
public Boolean SetPower(String factionName, Integer amount) {
Boolean success = false;
if (IsValid(factionName)) {
allFactions.get(factionName).factionPower = amount;
success = true;
}
return success;
}
// The user should verify the faction exists prior to calling this. 0 is default
// return if faction does not exist (or the faction actually has a balance of 0)
public Integer GetPower(String factionName) {
Integer amount = 0;
if (IsValid(factionName)) {
amount = allFactions.get(factionName).factionPower;
}
return amount;
}
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
/// @fn DeleteFaction /// @fn DeleteFaction

View File

@ -12,6 +12,7 @@ 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.MailSystem.MailMgr;
import jesse.keeblarcraft.Utils.ChatUtil; import jesse.keeblarcraft.Utils.ChatUtil;
import jesse.keeblarcraft.Utils.ChatUtil.CONSOLE_COLOR; import jesse.keeblarcraft.Utils.ChatUtil.CONSOLE_COLOR;
import jesse.keeblarcraft.Utils.CustomExceptions.FILE_WRITE_EXCEPTION; import jesse.keeblarcraft.Utils.CustomExceptions.FILE_WRITE_EXCEPTION;
@ -185,6 +186,45 @@ public class FactionManager {
return factionConfig.factions.FindFactionOfPlayer(playerUuid); return factionConfig.factions.FindFactionOfPlayer(playerUuid);
} }
public Boolean InvitePlayerToFaction(ServerPlayerEntity caller, String inviteeUuid, String inviteeDisplayName) {
String playerFaction = factionConfig.factions.FindFactionOfPlayer(caller.getUuidAsString());
Boolean success = false;
if (!playerFaction.equals("")) {
success = factionConfig.factions.InvitePlayerToFaction(playerFaction, caller.getUuidAsString(), inviteeUuid);
} else {
caller.sendMessage(Text.of("You aren't in a faction!"));
}
if (success) {
String mailMsg = "You receive a faction invite from " + caller.getEntityName() + "! You can join with /faction join " + playerFaction;
MailMgr.GetInstance().SendMail(inviteeUuid, mailMsg);
}
return success;
}
public Boolean SetFactionPower(ServerPlayerEntity caller, String factionName, Integer amount) {
Boolean success = false;
if (caller.hasPermissionLevel(4)) {
factionConfig.factions.SetPower(factionName, amount);
} else {
caller.sendMessage(Text.of("You do not have permission to use this command"));
}
return success;
}
public Integer GetFactionPower(ServerPlayerEntity caller) {
Integer amount = 0;
String playerFaction = factionConfig.factions.FindFactionOfPlayer(caller.getUuidAsString());
if (!playerFaction.equals("")) {
amount = factionConfig.factions.GetPower(playerFaction);
caller.sendMessage(Text.of("[" + playerFaction + " - POWER]: " + Integer.toString(amount)));
}
return amount;
}
public Boolean PromotePlayer(ServerPlayerEntity caller, String promoteeUuid, String promoteeDisplayName) { public Boolean PromotePlayer(ServerPlayerEntity caller, String promoteeUuid, String promoteeDisplayName) {
Boolean success = factionConfig.factions.PromotePlayer(GetFactionOfPlayer(caller.getUuidAsString()), caller.getUuidAsString(), promoteeUuid, promoteeDisplayName); Boolean success = factionConfig.factions.PromotePlayer(GetFactionOfPlayer(caller.getUuidAsString()), caller.getUuidAsString(), promoteeUuid, promoteeDisplayName);
@ -234,4 +274,4 @@ public class FactionManager {
System.out.println("config writing of faction file failed. oh well!"); System.out.println("config writing of faction file failed. oh well!");
} }
} }
} }

View File

@ -0,0 +1,81 @@
package jesse.keeblarcraft.MailSystem;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import jesse.keeblarcraft.ConfigMgr.ConfigManager;
public class MailMgr {
ConfigManager config = new ConfigManager();
MailConfigClass mailConfig;
String CONFIG_FILE = "mail/player_mail.json";
private static MailMgr static_inst;
public static MailMgr GetInstance() {
if (static_inst == null) {
static_inst = new MailMgr();
}
return static_inst;
}
private class MailConfigClass {
private HashMap<String, ArrayList<String>> mailList = new HashMap<String, ArrayList<String>>();
}
public MailMgr() {
System.out.println("Mail manager called");
Boolean existingFile = false;
try {
mailConfig = config.GetJsonObjectFromFile(CONFIG_FILE, MailConfigClass.class);
existingFile = true;
} catch (Exception e) {
System.out.println("Mail config could not correctly parse json file or it did not exist");
}
if (!existingFile) {
try {
config.CreateFile(CONFIG_FILE);
} catch (Exception e) {
System.out.println("Failed to correctly make or parse mail config file");
}
}
}
public void SendMail(String playerUuid, String mail) {
if (mailConfig != null) {
if (mailConfig.mailList.containsKey(playerUuid)) {
mailConfig.mailList.get(playerUuid).add(mail);
} else {
mailConfig.mailList.put(playerUuid, new ArrayList<>(Arrays.asList(mail)));
}
} else {
System.out.println("Mail config is null. Cannot send");
}
}
public List<String> GetMail(String playerUuid) {
List<String> mail = null;
if (mailConfig.mailList.containsKey(playerUuid)) {
mail = mailConfig.mailList.get(playerUuid);
}
return mail;
}
public void ClearMail(String playerUuid) {
if (mailConfig != null && mailConfig.mailList.containsKey(playerUuid)) {
mailConfig.mailList.remove(playerUuid);
}
}
public void FlashConfig() {
if (mailConfig != null) {
try {
config.WriteToJsonFile(CONFIG_FILE, mailConfig);
} catch (Exception e) {
System.out.println("Could not flash mail config");
}
}
}
}

View File

@ -14,17 +14,17 @@ import net.minecraft.server.network.ServerPlayNetworkHandler;
@Mixin(targets = "net.minecraft.server.network.ServerPlayNetworkHandler$1") @Mixin(targets = "net.minecraft.server.network.ServerPlayNetworkHandler$1")
public abstract class PlayerEntityInteractionHandler implements PlayerInteractEntityC2SPacket.Handler { public abstract class PlayerEntityInteractionHandler implements PlayerInteractEntityC2SPacket.Handler {
// Unsure what @Shadow is doing, but I'm sure fabric wiki can explain // Unsure what @Shadow is doing, but I'm sure fabric wiki can explain
@Shadow(aliases = "field_28963") @Final private ServerPlayNetworkHandler field_28963; // I assume this is just a bad named field which is the ServerPlayNetworkHandler // @Shadow(aliases = "field_28963") @Final private ServerPlayNetworkHandler field_28963; // I assume this is just a bad named field which is the ServerPlayNetworkHandler
@Shadow(aliases = "field_28962") @Final private Entity field_28962; // I assume this is just a bad named field which is the Entity in question depending on the function // @Shadow(aliases = "field_28962") @Final private Entity field_28962; // I assume this is just a bad named field which is the Entity in question depending on the function
// Probably not required for a tool since this is hitting, but you would need to check this if you DID want to make a longer reaching sword or something. Attack is // // Probably not required for a tool since this is hitting, but you would need to check this if you DID want to make a longer reaching sword or something. Attack is
// in PlayerEntity but this mixin targets the server handler because the server dictates hitting between stuff // // in PlayerEntity but this mixin targets the server handler because the server dictates hitting between stuff
@Inject(method = "attack()V", at = @At("HEAD"), require = 1, allow = 1, cancellable = true) // @Inject(method = "attack()V", at = @At("HEAD"), require = 1, allow = 1, cancellable = true)
private void isActuallyInHitRange(final CallbackInfo callback) { // private void isActuallyInHitRange(final CallbackInfo callback) {
// All we are doing in this class is telling the 'attack' function to return false immediately if the two entities are not within a squared distance of each other. // // All we are doing in this class is telling the 'attack' function to return false immediately if the two entities are not within a squared distance of each other.
// 100 hard coded because value of hit range is hard coded '10' in the ClientPlayerInteractionManagerMixin in the client section (10^2) // // 100 hard coded because value of hit range is hard coded '10' in the ClientPlayerInteractionManagerMixin in the client section (10^2)
if (!(this.field_28963.player.squaredDistanceTo(this.field_28962) <= 100)) { // 10^2 becauses 10 blocks chosen in Client mixin // if (!(this.field_28963.player.squaredDistanceTo(this.field_28962) <= 100)) { // 10^2 becauses 10 blocks chosen in Client mixin
callback.cancel(); // callback.cancel();
} // }
} // }
} }

View File

@ -14,27 +14,27 @@ import net.minecraft.server.network.ServerPlayNetworkHandler;
public abstract class ServerPlayNetworkHandlerMixin implements ServerPlayPacketListener { public abstract class ServerPlayNetworkHandlerMixin implements ServerPlayPacketListener {
// Truth be told not required for a pickaxe or tool probably // Truth be told not required for a pickaxe or tool probably
@Redirect( // @Redirect(
method = "onPlayerInteractEntity(Lnet/minecraft/network/packet/c2s/play/PlayerInteractEntityC2SPacket;)V", // method = "onPlayerInteractEntity(Lnet/minecraft/network/packet/c2s/play/PlayerInteractEntityC2SPacket;)V",
at = @At(value = "FIELD", target = "Lnet/minecraft/server/network/ServerPlayNetworkHandler;MAX_BREAK_SQUARED_DISTANCE:D", opcode = Opcodes.GETSTATIC)) // at = @At(value = "FIELD", target = "Lnet/minecraft/server/network/ServerPlayNetworkHandler;MAX_BREAK_SQUARED_DISTANCE:D", opcode = Opcodes.GETSTATIC))
private double getActualAttackRange() { // private double getActualAttackRange() {
return 100; // 10^2 becauses 10 blocks chosen in Client mixin // return 100; // 10^2 becauses 10 blocks chosen in Client mixin
} // }
// Essentially replaces the 'MAX_BREAK_SQUARED_DISTANCE' value with the value we have in the function (100), or 10 blocks which bc 10^2 // // Essentially replaces the 'MAX_BREAK_SQUARED_DISTANCE' value with the value we have in the function (100), or 10 blocks which bc 10^2
@Redirect( // @Redirect(
method = "onPlayerInteractBlock(Lnet/minecraft/network/packet/c2s/play/PlayerInteractBlockC2SPacket;)V", // method = "onPlayerInteractBlock(Lnet/minecraft/network/packet/c2s/play/PlayerInteractBlockC2SPacket;)V",
at = @At(value = "FIELD", target = "Lnet/minecraft/server/network/ServerPlayNetworkHandler;MAX_BREAK_SQUARED_DISTANCE:D", opcode = Opcodes.GETSTATIC)) // at = @At(value = "FIELD", target = "Lnet/minecraft/server/network/ServerPlayNetworkHandler;MAX_BREAK_SQUARED_DISTANCE:D", opcode = Opcodes.GETSTATIC))
private double getActualReachDistance() { // private double getActualReachDistance() {
return 100; // 10^2 becauses 10 blocks chosen in Client mixin // return 100; // 10^2 becauses 10 blocks chosen in Client mixin
} // }
// Search '64' inside the same onPlayerInteractBlock, would also need to replace that value maybe. This is in the github reference for that block breaking // // Search '64' inside the same onPlayerInteractBlock, would also need to replace that value maybe. This is in the github reference for that block breaking
// im not 100% sure what this is doing. If it's squared then sqrt(64) = 8 blocks but I'm not sure what 8 would represent here. // // im not 100% sure what this is doing. If it's squared then sqrt(64) = 8 blocks but I'm not sure what 8 would represent here.
@ModifyConstant( // @ModifyConstant(
method = "onPlayerInteractBlock(Lnet/minecraft/network/packet/c2s/play/PlayerInteractBlockC2SPacket;)V", // method = "onPlayerInteractBlock(Lnet/minecraft/network/packet/c2s/play/PlayerInteractBlockC2SPacket;)V",
require = 1, allow = 1, constant = @Constant(doubleValue = 64.0)) // require = 1, allow = 1, constant = @Constant(doubleValue = 64.0))
private double getActualReachDistance(final double reachDistance) { // private double getActualReachDistance(final double reachDistance) {
return 100; // 10^2 becauses 10 blocks chosen in Client mixin // return 100; // 10^2 becauses 10 blocks chosen in Client mixin
} // }
} }

View File

@ -13,12 +13,12 @@ import net.minecraft.server.network.ServerPlayerInteractionManager;
// This class is needed to validate the actual block breaking // This class is needed to validate the actual block breaking
@Mixin(ServerPlayerInteractionManager.class) @Mixin(ServerPlayerInteractionManager.class)
public abstract class ServerPlayerInteractionManagerMixin { public abstract class ServerPlayerInteractionManagerMixin {
@Shadow @Final protected ServerPlayerEntity player; // @Shadow @Final protected ServerPlayerEntity player;
@Redirect( // @Redirect(
method = "processBlockBreakingAction", // method = "processBlockBreakingAction",
at = @At(value = "FIELD", target = "Lnet/minecraft/server/network/ServerPlayNetworkHandler;MAX_BREAK_SQUARED_DISTANCE:D", opcode = Opcodes.GETSTATIC)) // at = @At(value = "FIELD", target = "Lnet/minecraft/server/network/ServerPlayNetworkHandler;MAX_BREAK_SQUARED_DISTANCE:D", opcode = Opcodes.GETSTATIC))
private double getActualReachDistance() { // private double getActualReachDistance() {
return 100; // 10^2 becauses 10 blocks chosen in Client mixin // return 100; // 10^2 becauses 10 blocks chosen in Client mixin
} // }
} }