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();
}
}
}
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;
}
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);
}
}
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);
}
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);
}
}
Aggregations