diff --git a/BuildConfigUpdater/BuildConfigUpdater.iml b/BuildConfigUpdater/BuildConfigUpdater.iml index 31ba17d..df2c815 100644 --- a/BuildConfigUpdater/BuildConfigUpdater.iml +++ b/BuildConfigUpdater/BuildConfigUpdater.iml @@ -12,7 +12,6 @@ - diff --git a/ButtonCore/pom.xml b/ButtonCore/pom.xml index 2ae7ccb..088389a 100755 --- a/ButtonCore/pom.xml +++ b/ButtonCore/pom.xml @@ -119,6 +119,10 @@ Votifier https://dl.bintray.com/nuvotifier/maven/ + + Multiverse-Core + http://repo.onarandombox.com/content/repositories/multiverse/ + @@ -182,6 +186,12 @@ 2.3.4 provided + + com.onarandombox.multiversecore + Multiverse-Core + 4.0.1 + provided + TBMCPlugins diff --git a/ButtonCore/src/main/java/buttondevteam/core/MainPlugin.java b/ButtonCore/src/main/java/buttondevteam/core/MainPlugin.java index 5c4463f..01132f9 100755 --- a/ButtonCore/src/main/java/buttondevteam/core/MainPlugin.java +++ b/ButtonCore/src/main/java/buttondevteam/core/MainPlugin.java @@ -6,6 +6,7 @@ import buttondevteam.core.component.channel.ChatRoom; import buttondevteam.core.component.members.MemberComponent; import buttondevteam.core.component.randomtp.RandomTPComponent; import buttondevteam.core.component.restart.RestartComponent; +import buttondevteam.core.component.spawn.SpawnComponent; import buttondevteam.core.component.towny.TownyComponent; import buttondevteam.core.component.updater.PluginUpdater; import buttondevteam.core.component.updater.PluginUpdaterComponent; @@ -89,6 +90,7 @@ public class MainPlugin extends ButtonPlugin { Component.registerComponent(this, new ChannelComponent()); Component.registerComponent(this, new RandomTPComponent()); Component.registerComponent(this, new MemberComponent()); + Component.registerComponent(this, new SpawnComponent()); if (Bukkit.getPluginManager().isPluginEnabled("Towny")) //It fails to load the component class otherwise Component.registerComponent(this, new TownyComponent()); if (Bukkit.getPluginManager().isPluginEnabled("Votifier") && economy != null) diff --git a/ButtonCore/src/main/java/buttondevteam/core/component/spawn/SpawnComponent.java b/ButtonCore/src/main/java/buttondevteam/core/component/spawn/SpawnComponent.java new file mode 100644 index 0000000..a9b9970 --- /dev/null +++ b/ButtonCore/src/main/java/buttondevteam/core/component/spawn/SpawnComponent.java @@ -0,0 +1,120 @@ +package buttondevteam.core.component.spawn; + +import buttondevteam.core.MainPlugin; +import buttondevteam.lib.architecture.Component; +import buttondevteam.lib.architecture.ConfigData; +import buttondevteam.lib.chat.Command2; +import buttondevteam.lib.chat.CommandClass; +import buttondevteam.lib.chat.ICommand2MC; +import com.google.common.io.ByteArrayDataInput; +import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; +import com.onarandombox.MultiverseCore.MultiverseCore; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.plugin.messaging.PluginMessageListener; + +import java.io.*; + +public class SpawnComponent extends Component implements PluginMessageListener { + @Override + protected void enable() { + registerCommand(new SpawnCommand()); + if (targetServer().get().length() == 0) { + spawnloc = MultiverseCore.getPlugin(MultiverseCore.class).getMVWorldManager().getFirstSpawnWorld() + .getSpawnLocation(); + } + + Bukkit.getServer().getMessenger().registerOutgoingPluginChannel(getPlugin(), "BungeeCord"); + Bukkit.getServer().getMessenger().registerIncomingPluginChannel(getPlugin(), "BungeeCord", this); + } + + @Override + protected void disable() { + Bukkit.getServer().getMessenger().unregisterIncomingPluginChannel(getPlugin(), "BungeeCord"); + Bukkit.getServer().getMessenger().unregisterOutgoingPluginChannel(getPlugin(), "BungeeCord"); + } + + @Override + public void onPluginMessageReceived(String channel, Player player, byte[] message) { + if (!channel.equals("BungeeCord")) { + return; + } + if (targetServer().get().length() != 0) + return; + ByteArrayDataInput in = ByteStreams.newDataInput(message); + String subchannel = in.readUTF(); + if ("ChromaCore-Spawn".equals(subchannel)) { + // Use the code sample in the 'Response' sections below to read + // the data. + System.out.println("Heh nice"); + short len = in.readShort(); + byte[] msgbytes = new byte[len]; + in.readFully(msgbytes); + + try { + DataInputStream msgin = new DataInputStream(new ByteArrayInputStream(msgbytes)); + String somedata = msgin.readUTF(); // Read the data in the same way you wrote it + if (!"SendToSpawn".equals(somedata)) { + System.out.println("somedata: " + somedata); + return; + } + player.teleport(spawnloc); + } catch (IOException e) { + e.printStackTrace(); + } + } else + System.out.println("Subchannel: " + subchannel); + } + + /** + * Set to empty if this server is the target. + */ + private ConfigData targetServer() { + return getConfig().getData("targetServer", ""); + } + + private Location spawnloc; + + @CommandClass(helpText = { + "Spawn", + "Teleport to spawn." + }) + public class SpawnCommand extends ICommand2MC { + @SuppressWarnings("UnstableApiUsage") + @Command2.Subcommand + public void def(Player player) { + if (targetServer().get().length() == 0) { + player.sendMessage("§bTeleporting to spawn."); + player.teleport(spawnloc); + return; + } + ByteArrayDataOutput out = ByteStreams.newDataOutput(); + out.writeUTF("Connect"); + out.writeUTF(targetServer().get()); + + player.sendPluginMessage(getPlugin(), "BungeeCord", out.toByteArray()); + + Bukkit.getScheduler().runTask(getPlugin(), () -> { //Delay it a bit + ByteArrayDataOutput outt = ByteStreams.newDataOutput(); + outt.writeUTF("Forward"); // So BungeeCord knows to forward it + outt.writeUTF("ALL"); + outt.writeUTF("ChromaCore-Spawn"); // The channel name to check if this your data + + ByteArrayOutputStream msgbytes = new ByteArrayOutputStream(); + DataOutputStream msgout = new DataOutputStream(msgbytes); + try { + msgout.writeUTF("SendToSpawn"); // You can do anything you want with msgout + } catch (IOException exception) { + exception.printStackTrace(); + } + + outt.writeShort(msgbytes.toByteArray().length); + outt.write(msgbytes.toByteArray()); + + player.sendPluginMessage(getPlugin(), "BungeeCord", outt.toByteArray()); + }); + } + } +} diff --git a/ButtonCore/src/main/resources/plugin.yml b/ButtonCore/src/main/resources/plugin.yml index 29bfbb1..7b3d8bf 100755 --- a/ButtonCore/src/main/resources/plugin.yml +++ b/ButtonCore/src/main/resources/plugin.yml @@ -20,4 +20,5 @@ depend: - Vault softdepend: - Towny - - Votifier \ No newline at end of file + - Votifier + - Multiverse-Core \ No newline at end of file