Skip to content

Commit 5cf84c0

Browse files
committed
Various minor changes for 1.14
1 parent c928033 commit 5cf84c0

File tree

7 files changed

+64
-14
lines changed

7 files changed

+64
-14
lines changed

src/main/java/vg/civcraft/mc/civmodcore/locations/chunkmeta/ChunkCoord.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import org.bukkit.World;
1010

11-
public class ChunkCoord {
11+
public class ChunkCoord implements Comparable<ChunkCoord>{
1212

1313
/**
1414
* When was this chunk last loaded in Minecraft as UNIX timestamp
@@ -37,10 +37,10 @@ public class ChunkCoord {
3737
*/
3838
private int z;
3939

40-
private int worldID;
40+
private short worldID;
4141
private World world;
4242

43-
ChunkCoord(int x, int z, int worldID, World world) {
43+
ChunkCoord(int x, int z, short worldID, World world) {
4444
this.x = x;
4545
this.z = z;
4646
this.worldID = worldID;
@@ -135,7 +135,7 @@ ChunkMeta<?> getMeta(int pluginID) {
135135
/**
136136
* @return Internal ID of the world this chunk is in
137137
*/
138-
public int getWorldID() {
138+
public short getWorldID() {
139139
return worldID;
140140
}
141141

@@ -189,4 +189,17 @@ void minecraftChunkLoaded() {
189189
void minecraftChunkUnloaded() {
190190
this.lastUnloadingTime = System.currentTimeMillis();
191191
}
192+
193+
@Override
194+
public int compareTo(ChunkCoord o) {
195+
int worldComp = Short.compare(this.worldID, o.getWorldID());
196+
if (worldComp != 0) {
197+
return worldComp;
198+
}
199+
int xComp = Integer.compare(this.x, o.getX());
200+
if (xComp != 0) {
201+
return worldComp;
202+
}
203+
return Integer.compare(this.z, o.getZ());
204+
}
192205
}

src/main/java/vg/civcraft/mc/civmodcore/locations/chunkmeta/ChunkDAO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public int getOrCreatePluginID(JavaPlugin plugin) {
5555
}
5656
}
5757

58-
int getOrCreateWorldID(World world) {
58+
short getOrCreateWorldID(World world) {
5959
try (Connection insertConn = db.getConnection();
6060
PreparedStatement insertWorld = insertConn
6161
.prepareStatement("select id from cmc_worlds where uuid = ?;")) {

src/main/java/vg/civcraft/mc/civmodcore/locations/chunkmeta/GlobalChunkMetaManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
public class GlobalChunkMetaManager {
1515

16-
private Map<UUID, Integer> uuidToInternalID;
16+
private Map<UUID, Short> uuidToInternalID;
1717
private Map<UUID, WorldChunkMetaManager> worldToManager;
1818
private ChunkDAO chunkDao;
1919

@@ -115,7 +115,7 @@ boolean registerWorld(World world) {
115115
if (uuidToInternalID.containsKey(world.getUID())) {
116116
return true;
117117
}
118-
int id = chunkDao.getOrCreateWorldID(world);
118+
short id = chunkDao.getOrCreateWorldID(world);
119119
if (id == -1) {
120120
// very bad
121121
return false;

src/main/java/vg/civcraft/mc/civmodcore/locations/chunkmeta/WorldChunkMetaManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class WorldChunkMetaManager {
3131
private static final long UNLOAD_DELAY = 5L * 60L * 1000L;
3232
private static final long UNLOAD_CHECK_INTERVAL = 5L * 60L * 1000L;
3333

34-
private final int worldID;
34+
private final short worldID;
3535
private final Map<ChunkCoord, ChunkCoord> metas;
3636
/**
3737
* A synchronized TreeSet holding all chunk metadata belonging to unloaded
@@ -45,7 +45,7 @@ public class WorldChunkMetaManager {
4545
private Queue<ChunkCoord> chunkLoadingQueue;
4646
private World world;
4747

48-
public WorldChunkMetaManager(World world, int worldID) {
48+
public WorldChunkMetaManager(World world, short worldID) {
4949
this.worldID = worldID;
5050
this.world = world;
5151
this.metas = new HashMap<>();

src/main/java/vg/civcraft/mc/civmodcore/locations/chunkmeta/block/table/TableBasedBlockChunkMeta.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public void put(int x, int y, int z, TableBasedDataObject blockData, boolean isN
6767
public void remove(TableBasedDataObject blockData) {
6868
super.remove(blockData);
6969
blockData.setCacheState(CacheState.DELETED);
70+
//this may look weird, but is what happens if the data was NEW previously, never written to the
71+
//db and doesn't need to be deleted from there either
7072
if (blockData.getCacheState() != CacheState.NORMAL) {
7173
modifiedEntries.add((D) blockData);
7274
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package vg.civcraft.mc.civmodcore.util;
2+
3+
import java.util.Comparator;
4+
5+
import org.bukkit.Location;
6+
7+
public class BukkitComparators {
8+
9+
private BukkitComparators() {
10+
11+
}
12+
13+
public static Comparator<Location> getLocation() {
14+
return (l1, l2) -> {
15+
int worldComp = l1.getWorld().getUID().compareTo(l2.getWorld().getUID());
16+
if (worldComp != 0) {
17+
return worldComp;
18+
}
19+
int xComp = Double.compare(l1.getX(), l2.getX());
20+
if (xComp != 0) {
21+
return xComp;
22+
}
23+
int zComp = Double.compare(l1.getZ(), l2.getZ());
24+
if (zComp != 0) {
25+
return zComp;
26+
}
27+
return Double.compare(l1.getY(), l2.getY());
28+
};
29+
}
30+
31+
}

src/main/java/vg/civcraft/mc/civmodcore/util/ConfigParsing.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,7 @@ public static ItemMap parseItemMapDirectly(ConfigurationSection current) {
198198
}
199199

200200
public static long parseTime(String arg, TimeUnit unit) {
201-
long inTicks = parseTime(arg);
202-
long millis = inTicks * 50;
201+
long millis = parseTime(arg);
203202
return unit.convert(millis, TimeUnit.MILLISECONDS);
204203
}
205204

@@ -217,7 +216,7 @@ public static long parseTime(String arg, TimeUnit unit) {
217216
* different values, but the values are not allowed to be separated by anything
218217
*
219218
* @param input Parsed string containing the time format
220-
* @return How many ticks the given time value is
219+
* @return How many milliseconds the given time value is
221220
*/
222221
public static long parseTime(String input) {
223222
input = input.replace(" ", "").replace(",", "").toLowerCase();
@@ -228,9 +227,9 @@ public static long parseTime(String input) {
228227
} catch (NumberFormatException e) {
229228
}
230229
while (!input.equals("")) {
231-
String typeSuffix = getSuffix(input, a -> Character.isLetter(a));
230+
String typeSuffix = getSuffix(input, Character::isLetter);
232231
input = input.substring(0, input.length() - typeSuffix.length());
233-
String numberSuffix = getSuffix(input, a -> Character.isDigit(a));
232+
String numberSuffix = getSuffix(input, Character::isDigit);
234233
input = input.substring(0, input.length() - numberSuffix.length());
235234
long duration;
236235
if (numberSuffix.length() == 0) {
@@ -275,6 +274,11 @@ public static long parseTime(String input) {
275274
case "months":
276275
result += TimeUnit.DAYS.toMillis(duration * 30);
277276
break;
277+
case "y":
278+
case "year":
279+
case "years":
280+
result += TimeUnit.DAYS.toMillis(duration * 365);
281+
break;
278282
case "never":
279283
case "inf":
280284
case "infinite":

0 commit comments

Comments
 (0)