Skip to content

Commit

Permalink
fix: update online player username
Browse files Browse the repository at this point in the history
  • Loading branch information
StarWishsama committed Jul 4, 2024
1 parent 759e89b commit fe47722
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,21 @@ public void getPlayerUuidAsync(String pName, IAsyncReadCallback<UUID> callback)
scheduleReadTask(() -> invokeCallback(callback, getPlayerUuid(pName)));
}

public void updateUsername(String uuid, String newName) {
var key = new RecordKey(DataScope.PLAYER_PROFILE);
key.addCondition(FieldKey.PLAYER_UUID, uuid);

var result = getData(key);
if (result.isEmpty()) {
return;
}

var data = new RecordSet();
data.put(FieldKey.PLAYER_NAME, newName);

scheduleWriteTask(new UUIDKey(DataScope.NONE, uuid), key, data, false);
}

private static RecordSet getRecordSet(PlayerBackpack bp) {
var re = new RecordSet();
re.put(FieldKey.PLAYER_UUID, bp.getOwner().getUniqueId().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.armor.RadiationTask;
import javax.annotation.Nonnull;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand All @@ -27,8 +28,16 @@ public JoinListener(@Nonnull Slimefun plugin) {

@EventHandler
public void onJoin(@Nonnull PlayerJoinEvent e) {
PlayerProfile.get(e.getPlayer(), playerProfile -> {
final ItemStack[] armorContents = e.getPlayer().getInventory().getArmorContents();
final var p = e.getPlayer();

PlayerProfile.get(p, playerProfile -> {
if (Bukkit.getOnlineMode()) {
Slimefun.getDatabaseManager()
.getProfileDataController()
.updateUsername(p.getUniqueId().toString(), p.getName());
}

final ItemStack[] armorContents = p.getInventory().getArmorContents();
final HashedArmorpiece[] hashedArmorpieces = playerProfile.getArmor();
for (int i = 0; i < 4; i++) {
final ItemStack armorPiece = armorContents[i];
Expand Down

0 comments on commit fe47722

Please sign in to comment.