Skip to content

Commit 6c8bfdf

Browse files
committed
More docs, better perm managing
1 parent c0bb48d commit 6c8bfdf

10 files changed

Lines changed: 150 additions & 24 deletions

common/src/main/java/org/samo_lego/taterzens/api/professions/DefaultProfession.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ public TaterzenProfession create(TaterzenNPC taterzen) {
8282
* You can create a local inventory in the profession and save it there.
8383
* Taterzen needs to have {@link TaterzenNPC#canPickUpLoot()} enabled.
8484
*
85-
* @param stack stack to be picked up
85+
* @param groundStack stack to be picked up
8686
*
8787
* @return true if item should be picked up, otherwise false.
8888
*/
8989
@Override
90-
public boolean tryPickupItem(ItemStack stack) {
90+
public boolean tryPickupItem(ItemStack groundStack) {
9191
return false;
9292
}
9393
}

common/src/main/java/org/samo_lego/taterzens/api/professions/TaterzenProfession.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ default ActionResult interactAt(PlayerEntity player, Vec3d pos, Hand hand) {
7777
* You can create a local inventory in the profession and save it there.
7878
* Taterzen needs to have {@link TaterzenNPC#canPickUpLoot()} enabled.
7979
*
80-
* @param stack stack to be picked up
80+
* @param groundStack stack to be picked up
8181
* @return true if item should be picked up, otherwise false.
8282
*/
83-
boolean tryPickupItem(ItemStack stack);
83+
boolean tryPickupItem(ItemStack groundStack);
8484
}

common/src/main/java/org/samo_lego/taterzens/commands/NpcCommand.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class NpcCommand {
6060

6161
public static void register(CommandDispatcher<ServerCommandSource> dispatcher, boolean dedicated) {
6262
dispatcher.register(literal("npc")
63-
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(4) || LUCKPERMS_ENABLED)
63+
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(config.perms.npcCommandPermissionLevel) || LUCKPERMS_ENABLED)
6464
.then(literal("create")
6565
.then(argument("name", message())
6666
.suggests((context, builder) -> CommandSource.suggestMatching(getOnlinePlayers(context), builder))
@@ -354,20 +354,25 @@ private static int listTaterzenCommands(CommandContext<ServerCommandSource> cont
354354
}
355355

356356
private static int setPermissionLevel(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
357-
if(LUCKPERMS_ENABLED && !permissions$checkPermission(context.getSource(), PERMISSIONS.npc_edit_commands_setPermissionLevel)) {
358-
context.getSource().sendError(new TranslatableText("commands.help.failed").formatted(Formatting.RED));
357+
ServerCommandSource source = context.getSource();
358+
if(LUCKPERMS_ENABLED && !permissions$checkPermission(source, PERMISSIONS.npc_edit_commands_setPermissionLevel)) {
359+
source.sendError(new TranslatableText("commands.help.failed").formatted(Formatting.RED));
359360
return -1;
360361
}
361362

362-
ServerPlayerEntity player = context.getSource().getPlayer();
363+
ServerPlayerEntity player = source.getPlayer();
363364
TaterzenNPC taterzen = ((TaterzenEditor) player).getNpc();
364365
if(taterzen != null) {
365366
int newPermLevel = IntegerArgumentType.getInteger(context, "level");
366-
player.sendMessage(successText(lang.success.updatedPermissionLevel, new LiteralText(String.valueOf(newPermLevel))), false);
367+
if(!config.perms.allowSettingHigherPermissionLevel && !source.hasPermissionLevel(newPermLevel)) {
368+
source.sendError(errorText(lang.error.cannotSetPermissionLevel, new LiteralText(String.valueOf(newPermLevel))));
369+
return -1;
370+
}
371+
source.sendFeedback(successText(lang.success.updatedPermissionLevel, new LiteralText(String.valueOf(newPermLevel))), false);
367372
taterzen.setPermissionLevel(newPermLevel);
368373

369374
} else
370-
context.getSource().sendError(noSelectedTaterzenError());
375+
source.sendError(noSelectedTaterzenError());
371376

372377
return 0;
373378
}

common/src/main/java/org/samo_lego/taterzens/commands/TaterzensCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
public class TaterzensCommand {
2222
public static void register(CommandDispatcher<ServerCommandSource> dispatcher, boolean dedicated) {
2323
dispatcher.register(literal("taterzens")
24-
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(4))
24+
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(config.perms.taterzensCommandPermissionLevel))
2525
.then(literal("config")
2626
.then(literal("reload")
2727
.executes(TaterzensCommand::reloadConfig)

common/src/main/java/org/samo_lego/taterzens/mixin/ServerPlayInteractionManagerMixin.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,15 @@ public class ServerPlayInteractionManagerMixin {
2626
*
2727
* @param blockPos position of the broken block
2828
* @param playerAction action the player is trying to do
29-
* @param direction
30-
* @param i
31-
* @param ci
29+
* @param direction direction
30+
* @param worldHeight world height
3231
*/
3332
@Inject(
3433
method = "processBlockBreakingAction(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/network/packet/c2s/play/PlayerActionC2SPacket$Action;Lnet/minecraft/util/math/Direction;I)V",
3534
at = @At("HEAD"),
3635
cancellable = true
3736
)
38-
private void onAttackBlock(BlockPos blockPos, PlayerActionC2SPacket.Action playerAction, Direction direction, int i, CallbackInfo ci) {
37+
private void onAttackBlock(BlockPos blockPos, PlayerActionC2SPacket.Action playerAction, Direction direction, int worldHeight, CallbackInfo ci) {
3938
if (playerAction == PlayerActionC2SPacket.Action.START_DESTROY_BLOCK) {
4039
TaterzenEditor player = (TaterzenEditor) this.player;
4140
if(player.getNpc() != null && player.inPathEditMode()) {

common/src/main/java/org/samo_lego/taterzens/mixin/ServerPlayNetworkHandlerMixin_MsgEditor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ public class ServerPlayNetworkHandlerMixin_MsgEditor {
2828
* message edit mode, messages sent to chat
2929
* will be saved to taterzen instead.
3030
*
31-
* @param msg
32-
* @param ci
31+
* @param msg message sent by player
3332
*/
3433
@Inject(
3534
method = "method_31286(Ljava/lang/String;)V",
@@ -56,7 +55,7 @@ private void onMessage(String msg, CallbackInfo ci) {
5655
}
5756
} else {
5857
Text text;
59-
if(msg.startsWith("{") && msg.endsWith("}")) {
58+
if((msg.startsWith("{") && msg.endsWith("}") || (msg.startsWith("[") && msg.endsWith("]")))) {
6059
// NBT tellraw message structure, try parse it
6160
try {
6261
text = Text.Serializer.fromJson(new StringReader(msg));

common/src/main/java/org/samo_lego/taterzens/mixin/ThreadedAnvilChunkStorageMixin_TaterzenList.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public class ThreadedAnvilChunkStorageMixin_TaterzenList {
1616
/**
1717
* Sets Taterzen to {@link org.samo_lego.taterzens.Taterzens#TATERZEN_NPCS NPC list}.
1818
* @param entity entity being loaded
19-
* @param ci
2019
*/
2120
@Inject(method = "loadEntity(Lnet/minecraft/entity/Entity;)V", at = @At("TAIL"))
2221
private void onEntityLoad(Entity entity, CallbackInfo ci) {
@@ -27,7 +26,6 @@ private void onEntityLoad(Entity entity, CallbackInfo ci) {
2726
/**
2827
* Unloads Taterzen from {@link org.samo_lego.taterzens.Taterzens#TATERZEN_NPCS NPC list}.
2928
* @param entity entity being unloaded
30-
* @param ci
3129
*/
3230
@Inject(method = "unloadEntity(Lnet/minecraft/entity/Entity;)V", at = @At("TAIL"))
3331
private void onEntityUnload(Entity entity, CallbackInfo ci) {

common/src/main/java/org/samo_lego/taterzens/npc/NPCData.java

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,65 @@
44
import net.minecraft.entity.player.PlayerEntity;
55
import net.minecraft.text.Text;
66
import net.minecraft.util.math.BlockPos;
7+
import org.jetbrains.annotations.Nullable;
78

89
import java.util.ArrayList;
910

1011
import static org.samo_lego.taterzens.Taterzens.config;
1112

1213
/**
1314
* Deafult NPC data.
15+
* Used for taterzen attributes.
1416
*/
1517
public class NPCData {
1618
/**
17-
* Used for taterzen attributes.
19+
* Whether Taterzen should be able to be put on a lead..
1820
*/
19-
public boolean hostile = false;
2021
public boolean leashable = config.defaults.leashable;
22+
/**
23+
* Current equipment editor for Taterzen.
24+
*/
25+
@Nullable
2126
public PlayerEntity equipmentEditor = null;
27+
/**
28+
* Default Taterzen movement.
29+
*/
2230
public Movement movement = Movement.NONE;
31+
/**
32+
* Path nodes, used when movement
33+
* is set to {@link NPCData.Movement#FORCED_PATH}
34+
* or {@link NPCData.Movement#PATH}.
35+
*/
2336
public ArrayList<BlockPos> pathTargets = new ArrayList<>();
37+
/**
38+
* Current index position
39+
* in {@link NPCData#pathTargets}.
40+
*/
2441
public int currentMoveTarget = 0;
42+
/**
43+
* Whether Taterzen should be pushable.
44+
*/
2545
public boolean pushable = config.defaults.pushable;
46+
/**
47+
* Messages of Taterzen.
48+
* Saved as &lt;Message Text, Delay&gt;
49+
*/
2650
public ArrayList<Pair<Text, Integer>> messages = new ArrayList<>();
51+
/**
52+
* Permission level of Taterzen.
53+
*/
2754
public int permissionLevel = config.defaults.commandPermissionLevel;
55+
/**
56+
* Commands to be executed on right click.
57+
*/
2858
public ArrayList<String> commands = new ArrayList<>();
59+
/**
60+
* Default behaviour of Taterzen.
61+
*/
2962
public Behaviour behaviour = Behaviour.PASSIVE;
63+
/**
64+
* Whether to allow dropping equipment on death.
65+
*/
3066
public boolean allowEquipmentDrops = false;
3167

3268
/**
@@ -61,6 +97,9 @@ public enum Movement {
6197
FREE
6298
}
6399

100+
/**
101+
* Behaviour types.
102+
*/
64103
public enum Behaviour {
65104
/**
66105
* Doesn't attack. What's a weapon?

common/src/main/java/org/samo_lego/taterzens/storage/TaterConfig.java

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,24 @@ public class TaterConfig {
2525
*/
2626
public String language = "en_us";
2727

28-
public final String _comment_disableRegistrySync = "// Whether to disable Fabric's registry sync. Leave this to true if you'd like to keep the mod server-sided.";
28+
public final String _comment_disableRegistrySync1 = "// Whether to remove Taterzens from Fabric's registry sync. Safe to be true.";
29+
public final String _comment_disableRegistrySync2 = "// If using Forge, this will remove WHOLE registry sync. Proceed with caution.";
30+
/**
31+
* Whether to disable Fabric's / Forge's registry sync.
32+
* This marks mod as serverside.
33+
*
34+
* If using Fabric, Taterzen NPC type is just removed from sync packet.
35+
* If using Forge, the whole thing is not synced. Use carefully!
36+
*/
2937
@SerializedName("disable_registry_sync")
3038
public boolean disableRegistrySync = true;
3139

3240
public final String _comment_taterzenTablistTimeout1 = "// After how many ticks Taterzens should be cleared from tablist.";
3341
public final String _comment_taterzenTablistTimeout2 = "// Some delay is needed, otherwise clients don't fetch their skins.";
42+
/**
43+
* After how many ticks Taterzens should be cleared from tablist.
44+
* Some delay is needed, otherwise clients don't fetch their skins.
45+
*/
3446
@SerializedName("taterzen_tablist_timeout")
3547
public int taterzenTablistTimeout = 30;
3648

@@ -48,43 +60,116 @@ public class TaterConfig {
4860
public Defaults defaults = new Defaults();
4961
public Path path = new Path();
5062
public Messages messages = new Messages();
63+
public Permissions perms = new Permissions();
64+
65+
/**
66+
* Some permission stuff.
67+
* If you are looking for permission nodes,
68+
* see the generated permission.json file.
69+
*
70+
* (You must have LuckPerms installed.)
71+
*/
72+
public static class Permissions {
73+
public final String _comment_npcCommandPermissionLevel1 = "// Permission level required to execute /npc command.";
74+
public final String _comment_npcCommandPermissionLevel2 = "// Valid only if LuckPerms isn't present.";
75+
/**
76+
* Permission level required to execute /npc command.
77+
* Valid only if LuckPerms isn't present.
78+
*/
79+
@SerializedName("npc_command_permission_level")
80+
public int npcCommandPermissionLevel = 2;
81+
82+
83+
public final String _comment_taterzensCommandPermissionLevel1 = "// Permission level required to execute /taterzens command.";
84+
public final String _comment_taterzensCommandPermissionLevel2 = "// Valid only if LuckPerms isn't present.";
85+
/**
86+
* Permission level required to execute /taterzens command.
87+
* Valid only if LuckPerms isn't present.
88+
*/
89+
@SerializedName("npc_command_permission_level")
90+
public int taterzensCommandPermissionLevel = 4;
91+
92+
public final String _comment_allowSettingHigherPermissionLevel1 = "// Whether to allow players to set the permission level";
93+
public final String _comment_allowSettingHigherPermissionLevel2 = "// of Taterzen higher than their own. Careful! This could";
94+
public final String _comment_allowSettingHigherPermissionLevel3 = "// enable players to bypass their permission level with NPC.";
95+
@SerializedName("allow_setting_higher_perm_level")
96+
public boolean allowSettingHigherPermissionLevel = false;
97+
}
5198

5299
/**
53100
* Default {@link org.samo_lego.taterzens.npc.TaterzenNPC} settings.
54101
*/
55102
public static class Defaults {
56103
public final String _comment_name = "// Default settings for new Taterzens.";
104+
/**
105+
* Default Taterzen name
106+
*/
57107
public String name = "Taterzen";
108+
/**
109+
* Whether Taterzens should be leashable.
110+
*/
58111
public boolean leashable = false;
59112
public boolean pushable = false;
60113

61-
public final String _comment_commandPermissionLevel = "// Default command permission level of Taterzen";
114+
public final String _comment_commandPermissionLevel = "// Default command permission level of Taterzen.";
115+
/**
116+
* Default command permission level of Taterzen.
117+
*/
62118
@SerializedName("command_permission_level")
63119
public int commandPermissionLevel = 4;
64120

65121
public final String _comment_sounds = "// Default sounds for Taterzens. Set to null to mute them.";
122+
/**
123+
* Default Taterzen death sound.
124+
* Can be null to not produce any sounds.
125+
*/
66126
@SerializedName("death_sound")
67127
public String deathSound = "entity.player.death";
128+
/**
129+
* Default Taterzen hurt / hit sound.
130+
* Can be null to not produce any sounds.
131+
*/
68132
@SerializedName("hurt_sound")
69133
public String hurtSound = "entity.player.hurt";
134+
/**
135+
* Default Taterzen ambient sound.
136+
* Can be null to not produce any sounds.
137+
*/
70138
@SerializedName("ambient_sound")
71139
public String ambientSound = "entity.player.breath";
140+
/**
141+
* Whether Taterzen is invulnerable by default.
142+
*/
72143
public boolean invulnerable = true;
73144
}
74145

146+
/**
147+
* Settings for Taterzen's messages
148+
*/
75149
public static class Messages {
76150
public final String _comment_messageDelay = "// Default delay between each message, in ticks.";
151+
/**
152+
* Default delay between each message, in ticks.
153+
*/
154+
@SerializedName("message_delay")
77155
public int messageDelay = 100;
78156
public final String _comment_exitEditorAfterMsgEdit = "// Whether to exit message editor mode after editing a message.";
157+
/**
158+
* Whether to exit message editor mode after editing a message.
159+
*/
79160
@SerializedName("exit_editor_after_msg_edit")
80161
public boolean exitEditorAfterMsgEdit = true;
81162
}
82163

83164

165+
/**
166+
* Settings for path visualisation.
167+
*/
84168
public static class Path {
85169
public Path.Color color = new Path.Color();
86170
/**
87171
* Color of particles used in path editor.
172+
* Accepts RGB values (0 - 255).
88173
*/
89174
public static class Color {
90175
public final String _comment = "// Which color of particles to use in path editor. Use RGB values ( 0 - 255 ).";

common/src/main/java/org/samo_lego/taterzens/storage/TaterLang.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public static class Error {
8181
public String noCommandFound = "No commands with id %s were found.";
8282
public String disguiseLibRequired = "DisguiseLib mod is required for this action.";
8383
public String noProfessionFound = "No professions with id %s were found.";
84+
public String cannotSetPermissionLevel = "Permission level %s is higher than your permission level.";
8485
}
8586

8687

0 commit comments

Comments
 (0)