From e49738bb3f0a29ab1031434bee71f46fcb0e77bf Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <65847850+JaylyDev@users.noreply.github.com> Date: Sun, 18 Jun 2023 14:49:53 +0100 Subject: [PATCH] f --- scripts/cps-counter/index.ts | 28 +++++++++++-------- .../Extensions/Actions/NightVision/Start.js | 5 ++-- scripts/editor-fullbright/index.ts | 6 ++-- scripts/get-effects/index.js | 7 ++--- scripts/get-scores/index.js | 2 +- 5 files changed, 26 insertions(+), 22 deletions(-) diff --git a/scripts/cps-counter/index.ts b/scripts/cps-counter/index.ts index 06617f5a..59a30bed 100644 --- a/scripts/cps-counter/index.ts +++ b/scripts/cps-counter/index.ts @@ -3,24 +3,28 @@ // Project: https://github.com/JaylyDev/ScriptAPI import { Player, world } from "@minecraft/server"; -declare module "@minecraft/server" { - interface ClickInfo { timestamp: number } - interface Player { - clicks?: ClickInfo[]; - } +interface ClickInfo { + readonly timestamp: number }; +// Using map because typescript doesn't support prototype property declaration properly +const clicks = new Map(); + world.afterEvents.entityHitBlock.subscribe(function ({ damagingEntity }) { if (damagingEntity instanceof Player) { - damagingEntity.clicks ||= []; - damagingEntity.clicks.push({ timestamp: Date.now() }); + const clickInfo = { timestamp: Date.now() }; + const playerClicks = clicks.get(damagingEntity) || []; + playerClicks.push(clickInfo); + clicks.set(damagingEntity, playerClicks); } }); world.afterEvents.entityHitEntity.subscribe(function ({ damagingEntity }) { if (damagingEntity instanceof Player) { - damagingEntity.clicks ||= []; - damagingEntity.clicks.push({ timestamp: Date.now() }); + const clickInfo = { timestamp: Date.now() }; + const playerClicks = clicks.get(damagingEntity) || []; + playerClicks.push(clickInfo); + clicks.set(damagingEntity, playerClicks); } }); @@ -31,9 +35,9 @@ world.afterEvents.entityHitEntity.subscribe(function ({ damagingEntity }) { */ export function getPlayerCPS(player: Player) { const currentTime = Date.now(); - player.clicks ||= []; - const recentClicks = player.clicks.filter(({ timestamp }) => currentTime - 1000 < timestamp); - player.clicks = recentClicks; + const playerClicks = clicks.get(player) || []; + const recentClicks = playerClicks.filter(({ timestamp }) => currentTime - 1000 < timestamp); + clicks.set(player, recentClicks); return recentClicks.length; } diff --git a/scripts/editor-extensions/Extensions/Actions/NightVision/Start.js b/scripts/editor-extensions/Extensions/Actions/NightVision/Start.js index b3d103a2..09c34a90 100644 --- a/scripts/editor-extensions/Extensions/Actions/NightVision/Start.js +++ b/scripts/editor-extensions/Extensions/Actions/NightVision/Start.js @@ -1,5 +1,6 @@ import * as Server from "@minecraft/server"; import * as Editor from "@minecraft/server-editor"; +import { MinecraftEffectTypes } from "@minecraft/vanilla-data"; /** * @param {import("@minecraft/server-editor").IPlayerUISession} uiSession */ @@ -13,7 +14,7 @@ export const Start = (uiSession) => { uiSession.actionManager.createAction( { actionType: Editor.ActionTypes.NoArgsAction, - onExecute: () => uiSession.extensionContext.player.addEffect( Server.MinecraftEffectTypes.nightVision, 20000000, { amplifier: 1, showParticles: false } ), + onExecute: () => uiSession.extensionContext.player.addEffect( MinecraftEffectTypes.NightVision, 20000000, { amplifier: 1, showParticles: false } ), }, ), ); @@ -23,7 +24,7 @@ export const Start = (uiSession) => { uiSession.actionManager.createAction( { actionType: Editor.ActionTypes.NoArgsAction, - onExecute: () => uiSession.extensionContext.player.removeEffect( Server.MinecraftEffectTypes.nightVision ), + onExecute: () => uiSession.extensionContext.player.removeEffect( MinecraftEffectTypes.NightVision ), }, ), ); diff --git a/scripts/editor-fullbright/index.ts b/scripts/editor-fullbright/index.ts index fe408986..4644c861 100644 --- a/scripts/editor-fullbright/index.ts +++ b/scripts/editor-fullbright/index.ts @@ -2,7 +2,7 @@ // Author: Jayly // Project: https://github.com/JaylyDev/ScriptAPI import { ActionTypes, EditorInputContext, IMenu, InputModifier, IPlayerUISession, KeyboardKey } from "@minecraft/server-editor"; -import { MinecraftEffectTypes } from "@minecraft/server"; +import { MinecraftEffectTypes } from "@minecraft/vanilla-data"; /** * Class to enable toggles for full bright in menu in editor mode @@ -14,13 +14,13 @@ export class FullbrightToggle { const enableAction = uiSession.actionManager.createAction({ actionType: ActionTypes.NoArgsAction, onExecute: () => { - player.addEffect(MinecraftEffectTypes.nightVision, 20000000, { amplifier: 1, showParticles: false }); + player.addEffect(MinecraftEffectTypes.NightVision, 20000000, { amplifier: 1, showParticles: false }); }, }); const disableAction = uiSession.actionManager.createAction({ actionType: ActionTypes.NoArgsAction, onExecute: () => { - player.runCommand("effect @s " + MinecraftEffectTypes.nightVision.getName() + " 0"); + player.removeEffect(MinecraftEffectTypes.NightVision); }, }); // Add actions to menu diff --git a/scripts/get-effects/index.js b/scripts/get-effects/index.js index b480d509..7d54b65a 100644 --- a/scripts/get-effects/index.js +++ b/scripts/get-effects/index.js @@ -3,13 +3,12 @@ // Project: https://github.com/JaylyDev/ScriptAPI import { - world, - MinecraftEffectTypes, /* Typings only */ Entity, Player, Effect, - EffectType + EffectType, + EffectTypes } from "@minecraft/server"; /** @@ -22,7 +21,7 @@ import { */ export function getEffects(entity) { const effectList = []; - for (const eff of Object.values(MinecraftEffectTypes)) { + for (const eff of EffectTypes.getAll()) { const effect = entity.getEffect(eff); if (!effect) continue; effectList.push({ diff --git a/scripts/get-scores/index.js b/scripts/get-scores/index.js index be1f296f..b5a0dbd6 100644 --- a/scripts/get-scores/index.js +++ b/scripts/get-scores/index.js @@ -11,7 +11,7 @@ export function getScores (target) { let targetScoreboard = {}; if (!(target.scoreboardIdentity instanceof ScoreboardIdentity)) return targetScoreboard; - for (const objective of objectives) targetScoreboard[objective.id] = objective.getScores().find((score) => score.participant.type !== ScoreboardIdentityType.fakePlayer ? score.participant.getEntity() === target : false)?.score; + for (const objective of objectives) targetScoreboard[objective.id] = objective.getScores().find((score) => score.participant.type !== ScoreboardIdentityType.FakePlayer ? score.participant.getEntity() === target : false)?.score; return targetScoreboard; };