Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
Signed-off-by: Blaumeise03 <[email protected]>
  • Loading branch information
Blaumeise03 committed Dec 2, 2020
1 parent cad7905 commit 0be596f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class BungeeMain extends Plugin {
@Override
public void onEnable() {
plugin = this;
getProxy().registerChannel(BLUE_UTILS_CHANNEL);
//ProxyServer.getInstance().getPluginManager().registerListener(this, new ChannelListener());
}

Expand Down
65 changes: 26 additions & 39 deletions src/main/java/de/blaumeise03/blueUtils/proxy/ChannelListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

package de.blaumeise03.blueUtils.proxy;

import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import de.blaumeise03.blueUtils.crossServer.ServerState;
import net.md_5.bungee.api.connection.Server;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.PluginMessageEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
Expand All @@ -18,49 +19,35 @@

import static de.blaumeise03.blueUtils.proxy.BungeeMain.BLUE_UTILS_CHANNEL;

@Deprecated
public class ChannelListener implements Listener {

@EventHandler
public void receive(PluginMessageEvent e) {
if (e.getTag().equalsIgnoreCase(BLUE_UTILS_CHANNEL + ":proxy")) {
if (e.getTag().equalsIgnoreCase(BLUE_UTILS_CHANNEL)) {
DataInputStream in = new DataInputStream(new ByteArrayInputStream(e.getData()));
try {
DataInputStream in = new DataInputStream(new ByteArrayInputStream(e.getData()));
String channel = in.readUTF(); // channel we delivered
BungeeMain.plugin.getLogger().info("Received message: " + channel);
if (channel.equals("setStatus")) {
//ServerInfo server = BungeeCord.getInstance().getPlayer(e.getReceiver().toString()).getServer().getInfo();
String serv = in.readUTF(); // the inputstring
String newState = in.readUTF();
boolean exist = false;
for (ServerState state : BungeeMain.plugin.serverStates) {
if (state.getServer().equalsIgnoreCase(serv)) {
state.setState(newState);
exist = true;
break;
}
String channel = in.readUTF();
if (channel.equals("tpPlayerToPlayer")) {
ServerInfo server = ProxyServer.getInstance().getPlayer(e.getReceiver().toString()).getServer().getInfo();
String pTarget = in.readUTF();
String pTo = in.readUTF();
ProxiedPlayer target = ProxyServer.getInstance().getPlayer(pTarget);
ProxiedPlayer executer = ProxyServer.getInstance().getPlayer(e.getReceiver().toString());
if (target == null) {
TextComponent text = new TextComponent("Couldn't teleport player \"" + pTarget + "\" to \"" + pTo + "\"! The player \"" + pTarget + "\" was not found on any server!");
executer.sendMessage(ChatMessageType.CHAT, text);
return;
}
if (!exist) {
BungeeMain.plugin.getLogger().info("Adding new Server!");
BungeeMain.plugin.serverStates.add(new ServerState(serv, newState));
}
BungeeMain.plugin.getLogger().info("Server: " + serv + " State: " + newState);
} else if (channel.equalsIgnoreCase("queryStatus")) {
if (!(e.getSender() instanceof Server)) return;
String server = in.readUTF();
for (ServerState state : BungeeMain.plugin.serverStates) {
if (state.getServer().equalsIgnoreCase(server)) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("statusResult");
out.writeUTF(state.getServer());
out.writeUTF(state.getState());
((Server) e.getSender()).sendData(BLUE_UTILS_CHANNEL + ":spigot", out.toByteArray());
break;
}
ProxiedPlayer to = ProxyServer.getInstance().getPlayer(pTo);
if (to == null) {
TextComponent text = new TextComponent("Couldn't teleport player \"" + pTarget + "\" to \"" + pTo + "\"! The player \"" + pTo + "\" was not found on any server!");
executer.sendMessage(ChatMessageType.CHAT, text);
return;
}

}
} catch (IOException e1) {
e1.printStackTrace();
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/de/blaumeise03/blueUtils/utils/PlayerUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.potion.PotionEffect;
import org.bukkit.util.Vector;

public class PlayerUtils {
Expand Down Expand Up @@ -34,5 +35,9 @@ public static void clearPlayer(Player player) {
pView.getTopInventory().clear();
player.setItemOnCursor(null);
player.updateInventory();
player.getActivePotionEffects()
.stream()
.map(PotionEffect::getType)
.forEach(player::removePotionEffect);
}
}

0 comments on commit 0be596f

Please sign in to comment.