本文整理汇总了Java中org.bukkit.event.player.PlayerGameModeChangeEvent.setCancelled方法的典型用法代码示例。如果您正苦于以下问题:Java PlayerGameModeChangeEvent.setCancelled方法的具体用法?Java PlayerGameModeChangeEvent.setCancelled怎么用?Java PlayerGameModeChangeEvent.setCancelled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.event.player.PlayerGameModeChangeEvent
的用法示例。
在下文中一共展示了PlayerGameModeChangeEvent.setCancelled方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onGamemodeChange
import org.bukkit.event.player.PlayerGameModeChangeEvent; //导入方法依赖的package包/类
@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");
}
}
}
示例2: onGamemodeChange
import org.bukkit.event.player.PlayerGameModeChangeEvent; //导入方法依赖的package包/类
@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);
}
}
示例3: onGameModeChange
import org.bukkit.event.player.PlayerGameModeChangeEvent; //导入方法依赖的package包/类
@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);
}
}
示例4: shouldDoNothingEventCancelled
import org.bukkit.event.player.PlayerGameModeChangeEvent; //导入方法依赖的package包/类
@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);
}
示例5: onGamemodeChange
import org.bukkit.event.player.PlayerGameModeChangeEvent; //导入方法依赖的package包/类
/**
* Used to prevent spectators from changing their gamemode whilst spectating.
*/
@EventHandler(priority=EventPriority.HIGHEST)
public void onGamemodeChange(final PlayerGameModeChangeEvent e)
{
final Spectator spectator = p.getPlayerData(e.getPlayer());
if (spectator.isSpectating() && e.getNewGameMode() != GameMode.ADVENTURE && !spectator.isGamemodeChangeAllowed())
{
e.setCancelled(true);
e.getPlayer().setAllowFlight(true);
}
}