mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-06-23 12:54:45 +02:00
b853afbd52
This adds separate permissions for accessing, creating and destroying of shops. It also adds a config entry to allow using of a shop even if someone have access to it due to their permissions.
36 lines
1.3 KiB
Java
36 lines
1.3 KiB
Java
package com.Acrobot.ChestShop.Listeners.PreShopCreation;
|
|
|
|
import com.Acrobot.ChestShop.Database.Account;
|
|
import com.Acrobot.ChestShop.Events.PreShopCreationEvent;
|
|
import com.Acrobot.ChestShop.Permission;
|
|
import com.Acrobot.ChestShop.UUIDs.NameManager;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.event.EventHandler;
|
|
import org.bukkit.event.EventPriority;
|
|
import org.bukkit.event.Listener;
|
|
|
|
import static com.Acrobot.ChestShop.Permission.OTHER_NAME_CREATE;
|
|
import static com.Acrobot.ChestShop.Signs.ChestShopSign.NAME_LINE;
|
|
import static com.Acrobot.ChestShop.Events.PreShopCreationEvent.CreationOutcome.UNKNOWN_PLAYER;
|
|
|
|
/**
|
|
* @author Acrobot
|
|
*/
|
|
public class NameChecker implements Listener {
|
|
|
|
@EventHandler(priority = EventPriority.LOWEST)
|
|
public static void onPreShopCreation(PreShopCreationEvent event) {
|
|
String name = event.getSignLine(NAME_LINE);
|
|
Player player = event.getPlayer();
|
|
|
|
if (name.isEmpty() || !NameManager.canUseName(player, OTHER_NAME_CREATE, name)) {
|
|
Account account = NameManager.getAccount(player.getName());
|
|
if (account != null) {
|
|
event.setSignLine(NAME_LINE, account.getShortName());
|
|
} else {
|
|
event.setOutcome(UNKNOWN_PLAYER);
|
|
}
|
|
}
|
|
}
|
|
}
|