Example usage for java.util List of

List of usage examples for java.util List of

Introduction

In this page you can find the example usage for java.util List of.

Prototype

@SafeVarargs
@SuppressWarnings("varargs")
static <E> List<E> of(E... elements) 

Source Link

Document

Returns an unmodifiable list containing an arbitrary number of elements.

Usage

From source file:com.clxcommunications.xms.api.TagsTest.java

@Property
public void canIterateOverTags(List<String> tags) throws Exception {
    for (String t : Tags.of(tags)) {
        assertThat(t, is(tags.remove(0)));
    }/*from   w ww.ja  v  a2  s  .  c o  m*/
}

From source file:eu.matejkormuth.rpgdavid.starving.listeners.HiddenCommandsListener.java

@EventHandler
private void onCommand(final PlayerCommandPreprocessEvent event) {
    // Command for listing all items.
    if (event.getMessage().equalsIgnoreCase("/items")) {
        List<Item> items = Starving.getInstance().getItemManager().getItems();
        for (int j = 0; j < items.size(); j++) {
            Item i = items.get(j);//from w  w w. j a v  a  2s  .c om
            event.getPlayer().sendMessage(j + " - " + i.getName());
        }
    }
    // Command for giving custom items.
    else if (event.getMessage().contains("/itemsgive")) {
        List<Item> items = Starving.getInstance().getItemManager().getItems();
        for (int j = 0; j < items.size(); j++) {
            Item i = items.get(j);
            if (j == Integer.valueOf(event.getMessage().split(Pattern.quote(" "))[1])) {
                event.getPlayer().getInventory().addItem(i.toItemStack());
            }

        }
    }
    // Command for giving custom chemicals.
    else if (event.getMessage().contains("/chemical")) {
        if (!event.getMessage().contains(" ")) {
            event.getPlayer().sendMessage("args missing!");
        }

        String args = event.getMessage().split(Pattern.quote(" "))[1];
        String[] chemicals = args.split(Pattern.quote(","));

        ChemicalItem ci = new ChemicalItem("spawnedChemicalItem", new ChemicalCompound()) {
            @Override
            public Recipe getRecipe() {
                return null;
            }

            @Override
            protected void onConsume0(Player player) {
            }
        };

        for (String chemical : chemicals) {
            String[] parts = chemical.split(Pattern.quote(":"));
            String name = parts[0];
            String amount = parts[1];
            for (Chemical ch : Chemicals.all()) {
                if (ch.getName().equalsIgnoreCase(name)) {
                    ci.getContents().add(ch, Float.valueOf(amount));
                }
            }
        }

        event.getPlayer().getInventory().addItem(ci.toItemStack());
    }
    // Command for setting entities target.
    else if (event.getMessage().contains("/settarget")) {
        String[] parts = event.getMessage().split(" ");
        int entity = Integer.valueOf(parts[1]);
        int target = Integer.valueOf(parts[2]);
        for (Entity e : Worlds.first().getEntities()) {
            if (e.getEntityId() == target) {
                Starving.getInstance().getZombieManager().get(entity).setFollowTarget(e);
            }
        }
    }
    // Command for spawning zombie walking the dog.
    else if (event.getMessage().contains("/zombieeaster")) {
        ZombieWithDog.spawn(event.getPlayer().getLocation());
    }
    // Command for settings time.
    else if (event.getMessage().contains("/time set")) {
        String[] parts = event.getMessage().split(" ");
        int time = Integer.valueOf(parts[2]);
        event.getPlayer().sendMessage(ChatColor.YELLOW + "[Starving] Shifting time...");
        Starving.getInstance().getRegistered(TimeUpdater.class).vanllaSetMoveTime(time);
        event.getPlayer().sendMessage(ChatColor.GREEN + "[Starving] Time set!");
    }
    // Command for spawning zombie.
    else if (event.getMessage().contains("/zombie")) {
        String[] parts = event.getMessage().split(" ");
        if (parts.length == 2) {
            int count = Integer.valueOf(parts[1]);

            for (int i = 0; i < count; i++) {
                Starving.getInstance().getZombieManager().spawnAt(event.getPlayer().getLocation()
                        .add((Math.random() - 0.5) * count / 4, 0, (Math.random() - 0.5) * count / 4));
            }
        } else {
            Starving.getInstance().getZombieManager().spawnAt(event.getPlayer().getLocation());
        }
    }
    // Command for testing some random things.
    else if (event.getMessage().contains("/darkness")) {
        ((CraftPlayer) event.getPlayer()).getHandle().playerConnection
                .sendPacket(new PacketPlayOutGameStateChange(7, 0.001f));
        ((CraftPlayer) event.getPlayer()).getHandle().playerConnection
                .sendPacket(new PacketPlayOutGameStateChange(8, 160));
    }
    // Command for testing some random things.
    else if (event.getMessage().contains("/npctest")) {
        String name = "debilko" + (int) Math.floor(Math.random() * 1000000);
        NPC npc = Starving.getInstance().getNPCManager().getMainRegistry().createPlayer()
                .withProfile(UUID.nameUUIDFromBytes(name.getBytes()), name)
                .withSpawnLocation(event.getPlayer().getLocation()).spawn();

        event.getPlayer().teleport(npc.getLocation());
    }
    // Command for generating access key.
    else if (event.getMessage().contains("/genkey")) {
        char[] VALID_CHARS = "0123456789abcdefghijklmnopqrstuvwxyz".toCharArray();
        int keyLength = 32;
        char[] key = new char[keyLength];
        for (int i = 0; i < keyLength; i++) {
            key[i] = VALID_CHARS[RandomUtils.nextInt(VALID_CHARS.length - 1)];
        }
        event.getPlayer().sendMessage("Your new accesskey is: " + new String(key));
        Data.of(event.getPlayer()).setRemoteAccesKey(new String(key));
        event.getPlayer().sendMessage("http://starving.eu/key.php?key=" + new String(key));
    }
    // Command for opening custom items inventory.
    else if (event.getMessage().contains("/itemsinv")) {
        ItemManager im = Starving.getInstance().getItemManager();
        int size = (im.getItems().size() / 9);
        Inventory inv = Bukkit.createInventory(null, 9 * (size + 1), ChatColor.GOLD + "Custom items: ");
        List<Item> sorted = im.getItems();
        Collections.sort(sorted, new ItemNameComparator());
        for (Item i : sorted) {
            inv.addItem(i.toItemStack());
        }
        event.getPlayer().openInventory(inv);
    }
    // Command for testing some random things.
    else if (event.getMessage().contains("/itemdropvehicle")) {
        org.bukkit.entity.Item i = ItemDrops.drop(event.getPlayer().getLocation(), Items.of(Material.APPLE));
        i.setVelocity(event.getPlayer().getEyeLocation().getDirection().multiply(3));
        i.setPassenger(event.getPlayer());
        i.setPickupDelay(20 * 15);
    }
    // Command for testing some random things.
    else if (event.getMessage().contains("/peadd")) {
        // FIXME: Please, remove this soon. Only for testing.
        ParticleEmitter pe = new ParticleEmitter(new Location(Bukkit.getWorld("Beta"), 571.5, 68, -235.5), 1f,
                40, ParticleEffect.SMOKE_LARGE);
        pe.setOffsets(0.5f, 0.1f, 0.5f);
        pe.setDirection(new Vector(0.1f, 0, 0.15f));
        Starving.getInstance().getParticleEmmiters().add(pe);
        ParticleEmitter pe2 = new ParticleEmitter(new Location(Bukkit.getWorld("Beta"), 571.5, 68, -235.5), 1f,
                80, ParticleEffect.REDSTONE);
        pe2.setOffsets(0.5f, 0.1f, 0.5f);
        pe2.setColor(new ParticleEffect.OrdinaryColor(255, 0, 255));
        //pe2.setDirection(new Vector(0.1f, 0, 0.15f));
        Starving.getInstance().getParticleEmmiters().add(pe2);
    }
    // Command for testing some random things.
    else if (event.getMessage().contains("/peclear")) {
        Starving.getInstance().getParticleEmmiters().clear();
    }
    // Command for testing some random things.
    else if (event.getMessage().contains("/ason")) {
        Starving.getInstance().getAmbientSoundManager().addPlayer(event.getPlayer());
    }
    // Command for testing some random things.
    else if (event.getMessage().contains("/asoff")) {
        Starving.getInstance().getAmbientSoundManager().removePlayer(event.getPlayer());
    }
}

