/
WorldCommand.java
121 lines (95 loc) · 4.3 KB
/
WorldCommand.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package net.aufdemrand.denizen.scripts.commands.core;
import net.aufdemrand.denizen.exceptions.CommandExecutionException;
import net.aufdemrand.denizen.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.scripts.commands.AbstractCommand;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.utilities.debugging.dB;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
/**
* Various world based commands.
* Such as: weather and times
*
* @author spaceemotion
*/
public class WorldCommand extends AbstractCommand {
private enum Action { WEATHER, TIME }
private enum SubAction {
// Time actions
DAY, NIGHT, DUSK, DAWN,
// Weather actions
THUNDERING, STORM, SUNNY, THUNDERSTORM
}
private enum Type { GLOBAL, PLAYER } // TODO: Player type will come when Bukkit PR gets accepted
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
Type type = Type.GLOBAL;
Action action = null;
SubAction sub = null;
Player player = scriptEntry.getPlayer().getPlayerEntity();
for (String arg : scriptEntry.getArguments()) {
if (aH.matchesArg("player", arg)) {
player = Bukkit.getServer().getPlayer(aH.getStringFrom("player"));
type = Type.PLAYER;
} else if (aH.matchesArg("weather", arg)) {
action = Action.WEATHER;
sub = SubAction.valueOf(aH.getStringFrom("weather"));
if(sub == null) throw new InvalidArgumentsException("Invalid sub action for WEATHER!");
} else if (aH.matchesArg("time", arg)) {
action = Action.TIME;
sub = SubAction.valueOf(aH.getStringFrom("time"));
if(sub == null) throw new InvalidArgumentsException("Invalid sub action for TIME!");
} else throw new InvalidArgumentsException(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg);
}
if (type == null)
throw new InvalidArgumentsException("Must specify an action! Valid: WEATHER, TIME");
scriptEntry.addObject("type", type);
scriptEntry.addObject("action", action);
scriptEntry.addObject("subaction", sub);
scriptEntry.addObject("player", player);
}
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
Type type = (Type) scriptEntry.getObject("time");
Action action = (Action) scriptEntry.getObject("action");
SubAction sub = (SubAction) scriptEntry.getObject("subaction");
Player player = (Player) scriptEntry.getObject("player");
dB.report(getName(),
aH.debugObj("Type", type.name())
+ aH.debugObj("Action", action.name())
+ aH.debugObj("Sub-Action", sub.name())
+ ((type == Type.PLAYER) ? aH.debugObj("Player", player.getName()) : ""));
switch(action) {
case WEATHER:
switch(sub) {
case SUNNY:
player.getWorld().setThundering(false);
player.getWorld().setStorm(false);
break;
case THUNDERSTORM:
player.getWorld().setThundering(true);
case STORM:
player.getWorld().setStorm(true);
break;
case THUNDERING:
player.getWorld().setThundering(true);
}
break;
case TIME:
switch(sub) {
case DAY:
player.getWorld().setTime(0);
break;
case NIGHT:
player.getWorld().setTime(13500);
break;
case DUSK:
player.getWorld().setTime(12500);
break;
case DAWN:
player.getWorld().setTime(23000);
}
}
}
}