org.spongepowered.api.event.entity.MoveEntityEvent Java Examples

The following examples show how to use org.spongepowered.api.event.entity.MoveEntityEvent. 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: EventRunner.java    From EagleFactions with MIT License 5 votes vote down vote up
/**
    * @return True if cancelled, false if not
    */
public static boolean runFactionAreaEnterEvent(final MoveEntityEvent moveEntityEvent, final Player player, final Optional<Faction> enteredFaction, final Optional<Faction> leftFaction)
{
    final EventContext eventContext = EventContext.builder()
           .add(EventContextKeys.OWNER, player)
           .add(EventContextKeys.PLAYER, player)
           .add(EventContextKeys.CREATOR, player)
           .build();

       final Cause eventCause = Cause.of(eventContext, player, enteredFaction, leftFaction);
       final FactionAreaEnterEvent event = new FactionAreaEnterEventImpl(moveEntityEvent, player, enteredFaction, leftFaction, eventCause);
       return Sponge.getEventManager().post(event);
}
 
Example #2
Source File: FactionAreaEnterEventImpl.java    From EagleFactions with MIT License 5 votes vote down vote up
public FactionAreaEnterEventImpl(final MoveEntityEvent moveEntityEvent, final Player creator, final Optional<Faction> enteredFaction, final Optional<Faction> leftFaction, final Cause cause)
{
	this.moveEntityEvent = moveEntityEvent;
	this.creator = creator;
	this.cause = cause;
	this.enteredFaction = enteredFaction;
	this.leftFaction = leftFaction;
}
 
Example #3
Source File: SpongeWorldChangeListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.POST)
public void onWorldChange(MoveEntityEvent.Teleport event, @First Player player) {
    if (event.isCancelled()) {
        return;
    }

    try {
        actOnEvent(event, player);
    } catch (Exception e) {
        errorLogger.log(L.ERROR, e, ErrorContext.builder().related(event).build());
    }
}
 
Example #4
Source File: SpongeWorldChangeListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void actOnEvent(MoveEntityEvent.Teleport event, Player player) {
    long time = System.currentTimeMillis();

    UUID uuid = player.getUniqueId();

    String worldName = event.getToTransform().getExtent().getName();
    String gameMode = getGameMode(player);

    dbSystem.getDatabase().executeTransaction(new WorldNameStoreTransaction(serverInfo.getServerUUID(), worldName));
    worldAliasSettings.addWorld(worldName);

    Optional<Session> cachedSession = SessionCache.getCachedSession(uuid);
    cachedSession.ifPresent(session -> session.changeState(worldName, gameMode, time));
}
 
Example #5
Source File: Sponge5ArmorListener.java    From ViaVersion with MIT License 5 votes vote down vote up
@Listener
public void onWorldChange(MoveEntityEvent.Teleport e) {
    if (!(e.getTargetEntity() instanceof Player)) return;
    if (!e.getFromTransform().getExtent().getUniqueId().equals(e.getToTransform().getExtent().getUniqueId())) {
        sendArmorUpdate((Player) e.getTargetEntity());
    }
}
 
Example #6
Source File: UCListener.java    From UltimateChat with GNU General Public License v3.0 5 votes vote down vote up
@Listener
public void onChangeWorld(MoveEntityEvent.Teleport e, @Getter("getTargetEntity") Player p) {
    if (!UChat.get().getConfig().root().general.check_channel_change_world) return;

    World tw = e.getToTransform().getExtent();
    UCChannel pch = UChat.get().getPlayerChannel(p);

    String toCh = "";
    if (!pch.availableInWorld(tw)) {
        if (UChat.get().getDefChannel(tw.getName()).availableInWorld(tw)) {
            UChat.get().getDefChannel(tw.getName()).addMember(p);
            toCh = UChat.get().getDefChannel(tw.getName()).getName();
        } else {
            for (UCChannel ch : UChat.get().getChannels().values()) {
                if (ch.availableInWorld(tw)) {
                    ch.addMember(p);
                    toCh = ch.getName();
                    break;
                }
            }
        }
    }
    if (!toCh.isEmpty()) {
        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.entered").replace("{channel}", toCh));
    } else if (!pch.availableInWorld(tw)) {
        pch.removeMember(p);
        UChat.get().getLang().sendMessage(p, "channel.world.none");
    }
}
 
