Skip to content

Commit

Permalink
chore: move loading functions into internal
Browse files Browse the repository at this point in the history
  • Loading branch information
tutinoko2048 committed Sep 20, 2023
1 parent 9f29c79 commit 4c8fdbb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 35 deletions.
30 changes: 29 additions & 1 deletion scripts/ac.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import './system/dog.js';
import './system/register_properties.js';
import { world, system, Player, ScriptEventSource } from '@minecraft/server';
import { VERSION, PropertyIds } from './util/constants';
import config from './config.js';
Expand All @@ -8,6 +10,8 @@ import { AdminPanel } from './form/AdminPanel';
import { DataManager, deleteDupe } from './util/DataManager';
import { updateConfig } from './util/update_config';
import { BanManager } from './util/BanManager';
import { events } from './lib/events/index.js';
import { PermissionType, Permissions } from './util/Permissions';

const entityOption = { entityTypes: [ 'minecraft:player' ] };

Expand All @@ -30,9 +34,33 @@ export class TNAntiCheat {

/** @type {Map<string, import('@minecraft/server').Vector3>} */
this.frozenPlayerMap = new Map();

// load system
events.worldLoad.subscribe(() => {
if (world.getDynamicProperty(PropertyIds.ownerId)) {
try {
this.#enable();
} catch (e) { console.error(e, e.stack) }
} else {
world.sendMessage('[§l§aTN-AntiCheat§r] 初めに §6/function start§f を実行してください');
}
});
system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
if (!(sourceEntity instanceof Player) || id !== 'ac:start') return;
this.#register(sourceEntity);
}, { namespaces: [ 'ac' ] });
}

/** @param {Player} player */
#register(player) {
if (world.getDynamicProperty(PropertyIds.ownerId)) return player.sendMessage('TNAC is already registered!');
Permissions.add(player, PermissionType.Admin);
world.setDynamicProperty(PropertyIds.ownerId, player.id);
this.#enable();
player.sendMessage('§aAdmin権限が付与されました。"!help" でコマンド一覧を表示します');
}

enable() {
#enable() {
if (this.#isEnabled) throw new Error('TN-AntiCheat has already enabled');
this.#isEnabled = true;

Expand Down
35 changes: 1 addition & 34 deletions scripts/index.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,4 @@
import { world, system, Player } from '@minecraft/server';
import { TNAntiCheat } from './ac';
import { events } from './lib/events/index.js';
import { PropertyIds } from './util/constants';
import { PermissionType, Permissions } from './util/Permissions';
import './system/dog.js';
import './system/register_properties.js';

// eslint-disable-next-line no-unused-vars
const ac = new TNAntiCheat();
events.worldLoad.subscribe(() => {
if (world.getDynamicProperty(PropertyIds.ownerId)) {
try {
ac.enable();
} catch (e) { console.error(e, e.stack) }

} else {
world.sendMessage('[§l§aTN-AntiCheat§r] 初めに §6/function start§f を実行してください');
}
});

system.afterEvents.scriptEventReceive.subscribe(ev => {
const { id, sourceEntity } = ev;
if (!(sourceEntity instanceof Player) || id != 'ac:start') return;
start(sourceEntity);
}, {
namespaces: [ 'ac' ]
});

/** @param {Player} player */
function start(player) {
if (world.getDynamicProperty(PropertyIds.ownerId)) return player.sendMessage('TNAC is already registered!');
Permissions.add(player, PermissionType.Admin);
world.setDynamicProperty(PropertyIds.ownerId, player.id);

ac.enable();
player.sendMessage('§aAdmin権限が付与されました。"!help" でコマンド一覧を表示します');
}

0 comments on commit 4c8fdbb

Please sign in to comment.