Java Code Examples for org.bukkit.event.player.PlayerMoveEvent#getPlayer()

The following examples show how to use org.bukkit.event.player.PlayerMoveEvent#getPlayer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Compat19.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent e) {
    Player p = e.getPlayer();

    // Glide options
    if (!p.hasPermission("redprotect.bypass.glide")) {
        if (!RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).player_glide.allow_elytra) {
            ItemStack item = p.getInventory().getChestplate();
            if (item != null && item.getType().equals(Material.ELYTRA)) {
                PlayerInventory inv = p.getInventory();
                inv.setChestplate(new ItemStack(Material.AIR));
                if (inv.firstEmpty() == -1) {
                    p.getWorld().dropItem(p.getLocation(), item);
                } else {
                    inv.setItem(inv.firstEmpty(), item);
                }
                p.playSound(p.getLocation(), Sound.ENTITY_ITEM_PICKUP, 10, 1);
                RedProtect.get().lang.sendMessage(p, "globallistener.elytra.cantequip");
            }
        }
    }
}
 
Example 2
Source File: BrushListener.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent event) {
    Location from = event.getFrom();
    Location to = event.getTo();
    if ((from.getYaw() != to.getYaw() &&  from.getPitch() != to.getPitch()) || from.getBlockX() != to.getBlockX() || from.getBlockZ() != to.getBlockZ() || from.getBlockY() != to.getBlockY()) {
        Player bukkitPlayer = event.getPlayer();
        FawePlayer<Object> fp = FawePlayer.wrap(bukkitPlayer);
        com.sk89q.worldedit.entity.Player player = fp.getPlayer();
        LocalSession session = fp.getSession();
        Tool tool = session.getTool(player);
        if (tool != null) {
            if (tool instanceof MovableTool) {
                ((MovableTool) tool).move(player);
            }
        }
    }
}
 
Example 3
Source File: Scotopic.java    From MineTinker with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onMoveImmune(PlayerMoveEvent event) {
	if (!this.givesImmunity) return;

	Player player = event.getPlayer();
	if (!player.hasPermission("minetinker.modifiers.scotopic.use")) {
		return;
	}

	ItemStack armor = player.getInventory().getHelmet();
	if (armor == null) return;

	if (!modManager.hasMod(armor, this)) return;
	if (player.hasPotionEffect(PotionEffectType.BLINDNESS)) {
		player.removePotionEffect(PotionEffectType.BLINDNESS);
		ChatWriter.logModifier(player, event, this, armor, "RemoveBlindness");
	}
}
 
Example 4
Source File: JumpPads.java    From HubBasics with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
    if (needsPressurePlate(event.getPlayer()) || !isBlockRequired(event.getPlayer())) return;
    Player player = event.getPlayer();
    if (!isEnabledInWorld(player.getWorld())) return;
    Location loc = player.getLocation().subtract(0, 1, 0);
    if (loc.getBlock().getType() == getMaterial(player)) {
        player.setVelocity(calculateVector(player));
        if (getSound(player) != null) {
            player.playSound(player.getLocation(), getSound(player), 1, 1);
        }
        if (getEffect(player) != null) {
            particleEffect.display(getEffect(player), player.getLocation(), 1, 1, 1, 1, 40);
        }
    }
}
 
Example 5
Source File: Trade.java    From TradePlus with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onMove(PlayerMoveEvent event) {
  if (cancelled || event.getTo() == null) return;
  Player player = event.getPlayer();
  if (player.equals(player1) || player.equals(player2)) {
    if (event.getFrom().distanceSquared(event.getTo()) < 0.01) return;
    if (System.currentTimeMillis() < startTime + 1000) {
      return;
    }
    if (player.equals(player1)) {
      player.teleport(location1);
    } else {
      player.teleport(location2);
    }
  }
}
 
