gmoehra

(rmcStaff) - Bukkit / main

Jan 14th, 2022
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. package redeminecraft.staff.bukkit.main;
  2.  
  3. import com.google.common.io.ByteArrayDataInput;
  4. import com.google.common.io.ByteStreams;
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.entity.Player;
  7. import org.bukkit.plugin.java.JavaPlugin;
  8. import org.bukkit.plugin.messaging.PluginMessageListener;
  9.  
  10. public class Main extends JavaPlugin implements PluginMessageListener {
  11.  
  12. public Main plugin;
  13.  
  14. @Override
  15. public void onEnable() {
  16. plugin = this;
  17.  
  18. getServer().getMessenger().registerOutgoingPluginChannel(this, "Staff");
  19. getServer().getMessenger().registerIncomingPluginChannel(this, "Staff", this);
  20.  
  21. System.out.println("§c" + plugin.getDescription().getName() + " - Modo Bukkit habilitado.");
  22. }
  23.  
  24. private void debug(String message) {
  25. Bukkit.getConsoleSender().sendMessage("§a[rmcStaff] - " + message);
  26. }
  27.  
  28. public void onPluginMessageReceived(String channel, Player player, byte[] message) {
  29. if (!channel.equals("Staff")) return;
  30.  
  31. ByteArrayDataInput in = ByteStreams.newDataInput(message);
  32. String subChannel = in.readUTF();
  33.  
  34. if (subChannel.equals("promote")) {
  35. String data = in.readUTF();
  36. String office = data.split(";")[0];
  37. String target = data.split(";")[1];
  38.  
  39. if (Bukkit.getPlayer(target) != null) {
  40. sendCommand("lp user " + target + " parent set " + office);
  41. Bukkit.getPlayer(target).sendMessage("§a» §7Você foi promovido para: §f" + office + "§7.");
  42. }
  43. plugin.debug("§f" + target + " §efoi promovido para §f" + office);
  44. }
  45.  
  46. if (subChannel.equals("demote")) {
  47. String data = in.readUTF();
  48. String office = data.split(";")[0];
  49. String target = data.split(";")[1];
  50.  
  51. if (Bukkit.getPlayer(target) != null) {
  52. sendCommand("lp user " + target + " parent remove " + office);
  53. sendCommand("lp user " + target + " parent set normal");
  54. Bukkit.getPlayer(target).sendMessage("§c» §7Você foi demotado.");
  55. }
  56. plugin.debug("§f" + target + " §efoi demotado para §f" + "Membro");
  57. }
  58. }
  59.  
  60.  
  61. private void sendCommand(String command) {
  62. Bukkit.getScheduler().runTask(this, () -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command));
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment