-
Notifications
You must be signed in to change notification settings - Fork 37
Per-team togglable friendlyfire #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of having a new command for the friendly fire option, it should be added to the existing modify command |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package io.icker.factions.command; | ||
|
|
||
| import com.mojang.brigadier.arguments.BoolArgumentType; | ||
| import com.mojang.brigadier.context.CommandContext; | ||
| import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
| import com.mojang.brigadier.tree.LiteralCommandNode; | ||
|
|
||
| import io.icker.factions.api.persistents.Faction; | ||
| import io.icker.factions.util.Command; | ||
| import io.icker.factions.util.Message; | ||
|
|
||
| import net.minecraft.server.command.CommandManager; | ||
| import net.minecraft.server.command.ServerCommandSource; | ||
| import net.minecraft.server.network.ServerPlayerEntity; | ||
| import net.minecraft.text.Text; | ||
| import net.minecraft.util.Formatting; | ||
|
|
||
| public class FriendlyFireCommand implements Command { | ||
| private int execute(CommandContext<ServerCommandSource> context) throws CommandSyntaxException { | ||
| boolean enabled = BoolArgumentType.getBool(context, "enabled"); | ||
|
|
||
| ServerCommandSource source = context.getSource(); | ||
| ServerPlayerEntity player = source.getPlayerOrThrow(); | ||
|
|
||
| Faction faction = Command.getUser(player).getFaction(); | ||
|
|
||
| faction.setFriendlyFire(enabled); | ||
|
|
||
| new Message( | ||
| Text.translatable( | ||
| enabled | ||
| ? "factions.command.friendlyfire.success.enabled" | ||
| : "factions.command.friendlyfire.success.disabled")) | ||
| .format(enabled ? Formatting.GREEN : Formatting.RED) | ||
| .prependFaction(faction) | ||
| .send(player, false); | ||
|
|
||
| return 1; | ||
| } | ||
|
|
||
| public LiteralCommandNode<ServerCommandSource> getNode() { | ||
| return CommandManager.literal("friendlyfire") | ||
| .requires( | ||
| Requires.multiple( | ||
| Requires.hasPerms("factions.friendlyfire.toggle", 0), | ||
| Requires.isLeader())) | ||
| .then( | ||
| CommandManager.argument("enabled", BoolArgumentType.bool()) | ||
| .executes(this::execute)) | ||
| .build(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ public class FactionsManager { | |
|
|
||
| public static void register() { | ||
| ServerLifecycleEvents.SERVER_STARTED.register(FactionsManager::serverStarted); | ||
| ServerLifecycleEvents.SERVER_STOPPING.register(FactionsManager::serverStopping); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh sorry, this was supposed to be for another pr also includes: #148 (comment)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so basically, whenever the server shuts down before the save interval is triggered, all data stored in memory is just gone which gives me an "Invalid player data" error when attempting to join my dev server
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The server saves itself as it stops, I’m not sure why this is needed |
||
| FactionEvents.MODIFY.register(FactionsManager::factionModified); | ||
| FactionEvents.MEMBER_JOIN.register(FactionsManager::memberChange); | ||
| FactionEvents.MEMBER_LEAVE.register(FactionsManager::memberChange); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ public static void register() { | |
| MiscEvents.ON_SAVE.register(ServerManager::save); | ||
| } | ||
|
|
||
| private static void save(MinecraftServer server) { | ||
| public static void save(MinecraftServer server) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this changed? |
||
| Claim.save(); | ||
| Faction.save(); | ||
| User.save(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using a boxed boolean type, this should use an enum with either true, false, or use config. I don't think our serialization system can handle this correctly as is and it would be more readable.