Example 6
Source File: Webbed.java    From MineTinker with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onMove(PlayerMoveEvent event) {
	if (!this.givesImmunity) return;

	Player player = event.getPlayer();
	if (!player.hasPermission("minetinker.modifiers.webbed.use")) {
		return;
	}

	boolean hasWebbed = false;
	ItemStack armor = null;
	for (ItemStack stack : player.getInventory().getArmorContents()) {
		if (stack == null) continue;
		if (modManager.hasMod(stack, this)) {
			hasWebbed = true;
			armor = stack;
			break;
		}
	}

	if (!hasWebbed) return;
	if (player.hasPotionEffect(PotionEffectType.SLOW)) {
		player.removePotionEffect(PotionEffectType.SLOW);
		ChatWriter.logModifier(player, event, this, armor, "RemoveEffect");
	}
}
 
Example 7
Source File: DPlayerListener.java    From DungeonsXL with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
    Player player = event.getPlayer();
    if (isCitizensNPC(player)) {
        return;
    }
    DGameWorld gameWorld = (DGameWorld) plugin.getGameWorld(player.getWorld());
    DGamePlayer gamePlayer = (DGamePlayer) dPlayers.getGamePlayer(player);
    if (gameWorld != null && gamePlayer != null) {
        if (gamePlayer.getDGroupTag() != null) {
            gamePlayer.getDGroupTag().update();
        }
        if (gamePlayer.isStealingFlag()) {
            DGroup group = gamePlayer.getGroup();
            Location startLocation = gameWorld.getStartLocation(group);

            if (startLocation.distance(player.getLocation()) < 3) {
                gamePlayer.captureFlag();
            }
        }
    }
}
 
Example 8
Source File: Autorepair.java    From ce with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void effect(Event e, ItemStack item, int level) {
	PlayerMoveEvent event = (PlayerMoveEvent) e;
	Player owner = event.getPlayer();

	
	if(owner != null && owner.isOnline() && !owner.isDead()) {
		if(healFully)
			item.setDurability((short) 0);
		else {
			int newDur = item.getDurability() - ( 1 + (healAmount*level));
			
			if(newDur > 0)
				item.setDurability((short) newDur);
			else
				item.setDurability((short) 0);
		}
	}
}
 
Example 9
Source File: SignUpdater.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void move(final PlayerMoveEvent event) {
    Player player = event.getPlayer();
    Location to = event.getTo();
    Location from = event.getFrom();
    Block toBlock = to.getBlock();
    Block fromBlock = from.getBlock();

    handleLook(player, to);

    if(PORTAL_MATERIALS.contains(toBlock.getType()) && !PORTAL_MATERIALS.contains(fromBlock.getType())) {
        nearestSign(event.getTo()).ifPresent(
            sign -> sign.connector().teleport(player)
        );
    }
}
 
Example 10
Source File: MoveEvent.java    From MCAuthenticator with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerMove(PlayerMoveEvent event) {
    Location from = event.getFrom();
    Location to = event.getTo();

    if (from.getBlockX() == to.getBlockX()
            && from.getBlockY() == to.getBlockY()
            && from.getBlockZ() == to.getBlockZ()) {
        return;
    }

    Player player = event.getPlayer();
    User u = instance.getCache().get(player.getUniqueId());

    if (u != null && u.authenticated()) return;

    event.setTo(from);
}
 
Example 11
Source File: RewardListener.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
    Player player = event.getPlayer();
    if (DPlayerListener.isCitizensNPC(player)) {
        return;
    }
    GlobalPlayer dPlayer = plugin.getPlayerCache().get(player);
    if (plugin.getInstanceWorld(player.getWorld()) != null) {
        return;
    }
    Block block = player.getLocation().getBlock();
    if (dPlayer.hasRewardItemsLeft() && !VanillaItem.NETHER_PORTAL.is(block.getRelative(0, 1, 0)) && !VanillaItem.NETHER_PORTAL.is(block.getRelative(0, -1, 0))
            && !VanillaItem.NETHER_PORTAL.is(block.getRelative(1, 0, 0)) && !VanillaItem.NETHER_PORTAL.is(block.getRelative(-1, 0, 0))
            && !VanillaItem.NETHER_PORTAL.is(block.getRelative(0, 0, 1)) && !VanillaItem.NETHER_PORTAL.is(block.getRelative(0, 0, -1))) {
        PaginatedInventoryGUI lootInventory = new PaginatedInventoryGUI(DMessage.PLAYER_TREASURES.getMessage());
        PaginatedFlowInventoryLayout layout = new PaginatedFlowInventoryLayout(lootInventory, 54, PaginationButtonPosition.BOTTOM);
        layout.setSwitchButtonLinePlaceholdersEnabled(true);
        lootInventory.setLayout(layout);
        lootInventory.register();
        for (ItemStack item : dPlayer.getRewardItems()) {
            if (item != null) {
                InventoryButton button = new InventoryButton(item);
                button.setStealable(true);
                lootInventory.add(button);
            }
        }
        lootInventory.open(player);
        dPlayer.setRewardItems(null);
    }
}
 
