org.bukkit.plugin.messaging.Messenger Java Examples

The following examples show how to use org.bukkit.plugin.messaging.Messenger. 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: EventExecutor.java    From PlayerSQL with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler
public void handle(PlayerKickEvent e) {
    Player player = e.getPlayer();
    if (handled.get(player.getUniqueId()) != Lifecycle.DATA_SENT) {
        return;
    }

    DataSupply supply = new DataSupply();// So we magic send player data at kick event.
    supply.setId(player.getUniqueId());
    supply.setGroup(group);
    if (isLocked(player.getUniqueId())) {
        supply.setBuf(EMPTY_ARRAY);
    } else {
        manager.lockUser(player);
        PlayerData dat = manager.getUserData(player, true);
        pending.put(player.getUniqueId(), dat);
        supply.setBuf(PlayerDataHelper.encode(dat));
    }

    byte[] message = supply.encode();
    if (message.length > Messenger.MAX_MESSAGE_SIZE) {// Overflow?
        supply.setBuf(EMPTY_ARRAY);
        message = supply.encode();
    }

    player.sendPluginMessage(main, PlayerSqlProtocol.NAMESPACE, message);// BungeeCord received this before kicks
}
 
Example #2
Source File: BungeeCordVariables.java    From ScoreboardStats with MIT License 5 votes vote down vote up
@Override
public void register() {
    Messenger messenger = Bukkit.getMessenger();
    messenger.registerOutgoingPluginChannel(plugin, BUNGEE_CHANNEL);
    messenger.registerIncomingPluginChannel(plugin, BUNGEE_CHANNEL, this);

    Bukkit.getScheduler().runTaskTimer(plugin, this, UPDATE_INTERVAL, UPDATE_INTERVAL);

    register("bungee-online").scoreSupply(() -> onlinePlayers);
}
 
Example #3
Source File: BungeeSender.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void reload(final Settings settings) {
    this.isEnabled = settings.getProperty(HooksSettings.BUNGEECORD);
    this.destinationServerOnLogin = settings.getProperty(HooksSettings.BUNGEECORD_SERVER);

    if (this.isEnabled) {
        final Messenger messenger = plugin.getServer().getMessenger();
        if (!messenger.isOutgoingChannelRegistered(plugin, "BungeeCord")) {
            messenger.registerOutgoingPluginChannel(plugin, "BungeeCord");
        }
    }
}
 
Example #4
Source File: BungeeReceiver.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void reload(final Settings settings) {
    this.isEnabled = settings.getProperty(HooksSettings.BUNGEECORD);

    if (this.isEnabled) {
        final Messenger messenger = plugin.getServer().getMessenger();
        if (!messenger.isIncomingChannelRegistered(plugin, "BungeeCord")) {
            messenger.registerIncomingPluginChannel(plugin, "BungeeCord", this);
        }
    }
}
 
Example #5
Source File: CraftServer.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Messenger getMessenger() {
    return messenger;
}
 
Example #6
Source File: PlayerServerChanger.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@Inject PlayerServerChanger(Plugin plugin, Messenger messenger, Server localServer) {
    this.plugin = plugin;
    this.messenger = messenger;
    this.localServer = localServer;
}
 
Example #7
Source File: Utils.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Sends a plugin message.
 *
 * Example usage using the "GetServers" bungee plugin message channel via an overload:
 * <code>
 *     Utils.sendPluginMessage("BungeeCord", r -> "GetServers".equals(r.readUTF()), "GetServers")
 *     			.thenAccept(response -> Bukkit.broadcastMessage(response.readUTF()) // comma delimited server broadcast
 *     			.exceptionally(ex -> {
 *     			 	Skript.warning("Failed to get servers because there are no players online");
 *     			 	return null;
 *     			});
 * </code>
 *
 * @param player the player to send the plugin message through
 * @param channel the channel for this plugin message
 * @param messageVerifier verifies that a plugin message is the response to the sent message
 * @param data the data to add to the outgoing message
 * @return a completable future for the message of the responding plugin message, if there is one.
 * this completable future will complete exceptionally if the player is null.
 */
public static CompletableFuture<ByteArrayDataInput> sendPluginMessage(Player player, String channel,
		Predicate<ByteArrayDataInput> messageVerifier, String... data) {
	CompletableFuture<ByteArrayDataInput> completableFuture = new CompletableFuture<>();

	if (player == null) {
		completableFuture.completeExceptionally(new IllegalStateException("Can't send plugin messages from a null player"));
		return completableFuture;
	}

	Skript skript = Skript.getInstance();
	Messenger messenger = Bukkit.getMessenger();

	messenger.registerOutgoingPluginChannel(skript, channel);

	PluginMessageListener listener = (sendingChannel, sendingPlayer, message) -> {
		ByteArrayDataInput input = ByteStreams.newDataInput(message);
		if (channel.equals(sendingChannel) && sendingPlayer == player && !completableFuture.isDone()
				&& !completableFuture.isCancelled() && messageVerifier.test(input)) {
			completableFuture.complete(input);
		}
	};

	messenger.registerIncomingPluginChannel(skript, channel, listener);

	completableFuture.whenComplete((r, ex) -> messenger.unregisterIncomingPluginChannel(skript, channel, listener));

	// if we haven't gotten a response after a minute, let's just assume there wil never be one
	Bukkit.getScheduler().scheduleSyncDelayedTask(skript, () -> {

		if (!completableFuture.isDone())
			completableFuture.cancel(true);

	}, 60 * 20);

	ByteArrayDataOutput out = ByteStreams.newDataOutput();
	Stream.of(data).forEach(out::writeUTF);
	player.sendPluginMessage(Skript.getInstance(), channel, out.toByteArray());

	return completableFuture;
}
 
Example #8
Source File: MockServer.java    From Chimera with MIT License 4 votes vote down vote up
@Override
public Messenger getMessenger() {
    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
 
Example #9
Source File: MockServer.java    From SaneEconomy with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Messenger getMessenger() {
    return null;
}
 
Example #10
Source File: CraftServer.java    From Thermos with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Messenger getMessenger() {
    return messenger;
}
 
Example #11
Source File: Server.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Gets the {@link Messenger} responsible for this server.
 *
 * @return messenger responsible for this server
 */
public Messenger getMessenger();
 
Example #12
Source File: Bukkit.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Gets the {@link Messenger} responsible for this server.
 *
 * @return messenger responsible for this server
 */
public static Messenger getMessenger() {
    return server.getMessenger();
}