diff --git a/Canopy [BP]/scripts/lib/canopy/Command.js b/Canopy [BP]/scripts/lib/canopy/Command.js index 66700a1..3c47cad 100644 --- a/Canopy [BP]/scripts/lib/canopy/Command.js +++ b/Canopy [BP]/scripts/lib/canopy/Command.js @@ -143,10 +143,10 @@ class Command { } world.beforeEvents.chatSend.subscribe((ev) => { - const { message, sender } = ev; + const { sender, message } = ev; let [name, ...args] = ArgumentParser.parseArgs(message); - if (!name.startsWith(Command.prefix)) + if (!String(name).startsWith(Command.prefix)) return; ev.cancel = true; if (!commands[name]) diff --git a/Canopy [BP]/scripts/lib/canopy/Rule.js b/Canopy [BP]/scripts/lib/canopy/Rule.js index 89c0959..baacf0b 100644 --- a/Canopy [BP]/scripts/lib/canopy/Rule.js +++ b/Canopy [BP]/scripts/lib/canopy/Rule.js @@ -90,6 +90,10 @@ class Rule { } } + getDependentRuleIDs() { + return Object.values(rules).filter(rule => rule.#contingentRules.includes(this.#identifier)).map(rule => rule.#identifier); + } + static exists(identifier) { return rules[identifier] !== undefined; } @@ -98,6 +102,10 @@ class Rule { return await Rule.getRule(identifier).getValue(); } + static getNativeValue(identifier) { + return Rule.getRule(identifier).parseString(world.getDynamicProperty(identifier)); + } + static setValue(identifier, value) { Rule.getRule(identifier).setValue(value); } diff --git a/Canopy [BP]/scripts/src/classes/ProbeManager.js b/Canopy [BP]/scripts/src/classes/ProbeManager.js index a24317b..bc5c769 100644 --- a/Canopy [BP]/scripts/src/classes/ProbeManager.js +++ b/Canopy [BP]/scripts/src/classes/ProbeManager.js @@ -116,7 +116,7 @@ class ProbeManager { removeProbe(player) { const probe = this.probeMap[player.id]; - if (!probe) return console.warn(`[Probe Manager] Error while removing: No probe found for player ${player?.name}`); + if (!probe) return; probe.detachFromPlayer(); if (probe.entity.isValid()) probe.entity.remove(); diff --git a/Canopy [BP]/scripts/src/commands/camera.js b/Canopy [BP]/scripts/src/commands/camera.js index 1aa860f..719793f 100644 --- a/Canopy [BP]/scripts/src/commands/camera.js +++ b/Canopy [BP]/scripts/src/commands/camera.js @@ -70,22 +70,22 @@ class BeforeSpectatorPlayer { } } -world.beforeEvents.playerGameModeChange.subscribe((ev) => { - const player = ev.player; - if (player.getDynamicProperty('isSpectating') && ev.fromGameMode === 'spectator' && ev.toGameMode !== 'spectator') { +world.beforeEvents.playerGameModeChange.subscribe((event) => { + const player = event.player; + if (player.getDynamicProperty('isSpectating') && event.fromGameMode === 'spectator' && event.toGameMode !== 'spectator') { system.run(() => { - player.setGameMode(ev.fromGameMode); + player.setGameMode(event.fromGameMode); player.onScreenDisplay.setActionBar('§cYou cannot change your gamemode while spectating.'); }); } }); -world.beforeEvents.playerLeave.subscribe((ev) => { - ev.player.setDynamicProperty('isViewingCamera', false); +world.beforeEvents.playerLeave.subscribe((event) => { + event.player.setDynamicProperty('isViewingCamera', false); }); -world.afterEvents.playerDimensionChange.subscribe((ev) => { - const player = ev.player; +world.afterEvents.playerDimensionChange.subscribe((event) => { + const player = event.player; if (!player.getDynamicProperty('isViewingCamera')) return; player.camera.clear(); player.setDynamicProperty('isViewingCamera', false); diff --git a/Canopy [BP]/scripts/src/commands/canopy.js b/Canopy [BP]/scripts/src/commands/canopy.js index f3522d5..16f6b7c 100644 --- a/Canopy [BP]/scripts/src/commands/canopy.js +++ b/Canopy [BP]/scripts/src/commands/canopy.js @@ -30,8 +30,11 @@ async function canopyCommand(sender, args) { if (ruleID === 'hopperCounters' && !enable) resetCounterMap(); - updateRules(sender, rule.getContigentRuleIDs(), enable); - updateRules(sender, rule.getIndependentRuleIDs(), !enable); + if (!enable) + await updateRules(sender, rule.getDependentRuleIDs(), enable); + else + await updateRules(sender, rule.getContigentRuleIDs(), enable); + await updateRules(sender, rule.getIndependentRuleIDs(), false); updateRule(sender, ruleID, ruleValue, enable); } @@ -42,9 +45,8 @@ function updateRule(sender, ruleID, ruleValue, enable) { sender.sendMessage(`§7${ruleID} is now ${enable ? '§l§aenabled' : '§l§cdisabled'}§r§7.`); } -function updateRules(sender, ruleIDs, enable) { +async function updateRules(sender, ruleIDs, enable) { for (const ruleID of ruleIDs) { - const rule = Rule.getRule(ruleID); - updateRule(sender, rule, enable); + updateRule(sender, ruleID, await Rule.getValue(ruleID), enable); } } diff --git a/Canopy [BP]/scripts/src/commands/info.js b/Canopy [BP]/scripts/src/commands/info.js index 7f643af..a5e08fb 100644 --- a/Canopy [BP]/scripts/src/commands/info.js +++ b/Canopy [BP]/scripts/src/commands/info.js @@ -43,7 +43,10 @@ function infoCommand(sender, args) { clearInfoDisplay(sender); const rule = InfoDisplayRule.getRule(ruleID); - updateRules(sender, rule.getContigentRuleIDs(), enable); + if (!enable) + updateRules(sender, rule.getDependentRuleIDs(), enable); + else + updateRules(sender, rule.getContigentRuleIDs(), enable); updateRules(sender, rule.getIndependentRuleIDs(), !enable); updateRule(sender, ruleID, InfoDisplayRule.getValue(sender, ruleID), enable); @@ -70,6 +73,6 @@ function updateRule(sender, ruleID, ruleValue, enable) { function updateRules(sender, ruleIDs, enable) { for (const ruleID of ruleIDs) { const rule = InfoDisplayRule.getRule(ruleID); - updateRule(sender, rule, enable); + updateRule(sender, ruleID, InfoDisplayRule.getValue(sender, ruleID), enable); } } diff --git a/Canopy [BP]/scripts/src/commands/jump.js b/Canopy [BP]/scripts/src/commands/jump.js index f91d615..a5c9aae 100644 --- a/Canopy [BP]/scripts/src/commands/jump.js +++ b/Canopy [BP]/scripts/src/commands/jump.js @@ -22,11 +22,11 @@ new Command({ helpHidden: true }) -function jumpCommand(sender) { +async function jumpCommand(sender) { let blockRayResult; let maxDistance = 64*16; let jumpLocation; - if (!Rule.getValue('commandJumpSurvival') && sender.getGameMode() === 'survival') + if (!await Rule.getValue('commandJumpSurvival') && sender.getGameMode() === 'survival') return sender.sendMessage('§cThe commandJumpSurvival feature is disabled.'); blockRayResult = Data.getLookingAtBlock(sender, maxDistance); diff --git a/Canopy [BP]/scripts/src/commands/scriptevents/counter.js b/Canopy [BP]/scripts/src/commands/scriptevents/counter.js index 6345ea0..9c6a240 100644 --- a/Canopy [BP]/scripts/src/commands/scriptevents/counter.js +++ b/Canopy [BP]/scripts/src/commands/scriptevents/counter.js @@ -3,9 +3,9 @@ import { Rule } from 'lib/canopy/Canopy'; import { channelMap, formatColor, query, queryAll } from 'src/commands/counter'; import Utils from 'stickycore/utils'; -system.afterEvents.scriptEventReceive.subscribe((event) => { +system.afterEvents.scriptEventReceive.subscribe(async (event) => { if (event.id !== 'canopy:counter') return; - if (!Rule.getValue('hopperCounters')) return Utils.broadcastActionBar('§cThe hopperCounters feature is disabled.'); + if (!await Rule.getValue('hopperCounters')) return Utils.broadcastActionBar('§cThe hopperCounters feature is disabled.'); const sourceName = Utils.getScriptEventSourceName(event); const message = event.message; diff --git a/Canopy [BP]/scripts/src/commands/spawn.js b/Canopy [BP]/scripts/src/commands/spawn.js index 7322118..7d896d9 100644 --- a/Canopy [BP]/scripts/src/commands/spawn.js +++ b/Canopy [BP]/scripts/src/commands/spawn.js @@ -42,11 +42,11 @@ let isMocking = false; let currMobIds = []; let currActiveArea = null; -world.afterEvents.entitySpawn.subscribe((event) => { +world.afterEvents.entitySpawn.subscribe(async (event) => { const entity = event.entity; if (worldSpawns && entity.typeId !== 'minecraft:item') worldSpawns.sendMobToTrackers(event.entity); - if (!isMocking || event.cause === 'Loaded' || !Rule.getValue('commandSpawnMocking')) return; + if (!isMocking || event.cause === 'Loaded' || !await Rule.getValue('commandSpawnMocking')) return; let shouldCancelSpawn = false; for (const category in categoryToMobMap) { if (categoryToMobMap[category].includes(event.entity.typeId.replace('minecraft:', ''))) shouldCancelSpawn = true; @@ -82,8 +82,8 @@ function printAllEntities(sender) { }); } -function handleMockingCmd(sender, enable) { - if (!Rule.getValue('commandSpawnMocking')) return sender.sendMessage('§cThe commandSpawnMocking rule is disabled.'); +async function handleMockingCmd(sender, enable) { + if (!await Rule.getValue('commandSpawnMocking')) return sender.sendMessage('§cThe commandSpawnMocking rule is disabled.'); if (enable === null) return sender.sendMessage('§cUsage: ./spawn mocking '); isMocking = enable; const messageColor = enable ? '§c' : '§a'; diff --git a/Canopy [BP]/scripts/src/commands/tick.js b/Canopy [BP]/scripts/src/commands/tick.js index d0aaa51..fb3ab50 100644 --- a/Canopy [BP]/scripts/src/commands/tick.js +++ b/Canopy [BP]/scripts/src/commands/tick.js @@ -30,8 +30,8 @@ let targetMSPT = 50.0; let shouldReset = false; let shouldStep = 0; -system.beforeEvents.watchdogTerminate.subscribe((event) => { - if (!Rule.getValue('commandTick')) return; +system.beforeEvents.watchdogTerminate.subscribe(async (event) => { + if (!await Rule.getValue('commandTick')) return; if (event.terminateReason === 'Hang' && targetMSPT > 50.0) { console.warn(`[Watchdog] Terminate hang ignored.`); event.cancel = true; diff --git a/Canopy [BP]/scripts/src/commands/tntfuse.js b/Canopy [BP]/scripts/src/commands/tntfuse.js index 8800358..2196040 100644 --- a/Canopy [BP]/scripts/src/commands/tntfuse.js +++ b/Canopy [BP]/scripts/src/commands/tntfuse.js @@ -20,11 +20,11 @@ const cmd = new Command({ contingentRules: ['commandTntFuse'] }); -world.afterEvents.entitySpawn.subscribe(event => { +world.afterEvents.entitySpawn.subscribe(async (event) => { if (event.entity.typeId !== 'minecraft:tnt') return; const fuseTimeProperty = world.getDynamicProperty('tntFuseTime'); let fuseTime = 80; - if (fuseTimeProperty !== undefined && Rule.getValue('commandTntFuse')) + if (fuseTimeProperty !== undefined && await Rule.getValue('commandTntFuse')) fuseTime = fuseTimeProperty; if (fuseTime === 80) { diff --git a/Canopy [BP]/scripts/src/commands/warp.js b/Canopy [BP]/scripts/src/commands/warp.js index 2c0cf6b..fa211d7 100644 --- a/Canopy [BP]/scripts/src/commands/warp.js +++ b/Canopy [BP]/scripts/src/commands/warp.js @@ -65,8 +65,8 @@ class Warps { } } -function warpActionCommand(sender, args) { - if (!Rule.getValue('commandWarpSurvival') && ['survival', 'adventure'].includes(sender.getGameMode())) +async function warpActionCommand(sender, args) { + if (!await Rule.getValue('commandWarpSurvival') && ['survival', 'adventure'].includes(sender.getGameMode())) return sender.sendMessage('§cThe commandWarpSurvival rule is disabled.'); let { action, name } = args; @@ -139,10 +139,8 @@ function setWarpMap(newWarpMap) { world.setDynamicProperty(`warps`, JSON.stringify(warps)); } -function warpListCommand(sender) { - if (!Rule.getValue('commandWarp')) - return sender.sendMessage('§cThe commandWarp rule is disabled.'); - else if (!Rule.getValue('commandWarpSurvival') && sender.getGameMode() === 'survival') +async function warpListCommand(sender) { + if (!await Rule.getValue('commandWarpSurvival') && sender.getGameMode() === 'survival') return sender.sendMessage('§cThe commandWarpSurvival rule is disabled.'); let warpMap = getWarpMapCopy(); diff --git a/Canopy [BP]/scripts/src/rules/InfoDisplay.js b/Canopy [BP]/scripts/src/rules/InfoDisplay.js index 006be01..c59f8e9 100644 --- a/Canopy [BP]/scripts/src/rules/InfoDisplay.js +++ b/Canopy [BP]/scripts/src/rules/InfoDisplay.js @@ -115,6 +115,7 @@ function InfoDisplay(player) { function parseCoordsAndFacing(player) { const showCoords = InfoDisplayRule.getValue(player, 'coords'); const showFacing = InfoDisplayRule.getValue(player, 'facing'); + if (!showCoords && !showFacing) return ''; let coords = player.location; let facing; let output = ''; @@ -131,6 +132,7 @@ function parseCoordsAndFacing(player) { function parseTPSAndEntities(player) { const showTPS = InfoDisplayRule.getValue(player, 'tps'); const showEntities = InfoDisplayRule.getValue(player, 'entities'); + if (!showTPS && !showEntities) return ''; let tpsData; let tps; let fovEntities; @@ -151,6 +153,7 @@ function parseTPSAndEntities(player) { function parseLightAndBiome(player) { const showLight = InfoDisplayRule.getValue(player, 'light'); const showBiome = InfoDisplayRule.getValue(player, 'biome'); + if (!showLight && !showBiome) return ''; let lightLevel; let biome; let output = ''; @@ -167,6 +170,7 @@ function parseLightAndBiome(player) { function parseDayAndTime(player) { const showDay = InfoDisplayRule.getValue(player, 'worldDay'); const showTimeOfDay = InfoDisplayRule.getValue(player, 'timeOfDay'); + if (!showDay && !showTimeOfDay) return ''; let day; let dayTime; let output = ''; @@ -196,13 +200,17 @@ function parseSessionTime(player) { function parseMoonPhaseAndSlimeChunk(player) { const showMoonPhase = InfoDisplayRule.getValue(player, 'moonPhase'); const showSlimeChunk = InfoDisplayRule.getValue(player, 'slimeChunk'); - const isSlime = player.dimension.id === "minecraft:overworld" && Data.isSlime(player.location.x, player.location.z); + if (!showMoonPhase && !showSlimeChunk) return ''; + let isSlime = false; let moonPhase; let slimeChunk; let output = ''; if (showMoonPhase) moonPhase = Data.getMoonPhase(); - if (showSlimeChunk) slimeChunk = isSlime ? '§7(§aSlime Chunk§7)§r' : ''; + if (showSlimeChunk) { + isSlime = player.dimension.id === "minecraft:overworld" && Data.isSlime(player.location.x, player.location.z); + slimeChunk = isSlime ? '§7(§aSlime Chunk§7)§r' : ''; + } if (showMoonPhase && showSlimeChunk) output += `§rMoon: §7${moonPhase}§r ${slimeChunk}\n`; else if (showMoonPhase) output += `§rMoon: §7${moonPhase}§r\n`; else if (showSlimeChunk && isSlime) output += `§r${slimeChunk}\n`; @@ -225,6 +233,7 @@ function parseHopperCounters(player) { function parseLookingAtAndPeek(player) { const showLookingAt = InfoDisplayRule.getValue(player, 'lookingAt'); const showPeekInventory = InfoDisplayRule.getValue(player, 'peekInventory'); + // if (!showLookingAt && !showPeekInventory) return ''; let blockRayResult; let entityRayResult; let lookingAtName; diff --git a/Canopy [BP]/scripts/src/rules/armorStandRespawning.js b/Canopy [BP]/scripts/src/rules/armorStandRespawning.js index a0332a9..7398506 100644 --- a/Canopy [BP]/scripts/src/rules/armorStandRespawning.js +++ b/Canopy [BP]/scripts/src/rules/armorStandRespawning.js @@ -7,8 +7,8 @@ new Rule({ description: 'Armor stands respawn when hit by a projectile, dropping their items.', }); -world.afterEvents.projectileHitEntity.subscribe((event) => { - if (!Rule.getValue('armorStandRespawning') || event.projectile.typeId === "minecraft:fishing_hook") return; +world.afterEvents.projectileHitEntity.subscribe(async (event) => { + if (!await Rule.getValue('armorStandRespawning') || event.projectile.typeId === "minecraft:fishing_hook") return; const entity = event.getEntityHit().entity; if (entity?.typeId === "minecraft:armor_stand") { const hasCleanedItem = cleanDroppedItem(event); diff --git a/Canopy [BP]/scripts/src/rules/autoItemPickup.js b/Canopy [BP]/scripts/src/rules/autoItemPickup.js index f22a4f0..1d1d800 100644 --- a/Canopy [BP]/scripts/src/rules/autoItemPickup.js +++ b/Canopy [BP]/scripts/src/rules/autoItemPickup.js @@ -14,15 +14,15 @@ system.runInterval(() => { brokenBlockEventsThisTick = []; }); -world.afterEvents.playerBreakBlock.subscribe(blockEvent => { - if (!Rule.getValue('autoItemPickup')) return; +world.afterEvents.playerBreakBlock.subscribe(async (blockEvent) => { + if (!await Rule.getValue('autoItemPickup')) return; if (blockEvent.player.getGameMode() === 'creative') return; brokenBlockEventsThisTick.push(blockEvent); }); -world.afterEvents.entitySpawn.subscribe(entityEvent => { +world.afterEvents.entitySpawn.subscribe(async (entityEvent) => { if (entityEvent.cause !== 'Spawned' || entityEvent.entity.typeId !== 'minecraft:item') return; - if (!Rule.getValue('autoItemPickup')) return; + if (!await Rule.getValue('autoItemPickup')) return; const item = entityEvent.entity; let brokenBlockEvent; diff --git a/Canopy [BP]/scripts/src/rules/dupeTnt.js b/Canopy [BP]/scripts/src/rules/dupeTnt.js index 872bec1..07bf8e8 100644 --- a/Canopy [BP]/scripts/src/rules/dupeTnt.js +++ b/Canopy [BP]/scripts/src/rules/dupeTnt.js @@ -16,13 +16,13 @@ system.runInterval(() => { }, 1); world.afterEvents.entitySpawn.subscribe((event) => { - if (event.entity.typeId !== 'minecraft:tnt' || !Rule.getValue('dupeTnt')) return; + if (event.entity.typeId !== 'minecraft:tnt' || !Rule.getNativeValue('dupeTnt')) return; const entity = event.entity; spawnedEntitiesThisTick.push(entity); }); world.afterEvents.pistonActivate.subscribe((event) => { - if (!Rule.getValue('dupeTnt')) return; + if (!Rule.getNativeValue('dupeTnt')) return; const block = event.block; const direction = block.permutation.getState('facing_direction'); let pistonState; diff --git a/Canopy [BP]/scripts/src/rules/entityInstantDeath.js b/Canopy [BP]/scripts/src/rules/entityInstantDeath.js index e7eaf57..4ca7212 100644 --- a/Canopy [BP]/scripts/src/rules/entityInstantDeath.js +++ b/Canopy [BP]/scripts/src/rules/entityInstantDeath.js @@ -8,7 +8,7 @@ new Rule({ }); world.afterEvents.entityDie.subscribe(async (event) => { - if (!await Rule.getValue('entityInstantDeath')) return; + if (!await Rule.getNativeValue('entityInstantDeath')) return; try { event.deadEntity.remove(); } catch {} // already dead diff --git a/Canopy [BP]/scripts/src/rules/explosionChainReactionOnly.js b/Canopy [BP]/scripts/src/rules/explosionChainReactionOnly.js index 379f79a..ac37f72 100644 --- a/Canopy [BP]/scripts/src/rules/explosionChainReactionOnly.js +++ b/Canopy [BP]/scripts/src/rules/explosionChainReactionOnly.js @@ -5,11 +5,11 @@ new Rule({ category: 'Rules', identifier: 'explosionChainReactionOnly', description: 'Makes explosion only affect TNT blocks.', - independentRules: ['explosionNoBlockDamage'] + independentRules: ['explosionNoBlockDamage', 'explosionOff'] }); world.beforeEvents.explosion.subscribe((event) => { - if (!Rule.getValue('explosionChainReactionOnly')) return; + if (!Rule.getNativeValue('explosionChainReactionOnly')) return; const explodedTntBlocks = event.getImpactedBlocks().filter(block => block.typeId === 'minecraft:tnt'); event.setImpactedBlocks(explodedTntBlocks); }); \ No newline at end of file diff --git a/Canopy [BP]/scripts/src/rules/explosionNoBlockDamage.js b/Canopy [BP]/scripts/src/rules/explosionNoBlockDamage.js index 3ad705d..a0a8027 100644 --- a/Canopy [BP]/scripts/src/rules/explosionNoBlockDamage.js +++ b/Canopy [BP]/scripts/src/rules/explosionNoBlockDamage.js @@ -5,10 +5,10 @@ new Rule({ category: 'Rules', identifier: 'explosionNoBlockDamage', description: 'Makes explosions not affect blocks.', - independantRules: ['explosionChainReactionOnly'] + independentRules: ['explosionChainReactionOnly', 'explosionOff'] }); -world.beforeEvents.explosion.subscribe(ev => { - if (!Rule.getValue('explosionNoBlockDamage')) return; - ev.setImpactedBlocks([]); +world.beforeEvents.explosion.subscribe((event) => { + if (!Rule.getNativeValue('explosionNoBlockDamage')) return; + event.setImpactedBlocks([]); }); \ No newline at end of file diff --git a/Canopy [BP]/scripts/src/rules/explosionOff.js b/Canopy [BP]/scripts/src/rules/explosionOff.js index 8530c8a..1bdfbb7 100644 --- a/Canopy [BP]/scripts/src/rules/explosionOff.js +++ b/Canopy [BP]/scripts/src/rules/explosionOff.js @@ -5,9 +5,10 @@ new Rule({ category: 'Rules', identifier: 'explosionOff', description: 'Disables explosions entirely.', + independentRules: ['explosionChainReactionOnly', 'explosionNoBlockDamage'] }); world.beforeEvents.explosion.subscribe((event) => { - if (!Rule.getValue('explosionOff')) return; + if (!Rule.getNativeValue('explosionOff')) return; event.cancel = true; }); \ No newline at end of file diff --git a/Canopy [BP]/scripts/src/rules/flippinArrows.js b/Canopy [BP]/scripts/src/rules/flippinArrows.js index aea1065..ed797d4 100644 --- a/Canopy [BP]/scripts/src/rules/flippinArrows.js +++ b/Canopy [BP]/scripts/src/rules/flippinArrows.js @@ -26,8 +26,8 @@ system.runInterval(() => { } }); -world.beforeEvents.playerPlaceBlock.subscribe(event => { - if (!Rule.getValue('flippinArrows')) return; +world.beforeEvents.playerPlaceBlock.subscribe(async (event) => { + if (!await Rule.getValue('flippinArrows')) return; const player = event.player; const offhandStack = player.getComponent('equippable').getEquipment("Offhand"); if (offhandStack?.typeId !== 'minecraft:arrow') return; @@ -40,8 +40,8 @@ world.beforeEvents.playerPlaceBlock.subscribe(event => { } }); -world.beforeEvents.itemUseOn.subscribe(event => { - if (!Rule.getValue('flippinArrows')) return; +world.beforeEvents.itemUseOn.subscribe(async (event) => { + if (!await Rule.getValue('flippinArrows')) return; if (event.itemStack.typeId !== 'minecraft:arrow') return; const block = event.block; if (needsCooldown(block)) return; diff --git a/Canopy [BP]/scripts/src/rules/hotbarSwitching.js b/Canopy [BP]/scripts/src/rules/hotbarSwitching.js index eba685e..0dfca16 100644 --- a/Canopy [BP]/scripts/src/rules/hotbarSwitching.js +++ b/Canopy [BP]/scripts/src/rules/hotbarSwitching.js @@ -20,26 +20,26 @@ const lastSelectedSlots = {}; const lastLoadedSlots = {}; const hotbarManagers = {}; -system.runInterval(() => { - if (!Rule.getValue('hotbarSwitching')) return; +system.runInterval(async () => { + if (!await Rule.getValue('hotbarSwitching')) return; const players = world.getAllPlayers(); for (const player of players) { - if (!hasAppropriateGameMode(player)) continue; + if (!await hasAppropriateGameMode(player)) continue; if (hotbarManagers[player.id] === undefined) hotbarManagers[player.id] = new HotbarManager(player); processHotbarSwitching(player); } }); -function hasAppropriateGameMode(player) { - return Rule.getValue('hotbarSwitchingSurvival') || player.getGameMode() === 'creative'; +async function hasAppropriateGameMode(player) { + return await Rule.getValue('hotbarSwitchingSurvival') || player.getGameMode() === 'creative'; } -function processHotbarSwitching(player) { - if (lastSelectedSlots[player.id] !== undefined && (!hasArrowInCorrectSlot(player) || !isInAppropriateGameMode(player))) { +async function processHotbarSwitching(player) { + if (lastSelectedSlots[player.id] !== undefined && (!hasArrowInCorrectSlot(player) || !await hasAppropriateGameMode(player))) { delete lastSelectedSlots[player.id]; return; - } else if (lastSelectedSlots[player.id] === undefined && (!hasArrowInCorrectSlot(player) || !isInAppropriateGameMode(player))) { + } else if (lastSelectedSlots[player.id] === undefined && (!hasArrowInCorrectSlot(player) || !await hasAppropriateGameMode(player))) { return; } if (hasScrolled(player) && player.isSneaking) { @@ -63,10 +63,6 @@ function hasArrowInCorrectSlot(player) { return container?.getItem(ARROW_SLOT)?.typeId === 'minecraft:arrow'; } -function isInAppropriateGameMode(player) { - return world.getDynamicProperty('hotbarSwitchingInSurvival') || player.getGameMode() === 'creative'; -} - function hasScrolled(player) { return player.selectedSlotIndex !== lastSelectedSlots[player.id]; } diff --git a/Canopy [BP]/scripts/src/rules/instantTame.js b/Canopy [BP]/scripts/src/rules/instantTame.js index ae45176..b09ee6e 100644 --- a/Canopy [BP]/scripts/src/rules/instantTame.js +++ b/Canopy [BP]/scripts/src/rules/instantTame.js @@ -14,12 +14,11 @@ new Rule({ contingentRules: ['instantTame'], }); -world.beforeEvents.playerInteractWithEntity.subscribe(event => { - if (!Rule.getValue('instantTame')) return; - if (!Rule.getValue('instantTameSurvival') && event.player.getGameMode() === 'survival') return; +world.beforeEvents.playerInteractWithEntity.subscribe(async (event) => { + if (!await Rule.getValue('instantTame')) return; + if (!await Rule.getValue('instantTameSurvival') && event.player.getGameMode() === 'survival') return; const tameable = event.target.getComponent('tameable'); if (tameable && isUsingTameItem(tameable.getTameItems, event.itemStack)) { - console.warn('taming', event.target.typeId) system.run(() => { try { tameable.tame(event.player); diff --git a/Canopy [BP]/scripts/src/rules/noTileDrops.js b/Canopy [BP]/scripts/src/rules/noTileDrops.js index a2a9403..16a1b64 100644 --- a/Canopy [BP]/scripts/src/rules/noTileDrops.js +++ b/Canopy [BP]/scripts/src/rules/noTileDrops.js @@ -16,16 +16,16 @@ system.runInterval(() => { brokenBlockEventsThisTick = []; }); -world.afterEvents.playerBreakBlock.subscribe(blockEvent => { +world.afterEvents.playerBreakBlock.subscribe(async (blockEvent) => { if (blockEvent.player.getGameMode() !== 'creative' - || !Rule.getValue('noTileDrops')) + || !await Rule.getValue('noTileDrops')) return; brokenBlockEventsThisTick.push(blockEvent); }); -world.afterEvents.entitySpawn.subscribe(entityEvent => { +world.afterEvents.entitySpawn.subscribe(async (entityEvent) => { if (entityEvent.cause !== 'Spawned' || entityEvent.entity.typeId !== 'minecraft:item') return; - if (!Rule.getValue('noTileDrops')) return; + if (!await Rule.getValue('noTileDrops')) return; const item = entityEvent.entity; const brokenBlockEvents = brokenBlockEventsThisTick.concat(brokenBlockEventsLastTick); diff --git a/Canopy [BP]/scripts/src/rules/pistonBedrockBreaking.js b/Canopy [BP]/scripts/src/rules/pistonBedrockBreaking.js index c67b1d4..1a58c74 100644 --- a/Canopy [BP]/scripts/src/rules/pistonBedrockBreaking.js +++ b/Canopy [BP]/scripts/src/rules/pistonBedrockBreaking.js @@ -10,8 +10,8 @@ new Rule({ const insideBedrockPistonList = []; -world.afterEvents.pistonActivate.subscribe(event => { - if (!Rule.getValue('pistonBedrockBreaking') || !['expanding', 'retracting'].includes(event.piston.state)) return; +world.afterEvents.pistonActivate.subscribe(async (event) => { + if (!await Rule.getNativeValue('pistonBedrockBreaking') || !['Expanding', 'Retracting'].includes(event.piston.state)) return; const piston = event.piston; const block = event.block; let directionState = DirectionStateFinder.getDirectionState(block.permutation); diff --git a/Canopy [BP]/scripts/src/rules/renewableElytra.js b/Canopy [BP]/scripts/src/rules/renewableElytra.js index b6f396e..f37f593 100644 --- a/Canopy [BP]/scripts/src/rules/renewableElytra.js +++ b/Canopy [BP]/scripts/src/rules/renewableElytra.js @@ -7,8 +7,8 @@ new Rule({ description: 'Phantoms have a 1%% chance to drop an elytra when killed by a shulker bullet.', }); -world.afterEvents.entityDie.subscribe((event) => { - if (!Rule.getValue('renewableElytra')) return; +world.afterEvents.entityDie.subscribe(async (event) => { + if (!await Rule.getValue('renewableElytra')) return; const entity = event.deadEntity; if (entity?.typeId === 'minecraft:phantom' && event.damageSource.damagingProjectile?.typeId === 'minecraft:shulker_bullet') { if (Math.random() > 0.01) return; diff --git a/Canopy [BP]/scripts/src/rules/renewableSponge.js b/Canopy [BP]/scripts/src/rules/renewableSponge.js index ba35b2a..e436de5 100644 --- a/Canopy [BP]/scripts/src/rules/renewableSponge.js +++ b/Canopy [BP]/scripts/src/rules/renewableSponge.js @@ -7,8 +7,8 @@ new Rule({ description: 'Guardians transform into elder guardians when hurt by lightning.', }); -world.afterEvents.entityHurt.subscribe(event => { - if (event.hurtEntity.typeId !== 'minecraft:guardian' || !Rule.getValue('renewableSponge') || event.damageSource.cause !== 'lightning') +world.afterEvents.entityHurt.subscribe(async (event) => { + if (event.hurtEntity.typeId !== 'minecraft:guardian' || !await Rule.getValue('renewableSponge') || event.damageSource.cause !== 'lightning') return; const guardian = event.hurtEntity; diff --git a/Canopy [BP]/scripts/src/rules/tntPrimeMaxMomentum.js b/Canopy [BP]/scripts/src/rules/tntPrimeMaxMomentum.js index 64c9393..c8e112a 100644 --- a/Canopy [BP]/scripts/src/rules/tntPrimeMaxMomentum.js +++ b/Canopy [BP]/scripts/src/rules/tntPrimeMaxMomentum.js @@ -10,10 +10,10 @@ new Rule({ const MAX_VELOCITY = 0.019600000232548116; // From vanilla TNT: 49/2500 with some floating point error -world.afterEvents.entitySpawn.subscribe((event) => { - if (event.entity.typeId !== 'minecraft:tnt' || !Rule.getValue('tntPrimeMaxMomentum')) return; +world.afterEvents.entitySpawn.subscribe(async (event) => { + if (event.entity.typeId !== 'minecraft:tnt' || !await Rule.getValue('tntPrimeMaxMomentum')) return; const entity = event.entity; - if (Rule.getValue('dupeTnt')) { + if (await Rule.getValue('dupeTnt')) { system.runTimeout(() => { correctErrorAndNegateXZVelocity(entity); applyHardcodedImpulse(entity); diff --git a/Canopy [BP]/scripts/src/rules/tntPrimeNoMomentum.js b/Canopy [BP]/scripts/src/rules/tntPrimeNoMomentum.js index 9d6d96b..fa52fa0 100644 --- a/Canopy [BP]/scripts/src/rules/tntPrimeNoMomentum.js +++ b/Canopy [BP]/scripts/src/rules/tntPrimeNoMomentum.js @@ -9,10 +9,10 @@ new Rule({ independentRules: ['tntPrimeMaxMomentum'], }); -world.afterEvents.entitySpawn.subscribe((event) => { - if (event.entity.typeId !== 'minecraft:tnt' || !Rule.getValue('tntPrimeNoMomentum')) return; +world.afterEvents.entitySpawn.subscribe(async (event) => { + if (event.entity.typeId !== 'minecraft:tnt' || !await Rule.getValue('tntPrimeNoMomentum')) return; const entity = event.entity; - if (Rule.getValue('dupeTnt')) { + if (await Rule.getValue('dupeTnt')) { system.runTimeout(() => { correctErrorAndNegateXZVelocity(entity); }, 1); diff --git a/Canopy [BP]/scripts/src/rules/universalChunkLoading.js b/Canopy [BP]/scripts/src/rules/universalChunkLoading.js index 66c7b99..cf5b55c 100644 --- a/Canopy [BP]/scripts/src/rules/universalChunkLoading.js +++ b/Canopy [BP]/scripts/src/rules/universalChunkLoading.js @@ -7,7 +7,7 @@ new Rule({ description: 'Makes minecarts tick a 5x5 chunk area around them for 10 seconds after they are spawned.' }); -world.afterEvents.entitySpawn.subscribe((event) => { - if (event.entity.typeId !== 'minecraft:minecart' || !Rule.getValue('universalChunkLoading')) return; +world.afterEvents.entitySpawn.subscribe(async (event) => { + if (event.entity.typeId !== 'minecraft:minecart' || !await Rule.getValue('universalChunkLoading')) return; event.entity.triggerEvent('canopy:tick_tenSeconds'); });