Example 12
Source File: RegionListener.java    From EchoPet with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent event) {
    Player p = event.getPlayer();
    IPet pet = EchoPet.getManager().getPet(p);
    if (pet != null) {
        if (!WorldUtil.allowRegion(event.getTo())) {
            EchoPet.getManager().removePet(pet, true);
            Lang.sendTo(p, Lang.ENTER_PET_DISABLED_REGION.toString());
        }
    }
}
 
Example 13
Source File: WalkingTaskType.java    From Quests with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onMove(PlayerMoveEvent event) {
    if (event.getFrom().getBlockX() == event.getTo().getBlockX() && event.getFrom().getBlockZ() == event.getTo().getBlockZ()) {
        return;
    }

    Player player = event.getPlayer();

    QPlayer qPlayer = QuestsAPI.getPlayerManager().getPlayer(player.getUniqueId(), true);
    QuestProgressFile questProgressFile = qPlayer.getQuestProgressFile();

    for (Quest quest : super.getRegisteredQuests()) {
        if (questProgressFile.hasStartedQuest(quest)) {
            QuestProgress questProgress = questProgressFile.getQuestProgress(quest);

            for (Task task : quest.getTasksOfType(super.getType())) {
                TaskProgress taskProgress = questProgress.getTaskProgress(task.getId());

                if (taskProgress.isCompleted()) {
                    continue;
                }

                int distanceNeeded = (int) task.getConfigValue("distance");

                int progressDistance;
                if (taskProgress.getProgress() == null) {
                    progressDistance = 0;
                } else {
                    progressDistance = (int) taskProgress.getProgress();
                }

                taskProgress.setProgress(progressDistance + 1);

                if (((int) taskProgress.getProgress()) >= distanceNeeded) {
                    taskProgress.setCompleted(true);
                }
            }
        }
    }
}
 
Example 14
Source File: PlayerMovementListener.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Fire a CoarsePlayerMoveEvent that wraps the given event, only if it crosses
 * a block boundary, or the PoseFlags change.
 * @param event         The movement event to potentially wrap
 * @return True if the original event was not cancelled, and a coarse event was fired,
 *         and that coarse event was cancelled. In this case, the wrapped event won't
 *         actually be cancelled, but callers should treat it like it is.
 */
private boolean callCoarsePlayerMove(final PlayerMoveEvent event) {
    // Don't fire coarse events for teleports that are not "in-game"
    // e.g. /jumpto command
    if(event instanceof PlayerTeleportEvent) {
        PlayerTeleportEvent teleportEvent = (PlayerTeleportEvent) event;
        if(teleportEvent.getCause() != TeleportCause.ENDER_PEARL &&
           teleportEvent.getCause() != TeleportCause.UNKNOWN) {
            return false;
        }
    }

    // If the movement does not cross a block boundary, and no PoseFlags changed, we don't care about it
    final EntityLocation from = event.getEntityFrom();
    final EntityLocation to = event.getEntityTo();
    if(from.position().coarseEquals(to.position()) && from.poseFlags().equals(to.poseFlags())) {
        return false;
    }

    // Remember whether the original event was already cancelled
    boolean wasCancelled = event.isCancelled();

    CoarsePlayerMoveEvent generalEvent = new CoarsePlayerMoveEvent(event, event.getPlayer(), from, to);
    this.eventBus.callEvent(generalEvent);

    if(!wasCancelled && generalEvent.isCancelled()) {
        // When a coarse event is cancelled, we have our own logic for resetting the
        // player's position, so we un-cancel the event and instead modify its
        // to location to put the player where we want them.
        resetPosition(event);
        return true;
    } else {
        return false;
    }
}
 
