Search in sources :

Example 1 with Vehicle

use of org.bukkit.entity.Vehicle in project Minigames by AddstarMC.

the class PlayerData method quitMinigame.

public void quitMinigame(MinigamePlayer player, boolean forced) {
    Minigame minigame = player.getMinigame();
    boolean isWinner = false;
    if (GameOverModule.getMinigameModule(minigame).getWinners().contains(player))
        isWinner = true;
    QuitMinigameEvent event = new QuitMinigameEvent(player, minigame, forced, isWinner);
    Bukkit.getServer().getPluginManager().callEvent(event);
    if (!event.isCancelled()) {
        if (!minigame.isSpectator(player)) {
            if (player.getEndTime() == 0)
                player.setEndTime(System.currentTimeMillis());
            if (isWinner)
                GameOverModule.getMinigameModule(minigame).getWinners().remove(player);
            else
                GameOverModule.getMinigameModule(minigame).getLosers().remove(player);
            if (!isWinner) {
                if (!minigame.canSaveCheckpoint() && minigame.isEnabled()) {
                    StoredGameStats saveData = new StoredGameStats(minigame, player);
                    saveData.addStat(MinigameStats.Attempts, 1);
                    for (DynamicMinigameStat stat : MinigameStats.getDynamicStats()) {
                        if (stat.doesApply(minigame, player, false)) {
                            saveData.addStat(stat, stat.getValue(minigame, player, false));
                        }
                    }
                    saveData.applySettings(minigame.getStatSettings(saveData));
                    plugin.queueStatSave(saveData, false);
                }
            }
            //Call Types quit.
            mdata.minigameType(minigame.getType()).quitMinigame(player, minigame, forced);
            //Call Mechanic quit.
            minigame.getMechanic().quitMinigame(minigame, player, forced);
            //Prepare player for quit
            if (player.getPlayer().getVehicle() != null) {
                Vehicle vehicle = (Vehicle) player.getPlayer().getVehicle();
                vehicle.eject();
            }
            player.getPlayer().closeInventory();
            if (player.getLoadout() != null) {
                player.getLoadout().removeLoadout(player);
            }
            player.removeMinigame();
            minigame.removePlayer(player);
            for (PotionEffect potion : player.getPlayer().getActivePotionEffects()) {
                player.getPlayer().removePotionEffect(potion.getType());
            }
            player.getPlayer().setFallDistance(0);
            player.getPlayer().setNoDamageTicks(60);
            final MinigamePlayer fplayer = player;
            Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

                @Override
                public void run() {
                    fplayer.getPlayer().setFireTicks(0);
                }
            });
            player.resetAllStats();
            if (!player.isDead()) {
                player.restorePlayerData();
                if (!isWinner)
                    player.teleport(minigame.getQuitPosition());
                else
                    player.teleport(minigame.getEndPosition());
            } else {
                if (!isWinner)
                    player.setQuitPos(minigame.getQuitPosition());
                else
                    player.setQuitPos(minigame.getEndPosition());
                player.setRequiredQuit(true);
            }
            //Reward Player
            if (isWinner) {
                player.claimTempRewardItems();
            }
            player.claimRewards();
            //Reset Minigame
            if (minigame.getPlayers().size() == 0) {
                if (minigame.getMinigameTimer() != null) {
                    minigame.getMinigameTimer().stopTimer();
                    minigame.setMinigameTimer(null);
                }
                if (minigame.getFloorDegenerator() != null) {
                    minigame.getFloorDegenerator().stopDegenerator();
                }
                minigame.setState(MinigameState.IDLE);
                if (minigame.getBlockRecorder().hasData()) {
                    minigame.getBlockRecorder().restoreBlocks();
                    minigame.getBlockRecorder().restoreEntities();
                    minigame.getBlockRecorder().setCreatedRegenBlocks(false);
                }
                if (minigame.getMpTimer() != null) {
                    minigame.getMpTimer().pauseTimer();
                    minigame.getMpTimer().removeTimer();
                    minigame.setMpTimer(null);
                }
                if (minigame.getMpBets() != null) {
                    minigame.setMpBets(null);
                }
                mdata.clearClaimedScore(minigame);
                WeatherTimeModule.getMinigameModule(minigame).stopTimeLoop();
                GameOverModule.getMinigameModule(minigame).stopEndGameTimer();
                for (Team team : TeamsModule.getMinigameModule(minigame).getTeams()) {
                    team.setScore(0);
                }
            }
            minigame.getScoreboardManager().resetScores(player.getName());
            for (MinigamePlayer pl : minigame.getSpectators()) {
                player.getPlayer().showPlayer(pl.getPlayer());
            }
            if (minigame.getPlayers().size() == 0 && !minigame.isRegenerating()) {
                HandlerList.unregisterAll(minigame.getBlockRecorder());
            }
            //Send out messages
            if (!forced) {
                mdata.sendMinigameMessage(minigame, MinigameUtils.formStr("player.quit.plyMsg", player.getName(), minigame.getName(true)), "error", player);
            }
            plugin.getLogger().info(player.getName() + " quit " + minigame);
            player.updateInventory();
        } else {
            if (player.getPlayer().getVehicle() != null) {
                Vehicle vehicle = (Vehicle) player.getPlayer().getVehicle();
                vehicle.eject();
            }
            player.getPlayer().setFallDistance(0);
            player.getPlayer().setNoDamageTicks(60);
            final Player fplayer = player.getPlayer();
            for (PotionEffect potion : player.getPlayer().getActivePotionEffects()) {
                player.getPlayer().removePotionEffect(potion.getType());
            }
            Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

                @Override
                public void run() {
                    fplayer.setFireTicks(0);
                }
            });
            player.getPlayer().closeInventory();
            if (!player.isDead()) {
                player.restorePlayerData();
            }
            player.teleport(minigame.getQuitPosition());
            player.removeMinigame();
            minigame.removeSpectator(player);
            for (MinigamePlayer pl : minigame.getPlayers()) {
                pl.getPlayer().showPlayer(player.getPlayer());
            }
            player.sendMessage(MinigameUtils.formStr("player.spectate.quit.plyMsg", minigame.getName(true)), "error");
            mdata.sendMinigameMessage(minigame, MinigameUtils.formStr("player.spectate.quit.minigameMsg", player.getName(), minigame.getName(true)), "error", player);
        }
        if (player.getPlayer().getGameMode() != GameMode.CREATIVE)
            player.setCanFly(false);
        if (!forced) {
            minigame.getScoreboardData().reload();
        }
    }
}
Also used : Vehicle(org.bukkit.entity.Vehicle) QuitMinigameEvent(au.com.mineauz.minigames.events.QuitMinigameEvent) Player(org.bukkit.entity.Player) StoredGameStats(au.com.mineauz.minigames.stats.StoredGameStats) PotionEffect(org.bukkit.potion.PotionEffect) Team(au.com.mineauz.minigames.minigame.Team) Minigame(au.com.mineauz.minigames.minigame.Minigame) DynamicMinigameStat(au.com.mineauz.minigames.stats.DynamicMinigameStat)

