Java Code Examples for org.bukkit.GameMode#valueOf()

The following examples show how to use org.bukkit.GameMode#valueOf() . 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: XMLUtils.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public static GameMode parseGameMode(Node node, String text) throws InvalidXMLException {
    text = text.trim();
    try {
        return GameMode.valueOf(text.toUpperCase());
    } catch(IllegalArgumentException e) {
        throw new InvalidXMLException("Unknown game-mode '" + text + "'", node);
    }
}
 
Example 2
Source File: ListenerGameMode.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
private GameMode getGameMode() {
    FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml");
    String gameModeString = config.getString("game-mode.game-mode");

    try {
        return GameMode.valueOf(gameModeString);
    } catch(IllegalArgumentException | NullPointerException ex) {
        Logger logger = this.expansion.getLogger();
        logger.log(Level.WARNING, "Invalid GameMode '" + gameModeString + "'. Defaulting to SURVIVAL.");
        return GameMode.SURVIVAL;
    }
}
 
Example 3
Source File: GroupManager.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Loads the groups defined in a 'worlds.yml' file into memory.
 *
 * @param config The contents of the configuration file.
 */
public void loadGroupsToMemory(FileConfiguration config) {
    groups.clear();

    for (String key : config.getConfigurationSection("groups.").getKeys(false)) {
        List<String> worlds;
        if (config.contains("groups." + key + ".worlds")) {
            worlds = config.getStringList("groups." + key + ".worlds");
        } else {
            worlds = config.getStringList("groups." + key);
            config.set("groups." + key, null);
            config.set("groups." + key + ".worlds", worlds);
            if (settings.getProperty(PwiProperties.SEPARATE_GAMEMODE_INVENTORIES)) {
                config.set("groups." + key + ".default-gamemode", "SURVIVAL");
            }
        }

        if (settings.getProperty(PwiProperties.MANAGE_GAMEMODES)) {
            GameMode gameMode = GameMode.SURVIVAL;
            if (config.getString("groups." + key + ".default-gamemode") != null) {
                gameMode = GameMode.valueOf(config.getString("groups." + key + ".default-gamemode").toUpperCase());
            }

            addGroup(key, worlds, gameMode);
        } else {
            addGroup(key, worlds);
        }

        setDefaultsFile(key);
    }
}
 
Example 4
Source File: GameModeCondition.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
public GameModeCondition(Instruction instruction) throws InstructionParseException {
    super(instruction, true);
    String string = instruction.next().toUpperCase();
    try {
        gameMode = GameMode.valueOf(string);
    } catch (IllegalArgumentException e) {
        throw new InstructionParseException("No such gamemode: " + string, e);
    }
}
 
Example 5
Source File: GroupManager.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Loads the groups defined in a 'worlds.yml' file into memory.
 *
 * @param config The contents of the configuration file.
 */
public void loadGroupsToMemory(FileConfiguration config) {
    groups.clear();

    for (String key : config.getConfigurationSection("groups.").getKeys(false)) {
        List<String> worlds;
        if (config.contains("groups." + key + ".worlds")) {
            worlds = config.getStringList("groups." + key + ".worlds");
        } else {
            worlds = config.getStringList("groups." + key);
            config.set("groups." + key, null);
            config.set("groups." + key + ".worlds", worlds);
            if (settings.getProperty(PwiProperties.SEPARATE_GAMEMODE_INVENTORIES)) {
                config.set("groups." + key + ".default-gamemode", "SURVIVAL");
            }
        }

        if (settings.getProperty(PwiProperties.MANAGE_GAMEMODES)) {
            GameMode gameMode = GameMode.SURVIVAL;
            if (config.getString("groups." + key + ".default-gamemode") != null) {
                gameMode = GameMode.valueOf(config.getString("groups." + key + ".default-gamemode").toUpperCase());
            }

            addGroup(key, worlds, gameMode);
        } else {
            addGroup(key, worlds);
        }

        setDefaultsFile(key);
    }
}
 
