Skip to content

Commit

Permalink
Fixed lag/spam points issue
Browse files Browse the repository at this point in the history
+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.
  • Loading branch information
CleverNucleus committed Feb 5, 2023
1 parent 830e65a commit 59161eb
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@

public interface ExperienceData extends ServerTickingComponent {
boolean updateExperienceNegationFactor(final int amount);
void resetExperienceNegationFactor();
}
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -46,9 +48,16 @@ public class AttributesPageLayer extends PageLayer {
private static final List<Identifier> 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<Identifier, Integer> buttonDelay = new HashMap<Identifier, Integer>();

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() {
Expand All @@ -61,13 +70,15 @@ private void forEachScreenButton(Consumer<ScreenButtonWidget> 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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Collection<Identifier>> PRIMARIES = () -> Sets.newHashSet(ExAPI.CONSTITUTION.getId(), ExAPI.STRENGTH.getId(), ExAPI.DEXTERITY.getId(), ExAPI.INTELLIGENCE.getId(), ExAPI.LUCKINESS.getId());
Expand Down Expand Up @@ -264,6 +269,30 @@ private static void registerRefundAttribute(CommandNode<ServerCommandSource> roo
attribute.addChild(requiresRefundPoints);
}

private static void registerResetChunk(CommandNode<ServerCommandSource> root) {
LiteralCommandNode<ServerCommandSource> 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<ServerCommandSource, EntitySelector> 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<ServerCommandSource> dispatcher, boolean dedicated) {
LiteralCommandNode<ServerCommandSource> root = CommandManager.literal("playerex").requires(source -> source.hasPermissionLevel(2)).build();
dispatcher.getRoot().addChild(root);
Expand All @@ -273,5 +302,6 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher, b
registerLevelUp(root);
registerSkillAttribute(root);
registerRefundAttribute(root);
registerResetChunk(root);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/playerex/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/playerex/lang/es_mx.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/playerex/lang/ko_kr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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에게 추가합니다.",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/playerex/lang/ru_ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/playerex/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -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技能点",
Expand Down

0 comments on commit 59161eb

Please sign in to comment.