This repository has been archived by the owner on Apr 12, 2022. It is now read-only.
/
EditBlockCommand.java
77 lines (68 loc) · 2.83 KB
/
EditBlockCommand.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
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.tags.objects.MapTag;
import com.denizenscript.denizen2core.utilities.debugging.ColorSet;
import com.denizenscript.denizen2sponge.Denizen2Sponge;
import com.denizenscript.denizen2sponge.tags.objects.LocationTag;
import com.denizenscript.denizen2sponge.utilities.DataKeys;
import org.spongepowered.api.block.BlockState;
import org.spongepowered.api.data.key.Key;
import org.spongepowered.api.world.BlockChangeFlag;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;
import java.util.Map;
public class EditBlockCommand extends AbstractCommand {
// <--[command]
// @Name editblock
// @Arguments <location> <map of properties>
// @Short Edits a block.
// @Updated 2016/09/29
// @Group World
// @Minimum 2
// @Maximum 2
// @Description
// Edits a location in a world to have the specified map of new properties.
// @Example
// # Edits a wool block to be blue.
// - editblock <player.location> dye_color:blue
// -->
@Override
public String getName() {
return "editblock";
}
@Override
public String getArguments() {
return "<location> <map of properties>";
}
@Override
public int getMinimumArguments() {
return 2;
}
@Override
public int getMaximumArguments() {
return 2;
}
@Override
public void execute(CommandQueue queue, CommandEntry entry) {
LocationTag locationTag = LocationTag.getFor(queue.error, entry.getArgumentObject(queue, 0));
Location<World> loc = locationTag.getInternal().toLocation();
BlockState bs = loc.getBlock();
MapTag propertyMap = MapTag.getFor(queue.error, entry.getArgumentObject(queue, 1));
for (Map.Entry<String, AbstractTagObject> mapEntry : propertyMap.getInternal().entrySet()) {
Key found = DataKeys.getKeyForName(mapEntry.getKey());
if (found == null) {
queue.handleError(entry, "Invalid property '" + mapEntry.getKey() + "' in EditBlock command!");
return;
}
bs = (BlockState) DataKeys.with(bs, found, mapEntry.getValue(), queue.error);
}
loc.setBlock(bs, BlockChangeFlag.NONE);
if (queue.shouldShowGood()) {
queue.outGood("Edited the location " + ColorSet.emphasis + locationTag.debug() + ColorSet.good
+ " to have the new following properties: " + propertyMap.debug());
}
}
}