From 36654776a7dd776876103c09b299cf440890bb75 Mon Sep 17 00:00:00 2001 From: codefactor-io Date: Sat, 25 Jun 2022 17:23:13 +0000 Subject: [PATCH] [CodeFactor] Apply fixes --- scripts/misc/dpwrapper.js | 102 +++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/scripts/misc/dpwrapper.js b/scripts/misc/dpwrapper.js index 6dbe19024..37949aaa4 100644 --- a/scripts/misc/dpwrapper.js +++ b/scripts/misc/dpwrapper.js @@ -6,8 +6,8 @@ import { crypto } from "../util.js"; if (config.dynamicPropertyWrapper.enabled) { // cancel registration - PropertyRegistry.prototype.registerEntityTypeDynamicProperties = () => {} - PropertyRegistry.prototype.registerWorldDynamicProperties = () => {} + PropertyRegistry.prototype.registerEntityTypeDynamicProperties = () => {}; + PropertyRegistry.prototype.registerWorldDynamicProperties = () => {}; // thing? const dpw = config.dynamicPropertyWrapper.uniqueID.slice(0, 6); @@ -18,109 +18,109 @@ if (config.dynamicPropertyWrapper.enabled) { uniqueID = String(crypto(dpw, pw)).slice(0, 6); } else { uniqueID = dpw; - }; + } const getPropertyDatas = (scoreObj) => { - const data = Object.create(null) + const data = Object.create(null); for (const [name] of scoreObj.getScores()) { // parse the saved value - const [match, id, type] = name.match(/(.*?)\|\|(string|number|boolean)\|\|/) ?? [] + const [match, id, type] = name.match(/(.*?)\|\|(string|number|boolean)\|\|/) ?? []; // skip if match is undefined (misformatted) - if (typeof match == 'undefined') continue + if (typeof match == 'undefined') continue; // parse value const valueStr = name.substring(match.length), value = type == 'number' ? +valueStr : type == 'boolean' ? valueStr == 'true' - : JSON.parse(`"${valueStr}"`) + : JSON.parse(`"${valueStr}"`); // add the value in property list data[JSON.parse(`"${id}"`)] = { cachedValue: value, scoreboardName: `${id}||${type}||${value}` - } + }; } - return data - } + return data; + }; // world dynamic property const worldObj = scoreboard.objective.for(`${uniqueID}:wld`).dummies; - const worldPropertyList = getPropertyDatas(worldObj) + const worldPropertyList = getPropertyDatas(worldObj); World.prototype.getDynamicProperty = (id) => { - return worldPropertyList[id]?.cachedValue - } + return worldPropertyList[id]?.cachedValue; + }; World.prototype.setDynamicProperty = (id, value) => { - const vtype = typeof value - if (vtype != 'string' && vtype != 'number' && vtype != 'boolean') throw new TypeError(`Unexpected value type ${vtype}`) + const vtype = typeof value; + if (vtype != 'string' && vtype != 'number' && vtype != 'boolean') throw new TypeError(`Unexpected value type ${vtype}`); // delete existing - const propData = worldPropertyList[id] ??= {} - if (propData.scoreboardName !== undefined) worldObj.delete(propData.scoreboardName) + const propData = worldPropertyList[id] ??= {}; + if (propData.scoreboardName !== undefined) worldObj.delete(propData.scoreboardName); // set - propData.cachedValue = value - worldObj.set(propData.scoreboardName = `${id}||${vtype}||${value}`, 0) - } + propData.cachedValue = value; + worldObj.set(propData.scoreboardName = `${id}||${vtype}||${value}`, 0); + }; World.prototype.removeDynamicProperty = (id) => { - if (!(id in worldPropertyList)) return false + if (!(id in worldPropertyList)) return false; // delete - worldObj.delete(worldPropertyList[id].scoreboardName) - delete worldPropertyList[id] + worldObj.delete(worldPropertyList[id].scoreboardName); + delete worldPropertyList[id]; - return true - } + return true; + }; // player dynamic property Player.prototype.getDynamicProperty = function(id) { - return getDataOfPlayer(this).data[id]?.cachedValue - } + return getDataOfPlayer(this).data[id]?.cachedValue; + }; Player.prototype.setDynamicProperty = function(id, value) { - const vtype = typeof value - if (vtype != 'string' && vtype != 'number' && vtype != 'boolean') throw new TypeError(`Unexpected value type ${vtype}`) + const vtype = typeof value; + if (vtype != 'string' && vtype != 'number' && vtype != 'boolean') throw new TypeError(`Unexpected value type ${vtype}`); - const {obj, data} = getDataOfPlayer(this) + const {obj, data} = getDataOfPlayer(this); // delete existing - const propData = data[id] ??= {} - if (propData.scoreboardName !== undefined) obj.delete(propData.scoreboardName) + const propData = data[id] ??= {}; + if (propData.scoreboardName !== undefined) obj.delete(propData.scoreboardName); // set - propData.cachedValue = value - obj.set(propData.scoreboardName = `${id}||${vtype}||${value}`, 0) - } + propData.cachedValue = value; + obj.set(propData.scoreboardName = `${id}||${vtype}||${value}`, 0); + }; Player.prototype.removeDynamicProperty = function (id) { - const {obj, data} = getDataOfPlayer(this) - if (!(id in data)) return false + const {obj, data} = getDataOfPlayer(this); + if (!(id in data)) return false; // delete - obj.delete(data[id].scoreboardName) - delete data[id] + obj.delete(data[id].scoreboardName); + delete data[id]; - return true - } + return true; + }; - SimulatedPlayer.prototype.getDynamicProperty = Player.prototype.getDynamicProperty - SimulatedPlayer.prototype.setDynamicProperty = Player.prototype.setDynamicProperty - SimulatedPlayer.prototype.removeDynamicProperty = Player.prototype.removeDynamicProperty + SimulatedPlayer.prototype.getDynamicProperty = Player.prototype.getDynamicProperty; + SimulatedPlayer.prototype.setDynamicProperty = Player.prototype.setDynamicProperty; + SimulatedPlayer.prototype.removeDynamicProperty = Player.prototype.removeDynamicProperty; // player data & uid registry const staticUidRegistry = scoreboard.objective.for(`${uniqueID}:uidreg`).players; - const dataList = new WeakMap() + const dataList = new WeakMap(); const getDataOfPlayer = (plr) => { // return if player data has already been set - if (dataList.has(plr)) return dataList.get(plr) + if (dataList.has(plr)) return dataList.get(plr); // set the player uid - staticUidRegistry.set(plr, 0) + staticUidRegistry.set(plr, 0); // sets the player obj & data - const obj = scoreboard.objective.for(`${uniqueID}:plr:${plr.scoreboard.id.toString(36)}`).dummies - dataList.set(plr, { obj: obj, data: getPropertyDatas(obj) }) + const obj = scoreboard.objective.for(`${uniqueID}:plr:${plr.scoreboard.id.toString(36)}`).dummies; + dataList.set(plr, { obj: obj, data: getPropertyDatas(obj) }); // return player obj & data - return dataList.get(plr) - } + return dataList.get(plr); + }; } \ No newline at end of file