forked from SteamWar/SteamWar
Update CustomMap
This commit is contained in:
@@ -42,7 +42,10 @@ import java.awt.image.BufferedImage;
|
||||
import java.awt.image.WritableRaster;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Month;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class CustomMap implements Listener {
|
||||
|
||||
@@ -56,7 +59,7 @@ public class CustomMap implements Listener {
|
||||
new Vector(2346, 45, 1297), new Vector(2345, 45, 1297), new Vector(2344, 45, 1297), new Vector(2343, 45, 1297), new Vector(2342, 45, 1297), new Vector(2341, 45, 1297), new Vector(2340, 45, 1297)
|
||||
);
|
||||
|
||||
private static final CustomMap RIGHT = new CustomMap(new File(System.getProperty("user.home") + "/lobbyBanner/right.png"),
|
||||
private static final CustomMap RIGHT = new CustomMap(new File(System.getProperty("user.home") + "/lobbyBanner/right/"),
|
||||
new Vector(2330, 48, 1297), new Vector(2329, 48, 1297), new Vector(2328, 48, 1297), new Vector(2327, 48, 1297), new Vector(2326, 48, 1297), new Vector(2325, 48, 1297), new Vector(2324, 48, 1297),
|
||||
new Vector(2330, 47, 1297), new Vector(2329, 47, 1297), new Vector(2328, 47, 1297), new Vector(2327, 47, 1297), new Vector(2326, 47, 1297), new Vector(2325, 47, 1297), new Vector(2324, 47, 1297),
|
||||
new Vector(2330, 46, 1297), new Vector(2329, 46, 1297), new Vector(2328, 46, 1297), new Vector(2327, 46, 1297), new Vector(2326, 46, 1297), new Vector(2325, 46, 1297), new Vector(2324, 46, 1297),
|
||||
@@ -66,32 +69,51 @@ public class CustomMap implements Listener {
|
||||
private File mapFile;
|
||||
private Map<Vector, Integer> itemFrameIndex = new HashMap<>();
|
||||
private ItemFrame[] itemFrames;
|
||||
private long lastModified = Long.MAX_VALUE;
|
||||
private boolean update = true;
|
||||
|
||||
public CustomMap(File mapFile, Vector... itemFrames) {
|
||||
this.mapFile = mapFile;
|
||||
public CustomMap(File mapFileOrDirectory, Vector... itemFrames) {
|
||||
this.mapFile = mapFileOrDirectory;
|
||||
this.itemFrames = new ItemFrame[itemFrames.length];
|
||||
for (int i = 0; i < itemFrames.length; i++) {
|
||||
itemFrameIndex.put(itemFrames[i], i);
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().runTaskTimer(LobbySystem.getInstance(), () -> {
|
||||
long modified = mapFile.lastModified();
|
||||
if (modified > lastModified) {
|
||||
lastModified = modified;
|
||||
System.out.println("Updating Banner: " + mapFile.getName());
|
||||
Bukkit.getScheduler().runTaskAsynchronously(LobbySystem.getInstance(), () -> {
|
||||
try {
|
||||
run();
|
||||
} catch (IOException e) {
|
||||
// Ignore
|
||||
}
|
||||
});
|
||||
}
|
||||
}, 200L, 200L);
|
||||
if (mapFileOrDirectory.isDirectory()) {
|
||||
AtomicReference<Month> lastMonth = new AtomicReference<>(LocalDateTime.now().getMonth());
|
||||
Bukkit.getScheduler().runTaskTimer(LobbySystem.getInstance(), () -> {
|
||||
Month current = LocalDateTime.now().getMonth();
|
||||
if (!current.equals(lastMonth.get()) || update) {
|
||||
lastMonth.set(current);
|
||||
update = false;
|
||||
this.mapFile = new File(mapFileOrDirectory, current.getValue() + ".png");
|
||||
update();
|
||||
}
|
||||
}, 200L, 1200L);
|
||||
} else {
|
||||
AtomicReference<Long> lastModified = new AtomicReference<>();
|
||||
Bukkit.getScheduler().runTaskTimer(LobbySystem.getInstance(), () -> {
|
||||
long modified = mapFileOrDirectory.lastModified();
|
||||
if (modified > lastModified.get() || update) {
|
||||
lastModified.set(modified);
|
||||
update = false;
|
||||
update();
|
||||
}
|
||||
}, 200L, 200L);
|
||||
}
|
||||
Bukkit.getPluginManager().registerEvents(this, LobbySystem.getInstance());
|
||||
}
|
||||
|
||||
private void update() {
|
||||
System.out.println("Updating Banner: " + mapFile.getName());
|
||||
Bukkit.getScheduler().runTaskAsynchronously(LobbySystem.getInstance(), () -> {
|
||||
try {
|
||||
run();
|
||||
} catch (IOException e) {
|
||||
// Ignore
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChunkLoad(ChunkLoadEvent event) {
|
||||
for (Entity entity : event.getChunk().getEntities()) {
|
||||
@@ -101,7 +123,7 @@ public class CustomMap implements Listener {
|
||||
if (itemFrameIndex.containsKey(vector)) {
|
||||
if (itemFrames[itemFrameIndex.get(vector)] != null) continue;
|
||||
itemFrames[itemFrameIndex.get(vector)] = itemFrame;
|
||||
lastModified = 0;
|
||||
update = true;
|
||||
|
||||
ItemStack itemStack = new ItemStack(Material.FILLED_MAP, 1);
|
||||
MapMeta mapMeta = (MapMeta) itemStack.getItemMeta();
|
||||
|
||||
Reference in New Issue
Block a user