This repository has been archived by the owner on Apr 12, 2022. It is now read-only.
/
DifficultyCommand.java
81 lines (72 loc) · 2.8 KB
/
DifficultyCommand.java
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.denizenscript.denizen2sponge.commands.world;
import com.denizenscript.denizen2core.commands.AbstractCommand;
import com.denizenscript.denizen2core.commands.CommandEntry;
import com.denizenscript.denizen2core.commands.CommandQueue;
import com.denizenscript.denizen2core.tags.AbstractTagObject;
import com.denizenscript.denizen2core.utilities.debugging.ColorSet;
import com.denizenscript.denizen2sponge.tags.objects.WorldTag;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.world.difficulty.Difficulty;
import org.spongepowered.api.world.storage.WorldProperties;
import java.util.Optional;
public class DifficultyCommand extends AbstractCommand {
// <--[command]
// @Since 0.3.0
// @Name difficulty
// @Arguments <world> <difficulty level>
// @Short sets the difficulty of a world.
// @Updated 2017/09/07
// @Group World
// @Minimum 2
// @Maximum 2
// @Description
// Sets the difficulty of a world. The standard set of difficulty levels
// is 'peaceful', 'easy', 'normal', and 'hard'.
// @Example
// # Sets the difficulty to 'hard' in world 'Survival'.
// - difficulty Survival hard
// -->
@Override
public String getName() {
return "difficulty";
}
@Override
public String getArguments() {
return "<world> <difficulty level>";
}
@Override
public int getMinimumArguments() {
return 2;
}
@Override
public int getMaximumArguments() {
return 2;
}
@Override
public void execute(CommandQueue queue, CommandEntry entry) {
AbstractTagObject world = entry.getArgumentObject(queue, 0);
WorldProperties properties;
if (world instanceof WorldTag) {
properties = ((WorldTag) world).getInternal().getProperties();
}
else {
Optional<WorldProperties> opt = Sponge.getServer().getWorldProperties(world.toString());
if (!opt.isPresent()) {
queue.handleError(entry, "Invalid world specified!");
return;
}
properties = opt.get();
}
String difficulty = entry.getArgumentObject(queue, 1).toString();
Optional<Difficulty> type = Sponge.getRegistry().getType(Difficulty.class, difficulty);
if (!type.isPresent()) {
queue.handleError(entry, "Invalid difficulty level: '" + difficulty + "'!");
return;
}
properties.setDifficulty(type.get());
if (queue.shouldShowGood()) {
queue.outGood("Set difficulty of world '" + ColorSet.emphasis + properties.getWorldName()
+ ColorSet.good + "' to: " + ColorSet.emphasis + type.get().getName() + ColorSet.good + "!");
}
}
}