Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dPlayer.send_to mechanism for BungeeCord
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/main/java/net/gnomeffinway/depenizen/extensions/bungee/BungeePlayerExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package net.gnomeffinway.depenizen.extensions.bungee; | ||
|
||
import com.google.common.io.ByteArrayDataOutput; | ||
import com.google.common.io.ByteStreams; | ||
import net.aufdemrand.denizen.objects.dPlayer; | ||
import net.aufdemrand.denizencore.objects.Element; | ||
import net.aufdemrand.denizencore.objects.Mechanism; | ||
import net.aufdemrand.denizencore.objects.dObject; | ||
import net.gnomeffinway.depenizen.Depenizen; | ||
import net.gnomeffinway.depenizen.extensions.dObjectExtension; | ||
import net.gnomeffinway.depenizen.objects.bungee.dServer; | ||
|
||
public class BungeePlayerExtension extends dObjectExtension { | ||
|
||
public static boolean describes(dObject pl) { | ||
return pl instanceof dPlayer; | ||
} | ||
|
||
public static BungeePlayerExtension getFrom(dObject pl) { | ||
if (!describes(pl)) return null; | ||
else return new BungeePlayerExtension((dPlayer) pl); | ||
} | ||
|
||
private BungeePlayerExtension(dPlayer pl) { player = pl; } | ||
|
||
dPlayer player = null; | ||
|
||
@Override | ||
public void adjust(Mechanism mechanism) { | ||
|
||
Element value = mechanism.getValue(); | ||
|
||
// <--[mechanism] | ||
// @object dPlayer | ||
// @name send_to | ||
// @input dServer | ||
// @description | ||
// Sends a player to the specified server. | ||
// @tags | ||
// None | ||
// --> | ||
if (mechanism.matches("send_to") | ||
&& mechanism.requireObject(dServer.class)) { | ||
ByteArrayDataOutput out = ByteStreams.newDataOutput(); | ||
out.writeUTF("Connect"); | ||
out.writeUTF(value.asType(dServer.class).getName()); | ||
player.getPlayerEntity().sendPluginMessage(Depenizen.getCurrentInstance(), "BungeeCord", out.toByteArray()); | ||
} | ||
} | ||
} |