-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Content Update * remove internal .d.ts file * add header * Update README.md * Update index.ts * Update README.md
- Loading branch information
Showing
23 changed files
with
945 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,74 @@ | ||
// Script example for ScriptAPI | ||
// Author: JaylyMC <https://github.com/JaylyDev> | ||
// Project: https://github.com/JaylyDev/ScriptAPI | ||
|
||
import { Enchantment, Entity, EntityInventoryComponent, ItemEnchantsComponent, ItemStack, system, TicksPerSecond, world } from '@minecraft/server'; | ||
const tickInterval = TicksPerSecond; | ||
import { EntityInventoryComponent, ItemEnchantableComponent, system, TicksPerSecond, world } from '@minecraft/server'; | ||
/** | ||
* Represents an event indicating incompatible enchantments on an item. | ||
*/ | ||
class IncompatibleEnchantmentAlertEvent { | ||
/** | ||
* Creates a new instance of IncompatibleEnchantmentAlertEvent. | ||
* @param {boolean} exceedMaxLevel - Indicates whether the enchantment exceeds its maximum level. | ||
* @param {boolean} incompatibleEnchantmentType - Indicates whether the enchantment type is incompatible. | ||
* @param {Enchantment} enchantment - The enchantment causing the alert. | ||
* @param {ItemStack} item - The item with the incompatible enchantment. | ||
* @param {Entity} source - The entity triggering the alert. | ||
*/ | ||
constructor(exceedMaxLevel, incompatibleEnchantmentType, enchantment, item, source) { | ||
/** | ||
* @type {boolean} | ||
*/ | ||
this.exceedMaxLevel = exceedMaxLevel; | ||
/** | ||
* @type {boolean} | ||
*/ | ||
this.incompatibleEnchantmentType = incompatibleEnchantmentType; | ||
/** | ||
* @type {Enchantment} | ||
*/ | ||
this.enchantment = enchantment; | ||
/** | ||
* @type {ItemStack} | ||
*/ | ||
this.item = item; | ||
/** | ||
* @type {Entity} | ||
*/ | ||
this.source = source; | ||
} | ||
; | ||
} | ||
; | ||
/** | ||
* Signal class for subscribing to events related to incompatible enchantments. | ||
*/ | ||
class IncompatibleEnchantmentAlertEventSignal { | ||
/** | ||
* @param {(arg0: IncompatibleEnchantmentAlertEvent) => void} callback | ||
*/ | ||
* Subscribes to the incompatible enchantment alert event and specifies a callback function. | ||
* @param {(arg0: IncompatibleEnchantmentAlertEvent) => void} callback - The callback function to be invoked when an alert occurs. | ||
* Accepts a single parameter of type IncompatibleEnchantmentAlertEvent. | ||
* @returns {number} - An identifier for the subscription, which can be used for unsubscribing. | ||
*/ | ||
subscribe(callback) { | ||
return system.runInterval(function () { | ||
for (const player of world.getAllPlayers()) { | ||
/** | ||
* @type {EntityInventoryComponent} | ||
*/ | ||
// @ts-ignore | ||
const inventory = player.getComponent(EntityInventoryComponent.componentId); | ||
for (let index = 0; index < inventory.container.size; index++) { | ||
const item = inventory.container.getItem(index); | ||
/** @type {ItemEnchantsComponent} */ | ||
// @ts-ignore | ||
const enchantments = item === null || item === void 0 ? void 0 : item.getComponent(ItemEnchantsComponent.componentId); | ||
if (!item || !enchantments) | ||
if (!item) | ||
continue; | ||
for (const enchantment of enchantments.enchantments) { | ||
const enchantmentIsIncompatible = enchantments.enchantments.canAddEnchantment(new Enchantment(enchantment.type)) === false; | ||
const enchantable = item.getComponent(ItemEnchantableComponent.componentId); | ||
for (const enchantment of enchantable.getEnchantments()) { | ||
const enchantmentIsIncompatible = enchantable.canAddEnchantment(enchantment) === false; | ||
if (typeof enchantment.type !== 'object') | ||
continue; | ||
const enchantmentExcceedsMaxLevel = enchantment.level > enchantment.type.maxLevel; | ||
if (!enchantmentIsIncompatible && !enchantmentExcceedsMaxLevel) | ||
continue; | ||
callback(new IncompatibleEnchantmentAlertEvent(enchantmentExcceedsMaxLevel, enchantmentIsIncompatible, enchantment, item, player)); | ||
} | ||
} | ||
} | ||
}, tickInterval); | ||
}, TicksPerSecond); | ||
} | ||
; | ||
/** | ||
* Unsubscribes from the incompatible enchantment alert event using the provided subscription identifier. | ||
* @param {number} id - The identifier of the subscription to be removed. | ||
*/ | ||
unsubscribe(id) { | ||
system.clearRun(id); | ||
} | ||
; | ||
} | ||
; | ||
/** | ||
* Global instance of IncompatibleEnchantmentAlertEventSignal for easy access and usage. | ||
* @type {IncompatibleEnchantmentAlertEventSignal} | ||
*/ | ||
export const incompatibleEnchantment = new IncompatibleEnchantmentAlertEventSignal(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Script example for ScriptAPI | ||
// Author: JaylyMC <https://github.com/JaylyDev> | ||
// Project: https://github.com/JaylyDev/ScriptAPI | ||
|
||
import { Enchantment, Entity, EntityInventoryComponent, ItemEnchantableComponent, ItemStack, system, TicksPerSecond, world } from '@minecraft/server'; | ||
|
||
/** | ||
* Represents an event indicating incompatible enchantments on an item. | ||
*/ | ||
class IncompatibleEnchantmentAlertEvent { | ||
exceedMaxLevel: boolean; | ||
incompatibleEnchantmentType: boolean; | ||
enchantment: Enchantment; | ||
item: ItemStack; | ||
source: Entity; | ||
/** | ||
* Creates a new instance of IncompatibleEnchantmentAlertEvent. | ||
* @param {boolean} exceedMaxLevel - Indicates whether the enchantment exceeds its maximum level. | ||
* @param {boolean} incompatibleEnchantmentType - Indicates whether the enchantment type is incompatible. | ||
* @param {Enchantment} enchantment - The enchantment causing the alert. | ||
* @param {ItemStack} item - The item with the incompatible enchantment. | ||
* @param {Entity} source - The entity triggering the alert. | ||
*/ | ||
constructor(exceedMaxLevel: boolean, incompatibleEnchantmentType: boolean, enchantment: Enchantment, item: ItemStack, source: Entity) { | ||
this.exceedMaxLevel = exceedMaxLevel; | ||
this.incompatibleEnchantmentType = incompatibleEnchantmentType; | ||
this.enchantment = enchantment; | ||
this.item = item; | ||
this.source = source; | ||
}; | ||
}; | ||
|
||
/** | ||
* Signal class for subscribing to events related to incompatible enchantments. | ||
*/ | ||
class IncompatibleEnchantmentAlertEventSignal { | ||
/** | ||
* Subscribes to the incompatible enchantment alert event and specifies a callback function. | ||
* @param {(arg0: IncompatibleEnchantmentAlertEvent) => void} callback - The callback function to be invoked when an alert occurs. | ||
* Accepts a single parameter of type IncompatibleEnchantmentAlertEvent. | ||
* @returns {number} - An identifier for the subscription, which can be used for unsubscribing. | ||
*/ | ||
subscribe(callback: (arg0: IncompatibleEnchantmentAlertEvent) => void): number { | ||
return system.runInterval(function () { | ||
for (const player of world.getAllPlayers()) { | ||
const inventory = player.getComponent(EntityInventoryComponent.componentId); | ||
for (let index = 0; index < inventory.container.size; index++) { | ||
const item = inventory.container.getItem(index); | ||
if (!item) continue; | ||
|
||
const enchantable = item.getComponent(ItemEnchantableComponent.componentId); | ||
|
||
for (const enchantment of enchantable.getEnchantments()) { | ||
const enchantmentIsIncompatible = enchantable.canAddEnchantment(enchantment) === false; | ||
if (typeof enchantment.type !== 'object') continue; | ||
const enchantmentExcceedsMaxLevel = enchantment.level > enchantment.type.maxLevel; | ||
if (!enchantmentIsIncompatible && !enchantmentExcceedsMaxLevel) | ||
continue; | ||
callback(new IncompatibleEnchantmentAlertEvent(enchantmentExcceedsMaxLevel, enchantmentIsIncompatible, enchantment, item, player)); | ||
} | ||
} | ||
} | ||
}, TicksPerSecond); | ||
}; | ||
|
||
/** | ||
* Unsubscribes from the incompatible enchantment alert event using the provided subscription identifier. | ||
* @param {number} id - The identifier of the subscription to be removed. | ||
*/ | ||
unsubscribe(id: number) { | ||
system.clearRun(id); | ||
}; | ||
}; | ||
|
||
/** | ||
* Global instance of IncompatibleEnchantmentAlertEventSignal for easy access and usage. | ||
* @type {IncompatibleEnchantmentAlertEventSignal} | ||
*/ | ||
export const incompatibleEnchantment: IncompatibleEnchantmentAlertEventSignal = new IncompatibleEnchantmentAlertEventSignal(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Script example for ScriptAPI | ||
// Author: Smell of curry <https://github.com/smell-of-curry> | ||
// JaylyMC <https://github.com/JaylyDev> | ||
// Remember M9 <https://github.com/Remember-M9> | ||
// Project: https://github.com/JaylyDev/ScriptAPI | ||
|
||
/** | ||
* Minecraft Bedrock Anti Hacked Items | ||
* @license MIT | ||
* @author Smell of curry & JaylyMC | ||
* @version 1.1.0 | ||
* -------------------------------------------------------------------------- | ||
* This is a anti hacked items, meaning it checks a players inventory every | ||
* tick then it tests if they have any banned items, then checks if they have | ||
* items that have hacked enchants and clears the item from inventory | ||
* -------------------------------------------------------------------------- | ||
*/ | ||
import * as mc from "@minecraft/server"; | ||
|
||
const { world, system } = mc; | ||
|
||
function onTick() { | ||
for (const player of world.getPlayers()) { | ||
/** @type {mc.EntityInventoryComponent} */ | ||
// @ts-ignore | ||
const inventory = player.getComponent("minecraft:inventory"); | ||
const { container, inventorySize } = inventory; | ||
if (container.emptySlotsCount == inventorySize) continue; | ||
for (let slot = 0; slot < inventorySize; slot++) { | ||
const item = container.getItem(slot); | ||
if (!item) continue; | ||
const enchantable = item.getComponent("minecraft:enchantable"); | ||
if (!enchantable) continue; | ||
for (const enchantment of enchantable.getEnchantments()) { | ||
if (enchantable.canAddEnchantment(enchantment)) continue; | ||
enchantable.removeEnchantment(enchantment.type); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
|
||
system.runInterval(onTick); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
import { world } from "@minecraft/server"; | ||
|
||
world.beforeEvents.chatSend.subscribe((data) => { | ||
data.sendToTargets = true | ||
data.setTargets([]) | ||
}) | ||
|
||
world.afterEvents.chatSend.subscribe((data) => { | ||
try { | ||
data.sender.runCommandAsync(`tellraw @a ${JSON.stringify({rawtext:[{text: "§l§8[§r" + ((data.sender.getTags().find(tag => tag.startsWith("rank:"))?.substring(5)?.replaceAll("--", "§r§l§8][§r")) ?? "§bMember") + `§l§8]§r §7${data.sender.nameTag}:§r ${data.message}`}]})}`) | ||
} catch (error) { | ||
return console.warn(`${error}, ${error.stack}`); | ||
} | ||
}); | ||
world.sendMessage({ | ||
rawtext: [ | ||
{ | ||
text: | ||
"§l§8[§r" + | ||
(data.sender | ||
.getTags() | ||
.find((tag) => tag.startsWith("rank:")) | ||
?.substring(5) | ||
?.replaceAll("--", "§r§l§8][§r") ?? "§bMember") + | ||
`§l§8]§r §7${data.sender.nameTag}:§r ${data.message}`, | ||
}, | ||
], | ||
}); | ||
data.cancel = true; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.