Example #7
Source File: WorldCalculator.java    From LuckPerms with MIT License 5 votes vote down vote up
@Listener(order = Order.LAST)
public void onWorldChange(MoveEntityEvent.Teleport e) {
    Entity targetEntity = e.getTargetEntity();
    if (!(targetEntity instanceof Player)) {
        return;
    }

    if (e.getFromTransform().getExtent().equals(e.getToTransform().getExtent())) {
        return;
    }

    Player player = (Player) targetEntity;
    this.plugin.getContextManager().signalContextUpdate(player);
}
 
Example #8
Source File: PreventListener.java    From FlexibleLogin with MIT License 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerMove(MoveEntityEvent playerMoveEvent, @First Player player) {
    if (playerMoveEvent instanceof MoveEntityEvent.Teleport) {
        return;
    }

    Vector3i oldLocation = playerMoveEvent.getFromTransform().getPosition().toInt();
    Vector3i newLocation = playerMoveEvent.getToTransform().getPosition().toInt();
    if (oldLocation.getX() != newLocation.getX() || oldLocation.getZ() != newLocation.getZ()) {
        checkLoginStatus(playerMoveEvent, player);
    }
}
 
Example #9
Source File: EntityEventHandler.java    From GriefDefender with MIT License 4 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityMove(MoveEntityEvent event){
    CommonEntityEventHandler.getInstance().onEntityMove(event, event.getFromTransform().getLocation(), event.getToTransform().getLocation(), event.getTargetEntity());
}
 
Example #10
Source File: SpongeAFKListener.java    From Plan with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Listener(order = Order.POST)
public void onMove(MoveEntityEvent event, @First Player player) {
    performedAction(player);
}
 
Example #11
Source File: PlayerMoveListener.java    From Nations with MIT License 4 votes vote down vote up
@Listener
public void onPlayerMove(MoveEntityEvent event, @First Player player)
{
	if (event.getFromTransform().getLocation().getBlockX() == event.getToTransform().getLocation().getBlockX() && 
			event.getFromTransform().getLocation().getBlockZ() == event.getToTransform().getLocation().getBlockZ())
	{
		return;
	}
	if (!ConfigHandler.getNode("worlds").getNode(event.getToTransform().getExtent().getName()).getNode("enabled").getBoolean())
	{
		return;
	}

	Location<World> loc = event.getToTransform().getLocation();
	Nation nation = DataHandler.getNation(loc);
	Nation lastNationWalkedOn = DataHandler.getLastNationWalkedOn(player.getUniqueId());
	Zone zone = null;
	if (nation != null)
	{
		zone = nation.getZone(loc);
	}
	Zone lastZoneWalkedOn = DataHandler.getLastZoneWalkedOn(player.getUniqueId());
	if ((nation == null && lastNationWalkedOn == null) || (nation != null && lastNationWalkedOn != null && nation.getUUID().equals(lastNationWalkedOn.getUUID())))
	{
		if ((zone == null && lastZoneWalkedOn == null) || (zone != null && lastZoneWalkedOn != null && zone.getUUID().equals(lastZoneWalkedOn.getUUID())))
		{
			return;
		}
	}
	DataHandler.setLastNationWalkedOn(player.getUniqueId(), nation);
	DataHandler.setLastZoneWalkedOn(player.getUniqueId(), zone);

	String toast;

	if (nation == null) {
		toast = ConfigHandler.getNode("toast", "wild").getString();
	} else {
		toast = (zone == null ? ConfigHandler.getNode("toast", "nation").getString() : ConfigHandler.getNode("toast", "zone").getString());
	}
	
	String formatPresident = "";
	
	if (nation != null && !nation.isAdmin()) {
		formatPresident = ConfigHandler.getNode("toast", "formatPresident").getString()
				.replaceAll("\\{TITLE\\}", DataHandler.getCitizenTitle(nation.getPresident()))
				.replaceAll("\\{NAME\\}", DataHandler.getPlayerName(nation.getPresident()));
	}
	
	String formatZoneName = "";
	String formatZoneOwner = "";
	String formatZonePrice = "";
	
	if (zone != null) {
		if (zone.isNamed())
			formatZoneName = ConfigHandler.getNode("toast", "formatZoneName").getString().replaceAll("\\{ARG\\}", zone.getName()) + " ";
		if (zone.isOwned())
			formatZoneOwner = ConfigHandler.getNode("toast", "formatZoneOwner").getString().replaceAll("\\{ARG\\}", DataHandler.getPlayerName(zone.getOwner())) + " ";
		if (zone.isForSale())
			formatZonePrice = ConfigHandler.getNode("toast", "formatZonePrice").getString().replaceAll("\\{ARG\\}", Utils.formatPricePlain(zone.getPrice())) + " ";
	}
	
	String formatPvp;
	
	if (DataHandler.getFlag("pvp", loc)) {
		formatPvp = ConfigHandler.getNode("toast", "formatPvp").getString().replaceAll("\\{ARG\\}", LanguageHandler.TOAST_PVP);
	} else {
		formatPvp = ConfigHandler.getNode("toast", "formatNoPvp").getString().replaceAll("\\{ARG\\}", LanguageHandler.TOAST_NOPVP);
	}
	
	if (nation != null) {
		toast = toast.replaceAll("\\{NATION\\}", nation.getName());
	} else {
		toast = toast.replaceAll("\\{WILD\\}", LanguageHandler.TOAST_WILDNAME);
	}


	Text finalToast = TextSerializers.FORMATTING_CODE.deserialize(toast
			.replaceAll("\\{FORMATPRESIDENT\\}", formatPresident)
			.replaceAll("\\{FORMATZONENAME\\}", formatZoneName)
			.replaceAll("\\{FORMATZONEOWNER\\}", formatZoneOwner)
			.replaceAll("\\{FORMATZONEPRICE\\}", formatZonePrice)
			.replaceAll("\\{FORMATPVP\\}", formatPvp));

	player.sendMessage(ChatTypes.ACTION_BAR, finalToast);
	MessageChannel.TO_CONSOLE.send(Text.of(player.getName(), " entered area ", finalToast));
}
 
