2013-01-15 21:33:00 +01:00
|
|
|
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.Security;
|
|
|
|
import com.Acrobot.ChestShop.Utils.uBlock;
|
2013-01-29 21:02:03 +01:00
|
|
|
import org.bukkit.Location;
|
2018-10-23 20:04:18 +02:00
|
|
|
import org.bukkit.block.Container;
|
2013-01-15 21:33:00 +01:00
|
|
|
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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Acrobot
|
|
|
|
*/
|
|
|
|
public class TerrainChecker implements Listener {
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public static void onPreShopCreation(PreShopCreationEvent event) {
|
|
|
|
Player player = event.getPlayer();
|
|
|
|
|
|
|
|
if (!Security.canPlaceSign(player, event.getSign())) {
|
|
|
|
event.setOutcome(NO_PERMISSION_FOR_TERRAIN);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-23 20:04:18 +02:00
|
|
|
Container connectedContainer = uBlock.findConnectedContainer(event.getSign().getBlock());
|
|
|
|
Location containerLocation = (connectedContainer != null ? connectedContainer.getLocation() : null);
|
2013-01-15 21:33:00 +01:00
|
|
|
|
2018-10-23 20:04:18 +02:00
|
|
|
BuildPermissionEvent bEvent = new BuildPermissionEvent(player, containerLocation, event.getSign().getLocation());
|
2013-01-15 21:33:00 +01:00
|
|
|
ChestShop.callEvent(bEvent);
|
|
|
|
|
|
|
|
if (!bEvent.isAllowed()) {
|
|
|
|
event.setOutcome(NO_PERMISSION_FOR_TERRAIN);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|