Skip to content

Commit 2d9988d

Browse files
authored
Scripts Update: 18/12/2023 (JaylyDev#336)
* Content Update * remove internal .d.ts file * add header * Update README.md * Update index.ts * Update README.md
1 parent e2a964e commit 2d9988d

23 files changed

Lines changed: 945 additions & 256 deletions

File tree

scripts/anti-32k-event/index.js

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,74 @@
11
// Script example for ScriptAPI
22
// Author: JaylyMC <https://github.com/JaylyDev>
33
// Project: https://github.com/JaylyDev/ScriptAPI
4-
5-
import { Enchantment, Entity, EntityInventoryComponent, ItemEnchantsComponent, ItemStack, system, TicksPerSecond, world } from '@minecraft/server';
6-
const tickInterval = TicksPerSecond;
4+
import { EntityInventoryComponent, ItemEnchantableComponent, system, TicksPerSecond, world } from '@minecraft/server';
5+
/**
6+
* Represents an event indicating incompatible enchantments on an item.
7+
*/
78
class IncompatibleEnchantmentAlertEvent {
9+
/**
10+
* Creates a new instance of IncompatibleEnchantmentAlertEvent.
11+
* @param {boolean} exceedMaxLevel - Indicates whether the enchantment exceeds its maximum level.
12+
* @param {boolean} incompatibleEnchantmentType - Indicates whether the enchantment type is incompatible.
13+
* @param {Enchantment} enchantment - The enchantment causing the alert.
14+
* @param {ItemStack} item - The item with the incompatible enchantment.
15+
* @param {Entity} source - The entity triggering the alert.
16+
*/
817
constructor(exceedMaxLevel, incompatibleEnchantmentType, enchantment, item, source) {
9-
/**
10-
* @type {boolean}
11-
*/
1218
this.exceedMaxLevel = exceedMaxLevel;
13-
/**
14-
* @type {boolean}
15-
*/
1619
this.incompatibleEnchantmentType = incompatibleEnchantmentType;
17-
/**
18-
* @type {Enchantment}
19-
*/
2020
this.enchantment = enchantment;
21-
/**
22-
* @type {ItemStack}
23-
*/
2421
this.item = item;
25-
/**
26-
* @type {Entity}
27-
*/
2822
this.source = source;
2923
}
3024
;
3125
}
3226
;
27+
/**
28+
* Signal class for subscribing to events related to incompatible enchantments.
29+
*/
3330
class IncompatibleEnchantmentAlertEventSignal {
3431
/**
35-
* @param {(arg0: IncompatibleEnchantmentAlertEvent) => void} callback
36-
*/
32+
* Subscribes to the incompatible enchantment alert event and specifies a callback function.
33+
* @param {(arg0: IncompatibleEnchantmentAlertEvent) => void} callback - The callback function to be invoked when an alert occurs.
34+
* Accepts a single parameter of type IncompatibleEnchantmentAlertEvent.
35+
* @returns {number} - An identifier for the subscription, which can be used for unsubscribing.
36+
*/
3737
subscribe(callback) {
3838
return system.runInterval(function () {
3939
for (const player of world.getAllPlayers()) {
40-
/**
41-
* @type {EntityInventoryComponent}
42-
*/
43-
// @ts-ignore
4440
const inventory = player.getComponent(EntityInventoryComponent.componentId);
4541
for (let index = 0; index < inventory.container.size; index++) {
4642
const item = inventory.container.getItem(index);
47-
/** @type {ItemEnchantsComponent} */
48-
// @ts-ignore
49-
const enchantments = item === null || item === void 0 ? void 0 : item.getComponent(ItemEnchantsComponent.componentId);
50-
if (!item || !enchantments)
43+
if (!item)
5144
continue;
52-
for (const enchantment of enchantments.enchantments) {
53-
const enchantmentIsIncompatible = enchantments.enchantments.canAddEnchantment(new Enchantment(enchantment.type)) === false;
45+
const enchantable = item.getComponent(ItemEnchantableComponent.componentId);
46+
for (const enchantment of enchantable.getEnchantments()) {
47+
const enchantmentIsIncompatible = enchantable.canAddEnchantment(enchantment) === false;
48+
if (typeof enchantment.type !== 'object')
49+
continue;
5450
const enchantmentExcceedsMaxLevel = enchantment.level > enchantment.type.maxLevel;
5551
if (!enchantmentIsIncompatible && !enchantmentExcceedsMaxLevel)
5652
continue;
5753
callback(new IncompatibleEnchantmentAlertEvent(enchantmentExcceedsMaxLevel, enchantmentIsIncompatible, enchantment, item, player));
5854
}
5955
}
6056
}
61-
}, tickInterval);
57+
}, TicksPerSecond);
6258
}
6359
;
60+
/**
61+
* Unsubscribes from the incompatible enchantment alert event using the provided subscription identifier.
62+
* @param {number} id - The identifier of the subscription to be removed.
63+
*/
6464
unsubscribe(id) {
6565
system.clearRun(id);
6666
}
6767
;
6868
}
6969
;
70+
/**
71+
* Global instance of IncompatibleEnchantmentAlertEventSignal for easy access and usage.
72+
* @type {IncompatibleEnchantmentAlertEventSignal}
73+
*/
7074
export const incompatibleEnchantment = new IncompatibleEnchantmentAlertEventSignal();

