<commit_before>/*
 * Pore
 * Copyright (c) 2014, <NAME> <http://bitbucket.org/mproncace>
 * Copyright (c) 2014, Lapis <https://github.com/LapisBlue>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package net.amigocraft.pore.util;

import net.amigocraft.pore.impl.entity.PoreFireball;
import net.amigocraft.pore.util.converter.vector.VectorConverter;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Egg;
import org.bukkit.entity.EnderPearl;
import org.bukkit.entity.Fireball;
import org.bukkit.entity.Fish;
import org.bukkit.entity.LargeFireball;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.Snowball;
import org.bukkit.entity.ThrownExpBottle;
import org.bukkit.entity.ThrownPotion;
import org.bukkit.util.Vector;
import org.spongepowered.api.entity.projectile.source.ProjectileSource;

import javax.annotation.Nullable;

public class ProjectileUtil {

    @SuppressWarnings("unchecked")
    public static <T extends Projectile> T
    launchProjectile(ProjectileSource source, Class<? extends T> projectile, @Nullable Vector velocity) {
        if (projectile.isAssignableFrom(Arrow.class)) {
            return (T) PoreFireball.of(source.launchProjectile(
                    org.spongepowered.api.entity.projectile.Arrow.class,
                    VectorConverter.create3f(velocity)
            ));
        } else if (projectile.isAssignableFrom(Egg.class)) {
            return (T) PoreFireball.of(source.launchProjectile(
                    org.spongepowered.api.entity.projectile.Egg.class,
                    VectorConverter.create3f(velocity)
            ));
        } else if (projectile.isAssignableFrom(EnderPearl.class)) {
            return (T) PoreFireball.of(source.launchProjectile(
                    org.spongepowered.api.entity.projectile.EnderPearl.class,
                    VectorConverter.create3f(velocity)
            ));
        } else if (projectile.isAssignableFrom(Fireball.class)) {
            if (projectile.isAssignableFrom(LargeFireball.class)) {
                return (T) PoreFireball.of(source.launchProjectile(
                        org.spongepowered.api.entity.projectile.fireball.LargeFireball.class,
                        VectorConverter.create3f(velocity)
                ));
            } else if (projectile.isAssignableFrom(LargeFireball.class)) {
                return (T) PoreFireball.of(source.launchProjectile(
                        org.spongepowered.api.entity.projectile.fireball.SmallFireball.class,
                        VectorConverter.create3f(velocity)
                ));
            } else if (projectile.isAssignableFrom(LargeFireball.class)) {
                return (T) PoreFireball.of(source.launchProjectile(
                        org.spongepowered.api.entity.projectile.fireball.WitherSkull.class,
                        VectorConverter.create3f(velocity)
                ));
            } else {
                return (T) PoreFireball.of(source.launchProjectile(
                        org.spongepowered.api.entity.projectile.fireball.Fireball.class,
                        VectorConverter.create3f(velocity)
                ));
            }
        } else if (projectile.isAssignableFrom(Fish.class)) {
            return (T) PoreFireball.of(source.launchProjectile(
                    org.spongepowered.api.entity.projectile.FishHook.class,
                    VectorConverter.create3f(velocity)
            ));
        } else if (projectile.isAssignableFrom(Snowball.class)) {
            return (T) PoreFireball.of(source.launchProjectile(
                    org.spongepowered.api.entity.projectile.Snowball.class,
                    VectorConverter.create3f(velocity)
            ));
        } else if (projectile.isAssignableFrom(ThrownExpBottle.class)) {
            return (T) PoreFireball.of(source.launchProjectile(
                    org.spongepowered.api.entity.projectile.ThrownExpBottle.class,
                    VectorConverter.create3f(velocity)
            ));
        } else if (projectile.isAssignableFrom(ThrownPotion.class)) {
            return (T) PoreFireball.of(source.launchProjectile(
                    org.spongepowered.api.entity.projectile.ThrownPotion.class,
                    VectorConverter.create3f(velocity)
            ));
        }
        throw new UnsupportedOperationException();
    }

}<commit_msg>Post Sponge ProjectileLaunchEvent upon firing a projectile via Bukkit<commit_after>/*
 * Pore
 * Copyright (c) 2014, <NAME> <http://bitbucket.org/mproncace>
 * Copyright (c) 2014, Lapis <https://github.com/LapisBlue>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package net.amigocraft.pore.util;

import com.google.common.base.Optional;
import net.amigocraft.pore.Pore;
import net.amigocraft.pore.impl.entity.PoreFireball;
import net.amigocraft.pore.impl.entity.PoreProjectile;
import net.amigocraft.pore.util.converter.vector.VectorConverter;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Egg;
import org.bukkit.entity.EnderPearl;
import org.bukkit.entity.Fireball;
import org.bukkit.entity.Fish;
import org.bukkit.entity.LargeFireball;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.Snowball;
import org.bukkit.entity.ThrownExpBottle;
import org.bukkit.entity.ThrownPotion;
import org.bukkit.util.Vector;
import org.spongepowered.api.Game;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.projectile.source.ProjectileSource;
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.event.entity.ProjectileLaunchEvent;
import org.spongepowered.api.util.event.callback.CallbackList;

import javax.annotation.Nullable;

public class ProjectileUtil {

    @SuppressWarnings("unchecked")
    public static <T extends Projectile> T
    launchProjectile(ProjectileSource source, Class<? extends T> projectile, @Nullable Vector velocity) {
        T entity = null;
        if (projectile.isAssignableFrom(Arrow.class)) {
            entity = (T) PoreFireball.of(source.launchProjectile(
                    org.spongepowered.api.entity.projectile.Arrow.class,
                    VectorConverter.create3f(velocity)
            ));
        } else if (projectile.isAssignableFrom(Egg.class)) {
            entity = (T) PoreFireball.of(source.launchProjectile(
                    org.spongepowered.api.entity.projectile.Egg.class,
                    VectorConverter.create3f(velocity)
            ));
        } else if (projectile.isAssignableFrom(EnderPearl.class)) {
            entity = (T) PoreFireball.of(source.launchProjectile(
                    org.spongepowered.api.entity.projectile.EnderPearl.class,
                    VectorConverter.create3f(velocity)
            ));
        } else if (projectile.isAssignableFrom(Fireball.class)) {
            if (projectile.isAssignableFrom(LargeFireball.class)) {
                entity = (T) PoreFireball.of(source.launchProjectile(
                        org.spongepowered.api.entity.projectile.fireball.LargeFireball.class,
                        VectorConverter.create3f(velocity)
                ));
            } else if (projectile.isAssignableFrom(LargeFireball.class)) {
                entity = (T) PoreFireball.of(source.launchProjectile(
                        org.spongepowered.api.entity.projectile.fireball.SmallFireball.class,
                        VectorConverter.create3f(velocity)
                ));
            } else if (projectile.isAssignableFrom(LargeFireball.class)) {
                entity = (T) PoreFireball.of(source.launchProjectile(
                        org.spongepowered.api.entity.projectile.fireball.WitherSkull.class,
                        VectorConverter.create3f(velocity)
                ));
            } else {
                entity = (T) PoreFireball.of(source.launchProjectile(
                        org.spongepowered.api.entity.projectile.fireball.Fireball.class,
                        VectorConverter.create3f(velocity)
                ));
            }
        } else if (projectile.isAssignableFrom(Fish.class)) {
            entity = (T) PoreFireball.of(source.launchProjectile(
                    org.spongepowered.api.entity.projectile.FishHook.class,
                    VectorConverter.create3f(velocity)
            ));
        } else if (projectile.isAssignableFrom(Snowball.class)) {
            entity = (T) PoreFireball.of(source.launchProjectile(
                    org.spongepowered.api.entity.projectile.Snowball.class,
                    VectorConverter.create3f(velocity)
            ));
        } else if (projectile.isAssignableFrom(ThrownExpBottle.class)) {
            entity = (T) PoreFireball.of(source.launchProjectile(
                    org.spongepowered.api.entity.projectile.ThrownExpBottle.class,
                    VectorConverter.create3f(velocity)
            ));
        } else if (projectile.isAssignableFrom(ThrownPotion.class)) {
            entity = (T) PoreFireball.of(source.launchProjectile(
                    org.spongepowered.api.entity.projectile.ThrownPotion.class,
                    VectorConverter.create3f(velocity)
            ));
        }
        if (entity == null) throw new UnsupportedOperationException();
        final T finalEntity = entity;
        Pore.getGame().getEventManager().post(new ProjectileLaunchEvent() {
            @Override
            public Optional<Cause> getCause() {
                return Optional.of(null); //TODO: cause
            }

            @Override
            public Entity getEntity() {
                return ((PoreProjectile)finalEntity).getHandle(); //TODO: verify this cast is safe
            }

            @Override
            public Game getGame() {
                return Pore.getGame();
            }

            @Override
            public CallbackList getCallbacks() {
                return null; //TODO: not sure exactly of what to return here
            }
        });
        return entity;
    }

}
{'fraction_non_alphanumeric': 0.09006986027944112, 'fraction_numerical': 0.003160345974717232, 'mean_word_length': 2.4936083672283558, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6958357', 'n_tokens_mistral': 3431, 'n_tokens_neox': 3212, 'n_words': 709}