Example 15
Source File: WorldGuardEvents.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
@SuppressWarnings("unused")
public void onPlayerMove(PlayerMoveEvent e) {
    if (e.getTo() == null || !plugin.getWorldManager().isSkyAssociatedWorld(e.getTo().getWorld())) {
        return;
    }
    String islandNameAt = WorldGuardHandler.getIslandNameAt(e.getTo());
    if (islandNameAt == null) {
        return;
    }
    IslandInfo islandInfo = plugin.getIslandInfo(islandNameAt);
    if (islandInfo == null || islandInfo.getBans().isEmpty()) {
        return;
    }
    Player player = e.getPlayer();
    if (!player.isOp() && !player.hasPermission("usb.mod.bypassprotection") && isBlockedFromEntry(player, islandInfo)) {
        e.setCancelled(true);
        Location l = e.getTo().clone();
        l.subtract(islandInfo.getIslandLocation());
        Vector v = new Vector(l.getX(), l.getY(), l.getZ());
        v.normalize();
        v.multiply(1.5); // Bounce
        player.setVelocity(v);
        if (islandInfo.isBanned(player)) {
            plugin.notifyPlayer(player, tr("\u00a7cBanned:\u00a7e You are banned from this island."));
        } else {
            plugin.notifyPlayer(player, tr("\u00a7cLocked:\u00a7e That island is locked! No entry allowed."));
        }
    }
}
 
Example 16
Source File: TrapListener.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onMove(PlayerMoveEvent event) {
    Player player = event.getPlayer();
    if (event.isCancelled() || !Main.isPlayerInGame(player)) {
        return;
    }

    double difX = Math.abs(event.getFrom().getX() - event.getTo().getX());
    double difZ = Math.abs(event.getFrom().getZ() - event.getTo().getZ());

    if (difX == 0.0 && difZ == 0.0) {
        return;
    }

    GamePlayer gPlayer = Main.getPlayerGameProfile(player);
    Game game = gPlayer.getGame();
    if (game.getStatus() == GameStatus.RUNNING && !gPlayer.isSpectator) {
        for (SpecialItem special : game.getActivedSpecialItems(Trap.class)) {
            Trap trapBlock = (Trap) special;

            if (trapBlock.isPlaced()) {
                if (game.getTeamOfPlayer(player) != trapBlock.getTeam()) {
                    if (event.getTo().getBlock().getLocation().equals(trapBlock.getLocation())) {
                        trapBlock.process(player, game.getPlayerTeam(gPlayer), false);
                    }
                }
            }
        }
    }
}
 
Example 17
Source File: DistanceTravelledListener.java    From Statz with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onMove(final PlayerMoveEvent event) {

    final PlayerStat stat = PlayerStat.DISTANCE_TRAVELLED;

    // Get player
    final Player player = event.getPlayer();

    // Do general check
    if (!plugin.doGeneralCheck(player, stat))
        return;

    String movementType = StatzUtil.getMovementType(player);

    final double distTravelled;

    try {
        distTravelled = event.getFrom().distance(event.getTo());
    } catch (IllegalArgumentException e) {
        // Did not move correctly, so ignore it.
        return;
    }

    if (distTravelled == 0) {
        return;
    }

    PlayerStatSpecification specification = new DistanceTravelledSpecification(player.getUniqueId(),
            distTravelled, player.getWorld().getName(), movementType);

    // Update value to new stat.
    plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat, specification.constructQuery());

}
 