From source file:org.diorite.config.ConfigTest.java

@Test
public void test() throws Exception {
    SerializationTest.prepareSerialization();
    ToStringBuilder.setDefaultStyle(ToStringStyle.SHORT_PREFIX_STYLE);

    ConfigTemplate<SomeConfig> configTemplate = this.configManager.getConfigFile(SomeConfig.class);
    Assert.assertNotNull(configTemplate);
    Assert.assertEquals(SomeConfig.class.getSimpleName(), configTemplate.getName());
    Assert.assertEquals(StandardCharsets.UTF_8, configTemplate.getDefaultDecoder().charset());
    Assert.assertEquals(StandardCharsets.UTF_8, configTemplate.getDefaultEncoder().charset());

    System.out.println("[ConfigTest] creating config instance.");
    SomeConfig someConfig = configTemplate.create();
    Assert.assertNotNull(someConfig);//  ww w .j  a va  2s  .  com

    this.testNicknames(someConfig);
    Assert.assertNotNull(someConfig.getSpecialData());
    someConfig.setStorage(SerializationTest.prepareObject());

    someConfig.save(System.out);

    try {
        someConfig.getSpecialData().clear();
        Assert.assertTrue("This should never happen, special data should be immutable.", false);
    } catch (UnsupportedOperationException e) {
    }
    MetaObject snowflake = new MetaObject("snowflake", new MetaValue("so special", 25));
    someConfig.putInSpecialData(snowflake);
    Assert.assertEquals(List.of(snowflake), someConfig.getSpecialData());

    UUID randomUUID = UUID.randomUUID();
    someConfig.putInEvenMoreSpecialData(randomUUID, snowflake);
    Assert.assertEquals(1, someConfig.getEvenMoreSpecialData().size());

    System.out.println("\n====================\n");
    someConfig.save(System.out);

    Assert.assertEquals(snowflake, someConfig.removeFromEvenMoreSpecialData(randomUUID));
    Assert.assertTrue(someConfig.getEvenMoreSpecialData().isEmpty());

    // check if all data is still valid after reload of config.
    StringBuilderWriter writer = new StringBuilderWriter(500);
    someConfig.save(writer);
    Assert.assertEquals(someConfig, configTemplate.load(new StringReader(writer.toString())));
}

