Search in sources :

Example 21 with BuildWorld

use of com.eintosti.buildsystem.object.world.BuildWorld in project BuildSystem by einTosti.

the class WorldManipulateListener method onBlockBreak.

@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockBreak(BlockBreakEvent event) {
    if (event.isCancelled()) {
        return;
    }
    Player player = event.getPlayer();
    BuildWorld buildWorld = worldManager.getBuildWorld(player.getWorld().getName());
    if (buildWorld == null) {
        return;
    }
    if (!manageWorldInteraction(player, event, buildWorld.isBlockBreaking())) {
        setStatus(buildWorld, player);
    }
}
Also used : BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) Player(org.bukkit.entity.Player) EventHandler(org.bukkit.event.EventHandler)

Example 22 with BuildWorld

use of com.eintosti.buildsystem.object.world.BuildWorld in project BuildSystem by einTosti.

the class WorldManipulateListener method onBlockPlace.

@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockPlace(BlockPlaceEvent event) {
    if (event.isCancelled()) {
        return;
    }
    Player player = event.getPlayer();
    BuildWorld buildWorld = worldManager.getBuildWorld(player.getWorld().getName());
    if (buildWorld == null) {
        return;
    }
    if (!manageWorldInteraction(player, event, buildWorld.isBlockPlacement())) {
        setStatus(buildWorld, player);
    }
}
Also used : BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) Player(org.bukkit.entity.Player) EventHandler(org.bukkit.event.EventHandler)

Example 23 with BuildWorld

use of com.eintosti.buildsystem.object.world.BuildWorld in project BuildSystem by einTosti.

the class WorldManipulateListener method onEntityDamageByEntity.

@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
    if (!(event.getDamager() instanceof Player)) {
        return;
    }
    Player player = (Player) event.getDamager();
    BuildWorld buildWorld = worldManager.getBuildWorld(player.getWorld().getName());
    if (buildWorld == null) {
        return;
    }
    if (event.getEntity() instanceof ArmorStand) {
        manageWorldInteraction(player, event, buildWorld.isBlockInteractions());
    }
}
Also used : BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) Player(org.bukkit.entity.Player) ArmorStand(org.bukkit.entity.ArmorStand) EventHandler(org.bukkit.event.EventHandler)

Example 24 with BuildWorld

use of com.eintosti.buildsystem.object.world.BuildWorld in project BuildSystem by einTosti.

the class WorldManipulateListener method manageWorldInteraction.

/**
 * Not every player can always interact with the {@link BuildWorld} they are in.
 * <p>
 * Reasons an interaction could be cancelled:
 * <ul>
 *     <li>The world has its {@link WorldStatus} set to archived;</li>
 *     <li>The world has a setting enabled which disallows certain events;</li>
 *     <li>The world only allows {@link Builder}s to build and the player is not such a builder.</li>
 * </ul>
 * <p>
 * However, a player can override these reasons if:
 * <ul>
 *     <li>The player has the permission {@code buildsystem.admin};</li>
 *     <li>The player has the permission {@code buildsystem.bypass.archive};</li>
 *     <li>The player has used {@code /build} to enter build-mode.</li>
 * </ul>
 *
 * @param player the player who manipulated the world
 * @param event  the event which was called by the world manipulation
 * @return if the event called when the player performs an action was cancelled
 */
private boolean manageWorldInteraction(Player player, Event event, boolean worldSetting) {
    String worldName = player.getWorld().getName();
    BuildWorld buildWorld = worldManager.getBuildWorld(worldName);
    if (buildWorld == null) {
        return false;
    }
    if (disableArchivedWorlds(buildWorld, player, event)) {
        return true;
    }
    if (checkWorldSettings(player, event, worldSetting)) {
        return true;
    }
    if (checkBuilders(buildWorld, player, event)) {
        return true;
    }
    return false;
}
Also used : BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld)

Example 25 with BuildWorld

use of com.eintosti.buildsystem.object.world.BuildWorld in project BuildSystem by einTosti.

the class WorldManipulateListener method onPlayerInteract.

@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerInteract(PlayerInteractEvent event) {
    ItemStack itemStack = event.getItem();
    if (itemStack != null && itemStack.getType() == plugin.getConfigValues().getWorldEditWand().parseMaterial()) {
        return;
    }
    Player player = event.getPlayer();
    BuildWorld buildWorld = worldManager.getBuildWorld(player.getWorld().getName());
    if (buildWorld == null) {
        return;
    }
    manageWorldInteraction(player, event, buildWorld.isBlockInteractions());
    if (!buildWorld.isPhysics() && event.getClickedBlock() != null) {
        if (event.getAction() == Action.PHYSICAL && event.getClickedBlock().getType() == XMaterial.FARMLAND.parseMaterial()) {
            event.setCancelled(true);
        }
    }
}
Also used : BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) Player(org.bukkit.entity.Player) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Aggregations

BuildWorld (com.eintosti.buildsystem.object.world.BuildWorld)143 EventHandler (org.bukkit.event.EventHandler)58 Player (org.bukkit.entity.Player)52 World (org.bukkit.World)40 Block (org.bukkit.block.Block)20 ItemStack (org.bukkit.inventory.ItemStack)18 XMaterial (com.cryptomorin.xseries.XMaterial)16 PlayerChatInput (com.eintosti.buildsystem.util.external.PlayerChatInput)16 UUID (java.util.UUID)14 Location (org.bukkit.Location)14 File (java.io.File)12 ArrayList (java.util.ArrayList)9 BuildSystem (com.eintosti.buildsystem.BuildSystem)6 Builder (com.eintosti.buildsystem.object.world.Builder)6 List (java.util.List)6 Bukkit (org.bukkit.Bukkit)6 Material (org.bukkit.Material)6 ChunkGenerator (org.bukkit.generator.ChunkGenerator)6 Inventory (org.bukkit.inventory.Inventory)6 ItemMeta (org.bukkit.inventory.meta.ItemMeta)6