Skip to content

Commit 59161eb

Browse files
committed
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.
1 parent 830e65a commit 59161eb

File tree

10 files changed

+65
-3
lines changed

10 files changed

+65
-3
lines changed

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ minecraft_version=1.18.2
44
yarn_mappings=1.18.2+build.4
55
loader_version=0.14.10
66

7-
mod_version = 3.4.1
7+
mod_version = 3.4.2
88
maven_group = com.github.clevernucleus
99
archives_base_name = playerex
1010

src/main/java/com/github/clevernucleus/playerex/api/ExperienceData.java

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44

55
public interface ExperienceData extends ServerTickingComponent {
66
boolean updateExperienceNegationFactor(final int amount);
7+
void resetExperienceNegationFactor();
78
}

src/main/java/com/github/clevernucleus/playerex/client/gui/AttributesPageLayer.java

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.github.clevernucleus.playerex.client.gui;
22

33
import java.util.ArrayList;
4+
import java.util.HashMap;
45
import java.util.List;
6+
import java.util.Map;
57
import java.util.function.Consumer;
68
import java.util.function.Supplier;
79

@@ -46,9 +48,16 @@ public class AttributesPageLayer extends PageLayer {
4648
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());
4749

4850
private PlayerData playerData;
51+
private final Map<Identifier, Integer> buttonDelay = new HashMap<Identifier, Integer>();
4952

5053
public AttributesPageLayer(HandledScreen<?> parent, ScreenHandler handler, PlayerInventory inventory, Text title) {
5154
super(parent, handler, inventory, title);
55+
this.buttonDelay.put(ExAPI.LEVEL.getId(), 0);
56+
this.buttonDelay.put(ExAPI.CONSTITUTION.getId(), 0);
57+
this.buttonDelay.put(ExAPI.STRENGTH.getId(), 0);
58+
this.buttonDelay.put(ExAPI.DEXTERITY.getId(), 0);
59+
this.buttonDelay.put(ExAPI.INTELLIGENCE.getId(), 0);
60+
this.buttonDelay.put(ExAPI.LUCKINESS.getId(), 0);
5261
}
5362

5463
private boolean canRefund() {
@@ -61,13 +70,15 @@ private void forEachScreenButton(Consumer<ScreenButtonWidget> consumer) {
6170

6271
private void buttonPressed(ButtonWidget buttonIn) {
6372
ScreenButtonWidget button = (ScreenButtonWidget)buttonIn;
64-
EntityAttributeSupplier attribute = EntityAttributeSupplier.of(button.key());
73+
Identifier key = button.key();
74+
EntityAttributeSupplier attribute = EntityAttributeSupplier.of(key);
6575
DataAttributesAPI.ifPresent(this.client.player, attribute, (Object)null, amount -> {
6676
double value = this.canRefund() ? -1.0D : 1.0D;
6777
ClientUtil.modifyAttributes(this.canRefund() ? PacketType.REFUND : PacketType.SKILL, c -> c.accept(attribute, value));
6878
this.client.player.playSound(PlayerEx.SP_SPEND_SOUND, SoundCategory.NEUTRAL, ExAPI.getConfig().skillUpVolume(), 1.5F);
6979
return (Object)null;
7080
});
81+
this.buttonDelay.put(key, 40);
7182
}
7283

7384
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
151162

152163
button.alt = this.canRefund();
153164
}
165+
166+
int buttonDelay = this.buttonDelay.getOrDefault(key, 0);
167+
button.active &= (buttonDelay == 0);
168+
169+
if(buttonDelay > 0) {
170+
this.buttonDelay.put(key, Math.max(0, buttonDelay - 1));
171+
}
154172
}
155173

