Skip to content

Commit

Permalink
Added PlayerReplaceEvent for when players changing their uuids
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed May 28, 2022
1 parent ad08238 commit 4289271
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
@@ -0,0 +1,53 @@
package com.bgsoftware.superiorskyblock.api.events;

import com.bgsoftware.superiorskyblock.api.wrappers.SuperiorPlayer;
import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;

/**
* PlayerReplaceEvent is called when a player changes his uuid and replaced with another one.
*/
public class PlayerReplaceEvent extends Event {

private static final HandlerList handlers = new HandlerList();

private final SuperiorPlayer oldPlayer;
private final SuperiorPlayer newPlayer;

/**
* The constructor of the event.
*
* @param oldPlayer The old player that had his UUID changed.
* @param newPlayer The new player that has the new UUID.
*/
public PlayerReplaceEvent(SuperiorPlayer oldPlayer, SuperiorPlayer newPlayer) {
super(!Bukkit.isPrimaryThread());
this.oldPlayer = oldPlayer;
this.newPlayer = newPlayer;
}

/**
* Get the old player that had his UUID changed.
*/
public SuperiorPlayer getOldPlayer() {
return oldPlayer;
}

/**
* Get the new player that has the new UUID.
*/
public SuperiorPlayer getNewPlayer() {
return newPlayer;
}

@Override
public HandlerList getHandlers() {
return handlers;
}

public static HandlerList getHandlerList() {
return handlers;
}

}
Expand Up @@ -151,6 +151,8 @@ public void replacePlayers(SuperiorPlayer originPlayer, SuperiorPlayer newPlayer

for (Island island : plugin.getGrid().getIslands())
island.replacePlayers(originPlayer, newPlayer);

plugin.getEventsBus().callPlayerReplaceEvent(originPlayer, newPlayer);
}

// Updating last time status
Expand Down
Expand Up @@ -91,6 +91,7 @@
import com.bgsoftware.superiorskyblock.api.events.PlayerChangeRoleEvent;
import com.bgsoftware.superiorskyblock.api.events.PlayerCloseMenuEvent;
import com.bgsoftware.superiorskyblock.api.events.PlayerOpenMenuEvent;
import com.bgsoftware.superiorskyblock.api.events.PlayerReplaceEvent;
import com.bgsoftware.superiorskyblock.api.events.PlayerToggleBlocksStackerEvent;
import com.bgsoftware.superiorskyblock.api.events.PlayerToggleBorderEvent;
import com.bgsoftware.superiorskyblock.api.events.PlayerTogglePanelEvent;
Expand Down Expand Up @@ -667,6 +668,12 @@ public boolean callPlayerOpenMenuEvent(SuperiorPlayer superiorPlayer, ISuperiorM
return callEvent(() -> new PlayerOpenMenuEvent(superiorPlayer, superiorMenu), "playeropenmenuevent");
}

public void callPlayerReplaceEvent(SuperiorPlayer oldPlayer, SuperiorPlayer newPlayer) {
if (!plugin.getSettings().getDisabledEvents().contains("playerreplaceevent")) {
callEvent(new PlayerReplaceEvent(oldPlayer, newPlayer));
}
}

public boolean callPlayerToggleBlocksStackerEvent(SuperiorPlayer superiorPlayer) {
return callEvent(() -> new PlayerToggleBlocksStackerEvent(superiorPlayer), "playertoggleblocksstackerevent");
}
Expand Down

0 comments on commit 4289271

Please sign in to comment.