Search in sources :

Example 1 with Vector

use of org.bukkit.util.Vector in project TotalFreedomMod by TotalFreedom.

the class Jumppads method onPlayerMove.

@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
    if (mode == JumpPadMode.OFF) {
        return;
    }
    final Player player = event.getPlayer();
    final Block block = event.getTo().getBlock();
    final Vector velocity = player.getVelocity().clone();
    if (mode == JumpPadMode.MADGEEK) {
        Boolean canPush = pushMap.get(player);
        if (canPush == null) {
            canPush = true;
        }
        if (block.getRelative(0, -1, 0).getType() == BLOCK_ID) {
            if (canPush) {
                velocity.multiply(strength + 0.85).multiply(-1.0);
            }
            canPush = false;
        } else {
            canPush = true;
        }
        pushMap.put(player, canPush);
    } else {
        if (block.getRelative(0, -1, 0).getType() == BLOCK_ID) {
            velocity.add(new Vector(0.0, strength, 0.0));
        }
        if (mode == JumpPadMode.NORMAL_AND_SIDEWAYS) {
            if (block.getRelative(1, 0, 0).getType() == BLOCK_ID) {
                velocity.add(new Vector(-DAMPING_COEFFICIENT * strength, 0.0, 0.0));
            }
            if (block.getRelative(-1, 0, 0).getType() == BLOCK_ID) {
                velocity.add(new Vector(DAMPING_COEFFICIENT * strength, 0.0, 0.0));
            }
            if (block.getRelative(0, 0, 1).getType() == BLOCK_ID) {
                velocity.add(new Vector(0.0, 0.0, -DAMPING_COEFFICIENT * strength));
            }
            if (block.getRelative(0, 0, -1).getType() == BLOCK_ID) {
                velocity.add(new Vector(0.0, 0.0, DAMPING_COEFFICIENT * strength));
            }
        }
    }
    if (!player.getVelocity().equals(velocity)) {
        player.setFallDistance(0.0f);
        player.setVelocity(velocity);
    }
}
Also used : Player(org.bukkit.entity.Player) Block(org.bukkit.block.Block) Vector(org.bukkit.util.Vector) EventHandler(org.bukkit.event.EventHandler)

Example 2 with Vector

use of org.bukkit.util.Vector in project TotalFreedomMod by TotalFreedom.

the class Landminer method onPlayerMove.

@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerMove(PlayerMoveEvent event) {
    if (!(ConfigEntry.LANDMINES_ENABLED.getBoolean() && ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())) {
        return;
    }
    final Player player = event.getPlayer();
    final Iterator<Landmine> lit = landmines.iterator();
    while (lit.hasNext()) {
        final Landmine landmine = lit.next();
        final Location location = landmine.location;
        if (location.getBlock().getType() != Material.TNT) {
            lit.remove();
            continue;
        }
        if (landmine.planter.equals(player)) {
            break;
        }
        if (!player.getWorld().equals(location.getWorld())) {
            continue;
        }
        if (!(player.getLocation().distanceSquared(location) <= (landmine.radius * landmine.radius))) {
            break;
        }
        landmine.location.getBlock().setType(Material.AIR);
        final TNTPrimed tnt1 = location.getWorld().spawn(location, TNTPrimed.class);
        tnt1.setFuseTicks(40);
        tnt1.setPassenger(player);
        tnt1.setVelocity(new Vector(0.0, 2.0, 0.0));
        final TNTPrimed tnt2 = location.getWorld().spawn(player.getLocation(), TNTPrimed.class);
        tnt2.setFuseTicks(1);
        player.setGameMode(GameMode.SURVIVAL);
        lit.remove();
    }
}
Also used : Player(org.bukkit.entity.Player) TNTPrimed(org.bukkit.entity.TNTPrimed) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 3 with Vector

use of org.bukkit.util.Vector in project TotalFreedomMod by TotalFreedom.

the class Orbiter method onPlayerMove.

@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerMove(PlayerMoveEvent event) {
    final Player player = event.getPlayer();
    final FPlayer fPlayer = plugin.pl.getPlayer(player);
    if (!fPlayer.isOrbiting()) {
        return;
    }
    if (player.getVelocity().length() < fPlayer.orbitStrength() * (2.0 / 3.0)) {
        player.setVelocity(new Vector(0, fPlayer.orbitStrength(), 0));
    }
}
Also used : FPlayer(me.totalfreedom.totalfreedommod.player.FPlayer) FPlayer(me.totalfreedom.totalfreedommod.player.FPlayer) Player(org.bukkit.entity.Player) Vector(org.bukkit.util.Vector) EventHandler(org.bukkit.event.EventHandler)

