Java Code Examples for org.bukkit.event.player.PlayerGameModeChangeEvent

The following are top voted examples for showing how to use org.bukkit.event.player.PlayerGameModeChangeEvent. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Uranium   File: CraftPlayer.java   View source code 6 votes vote down vote up
@Override
public void setGameMode(GameMode mode) {
    if (getHandle().playerNetServerHandler == null) return;

    if (mode == null) {
        throw new IllegalArgumentException("Mode cannot be null");
    }

    if (mode != getGameMode()) {
        PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(this, mode);
        server.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            return;
        }

        getHandle().theItemInWorldManager.setGameType(net.minecraft.world.WorldSettings.GameType.getByID(mode.getValue()));
        getHandle().fallDistance = 0;
        getHandle().playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S2BPacketChangeGameState(3, mode.getValue()));
    }
}
 
Example 2
Project: WorldGuardExtraFlagsPlugin   File: PlayerListener.java   View source code 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerGameModeChangeEvent(PlayerGameModeChangeEvent event)
{
	Player player = event.getPlayer();
	
	if (!WorldGuardUtils.hasBypass(player))
	{
		new BukkitRunnable()
		{
			@Override
			public void run()
			{
				try
				{
					event.getPlayer().setAllowFlight(WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().get(player).getHandler(FlyFlag.class).getCurrentValue());
				}
				catch(Exception ignored)
				{
					
				}
			}
		}.runTask(WorldGuardExtraFlagsPlugin.getPlugin());
	}
}
 
Example 3
Project: ThermosRebased   File: CraftPlayer.java   View source code 6 votes vote down vote up
@Override
public void setGameMode(GameMode mode) {
    if (getHandle().playerNetServerHandler == null) return;

    if (mode == null) {
        throw new IllegalArgumentException("Mode cannot be null");
    }

    if (mode != getGameMode()) {
        PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(this, mode);
        server.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            return;
        }

        getHandle().theItemInWorldManager.setGameType(net.minecraft.world.WorldSettings.GameType.getByID(mode.getValue()));
        getHandle().fallDistance = 0;
        getHandle().playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S2BPacketChangeGameState(3, mode.getValue()));
    }
}
 
Example 4
Project: Thermos   File: CraftPlayer.java   View source code 6 votes vote down vote up
@Override
public void setGameMode(GameMode mode) {
    if (getHandle().playerNetServerHandler == null) return;

    if (mode == null) {
        throw new IllegalArgumentException("Mode cannot be null");
    }

    if (mode != getGameMode()) {
        PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(this, mode);
        server.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            return;
        }

        getHandle().theItemInWorldManager.setGameType(net.minecraft.world.WorldSettings.GameType.getByID(mode.getValue()));
        getHandle().fallDistance = 0;
        getHandle().playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S2BPacketChangeGameState(3, mode.getValue()));
    }
}
 
Example 5
Project: KCauldron   File: CraftPlayer.java   View source code 6 votes vote down vote up
@Override
public void setGameMode(GameMode mode) {
    if (getHandle().playerNetServerHandler == null) return;

    if (mode == null) {
        throw new IllegalArgumentException("Mode cannot be null");
    }

    if (mode != getGameMode()) {
        PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(this, mode);
        server.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            return;
        }

        getHandle().theItemInWorldManager.setGameType(net.minecraft.world.WorldSettings.GameType.getByID(mode.getValue()));
        getHandle().fallDistance = 0;
        getHandle().playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S2BPacketChangeGameState(3, mode.getValue()));
    }
}
 
Example 6
Project: CauldronGit   File: CraftPlayer.java   View source code 6 votes vote down vote up
@Override
public void setGameMode(GameMode mode) {
    if (getHandle().playerNetServerHandler == null) return;

    if (mode == null) {
        throw new IllegalArgumentException("Mode cannot be null");
    }

    if (mode != getGameMode()) {
        PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(this, mode);
        server.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            return;
        }

        getHandle().theItemInWorldManager.setGameType(net.minecraft.world.WorldSettings.GameType.getByID(mode.getValue()));
        getHandle().fallDistance = 0;
        getHandle().playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S2BPacketChangeGameState(3, mode.getValue()));
    }
}
 
