本文整理汇总了Java中com.hm.mcshared.particle.PacketSender类的典型用法代码示例。如果您正苦于以下问题:Java PacketSender类的具体用法?Java PacketSender怎么用?Java PacketSender使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PacketSender类属于com.hm.mcshared.particle包,在下文中一共展示了PacketSender类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: displayReceiverMessages
import com.hm.mcshared.particle.PacketSender; //导入依赖的package包/类
/**
* Displays texts related to the achievement in the receiver's chat. This method can display a single hoverable
* message or several messages one after the other.
*
* @param player
* @param nameToShowUser
* @param messageToShowUser
* @param rewardTexts
*/
private void displayReceiverMessages(Player player, String nameToShowUser, String messageToShowUser,
List<String> rewardTexts) {
if (configHoverableReceiverChatText) {
StringBuilder hover = new StringBuilder(messageToShowUser + "\n");
rewardTexts.stream().filter(StringUtils::isNotBlank)
.forEach(t -> hover.append(ChatColor.translateAlternateColorCodes('&', t)).append("\n"));
String json = "{\"text\":\"" + langAchievementNew + nameToShowUser
+ "\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":[{\"text\":\""
+ hover.substring(0, hover.length() - 1) + "\"}]}}";
try {
PacketSender.sendChatMessagePacket(player, json);
return;
} catch (Exception e) {
plugin.getLogger().warning(
"Failed to display hoverable message for achievement reception. Displaying standard messages instead.");
}
}
player.sendMessage(langAchievementNew + nameToShowUser);
player.sendMessage(plugin.getChatHeader() + ChatColor.WHITE + messageToShowUser);
rewardTexts.stream().filter(StringUtils::isNotBlank).forEach(
t -> player.sendMessage(plugin.getChatHeader() + ChatColor.translateAlternateColorCodes('&', t)));
}
示例2: displayNotification
import com.hm.mcshared.particle.PacketSender; //导入依赖的package包/类
/**
* Displays an action bar message or chat notification to another player.
*
* @param achievementReceiver
* @param nameToShowUser
* @param otherPlayer
*/
private void displayNotification(Player achievementReceiver, String nameToShowUser, Player otherPlayer) {
if (configActionBarNotify) {
String actionBarJsonMessage = "{\"text\":\"&o"
+ StringUtils.replaceOnce(langAchievementReceived, "PLAYER", achievementReceiver.getName())
+ nameToShowUser + "\"}";
try {
PacketSender.sendActionBarPacket(otherPlayer, actionBarJsonMessage);
} catch (Exception e) {
plugin.getLogger()
.warning("Failed to display action bar message for achievement reception notification.");
}
} else {
otherPlayer.sendMessage(plugin.getChatHeader()
+ StringUtils.replaceOnce(langAchievementReceived, "PLAYER", achievementReceiver.getName())
+ nameToShowUser);
}
}
示例3: sendJsonClickableHoverableMessage
import com.hm.mcshared.particle.PacketSender; //导入依赖的package包/类
/**
* Sends a packet message to the server in order to display a clickable and hoverable message. A suggested command
* is displayed in the chat when clicked on, and an additional help message appears when a command is hovered.
*
* @param sender
* @param message
* @param command
* @param hover
*/
private void sendJsonClickableHoverableMessage(CommandSender sender, String message, String command, String hover) {
// Send clickable and hoverable message if sender is a player and if supported by the Minecraft version.
if (sender instanceof Player && plugin.getServerVersion() > 7) {
// Build the json format string.
String json = "{\"text\":\"" + message + "\",\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\""
+ command + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":[{\"text\":\"" + hover
+ "\",\"color\":\"" + configColor.name().toLowerCase() + "\"}]}}";
try {
PacketSender.sendChatMessagePacket((Player) sender, json);
} catch (Exception e) {
plugin.getLogger().warning(
"Failed to display clickable and hoverable message in /aach help command. Displaying standard message instead.");
sender.sendMessage(message);
}
} else {
sender.sendMessage(message);
}
}
示例4: sendJsonClickableHoverableMessage
import com.hm.mcshared.particle.PacketSender; //导入依赖的package包/类
/**
* Send a packet message to the server in order to display a clickable and hoverable message. A suggested command is
* displayed in the chat when clicked on, and an additional help message appears when a command is hovered.
*
* @param sender
* @param message
* @param command
* @param hover
*/
public void sendJsonClickableHoverableMessage(CommandSender sender, String message, String command, String hover) {
// Build the json format string.
String json = "{\"text\":\"" + message + "\",\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\""
+ command + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":[{\"text\":\"" + hover
+ "\",\"color\":\"blue\"}]}}";
// Send clickable and hoverable message if sender is a player and if no exception is caught.
if (sender instanceof Player) {
try {
PacketSender.sendChatMessagePacket((Player) sender, json);
} catch (Exception ex) {
plugin.getLogger().severe(
"Errors while trying to display clickable and hoverable message in /awf help command. Displaying standard message instead.");
sender.sendMessage(message);
}
} else {
sender.sendMessage(message);
}
}
示例5: sendJsonClickableHoverableMessage
import com.hm.mcshared.particle.PacketSender; //导入依赖的package包/类
/**
* Sends a packet message to the server in order to display a clickable and hoverable message. A suggested command
* is displayed in the chat when clicked on, and an additional help message appears when a command is hovered.
*
* @param sender
* @param message
* @param command
* @param hover
*/
public void sendJsonClickableHoverableMessage(CommandSender sender, String message, String command, String hover) {
// Send clickable and hoverable message if sender is a player and if no exception is caught.
if (sender instanceof Player) {
// Build the json format string.
String json = "{\"text\":\"" + message + "\",\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\""
+ command + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":[{\"text\":\"" + hover
+ "\",\"color\":\"gold\"}]}}";
try {
PacketSender.sendChatMessagePacket((Player) sender, json);
} catch (Exception ex) {
plugin.getLogger()
.severe("Errors while trying to display clickable and hoverable message in /petm help command. "
+ "Displaying standard message instead.");
sender.sendMessage(message);
}
} else {
sender.sendMessage(message);
}
}
示例6: displayActionBarMessage
import com.hm.mcshared.particle.PacketSender; //导入依赖的package包/类
/**
* Displays the cooldown action bar message.
*
* @param player
* @param actionBarJsonMessage
*/
private void displayActionBarMessage(Player player, String actionBarJsonMessage) {
try {
PacketSender.sendActionBarPacket(player, actionBarJsonMessage);
} catch (Exception e) {
plugin.getLogger().warning("Failed to display action bar message for cooldown.");
}
}
示例7: displayTitle
import com.hm.mcshared.particle.PacketSender; //导入依赖的package包/类
/**
* Displays title when receiving an achievement.
*
* @param player
* @param nameToShowUser
* @param messageToShowUser
*/
private void displayTitle(Player player, String nameToShowUser, String messageToShowUser) {
try {
// Escape quotations in case quotations are used in config.yml.
PacketSender.sendTitlePacket(player,
"{\"text\":\"" + StringUtils.replace(nameToShowUser, "\"", "\\\"") + "\"}",
"{\"text\":\"" + StringUtils.replace(messageToShowUser, "\"", "\\\"") + "\"}");
} catch (Exception e) {
plugin.getLogger().warning("Failed to display achievement screen title.");
}
}
示例8: onPlayerCommandPreprocessEvent
import com.hm.mcshared.particle.PacketSender; //导入依赖的package包/类
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerCommandPreprocessEvent(PlayerToggleFlightEvent event) {
if (plugin.isDisabled() || event.getPlayer().hasPermission("antiworldfly.fly")) {
return;
}
if (!this.plugin.isAntiFlyCreative() && event.getPlayer().getGameMode() == GameMode.CREATIVE
|| "SPECTATOR".equals(event.getPlayer().getGameMode().toString())) {
return;
}
Player player = event.getPlayer();
for (String world : plugin.getAntiFlyWorlds()) {
if (event.getPlayer().getWorld().getName().equalsIgnoreCase(world)) {
// Disable flying.
player.setAllowFlight(false);
player.getPlayer().setFlying(false);
event.setCancelled(true);
if (plugin.isChatMessage()) {
player.sendMessage(plugin.getChatHeader() + plugin.getPluginLang().getString("fly-disabled-chat",
"Flying is disabled in this world."));
}
if (plugin.isTitleMessage()) {
try {
PacketSender.sendTitlePacket(player, "{\"text\":\""
+ plugin.getPluginLang().getString("fly-disabled-title", "&9AntiWorldFly") + "\"}",
"{\"text\":\"" + plugin.getPluginLang().getString("fly-disabled-subtitle",
"Flying is disabled in this world.") + "\"}");
} catch (Exception e) {
plugin.getLogger().log(Level.SEVERE, "Errors while trying to display flying disabled title: ",
e);
}
}
break;
}
}
}
示例9: run
import com.hm.mcshared.particle.PacketSender; //导入依赖的package包/类
@Override
public void run() {
if (plugin.isDisabled() || player.hasPermission("antiworldfly.fly")) {
return;
}
if (!this.plugin.isAntiFlyCreative() && player.getGameMode() == GameMode.CREATIVE
|| "SPECTATOR".equals(player.getGameMode().toString())) {
return;
}
if (plugin.isChatMessage()
&& (plugin.isNotifyNotFlying() || !plugin.isNotifyNotFlying() && player.isFlying())) {
player.sendMessage(plugin.getChatHeader()
+ plugin.getPluginLang().getString("fly-disabled-chat", "Flying is disabled in this world."));
}
if (plugin.isTitleMessage()
&& (plugin.isNotifyNotFlying() || !plugin.isNotifyNotFlying() && player.isFlying())) {
try {
PacketSender.sendTitlePacket(player,
"{\"text\":\"" + plugin.getPluginLang().getString("fly-disabled-title", "&9AntiWorldFly")
+ "\"}",
"{\"text\":\"" + plugin.getPluginLang().getString("fly-disabled-subtitle",
"Flying is disabled in this world.") + "\"}");
} catch (Exception e) {
plugin.getLogger().log(Level.SEVERE, "Errors while trying to display flying disabled title: ", e);
}
}
// Disable flying.
player.setAllowFlight(false);
player.setFlying(false);
}