org.bukkit.event.player.PlayerBedEnterEvent Java Examples

The following examples show how to use org.bukkit.event.player.PlayerBedEnterEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BedListener.java    From Harbor with MIT License 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onBedEnter(final PlayerBedEnterEvent event) {
    if (event.getBedEnterResult() != PlayerBedEnterEvent.BedEnterResult.OK) return;
    if (Checker.SKIPPING_WORLDS.contains(event.getPlayer().getWorld())) return;
    if (Checker.isVanished(event.getPlayer())) return;

    Bukkit.getScheduler().runTaskLater(Harbor.getHarbor(), () -> {
        final UUID playerUuid = event.getPlayer().getUniqueId();
        if (!(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - getCooldown(playerUuid)) >
                Config.getInteger("messages.chat.message-cooldown"))) return;

        Messages.sendWorldChatMessage(event.getBed().getWorld(),
                Config.getString("messages.chat.player-sleeping")
                        .replace("[player]", event.getPlayer().getName())
                        .replace("[displayname]", event.getPlayer().getDisplayName()));
        COOLDOWNS.put(playerUuid, System.currentTimeMillis());
    }, 1);
}
 
Example #2
Source File: PlayerListener.java    From BedwarsRel with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onSleep(PlayerBedEnterEvent bee) {

  Player p = bee.getPlayer();

  Game g = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(p);
  if (g == null) {
    return;
  }

  if (g.getState() == GameState.STOPPED) {
    return;
  }

  bee.setCancelled(true);
}
 
Example #3
Source File: BlockListener.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
public void OnPlayerBedEnterEvent(PlayerBedEnterEvent event) {
	
	Resident resident = CivGlobal.getResident(event.getPlayer().getName());

	if (resident == null) {
		event.setCancelled(true);
		return;
	}
			
	coord.setFromLocation(event.getPlayer().getLocation());
	Camp camp = CivGlobal.getCampFromChunk(coord);
	if (camp != null) {
		if (!camp.hasMember(event.getPlayer().getName())) {
			CivMessage.sendError(event.getPlayer(), "You cannot sleep in a camp you do not belong to.");
			event.setCancelled(true);
			return;
		}
	}		
}
 
Example #4
Source File: EventFilterMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onBedEnter(final PlayerBedEnterEvent event) {
  cancel(
      event,
      true,
      event.getPlayer().getWorld(),
      match.getPlayer(event.getPlayer()),
      TranslatableComponent.of("match.disabled.bed"));
}
 
Example #5
Source File: IslandGuard.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW)
public void onPlayerBedEnter(final PlayerBedEnterEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
    }
    // Check world
    if (inWorld(e.getPlayer())) {
        if (actionAllowed(e.getPlayer(),e.getBed().getLocation(), SettingsFlag.BED)) {
            return;
        }
        // Not allowed
        Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
        e.setCancelled(true);
    }
}
 
Example #6
Source File: PlayerListenerTest.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void shouldHandleSimpleCancelableEvents() {
    withServiceMock(listenerService)
        .check(listener::onPlayerShear, PlayerShearEntityEvent.class)
        .check(listener::onPlayerFish, PlayerFishEvent.class)
        .check(listener::onPlayerBedEnter, PlayerBedEnterEvent.class)
        .check(listener::onPlayerDropItem, PlayerDropItemEvent.class)
        .check(listener::onPlayerHitPlayerEvent, EntityDamageByEntityEvent.class)
        .check(listener::onPlayerConsumeItem, PlayerItemConsumeEvent.class)
        .check(listener::onPlayerInteract, PlayerInteractEvent.class)
        .check(listener::onPlayerPickupItem, PlayerPickupItemEvent.class)
        .check(listener::onPlayerInteractEntity, PlayerInteractEntityEvent.class)
        .check(listener::onPlayerHeldItem, PlayerItemHeldEvent.class);
}
 
Example #7
Source File: EventFilterMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onBedEnter(final PlayerBedEnterEvent event) {
    cancel(event, true, event.getPlayer().getWorld(), getMatch().getPlayer(event.getPlayer()), new TranslatableComponent("match.bed.disabled"));
}
 
Example #8
Source File: EnteredBedsListener.java    From Statz with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBedEnter(final PlayerBedEnterEvent event) {

	final PlayerStat stat = PlayerStat.ENTERED_BEDS;

	// Get player
	final Player player = event.getPlayer();

	// Do general check
	if (!plugin.doGeneralCheck(player, stat))
		return;

	PlayerStatSpecification specification = new EnteredBedsSpecification(player.getUniqueId(), 1,
			player.getWorld().getName());

	// Update value to new stat.
	plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat, specification.constructQuery());

}
 
Example #9
Source File: PlayerListener.java    From AuthMeReloaded with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlayerBedEnter(PlayerBedEnterEvent event) {
    if (listenerService.shouldCancelEvent(event)) {
        event.setCancelled(true);
    }
}