Example 4 with Vector

use of org.bukkit.util.Vector in project TotalFreedomMod by TotalFreedom.

the class Command_doom method run.

@Override
public boolean run(final CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
    if (args.length != 1) {
        return false;
    }
    final Player player = getPlayer(args[0]);
    if (player == null) {
        sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
        return true;
    }
    FUtil.adminAction(sender.getName(), "Casting oblivion over " + player.getName(), true);
    FUtil.bcastMsg(player.getName() + " will be completely obliviated!", ChatColor.RED);
    final String ip = player.getAddress().getAddress().getHostAddress().trim();
    // Remove from superadmin
    Admin admin = getAdmin(player);
    if (admin != null) {
        FUtil.adminAction(sender.getName(), "Removing " + player.getName() + " from the superadmin list", true);
        plugin.al.removeAdmin(admin);
    }
    // Remove from whitelist
    player.setWhitelisted(false);
    // Deop
    player.setOp(false);
    // Ban player
    Ban ban = Ban.forPlayer(player, sender);
    ban.setReason("&cFUCKOFF");
    for (String playerIp : plugin.pl.getData(player).getIps()) {
        ban.addIp(playerIp);
    }
    plugin.bm.addBan(ban);
    // Set gamemode to survival
    player.setGameMode(GameMode.SURVIVAL);
    // Clear inventory
    player.closeInventory();
    player.getInventory().clear();
    // Ignite player
    player.setFireTicks(10000);
    // Generate explosion
    player.getWorld().createExplosion(player.getLocation(), 0F, false);
    // Shoot the player in the sky
    player.setVelocity(player.getVelocity().clone().add(new Vector(0, 20, 0)));
    new BukkitRunnable() {

        @Override
        public void run() {
            // strike lightning
            player.getWorld().strikeLightning(player.getLocation());
            // kill (if not done already)
            player.setHealth(0.0);
        }
    }.runTaskLater(plugin, 2L * 20L);
    new BukkitRunnable() {

        @Override
        public void run() {
            // message
            FUtil.adminAction(sender.getName(), "Banning " + player.getName() + ", IP: " + ip, true);
            // generate explosion
            player.getWorld().createExplosion(player.getLocation(), 0F, false);
            // kick player
            player.kickPlayer(ChatColor.RED + "FUCKOFF, and get your shit together!");
        }
    }.runTaskLater(plugin, 3L * 20L);
    return true;
}
Also used : Player(org.bukkit.entity.Player) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Admin(me.totalfreedom.totalfreedommod.admin.Admin) Vector(org.bukkit.util.Vector) Ban(me.totalfreedom.totalfreedommod.banning.Ban)

Example 5 with Vector

use of org.bukkit.util.Vector in project Denizen-For-Bukkit by DenizenScript.

the class ShootCommand method execute.

