本文整理汇总了Java中net.engio.mbassy.listener.Handler类的典型用法代码示例。如果您正苦于以下问题:Java Handler类的具体用法?Java Handler怎么用?Java Handler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Handler类属于net.engio.mbassy.listener包,在下文中一共展示了Handler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleEvents
import net.engio.mbassy.listener.Handler; //导入依赖的package包/类
@Handler
public void handleEvents(ISignedEventStreamEntry evSE) {
ISignedEvent ev = evSE.get();
if (!RoomEventType.Aliases.is(ev.getType())) {
return;
}
if (!StringUtils.equals(global.getDomain(), ev.getOrigin())) {
return;
}
List<String> newAliases = new ArrayList<>(new RoomAliasEvent(ev).getAliases());
log.info("Processing new aliases of room {}: {}", ev.getRoomId(), newAliases);
List<String> oldAliases = new ArrayList<>(idToAliases.getOrDefault(ev.getRoomId(), Collections.emptyList()));
oldAliases.removeAll(newAliases);
idToAliases.put(ev.getRoomId(), Collections.unmodifiableList(newAliases));
newAliases.forEach(a -> mappings.put(a, ev.getRoomId()));
oldAliases.forEach(alias -> mappings.remove(alias));
}
示例2: onClientConnected
import net.engio.mbassy.listener.Handler; //导入依赖的package包/类
@Handler
private void onClientConnected(ClientConnectedEvent event) {
if (configs.containsKey(PASSWORD_KEY)) {
AuthManager auth = client.getAuthManager();
auth.addProtocol(new SaslPlain(client,
client.getIntendedNick(), configs.get(PASSWORD_KEY)));
}
for (String channel : channels) {
try {
client.addChannel(channel);
logger.info("Joined '{}'", channel);
} catch (IllegalArgumentException e) {
logger.error("Invalid channel name '{}' on '{}'.",
channel,
configs.get(HOST_KEY), e);
}
}
}
示例3: handleThrowable
import net.engio.mbassy.listener.Handler; //导入依赖的package包/类
@Handler
public void handleThrowable(ThrowableEvent event) {
Platform.runLater(() -> {
TitledPane pane = new TitledPane();
pane.setId("stacktrace");
pane.setCollapsible(false);
pane.setText("Stacktrace");
TextArea textArea = new TextArea();
textArea.setEditable(false);
pane.setContent(textArea);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
event.getThrowable().printStackTrace(new PrintStream(baos));
textArea.setText(baos.toString());
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error");
alert.setHeaderText("An unexpected error occurred");
alert.getDialogPane().setContent(pane);
alert.showAndWait();
});
}
示例4: handleThrowable
import net.engio.mbassy.listener.Handler; //导入依赖的package包/类
@Handler
public void handleThrowable(ThrowableEvent event) {
Platform.runLater(() -> {
TitledPane pane = new TitledPane();
pane.setCollapsible(false);
pane.setText("Stacktrace");
TextArea textArea = new TextArea();
textArea.setEditable(false);
pane.setContent(textArea);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
event.getThrowable().printStackTrace(new PrintStream(baos));
textArea.setText(baos.toString());
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error");
alert.setHeaderText("An unexpected error occurred");
alert.getDialogPane().setContent(pane);
alert.showAndWait();
});
}
示例5: onPlayerJoinTeam
import net.engio.mbassy.listener.Handler; //导入依赖的package包/类
@Handler(priority = Priority.HIGHER)
public void onPlayerJoinTeam(PlayerJoinTeamEvent event) {
if (event.isCanceled()) {
return;
}
GamePlayer player = event.getGamePlayer();
for (TeamLockRule rule : this.rules) {
FilterResult result = rule.getFilter().filter(event.getPlayer(), player, this.teams, this.teams.getMatch());
if (result.equals(FilterResult.DENY)) {
event.setCanceled(true);
String message = rule.getMessage();
if (message != null) {
player.sendError(message);
} else {
player.sendError("You can't join this game right now.");
}
break;
}
}
}
示例6: onMatchStartCountdown
import net.engio.mbassy.listener.Handler; //导入依赖的package包/类
@Handler(priority = Priority.HIGHER)
public void onMatchStartCountdown(MatchStartCountdownEvent event) {
if (!this.getMatch().isStarting() ||
this.getPlugin().getGames().getCycleCountdown().isTaskRunning() ||
this.getPlugin().getGames().getRestartCountdown().isTaskRunning()) {
event.setCanceled(true);
return;
}
boolean idle = false;
for (Team team : this.getTeams()) {
if (team.isParticipating() && team.getOnlineMembers().size() < team.getMinPlayers()) {
idle = true;
break;
}
}
if (!this.getMatch().isForceStart() && idle) {
event.setCanceled(true);
}
}
示例7: onPlayerJoinGame
import net.engio.mbassy.listener.Handler; //导入依赖的package包/类
@Handler(priority = Priority.NORMAL)
public void onPlayerJoinGame(GameCommands.JoinCommandEvent event) {
if (event.isCanceled()) {
return;
}
try {
Team team = this.getTeam(event.getJoinGamePlayer());
if (team != null && !team.equals(this.getMatch().getObservers()) && this.getMatch().isRunning()) {
throw new CommandException("You are already in the game.");
} else if (event.isAuto()) {
this.autoJoinTeam(event.getJoinGamePlayer());
} else {
this.joinTeam(event.getJoinGamePlayer(), event.getContext().getParams(0));
}
event.setJoined(true);
} catch (CommandException ex) {
if (ex.getMessage() != null) {
event.getSender().sendError(ex.getMessage());
}
event.setJoined(false);
event.setCanceled(true);
}
}
示例8: onPlayerLeaveGame
import net.engio.mbassy.listener.Handler; //导入依赖的package包/类
@Handler(priority = Priority.HIGH)
public void onPlayerLeaveGame(GameCommands.LeaveCommandEvent event) {
try {
Team team = this.getTeam(event.getLeaveGamePlayer());
if (team != null && team.equals(this.getMatch().getObservers())) {
throw new CommandException("You are not in the game.");
}
this.joinTeam(event.getLeaveGamePlayer(), this.getMatch().getObservers(), true);
} catch (CommandException ex) {
if (ex.getMessage() != null) {
event.getSender().sendError(ex.getMessage());
} else {
event.getSender().sendError("Could not join observers right now. Please try again later.");
}
}
}
示例9: onChannelSpy
import net.engio.mbassy.listener.Handler; //导入依赖的package包/类
@Handler(priority = Priority.LAST)
public void onChannelSpy(ChannelMessageEvent event) {
if (event.isCanceled() ||
event.getChannel() instanceof GlobalChatChannel) {
return;
}
String message = ChatColor.DARK_AQUA + ChatColor.ITALIC.toString() +
"[Spy]" + ChatColor.RESET + " " + ChatColor.GRAY +
event.getAuthorName() + ChatColor.RESET +
ChatColor.GRAY + ": " + event.getMessage();
for (ArcadePlayer online : this.game.getPlugin().getPlayers()) {
GamePlayer player = online.getGamePlayer();
if (player == null || event.getChannel().hasMember(player)) {
continue;
}
if (player.hasPermission(CHANNEL_SPY_PERMISSION) &&
!player.isParticipating()) {
player.sendChat(message);
}
}
}
示例10: onCycleCountdownAutoStart
import net.engio.mbassy.listener.Handler; //导入依赖的package包/类
@Handler(priority = Priority.LOWEST)
public void onCycleCountdownAutoStart(MatchEndedEvent event) {
if (!this.isAutoCycle()) {
// auto cycle is disabled
return;
}
GameManager games = event.getPlugin().getGames();
Countdown countdown;
if (games.isNextRestart()) {
countdown = games.getRestartCountdown();
if (!countdown.isTaskRunning()) {
((RestartCountdown) countdown).setDefaultDuration();
}
} else {
countdown = games.getCycleCountdown();
if (!countdown.isTaskRunning()) {
((CycleCountdown) countdown).setDefaultDuration();
}
}
if (!countdown.isTaskRunning()) {
countdown.countSync();
}
}
示例11: onMatchTimeDescribe
import net.engio.mbassy.listener.Handler; //导入依赖的package包/类
@Handler(priority = Priority.NORMAL)
public void onMatchTimeDescribe(GameCommands.GameCommandEvent event) {
Time time = Time.ZERO;
switch (this.getMatch().getState()) {
case RUNNING:
time = Time.now().minus(Time.of(this.getMatch().getStartTime()));
break;
case CYCLING:
time = Time.of(this.getMatch().getTime());
break;
default:
break;
}
event.getSender().send(ChatColor.GREEN + "Time: " + ChatColor.DARK_AQUA + TimeUtils.prettyTime(time));
}
示例12: detectLiquidFlow
import net.engio.mbassy.listener.Handler; //导入依赖的package包/类
@Handler(priority = Priority.HIGHER)
public void detectLiquidFlow(BlockTransformEvent event) {
if (event.isCanceled()) {
return;
}
Liquid liquid = this.getLiquid();
if (liquid.accepts(event.getNewState().getMaterial())) {
return;
}
if (this.getSnapshot().contains(event.getBlock())) {
event.setCanceled(true);
if (event.hasPlayer()) {
event.getPlayer().sendError("You may not build inside " + ChatColor.GOLD +
this.getColoredName() + Messageable.ERROR_COLOR + ".");
}
}
}
示例13: onGameDestroyed
import net.engio.mbassy.listener.Handler; //导入依赖的package包/类
@Handler(priority = Priority.NORMAL)
public void onGameDestroyed(GameDestroyedEvent event) {
if (this.directory == null) {
return;
}
String worldName = event.getGame().getMap().getWorldName();
File worldContainer = this.getPlugin().getMaps().getWorldContainer();
File worldDirectory = new File(worldContainer, worldName);
if (!worldDirectory.exists() || !worldDirectory.isDirectory()) {
return;
}
File destination = new File(this.directory, worldName);
if (destination.exists()) {
FileUtils.deleteQuietly(destination);
}
try {
FileUtils.copyDirectory(worldDirectory, destination);
} catch (IOException io) {
io.printStackTrace();
}
}
示例14: antiLogout
import net.engio.mbassy.listener.Handler; //导入依赖的package包/类
/**
* Call a {@link PlayerDeathEvent} and handle this logout as a escape from
* death by the enemy. If the player wasn't escaped the
* {@link Player#getKiller()} returns null. This method is used to drop the
* players items on the ground.
*/
@Handler(priority = Priority.LAST)
public void antiLogout(PlayerQuitEvent event) {
GamePlayer player = event.getGamePlayer();
Player bukkit = event.getBukkitPlayer();
if (player != null && bukkit != null && player.isParticipating()) {
PlayerDeathEvent death = new PlayerDeathEvent(
bukkit,
Arrays.asList(bukkit.getInventory().getContents()),
bukkit.getTotalExperience(),
null
);
// call the fake event
this.plugin.getServer().getPluginManager().callEvent(death);
}
}
示例15: gameOver
import net.engio.mbassy.listener.Handler; //导入依赖的package包/类
@Handler(priority = Priority.LAST)
public void gameOver(GameStopEvent event) {
// There might be issues with this event. GameStopEvent is called AFTER
// a new game actually starts and calls GameStartEvent. The Minecraft
// client might have limit of displayed boss bars and boss bars rendered
// in a new game (which would be called in GameStartEvent) might not be
// displayed.
// NOTE: We won't use ServerCycleEvent since this event is not
// representing the stopping game.
for (BossBar bossBar : this.bossBars.values()) {
// We need need to send the "REMOVE" packet to all members
// of this boss bar to remove it from their views.
bossBar.removeAll();
}
this.bossBars.clear();
}