Search in sources :

Example 56 with BuildWorld

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

the class WorldsTabComplete method onTabComplete.

@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) {
    ArrayList<String> arrayList = new ArrayList<>();
    if (!(sender instanceof Player)) {
        return arrayList;
    }
    Player player = (Player) sender;
    switch(args.length) {
        case 1:
            {
                for (Argument argument : Argument.values()) {
                    String command = argument.getCommand();
                    String permission = argument.getPermission();
                    if (permission == null || player.hasPermission(permission)) {
                        addArgument(args[0], command, arrayList);
                    }
                }
                return arrayList;
            }
        case 2:
            {
                switch(args[0].toLowerCase()) {
                    case "builders":
                    case "edit":
                    case "info":
                    case "rename":
                    case "setcreator":
                    case "setitem":
                    case "setpermission":
                    case "setproject":
                    case "setstatus":
                    case "tp":
                    case "unimport":
                        worldManager.getBuildWorlds().stream().filter(world -> player.hasPermission(world.getPermission()) || world.getPermission().equalsIgnoreCase("-")).forEach(world -> addArgument(args[1], world.getName(), arrayList));
                        break;
                    case "addbuilder":
                    case "delete":
                    case "removebuilder":
                        worldManager.getBuildWorlds().stream().filter(world -> world.isCreator(player) || player.hasPermission(BuildSystem.ADMIN_PERMISSION)).forEach(world -> addArgument(args[1], world.getName(), arrayList));
                        break;
                    case "import":
                        String[] directories = Bukkit.getWorldContainer().list((dir, name) -> {
                            for (String charString : name.split("")) {
                                if (charString.matches("[^A-Za-z0-9/_-]")) {
                                    return false;
                                }
                            }
                            File worldFolder = new File(dir, name);
                            if (!worldFolder.isDirectory()) {
                                return false;
                            }
                            File levelFile = new File(dir + File.separator + name + File.separator + "level.dat");
                            if (!levelFile.exists()) {
                                return false;
                            }
                            BuildWorld buildWorld = worldManager.getBuildWorld(name);
                            return buildWorld == null;
                        });
                        if (directories == null || directories.length == 0) {
                            return arrayList;
                        }
                        for (String projectName : directories) {
                            addArgument(args[1], projectName, arrayList);
                        }
                        break;
                }
                return arrayList;
            }
        case 3:
            {
                if (args[0].equalsIgnoreCase("import")) {
                    if (args[1].equalsIgnoreCase(" ")) {
                        return arrayList;
                    }
                    arrayList.add("-g");
                    return arrayList;
                }
            }
        case 4:
            {
                if (!args[2].equalsIgnoreCase("-g")) {
                    return arrayList;
                }
                for (Generator value : new Generator[] { Generator.NORMAL, Generator.FLAT, Generator.VOID }) {
                    addArgument(args[3], value.name(), arrayList);
                }
                return arrayList;
            }
    }
    return arrayList;
}
Also used : CommandSender(org.bukkit.command.CommandSender) BuildSystem(com.eintosti.buildsystem.BuildSystem) TabCompleter(org.bukkit.command.TabCompleter) Player(org.bukkit.entity.Player) File(java.io.File) ArrayList(java.util.ArrayList) List(java.util.List) BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) Generator(com.eintosti.buildsystem.object.world.generator.Generator) Command(org.bukkit.command.Command) WorldManager(com.eintosti.buildsystem.manager.WorldManager) NotNull(org.jetbrains.annotations.NotNull) Bukkit(org.bukkit.Bukkit) BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) File(java.io.File) Generator(com.eintosti.buildsystem.object.world.generator.Generator)

Example 57 with BuildWorld

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

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.getStatus().getName();
        case "time":
            return buildWorld.getWorldTime();
        case "type":
            return buildWorld.getType().getName();
        case "world":
            return buildWorld.getName();
        default:
            return null;
    }
}
Also used : BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) Nullable(org.jetbrains.annotations.Nullable)

