ChestShop-3/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/ChestChecker.java
Acrobot a5bfa86bca Mavenized the project
Switched the project to Maven - you're now able to easily build
ChestShop.
2013-03-08 20:31:15 +01:00

50 lines
1.5 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.Chest;
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;
}
Chest connectedChest = uBlock.findConnectedChest(event.getSign().getBlock());
if (connectedChest == null) {
event.setOutcome(NO_CHEST);
return;
}
Player player = event.getPlayer();
if (Permission.has(player, ADMIN)) {
return;
}
if (!Security.canAccess(player, connectedChest.getBlock())) {
event.setOutcome(NO_PERMISSION_FOR_CHEST);
}
}
}