Example 7
Project: Cauldron-Old   File: CraftPlayer.java   View source code 6 votes vote down vote up
@Override
public void setGameMode(GameMode mode) {
    if (getHandle().playerNetServerHandler == null) return;

    if (mode == null) {
        throw new IllegalArgumentException("Mode cannot be null");
    }

    if (mode != getGameMode()) {
        PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(this, mode);
        server.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            return;
        }

        getHandle().theItemInWorldManager.setGameType(net.minecraft.world.WorldSettings.GameType.getByID(mode.getValue()));
        getHandle().fallDistance = 0;
        getHandle().playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S2BPacketChangeGameState(3, mode.getValue()));
    }
}
 
Example 8
Project: Cauldron-Reloaded   File: CraftPlayer.java   View source code 6 votes vote down vote up
@Override
public void setGameMode(GameMode mode) {
    if (getHandle().playerNetServerHandler == null) return;

    if (mode == null) {
        throw new IllegalArgumentException("Mode cannot be null");
    }

    if (mode != getGameMode()) {
        PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(this, mode);
        server.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            return;
        }

        getHandle().theItemInWorldManager.setGameType(net.minecraft.world.WorldSettings.GameType.getByID(mode.getValue()));
        getHandle().fallDistance = 0;
        getHandle().playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S2BPacketChangeGameState(3, mode.getValue()));
    }
}
 
Example 9
Project: PerWorldInventory   File: PlayerGameModeChangeListenerTest.java   View source code 6 votes vote down vote up
@Test
public void shouldDoEverything() {
    // given
    Player player = mock(Player.class);
    World world = mock(World.class);
    given(world.getName()).willReturn("world");
    given(player.getWorld()).willReturn(world);
    Group group = mockGroup("world");
    given(groupManager.getGroupFromWorld("world")).willReturn(group);

    PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(player, GameMode.CREATIVE);

    // when
    listener.onPlayerGameModeChange(event);

    // then
    verify(groupManager).getGroupFromWorld("world");
    verify(playerManager).addPlayer(player, group);
    verify(bukkitService).runTaskLater(any(Runnable.class), any(Long.class));
}
 
Example 10
Project: Spigot-Plus   File: GamemodeManager.java   View source code 6 votes vote down vote up
@EventHandler
public void onGamemodeChange(PlayerGameModeChangeEvent event){
	GameMode newMode = event.getNewGameMode();
	String worldName = event.getPlayer().getWorld().getName();
	if(!event.getPlayer().hasPermission("spigotplus.gamemode." + worldName + "." + newMode)){
		boolean modeFound = false;
		for(GameMode mode : GameMode.values()){
			if(event.getPlayer().hasPermission("spigotplus.gamemode." + worldName + "." + mode)){
				modeFound = true;
				break;
			}
		}

		event.setCancelled(true);
		event.getPlayer().sendMessage("You are not permitted to use the " + newMode + " gamemode in this world");
		
		if(!modeFound){
			logWarn("The player " + event.getPlayer().getName() + " is not permitted to use any gamemode in the world \"" + worldName + "\"");
			event.getPlayer().kickPlayer("There is a configuration error with the gamemodes you are permitted to use. Please contact the server administrator");
		}
	}
}
 
Example 11
Project: FFoKC   File: CraftPlayer.java   View source code 6 votes vote down vote up
@Override
public void setGameMode(GameMode mode) {
    if (getHandle().playerNetServerHandler == null) return;

    if (mode == null) {
        throw new IllegalArgumentException("Mode cannot be null");
    }

    if (mode != getGameMode()) {
        PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(this, mode);
        server.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            return;
        }

        getHandle().theItemInWorldManager.setGameType(net.minecraft.world.WorldSettings.GameType.getByID(mode.getValue()));
        getHandle().fallDistance = 0;
        getHandle().playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S2BPacketChangeGameState(3, mode.getValue()));
    }
}
 
