summaryrefslogtreewikicommitdiff
path: root/src/main/java/cat/freya/khs/command/world/Tp.java
blob: ff6190aacd942d4f825cdc4a7d050b7a27df28c7 (plain)
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
package cat.freya.khs.command.world;

import cat.freya.khs.Main;
import cat.freya.khs.command.util.ICommand;
import cat.freya.khs.configuration.Config;
import cat.freya.khs.configuration.Localization;
import cat.freya.khs.util.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.List;

public class Tp implements ICommand {
    public void execute(Player sender, String[] args) {
        Location test = new Location(args[0], 0, 0,0);
        if(!test.exists()) {
            sender.sendMessage(Config.errorPrefix + Localization.message("WORLD_DOESNT_EXIT"));
            return;
        }
        World world = test.load();
        if(world == null) {
            sender.sendMessage(Config.errorPrefix + Localization.message("WORLD_LOAD_FAILED"));
            return;
        }
        Location loc = new Location(world.getName(), world.getSpawnLocation());
        loc.teleport(sender);
    }

    public String getLabel() {
        return "tp";
    }

    public String getUsage() {
        return "<world>";
    }

    public String getDescription() {
        return "Teleport to another world";
    }

    public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
        if(parameter.equals("world")) {
            return Main.getInstance().getWorlds();
        }
        return null;
    }
}