Search in sources :

Example 81 with BuildWorld

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

the class PlayerInteractListener method isValid.

/**
 * Not every player can always interact with the {@link BuildWorld} they are in.
 * <p>
 * Reasons an interaction could be cancelled:<br>
 * - The world has its {@link WorldStatus} set to archived<br>
 * - The world has a setting enabled which disallows certain events<br>
 * - The world only allows {@link Builder}s to build and the player is not such a builder<br>
 * <p>
 * However, a player can override these reasons if:<br>
 * - The player has the permission `buildsystem.admin`<br>
 * - The player has the permission `buildsystem.bypass.archive`<br>
 * - The player has used `/build` to enter build-mode<br>
 *
 * @param event the event which was called by the world manipulation
 * @return if the interaction with the world is valid
 */
private boolean isValid(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    if (plugin.canBypass(player)) {
        return true;
    }
    BuildWorld buildWorld = worldManager.getBuildWorld(player.getWorld().getName());
    if (buildWorld == null) {
        return true;
    }
    boolean isInBuildMode = playerManager.getBuildPlayers().contains(player.getUniqueId());
    if (buildWorld.getStatus() == WorldStatus.ARCHIVE && !isInBuildMode) {
        return false;
    }
    if (!buildWorld.isBlockPlacement() && !isInBuildMode) {
        return false;
    }
    if (buildWorld.isBuilders() && !buildWorld.isBuilder(player)) {
        return buildWorld.getCreatorId() == null || buildWorld.getCreatorId().equals(player.getUniqueId());
    }
    return true;
}
Also used : BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) Player(org.bukkit.entity.Player)

Example 82 with BuildWorld

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

the class PlayerJoinListener method onPlayerJoin.

@EventHandler
@SuppressWarnings("deprecation")
public void onPlayerJoin(PlayerJoinEvent event) {
    Player player = event.getPlayer();
    settingsManager.createSettings(player);
    plugin.getSkullCache().cacheSkull(player.getName());
    String worldName = player.getWorld().getName();
    BuildWorld buildWorld = worldManager.getBuildWorld(worldName);
    if (buildWorld != null) {
        if (!buildWorld.isPhysics() && player.hasPermission("buildsystem.physics.message")) {
            player.sendMessage(plugin.getString("physics_deactivated_in_world").replace("%world%", buildWorld.getName()));
        }
        if (configValues.isArchiveVanish() && buildWorld.getStatus() == WorldStatus.ARCHIVE) {
            player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 0, false, false), false);
            Bukkit.getOnlinePlayers().forEach(pl -> pl.hidePlayer(player));
        }
    }
    Settings settings = settingsManager.getSettings(player);
    if (settings.isNoClip()) {
        plugin.getNoClipManager().startNoClip(player);
    }
    if (settings.isScoreboard()) {
        settingsManager.startScoreboard(player);
        plugin.getPlayerManager().forceUpdateSidebar(player);
    }
    if (settings.isSpawnTeleport()) {
        spawnManager.teleport(player);
    }
    if (settings.isClearInventory()) {
        player.getInventory().clear();
    }
    manageHidePlayer(player);
    addJoinItem(player);
    if (player.hasPermission("buildsystem.updates")) {
        performUpdateCheck(player);
    }
}
Also used : BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) Player(org.bukkit.entity.Player) PotionEffect(org.bukkit.potion.PotionEffect) Settings(com.eintosti.buildsystem.object.settings.Settings) EventHandler(org.bukkit.event.EventHandler)

Example 83 with BuildWorld

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

the class RoleCalculator method calculate.

@Override
public void calculate(@NonNull Player player, @NonNull ContextConsumer contextConsumer) {
    BuildWorld buildWorld = worldManager.getBuildWorld(player.getWorld());
    contextConsumer.accept(KEY, Role.matchRole(player, buildWorld).toString());
}
Also used : BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld)

Example 84 with BuildWorld

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

the class PlaceholderApiExpansion method parseBuildWorldPlaceholder.

/**
 * This is the method called when a placeholder with the identifier needed for
 * {@link PlaceholderApiExpansion#parseSettingsPlaceholder(Player, String)} is not found
 * <p>
 * The default layout for a world placeholder is {@code %buildsystem_<value>%}.
 * If a world is not specified by using the format {@code %buildsystem_<value>_<world>%}
 * then the world the player is currently in will be used.
 *
 * @param player     A Player.
 * @param identifier A String containing the identifier/value.
 * @return possibly-null String of the requested identifier.
 */
