Skip to content

Commit

Permalink
Scripts Update: 18/12/2023 (#336)
Browse files Browse the repository at this point in the history
* Content Update

* remove internal .d.ts file

* add header

* Update README.md

* Update index.ts

* Update README.md
  • Loading branch information
JaylyDev authored Dec 18, 2023
1 parent e2a964e commit 2d9988d
Show file tree
Hide file tree
Showing 23 changed files with 945 additions and 256 deletions.
66 changes: 35 additions & 31 deletions scripts/anti-32k-event/index.js
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();
79 changes: 79 additions & 0 deletions scripts/anti-32k-event/index.ts
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();
48 changes: 22 additions & 26 deletions scripts/anti-32k/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// 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
Expand All @@ -16,32 +15,29 @@
* --------------------------------------------------------------------------
*/
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;
/** @type {mc.ItemEnchantsComponent} */
// @ts-ignore
const enchants = item.getComponent("enchantments");
const enchantments = enchants.enchantments;
const newEnchants = new mc.EnchantmentList(enchantments.slot);
for (let enchant of enchantments) {
if (newEnchants.addEnchantment(enchant)) continue;
container.setItem(slot);
break;
}
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);
43 changes: 43 additions & 0 deletions scripts/anti-32k/index.ts
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);
27 changes: 16 additions & 11 deletions scripts/chat-rank/chat-rank.js
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;
});
5 changes: 1 addition & 4 deletions scripts/chat-ranks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ function getRanks(player) {
return ranks.length == 0 ? [DEFAULT_RANK] : ranks;
}
world.beforeEvents.chatSend.subscribe((data) => {
data.sendToTargets = true;
data.setTargets([]);
});
world.afterEvents.chatSend.subscribe((data) => {
const ranks = getRanks(data.sender).join("§r§l§8][§r");
const message = data.message;
world.sendMessage(`§r§l§8[§r${ranks}§r§l§8]§r§7 ${data.sender.name}:§r ${message}`);
data.cancel = true;
});
8 changes: 2 additions & 6 deletions scripts/chat-ranks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,8 @@ function getRanks(player: Player): string[] {
}

world.beforeEvents.chatSend.subscribe((data) => {
data.sendToTargets = true;
data.setTargets([]);
});

world.afterEvents.chatSend.subscribe((data) => {
const ranks = getRanks(data.sender).join("§r§l§8][§r");
const message = data.message;
world.sendMessage(`§r§l§8[§r${ranks}§r§l§8]§r§7 ${data.sender.name}:§r ${message}`);
});
data.cancel = true;
});
4 changes: 0 additions & 4 deletions scripts/entity-death-event/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,9 @@ const callbacks = [];
// backend
world.afterEvents.entityHurt.subscribe((event) => {
const { hurtEntity } = event;

if (!hurtEntity) return;

/** @type {EntityHealthComponent} */
// @ts-expect-error
const health = hurtEntity.getComponent(EntityHealthComponent.componentId);

if (health.currentValue > 0) return;

for (const callback of callbacks) {
Expand Down
Loading

0 comments on commit 2d9988d

Please sign in to comment.