use of org.bukkit.entity.Vehicle in project Prism-Bukkit by prism.
the class PrismVehicleEvents method onVehicleExit.
/**
* VehicleExitEvent.
*
* @param event VehicleExitEvent
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onVehicleExit(final VehicleExitEvent event) {
final Vehicle vehicle = event.getVehicle();
final Entity entity = event.getExited();
handlePlayerAction(entity, vehicle, "vehicle-exit", "vehicle-enter");
}
use of org.bukkit.entity.Vehicle in project Prism-Bukkit by prism.
the class PrismVehicleEvents method onVehicleEnter.
/**
* VehicleEnterEvent.
*
* @param event VehicleEnterEvent
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onVehicleEnter(final VehicleEnterEvent event) {
final Vehicle vehicle = event.getVehicle();
final Entity entity = event.getEntered();
handlePlayerAction(entity, vehicle, "vehicle-enter");
}
use of org.bukkit.entity.Vehicle in project NoCheatPlus by NoCheatPlus.
the class VehicleChecks method onVehicleUpdate.
/**
* This should always fire, prefer over VehicleMoveEvent, if possible.
*
* @param event
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onVehicleUpdate(final VehicleUpdateEvent event) {
// TODO: VehicleUpdateEvent. How to track teleporting of the vehicle?
// TODO: Track just left vehicle/entity positions otherwise (on tick + vehicle update)?
// TODO: No problem: (?) update 'authorized state' if no player passenger.
final Vehicle vehicle = event.getVehicle();
final EntityType vehicleType = vehicle.getType();
if (!normalVehicles.contains(vehicleType)) {
// A little extra sweep to check for debug flags.
normalVehicles.add(vehicleType);
if (worldDataManager.getWorldData(vehicle.getWorld()).isDebugActive(checkType)) {
debug(null, "VehicleUpdateEvent fired for: " + vehicleType);
}
}
// TODO: Detect if a VehicleMove event will fire (not strictly possible without nms, depends on visibility of fields, possibly estimate instead?).
if (vehicle.getVehicle() != null) {
// Do ignore events for vehicles inside of other vehicles.
return;
}
final Player player = passengerUtil.getFirstPlayerPassenger(vehicle);
if (player == null || player.isDead()) {
return;
}
if (vehicle.isDead() || !vehicle.isValid()) {
// TODO: Actually force dismount?
onPlayerVehicleLeave(player, vehicle);
return;
}
final IPlayerData pData = DataManager.getPlayerData(player);
final MovingData data = pData.getGenericInstance(MovingData.class);
// final MovingConfig cc = MovingConfig.getConfig(player);
final boolean debug = pData.isDebugActive(checkType);
if (debug) {
final Location loc = vehicle.getLocation(useLoc1);
debug(player, "VehicleUpdateEvent: " + vehicleType + " " + loc);
useLoc1.setWorld(null);
}
onVehicleUpdate(vehicle, vehicleType, player, false, data, pData, debug);
}
use of org.bukkit.entity.Vehicle in project Minigames by AddstarMC.
the class MinigamePlayerManager 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);
if (minigame.getShowCompletionTime()) {
player.setCompleteTime(player.getEndTime() - player.getStartTime() + player.getStoredTime());
}
} 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.
mgManager.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().runTaskLater(plugin, () -> fplayer.getPlayer().setFireTicks(0), 0L);
player.resetAllStats();
player.setStartPos(null);
if (!player.isDead()) {
player.restorePlayerData();
Location loc;
if (!isWinner) {
if (minigame.getQuitPosition() != null) {
loc = minigame.getQuitPosition();
} else {
loc = minigame.getEndPosition();
}
} else {
loc = minigame.getEndPosition();
}
player.teleport(loc);
} else {
if (!isWinner)
player.setQuitPos(minigame.getQuitPosition());
else
player.setQuitPos(minigame.getEndPosition());
player.setRequiredQuit(true);
}
player.setStartPos(null);
// 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);
minigame.setPlayersAtStart(false);
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);
}
mgManager.clearClaimedScore(minigame);
WeatherTimeModule mod = WeatherTimeModule.getMinigameModule(minigame);
if (mod != null) {
mod.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(plugin, pl.getPlayer());
}
if (minigame.getPlayers().size() == 0 && !minigame.isRegenerating()) {
HandlerList.unregisterAll(minigame.getBlockRecorder());
}
// Send out messages
if (!forced) {
mgManager.sendMinigameMessage(minigame, MinigameUtils.formStr("player.quit.plyMsg", player.getName(), minigame.getName(true)), MinigameMessageType.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, () -> fplayer.setFireTicks(0));
player.getPlayer().closeInventory();
if (!player.isDead()) {
player.restorePlayerData();
}
player.teleport(minigame.getQuitPosition());
player.setStartPos(null);
player.removeMinigame();
minigame.removeSpectator(player);
for (MinigamePlayer pl : minigame.getPlayers()) {
pl.getPlayer().showPlayer(plugin, player.getPlayer());
}
player.sendMessage(MinigameUtils.formStr("player.spectate.quit.plyMsg", minigame.getName(true)), MinigameMessageType.ERROR);
mgManager.sendMinigameMessage(minigame, MinigameUtils.formStr("player.spectate.quit.minigameMsg", player.getName(), minigame.getName(true)), MinigameMessageType.ERROR, player);
}
if (ResourcePackModule.getMinigameModule(minigame).isEnabled()) {
if (player.applyResourcePack(plugin.getResourceManager().getResourcePack("empty"))) {
Minigames.log().warning("Could not apply empty resource pack to " + player.getDisplayName());
} else {
player.sendInfoMessage(MinigameUtils.getLang("minigames.resourcepack.remove"));
}
}
if (player.getPlayer().getGameMode() != GameMode.CREATIVE)
player.setCanFly(false);
if (!forced) {
minigame.getScoreboardData().reload();
}
}
}
use of org.bukkit.entity.Vehicle in project Glowstone by GlowstoneMC.
the class GlowEntity method removePassenger.
@Override
public boolean removePassenger(Entity passenger) {
Preconditions.checkArgument(!this.equals(passenger), "Entity cannot ride itself.");
if (passenger == null || !passengers.contains(passenger)) {
// nothing changed
return false;
}
if (EventFactory.getInstance().callEvent(new EntityDismountEvent(passenger, this)).isCancelled()) {
return false;
}
if (!(passenger instanceof GlowEntity)) {
return false;
}
GlowEntity glowPassenger = (GlowEntity) passenger;
if (this instanceof Vehicle && glowPassenger instanceof LivingEntity) {
VehicleExitEvent event = EventFactory.getInstance().callEvent(new VehicleExitEvent((Vehicle) this, (LivingEntity) glowPassenger));
if (event.isCancelled()) {
return false;
}
}
passengerChanged = true;
glowPassenger.vehicle = null;
glowPassenger.teleport(getDismountLocation());
return passengers.remove(passenger);
}
Aggregations