Search in sources :

Example 1 with SignChangeEvent

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();
}
Also used : Player(org.bukkit.entity.Player) SignChangeEvent(org.bukkit.event.block.SignChangeEvent) Test(org.junit.Test)

Example 2 with SignChangeEvent

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();
    }
}
Also used : BlockState(org.bukkit.block.BlockState) GlowPlayer(net.glowstone.entity.GlowPlayer) Sign(org.bukkit.block.Sign) SignChangeEvent(org.bukkit.event.block.SignChangeEvent) Location(org.bukkit.Location)

Example 3 with SignChangeEvent

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);
}
Also used : Player(org.bukkit.entity.Player) SignChangeEvent(org.bukkit.event.block.SignChangeEvent) Test(org.junit.Test)

Aggregations

SignChangeEvent (org.bukkit.event.block.SignChangeEvent)3 Player (org.bukkit.entity.Player)2 Test (org.junit.Test)2 GlowPlayer (net.glowstone.entity.GlowPlayer)1 Location (org.bukkit.Location)1 BlockState (org.bukkit.block.BlockState)1 Sign (org.bukkit.block.Sign)1