mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-09-25 13:12:51 +02:00
50 lines
1.6 KiB
Java
50 lines
1.6 KiB
Java
package com.Acrobot.ChestShop.Listeners.PreShopCreation;
|
|
|
|
import com.Acrobot.ChestShop.Events.PreShopCreationEvent;
|
|
import com.Acrobot.ChestShop.Permission;
|
|
import com.Acrobot.ChestShop.Security;
|
|
import com.Acrobot.ChestShop.Signs.ChestShopSign;
|
|
import com.Acrobot.ChestShop.Utils.uBlock;
|
|
import org.bukkit.block.Container;
|
|
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.Events.PreShopCreationEvent.CreationOutcome.NO_CHEST;
|
|
import static com.Acrobot.ChestShop.Events.PreShopCreationEvent.CreationOutcome.NO_PERMISSION_FOR_CHEST;
|
|
import static com.Acrobot.ChestShop.Permission.ADMIN;
|
|
import static com.Acrobot.ChestShop.Signs.ChestShopSign.NAME_LINE;
|
|
|
|
/**
|
|
* @author Acrobot
|
|
*/
|
|
public class ChestChecker implements Listener {
|
|
|
|
@EventHandler(priority = EventPriority.LOW)
|
|
public static void onPreShopCreation(PreShopCreationEvent event) {
|
|
String nameLine = event.getSignLine(NAME_LINE);
|
|
|
|
if (ChestShopSign.isAdminShop(nameLine)) {
|
|
return;
|
|
}
|
|
|
|
Container connectedContainer = uBlock.findConnectedContainer(event.getSign().getBlock());
|
|
|
|
if (connectedContainer == null) {
|
|
event.setOutcome(NO_CHEST);
|
|
return;
|
|
}
|
|
|
|
Player player = event.getPlayer();
|
|
|
|
if (Permission.has(player, ADMIN)) {
|
|
return;
|
|
}
|
|
|
|
if (!Security.canAccess(player, connectedContainer.getBlock())) {
|
|
event.setOutcome(NO_PERMISSION_FOR_CHEST);
|
|
}
|
|
}
|
|
}
|