Skip to content

Commit

Permalink
tes
Browse files Browse the repository at this point in the history
  • Loading branch information
JaylyDev committed Jun 18, 2023
1 parent 790063c commit 251d5c3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
24 changes: 11 additions & 13 deletions scripts/cps-counter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,19 @@ interface ClickInfo {
const clicks = new Map<Player, ClickInfo[]>();

world.afterEvents.entityHitBlock.subscribe(function ({ damagingEntity }) {
if (damagingEntity instanceof Player) {
const clickInfo = { timestamp: Date.now() };
const playerClicks = clicks.get(damagingEntity) || [];
playerClicks.push(clickInfo);
clicks.set(damagingEntity, playerClicks);
}
if (!(damagingEntity instanceof Player)) return;
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) {
const clickInfo = { timestamp: Date.now() };
const playerClicks = clicks.get(damagingEntity) || [];
playerClicks.push(clickInfo);
clicks.set(damagingEntity, playerClicks);
}
if (!(damagingEntity instanceof Player)) return;
const clickInfo = { timestamp: Date.now() };
const playerClicks = clicks.get(damagingEntity) || [];
playerClicks.push(clickInfo);
clicks.set(damagingEntity, playerClicks);
});

/**
Expand All @@ -40,4 +38,4 @@ export function getPlayerCPS(player: Player) {
clicks.set(player, recentClicks);

return recentClicks.length;
}
};
19 changes: 15 additions & 4 deletions scripts/dimension-entities/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
// Script example for ScriptAPI
// Author: Jayly#1397 <Jayly Discord>
// Project: https://github.com/JaylyDev/ScriptAPI
import { Dimension, world } from "@minecraft/server";

/**
* Get entities that are in specific dimension
* @param {Dimension} dimension
* @param {import("@minecraft/server").EntityQueryOptions} [getEntities]
* @param {import("@minecraft/server").EntityQueryOptions} [options]
*/
export function getEntities(dimension, getEntities) {
return [...dimension.getEntities(getEntities)].filter((entity) => entity.dimension === dimension);
export function getEntities(dimension, options) {
const mergedOptions = {
minDistance: 0,
...(typeof options.minDistance !== 'undefined' ? { minDistance: options.minDistance } : {})
};
return dimension.getEntities(mergedOptions);
};

/**
Expand All @@ -15,5 +22,9 @@ export function getEntities(dimension, getEntities) {
* @param {import("@minecraft/server").EntityQueryOptions} [options]
*/
export function getPlayers(dimension, options) {
return [...world.getPlayers(options)].filter((player) => player.dimension === dimension);
const mergedOptions = {
minDistance: 0,
...(typeof options.minDistance !== 'undefined' ? { minDistance: options.minDistance } : {})
};
return dimension.getPlayers(mergedOptions);
};

0 comments on commit 251d5c3

Please sign in to comment.