156174
return (Object)null;
@@ -162,7 +180,10 @@ public void drawBackground(MatrixStack matrices, float delta, int mouseX, int mo
162180
protected void init() {
163181
super.init();
164182
this.playerData = ExAPI.PLAYER_DATA.get(this.client.player);
165-
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));
183+
this.addDrawableChild(new ScreenButtonWidget(this.parent, 8, 23, 204, 0, 11, 10, BUTTON_KEYS.get(0), btn -> {
184+
ClientUtil.modifyAttributes(PacketType.LEVEL, c -> c.accept(ExAPI.LEVEL, 1.0D));
185+
this.buttonDelay.put(((ScreenButtonWidget)btn).key(), 40);
186+
}, this::buttonTooltip));
166187
this.addDrawableChild(new ScreenButtonWidget(this.parent, 8, 56, 204, 0, 11, 10, BUTTON_KEYS.get(1), this::buttonPressed, this::buttonTooltip));
167188
this.addDrawableChild(new ScreenButtonWidget(this.parent, 8, 67, 204, 0, 11, 10, BUTTON_KEYS.get(2), this::buttonPressed, this::buttonTooltip));
168189
this.addDrawableChild(new ScreenButtonWidget(this.parent, 8, 78, 204, 0, 11, 10, BUTTON_KEYS.get(3), this::buttonPressed, this::buttonTooltip));

src/main/java/com/github/clevernucleus/playerex/impl/CommandsImpl.java

+30
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.github.clevernucleus.dataattributes.api.attribute.IEntityAttribute;
88
import com.github.clevernucleus.playerex.api.EntityAttributeSupplier;
99
import com.github.clevernucleus.playerex.api.ExAPI;
10+
import com.github.clevernucleus.playerex.api.ExperienceData;
1011
import com.github.clevernucleus.playerex.api.PacketType;
1112
import com.github.clevernucleus.playerex.api.PlayerData;
1213
import com.google.common.collect.Sets;
@@ -29,7 +30,11 @@
2930
import net.minecraft.text.TranslatableText;
3031
import net.minecraft.util.Formatting;
3132
import net.minecraft.util.Identifier;
33+
import net.minecraft.util.math.BlockPos;
3234
import net.minecraft.util.math.MathHelper;
35+
import net.minecraft.util.math.Vec3d;
36+
import net.minecraft.world.World;
37+
import net.minecraft.world.chunk.Chunk;
3338

3439
public final class CommandsImpl {
3540
private static final Supplier<Collection<Identifier>> 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<ServerCommandSource> roo
264269
attribute.addChild(requiresRefundPoints);
265270
}
266271

272+
private static void registerResetChunk(CommandNode<ServerCommandSource> root) {
273+
LiteralCommandNode<ServerCommandSource> reset = CommandManager.literal("resetChunk").executes(ctx -> {
274+
World world = ctx.getSource().getWorld();
275+
Vec3d vec3d = ctx.getSource().getPosition();
276+
BlockPos pos = new BlockPos(vec3d);
277+
Chunk chunk = world.getChunk(pos);
278+
279+
ExAPI.EXPERIENCE_DATA.maybeGet(chunk).ifPresent(ExperienceData::resetExperienceNegationFactor);
280+
ctx.getSource().sendFeedback(new TranslatableText("playerex.command.reset_chunk", pos), false);
281+
return 1;
282+
}).build();
283+
root.addChild(reset);
284+
285+
ArgumentCommandNode<ServerCommandSource, EntitySelector> player = CommandManager.argument("player", EntityArgumentType.player()).executes(ctx -> {
286+
ServerPlayerEntity serverPlayerEntity = EntityArgumentType.getPlayer(ctx, "player");
287+
PlayerData playerData = ExAPI.PLAYER_DATA.get(serverPlayerEntity);
288+
playerData.reset();
289+
ctx.getSource().sendFeedback(new TranslatableText("playerex.command.reset", serverPlayerEntity.getName()), false);
290+
291+
return 1;
292+
}).build();
293+
reset.addChild(player);
294+
}
295+
267296
public static void register(CommandDispatcher<ServerCommandSource> dispatcher, boolean dedicated) {
268297
LiteralCommandNode<ServerCommandSource> root = CommandManager.literal("playerex").requires(source -> source.hasPermissionLevel(2)).build();
269298
dispatcher.getRoot().addChild(root);
@@ -273,5 +302,6 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher, b
273302
registerLevelUp(root);
274303
registerSkillAttribute(root);
275304
registerRefundAttribute(root);
305+
registerResetChunk(root);
276306
}
277307
}

src/main/java/com/github/clevernucleus/playerex/impl/ExperienceDataManager.java

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ public boolean updateExperienceNegationFactor(final int amount) {
3939
return false;
4040
}
4141