scripts/anti-32k-event/index.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Script example for ScriptAPI
2+
// Author: JaylyMC <https://github.com/JaylyDev>
3+
// Project: https://github.com/JaylyDev/ScriptAPI
4+
5+
import { Enchantment, Entity, EntityInventoryComponent, ItemEnchantableComponent, ItemStack, system, TicksPerSecond, world } from '@minecraft/server';
6+
7+
/**
8+
* Represents an event indicating incompatible enchantments on an item.
9+
*/
10+
class IncompatibleEnchantmentAlertEvent {
11+
exceedMaxLevel: boolean;
12+
incompatibleEnchantmentType: boolean;
13+
enchantment: Enchantment;
14+
item: ItemStack;
15+
source: Entity;
16+
/**
17+
* Creates a new instance of IncompatibleEnchantmentAlertEvent.
18+
* @param {boolean} exceedMaxLevel - Indicates whether the enchantment exceeds its maximum level.
19+
* @param {boolean} incompatibleEnchantmentType - Indicates whether the enchantment type is incompatible.
20+
* @param {Enchantment} enchantment - The enchantment causing the alert.
21+
* @param {ItemStack} item - The item with the incompatible enchantment.
22+
* @param {Entity} source - The entity triggering the alert.
23+
*/
24+
constructor(exceedMaxLevel: boolean, incompatibleEnchantmentType: boolean, enchantment: Enchantment, item: ItemStack, source: Entity) {
25+
this.exceedMaxLevel = exceedMaxLevel;
26+
this.incompatibleEnchantmentType = incompatibleEnchantmentType;
27+
this.enchantment = enchantment;
28+
this.item = item;
29+
this.source = source;
30+
};
31+
};
32+
33+
/**
34+
* Signal class for subscribing to events related to incompatible enchantments.
35+
*/
36+
class IncompatibleEnchantmentAlertEventSignal {
37+
/**
38+
* Subscribes to the incompatible enchantment alert event and specifies a callback function.
39+
* @param {(arg0: IncompatibleEnchantmentAlertEvent) => void} callback - The callback function to be invoked when an alert occurs.
40+
* Accepts a single parameter of type IncompatibleEnchantmentAlertEvent.
41+
* @returns {number} - An identifier for the subscription, which can be used for unsubscribing.
42+
*/
43+
subscribe(callback: (arg0: IncompatibleEnchantmentAlertEvent) => void): number {
44+
return system.runInterval(function () {
45+
for (const player of world.getAllPlayers()) {
46+
const inventory = player.getComponent(EntityInventoryComponent.componentId);
47+
for (let index = 0; index < inventory.container.size; index++) {
48+
const item = inventory.container.getItem(index);
49+
if (!item) continue;
50+
51+
const enchantable = item.getComponent(ItemEnchantableComponent.componentId);
52+
53+
for (const enchantment of enchantable.getEnchantments()) {
54+
const enchantmentIsIncompatible = enchantable.canAddEnchantment(enchantment) === false;
55+
if (typeof enchantment.type !== 'object') continue;
56+
const enchantmentExcceedsMaxLevel = enchantment.level > enchantment.type.maxLevel;
57+
if (!enchantmentIsIncompatible && !enchantmentExcceedsMaxLevel)
58+
continue;
59+
callback(new IncompatibleEnchantmentAlertEvent(enchantmentExcceedsMaxLevel, enchantmentIsIncompatible, enchantment, item, player));
60+
}
61+
}
62+
}
63+
}, TicksPerSecond);
64+
};
65+
66+
/**
67+
* Unsubscribes from the incompatible enchantment alert event using the provided subscription identifier.
68+
* @param {number} id - The identifier of the subscription to be removed.
69+
*/
70+
unsubscribe(id: number) {
71+
system.clearRun(id);
72+
};
73+
};
74+
75+
/**
76+
* Global instance of IncompatibleEnchantmentAlertEventSignal for easy access and usage.
77+
* @type {IncompatibleEnchantmentAlertEventSignal}
78+
*/
79+
export const incompatibleEnchantment: IncompatibleEnchantmentAlertEventSignal = new IncompatibleEnchantmentAlertEventSignal();