Example 2 with Vehicle

use of org.bukkit.entity.Vehicle in project Denizen-For-Bukkit by DenizenScript.

the class BukkitScriptEvent method tryEntity.

public boolean tryEntity(dEntity entity, String comparedto) {
    if (comparedto == null || comparedto.isEmpty() || entity == null) {
        return false;
    }
    Entity bEntity = entity.getBukkitEntity();
    comparedto = CoreUtilities.toLowerCase(comparedto);
    if (comparedto.equals("entity")) {
        return true;
    } else if (comparedto.equals("npc")) {
        return entity.isCitizensNPC();
    } else if (comparedto.equals("player")) {
        return entity.isPlayer();
    } else if (comparedto.equals("vehicle")) {
        return bEntity instanceof Vehicle;
    } else if (comparedto.equals("projectile")) {
        return bEntity instanceof Projectile;
    } else if (comparedto.equals("hanging")) {
        return bEntity instanceof Hanging;
    } else if (entity.getEntityScript() != null && comparedto.equals(CoreUtilities.toLowerCase(entity.getEntityScript()))) {
        return true;
    } else if (comparedto.equals(entity.getEntityType().getLowercaseName())) {
        return true;
    }
    return false;
}
Also used : Vehicle(org.bukkit.entity.Vehicle) Entity(org.bukkit.entity.Entity) Hanging(org.bukkit.entity.Hanging) Projectile(org.bukkit.entity.Projectile)