Example 12
Project: CraftBukkit   File: CraftPlayer.java   View source code 6 votes vote down vote up
@Override
public void setGameMode(GameMode mode) {
    if (getHandle().playerConnection == null) return;

    if (mode == null) {
        throw new IllegalArgumentException("Mode cannot be null");
    }

    if (mode != getGameMode()) {
        PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(this, mode);
        server.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            return;
        }

        getHandle().playerInteractManager.setGameMode(EnumGamemode.getById(mode.getValue()));
        getHandle().fallDistance = 0;
        getHandle().playerConnection.sendPacket(new PacketPlayOutGameStateChange(3, mode.getValue()));
    }
}
 
Example 13
Project: NexusInventory   File: PlayerGameModeChangeListener.java   View source code 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
    Player player = event.getPlayer();
    GameMode oldGameMode = player.getGameMode();
    GameMode newGameMode = event.getNewGameMode();
    Group group = plugin.getGroupManager().getGroupFromWorld(player.getWorld().getName());
    if (group == null) {
        group = new Group(player.getWorld().getName(), null, null);
    }

    plugin.getSerializer().writePlayerDataToFile(player,
            PlayerSerialization.serializePlayer(player, plugin),
            group,
            oldGameMode);

    plugin.getSerializer().getPlayerDataFromFile(
            player,
            group,
            newGameMode);
}
 
Example 14
Project: Craftbukkit   File: CraftPlayer.java   View source code 6 votes vote down vote up
@Override
public void setGameMode(GameMode mode) {
    if (getHandle().playerConnection == null) return;

    if (mode == null) {
        throw new IllegalArgumentException("Mode cannot be null");
    }

    if (mode != getGameMode()) {
        PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(this, mode);
        server.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            return;
        }
        
        getHandle().setSpectatorTarget(getHandle());
        getHandle().playerInteractManager.setGameMode(WorldSettings.EnumGamemode.getById(mode.getValue()));
        getHandle().fallDistance = 0;
        getHandle().playerConnection.sendPacket(new PacketPlayOutGameStateChange(3, mode.getValue()));
    }
}
 
Example 15
Project: Almura-Server   File: CraftPlayer.java   View source code 6 votes vote down vote up
@Override
public void setGameMode(GameMode mode) {
    if (getHandle().playerConnection == null) return;

    if (mode == null) {
        throw new IllegalArgumentException("Mode cannot be null");
    }

    if (mode != getGameMode()) {
        PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(this, mode);
        server.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            return;
        }

        getHandle().playerInteractManager.setGameMode(EnumGamemode.a(mode.getValue()));
        getHandle().playerConnection.sendPacket(new Packet70Bed(3, mode.getValue()));
    }
}
 
Example 16
Project: Tweakkit-Server   File: CraftPlayer.java   View source code 6 votes vote down vote up
@Override
public void setGameMode(GameMode mode) {
    if (getHandle().playerConnection == null) return;

    if (mode == null) {
        throw new IllegalArgumentException("Mode cannot be null");
    }

    if (mode != getGameMode()) {
        PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(this, mode);
        server.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            return;
        }

        getHandle().playerInteractManager.setGameMode(EnumGamemode.getById(mode.getValue()));
        getHandle().fallDistance = 0;
        getHandle().playerConnection.sendPacket(new PacketPlayOutGameStateChange(3, mode.getValue()));
    }
}
 