scripts/anti-32k/index.js

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// JaylyMC <https://github.com/JaylyDev>
44
// Remember M9 <https://github.com/Remember-M9>
55
// Project: https://github.com/JaylyDev/ScriptAPI
6-
76
/**
87
* Minecraft Bedrock Anti Hacked Items
98
* @license MIT
@@ -16,32 +15,29 @@
1615
* --------------------------------------------------------------------------
1716
*/
1817
import * as mc from "@minecraft/server";
19-
2018
const { world, system } = mc;
21-
2219
function onTick() {
23-
for (const player of world.getPlayers()) {
24-
/** @type {mc.EntityInventoryComponent} */
25-
// @ts-ignore
26-
const inventory = player.getComponent("minecraft:inventory");
27-
const { container, inventorySize } = inventory;
28-
if (container.emptySlotsCount == inventorySize) continue;
29-
for (let slot = 0; slot < inventorySize; slot++) {
30-
const item = container.getItem(slot);
31-
if (!item) continue;
32-
/** @type {mc.ItemEnchantsComponent} */
33-
// @ts-ignore
34-
const enchants = item.getComponent("enchantments");
35-
const enchantments = enchants.enchantments;
36-
const newEnchants = new mc.EnchantmentList(enchantments.slot);
37-
for (let enchant of enchantments) {
38-
if (newEnchants.addEnchantment(enchant)) continue;
39-
container.setItem(slot);
40-
break;
41-
}
20+
for (const player of world.getPlayers()) {
21+
/** @type {mc.EntityInventoryComponent} */
22+
// @ts-ignore
23+
const inventory = player.getComponent("minecraft:inventory");
24+
const { container, inventorySize } = inventory;
25+
if (container.emptySlotsCount == inventorySize)
26+
continue;
27+
for (let slot = 0; slot < inventorySize; slot++) {
28+
const item = container.getItem(slot);
29+
if (!item)
30+
continue;
31+
const enchantable = item.getComponent("minecraft:enchantable");
32+
if (!enchantable)
33+
continue;
34+
for (const enchantment of enchantable.getEnchantments()) {
35+
if (enchantable.canAddEnchantment(enchantment))
36+
continue;
37+
enchantable.removeEnchantment(enchantment.type);
38+
}
39+
}
4240
}
43-
}
44-
};
45-
46-
41+
}
42+
;
4743
system.runInterval(onTick);