Example 3 with Vehicle

use of org.bukkit.entity.Vehicle in project RedProtect by FabioZumbi12.

the class RPGlobalListener method onVehicleBreak.

@EventHandler
public void onVehicleBreak(VehicleDestroyEvent e) {
    if (e.isCancelled()) {
        return;
    }
    if (!(e.getAttacker() instanceof Player)) {
        return;
    }
    Vehicle cart = e.getVehicle();
    Player p = (Player) e.getAttacker();
    Region r = RedProtect.get().rm.getTopRegion(cart.getLocation());
    if (r != null) {
        return;
    }
    if (!RPConfig.getGlobalFlagBool(p.getWorld().getName() + ".use-minecart") && !p.hasPermission("redprotect.bypass.world")) {
        e.setCancelled(true);
    }
}
Also used : Vehicle(org.bukkit.entity.Vehicle) Player(org.bukkit.entity.Player) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) EventHandler(org.bukkit.event.EventHandler)

Example 4 with Vehicle

use of org.bukkit.entity.Vehicle in project NoCheatPlus by NoCheatPlus.

the class VehicleChecks method onVehicleMove.

/**
 * When a vehicle moves, its player will be checked for various suspicious behaviors.
 *
 * @param event
 *            the event
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onVehicleMove(final VehicleMoveEvent event) {
    // Check data.
    final Vehicle vehicle = event.getVehicle();
    if (vehicle == null) {
        return;
    }
    // Mind that players could be riding horses inside of minecarts etc.
    if (vehicle.getVehicle() != null) {
        // Do ignore events for vehicles inside of other vehicles.
        return;
    }
    final Player player = passengerUtil.getFirstPlayerPassenger(vehicle);
    if (player == null) {
        return;
    }
    if (vehicle.isDead() || !vehicle.isValid()) {
        // TODO: Actually force dismount?
        onPlayerVehicleLeave(player, vehicle);
        return;
    }
    final EntityType vehicleType = vehicle.getType();
    final IPlayerData pData = DataManager.getPlayerData(player);
    final MovingData data = pData.getGenericInstance(MovingData.class);
    final Location from = event.getFrom();
    final Location to = event.getTo();
    if (pData.isDebugActive(checkType)) {
        outputDebugVehicleMoveEvent(player, from, to);
    }
    if (from == null) {
        // TODO: (In case update doesn't, could fake it here.)
        return;
    } else if (from.equals(to)) {
    // Not possible by obc code.
    } else {
        if (!from.getWorld().equals(to.getWorld())) {
            // TODO: Data adjustments will be necessary with the envelope check.
            return;
        }
    // TODO: Check consistency with assumed/tracked past position, both for from and to. Do something based on result.
    }
    if (normalVehicles.contains(vehicleType)) {
        // Assume handled.
        return;
    } else {
    // Should not be possible, unless plugins somehow force this.
    // TODO: Log warning once / what?
    // TODO: Ignore or continue?
    }
    // Process as move.
    final boolean debug = pData.isDebugActive(checkType);
    if (debug) {
        debug(player, "VehicleMoveEvent: legacy handling, potential issue.");
    }
    // TODO: Actually here consistency with past position tracking should be tested.
    // TODO: Abstraction creation before calling checkVehicleMove, compare/align with onVehicleUpdate.
    checkVehicleMove(vehicle, vehicleType, from, to, player, false, data, pData, debug);
}
Also used : Vehicle(org.bukkit.entity.Vehicle) EntityType(org.bukkit.entity.EntityType) Player(org.bukkit.entity.Player) MovingData(fr.neatmonster.nocheatplus.checks.moving.MovingData) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) Location(org.bukkit.Location) RichBoundsLocation(fr.neatmonster.nocheatplus.utilities.location.RichBoundsLocation) EventHandler(org.bukkit.event.EventHandler)

Example 5 with Vehicle

use of org.bukkit.entity.Vehicle in project Glowstone by GlowstoneMC.

the class VehicleMoveHandler method handle.

@Override
public void handle(GlowSession session, VehicleMoveMessage message) {
    GlowPlayer player = session.getPlayer();
    if (!player.isInsideVehicle() || !(player.getVehicle() instanceof Vehicle)) {
        return;
    }
    GlowEntity vehicle = (GlowEntity) player.getVehicle();
    Location oldLocation = vehicle.getLocation();
    Location newLocation = oldLocation.clone();
    message.update(newLocation);
    // don't let players reach an illegal position
    if (Math.abs(newLocation.getBlockX()) > 32000000 || Math.abs(newLocation.getBlockZ()) > 32000000) {
        session.getPlayer().kickPlayer("Illegal position");
        return;
    }
    /*
          don't let players move more than 100 blocks in a single packet
          if they move greater than 10 blocks, but less than 100, just warn
          this is NOT robust hack prevention - only to prevent client
          confusion about where its actual location is (e.g. during login)
        */
    if (Position.hasMoved(oldLocation, newLocation) && !player.isDead() && !vehicle.isDead()) {
        double distance = newLocation.distanceSquared(oldLocation);
        if (distance > 100 * 100) {
            session.getPlayer().kickPlayer("You moved too quickly :( (Hacking?)");
            return;
        } else if (distance > 100) {
            GlowServer.logger.warning(session.getPlayer().getName() + " moved too quickly!");
        }
    }
    if (!isValidMovement(vehicle, oldLocation, newLocation)) {
        vehicle.teleport(oldLocation);
        return;
    }
    // call move event if movement actually occurred and there are handlers registered
    if (!oldLocation.equals(newLocation) && VehicleMoveEvent.getHandlerList().getRegisteredListeners().length > 0) {
        EventFactory.getInstance().callEvent(new VehicleMoveEvent((Vehicle) vehicle, oldLocation, newLocation.clone()));
    }
    // simply update location
    vehicle.setRawLocation(newLocation);
    player.setRawLocation(vehicle.getMountLocation());
    // track movement stats
    Vector delta = newLocation.clone().subtract(oldLocation).toVector();
    delta.setX(Math.abs(delta.getX()));
    delta.setY(Math.abs(delta.getY()));
    delta.setZ(Math.abs(delta.getZ()));
    int flatDistance = (int) Math.round(Math.hypot(delta.getX(), delta.getZ()) * 100.0);
    if (vehicle instanceof Boat) {
        player.incrementStatistic(Statistic.BOAT_ONE_CM, flatDistance);
    } else if (vehicle instanceof Minecart) {
        player.incrementStatistic(Statistic.MINECART_ONE_CM, flatDistance);
    }
}
Also used : Vehicle(org.bukkit.entity.Vehicle) GlowPlayer(net.glowstone.entity.GlowPlayer) GlowEntity(net.glowstone.entity.GlowEntity) VehicleMoveEvent(org.bukkit.event.vehicle.VehicleMoveEvent) Minecart(org.bukkit.entity.Minecart) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location) Boat(org.bukkit.entity.Boat)

