-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.java
More file actions
127 lines (112 loc) · 3.63 KB
/
Copy pathConfig.java
File metadata and controls
127 lines (112 loc) · 3.63 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package treebreaker;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraftforge.common.Configuration;
import cpw.mods.fml.common.FMLLog;
public class Config {
public static final String channel = "tb";
public static Set<Integer> logs = new LinkedHashSet();
public static Set<Integer> leaves = new LinkedHashSet();
public static Set<String> tools = new LinkedHashSet();
public static boolean effective_tool_only = true;
public static EnumMode mode = EnumMode.off;
public static List<EnumMode> allowMode = new ArrayList();
public boolean drop_to_player = true;
public boolean allow_register = true;
public void load(File file) {
Configuration cfg = new Configuration(file);
try {
cfg.load();
String value = cfg.get(Configuration.CATEGORY_GENERAL, "logIDs", "17").getString();
for(String token : value.split(",")) {
try {
Integer blockId = Integer.parseInt(token.trim());
if(blockId != null) {
logs.add(blockId.intValue());
}
}
catch(NumberFormatException e) {
}
}
value = cfg.get(Configuration.CATEGORY_GENERAL, "leavesIDs", "18").getString();
for(String token : value.split(",")) {
try {
Integer blockId = Integer.parseInt(token.trim());
if(blockId != null) {
leaves.add(blockId.intValue());
}
}
catch(NumberFormatException e) {
}
}
value = cfg.get(Configuration.CATEGORY_GENERAL, "additional_tools", "").getString();
for(String token : value.split(",")) {
try {
tools.add(token);
}
catch(NumberFormatException e) {
}
}
effective_tool_only = cfg.get(Configuration.CATEGORY_GENERAL, "effective_tool_only", true).getBoolean(true);
drop_to_player = cfg.get(Configuration.CATEGORY_GENERAL, "drop_to_player", true).getBoolean(true);
allow_register = cfg.get(Configuration.CATEGORY_GENERAL, "allow_register", true).getBoolean(true);
allowMode.add(EnumMode.off);
if(cfg.get(Configuration.CATEGORY_GENERAL, "enable_treebreaker", true).getBoolean(true)) {
allowMode.add(EnumMode.logs);
allowMode.add(EnumMode.leaves);
allowMode.add(EnumMode.all);
}
cfg.save();
} catch (Exception e) {
FMLLog.log(Level.SEVERE, e, "TreeBreaker load config exception");
} finally {
cfg.save();
}
}
public void toggleMode() {
for(int i = 0; i < allowMode.size(); ++i) {
if(allowMode.get(i).equals(mode)) {
i = (i + 1) % allowMode.size();
mode = allowMode.get(i);
break;
}
}
}
public EnumMode getMode() {
return mode;
}
public void sendTargetToPlayer(INetworkManager manager) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream stream = new DataOutputStream(bytes);
try {
stream.writeUTF(EnumCommand.TARGET.toString());
stream.writeInt(TreeBreaker.config.logs.size());
for(int blockId : TreeBreaker.config.logs) {
stream.writeInt(blockId);
stream.writeInt(0);
}
stream.writeInt(TreeBreaker.config.leaves.size());
for(int blockId : TreeBreaker.config.leaves) {
stream.writeInt(blockId);
stream.writeInt(0);
}
Packet250CustomPayload packet = new Packet250CustomPayload();
packet.channel = Config.channel;
packet.data = bytes.toByteArray();
packet.length = packet.data.length;
manager.addToSendQueue(packet);
} catch (IOException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
}
}
}