Skip to content

Commit

Permalink
Add dPlayer.send_to mechanism for BungeeCord
Browse files Browse the repository at this point in the history
  • Loading branch information
Morphan1 committed Jun 3, 2015
1 parent 57c2e09 commit 5be7e4c
Showing 1 changed file with 50 additions and 0 deletions.
@@ -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());
}
}
}

0 comments on commit 5be7e4c

Please sign in to comment.