use of org.bukkit.event.block.SignChangeEvent in project AuthMeReloaded by AuthMe.
the class PlayerListenerTest method shouldAllowSignChangeEvent.
@Test
public void shouldAllowSignChangeEvent() {
// given
SignChangeEvent event = mock(SignChangeEvent.class);
Player player = mock(Player.class);
given(event.getPlayer()).willReturn(player);
given(listenerService.shouldCancelEvent(player)).willReturn(false);
// when
listener.onSignChange(event);
// then
verify(event, only()).getPlayer();
}
use of org.bukkit.event.block.SignChangeEvent in project Glowstone by GlowstoneMC.
the class UpdateSignHandler method handle.
@Override
public void handle(GlowSession session, UpdateSignMessage message) {
GlowPlayer player = session.getPlayer();
Location location = new Location(player.getWorld(), message.getX(), message.getY(), message.getZ());
if (!player.checkSignLocation(location)) {
GlowServer.logger.warning(session + " tried to edit sign at " + location);
return;
}
// filter out json messages that aren't plaintext
String[] lines = new String[4];
for (int i = 0; i < lines.length; ++i) {
lines[i] = message.getMessage()[i].asPlaintext();
}
SignChangeEvent event = new SignChangeEvent(location.getBlock(), player, lines);
EventFactory.callEvent(event);
if (event.isCancelled()) {
GlowServer.logger.warning("Sign was cancelled");
return;
}
// update the sign if it's actually still there
BlockState state = location.getBlock().getState();
if (state instanceof Sign) {
Sign sign = (Sign) state;
for (int i = 0; i < lines.length; ++i) {
sign.setLine(i, lines[i]);
}
sign.update();
}
}
use of org.bukkit.event.block.SignChangeEvent in project AuthMeReloaded by AuthMe.
the class PlayerListenerTest method shouldCancelSignChangeEvent.
@Test
public void shouldCancelSignChangeEvent() {
// given
SignChangeEvent event = mock(SignChangeEvent.class);
Player player = mock(Player.class);
given(event.getPlayer()).willReturn(player);
given(listenerService.shouldCancelEvent(player)).willReturn(true);
// when
listener.onSignChange(event);
// then
verify(event).setCancelled(true);
}
Aggregations