forked from ChestShop-authors/ChestShop-3
-
Notifications
You must be signed in to change notification settings - Fork 2
/
NameChecker.java
34 lines (25 loc) · 1.06 KB
/
NameChecker.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package com.Acrobot.ChestShop.Listeners.PreShopCreation;
import java.util.UUID;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import com.Acrobot.ChestShop.Permission;
import com.Acrobot.ChestShop.Events.PreShopCreationEvent;
import com.Acrobot.ChestShop.UUIDs.NameManager;
/**
* @author Acrobot
*/
public class NameChecker implements Listener {
@EventHandler(priority = EventPriority.LOWEST)
public static void onPreShopCreation(PreShopCreationEvent event) {
String name = event.getOwnerName();
Player player = event.getPlayer();
UUID uuidForFullName = name.isBlank() ? player.getUniqueId() : NameManager.getUUIDFor(name);
if (!uuidForFullName.equals(player.getUniqueId()) && Permission.has(player, Permission.ADMIN)) {
name = NameManager.getFullNameFor(uuidForFullName);
} else
name = NameManager.getNameFor(player);
event.setOwnerName(name.substring(0, Math.min(name.length(), 15)));
}
}