Search in sources :

Example 16 with GameMode

use of org.bukkit.GameMode in project Bukkit by Bukkit.

the class DefaultGameModeCommand method execute.

@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!testPermission(sender))
        return true;
    if (args.length == 0) {
        sender.sendMessage("Usage: " + usageMessage);
        return false;
    }
    String modeArg = args[0];
    int value = -1;
    try {
        value = Integer.parseInt(modeArg);
    } catch (NumberFormatException ex) {
    }
    GameMode mode = GameMode.getByValue(value);
    if (mode == null) {
        if (modeArg.equalsIgnoreCase("creative") || modeArg.equalsIgnoreCase("c")) {
            mode = GameMode.CREATIVE;
        } else if (modeArg.equalsIgnoreCase("adventure") || modeArg.equalsIgnoreCase("a")) {
            mode = GameMode.ADVENTURE;
        } else {
            mode = GameMode.SURVIVAL;
        }
    }
    Bukkit.getServer().setDefaultGameMode(mode);
    Command.broadcastCommandMessage(sender, "Default game mode set to " + mode.toString().toLowerCase());
    return true;
}
Also used : GameMode(org.bukkit.GameMode)

Example 17 with GameMode

use of org.bukkit.GameMode in project Bukkit by Bukkit.

the class GameModeCommand method execute.

@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
    if (!testPermission(sender))
        return true;
    if (args.length == 0) {
        sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
        return false;
    }
    String modeArg = args[0];
    String playerArg = sender.getName();
    if (args.length == 2) {
        playerArg = args[1];
    }
    Player player = Bukkit.getPlayerExact(playerArg);
    if (player != null) {
        int value = -1;
        try {
            value = Integer.parseInt(modeArg);
        } catch (NumberFormatException ex) {
        }
        GameMode mode = GameMode.getByValue(value);
        if (mode == null) {
            if (modeArg.equalsIgnoreCase("creative") || modeArg.equalsIgnoreCase("c")) {
                mode = GameMode.CREATIVE;
            } else if (modeArg.equalsIgnoreCase("adventure") || modeArg.equalsIgnoreCase("a")) {
                mode = GameMode.ADVENTURE;
            } else {
                mode = GameMode.SURVIVAL;
            }
        }
        if (mode != player.getGameMode()) {
            player.setGameMode(mode);
            if (mode != player.getGameMode()) {
                sender.sendMessage("Game mode change for " + player.getName() + " failed!");
            } else {
                if (player == sender) {
                    Command.broadcastCommandMessage(sender, "Set own game mode to " + mode.toString() + " mode");
                } else {
                    Command.broadcastCommandMessage(sender, "Set " + player.getName() + "'s game mode to " + mode.toString() + " mode");
                }
            }
        } else {
            sender.sendMessage(player.getName() + " already has game mode " + mode.getValue());
        }
    } else {
        sender.sendMessage("Can't find player " + playerArg);
    }
    return true;
}
Also used : GameMode(org.bukkit.GameMode) Player(org.bukkit.entity.Player)

Example 18 with GameMode

use of org.bukkit.GameMode in project Glowstone by GlowstoneMC.

the class CommandTarget method getMatched.

/**
 * Gets all the matched entities from the target.
 *
 * @param source the location from which the targets should be found
 * @return the entities matching the query
 */
public Entity[] getMatched(Location source) {
    if (selector == SelectorType.SENDER) {
        if (sender instanceof Entity) {
            return new Entity[] { (Entity) sender };
        } else {
            return new Entity[0];
        }
    }
    List<EntityType> types = getTypes();
    List<GameMode> gameModes = getGameModes();
    Integer count = getCount();
    int maxRadius = getMaxRange() * getMaxRange();
    int minRadius = getMinRange() * getMinRange();
    Integer minLevel = getMinLevel();
    Integer maxLevel = getMaxLevel();
    List<Entity> entities = new ArrayList<>();
    if (count == null) {
        if (selector == SelectorType.NEAREST_PLAYER || selector == SelectorType.RANDOM) {
            count = 1;
        } else {
            count = source.getWorld().getEntities().size();
        }
    }
    for (Entity entity : source.getWorld().getEntities()) {
        if (entity.getLocation().distanceSquared(source) < minRadius) {
            continue;
        }
        if (!(maxRadius == 0 || entity.getLocation().distanceSquared(source) < maxRadius)) {
            continue;
        }
        if (!types.contains(entity.getType())) {
            continue;
        }
        if (getX() != null && getX() != entity.getLocation().getBlockX()) {
            continue;
        }
        if (getY() != null && getY() != entity.getLocation().getBlockY()) {
            continue;
        }
        if (getZ() != null && getZ() != entity.getLocation().getBlockZ()) {
            continue;
        }
        if (gameModes != null && entity.getType() != EntityType.PLAYER) {
            continue;
        }
        if (gameModes != null && gameModes.contains(((Player) entity).getGameMode())) {
            continue;
        }
        if (maxLevel != null && entity.getType() != EntityType.PLAYER) {
            continue;
        }
        if (maxLevel != null && ((Player) entity).getLevel() > maxLevel) {
            continue;
        }
        if (minLevel != null && entity.getType() != EntityType.PLAYER) {
            continue;
        }
        if (minLevel != null && ((Player) entity).getLevel() < minLevel) {
            continue;
        }
        // TODO: Add more checks
        entities.add(entity);
    }
    Collections.sort(entities, new EntityDistanceComparator(count < 0, source));
    if (count > entities.size()) {
        count = entities.size();
    }
    List<Entity> matched = new ArrayList<>();
    List<Integer> used = new ArrayList<>();
    for (int i = 0; i < count; i++) {
        if (selector == SelectorType.RANDOM) {
            while (true) {
                int random = ThreadLocalRandom.current().nextInt(entities.size());
                if (!used.contains(random)) {
                    matched.add(entities.get(random));
                    used.add(random);
                    break;
                }
            }
        } else {
            matched.add(entities.get(i));
        }
    }
    return matched.toArray(new Entity[matched.size()]);
}
Also used : EntityType(org.bukkit.entity.EntityType) Entity(org.bukkit.entity.Entity) GameMode(org.bukkit.GameMode) Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList)

