Skip to content

Commit

Permalink
fix: xp field resolve not working when cooldown not zero
Browse files Browse the repository at this point in the history
  • Loading branch information
CuukyOfficial committed Nov 5, 2024
1 parent 7626b44 commit b15c43f
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/*
* MIT License
*
*
* Copyright (c) 2020-2022 CuukyOfficial
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -93,11 +93,12 @@ protected void searchXpField(Player player, String humanClassName, String experi
Map<Field, Integer> values = new HashMap<>();
Object craftPlayer = this.getHandle(player);

// Get values of all int fields of player
// Get values of all int fields of player and set to 0
for (Field field : entityHumanClass.getDeclaredFields()) {
if (field.getType() == int.class) {
field.setAccessible(true);
values.put(field, field.getInt(craftPlayer));
field.set(craftPlayer, 0);
}
}

Expand All @@ -117,13 +118,18 @@ protected void searchXpField(Player player, String humanClassName, String experi

// Compare values and use the field with changed value
for (Field field : values.keySet()) {
if (field.getInt(craftPlayer) != values.get(field)) {
if (field.getInt(craftPlayer) != 0) {
this.xpCooldownField = field;
return;
break;
}
}

throw new Error("Unable to find xp cooldown field");
// Restore all previous values
for (Field field : values.keySet())
field.set(craftPlayer, values.get(field));

if (this.xpCooldownField == null)
throw new Error("Unable to find xp cooldown field");
} catch (SecurityException | IllegalAccessException | InvocationTargetException | ClassNotFoundException e) {
throw new Error(e);
}
Expand Down

0 comments on commit b15c43f

Please sign in to comment.