aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/MylesAndMore/tumble/commands/SetWorldConfig.java
blob: 840625300fe17f35822e4c64ea92b4b620dc919e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.MylesAndMore.tumble.commands;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;

import java.util.Objects;

public class SetWorldConfig implements CommandExecutor {
    Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("tumble");

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        // Initialize vars for their respective command arguments
        String world = args[0];
        String worldType = args[1];
        // Catch for null arguments
        if (args.length > 0) {
            // Check if the world type is lobby
            if (Objects.equals(worldType, "lobby")) {
                // Check if the world is actually a world on the server
                if (Bukkit.getWorld(world) != null) {
                    // Set the specified value of the world in the config under lobbyWorld
                    plugin.getConfig().set("lobbyWorld", world);
                    // Save said config
                    plugin.saveConfig();
                    // Feedback
                    sender.sendMessage(ChatColor.GREEN + "Lobby world successfully linked: " + ChatColor.GRAY + world);
                    sender.sendMessage(ChatColor.GREEN + "Run /tumble:reload for the changes to take effect.");
                }
                // Feedback for if the world doesn't exist
                else {
                    sender.sendMessage(ChatColor.RED + "Failed to find a world named " + ChatColor.GRAY + world);
                }
            }
            // Check if the world type is game
            else if (Objects.equals(args[1], "game")) {
                if (Bukkit.getWorld(world) != null) {
                    plugin.getConfig().set("gameWorld", world);
                    plugin.saveConfig();
                    sender.sendMessage(ChatColor.GREEN + "Game world successfully linked: " + ChatColor.GRAY + world);
                    sender.sendMessage(ChatColor.GREEN + "Run /tumble:reload for the changes to take effect.");
                }
                else {
                    sender.sendMessage(ChatColor.RED + "Failed to find a world named " + ChatColor.GRAY + world);
                }
            }
            // Feedback for if lobby or game wasn't entered
            else {
                sender.sendMessage(ChatColor.RED + "Allowed world types are " + ChatColor.GRAY + "lobby " + ChatColor.RED + "and " + ChatColor.GRAY + "game" + ChatColor.RED + ".");
            }
        }
        // Feedback for if no args were entered
        else {
            sender.sendMessage(ChatColor.RED + "Usage: " + ChatColor.GRAY + "/tumble:setworld <world> lobby|game");
        }
        return true;
    }
}