-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
CopyBlockCommand.java
72 lines (52 loc) · 2.61 KB
/
CopyBlockCommand.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
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.arguments.dLocation;
import net.aufdemrand.denizen.arguments.aH;
import net.aufdemrand.denizen.arguments.aH.ArgumentType;
import net.aufdemrand.denizen.utilities.debugging.dB.Messages;
import org.bukkit.block.Block;
import org.bukkit.inventory.InventoryHolder;
/**
* Modifies blocks based based of single block location.
* Possibility to do faux animations with blocks.
*
* @author Mason Adkins
*/
public class CopyBlockCommand extends AbstractCommand{
@Override
public void parseArgs(ScriptEntry scriptEntry)throws InvalidArgumentsException {
dLocation copy_location = null;
dLocation destination = null;
boolean remove_original = false;
for (String arg : scriptEntry.getArguments()) {
if (aH.matchesLocation(arg))
copy_location = aH.getLocationFrom(arg);
if (aH.matchesValueArg("to", arg, ArgumentType.Location))
destination = aH.getLocationFrom(arg);
if (aH.matchesArg("and_remove", arg))
remove_original = true;
else throw new InvalidArgumentsException(Messages.ERROR_UNKNOWN_ARGUMENT, arg);
}
if (copy_location == null || destination == null)
throw new InvalidArgumentsException(Messages.ERROR_MISSING_LOCATION);
scriptEntry.addObject("copy_location", copy_location)
.addObject("destination", destination)
.addObject("remove_original", remove_original);
}
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
dLocation copy_location = (dLocation) scriptEntry.getObject("copy_location");
dLocation destination = (dLocation) scriptEntry.getObject("destination");
Boolean remove_original = (Boolean) scriptEntry.getObject("remove_original");
Block source = copy_location.getBlock();
Block update = destination.getBlock();
update.setTypeIdAndData(source.getTypeId(), source.getData(), false);
if (source instanceof InventoryHolder)
((InventoryHolder) update.getState()).getInventory()
.setContents(((InventoryHolder) source.getState()).getInventory().getContents());
// TODO: Account for Noteblock, Skull, Jukebox, Sign
}
}