Example #12
Source File: PlayerMoveListener.java    From EssentialCmds with MIT License 4 votes vote down vote up
@Listener
public void onPlayerMove(MoveEntityEvent event)
{
	if (event.getTargetEntity() instanceof Player)
	{
		Player player = (Player) event.getTargetEntity();

		if (Utils.isTeleportCooldownEnabled() && EssentialCmds.teleportingPlayers.contains(player.getUniqueId()))
		{
			EssentialCmds.teleportingPlayers.remove(player.getUniqueId());
			player.sendMessage(Text.of(TextColors.RED, "Teleportation canceled due to movement."));
		}

		if (EssentialCmds.frozenPlayers.contains(player.getUniqueId()))
		{
			player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You cannot move while frozen."));
			event.setCancelled(true);
			return;
		}

		if (EssentialCmds.recentlyJoined.contains(player))
		{
			EssentialCmds.recentlyJoined.remove(player);

			if (EssentialCmds.afkList.containsKey(player.getUniqueId()))
			{
				EssentialCmds.afkList.remove(player.getUniqueId());
			}
		}
		else
		{
			if (EssentialCmds.afkList.containsKey(player.getUniqueId()))
			{
				AFK removeAFK = EssentialCmds.afkList.get(player.getUniqueId());

				if (removeAFK.getAFK())
				{
					if (Utils.shouldAnnounceAFK())
					{
						MessageChannel.TO_ALL.send(Text.of(TextColors.BLUE, player.getName(), TextColors.GOLD, " is no longer AFK."));
					}
				}

				EssentialCmds.afkList.remove(removeAFK);
			}

			AFK afk = new AFK(System.currentTimeMillis());
			EssentialCmds.afkList.put(player.getUniqueId(), afk);
		}

		if (!event.getFromTransform().getExtent().getUniqueId().equals(event.getToTransform().getExtent().getUniqueId()))
		{
			World oldWorld = event.getFromTransform().getExtent();
			World newWorld = event.getToTransform().getExtent();

			Utils.savePlayerInventory(player, oldWorld.getUniqueId());

			if (!Utils.doShareInventories(oldWorld.getName(), newWorld.getName()))
			{
				Utils.updatePlayerInventory(player, newWorld.getUniqueId());
			}

			player.offer(Keys.GAME_MODE, newWorld.getProperties().getGameMode());
		}
	}
}