/
WorldConfiguration.java
118 lines (100 loc) · 3.85 KB
/
WorldConfiguration.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
/*
* WorldGuard, a suite of tools for Minecraft
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.config;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import com.sk89q.worldguard.blacklist.Blacklist;
import com.sk89q.worldguard.util.report.Unreported;
import java.io.File;
import java.util.List;
import java.util.logging.Logger;
import java.util.stream.Collectors;
/**
* Holds the configuration for individual worlds.
*
* @author sk89q
* @author Michael
*/
public abstract class WorldConfiguration {
public static final Logger log = Logger.getLogger(WorldConfiguration.class.getCanonicalName());
public static final String CONFIG_HEADER = "#\r\n" +
"# WorldGuard's world configuration file\r\n" +
"#\r\n" +
"# This is a world configuration file. Anything placed into here will only\r\n" +
"# affect this world. If you don't put anything in this file, then the\r\n" +
"# settings will be inherited from the main configuration file.\r\n" +
"#\r\n" +
"# If you see {} below, that means that there are NO entries in this file.\r\n" +
"# Remove the {} and add your own entries.\r\n" +
"#\r\n";
@Unreported private String worldName;
protected File blacklistFile;
@Unreported protected Blacklist blacklist;
public boolean boundedLocationFlags;
public boolean useRegions;
/**
* Load the configuration.
*/
public abstract void loadConfiguration();
public Blacklist getBlacklist() {
return this.blacklist;
}
public String getWorldName() {
return this.worldName;
}
public List<String> convertLegacyItems(List<String> legacyItems) {
return legacyItems.stream().map(this::convertLegacyItem).collect(Collectors.toList());
}
public String convertLegacyItem(String legacy) {
String item = legacy;
try {
String[] splitter = item.split(":", 2);
int id = 0;
byte data = 0;
if (splitter.length == 1) {
id = Integer.parseInt(item);
} else {
id = Integer.parseInt(splitter[0]);
data = Byte.parseByte(splitter[1]);
}
item = LegacyMapper.getInstance().getItemFromLegacy(id, data).getId();
} catch (Throwable e) {
}
return item;
}
public List<String> convertLegacyBlocks(List<String> legacyBlocks) {
return legacyBlocks.stream().map(this::convertLegacyBlock).collect(Collectors.toList());
}
public String convertLegacyBlock(String legacy) {
String block = legacy;
try {
String[] splitter = block.split(":", 2);
int id = 0;
byte data = 0;
if (splitter.length == 1) {
id = Integer.parseInt(block);
} else {
id = Integer.parseInt(splitter[0]);
data = Byte.parseByte(splitter[1]);
}
block = LegacyMapper.getInstance().getBlockFromLegacy(id, data).getBlockType().getId();
} catch (Throwable e) {
}
return block;
}
}