Example 17
Project: PerWorldInventory   File: PlayerGameModeChangeListenerTest.java   View source code 6 votes vote down vote up
@Test
public void shouldDoEverything() {
    // given
    Player player = mock(Player.class);
    World world = mock(World.class);
    given(world.getName()).willReturn("world");
    given(player.getWorld()).willReturn(world);
    Group group = mockGroup("world");
    given(groupManager.getGroupFromWorld("world")).willReturn(group);

    PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(player, GameMode.CREATIVE);

    // when
    listener.onPlayerGameModeChange(event);

    // then
    verify(groupManager).getGroupFromWorld("world");
    verify(playerManager).addPlayer(player, group);
    verify(bukkitService).runTaskLater(any(Runnable.class), any(Long.class));
}
 
Example 18
Project: Cauldron   File: CraftPlayer.java   View source code 6 votes vote down vote up
@Override
public void setGameMode(GameMode mode) {
    if (getHandle().playerNetServerHandler == null) return;

    if (mode == null) {
        throw new IllegalArgumentException("Mode cannot be null");
    }

    if (mode != getGameMode()) {
        PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(this, mode);
        server.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            return;
        }

        getHandle().theItemInWorldManager.setGameType(net.minecraft.world.WorldSettings.GameType.getByID(mode.getValue()));
        getHandle().fallDistance = 0;
        getHandle().playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S2BPacketChangeGameState(3, mode.getValue()));
    }
}
 
Example 19
Project: SpigotSource   File: CraftPlayer.java   View source code 6 votes vote down vote up
@Override
public void setGameMode(GameMode mode) {
    if (getHandle().playerConnection == null) return;

    if (mode == null) {
        throw new IllegalArgumentException("Mode cannot be null");
    }

    if (mode != getGameMode()) {
        PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(this, mode);
        server.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            return;
        }
        
        getHandle().setSpectatorTarget(getHandle());
        getHandle().playerInteractManager.setGameMode(WorldSettings.EnumGamemode.getById(mode.getValue()));
        getHandle().fallDistance = 0;
        getHandle().playerConnection.sendPacket(new PacketPlayOutGameStateChange(3, mode.getValue()));
    }
}
 
Example 20
Project: NPlugins   File: FlyModeListener.java   View source code 6 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerQuitCreative(final PlayerGameModeChangeEvent event) {
    if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
        final boolean wasFlying = event.getPlayer().isFlying();
        final Player player = event.getPlayer();
        if (Perms.hasFly(event.getPlayer()) && this.feature.hasFlyMode(event.getPlayer())) {
            Bukkit.getScheduler().runTaskLater(this.feature.getPlugin(), new BukkitRunnable() {

                @Override
                public void run() {
                    if (player.isOnline()) {
                        player.setAllowFlight(true);
                        player.setFlying(wasFlying);
                    }
                }
            }, 1L);
        }
    }
}
 
Example 21
Project: Craft-city   File: CraftPlayer.java   View source code 6 votes vote down vote up
@Override
public void setGameMode(GameMode mode) {
    if (getHandle().playerConnection == null) return;

    if (mode == null) {
        throw new IllegalArgumentException("Mode cannot be null");
    }

    if (mode != getGameMode()) {
        PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(this, mode);
        server.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            return;
        }

        getHandle().playerInteractManager.setGameMode(EnumGamemode.a(mode.getValue()));
        getHandle().playerConnection.sendPacket(new Packet70Bed(3, mode.getValue()));
    }
}
 
Example 22
Project: MCPBukkit   File: CraftPlayer.java   View source code 6 votes vote down vote up
@Override
public void setGameMode(GameMode mode) {
    if (getHandle().field_71135_a == null) return;

    if (mode == null) {
        throw new IllegalArgumentException("Mode cannot be null");
    }

    if (mode != getGameMode()) {
        PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(this, mode);
        server.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            return;
        }

        getHandle().field_71134_c.func_73076_a(net.minecraft.world.EnumGameType.func_77146_a(mode.getValue()));
        getHandle().field_71135_a.func_72567_b(new net.minecraft.network.packet.Packet70GameEvent(3, mode.getValue()));
    }
}
 