Example 6
Source File: CreateTutorial.java    From ServerTutorial with MIT License 5 votes vote down vote up
@Override
public Prompt acceptInput(ConversationContext context, String input) {
    try {
        GameMode gm = GameMode.valueOf(input.toUpperCase());
        context.setSessionData("gamemode", gm.toString().toUpperCase());
        return new EndCommandTypeMessage();
    } catch (IllegalArgumentException e) {
        return new GamemodeMessage();
    }
}
 
Example 7
Source File: GameVars.java    From AnnihilationPro with MIT License 4 votes vote down vote up
public static void loadGameVars(ConfigurationSection config)
	{
		if(config != null)
		{
			useMOTD = config.getBoolean("useMOTD");
			endOfGameCountdown = config.getInt("End-Of-Game-Countdown");
			String command = config.getString("EndGameCommand");
			if(command != null)
				endGameCommand = command.trim();
			//killOnLeave = config.getBoolean("Kill-On-Leave");
			ConfigurationSection gameVars = config.getConfigurationSection("GameVars");
			if(gameVars != null)
			{		
				ConfigurationSection auto = gameVars.getConfigurationSection("AutoStart");
				AutoStart = auto.getBoolean("On");//auto.set("On", false);
				PlayerstoStart = auto.getInt("PlayersToStart");//auto.set("PlayersToStart", 4);
				CountdowntoStart = auto.getInt("CountdownTime");
				
				ConfigurationSection mapload = gameVars.getConfigurationSection("MapLoading");
				Voting = mapload.getBoolean("Voting");//mapload.set("Voting", true);
				maxVotingMaps = mapload.getInt("Max-Maps-For-Voting");
				Map = mapload.getString("UseMap");//mapload.set("UseMap", "plugins/Annihilation/Worlds/Test");
				
				ConfigurationSection autorestart = gameVars.getConfigurationSection("AutoRestart");
				AutoReStart = autorestart.getBoolean("On");//autorestart.set("On", false);
				PlayersToRestart = autorestart.getInt("PlayersToAutoRestart");//autorestart.set("PlayersToAutoRestart", 0);
				CountdowntoRestart = autorestart.getInt("CountdownTime");
				
				ConfigurationSection balance = gameVars.getConfigurationSection("Team-Balancing");
				useTeamBalance = balance.getBoolean("On");//autorestart.set("On", false);
				balanceTolerance = balance.getInt("Tolerance");//autorestart.set("PlayersToAutoRestart", 0);

                ConfigurationSection antilog = gameVars.getConfigurationSection("Anti-Log-System");
                useAntiLog = antilog.getBoolean("On");//autorestart.set("On", false);
                npcTimeout = antilog.getInt("NPC-Time");//autorestart.set("PlayersToAutoRestart", 0);
			
				String gamemode = gameVars.getString("DefaultGameMode");
				if(gamemode != null)
				{
					try
					{
						defaultGamemode = GameMode.valueOf(gamemode.toUpperCase());
					}
					catch(Exception e)
					{
						defaultGamemode = GameMode.ADVENTURE;
					}
				}
			}
		}
		File worldFolder = new File(AnnihilationMain.getInstance().getDataFolder().getAbsolutePath()+"/Worlds");
		if(!worldFolder.exists())
			worldFolder.mkdir();
//		tempWorldPath = AnnihilationMain.getInstance().getDataFolder().getAbsolutePath()+"/TempWorld";
//		worldFolder = new File(tempWorldPath);
//		if(!worldFolder.exists())
//			worldFolder.mkdir();
	}
 
Example 8
Source File: PWIPlayerManager.java    From PerWorldInventory with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Save all cached instances of a player to the disk.
 *
 * @param group The Group the player is currently in.
 * @param player The player to save.
 * @param createTask If a new task should be started.
 */