Example 58 with BuildWorld

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

the class DeleteInventory method onInventoryClick.

@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
    if (!inventoryManager.checkIfValidClick(event, "delete_title")) {
        return;
    }
    Player player = (Player) event.getWhoClicked();
    BuildWorld buildWorld = plugin.getPlayerManager().getSelectedWorld().get(player.getUniqueId());
    if (buildWorld == null) {
        player.sendMessage(plugin.getString("worlds_delete_error"));
        player.closeInventory();
        return;
    }
    int slot = event.getSlot();
    if (slot == 11) {
        XSound.ENTITY_PLAYER_LEVELUP.play(player);
        player.closeInventory();
        plugin.getWorldManager().deleteWorld(player, buildWorld);
    } else if (slot == 15) {
        XSound.ENTITY_ZOMBIE_BREAK_WOODEN_DOOR.play(player);
        player.closeInventory();
        player.sendMessage(plugin.getString("worlds_delete_canceled").replace("%world%", buildWorld.getName()));
    }
}
Also used : BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) Player(org.bukkit.entity.Player) EventHandler(org.bukkit.event.EventHandler)

Example 59 with BuildWorld

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

the class StatusInventory method onInventoryClick.

@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
    Player player = (Player) event.getWhoClicked();
    String selectedWorldName = playerManager.getSelectedWorldName(player);
    if (selectedWorldName == null) {
        return;
    }
    String title = plugin.getString("status_title").replace("%world%", selectedWorldName);
    if (!event.getView().getTitle().equals(title)) {
        return;
    }
    event.setCancelled(true);
    ItemStack itemStack = event.getCurrentItem();
    if (itemStack == null) {
        return;
    }
    Material itemType = itemStack.getType();
    if (itemType == Material.AIR || !itemStack.hasItemMeta()) {
        return;
    }
    BuildWorld buildWorld = playerManager.getSelectedWorld().get(player.getUniqueId());
    if (buildWorld == null) {
        player.closeInventory();
        player.sendMessage(plugin.getString("worlds_setstatus_error"));
        return;
    }
    switch(event.getSlot()) {
        case 10:
            buildWorld.setStatus(WorldStatus.NOT_STARTED);
            break;
        case 11:
            buildWorld.setStatus(WorldStatus.IN_PROGRESS);
            break;
        case 12:
            buildWorld.setStatus(WorldStatus.ALMOST_FINISHED);
            break;
        case 13:
            buildWorld.setStatus(WorldStatus.FINISHED);
            break;
        case 14:
            buildWorld.setStatus(WorldStatus.ARCHIVE);
            break;
        case 16:
            buildWorld.setStatus(WorldStatus.HIDDEN);
            break;
        default:
            XSound.BLOCK_CHEST_OPEN.play(player);
            plugin.getEditInventory().openInventory(player, buildWorld);
            return;
    }
    playerManager.forceUpdateSidebar(buildWorld);
    player.closeInventory();
    XSound.ENTITY_CHICKEN_EGG.play(player);
    player.sendMessage(plugin.getString("worlds_setstatus_set").replace("%world%", buildWorld.getName()).replace("%status%", buildWorld.getStatus().getName()));
    playerManager.getSelectedWorld().remove(player.getUniqueId());
}
Also used : BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) Player(org.bukkit.entity.Player) XMaterial(com.cryptomorin.xseries.XMaterial) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 60 with BuildWorld

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

the class BlockPhysicsListener method onBlockSpread.

@EventHandler
public void onBlockSpread(BlockSpreadEvent event) {
    Block block = event.getBlock();
    BuildWorld buildWorld = worldManager.getBuildWorld(block.getWorld().getName());
    if (buildWorld != null && !buildWorld.isPhysics()) {
        event.setCancelled(true);
    }
}
Also used : BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) Block(org.bukkit.block.Block) 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