Example 23
Project: SkyWarsReloaded   File: SpectatorListener.java   View source code 5 votes vote down vote up
@EventHandler(priority=EventPriority.HIGH)
protected void onGamemodeChange(PlayerGameModeChangeEvent e) {
	if (SkyWarsReloaded.getPC().getPlayer(e.getPlayer().getUniqueId()) != null
			&& SkyWarsReloaded.getPC().getPlayer(e.getPlayer().getUniqueId()).isSpectating()
			&& !e.getNewGameMode().equals(GameMode.ADVENTURE)
			&& SkyWarsReloaded.getPC().getPlayer(e.getPlayer().getUniqueId()).gamemodeChangeAllowed()) {
		
		e.setCancelled(true);
		e.getPlayer().setAllowFlight(true);
	}
}
 
Example 24
Project: Arc-v2   File: PlayerListener.java   View source code 5 votes vote down vote up
@EventHandler
public void onGameModeChange(PlayerGameModeChangeEvent event) {
    GameMode gameMode = event.getPlayer().getGameMode();
    // check if we switch to survival from an exempt GameMode and update.
    if (Arc.COMPATIBILITY) {
        if ((gameMode == GameMode.CREATIVE && event.getNewGameMode() == GameMode.SURVIVAL)) {
            MovingData.getData(event.getPlayer()).setLastGameModeChange(System.currentTimeMillis());
        }
    } else {
        if ((gameMode == GameMode.CREATIVE || gameMode == GameMode.SPECTATOR) && event.getNewGameMode() == GameMode.SURVIVAL) {
            MovingData.getData(event.getPlayer()).setLastGameModeChange(System.currentTimeMillis());
        }
    }
}
 
Example 25
Project: UltimateSpawn   File: LittlesEvent.java   View source code 5 votes vote down vote up
@EventHandler
public void onChangeGM(PlayerGameModeChangeEvent e) {
	Player p = e.getPlayer();
       UUID pU = e.getPlayer().getUniqueId();
       
	int GamemodeTemp1 = 0; 
       if (e.getNewGameMode() == GameMode.SURVIVAL) {
       	GamemodeTemp1 = 0;
       } else if (e.getNewGameMode() == GameMode.CREATIVE) {
       	GamemodeTemp1 = 1;
       } else if (e.getNewGameMode() == GameMode.ADVENTURE) {
       	GamemodeTemp1 = 2;
       } else if (e.getNewGameMode() == GameMode.SPECTATOR) {
       	GamemodeTemp1 = 3;
       }
       int GamemodeTemp2 = Integer.valueOf(GamemodeTemp1);
       
       if (!ConfigTemp.getConfig().contains(String.valueOf(pU))) {
       	ConfigTemp.getConfig().set(pU+".Player", String.valueOf(p));
       	ConfigTemp.getConfig().set(pU+".Options.Gamemode", Integer.valueOf(GamemodeTemp2));
       	
       	ConfigTemp.saveConfigFile();
       } else if (ConfigTemp.getConfig().contains(String.valueOf(pU))) {
       	ConfigTemp.getConfig().set(pU+".Player", String.valueOf(p));
       	ConfigTemp.getConfig().set(pU+".Options.Gamemode", Integer.valueOf(GamemodeTemp2));
       	
       	ConfigTemp.saveConfigFile();
       }
}
 
Example 26
Project: RPGInventory   File: LockerListener.java   View source code 5 votes vote down vote up
@EventHandler
public void onGameModeSwitch(PlayerGameModeChangeEvent event) {
    Player player = event.getPlayer();

    if (!InventoryManager.playerIsLoaded(player)) {
        return;
    }

    if (event.getNewGameMode() == GameMode.CREATIVE) {
        InventoryLocker.unlockSlots(player);
    } else if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
        InventoryLocker.lockSlots(player, true);
    }
}
 
