Java Code Examples for org.bukkit.event.player.PlayerGameModeChangeEvent#getPlayer()

The following examples show how to use org.bukkit.event.player.PlayerGameModeChangeEvent#getPlayer() . 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: GameModeChangeListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void actOnEvent(PlayerGameModeChangeEvent event) {
    Player player = event.getPlayer();
    UUID uuid = player.getUniqueId();
    long time = System.currentTimeMillis();
    String gameMode = event.getNewGameMode().name();
    String worldName = player.getWorld().getName();

    dbSystem.getDatabase().executeTransaction(new WorldNameStoreTransaction(serverInfo.getServerUUID(), worldName));
    worldAliasSettings.addWorld(worldName);

    Optional<Session> cachedSession = SessionCache.getCachedSession(uuid);
    cachedSession.ifPresent(session -> session.changeState(worldName, gameMode, time));
}
 
Example 2
Source File: PlayerListener.java    From WorldGuardExtraFlagsPlugin with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerGameModeChangeEvent(PlayerGameModeChangeEvent event)
{
	Player player = event.getPlayer();
	
	Session wgSession = this.plugin.getWorldGuardCommunicator().getSessionManager().getIfPresent(player);
	if (wgSession != null)
	{
		Boolean value = wgSession.getHandler(FlyFlagHandler.class).getCurrentValue();
		if (value != null)
		{
			new BukkitRunnable()
			{
				@Override
				public void run()
				{
					PlayerListener.this.checkFlyStatus(player);
				}
			}.runTask(WorldGuardExtraFlagsPlugin.getPlugin());
		}
	}
	else
	{
		new BukkitRunnable()
		{
			@Override
			public void run()
			{
				PlayerListener.this.checkFlyStatus(player);
			}
		}.runTask(WorldGuardExtraFlagsPlugin.getPlugin());
	}
}
 
Example 3
Source File: ListenerGameMode.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority=EventPriority.HIGH, ignoreCancelled=true)
public void onChangeGameMode(PlayerGameModeChangeEvent e) {
    FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml");
    if(!config.getBoolean("game-mode.prevent-game-mode-change")) return;

    Player player = e.getPlayer();
    ICombatManager manager = this.plugin.getCombatManager();
    if(!manager.isInCombat(player)) return;

    e.setCancelled(true);
    String message = this.plugin.getLanguageMessageColoredWithPrefix("cheat-prevention.game-mode.no-changing");
    this.plugin.sendMessage(player, message);
}
 
Example 4
Source File: ListenerGameMode.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void afterChangeGameMode(PlayerGameModeChangeEvent e) {
    FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml");
    if(!config.getBoolean("game-mode.untag-on-change-game-mode")) return;

    Player player = e.getPlayer();
    ICombatManager manager = this.plugin.getCombatManager();
    if(!manager.isInCombat(player)) return;

    manager.untag(player, UntagReason.EXPIRE);
}
 
Example 5
Source File: PlayerGameModeChangeListener.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
    if (event.isCancelled()) {
        return;
    }

    Player player = event.getPlayer();
    Group group = groupManager.getGroupFromWorld(player.getWorld().getName());

    ConsoleLogger.debug("[GM PROCESS] Player '" + player.getName() + "' changed to GameMode '" +
            event.getNewGameMode().name() + "' in group '" + group.getName() + "'");

    playerManager.addPlayer(player, group);
    bukkitService.runTaskLater(() -> process.processGameModeChange(player, event.getNewGameMode(), group), 1L);
}
 
Example 6
Source File: PlayerGameModeChangeListener.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
    if (event.isCancelled()) {
        return;
    }

    Player player = event.getPlayer();
    Group group = groupManager.getGroupFromWorld(player.getWorld().getName());

    ConsoleLogger.debug("[GM PROCESS] Player '" + player.getName() + "' changed to GameMode '" +
            event.getNewGameMode().name() + "' in group '" + group.getName() + "'");

    playerManager.addPlayer(player, group);
    bukkitService.runTaskLater(() -> process.processGameModeChange(player, event.getNewGameMode(), group), 1L);
}