Search in sources :

Example 1 with BuildWorld

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

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 "delete":
                    case "edit":
                    case "info":
                    case "rename":
                    case "setcreator":
                    case "setitem":
                    case "setpermission":
                    case "setproject":
                    case "setstatus":
                    case "tp":
                    case "unimport":
                        worldManager.getBuildWorlds().forEach(world -> {
                            if (player.hasPermission(world.getPermission()) || world.getPermission().equalsIgnoreCase("-")) {
                                String worldName = world.getName();
                                addArgument(args[1], worldName, arrayList);
                            }
                        });
                        break;
                    case "addbuilder":
                    case "removebuilder":
                        worldManager.getBuildWorlds().forEach(world -> {
                            if (player.hasPermission("buildsystem.admin") || (world.getCreatorId() != null && world.getCreatorId().equals(player.getUniqueId()))) {
                                String worldName = world.getName();
                                addArgument(args[1], worldName, 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 }) {
                    String valueName = value.name();
                    addArgument(args[3], valueName, 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 2 with BuildWorld

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

the class PlayerManager method forceUpdateSidebar.

public void forceUpdateSidebar(BuildWorld buildWorld) {
    if (!configValues.isScoreboard()) {
        return;
    }
    World bukkitWorld = Bukkit.getWorld(buildWorld.getName());
    if (bukkitWorld == null) {
        return;
    }
    bukkitWorld.getPlayers().forEach(this::forceUpdateSidebar);
}
Also used : World(org.bukkit.World) BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld)

Example 3 with BuildWorld

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

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.getStatusName()));
    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 4 with BuildWorld

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

the class PlayerChangedWorldListener method checkWorldStatus.

@SuppressWarnings("deprecation")
private void checkWorldStatus(Player player) {
    String worldName = player.getWorld().getName();
    BuildWorld buildWorld = worldManager.getBuildWorld(worldName);
    if (buildWorld == null) {
        return;
    }
    UUID playerUUID = player.getUniqueId();
    PlayerInventory playerInventory = player.getInventory();
    if (this.playerGamemode.containsKey(playerUUID)) {
        player.setGameMode(this.playerGamemode.get(playerUUID));
        this.playerGamemode.remove(playerUUID);
    }
    if (this.playerInventory.containsKey(playerUUID)) {
        playerInventory.clear();
        playerInventory.setContents(this.playerInventory.get(playerUUID));
        this.playerInventory.remove(playerUUID);
    }
    if (this.playerArmor.containsKey(playerUUID)) {
        removeArmorContent(player);
        playerInventory.setArmorContents(this.playerArmor.get(playerUUID));
        this.playerArmor.remove(playerUUID);
    }
    if (buildWorld.getStatus() == WorldStatus.ARCHIVE) {
        this.playerGamemode.put(playerUUID, player.getGameMode());
        this.playerInventory.put(playerUUID, playerInventory.getContents());
        this.playerArmor.put(playerUUID, playerInventory.getArmorContents());
        removeArmorContent(player);
        playerInventory.clear();
        playerInventory.setItem(8, inventoryManager.getItemStack(configValues.getNavigatorItem(), plugin.getString("navigator_item")));
        setSpectatorMode(player);
        if (configValues.isArchiveVanish()) {
            player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 0, false, false), false);
            Bukkit.getOnlinePlayers().forEach(pl -> pl.hidePlayer(player));
        }
    } else {
        playerInventory.setItem(8, inventoryManager.getItemStack(configValues.getNavigatorItem(), plugin.getString("navigator_item")));
        if (player.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
            player.removePotionEffect(PotionEffectType.INVISIBILITY);
        }
        Bukkit.getOnlinePlayers().forEach(pl -> pl.showPlayer(player));
    }
}
Also used : BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) PotionEffect(org.bukkit.potion.PotionEffect) PlayerInventory(org.bukkit.inventory.PlayerInventory) UUID(java.util.UUID)

Example 5 with BuildWorld

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

the class PlayerChangedWorldListener method onPlayerChangedWorld.

@EventHandler
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
    Player player = event.getPlayer();
    String worldName = player.getWorld().getName();
    BuildWorld oldWorld = worldManager.getBuildWorld(event.getFrom().getName());
    if (oldWorld != null && configValues.isUnloadWorlds()) {
        oldWorld.resetUnloadTask();
    }
    BuildWorld newWorld = worldManager.getBuildWorld(worldName);
    if (newWorld != null) {
        if (!newWorld.isPhysics()) {
            if (player.hasPermission("buildsystem.physics.message")) {
                player.sendMessage(plugin.getString("physics_deactivated_in_world").replace("%world%", newWorld.getName()));
            }
        }
    }
    removeOldNavigator(player);
    removeBuildMode(player);
    setGoldBlock(newWorld);
    checkWorldStatus(player);
    if (settingsManager.getSettings(player).isScoreboard()) {
        playerManager.forceUpdateSidebar(player);
    }
}
Also used : BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) Player(org.bukkit.entity.Player) EventHandler(org.bukkit.event.EventHandler)

Aggregations

BuildWorld (com.eintosti.buildsystem.object.world.BuildWorld)71 EventHandler (org.bukkit.event.EventHandler)28 Player (org.bukkit.entity.Player)26 World (org.bukkit.World)19 Block (org.bukkit.block.Block)10 ItemStack (org.bukkit.inventory.ItemStack)9 XMaterial (com.cryptomorin.xseries.XMaterial)8 PlayerChatInput (com.eintosti.buildsystem.util.external.PlayerChatInput)8 UUID (java.util.UUID)7 Location (org.bukkit.Location)7 File (java.io.File)6 ArrayList (java.util.ArrayList)5 BuildSystem (com.eintosti.buildsystem.BuildSystem)3 Builder (com.eintosti.buildsystem.object.world.Builder)3 List (java.util.List)3 Bukkit (org.bukkit.Bukkit)3 Material (org.bukkit.Material)3 XSound (com.cryptomorin.xseries.XSound)2 InventoryManager (com.eintosti.buildsystem.manager.InventoryManager)2 PlayerManager (com.eintosti.buildsystem.manager.PlayerManager)2