Example 27
Project: MultiLineAPI   File: EventListener.java   View source code 5 votes vote down vote up
@EventHandler
public void onGameMode(PlayerGameModeChangeEvent e) {
    if (e.getNewGameMode().equals(GameMode.SPECTATOR) && !e.getPlayer().getGameMode().equals(GameMode.SPECTATOR)) {
        packet.despawnAllStacks(e.getPlayer());
    } else if (!e.getNewGameMode().equals(GameMode.SPECTATOR) &&
            e.getPlayer().getGameMode().equals(GameMode.SPECTATOR)) {
        packet.spawnAllStacks(e.getPlayer());
    }
}
 
Example 28
Project: UHC   File: JoinQuitHandlers.java   View source code 5 votes vote down vote up
@EventHandler
public void gameModeChange(final PlayerGameModeChangeEvent event) {
    Optional<User> optionalUser = UserManager.getInstance().getUser(event.getPlayer().getUniqueId());
    User user = optionalUser.orElseGet(() -> new User(event.getPlayer(), Participation.SPECTATOR));
    if (event.getPlayer().isOp() || event.getNewGameMode() == GameMode.CREATIVE) {
        user.setParticipation(Participation.ADMIN);
    } else {
        user.setParticipation(Participation.PARTICIPATOR);
    }
    UserManager.getInstance().addUser(user);
}
 
Example 29
Project: Thirst   File: PlayerGamemodeChangeListener.java   View source code 5 votes vote down vote up
@EventHandler
public void onGamemodeChange(PlayerGameModeChangeEvent event)
{
	Player player = event.getPlayer();

	if (event.getNewGameMode() != GameMode.CREATIVE || Thirst.getInstance().getYAMLConfig().ignoreCreative)
	{
		ThirstManager.getThirst().displayThirst(player);
		return;
	}
	else if (event.getNewGameMode() == GameMode.CREATIVE && !Thirst.getInstance().getYAMLConfig().ignoreCreative)
	{
		for (PotionEffect effect : player.getActivePotionEffects())
		{
			player.removePotionEffect(effect.getType());
		}
	}

	if (Thirst.getInstance().getYAMLConfig().displayType.equalsIgnoreCase("scoreboard"))
	{
		if (Thirst.getInstance().getYAMLConfig().displayType.equalsIgnoreCase("SCOREBOARD"))
			player.setScoreboard(Bukkit.getServer().getScoreboardManager().getNewScoreboard());
	}
	else if (Thirst.getInstance().getYAMLConfig().displayType.equalsIgnoreCase("action"))
	{
		UtilActionBar.getInstance().sendActionBar(player, "");
	}
	else if (Thirst.getInstance().getYAMLConfig().displayType.equalsIgnoreCase("bossbar"))
	{
		ThirstData data = ThirstManager.getThirst().getThirstData(player);

		if (data.getBar() != null)
		{
			data.getBar().removePlayer(player);
		}
	}
}
 
Example 30
Project: Skript   File: ExprGameMode.java   View source code 5 votes vote down vote up
@Override
protected GameMode[] get(final Event e, final Player[] source) {
	return get(source, new Converter<Player, GameMode>() {
		@Override
		@Nullable
		public GameMode convert(final Player p) {
			if (getTime() >= 0 && e instanceof PlayerGameModeChangeEvent && ((PlayerGameModeChangeEvent) e).getPlayer() == p && !Delay.isDelayed(e))
				return ((PlayerGameModeChangeEvent) e).getNewGameMode();
			return p.getGameMode();
		}
	});
}
 
Example 31
Project: Skript   File: ExprGameMode.java   View source code 5 votes vote down vote up
@Override
public void change(final Event e, final @Nullable Object[] delta, final ChangeMode mode) throws UnsupportedOperationException {
	final GameMode m = delta == null ? Bukkit.getDefaultGameMode() : (GameMode) delta[0];
	for (final Player p : getExpr().getArray(e)) {
		if (getTime() >= 0 && e instanceof PlayerGameModeChangeEvent && ((PlayerGameModeChangeEvent) e).getPlayer() == p && !Delay.isDelayed(e)) {
			if (((PlayerGameModeChangeEvent) e).getNewGameMode() != m)
				((PlayerGameModeChangeEvent) e).setCancelled(true);
		}
		p.setGameMode(m);
	}
}
 
