-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added forward command from Bukkit to BungeeCord
- Loading branch information
Showing
13 changed files
with
150 additions
and
84 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
73 changes: 0 additions & 73 deletions
73
.../main/java/com/github/games647/changeskin/bungee/listener/PermissionsMessageListener.java
This file was deleted.
Oops, something went wrong.
85 changes: 85 additions & 0 deletions
85
...e/src/main/java/com/github/games647/changeskin/bungee/listener/PluginMessageListener.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,85 @@ | ||
package com.github.games647.changeskin.bungee.listener; | ||
|
||
import com.github.games647.changeskin.bungee.ChangeSkinBungee; | ||
import com.github.games647.changeskin.core.SkinData; | ||
import com.github.games647.changeskin.core.UserPreference; | ||
import com.google.common.io.ByteArrayDataInput; | ||
import com.google.common.io.ByteStreams; | ||
|
||
import java.util.UUID; | ||
|
||
import net.md_5.bungee.api.ProxyServer; | ||
import net.md_5.bungee.api.connection.ProxiedPlayer; | ||
import net.md_5.bungee.api.event.PluginMessageEvent; | ||
import net.md_5.bungee.event.EventHandler; | ||
|
||
public class PluginMessageListener extends AbstractSkinListener { | ||
|
||
public PluginMessageListener(ChangeSkinBungee plugin) { | ||
super(plugin); | ||
} | ||
|
||
@EventHandler | ||
public void onPluginMessage(PluginMessageEvent messageEvent) { | ||
String channel = messageEvent.getTag(); | ||
if (messageEvent.isCancelled() || !plugin.getDescription().getName().equals(channel)) { | ||
return; | ||
} | ||
|
||
ByteArrayDataInput dataInput = ByteStreams.newDataInput(messageEvent.getData()); | ||
String subChannel = dataInput.readUTF(); | ||
|
||
ProxiedPlayer invoker = (ProxiedPlayer) messageEvent.getReceiver(); | ||
if ("PermissionsSuccess".equals(subChannel)) { | ||
onPermissionSuccess(dataInput, invoker); | ||
} else if ("PermissionsFailure".equals(subChannel)) { | ||
plugin.sendMessage(invoker, "no-permission"); | ||
} else if ("ForwardCmd".equals(subChannel)) { | ||
onCommandForward(invoker, dataInput); | ||
} | ||
} | ||
|
||
private void onPermissionSuccess(ByteArrayDataInput dataInput, ProxiedPlayer invoker) { | ||
int skinId = dataInput.readInt(); | ||
|
||
String encodedData = dataInput.readUTF(); | ||
String encodedSignature = dataInput.readUTF(); | ||
final SkinData targetSkin = new SkinData(encodedData, encodedSignature); | ||
targetSkin.setSkinId(skinId); | ||
|
||
UUID receiverUUID = UUID.fromString(dataInput.readUTF()); | ||
ProxiedPlayer receiver = ProxyServer.getInstance().getPlayer(receiverUUID); | ||
if (receiver == null || !receiver.isConnected()) { | ||
//receiver is not online cancel | ||
return; | ||
} | ||
|
||
//add cooldown | ||
plugin.addCooldown(invoker.getUniqueId()); | ||
//Save the target uuid from the requesting player source | ||
final UserPreference preferences = plugin.getStorage().getPreferences(receiver.getUniqueId()); | ||
preferences.setTargetSkin(targetSkin); | ||
|
||
ProxyServer.getInstance().getScheduler().runAsync(plugin, new Runnable() { | ||
@Override | ||
public void run() { | ||
if (plugin.getStorage().save(targetSkin)) { | ||
plugin.getStorage().save(preferences); | ||
} | ||
} | ||
}); | ||
|
||
if (plugin.getConfig().getBoolean("instantSkinChange")) { | ||
plugin.applySkin(receiver, targetSkin); | ||
plugin.sendMessage(invoker, "skin-changed"); | ||
} else { | ||
plugin.sendMessage(invoker, "skin-changed-no-instant"); | ||
} | ||
} | ||
|
||
private void onCommandForward(ProxiedPlayer invoker, ByteArrayDataInput dataInput) { | ||
String commandName = dataInput.readUTF(); | ||
String args = dataInput.readUTF(); | ||
ProxyServer.getInstance().getPluginManager().dispatchCommand(invoker, commandName + ' ' + args); | ||
} | ||
} |
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
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
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
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