public static void teleportUser(Player player, String targetServer, int ticketId) throws IOException { if (!ReportRTS.getPlugin().bungeeCordSupport || player == null || serverName == null) return; ByteArrayOutputStream b = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(b); out.writeUTF("Forward"); out.writeUTF(targetServer); out.writeUTF("ReportRTS"); ByteArrayOutputStream msgbytes = new ByteArrayOutputStream(); DataOutputStream msgout = new DataOutputStream(msgbytes); msgout.writeUTF("TeleportNotify"); msgout.writeInt(ticketId); msgout.writeUTF(player.getName()); out.writeShort(msgbytes.toByteArray().length); out.write(msgbytes.toByteArray()); player.sendPluginMessage(ReportRTS.getPlugin(), "BungeeCord", b.toByteArray()); // Teleport ByteArrayOutputStream b1 = new ByteArrayOutputStream(); DataOutputStream out1 = new DataOutputStream(b1); out1.writeUTF("Connect"); out1.writeUTF(targetServer); out1.writeShort(msgbytes.toByteArray().length); out1.write(msgbytes.toByteArray()); player.sendPluginMessage(ReportRTS.getPlugin(), "BungeeCord", b1.toByteArray()); }
@Override public void sendPluginMessage(Plugin source, String channel, byte[] message) { StandardMessenger.validatePluginMessage(getMessenger(), source, channel, message); for (Player player : getOnlinePlayers()) { player.sendPluginMessage(source, channel, message); } }
public static void notifyUser(String username, String message, int ticketId) throws IOException { if (!ReportRTS.getPlugin().bungeeCordSupport || serverName == null) return; String serverPrefix = (ReportRTS.getPlugin().bungeeCordServerPrefix == null || ReportRTS.getPlugin().bungeeCordServerPrefix.equals("") ? "[" + serverName + "]" : Message.parseColors(ReportRTS.getPlugin().bungeeCordServerPrefix)); ByteArrayOutputStream b = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(b); out.writeUTF("Forward"); out.writeUTF("ALL"); out.writeUTF("ReportRTS"); ByteArrayOutputStream msgbytes = new ByteArrayOutputStream(); DataOutputStream msgout = new DataOutputStream(msgbytes); msgout.writeUTF("NotifyUserAndSync"); msgout.writeInt(ticketId); msgout.writeUTF(username); msgout.writeUTF(serverPrefix + " " + message); out.writeShort(msgbytes.toByteArray().length); out.write(msgbytes.toByteArray()); Player player = (Bukkit.getOnlinePlayers().length == 0 ? null : Bukkit.getOnlinePlayers()[0]); if (player != null) { player.sendPluginMessage(ReportRTS.getPlugin(), "BungeeCord", b.toByteArray()); } else { pendingRequests.add(b.toByteArray()); } }
private void sendMessage(Player player, String[] message, String channel) { ByteArrayDataOutput out = ByteStreams.newDataOutput(); for (int i = 0; i < message.length; ++i) { out.writeUTF(message[i]); } player.sendPluginMessage(plugin, channel, out.toByteArray()); }
public static void processPendingRequests() { if (!pendingRequests.isEmpty()) { for (byte[] toSend : pendingRequests) { Player player = Bukkit.getOnlinePlayers()[0]; if (player != null) { player.sendPluginMessage(ReportRTS.getPlugin(), "BungeeCord", toSend); pendingRequests.remove(toSend); } else { break; } } } }
public void msg(String player, String msg) { ByteArrayOutputStream b = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(b); try { out.writeUTF("Message"); out.writeUTF(player); out.writeUTF( ChatColor.translateAlternateColorCodes("&".charAt(0), "&6[&bDD&2Votes&6] " + msg)); } catch (IOException e) { e.printStackTrace(); } Player p = Bukkit.getOnlinePlayers()[0]; p.sendPluginMessage(plugin, "BungeeCord", b.toByteArray()); }
@EventHandler public void onPlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); for (Portal portal : ConfigPortals.portals) { if (portal.containsBlock(player.getLocation()) && player.hasPermission(portal.getPermission())) { player.teleport(player.getWorld().getSpawnLocation()); ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF("Connect"); out.writeUTF(portal.getServer()); player.sendPluginMessage(Main.getInstance(), "BungeeCord", out.toByteArray()); } } }
/** * Sends a {@link Player} to a specific bungee server. <br> * The one and only case where the returned boolean would be false is if the {@code player} was * already being sent within the {@link #getConnectCooldown()} ticks. * * @param player player to send * @param serverName bungee server to send player to * @return whether the player is being sent to the specified {@code serverName}. */ public boolean sendPlayerTo(final Player player, String serverName) { Preconditions.checkState(getState().equals(State.ACTIVE), "Bungee module not active."); Long previous = this.connecting.get(player.getUniqueId()); // below, connectCooldown is being converted from minecraft ticks to milliseconds if (previous != null && previous < System.currentTimeMillis() + (this.connectCooldown * 50)) { return false; } ByteArrayOutputStream bout = new ByteArrayOutputStream(); try (DataOutputStream out = new DataOutputStream(bout)) { out.writeUTF("Connect"); out.writeUTF(serverName); } catch (IOException e) { throw new RuntimeException(e); } player.sendPluginMessage(this.plugin, "BungeeCord", bout.toByteArray()); this.connecting.put(player.getUniqueId(), System.currentTimeMillis()); return true; }
public static String getServer() { if (!ReportRTS.getPlugin().bungeeCordSupport) { return ""; } if (serverName != null) { return serverName; } else { Player player = Bukkit.getOnlinePlayers()[0]; ByteArrayOutputStream b = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(b); try { out.writeUTF("GetServer"); } catch (IOException e) { e.printStackTrace(); } if (player != null) { player.sendPluginMessage(ReportRTS.getPlugin(), "BungeeCord", b.toByteArray()); } else { pendingRequests.add(b.toByteArray()); } } return ""; }
/** * Sets the player's current texture pack * * @param player The player whose texture pack is being set * @param pack The name of the texture pack */ public void setPack(Player player, String pack) { try { String url; if (pack == null || (url = packs.get(pack)) == null) { getPlayers().set(player.getName().toLowerCase(), null); savePlayers(); return; } player.setTexturePack(url); String message = "You have selected the " + ChatColor.GREEN + pack + ChatColor.RESET + " pack."; if (player.getListeningPluginChannels().contains("SimpleNotice")) { player.sendPluginMessage( this, "SimpleNotice", message.getBytes(java.nio.charset.Charset.forName("UTF-8"))); } else { player.sendMessage(message); } getPlayers().set(player.getName().toLowerCase(), pack); savePlayers(); } catch (IllegalArgumentException e) { player.sendMessage(ChatColor.RED + "The supplied pack name was invalid."); warn(e.getLocalizedMessage()); } }
@EventHandler(priority = EventPriority.MONITOR) public void guiClick(InventoryClickEvent event) { invetaryname = event.getInventory().getName(); p = ((Player) event.getWhoClicked()); if (!invetaryname.contains("§6\u2739 §d§lCommande Générales §6\u2739")) return; if ((event.getSlot() < 0) || (event.getSlot() > 53)) return; event.setCancelled(true); if ((event.getCurrentItem().getType() == Material.STAINED_GLASS) && (event.getCurrentItem().getDurability() == 0)) { ByteArrayOutputStream b = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(b); p.closeInventory(); try { out.writeUTF("Connect"); out.writeUTF("lobby"); } catch (IOException ex) { } p.sendPluginMessage(crea.plugin, "BungeeCord", b.toByteArray()); } if ((event.getCurrentItem().getType() == Material.STAINED_GLASS) && (event.getCurrentItem().getDurability() == 1)) { p.closeInventory(); p.performCommand("spawn"); } if ((event.getCurrentItem().getType() == Material.STAINED_GLASS) && (event.getCurrentItem().getDurability() == 2)) { p.closeInventory(); p.performCommand("list"); } if ((event.getCurrentItem().getType() == Material.STAINED_GLASS) && (event.getCurrentItem().getDurability() == 3)) { p.closeInventory(); p.performCommand("stats"); } if ((event.getCurrentItem().getType() == Material.STAINED_GLASS) && (event.getCurrentItem().getDurability() == 4)) { p.closeInventory(); p.performCommand("ci"); } if ((event.getCurrentItem().getType() == Material.STAINED_GLASS) && (event.getCurrentItem().getDurability() == 5)) { p.closeInventory(); if (p.hasPermission("crea.journuit")) crea.plugin .getServer() .dispatchCommand( crea.plugin.getServer().getConsoleSender(), "ptime day " + p.getName()); else p.sendMessage("§cVous devez avoir le grade Maçon ou +"); } if ((event.getCurrentItem().getType() == Material.STAINED_GLASS) && (event.getCurrentItem().getDurability() == 6)) { p.closeInventory(); if (p.hasPermission("crea.journuit")) crea.plugin .getServer() .dispatchCommand( crea.plugin.getServer().getConsoleSender(), "ptime night " + p.getName()); else p.sendMessage("§cVous devez avoir le grade Maçon ou +"); } if ((event.getCurrentItem().getType() == Material.STAINED_GLASS) && (event.getCurrentItem().getDurability() == 7)) { p.closeInventory(); if (p.hasPermission("crea.speed")) crea.plugin .getServer() .dispatchCommand( crea.plugin.getServer().getConsoleSender(), "speed fly 2 " + p.getName()); else p.sendMessage("§cVous devez avoir le grade Décorateur ou +"); } if ((event.getCurrentItem().getType() == Material.STAINED_GLASS) && (event.getCurrentItem().getDurability() == 8)) { p.closeInventory(); p.performCommand("tpyes"); } if ((event.getCurrentItem().getType() == Material.STAINED_GLASS) && (event.getCurrentItem().getDurability() == 9)) { p.closeInventory(); p.performCommand("tpno"); } if ((event.getCurrentItem().getType() == Material.STAINED_GLASS) && (event.getCurrentItem().getDurability() == 10)) { // p.closeInventory(); // p.performCommand(""); } if ((event.getCurrentItem().getType() == Material.STAINED_GLASS) && (event.getCurrentItem().getDurability() == 11)) { // p.closeInventory(); // p.performCommand(""); } if ((event.getCurrentItem().getType() == Material.STAINED_GLASS) && (event.getCurrentItem().getDurability() == 12)) { p.closeInventory(); p.performCommand("back"); } if ((event.getCurrentItem().getType() == Material.STAINED_GLASS) && (event.getCurrentItem().getDurability() == 13)) { // p.closeInventory(); // p.performCommand(""); } if ((event.getCurrentItem().getType() == Material.STAINED_GLASS) && (event.getCurrentItem().getDurability() == 14)) { // p.closeInventory(); // p.performCommand(""); } if (event.getCurrentItem().getType() == Material.WOOD_DOOR) { p.playSound(p.getLocation(), Sound.DOOR_OPEN, 2.0F, 13.0F); p.closeInventory(); p.openInventory(menu.displayGUImenu()); } }
@Override public boolean onCommand(CommandSender sender, Command command, String name, String[] args) { switch (command.getName().toLowerCase()) { case "spawn": if (sender instanceof Player) { ((Player) sender).teleport(config.spawn.LOCATION); sender.sendMessage(ChatColor.RED + "Wooosh!"); } else { sender.sendMessage(ChatColor.RED + "Only usable by players, sorry!"); } break; case "o3-reload": config.reload(); sender.sendMessage(String.format("%sDone.", ChatColor.RED)); break; case "world": if (args.length == 0) return false; if (!(args.length == 4 || args.length == 1)) return false; if (!(sender instanceof Player)) { sender.sendMessage("Only usable by players"); return false; } World world = getServer().getWorld(args[0]); if (world == null) { sender.sendMessage( "This world doesn't exist. Try 'world', 'world_nether', or 'world_the_end'"); return true; } if (args.length == 4) { ((Player) sender) .teleport( new Location( world, Double.parseDouble(args[1]), Double.parseDouble(args[2]), Double.parseDouble(args[3]))); } else { ((Player) sender).teleport(world.getSpawnLocation()); } break; case "coords": if (sender instanceof Player) { Location loc = ((Player) sender).getLocation(); sender.sendMessage( String.format( "%sx: %d %sy: %d %sz: %d", ChatColor.RED, loc.getBlockX(), ChatColor.BLUE, loc.getBlockY(), ChatColor.AQUA, loc.getBlockZ())); } else { sender.sendMessage( String.format("%sThis command is only usable by players", ChatColor.RED)); } break; case "item": if (sender instanceof Player) { Player player = (Player) sender; if (args.length < 1 || args.length > 2) return false; String blockID = ""; String blockData = ""; String amount = "64"; if (args[0].contains(":")) { String[] temp = args[0].split(":"); blockID = temp[0]; blockData = temp[1]; } else { blockID = args[0]; } if (args.length == 2) { amount = args[1]; } getServer() .dispatchCommand( player, String.format("give %s %s %s %s", player.getName(), blockID, amount, blockData)); } else { sender.sendMessage( String.format("%sThis command is only usable by players", ChatColor.RED)); } break; case "staffchest": getServer().dispatchCommand(sender, "cmodify g:base_assistance"); break; case "unstaff": getServer().dispatchCommand(sender, "cmodify -g:base_assistance"); break; case "trace": if (args.length < 1 || args.length > 2) { return false; } else if (args.length == 1) { getServer() .dispatchCommand( sender, String.format( "lb lookup player %s sum blocks block 1 block 56 block 14 block 129", args[0])); } else if (args.length == 2) { getServer() .dispatchCommand( sender, String.format( "lb lookup player %s sum blocks block 1 block 56 block 14 block 129 since %s days", args[0], args[1])); } break; case "tppos": if (args.length == 4) { getServer() .dispatchCommand( sender, String.format("world %s %s %s %s", args[0], args[1], args[2], args[3])); } else if (args.length == 3) { getServer() .dispatchCommand(sender, String.format("tp %s %s %s", args[0], args[1], args[2])); } else { return false; } break; case "entity-magnet": if (args.length != 2) { return false; } else { if (sender instanceof Player) { Player player = (Player) sender; EntityType entityType = null; try { entityType = EntityType.valueOf(args[0].toUpperCase()); } catch (Exception e) { player.sendMessage("Entity type does not exist"); return true; } double range = 0; if (range > 50) { sender.sendMessage( "You don't have enough power! Entity magnet only works up to 50 blocks away."); return true; } if (blockedEntities.contains(entityType)) { sender.sendMessage("Magnet doesn't work on this block :("); return true; } try { range = Double.parseDouble(args[1]) / 2; } catch (Exception e) { player.sendMessage("Invalid range"); return true; } for (Entity e : player.getNearbyEntities(range, range, range)) { if (e.getType().equals(entityType)) { e.teleport(player); } } } } break; case "swap-player": if (args.length != 2) { return false; } Player p = getServer().getPlayer(args[0]); bungeePluginChannel = new DataOutputStream(new ByteArrayOutputStream()); ByteArrayOutputStream b = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(b); try { out.writeUTF("Connect"); out.writeUTF(args[1]); p.sendPluginMessage(this, "BungeeCord", b.toByteArray()); } catch (Exception e) { e.printStackTrace(); } break; case "give-pet": if (sender instanceof Player) { Player player = (Player) sender; if (args.length == 1) { if (getServer().getPlayer(args[0]) != null) { player.setMetadata("give-pet", new FixedMetadataValue(this, args[0])); player.sendMessage( "Right click the pet you want to give away. This cannot be undone"); } else { player.sendMessage("This player is not online"); } } else { return false; } } break; case "thor": if (args.length == 1) { Player player = getServer().getPlayer(args[0]); if (player == null) return false; player.getWorld().strikeLightning(player.getLocation()); player.setHealth(0); sender.sendMessage( String.format( "%sThou hast smote the evil player %s with thy mighty hand.", ChatColor.LIGHT_PURPLE, player.getDisplayName())); player.sendMessage( String.format("%sYou have been smote by Thor's Hammer!", ChatColor.RED)); getServer() .dispatchCommand( sender, String.format( "transmission:staffchat I have smitten %s", player.getDisplayName())); } else { return false; } break; case "lsd": for (int j = 0; j < 10; j++) { StringBuilder lsd = new StringBuilder(); for (int i = 0; i < 40; i++) { lsd.append(colors.get(rand.nextInt(colors.size()))); lsd.append(ChatColor.MAGIC); lsd.append('x'); } sender.sendMessage(String.format("%s%s", ChatColor.MAGIC, lsd.toString())); } if (sender instanceof Player) { Player player = (Player) sender; player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 600, 1)); } break; } return true; }