本文整理汇总了Java中cn.nukkit.event.player.PlayerChatEvent.setCancelled方法的典型用法代码示例。如果您正苦于以下问题:Java PlayerChatEvent.setCancelled方法的具体用法?Java PlayerChatEvent.setCancelled怎么用?Java PlayerChatEvent.setCancelled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cn.nukkit.event.player.PlayerChatEvent
的用法示例。
在下文中一共展示了PlayerChatEvent.setCancelled方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onChat
import cn.nukkit.event.player.PlayerChatEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onChat(final PlayerChatEvent event) {
// Substitute variable - thread safe
String level = "";
if (playerLevels.containsKey(event.getPlayer())) {
level = playerLevels.get(event.getPlayer());
}
String format = event.getFormat().replace("{ISLAND_LEVEL}", level);
event.setFormat(format);
if (Settings.teamChat && teamChatUsers.containsKey(event.getPlayer())) {
// Cancel the event
event.setCancelled(true);
// Queue the sync task because you cannot use HashMaps asynchronously. Delaying to the next tick
// won't be a major issue for synch events either.
Server.getInstance().getScheduler().scheduleTask(plugin, () -> {
teamChat(event, event.getMessage());
});
}
}
示例2: onPlayerChat
import cn.nukkit.event.player.PlayerChatEvent; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true,priority = EventPriority.LOWEST)
public void onPlayerChat(PlayerChatEvent event) {
String message = event.getMessage();
if (message.charAt(0) == '.') {
String[] split = event.getMessage().split(" ");
if (split.length > 0) {
split[0] = split[0].substring(1).replace('.', '/');
CommandManager cmdMan = WorldEdit.getInstance().getPlatformManager().getCommandManager();
split = cmdMan.commandDetection(split);
CommandEvent cmdEvent = new CommandEvent(plugin.wrapCommandSender(event.getPlayer()), Joiner.on(" ").join(Arrays.asList(split)));
if (cmdMan.getDispatcher().contains(split[0])) {
WorldEdit.getInstance().getEventBus().post(cmdEvent);
event.setCancelled(true);
}
}
}
}
示例3: onChat
import cn.nukkit.event.player.PlayerChatEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST)
public void onChat(PlayerChatEvent event) {
Player player = event.getPlayer();
String msg = event.getMessage();
CheckChat checkChat = new CheckChat(player, msg);
CheckWords checkWords = new CheckWords(player, msg);
if (AntiCheatAPI.getInstance().getMasterConfig().getCheckChat() && checkChat.isCheat()) {
AntiCheatAPI.getInstance().addRecord(player, checkChat.getCheatType());
player.sendMessage(TextFormat.RED + "You chat faster than predetermined value.");
event.setCancelled();
}
if (AntiCheatAPI.getInstance().getMasterConfig().getCheckChatWord() && checkWords.isCheat()) {
event.setMessage(checkWords.ChangeMessage());
}
}
示例4: onChat
import cn.nukkit.event.player.PlayerChatEvent; //导入方法依赖的package包/类
@EventHandler
public void onChat(PlayerChatEvent event){
if(!this.manager.isAuthenticated(event.getPlayer())){
event.setCancelled();
this.sendLoginMessage(event.getPlayer());
}
}
示例5: onChat
import cn.nukkit.event.player.PlayerChatEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onChat(PlayerChatEvent event) {
PlotPlayer plotPlayer = NukkitUtil.getPlayer(event.getPlayer());
Location location = plotPlayer.getLocation();
PlotArea area = location.getPlotArea();
if (area == null || (area.PLOT_CHAT == plotPlayer.getAttribute("chat"))) {
return;
}
Plot plot = area.getPlot(location);
if (plot == null) {
return;
}
event.setCancelled(true);
String message = event.getMessage();
String format = C.PLOT_CHAT_FORMAT.s();
String sender = event.getPlayer().getDisplayName();
PlotId id = plot.getId();
Set<CommandSender> recipients = event.getRecipients();
recipients.clear();
for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
PlotPlayer pp = entry.getValue();
if (pp.getAttribute("chatspy")) {
String spy = event.getFormat();
spy = String.format(spy, sender, message);
pp.sendMessage(spy);
} else {
Plot current = pp.getCurrentPlot();
if (current != null && current.getBasePlot(false).equals(plot)) {
recipients.add(((NukkitPlayer) pp).player);
}
}
}
String partial = C.color(format.replace("%plot_id%", id.x + ";" + id.y).replace("%sender%", sender));
String full = partial.replace("%msg%", message);
for (CommandSender receiver : recipients) {
receiver.sendMessage(full);
}
}