From 59161eb82b57827f772798c426f5f7da7f67a84b Mon Sep 17 00:00:00 2001 From: CleverNucleus Date: Sun, 5 Feb 2023 14:08:41 +0000 Subject: [PATCH] Fixed lag/spam points issue +Incremented version *Fixed server lag occasionally allowing players to spam click level up and gaining more skill points then they should. +Added command to reset a chunk's experience negation factor. --- gradle.properties | 2 +- .../playerex/api/ExperienceData.java | 1 + .../client/gui/AttributesPageLayer.java | 25 ++++++++++++++-- .../playerex/impl/CommandsImpl.java | 30 +++++++++++++++++++ .../playerex/impl/ExperienceDataManager.java | 5 ++++ .../resources/assets/playerex/lang/en_us.json | 1 + .../resources/assets/playerex/lang/es_mx.json | 1 + .../resources/assets/playerex/lang/ko_kr.json | 1 + .../resources/assets/playerex/lang/ru_ru.json | 1 + .../resources/assets/playerex/lang/zh_cn.json | 1 + 10 files changed, 65 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 78a55c95..afcee309 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ minecraft_version=1.18.2 yarn_mappings=1.18.2+build.4 loader_version=0.14.10 -mod_version = 3.4.1 +mod_version = 3.4.2 maven_group = com.github.clevernucleus archives_base_name = playerex diff --git a/src/main/java/com/github/clevernucleus/playerex/api/ExperienceData.java b/src/main/java/com/github/clevernucleus/playerex/api/ExperienceData.java index f2949c2d..9afa9cac 100644 --- a/src/main/java/com/github/clevernucleus/playerex/api/ExperienceData.java +++ b/src/main/java/com/github/clevernucleus/playerex/api/ExperienceData.java @@ -4,4 +4,5 @@ public interface ExperienceData extends ServerTickingComponent { boolean updateExperienceNegationFactor(final int amount); + void resetExperienceNegationFactor(); } diff --git a/src/main/java/com/github/clevernucleus/playerex/client/gui/AttributesPageLayer.java b/src/main/java/com/github/clevernucleus/playerex/client/gui/AttributesPageLayer.java index 5b61bced..4ba070e9 100644 --- a/src/main/java/com/github/clevernucleus/playerex/client/gui/AttributesPageLayer.java +++ b/src/main/java/com/github/clevernucleus/playerex/client/gui/AttributesPageLayer.java @@ -1,7 +1,9 @@ package com.github.clevernucleus.playerex.client.gui; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.function.Consumer; import java.util.function.Supplier; @@ -46,9 +48,16 @@ public class AttributesPageLayer extends PageLayer { private static final List BUTTON_KEYS = ImmutableList.of(ExAPI.LEVEL.getId(), ExAPI.CONSTITUTION.getId(), ExAPI.STRENGTH.getId(), ExAPI.DEXTERITY.getId(), ExAPI.INTELLIGENCE.getId(), ExAPI.LUCKINESS.getId()); private PlayerData playerData; + private final Map buttonDelay = new HashMap(); public AttributesPageLayer(HandledScreen parent, ScreenHandler handler, PlayerInventory inventory, Text title) { super(parent, handler, inventory, title); + this.buttonDelay.put(ExAPI.LEVEL.getId(), 0); + this.buttonDelay.put(ExAPI.CONSTITUTION.getId(), 0); + this.buttonDelay.put(ExAPI.STRENGTH.getId(), 0); + this.buttonDelay.put(ExAPI.DEXTERITY.getId(), 0); + this.buttonDelay.put(ExAPI.INTELLIGENCE.getId(), 0); + this.buttonDelay.put(ExAPI.LUCKINESS.getId(), 0); } private boolean canRefund() { @@ -61,13 +70,15 @@ private void forEachScreenButton(Consumer consumer) { private void buttonPressed(ButtonWidget buttonIn) { ScreenButtonWidget button = (ScreenButtonWidget)buttonIn; - EntityAttributeSupplier attribute = EntityAttributeSupplier.of(button.key()); + Identifier key = button.key(); + EntityAttributeSupplier attribute = EntityAttributeSupplier.of(key); DataAttributesAPI.ifPresent(this.client.player, attribute, (Object)null, amount -> { double value = this.canRefund() ? -1.0D : 1.0D; ClientUtil.modifyAttributes(this.canRefund() ? PacketType.REFUND : PacketType.SKILL, c -> c.accept(attribute, value)); this.client.player.playSound(PlayerEx.SP_SPEND_SOUND, SoundCategory.NEUTRAL, ExAPI.getConfig().skillUpVolume(), 1.5F); return (Object)null; }); + this.buttonDelay.put(key, 40); } private void buttonTooltip(ButtonWidget buttonIn, MatrixStack matrices, int mouseX, int mouseY) { @@ -151,6 +162,13 @@ public void drawBackground(MatrixStack matrices, float delta, int mouseX, int mo button.alt = this.canRefund(); } + + int buttonDelay = this.buttonDelay.getOrDefault(key, 0); + button.active &= (buttonDelay == 0); + + if(buttonDelay > 0) { + this.buttonDelay.put(key, Math.max(0, buttonDelay - 1)); + } } return (Object)null; @@ -162,7 +180,10 @@ public void drawBackground(MatrixStack matrices, float delta, int mouseX, int mo protected void init() { super.init(); this.playerData = ExAPI.PLAYER_DATA.get(this.client.player); - this.addDrawableChild(new ScreenButtonWidget(this.parent, 8, 23, 204, 0, 11, 10, BUTTON_KEYS.get(0), btn -> ClientUtil.modifyAttributes(PacketType.LEVEL, c -> c.accept(ExAPI.LEVEL, 1.0D)), this::buttonTooltip)); + this.addDrawableChild(new ScreenButtonWidget(this.parent, 8, 23, 204, 0, 11, 10, BUTTON_KEYS.get(0), btn -> { + ClientUtil.modifyAttributes(PacketType.LEVEL, c -> c.accept(ExAPI.LEVEL, 1.0D)); + this.buttonDelay.put(((ScreenButtonWidget)btn).key(), 40); + }, this::buttonTooltip)); this.addDrawableChild(new ScreenButtonWidget(this.parent, 8, 56, 204, 0, 11, 10, BUTTON_KEYS.get(1), this::buttonPressed, this::buttonTooltip)); this.addDrawableChild(new ScreenButtonWidget(this.parent, 8, 67, 204, 0, 11, 10, BUTTON_KEYS.get(2), this::buttonPressed, this::buttonTooltip)); this.addDrawableChild(new ScreenButtonWidget(this.parent, 8, 78, 204, 0, 11, 10, BUTTON_KEYS.get(3), this::buttonPressed, this::buttonTooltip)); diff --git a/src/main/java/com/github/clevernucleus/playerex/impl/CommandsImpl.java b/src/main/java/com/github/clevernucleus/playerex/impl/CommandsImpl.java index 46c50180..e86d9bf7 100644 --- a/src/main/java/com/github/clevernucleus/playerex/impl/CommandsImpl.java +++ b/src/main/java/com/github/clevernucleus/playerex/impl/CommandsImpl.java @@ -7,6 +7,7 @@ import com.github.clevernucleus.dataattributes.api.attribute.IEntityAttribute; import com.github.clevernucleus.playerex.api.EntityAttributeSupplier; import com.github.clevernucleus.playerex.api.ExAPI; +import com.github.clevernucleus.playerex.api.ExperienceData; import com.github.clevernucleus.playerex.api.PacketType; import com.github.clevernucleus.playerex.api.PlayerData; import com.google.common.collect.Sets; @@ -29,7 +30,11 @@ import net.minecraft.text.TranslatableText; import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; public final class CommandsImpl { private static final Supplier> PRIMARIES = () -> Sets.newHashSet(ExAPI.CONSTITUTION.getId(), ExAPI.STRENGTH.getId(), ExAPI.DEXTERITY.getId(), ExAPI.INTELLIGENCE.getId(), ExAPI.LUCKINESS.getId()); @@ -264,6 +269,30 @@ private static void registerRefundAttribute(CommandNode roo attribute.addChild(requiresRefundPoints); } + private static void registerResetChunk(CommandNode root) { + LiteralCommandNode reset = CommandManager.literal("resetChunk").executes(ctx -> { + World world = ctx.getSource().getWorld(); + Vec3d vec3d = ctx.getSource().getPosition(); + BlockPos pos = new BlockPos(vec3d); + Chunk chunk = world.getChunk(pos); + + ExAPI.EXPERIENCE_DATA.maybeGet(chunk).ifPresent(ExperienceData::resetExperienceNegationFactor); + ctx.getSource().sendFeedback(new TranslatableText("playerex.command.reset_chunk", pos), false); + return 1; + }).build(); + root.addChild(reset); + + ArgumentCommandNode player = CommandManager.argument("player", EntityArgumentType.player()).executes(ctx -> { + ServerPlayerEntity serverPlayerEntity = EntityArgumentType.getPlayer(ctx, "player"); + PlayerData playerData = ExAPI.PLAYER_DATA.get(serverPlayerEntity); + playerData.reset(); + ctx.getSource().sendFeedback(new TranslatableText("playerex.command.reset", serverPlayerEntity.getName()), false); + + return 1; + }).build(); + reset.addChild(player); + } + public static void register(CommandDispatcher dispatcher, boolean dedicated) { LiteralCommandNode root = CommandManager.literal("playerex").requires(source -> source.hasPermissionLevel(2)).build(); dispatcher.getRoot().addChild(root); @@ -273,5 +302,6 @@ public static void register(CommandDispatcher dispatcher, b registerLevelUp(root); registerSkillAttribute(root); registerRefundAttribute(root); + registerResetChunk(root); } } diff --git a/src/main/java/com/github/clevernucleus/playerex/impl/ExperienceDataManager.java b/src/main/java/com/github/clevernucleus/playerex/impl/ExperienceDataManager.java index 92431c09..6dde0a8e 100644 --- a/src/main/java/com/github/clevernucleus/playerex/impl/ExperienceDataManager.java +++ b/src/main/java/com/github/clevernucleus/playerex/impl/ExperienceDataManager.java @@ -39,6 +39,11 @@ public boolean updateExperienceNegationFactor(final int amount) { return false; } + @Override + public void resetExperienceNegationFactor() { + this.expNegationFactor = 1.0F; + } + @Override public void serverTick() { if(this.expNegationFactor == 1.0F) return; diff --git a/src/main/resources/assets/playerex/lang/en_us.json b/src/main/resources/assets/playerex/lang/en_us.json index f08c295a..4ef79dd1 100644 --- a/src/main/resources/assets/playerex/lang/en_us.json +++ b/src/main/resources/assets/playerex/lang/en_us.json @@ -39,6 +39,7 @@ "text.autoconfig.playerex.option.tooltip": "Tooltip Attributes", "text.autoconfig.playerex.option.tooltip.@Tooltip": "DEFAULT: no change to the tooltip (for mod compatibility).\nVANILLA: fixes attack damage/speed not showing their true value.\nPLAYEREX: attack damage/speed display as regular attribute modifiers.", "playerex.command.reset": "Reset attributes to default values for player %s", + "playerex.command.reset_chunk": "Reset experience negation factor for chunk at %s", "playerex.command.refund": "Refunded %s skill points for player %s", "playerex.command.refund_alt": "Refunded 1 skill point for player %s", "playerex.command.levelup": "Added %s levels to player %s", diff --git a/src/main/resources/assets/playerex/lang/es_mx.json b/src/main/resources/assets/playerex/lang/es_mx.json index cd91ba64..4caba201 100644 --- a/src/main/resources/assets/playerex/lang/es_mx.json +++ b/src/main/resources/assets/playerex/lang/es_mx.json @@ -43,6 +43,7 @@ "text.autoconfig.playerex.option.tooltip": "Descripciones de atributos", "text.autoconfig.playerex.option.tooltip.@Tooltip": "DEFAULT: sin cambios en las descripciones (para compatibilidad con mods).\nVANILLA: corrige el da�o de ataque/velocidad que no muestra su verdadero valor.\nPLAYEREX: el da�o de ataque/la velocidad se muestran como otros atributos.", "command.playerex.reset": "Reinicia los atributos a sus valores predeterminados para %s", + "playerex.command.reset_chunk": "Reset experience negation factor for chunk at %s", "command.playerex.refund": "Se le devolvieron %s puntos de habilidad al jugador %s", "command.playerex.refund_alt": "Se le devolvi� 1 punto de habilidad al jugador %s", "command.playerex.levelup": "Se le agregaron %s niveles al jugador %s", diff --git a/src/main/resources/assets/playerex/lang/ko_kr.json b/src/main/resources/assets/playerex/lang/ko_kr.json index 9b483c82..ac505585 100644 --- a/src/main/resources/assets/playerex/lang/ko_kr.json +++ b/src/main/resources/assets/playerex/lang/ko_kr.json @@ -43,6 +43,7 @@ "text.autoconfig.playerex.option.tooltip": "특성 툴팁", "text.autoconfig.playerex.option.tooltip.@Tooltip": "DEFAULT: 툴팁 (모드 호환)을 변경하지 않습니다.\nVANILLA: 공격 데미지/속도 값을 실제 값으로 표시하지 않습니다.\nPLAYEREX: 공격 데미지/속도 값을 일반 특성 수정자로 표시합니다.", "playerex.command.reset": "플레이어 %s 값을 기본값으로 초기화합니다.", + "playerex.command.reset_chunk": "Reset experience negation factor for chunk at %s", "playerex.command.refund": "스킬 포인트 %s를 플레이어 %s에게 돌려줍니다.", "playerex.command.refund_alt": "스킬 포인트 1을 플레이어 %s에게 돌려줍니다.", "playerex.command.levelup": "%s레벨을 플레이어 %s에게 추가합니다.", diff --git a/src/main/resources/assets/playerex/lang/ru_ru.json b/src/main/resources/assets/playerex/lang/ru_ru.json index 8d04b608..0165713c 100644 --- a/src/main/resources/assets/playerex/lang/ru_ru.json +++ b/src/main/resources/assets/playerex/lang/ru_ru.json @@ -43,6 +43,7 @@ "text.autoconfig.playerex.option.tooltip": "Подсказки характеристик", "text.autoconfig.playerex.option.tooltip.@Tooltip": "ПО УМОЛЧАНИЮ: всплывающая подсказка не изменяется (для совместимости с модами).\nVANILLA: исправляет урон/скорость атаки, не отображающие их истинное значение.\nPLAYEREX: отображение урона/скорости атаки в качестве обычных параметров характеристик.", "playerex.command.reset": "Сбросить характеристики по умолчанию для игрока %s", + "playerex.command.reset_chunk": "Reset experience negation factor for chunk at %s", "playerex.command.refund": "Вернуть %s очков навыка для игрока %s", "playerex.command.refund_alt": "Возвращено 1 очко умений для игрока %s", "playerex.command.levelup": "Добавлено %s уровней для игрока %s", diff --git a/src/main/resources/assets/playerex/lang/zh_cn.json b/src/main/resources/assets/playerex/lang/zh_cn.json index 37449656..fc0adee0 100644 --- a/src/main/resources/assets/playerex/lang/zh_cn.json +++ b/src/main/resources/assets/playerex/lang/zh_cn.json @@ -43,6 +43,7 @@ "text.autoconfig.playerex.option.tooltip": "工具提示属性", "text.autoconfig.playerex.option.tooltip.@Tooltip": "默认:不更改工具提示(为了模组兼容性)。/nVANILLA:修复了攻击伤害/速度显示错误的问题。/nPLAYEREX:攻击伤害/速度显示为常规属性修饰符。", "playerex.command.reset": "将玩家%s的属性设为默认值。", + "playerex.command.reset_chunk": "Reset experience negation factor for chunk at %s", "playerex.command.refund": "玩家%2$s获得%1$s回退点。", "playerex.command.refund_alt": "玩家%2$s获得1回退点。", "playerex.command.levelup": "玩家%2$s获得%1$s技能点",