-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathCommandHandler.java
More file actions
104 lines (94 loc) · 3.41 KB
/
CommandHandler.java
File metadata and controls
104 lines (94 loc) · 3.41 KB
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
package com.github.devotedmc.hiddenore.commands;
import com.github.devotedmc.hiddenore.BlockConfig;
import com.github.devotedmc.hiddenore.Config;
import com.github.devotedmc.hiddenore.DropConfig;
import com.github.devotedmc.hiddenore.DropItemConfig;
import com.github.devotedmc.hiddenore.HiddenOre;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
/**
* Management and maintenance commands
*
* @author programmerdan
*/
public class CommandHandler implements CommandExecutor {
final HiddenOre plugin;
public CommandHandler(HiddenOre instance) {
plugin = instance;
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("hiddenore")) {
if (sender.hasPermission(plugin.getCommand("hiddenore").getPermission())) {
if (args.length >= 2) {
if ("debug".equals(args[0])) {
Config.isDebug = Boolean.parseBoolean(args[1]);
sender.sendMessage("HiddenOre debug mode now " + (Config.isDebug ? "on" : "off"));
return true;
}
}
if (args.length >= 1) {
if ("save".equals(args[0])) {
plugin.getTracking().liveSave();
sender.sendMessage("HiddenOre tracking forced live save scheduled");
return true;
} else if ("generate".equals(args[0])) {
if (!(sender instanceof Player)) {
sender.sendMessage("Cannot be run as console");
}
Player player = (Player) sender;
double mult = 1;
try {
mult = Integer.parseInt(args[1]);
} catch (Exception e) {mult = 1;}
final double vmult = mult;
final UUID world = player.getWorld().getUID();
sender.sendMessage("Generating all drops, this could cause lag");
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
long delay = 0l;
Map<NamespacedKey, List<BlockConfig>> worldBlockConfigs = Config.instance.blockConfigs.getOrDefault(world, Config.instance.blockConfigs.get(null));
if (worldBlockConfigs == null) {
sender.sendMessage("No drops configured for blocks in this world.");
return;
}
for (NamespacedKey blockConf : worldBlockConfigs.keySet()) {
for (BlockConfig block : worldBlockConfigs.get(blockConf)) {
for (String dropConf : block.getDrops()) {
DropConfig drop = block.getDropConfig(dropConf);
for (DropItemConfig item : drop.drops) {
Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
@Override
public void run() {
sender.sendMessage(String.format("Block: %s, drop: %s", blockConf.toString(), dropConf));
Item dropped = player.getWorld().dropItem(player.getLocation().add(0, 1.0, 0), item.render(vmult));
dropped.setPickupDelay(20);
}
}, delay++);
}
}
}
}
}
});
return true;
}
} else {
Bukkit.getPluginManager().disablePlugin(plugin, false);
Bukkit.getPluginManager().enablePlugin(plugin);
sender.sendMessage("HiddenOre reloaded");
return true;
}
}
}
return false;
}
}