scripts/anti-32k/index.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Script example for ScriptAPI
2+
// Author: Smell of curry <https://github.com/smell-of-curry>
3+
// JaylyMC <https://github.com/JaylyDev>
4+
// Remember M9 <https://github.com/Remember-M9>
5+
// Project: https://github.com/JaylyDev/ScriptAPI
6+
7+
/**
8+
* Minecraft Bedrock Anti Hacked Items
9+
* @license MIT
10+
* @author Smell of curry & JaylyMC
11+
* @version 1.1.0
12+
* --------------------------------------------------------------------------
13+
* This is a anti hacked items, meaning it checks a players inventory every
14+
* tick then it tests if they have any banned items, then checks if they have
15+
* items that have hacked enchants and clears the item from inventory
16+
* --------------------------------------------------------------------------
17+
*/
18+
import * as mc from "@minecraft/server";
19+
20+
const { world, system } = mc;
21+
22+
function onTick() {
23+
for (const player of world.getPlayers()) {
24+
/** @type {mc.EntityInventoryComponent} */
25+
// @ts-ignore
26+
const inventory = player.getComponent("minecraft:inventory");
27+
const { container, inventorySize } = inventory;
28+
if (container.emptySlotsCount == inventorySize) continue;
29+
for (let slot = 0; slot < inventorySize; slot++) {
30+
const item = container.getItem(slot);
31+
if (!item) continue;
32+
const enchantable = item.getComponent("minecraft:enchantable");
33+
if (!enchantable) continue;
34+
for (const enchantment of enchantable.getEnchantments()) {
35+
if (enchantable.canAddEnchantment(enchantment)) continue;
36+
enchantable.removeEnchantment(enchantment.type);
37+
}
38+
}
39+
}
40+
};
41+
42+
43+
system.runInterval(onTick);

scripts/chat-rank/chat-rank.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import { world } from "@minecraft/server";
22

33
world.beforeEvents.chatSend.subscribe((data) => {
4-
data.sendToTargets = true
5-
data.setTargets([])
6-
})
7-
8-
world.afterEvents.chatSend.subscribe((data) => {
9-
try {
10-
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}`}]})}`)
11-
} catch (error) {
12-
return console.warn(`${error}, ${error.stack}`);
13-
}
14-
});
4+
world.sendMessage({
5+
rawtext: [
6+
{
7+
text:
8+
"§l§8[§r" +
9+
(data.sender
10+
.getTags()
11+
.find((tag) => tag.startsWith("rank:"))
12+
?.substring(5)
13+
?.replaceAll("--", "§r§l§8][§r") ?? "§bMember") +
14+
`§l§8]§r §7${data.sender.nameTag}:§r ${data.message}`,
15+
},
16+
],
17+
});
18+
data.cancel = true;
19+
});

scripts/chat-ranks/index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,8 @@ function getRanks(player) {
2828
return ranks.length == 0 ? [DEFAULT_RANK] : ranks;
2929
}
3030
world.beforeEvents.chatSend.subscribe((data) => {
31-
data.sendToTargets = true;
32-
data.setTargets([]);
33-
});
34-
world.afterEvents.chatSend.subscribe((data) => {
3531
const ranks = getRanks(data.sender).join("§r§l§8][§r");
3632
const message = data.message;
3733
world.sendMessage(`§r§l§8[§r${ranks}§r§l§8]§r§7 ${data.sender.name}:§r ${message}`);
34+
data.cancel = true;
3835
});

scripts/chat-ranks/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,8 @@ function getRanks(player: Player): string[] {
3131
}
3232

3333
world.beforeEvents.chatSend.subscribe((data) => {
34-
data.sendToTargets = true;
35-
data.setTargets([]);
36-
});
37-
38-
world.afterEvents.chatSend.subscribe((data) => {
3934
const ranks = getRanks(data.sender).join("§r§l§8][§r");
4035
const message = data.message;
4136
world.sendMessage(`§r§l§8[§r${ranks}§r§l§8]§r§7 ${data.sender.name}:§r ${message}`);
42-
});
37+
data.cancel = true;
38+
});

scripts/entity-death-event/index.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,9 @@ const callbacks = [];
1717
// backend
1818
world.afterEvents.entityHurt.subscribe((event) => {
1919
const { hurtEntity } = event;
20-
2120
if (!hurtEntity) return;
2221

23-
/** @type {EntityHealthComponent} */
24-
// @ts-expect-error
2522
const health = hurtEntity.getComponent(EntityHealthComponent.componentId);
26-
2723
if (health.currentValue > 0) return;
2824

2925
for (const callback of callbacks) {

0 commit comments

Comments
 (0)