@SuppressWarnings("unchecked")
@Override
public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {
    dEntity originEntity = (dEntity) scriptEntry.getObject("originEntity");
    dLocation originLocation = scriptEntry.hasObject("originLocation") ? (dLocation) scriptEntry.getObject("originLocation") : new dLocation(originEntity.getEyeLocation().add(originEntity.getEyeLocation().getDirection()));
    boolean no_rotate = scriptEntry.hasObject("no_rotate") && scriptEntry.getElement("no_rotate").asBoolean();
    // If there is no destination set, but there is a shooter, get a point
    // in front of the shooter and set it as the destination
    final dLocation destination = scriptEntry.hasObject("destination") ? (dLocation) scriptEntry.getObject("destination") : (originEntity != null ? new dLocation(originEntity.getEyeLocation().clone().add(originEntity.getEyeLocation().clone().getDirection().multiply(30))) : (originLocation != null ? new dLocation(originLocation.clone().add(originLocation.getDirection().multiply(30))) : null));
    // TODO: Same as PUSH -- is this the place to do this?
    if (destination == null) {
        dB.report(scriptEntry, getName(), "No destination specified!");
        return;
    }
    final List<dEntity> entities = (List<dEntity>) scriptEntry.getObject("entities");
    final dScript script = (dScript) scriptEntry.getObject("script");
    final dList definitions = (dList) scriptEntry.getObject("definitions");
    dEntity shooter = (dEntity) scriptEntry.getObject("shooter");
    Element height = scriptEntry.getElement("height");
    Element gravity = scriptEntry.getElement("gravity");
    Element speed = scriptEntry.getElement("speed");
    Element spread = scriptEntry.getElement("spread");
    dLocation lead = (dLocation) scriptEntry.getObject("lead");
    // Report to dB
    dB.report(scriptEntry, getName(), aH.debugObj("origin", originEntity != null ? originEntity : originLocation) + aH.debugObj("entities", entities.toString()) + destination.debug() + height.debug() + (gravity != null ? gravity.debug() : "") + (speed != null ? speed.debug() : "") + (script != null ? script.debug() : "") + (shooter != null ? shooter.debug() : "") + (spread != null ? spread.debug() : "") + (lead != null ? lead.debug() : "") + (no_rotate ? aH.debugObj("no_rotate", "true") : "") + (definitions != null ? definitions.debug() : ""));
    // Keep a dList of entities that can be called using <entry[name].shot_entities>
    // later in the script queue
    final dList entityList = new dList();
    // Go through all the entities, spawning/teleporting and rotating them
    for (dEntity entity : entities) {
        if (!entity.isSpawned() || !no_rotate) {
            entity.spawnAt(originLocation);
        }
        // Only add to entityList after the entities have been
        // spawned, otherwise you'll get something like "e@skeleton"
        // instead of "e@57" on it
        entityList.add(entity.toString());
        if (!no_rotate) {
            NMSHandler.getInstance().getEntityHelper().faceLocation(entity.getBukkitEntity(), destination);
        }
        // when applicable
        if (entity.isProjectile() && (shooter != null || originEntity != null)) {
            entity.setShooter(shooter != null ? shooter : originEntity);
            // Also, watch for it hitting a target
            arrows.put(entity.getUUID(), null);
        }
    }
    // Add entities to context so that the specific entities created/spawned
    // can be fetched.
    scriptEntry.addObject("shot_entities", entityList);
    if (spread == null) {
        Position.mount(Conversion.convertEntities(entities));
    }
    // Get the entity at the bottom of the entity list, because
    // only its gravity should be affected and tracked considering
    // that the other entities will be mounted on it
    final dEntity lastEntity = entities.get(entities.size() - 1);
    if (gravity == null) {
        gravity = new Element(lastEntity.getEntityType().getGravity());
    }
    if (speed == null) {
        Vector v1 = lastEntity.getLocation().toVector();
        Vector v2 = destination.toVector();
        Vector v3 = Velocity.calculate(v1, v2, gravity.asDouble(), height.asDouble());
        lastEntity.setVelocity(v3);
    } else if (lead == null) {
        Vector relative = destination.clone().subtract(originLocation).toVector();
        lastEntity.setVelocity(relative.normalize().multiply(speed.asDouble()));
    } else {
        double g = 20;
        double v = speed.asDouble();
        Vector relative = destination.clone().subtract(originLocation).toVector();
        double testAng = Velocity.launchAngle(originLocation, destination.toVector(), v, relative.getY(), g);
        double hangTime = Velocity.hangtime(testAng, v, relative.getY(), g);
        Vector to = destination.clone().add(lead.clone().multiply(hangTime)).toVector();
        relative = to.clone().subtract(originLocation.toVector());
        Double dist = Math.sqrt(relative.getX() * relative.getX() + relative.getZ() * relative.getZ());
        if (dist == 0) {
            dist = 0.1d;
        }
        testAng = Velocity.launchAngle(originLocation, to, v, relative.getY(), g);
        relative.setY(Math.tan(testAng) * dist);
        relative = relative.normalize();
        v = v + (1.188 * Math.pow(hangTime, 2));
        relative = relative.multiply(v / 20.0d);
        lastEntity.setVelocity(relative);
    }
    if (spread != null) {
        Vector base = lastEntity.getVelocity().clone();
        float sf = spread.asFloat();
        for (dEntity entity : entities) {
            Vector newvel = Velocity.spread(base, (CoreUtilities.getRandom().nextDouble() > 0.5f ? 1 : -1) * Math.toRadians(CoreUtilities.getRandom().nextDouble() * sf), (CoreUtilities.getRandom().nextDouble() > 0.5f ? 1 : -1) * Math.toRadians(CoreUtilities.getRandom().nextDouble() * sf));
            entity.setVelocity(newvel);
        }
    }
    final dLocation start = new dLocation(lastEntity.getLocation());
    final Vector start_vel = lastEntity.getVelocity();
    // A task used to trigger a script if the entity is no longer
    // being shot, when the script argument is used
    BukkitRunnable task = new BukkitRunnable() {

        boolean flying = true;

        dLocation lastLocation = null;

        Vector lastVelocity = null;

        public void run() {
            // If the entity is no longer spawned, stop the task
            if (!lastEntity.isSpawned()) {
                flying = false;
            } else // the air, stop the task
            if (lastVelocity != null) {
                if (lastVelocity.distance(lastEntity.getBukkitEntity().getVelocity()) < 0.05) {
                    flying = false;
                }
            }
            // are met
            if (!flying) {
                this.cancel();
                if (script != null) {
                    if (lastLocation == null) {
                        lastLocation = start;
                    }
                    if (lastVelocity == null) {
                        lastVelocity = start_vel;
                    }
                    // Build a queue out of the targeted script
                    List<ScriptEntry> entries = script.getContainer().getBaseEntries(scriptEntry.entryData.clone());
                    ScriptQueue queue = InstantQueue.getQueue(ScriptQueue.getNextId(script.getContainer().getName())).addEntries(entries);
                    // Add relevant definitions
                    queue.addDefinition("location", lastLocation.identify());
                    queue.addDefinition("shot_entities", entityList.toString());
                    queue.addDefinition("last_entity", lastEntity.identify());
                    // Handle hit_entities definition
                    dList hitEntities = new dList();
                    for (dEntity entity : entities) {
                        if (arrows.containsKey(entity.getUUID())) {
                            dEntity hit = arrows.get(entity.getUUID());
                            arrows.remove(entity.getUUID());
                            if (hit != null) {
                                hitEntities.add(hit.identify());
                            }
                        }
                    }
                    queue.addDefinition("hit_entities", hitEntities.identify());
                    if (definitions != null) {
                        int x = 1;
                        String[] definition_names = null;
                        try {
                            definition_names = script.getContainer().getString("definitions").split("\\|");
                        } catch (Exception e) {
                        // TODO: less lazy handling
                        }
                        for (String definition : definitions) {
                            String name = definition_names != null && definition_names.length >= x ? definition_names[x - 1].trim() : String.valueOf(x);
                            queue.addDefinition(name, definition);
                            dB.echoDebug(scriptEntry, "Adding definition %" + name + "% as " + definition);
                            x++;
                        }
                    }
                    // Start it!
                    queue.start();
                }
                scriptEntry.setFinished(true);
            } else {
                // Record it's position in case the entity dies
                lastLocation = lastEntity.getLocation();
                lastVelocity = lastEntity.getVelocity();
            }
        }
    };
    task.runTaskTimer(DenizenAPI.getCurrentInstance(), 0, 2);
}
Also used : net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Element(net.aufdemrand.denizencore.objects.Element) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) ScriptEntry(net.aufdemrand.denizencore.scripts.ScriptEntry) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException) CommandExecutionException(net.aufdemrand.denizencore.exceptions.CommandExecutionException) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) net.aufdemrand.denizencore.objects.dScript(net.aufdemrand.denizencore.objects.dScript) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) List(java.util.List) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) Vector(org.bukkit.util.Vector) ScriptQueue(net.aufdemrand.denizencore.scripts.queues.ScriptQueue)

Aggregations

Vector (org.bukkit.util.Vector)614 Location (org.bukkit.Location)224 Entity (org.bukkit.entity.Entity)72 LivingEntity (org.bukkit.entity.LivingEntity)72 Player (org.bukkit.entity.Player)60 Block (org.bukkit.block.Block)52 ArrayList (java.util.ArrayList)45 ItemStack (org.bukkit.inventory.ItemStack)43 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)43 EventHandler (org.bukkit.event.EventHandler)39 Material (org.bukkit.Material)29 List (java.util.List)20 BlockFace (org.bukkit.block.BlockFace)19 World (org.bukkit.World)18 Item (org.bukkit.entity.Item)17 PotionEffect (org.bukkit.potion.PotionEffect)17 BlockVector (org.bukkit.util.BlockVector)17 Test (org.junit.Test)15 HashMap (java.util.HashMap)14 Random (java.util.Random)13