public void savePlayer(Group group, Player player, boolean createTask) {
    String key = makeKey(player.getUniqueId(), group, player.getGameMode());

    // Remove any entry with the current key, if one exists
    // Should remove the possibility of having to write the same data twice
    playerCache.remove(key);

    for (String cachedKey : playerCache.keySet()) {
        if (cachedKey.startsWith(player.getUniqueId().toString())) {
            PWIPlayer cached = playerCache.get(cachedKey);
            if (cached.isSaved()) {
                continue;
            }

            String[] parts = cachedKey.split("\\.");
            Group groupKey = groupManager.getGroup(parts[1]);
            GameMode gamemode = GameMode.valueOf(parts[2].toUpperCase());

            ConsoleLogger.debug("Saving cached player '" + cached.getName() + "' for group '" + groupKey.getName() + "' with gamemdde '" + gamemode.name() + "'");

            cached.setSaved(true);
            if (!createTask) {
                dataSource.saveToDatabase(groupKey, gamemode, cached);
            } else {
                bukkitService.runTaskAsync(() -> dataSource.saveToDatabase(groupKey, gamemode, cached));
            }
        }
    }

    PWIPlayer pwiPlayer = pwiPlayerFactory.create(player, group);
    if (!createTask) {
        dataSource.saveToDatabase(group,
                settings.getProperty(PwiProperties.SEPARATE_GAMEMODE_INVENTORIES) ? player.getGameMode() : GameMode.SURVIVAL,
                pwiPlayer);
    } else {
        bukkitService.runTaskAsync(() -> dataSource.saveToDatabase(group,
                settings.getProperty(PwiProperties.SEPARATE_GAMEMODE_INVENTORIES) ? player.getGameMode() : GameMode.SURVIVAL,
                pwiPlayer));
    }
    dataSource.saveLogoutData(pwiPlayer, createTask); // If we're disabling, cant create a new task
    removePlayer(player);
}
 
Example 9
Source File: PWIPlayerManager.java    From PerWorldInventory with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Save all cached instances of a player to the disk.
 *
 * @param group The Group the player is currently in.
 * @param player The player to save.
 * @param createTask If a new task should be started.
 */
public void savePlayer(Group group, Player player, boolean createTask) {
    String key = makeKey(player.getUniqueId(), group, player.getGameMode());

    // Remove any entry with the current key, if one exists
    // Should remove the possibility of having to write the same data twice
    playerCache.remove(key);

    for (String cachedKey : playerCache.keySet()) {
        if (cachedKey.startsWith(player.getUniqueId().toString())) {
            PWIPlayer cached = playerCache.get(cachedKey);
            if (cached.isSaved()) {
                continue;
            }

            String[] parts = cachedKey.split("\\.");
            Group groupKey = groupManager.getGroup(parts[1]);
            GameMode gamemode = GameMode.valueOf(parts[2].toUpperCase());

            ConsoleLogger.debug("Saving cached player '" + cached.getName() + "' for group '" + groupKey.getName() + "' with gamemdde '" + gamemode.name() + "'");

            cached.setSaved(true);
            if (!createTask) {
                dataSource.saveToDatabase(groupKey, gamemode, cached);
            } else {
                bukkitService.runTaskAsync(() -> dataSource.saveToDatabase(groupKey, gamemode, cached));
            }
        }
    }

    PWIPlayer pwiPlayer = pwiPlayerFactory.create(player, group);
    if (!createTask) {
        dataSource.saveToDatabase(group,
                settings.getProperty(PwiProperties.SEPARATE_GAMEMODE_INVENTORIES) ? player.getGameMode() : GameMode.SURVIVAL,
                pwiPlayer);
    } else {
        bukkitService.runTaskAsync(() -> dataSource.saveToDatabase(group,
                settings.getProperty(PwiProperties.SEPARATE_GAMEMODE_INVENTORIES) ? player.getGameMode() : GameMode.SURVIVAL,
                pwiPlayer));
    }
    dataSource.saveLogoutData(pwiPlayer, createTask); // If we're disabling, cant create a new task
    removePlayer(player);
}
 
Example 10
Source File: TempPlayerData.java    From ServerTutorial with MIT License 4 votes vote down vote up
private void getTempPlayerData() {
    this.inventory = Base64Serialize.fromBase64(DataLoading.getDataLoading().getTempData().getString("players." + this.playerUUID + ".inventory"));
    this.gameMode = GameMode.valueOf(DataLoading.getDataLoading().getTempData().getString("players." + this.playerUUID + ".gamemode"));
    this.armorItemStack = Base64Serialize.itemStackArrayFromBase64(DataLoading.getDataLoading().getTempData().getString("players." + this.playerUUID + ".armor"));
}