42+
@Override
43+
public void resetExperienceNegationFactor() {
44+
this.expNegationFactor = 1.0F;
45+
}
46+
4247
@Override
4348
public void serverTick() {
4449
if(this.expNegationFactor == 1.0F) return;

src/main/resources/assets/playerex/lang/en_us.json

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"text.autoconfig.playerex.option.tooltip": "Tooltip Attributes",
4040
"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.",
4141
"playerex.command.reset": "Reset attributes to default values for player %s",
42+
"playerex.command.reset_chunk": "Reset experience negation factor for chunk at %s",
4243
"playerex.command.refund": "Refunded %s skill points for player %s",
4344
"playerex.command.refund_alt": "Refunded 1 skill point for player %s",
4445
"playerex.command.levelup": "Added %s levels to player %s",

src/main/resources/assets/playerex/lang/es_mx.json

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"text.autoconfig.playerex.option.tooltip": "Descripciones de atributos",
4444
"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.",
4545
"command.playerex.reset": "Reinicia los atributos a sus valores predeterminados para %s",
46+
"playerex.command.reset_chunk": "Reset experience negation factor for chunk at %s",
4647
"command.playerex.refund": "Se le devolvieron %s puntos de habilidad al jugador %s",
4748
"command.playerex.refund_alt": "Se le devolvi� 1 punto de habilidad al jugador %s",
4849
"command.playerex.levelup": "Se le agregaron %s niveles al jugador %s",

src/main/resources/assets/playerex/lang/ko_kr.json

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"text.autoconfig.playerex.option.tooltip": "특성 툴팁",
4444
"text.autoconfig.playerex.option.tooltip.@Tooltip": "DEFAULT: 툴팁 (모드 호환)을 변경하지 않습니다.\nVANILLA: 공격 데미지/속도 값을 실제 값으로 표시하지 않습니다.\nPLAYEREX: 공격 데미지/속도 값을 일반 특성 수정자로 표시합니다.",
4545
"playerex.command.reset": "플레이어 %s 값을 기본값으로 초기화합니다.",
46+
"playerex.command.reset_chunk": "Reset experience negation factor for chunk at %s",
4647
"playerex.command.refund": "스킬 포인트 %s를 플레이어 %s에게 돌려줍니다.",
4748
"playerex.command.refund_alt": "스킬 포인트 1을 플레이어 %s에게 돌려줍니다.",
4849
"playerex.command.levelup": "%s레벨을 플레이어 %s에게 추가합니다.",

src/main/resources/assets/playerex/lang/ru_ru.json

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"text.autoconfig.playerex.option.tooltip": "Подсказки характеристик",
4444
"text.autoconfig.playerex.option.tooltip.@Tooltip": "ПО УМОЛЧАНИЮ: всплывающая подсказка не изменяется (для совместимости с модами).\nVANILLA: исправляет урон/скорость атаки, не отображающие их истинное значение.\nPLAYEREX: отображение урона/скорости атаки в качестве обычных параметров характеристик.",
4545
"playerex.command.reset": "Сбросить характеристики по умолчанию для игрока %s",
46+
"playerex.command.reset_chunk": "Reset experience negation factor for chunk at %s",
4647
"playerex.command.refund": "Вернуть %s очков навыка для игрока %s",
4748
"playerex.command.refund_alt": "Возвращено 1 очко умений для игрока %s",
4849
"playerex.command.levelup": "Добавлено %s уровней для игрока %s",

src/main/resources/assets/playerex/lang/zh_cn.json

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"text.autoconfig.playerex.option.tooltip": "工具提示属性",
4444
"text.autoconfig.playerex.option.tooltip.@Tooltip": "默认:不更改工具提示(为了模组兼容性)。/nVANILLA:修复了攻击伤害/速度显示错误的问题。/nPLAYEREX:攻击伤害/速度显示为常规属性修饰符。",
4545
"playerex.command.reset": "将玩家%s的属性设为默认值。",
46+
"playerex.command.reset_chunk": "Reset experience negation factor for chunk at %s",
4647
"playerex.command.refund": "玩家%2$s获得%1$s回退点。",
4748
"playerex.command.refund_alt": "玩家%2$s获得1回退点。",
4849
"playerex.command.levelup": "玩家%2$s获得%1$s技能点",

0 commit comments

Comments
 (0)