115 lines
5.2 KiB
JavaScript
115 lines
5.2 KiB
JavaScript
// Announcements shown to players on join.
|
|
// NOTE: the previous implementation used a Java TreeMap keyed by
|
|
// DefaultArtifactVersion. On this KubeJS/Rhino version, ANY member access on a
|
|
// non-empty Java map (e.g. `map.computeIfAbsent(...)` / `map.forEach(...)`) is
|
|
// resolved as a string key lookup against the map, throwing a ClassCastException
|
|
// (String.compareTo vs DefaultArtifactVersion keys). That fired on every
|
|
// PlayerEvents.loggedIn and ServerEvents.loaded. NeoForge's EventBus aborts the
|
|
// whole listener chain when a handler throws, silently killing other mods' join
|
|
// handlers (e.g. Advanced Rocketry 3's onPlayerJoin dimension sync). Rewritten
|
|
// with plain JS structures; handlers are wrapped in try/catch so a script error
|
|
// can never abort the event chain again.
|
|
|
|
let $DefaultArtifactVersion = Java.loadClass("org.apache.maven.artifact.versioning.DefaultArtifactVersion")
|
|
let currentVersion = null
|
|
|
|
// List of { version, component } in insertion order
|
|
let announcements = []
|
|
|
|
// files related:
|
|
// kubejs/assets/atm/lang/en_us.json
|
|
|
|
// Add your announcements here
|
|
function initAnnouncements(){
|
|
addAnnouncement("4.0", "Added mods: Ars Creo, Ice and Fire, Oritech,")
|
|
addAnnouncement("4.1", "Added mods: Oritech Things")
|
|
addAnnouncement("4.2", "Removed mods: Oritech Things")
|
|
addAnnouncement("4.3", "Added mods: Ars Controle, Create Aquatic Ambitions, Create Hypertube, Mekanism More Machines")
|
|
addAnnouncement("4.5", "Added mods: Expanded Ae, Industrialization Overdrive and RFTools Storage")
|
|
addAnnouncement("4.6", "Added mods: Aether, BotanyPots, BotanyTrees and RefinedTypes")
|
|
addAnnouncement("4.6", "Removed mods: Harvest with ease, FTB Ultimine does that now")
|
|
addAnnouncement("4.7", "Added mods: Draconic Evolution and BotanyPots-Mystical")
|
|
addAnnouncement("4.12", "Added mods: ModularBees")
|
|
addAnnouncement("4.13", "Added mods: Dyson Cube Project")
|
|
addAnnouncement("5.0", "Removed mods: Modular Machinery Reborn, use Modern Industrialization")
|
|
addAnnouncement("5.3", Text.of("We are preparing to ").append(Text.red("REMOVE")).append(" mods ").append(Text.blue("Eternal Starlight")).append(" and ").append(Text.blue("Hyperbox")).append(", be ready when updating to version 6.0+"))
|
|
addAnnouncement("5.5", Text.of("We just launched ").append(Text.green("All The Mons (ATM10 + Cobblemon)").clickOpenUrl("https://www.curseforge.com/minecraft/modpacks/all-the-mons").hover(Text.translatable("mco.notification.visitUrl.buttonText.default"))).append(" for public beta testing!"))
|
|
}
|
|
|
|
ServerEvents.loaded(event => {
|
|
try {
|
|
if (!Platform.isLoaded("bcc")) return
|
|
announcements = []
|
|
let $BccInstance = Java.loadClass("dev.wuffs.bcc.BetterCompatibilityChecker")
|
|
currentVersion = new $DefaultArtifactVersion($BccInstance.betterStatus.version())
|
|
initAnnouncements()
|
|
} catch (e) {
|
|
console.error("announcements.ServerEvents.loaded failed: " + e)
|
|
}
|
|
})
|
|
|
|
function addAnnouncement(version, component) {
|
|
announcements.push({
|
|
version: new $DefaultArtifactVersion(version),
|
|
component: typeof component == "string" ? Text.of(component) : component
|
|
})
|
|
}
|
|
|
|
PlayerEvents.loggedIn(event => {
|
|
try {
|
|
if (currentVersion == null) return
|
|
let currentDismissed = event.player.persistentData.getString("LastDismissedAnnouncementVersion")
|
|
if (currentDismissed == null || currentDismissed.length == 0) {
|
|
currentDismissed = new $DefaultArtifactVersion("0.0.0")
|
|
} else {
|
|
currentDismissed = new $DefaultArtifactVersion(currentDismissed)
|
|
}
|
|
let ableToDismiss = false
|
|
let printHeader = true
|
|
for (let i = 0; i < announcements.length; i++) {
|
|
let key = announcements[i].version
|
|
let component = announcements[i].component
|
|
if (currentDismissed.compareTo(key) < 0 && currentVersion.compareTo(key) >= 0) {
|
|
ableToDismiss = true
|
|
if (printHeader) {
|
|
event.player.tell(Text.translatable("=====[ %s ]=====", Text.yellow("All The Mods Announcements").bold()).gold().bold())
|
|
printHeader = false
|
|
}
|
|
let message = Text.translatable("[%s] - %s", Text.gold(key.toString()), component.yellow()).yellow()
|
|
event.player.tell(message)
|
|
}
|
|
}
|
|
|
|
if (ableToDismiss) {
|
|
let message = Text.translatable("announcements.atm.dismiss_up_to_version", Text.blue(currentVersion.toString()))
|
|
.green()
|
|
.hover(Text.translatable("kubejs.atm.click_here"))
|
|
.clickRunCommand("/dismiss_announcements")
|
|
|
|
event.player.tell(message)
|
|
}
|
|
} catch (e) {
|
|
console.error("announcements.loggedIn failed: " + e)
|
|
}
|
|
})
|
|
|
|
ServerEvents.basicPublicCommand("dismiss_announcements", event => {
|
|
let player = event.player
|
|
if (player == null) {
|
|
event.cancel("Player was not found!")
|
|
} else {
|
|
let pData = player.getPersistentData()
|
|
if (event.input == "clear") {
|
|
pData.putString("LastDismissedAnnouncementVersion", "0.0.0")
|
|
event.respond(Text.yellow("Cleared dismissed version!"))
|
|
} else {
|
|
if (currentVersion == null) {
|
|
event.cancel("Current version of the modpack is null, is BetterCompatibilityCheck installed?")
|
|
} else {
|
|
pData.putString("LastDismissedAnnouncementVersion", currentVersion.toString())
|
|
event.respond(Text.translatable("announcements.atm.dismiss_up_to_version", currentVersion.toString()).yellow())
|
|
}
|
|
}
|
|
}
|
|
})
|