Aggregations

Vehicle (org.bukkit.entity.Vehicle)22 EventHandler (org.bukkit.event.EventHandler)13 Player (org.bukkit.entity.Player)9 Location (org.bukkit.Location)7 Entity (org.bukkit.entity.Entity)6 Vector (org.bukkit.util.Vector)3 Minigame (au.com.mineauz.minigames.minigame.Minigame)2 Team (au.com.mineauz.minigames.minigame.Team)2 DynamicMinigameStat (au.com.mineauz.minigames.stats.DynamicMinigameStat)2 StoredGameStats (au.com.mineauz.minigames.stats.StoredGameStats)2 Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)2 IntVector3 (com.bergerkiller.bukkit.common.bases.IntVector3)2 BlockData (com.bergerkiller.bukkit.common.wrappers.BlockData)2 MovingData (fr.neatmonster.nocheatplus.checks.moving.MovingData)2 IPlayerData (fr.neatmonster.nocheatplus.players.IPlayerData)2 RichBoundsLocation (fr.neatmonster.nocheatplus.utilities.location.RichBoundsLocation)2 Random (java.util.Random)2 Boat (org.bukkit.entity.Boat)2 LivingEntity (org.bukkit.entity.LivingEntity)2 VehicleExitEvent (org.bukkit.event.vehicle.VehicleExitEvent)2