From source file:org.diorite.config.ConfigTestNoSpecial.java

@Test
public void test() throws Exception {
    SerializationTest.prepareSerialization();
    ToStringBuilder.setDefaultStyle(ToStringStyle.SHORT_PREFIX_STYLE);

    ConfigTemplate<SomeConfigNoSpecial> configTemplate = this.configManager
            .getConfigFile(SomeConfigNoSpecial.class);
    Assert.assertNotNull(configTemplate);
    Assert.assertEquals(SomeConfigNoSpecial.class.getSimpleName(), configTemplate.getName());
    Assert.assertEquals(StandardCharsets.UTF_8, configTemplate.getDefaultDecoder().charset());
    Assert.assertEquals(StandardCharsets.UTF_8, configTemplate.getDefaultEncoder().charset());

    System.out.println("[ConfigTest] creating config instance.");
    SomeConfigNoSpecial someConfig = configTemplate.create();
    Assert.assertNotNull(someConfig);//from ww w  . j a v a 2  s .  c om

    this.testNicknames(someConfig);
    Assert.assertNotNull(someConfig.getSpecialData());
    someConfig.setStorage(SerializationTest.prepareObject());

    someConfig.save(System.out);

    try {
        someConfig.getSpecialData().clear();
        Assert.assertTrue("This should never happen, special data should be immutable.", false);
    } catch (UnsupportedOperationException e) {
    }
    MetaObject snowflake = new MetaObject("snowflake", new MetaValue("so special", 25));
    someConfig.putInSpecialData(snowflake);
    Assert.assertEquals(List.of(snowflake), someConfig.getSpecialData());

    UUID randomUUID = UUID.randomUUID();
    someConfig.putInEvenMoreSpecialData(randomUUID, snowflake);
    Assert.assertEquals(1, someConfig.getEvenMoreSpecialData().size());

    System.out.println("\n====================\n");
    someConfig.save(System.out);

    Assert.assertEquals(snowflake, someConfig.removeFromEvenMoreSpecialData(randomUUID));
    Assert.assertTrue(someConfig.getEvenMoreSpecialData().isEmpty());

    // check if all data is still valid after reload of config.
    StringBuilderWriter writer = new StringBuilderWriter(500);
    someConfig.save(writer);
    Assert.assertEquals(someConfig, configTemplate.load(new StringReader(writer.toString())));
}

From source file:org.diorite.config.impl.actions.AbstractPropertyAction.java

protected AbstractPropertyAction(String name, @RegEx String... strPatterns) {
    this.name = name;
    Pattern[] patterns = new Pattern[strPatterns.length];
    for (int i = 0; i < strPatterns.length; i++) {
        patterns[i] = Pattern.compile("^" + strPatterns[i] + "$");
    }/*from  w  w w . j  a v a 2  s.  c  o  m*/
    this.patterns = List.of(patterns);
}

From source file:org.diorite.config.impl.actions.AbstractPropertyAction.java

protected AbstractPropertyAction(String name, Pattern... patterns) {
    this.name = name;
    this.patterns = List.of(patterns);
}