mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-06-29 15:54:44 +02:00
54 lines
1.7 KiB
Java
54 lines
1.7 KiB
Java
|
package com.Acrobot.ChestShop.Listeners.PreShopCreation;
|
||
|
|
||
|
import com.Acrobot.ChestShop.ChestShop;
|
||
|
import com.Acrobot.ChestShop.Events.PreShopCreationEvent;
|
||
|
import com.Acrobot.ChestShop.Events.Protection.BuildPermissionEvent;
|
||
|
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.Chest;
|
||
|
import org.bukkit.entity.Player;
|
||
|
import org.bukkit.event.EventHandler;
|
||
|
import org.bukkit.event.Listener;
|
||
|
|
||
|
import static com.Acrobot.ChestShop.Events.PreShopCreationEvent.CreationOutcome.NO_PERMISSION_FOR_TERRAIN;
|
||
|
import static com.Acrobot.ChestShop.Permission.ADMIN;
|
||
|
import static com.Acrobot.ChestShop.Signs.ChestShopSign.NAME_LINE;
|
||
|
|
||
|
/**
|
||
|
* @author Acrobot
|
||
|
*/
|
||
|
public class TerrainChecker implements Listener {
|
||
|
|
||
|
@EventHandler
|
||
|
public static void onPreShopCreation(PreShopCreationEvent event) {
|
||
|
String nameLine = event.getSignLine(NAME_LINE);
|
||
|
|
||
|
if (ChestShopSign.isAdminShop(nameLine)) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
Player player = event.getPlayer();
|
||
|
|
||
|
if (Permission.has(player, ADMIN)) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (!Security.canPlaceSign(player, event.getSign())) {
|
||
|
event.setOutcome(NO_PERMISSION_FOR_TERRAIN);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
Chest connectedChest = uBlock.findConnectedChest(event.getSign().getBlock());
|
||
|
|
||
|
BuildPermissionEvent bEvent = new BuildPermissionEvent(player, connectedChest.getLocation(), event.getSign().getLocation());
|
||
|
ChestShop.callEvent(bEvent);
|
||
|
|
||
|
if (!bEvent.isAllowed()) {
|
||
|
event.setOutcome(NO_PERMISSION_FOR_TERRAIN);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|