Skip to content

Commit

Permalink
refactor: rename protectj module into multiplier module and gener…
Browse files Browse the repository at this point in the history
…alized the module.
  • Loading branch information
sakurawald committed Jul 16, 2024
1 parent 524bf75 commit d4abbfc
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 104 deletions.
15 changes: 9 additions & 6 deletions src/main/java/io/github/sakurawald/Fuji.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,27 @@
// TODO: spawn module
// TODO: command warmup module
// TODO: tppos module
// TODO: remove fabric-api dep
// TODO: invsee module
// TODO: condense module
// TODO: powertool module

// TODO: a program to generate module reference DAG
// TODO: code review for skin module

// TODO: nickname module -> luckperms

// TODO: luckperms context calculator

// TODO: a lisp-like DSL (parser and code-walker) for specific command.
// TODO: refactor command facility (selector, aop, options, parser)
// TODO: specific command module
// TODO: add native shell support specific command
// TODO: kit module -> spec-command

// TODO: a generalized mixin plugin to dispatch text.

// TODO: sign module
// TODO: feature for chat module -> handle more chat types
// TODO: a program to generate module reference DAG

// TODO: nickname module -> luckperms
// TODO: luckperms context calculator

public class Fuji implements ModInitializer {
public static final String MOD_ID = "fuji";
public static final Logger LOGGER = LogUtil.createLogger(StringUtils.capitalize(MOD_ID));
Expand Down
46 changes: 24 additions & 22 deletions src/main/java/io/github/sakurawald/config/model/ConfigModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public class Modules {
public Smithing smithing = new Smithing();
public World world = new World();
public Realname realname = new Realname();
public Protect protect = new Protect();
public Multiplier multiplier = new Multiplier();

@Documentation("""
This module adds another 3 worlds called `resource world`: resource_overworld, resource_nether, resource_the_end .
Expand Down Expand Up @@ -1033,30 +1033,32 @@ public class Realname {
}

@Documentation("""
This module provides damage-cancel by permission.
For performance considered:
1. This module only check damage_type inside this checklist.
2. The permission is checked by cache.
You can query damage_type list in minecraft using `/damage @r 1 <damage_type>`
For example,
If you want to protect all the players from fall damage, you should do:
1. add `minecraft:fall` into the `damage_type_checklist`.
2. grant the permission for players: `/lp group default permission set fuji.protect.minecraft:fall`
If you grant permission `/lp group default permission set fuji.protect.*`, then it means cancel
all the damage types inside the `damage_type_checklist`.
This module provides some `numeric multiplier`.
Supported numeric types:
- damage
- experience
- Example 1
If you want to `doubled` the damage from zombie to a player.
You can set a meta by: `/lp group default meta set fuji.multiplier.damage.minecraft:zombie 2`
- Example 2
If you want to cancel fall damage for all players. You can use `damage multiplier`.
You can set a meta by: `/lp group default meta set fuji.multiplier.damage.minecraft:fall 0`
- Example 3
If you want to `doubled` all the damages to a player.
You can set a meta by: `/lp group default meta set fuji.multiplier.damage.all 2`
- Example 4
If you want to `doubled` all the experience a player gained.
You can set a meta by: `/lp group default meta set fuji.multiplier.experience.all 2`
""")
public class Protect {
public class Multiplier {
public boolean enable = false;

public Set<String> damage_type_checklist = new HashSet<>() {
{
this.add("minecraft:fall");
}
};
}

public AntiBuild anti_build = new AntiBuild();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import java.util.List;
import java.util.Map;

@Mixin(value = RegistryLoader.class, priority = 900)
@Mixin(value = RegistryLoader.class)
@Slf4j
public class RegistryLoaderMixin {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.sakurawald.module.mixin.chat;

import io.github.sakurawald.config.Configs;
import io.github.sakurawald.module.ModuleManager;
import io.github.sakurawald.module.initializer.chat.ChatInitializer;
import lombok.extern.slf4j.Slf4j;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.github.sakurawald.module.mixin.multiplier;

import com.llamalad7.mixinextras.sugar.Local;
import io.github.sakurawald.util.LuckPermsUtil;
import lombok.extern.slf4j.Slf4j;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.server.network.ServerPlayerEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;

import java.util.Optional;

@Mixin(ServerPlayerEntity.class)
@Slf4j
public abstract class ServerPlayerMixin {

@Unique
ServerPlayerEntity player = (ServerPlayerEntity) (Object) this;

@Unique
float transform(ServerPlayerEntity player, String type, String key, float f) {
Optional<Float> meta = LuckPermsUtil.getMeta(player, "fuji.multiplier.%s.%s".formatted(type, key), Float::valueOf);
return meta.map(factor -> f * factor).orElse(f);
}

@ModifyVariable(method = "damage", at = @At(value = "HEAD"), argsOnly = true)
public float transformDamage(float damage, @Local(argsOnly = true) DamageSource damageSource) {
damage = transform(player, "damage", "all", damage);
damage = transform(player, "damage", damageSource.getTypeRegistryEntry().getIdAsString(), damage);
return damage;
}

@ModifyVariable(method = "addExperience", at = @At(value = "HEAD"), argsOnly = true)
public int transformExperience(int exp) {
exp = (int) transform(player, "experience", "all", exp);
return exp;
}

}

This file was deleted.

84 changes: 42 additions & 42 deletions src/main/resources/fuji.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,58 @@
"compatibilityLevel": "JAVA_17",
"plugin": "io.github.sakurawald.module.mixin.ModuleMixinConfigPlugin",
"mixins": [
"_internal.low_level.GameProfileCacheMixin",
"_internal.low_level.MinecraftServerMixin",
"afk.PlayerListMixin",
"afk.ServerPlayerMixin",
"anti_build.BlockMixin",
"anti_build.EntityMixin",
"fake_player_manager.PlayerCommandMixin",
"anti_build.ServerPlayerInteractionManagerMixin",
"back.ServerPlayerMixin",
"better_info.InfoCommandMixin",
"bypass_chat_speed.ServerGamePacketListenerImplMixin",
"sit.InteractModifierMixin",
"teleport_warmup.ServerPlayerMixin",
"command_interactive.SignBlockMixin",
"resource_world.registry.DimensionOptionsMixin",
"enchantment.EnchantmentScreenHandlerMixin",
"works.HopperBlockEntityMixin",
"resource_world.registry.WorldGenSettingsMixin",
"bypass_max_player_limit.DedicatedPlayerManagerMixin",
"resource_world.ServerWorldMixin",
"command_rewrite.ServerPlayNetworkHandlerMixin",
"skin.PlayerListMixin",
"placeholder.ServerPlayNetworkHandlerMixin",
"anti_build.BlockMixin",
"afk.ServerPlayerMixin",
"_internal.low_level.MinecraftServerMixin",
"motd.ServerQueryNetworkHandlerMixin",
"bypass_move_speed.ServerGamePacketListenerImplMixin",
"chat.PlayerListMixin",
"chat.RegistryLoaderMixin",
"afk.PlayerListMixin",
"resource_world.MinecraftServerMixin",
"newbie_welcome.PlayerListMixin",
"multi_obsidian_platform.EndPortalBlockMixin",
"fix_player_list_cme.ServerLevelMixin",
"resource_world.EndGatewayBlockEntityMixin",
"fake_player_manager.PlayerMixin",
"placeholder.PlayerEntityMixin",
"chat.ServerGamePacketListenerImplMixin",
"system_message.ComponentMixin",
"_internal.low_level.GameProfileCacheMixin",
"bypass_chat_speed.ServerGamePacketListenerImplMixin",
"fake_player_manager.PlayerListMixin",
"op_protect.ServerPlayNetworkHandlerMixin",
"command_cooldown.CommandsMixin",
"command_interactive.SignBlockMixin",
"command_permission.CommandNodeAccessor",
"command_rewrite.ServerPlayNetworkHandlerMixin",
"reply.MsgCommandMixin",
"skin.ServerLoginNetworkHandlerMixin",
"command_spy.CommandsMixin",
"deathlog.ServerPlayerMixin",
"enchantment.EnchantmentScreenHandlerMixin",
"fake_player_manager.PlayerCommandMixin",
"fake_player_manager.PlayerListMixin",
"fake_player_manager.PlayerMixin",
"fix_player_list_cme.PlayerListMixin",
"fix_player_list_cme.ServerLevelMixin",
"fix_whitelist.UserWhiteListMixin",
"language.ServerPlayerMixin",
"motd.ServerQueryNetworkHandlerMixin",
"multi_obsidian_platform.EndPortalBlockMixin",
"newbie_welcome.PlayerListMixin",
"op_protect.ServerPlayNetworkHandlerMixin",
"placeholder.PlayerEntityMixin",
"placeholder.ServerPlayNetworkHandlerMixin",
"protect.ServerPlayerMixin",
"pvp.PvpToggleMixin",
"reply.MsgCommandMixin",
"resource_world.EndGatewayBlockEntityMixin",
"resource_world.MinecraftServerMixin",
"resource_world.ServerWorldMixin",
"resource_world.registry.DimensionOptionsMixin",
"_internal.low_level.SimpleRegistryMixin",
"resource_world.registry.WorldGenSettingsMixin",
"multiplier.ServerPlayerMixin",
"seen.PlayerListMixin",
"sit.InteractModifierMixin",
"skin.PlayerListMixin",
"skin.ServerLoginNetworkHandlerMixin",
"system_message.ComponentMixin",
"teleport_warmup.ServerPlayerMixin",
"back.ServerPlayerMixin",
"language.ServerPlayerMixin",
"chat.PlayerListMixin",
"fix_whitelist.UserWhiteListMixin",
"_internal.low_level.SimpleRegistryMixin",
"top_chunks.ThreadedAnvilChunkStorageMixin",
"works.HopperBlockEntityMixin"
"command_permission.CommandNodeAccessor",
"anti_build.EntityMixin",
"better_info.InfoCommandMixin",
"chat.RegistryLoaderMixin",
"fix_player_list_cme.PlayerListMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit d4abbfc

Please sign in to comment.