Example 32
Project: Skript   File: EvtGameMode.java   View source code 5 votes vote down vote up
@Override
public boolean check(final Event e) {
	if (mode != null) {
		return mode.check(e, new Checker<GameMode>() {
			@Override
			public boolean check(final GameMode m) {
				return ((PlayerGameModeChangeEvent) e).getNewGameMode().equals(m);
			}
		});
	}
	return true;
}
 
Example 33
Project: SuperVanish   File: SilentOpenChest.java   View source code 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onGameModeChange(PlayerGameModeChangeEvent e) {
    Player p = e.getPlayer();
    if (playerStateInfoMap.containsKey(p) && e.getNewGameMode() != GameMode.SPECTATOR) {
        // Don't let low-priority event listeners cancel the gamemode change
        if (e.isCancelled()) e.setCancelled(false);
    }
}
 
Example 34
Project: AIOJetpacks   File: AIOPlugin.java   View source code 5 votes vote down vote up
@EventHandler
public void onPlayerChangeGameMode(final PlayerGameModeChangeEvent e)
{
	// Run this next Tick because bukkit and some plugins are changing variables after calling that event
	this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
		@Override
		public void run()
		{
			AIOPlugin.getInstance().getJetpackManager().checkJetpackItemForPlayer(e.getPlayer());
		}
	});
}
 
Example 35
Project: PerWorldInventory   File: PlayerGameModeChangeListener.java   View source code 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 36
Project: PerWorldInventory   File: PlayerGameModeChangeListenerTest.java   View source code 5 votes vote down vote up
@Test
public void shouldDoNothingEventCancelled() {
    // given
    PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(mock(Player.class), GameMode.CREATIVE);
    event.setCancelled(true);

    // when
    listener.onPlayerGameModeChange(event);

    // then
    verifyZeroInteractions(groupManager);
    verifyZeroInteractions(playerManager);
    verifyZeroInteractions(bukkitService);
}
 
Example 37
Project: Spigot-Plus   File: InventoryManager.java   View source code 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerGamemodeChanged(PlayerGameModeChangeEvent evt) {
    InventoryKey beforeKey = new InventoryKey(evt.getPlayer().getUniqueId(), getGroupName(evt
            .getPlayer().getWorld().getName()), evt.getPlayer().getGameMode());
    InventoryKey afterKey = new InventoryKey(evt.getPlayer().getUniqueId(), getGroupName(evt
            .getPlayer().getWorld().getName()), evt.getNewGameMode());

    if (!beforeKey.equals(afterKey)) {
    	switchInventory(beforeKey, afterKey);
    }
}
 
Example 38
Project: AdvancedAchievements   File: AchieveConnectionListener.java   View source code 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onGameModeChange(PlayerGameModeChangeEvent event) {
	if (playersProcessingRan.contains(event.getPlayer().getUniqueId().toString())) {
		return;
	}

	scheduleTask(event.getPlayer());
}
 
Example 39
Project: BuildTools   File: Events.java   View source code 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void gamemodeChange(PlayerGameModeChangeEvent event){
	BTPlayer ply;
	try{
		ply = pdata.getBTPlayer(event.getPlayer());
	}
	catch (UnknownBTPlayerException e){
		return;
	}
	
	if(event.getNewGameMode() != GameMode.CREATIVE && ply.isBuildModeActive()){
		ply.setBuildModeActive(false);
		ply.sendMessage("Build mode deactivated.", ChatColor.RED);
	}
}
 
Example 40
Project: PerWorldInventory   File: PlayerGameModeChangeListener.java   View source code 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);
}