Example 18
Source File: RealmListener.java    From NyaaUtils with MIT License 4 votes vote down vote up
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
    Player player = event.getPlayer();
    UUID id = player.getUniqueId();
    if(muteList.contains(id)){
        return;
    }
    String currentRealmName = currentRealm.getOrDefault(id, "");
    Realm realm = getRealm(player.getLocation());
    if (realm == null) {
        return;
    }
    if (currentRealmName.equals(realm.getName()) && realm.inArea(player.getLocation())) {
        return;
    }
    if (!currentRealmName.equals(realm.getName()) && !Realm.__DEFAULT__.equals(realm.getName())) {
        currentRealm.put(id, realm.getName());
        if(plugin.cfg.realm_notification_type == MessageType.TITLE){
            String title, subtitle;
            if (realm.getType().equals(RealmType.PUBLIC)) {
                title = I18n.format("user.realm.notification.public_title", realm.getName());
                subtitle = I18n.format("user.realm.notification.public_subtitle");
            } else {
                title = I18n.format("user.realm.notification.private_title", realm.getName());
                subtitle = I18n.format("user.realm.notification.private_subtitle", realm.getOwner().getName());
            }
            Message.sendTitle(player,
                    new Message(title).inner,
                    new Message(subtitle).inner,
                    plugin.cfg.realm_notification_title_fadein_tick,
                    plugin.cfg.realm_notification_title_stay_tick,
                    plugin.cfg.realm_notification_title_fadeout_tick
            );
        }else{
            if (realm.getType().equals(RealmType.PUBLIC)) {
                new Message(I18n.format("user.realm.notification.public", realm.getName())).
                        send(player, plugin.cfg.realm_notification_type);
            } else {
                new Message(I18n.format("user.realm.notification.private", realm.getName(),
                        realm.getOwner().getName())).send(player, plugin.cfg.realm_notification_type);
            }
        }
        return;
    } else if (!currentRealm.containsKey(id) || !Realm.__DEFAULT__.equals(currentRealmName)) {
        currentRealm.put(id, Realm.__DEFAULT__);
        new Message(ChatColor.translateAlternateColorCodes('&', plugin.cfg.realm_default_name))
                .send(player, plugin.cfg.realm_notification_type);
    }
    return;
}
 
Example 19
Source File: PositionTaskType.java    From Quests with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onMove(PlayerMoveEvent event) {
    if (event.getFrom().getBlockX() == event.getTo().getBlockX() && event.getFrom().getBlockZ() == event.getTo().getBlockZ()) {
        return;
    }

    Player player = event.getPlayer();

    QPlayer qPlayer = QuestsAPI.getPlayerManager().getPlayer(player.getUniqueId(), true);
    QuestProgressFile questProgressFile = qPlayer.getQuestProgressFile();

    for (Quest quest : super.getRegisteredQuests()) {
        if (questProgressFile.hasStartedQuest(quest)) {
            QuestProgress questProgress = questProgressFile.getQuestProgress(quest);

            for (Task task : quest.getTasksOfType(super.getType())) {
                TaskProgress taskProgress = questProgress.getTaskProgress(task.getId());

                if (taskProgress.isCompleted()) {
                    continue;
                }

                int x = (int) task.getConfigValue("x");
                int y = (int) task.getConfigValue("y");
                int z = (int) task.getConfigValue("z");
                String worldString = (String) task.getConfigValue("world");
                int padding = 0;
                if (task.getConfigValue("distance-padding") != null) {
                    padding = (int) task.getConfigValue("distance-padding");
                }
                World world = Bukkit.getWorld(worldString);
                if (world == null) {
                    return;
                }

                Location location = new Location(world, x, y, z);
                if (player.getWorld().equals(world) && player.getLocation().getBlockX() == location.getBlockX() && player.getLocation().getBlockY() == location.getBlockY() && player.getLocation().getBlockZ() == location.getBlockZ()) {
                    taskProgress.setCompleted(true);
                } else if (player.getWorld().equals(world) && player.getLocation().distance(location) < padding) {
                    taskProgress.setCompleted(true);
                }
            }
        }
    }
}
 
Example 20
Source File: WarpPowderListener.java    From BedwarsRel with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onMove(PlayerMoveEvent mv) {
  if (mv.isCancelled()) {
    return;
  }

  if (mv.getFrom().getBlock().equals(mv.getTo().getBlock())) {
    return;
  }

  Player player = mv.getPlayer();
  Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player);

  if (game == null) {
    return;
  }

  if (game.getState() != GameState.RUNNING) {
    return;
  }

  WarpPowder powder = null;
  for (SpecialItem item : game.getSpecialItems()) {
    if (!(item instanceof WarpPowder)) {
      continue;
    }

    powder = (WarpPowder) item;
    if (powder.getPlayer().equals(player)) {
      break;
    }

    powder = null;
  }

  if (powder != null) {
    powder.setStackAmount(powder.getStack().getAmount() + 1);
    player.updateInventory();
    powder.cancelTeleport(true, true);
    return;
  }
}