@Nullable
private String parseBuildWorldPlaceholder(Player player, String identifier) {
    String worldName = player.getWorld().getName();
    if (identifier.matches(".*_.*")) {
        String[] splitString = identifier.split("_");
        worldName = splitString[1];
        identifier = splitString[0];
    }
    BuildWorld buildWorld = worldManager.getBuildWorld(worldName);
    if (buildWorld == null) {
        return "-";
    }
    switch(identifier.toLowerCase()) {
        case "blockbreaking":
            return String.valueOf(buildWorld.isBlockBreaking());
        case "blockplacement":
            return String.valueOf(buildWorld.isBlockPlacement());
        case "builders":
            return buildWorld.getBuildersInfo();
        case "buildersenabled":
            return String.valueOf(buildWorld.isBuilders());
        case "creation":
            return buildWorld.getFormattedCreationDate();
        case "creator":
            return buildWorld.getCreator();
        case "creatorid":
            return String.valueOf(buildWorld.getCreatorId());
        case "explosions":
            return String.valueOf(buildWorld.isExplosions());
        case "loaded":
            return String.valueOf(buildWorld.isLoaded());
        case "material":
            return String.valueOf(buildWorld.getMaterial().parseMaterial());
        case "mobai":
            return String.valueOf(buildWorld.isMobAI());
        case "permission":
            return buildWorld.getPermission();
        case "private":
            return String.valueOf(buildWorld.isPrivate());
        case "project":
            return buildWorld.getProject();
        case "physics":
            return String.valueOf(buildWorld.isPhysics());
        case "spawn":
            return buildWorld.getCustomSpawn();
        case "status":
            return buildWorld.getStatusName();
        case "time":
            return buildWorld.getWorldTime();
        case "type":
            return buildWorld.getTypeName();
        case "world":
            return buildWorld.getName();
        default:
            return null;
    }
}
Also used : BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) Nullable(org.jetbrains.annotations.Nullable)

Example 85 with BuildWorld

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

the class EditInventory method onInventoryClick.

@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
    if (!inventoryManager.checkIfValidClick(event, "worldeditor_title")) {
        return;
    }
    ItemStack itemStack = event.getCurrentItem();
    if (itemStack == null) {
        return;
    }
    Player player = (Player) event.getWhoClicked();
    BuildWorld buildWorld = plugin.getPlayerManager().getSelectedWorld().get(player.getUniqueId());
    if (buildWorld == null) {
        player.closeInventory();
        player.sendMessage(plugin.getString("worlds_edit_error"));
        return;
    }
    switch(event.getSlot()) {
        case 20:
            buildWorld.setBlockBreaking(!buildWorld.isBlockBreaking());
            break;
        case 21:
            buildWorld.setBlockPlacement(!buildWorld.isBlockPlacement());
            break;
        case 22:
            buildWorld.setPhysics(!buildWorld.isPhysics());
            break;
        case 23:
            changeTime(player, buildWorld);
            break;
        case 24:
            buildWorld.setExplosions(!buildWorld.isExplosions());
            break;
        case 29:
            removeEntities(player, buildWorld);
            return;
        case 30:
            if (itemStack.getType() == XMaterial.BARRIER.parseMaterial()) {
                XSound.ENTITY_ITEM_BREAK.play(player);
                return;
            }
            if (event.isRightClick()) {
                XSound.BLOCK_CHEST_OPEN.play(player);
                player.openInventory(plugin.getBuilderInventory().getInventory(buildWorld, player));
                return;
            }
            buildWorld.setBuilders(!buildWorld.isBuilders());
            break;
        case 31:
            buildWorld.setMobAI(!buildWorld.isMobAI());
            break;
        case 32:
            if (itemStack.getType() == XMaterial.BARRIER.parseMaterial()) {
                XSound.ENTITY_ITEM_BREAK.play(player);
                return;
            }
            buildWorld.setPrivate(!buildWorld.isPrivate());
            break;
        case 33:
            buildWorld.setBlockInteractions(!buildWorld.isBlockInteractions());
            break;
        case 38:
            XSound.BLOCK_CHEST_OPEN.play(player);
            plugin.getGameRules().resetInvIndex(player.getUniqueId());
            plugin.getGameRuleInventory().openInventory(player, buildWorld);
            return;
        case 39:
            XSound.ENTITY_CHICKEN_EGG.play(player);
            plugin.getStatusInventory().openInventory(player);
            return;
        case 41:
            XSound.ENTITY_CHICKEN_EGG.play(player);
            plugin.getWorldsCommand().getProjectInput(player, false);
            return;
        case 42:
            XSound.ENTITY_CHICKEN_EGG.play(player);
            plugin.getWorldsCommand().getPermissionInput(player, false);
            return;
        default:
            return;
    }
    XSound.ENTITY_CHICKEN_EGG.play(player);
    openInventory(player, buildWorld);
}
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