Example 19 with GameMode

use of org.bukkit.GameMode in project Glowstone by GlowstoneMC.

the class DefaultGameModeCommand method execute.

@Override
public boolean execute(CommandSender sender, String label, String[] args, CommandMessages messages) {
    if (!testPermission(sender, messages.getPermissionMessage())) {
        return true;
    }
    if (args.length == 0) {
        sendUsageMessage(sender, messages);
        return false;
    }
    final String inputMode = args[0];
    final ResourceBundle bundle = messages.getResourceBundle();
    final GameMode gamemode = GameModeUtils.build(inputMode, messages.getLocale());
    if (gamemode == null) {
        new LocalizedStringImpl("defaultgamemode.unknown", bundle).sendInColor(ChatColor.RED, sender, inputMode);
        return false;
    }
    ServerProvider.getServer().setDefaultGameMode(gamemode);
    new LocalizedStringImpl("defaultgamemode.done", bundle).send(sender, ChatColor.GRAY + "" + ChatColor.ITALIC + GameModeUtils.prettyPrint(gamemode, messages.getLocale()));
    return true;
}
Also used : GameMode(org.bukkit.GameMode) LocalizedStringImpl(net.glowstone.i18n.LocalizedStringImpl) ResourceBundle(java.util.ResourceBundle)

Example 20 with GameMode

use of org.bukkit.GameMode in project Glowstone by GlowstoneMC.

the class GlowAnimal method entityInteract.

@Override
public boolean entityInteract(GlowPlayer player, InteractEntityMessage message) {
    if (!super.entityInteract(player, message) && message.getAction() == InteractEntityMessage.Action.INTERACT.ordinal()) {
        GameMode gameMode = player.getGameMode();
        if (gameMode == GameMode.SPECTATOR) {
            return false;
        }
        ItemStack item = player.getInventory().getItem(message.getHandSlot());
        if (InventoryUtil.isEmpty(item)) {
            return false;
        }
        boolean successfullyUsed = tryFeed(item.getType(), player);
        if (successfullyUsed && GameMode.CREATIVE != gameMode) {
            player.getInventory().consumeItem(message.getHand());
        }
        return successfullyUsed;
    }
    return false;
}
Also used : GameMode(org.bukkit.GameMode) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

GameMode (org.bukkit.GameMode)22 Player (org.bukkit.entity.Player)7 Location (org.bukkit.Location)3 ItemStack (org.bukkit.inventory.ItemStack)3 ModelFlying (fr.neatmonster.nocheatplus.checks.moving.model.ModelFlying)2 ResourceBundle (java.util.ResourceBundle)2 LocalizedStringImpl (net.glowstone.i18n.LocalizedStringImpl)2 Entity (org.bukkit.entity.Entity)2 EventHandler (org.bukkit.event.EventHandler)2 MinigameType (au.com.mineauz.minigames.gametypes.MinigameType)1 GameMechanicBase (au.com.mineauz.minigames.mechanics.GameMechanicBase)1 Callback (au.com.mineauz.minigames.menu.Callback)1 Menu (au.com.mineauz.minigames.menu.Menu)1 MenuItem (au.com.mineauz.minigames.menu.MenuItem)1 MenuItemAddFlag (au.com.mineauz.minigames.menu.MenuItemAddFlag)1 MenuItemBoolean (au.com.mineauz.minigames.menu.MenuItemBoolean)1 MenuItemCustom (au.com.mineauz.minigames.menu.MenuItemCustom)1 MenuItemDisplayLoadout (au.com.mineauz.minigames.menu.MenuItemDisplayLoadout)1 MenuItemDisplayWhitelist (au.com.mineauz.minigames.menu.MenuItemDisplayWhitelist)1 MenuItemFlag (au.com.mineauz.minigames.menu.MenuItemFlag)1