fix(kubejs): update kubejs scripts
This commit is contained in:
parent
28a30d94c0
commit
57be389894
13 changed files with 921 additions and 251 deletions
|
|
@ -1,34 +0,0 @@
|
|||
{
|
||||
"dimensions": [
|
||||
{
|
||||
"id": "retards:creative",
|
||||
"gamemode": "creative",
|
||||
"portal": {
|
||||
"material": "minecraft:glowstone",
|
||||
"fluid": "minecraft:water",
|
||||
"color": "#1E66F5"
|
||||
},
|
||||
"worldgen": {
|
||||
"minecraft:bedrock": 1,
|
||||
"minecraft:stone": 40,
|
||||
"minecraft:dirt": 8,
|
||||
"minecraft:grass_block": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "retards:adventure",
|
||||
"gamemode": "adventure",
|
||||
"portal": {
|
||||
"material": "minecraft:bedrock",
|
||||
"fluid": "minecraft:water",
|
||||
"color": "#1E66F5"
|
||||
},
|
||||
"worldgen": {
|
||||
"minecraft:bedrock": 1,
|
||||
"minecraft:stone": 40,
|
||||
"minecraft:dirt": 8,
|
||||
"minecraft:grass_block": 1
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
17
kubejs/jsconfig.json
Normal file
17
kubejs/jsconfig.json
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"allowJs": true,
|
||||
"noEmit": true,
|
||||
"checkJs": true,
|
||||
"strict": true,
|
||||
"target": "ES2020",
|
||||
"module": "ES2020",
|
||||
"lib": ["ES2020", "DOM"],
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": ["*"]
|
||||
}
|
||||
},
|
||||
"include": ["**/*.js", "**/*.d.ts"],
|
||||
"exclude": ["probe/cache/**/*"]
|
||||
}
|
||||
61
kubejs/server_scripts/config.js
Normal file
61
kubejs/server_scripts/config.js
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/**
|
||||
* @type {{
|
||||
* dimensions: Array<{
|
||||
* id: string,
|
||||
* gamemode: string,
|
||||
* portal: {
|
||||
* material: string,
|
||||
* fluid: string,
|
||||
* color: string,
|
||||
* },
|
||||
* worldgen: {
|
||||
* [key: string]: number,
|
||||
* },
|
||||
* }>,
|
||||
* greeting: {
|
||||
* [key: string]: string
|
||||
* },
|
||||
* }}
|
||||
*/
|
||||
const config = {
|
||||
dimensions: [
|
||||
{
|
||||
id: "retards:creative",
|
||||
gamemode: "creative",
|
||||
portal: {
|
||||
material: "minecraft:glowstone",
|
||||
fluid: "minecraft:water",
|
||||
color: "#1E66F5",
|
||||
},
|
||||
worldgen: {
|
||||
"minecraft:bedrock": 1,
|
||||
"minecraft:stone": 40,
|
||||
"minecraft:dirt": 8,
|
||||
"minecraft:grass_block": 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "retards:adventure",
|
||||
gamemode: "adventure",
|
||||
portal: {
|
||||
material: "minecraft:bedrock",
|
||||
fluid: "minecraft:water",
|
||||
color: "#1E66F5",
|
||||
},
|
||||
worldgen: {
|
||||
"minecraft:bedrock": 1,
|
||||
"minecraft:stone": 40,
|
||||
"minecraft:dirt": 8,
|
||||
"minecraft:grass_block": 1,
|
||||
},
|
||||
},
|
||||
],
|
||||
greeting: {
|
||||
Sbebas_s: "MCFLURRY!!!",
|
||||
Mark917: "CUCARACHA",
|
||||
Anthony_7: "onion rings",
|
||||
Tren_boy: "Kebab",
|
||||
Cheruz: "Fa freddo",
|
||||
default: "Welcome",
|
||||
},
|
||||
};
|
||||
|
|
@ -1,17 +1,3 @@
|
|||
// Creates and configures custom dimensions
|
||||
|
||||
const raw = JsonIO.readJson("kubejs/config/settings.json");
|
||||
const config = raw ? JSON.parse(raw.toString()) : {};
|
||||
|
||||
function hexToRgb(hex) {
|
||||
const h = hex.replace("#", "");
|
||||
return {
|
||||
r: parseInt(h.substring(0, 2), 16),
|
||||
g: parseInt(h.substring(2, 4), 16),
|
||||
b: parseInt(h.substring(4, 6), 16),
|
||||
};
|
||||
}
|
||||
|
||||
var portalColor;
|
||||
|
||||
ServerEvents.highPriorityData((event) => {
|
||||
|
|
@ -19,9 +5,8 @@ ServerEvents.highPriorityData((event) => {
|
|||
config.dimensions.forEach((dimension) => {
|
||||
const [modId, dimId] = dimension.id.split(":");
|
||||
|
||||
/////////////////
|
||||
/// DIMENSION ///
|
||||
/////////////////
|
||||
// Add dimension
|
||||
/** @type {any} */
|
||||
const dimJson = { type: "minecraft:overworld" };
|
||||
if (dimension.worldgen)
|
||||
dimJson["generator"] = {
|
||||
|
|
@ -41,29 +26,28 @@ ServerEvents.highPriorityData((event) => {
|
|||
};
|
||||
event.addJson(`${modId}:dimension/${dimId}.json`, dimJson);
|
||||
|
||||
//////////////
|
||||
/// PORTAL ///
|
||||
//////////////
|
||||
// Add portal
|
||||
const portal = dimension.portal;
|
||||
if (portal) {
|
||||
portalColor = hexToRgb(portal.color);
|
||||
event.addJson(`${modId}:portals/${dimId}.json`, {
|
||||
block: portal.material,
|
||||
dim: dimension.id,
|
||||
r: portalColor.r,
|
||||
g: portalColor.g,
|
||||
b: portalColor.b,
|
||||
ignitionType: "FLUID",
|
||||
ignitionSource: portal.fluid,
|
||||
});
|
||||
event.addJson(
|
||||
`${modId}:portals/${dimId}.json`,
|
||||
/** @type {any} */ ({
|
||||
block: portal.material,
|
||||
dim: dimension.id,
|
||||
r: portalColor.r,
|
||||
g: portalColor.g,
|
||||
b: portalColor.b,
|
||||
ignitionType: "FLUID",
|
||||
ignitionSource: portal.fluid,
|
||||
}),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
//////////////
|
||||
/// DIMINV ///
|
||||
//////////////
|
||||
// Setup Dimensional Inventories
|
||||
PlayerEvents.loggedIn((event) => {
|
||||
if (config.dimensions) {
|
||||
config.dimensions.forEach((dimension) => {
|
||||
|
|
@ -71,22 +55,38 @@ PlayerEvents.loggedIn((event) => {
|
|||
const data = event.server.persistentData;
|
||||
if (!data.getBoolean(`${dimId}Initialized`)) {
|
||||
data.putBoolean(`${dimId}Initialized`, true);
|
||||
event.server.scheduleInTicks(20, () => {
|
||||
event.server.runCommandSilent(`diminv pool ${dimId} create`);
|
||||
event.server.runCommandSilent(
|
||||
`diminv pool ${dimId} dimension ${dimension.id} assign`,
|
||||
);
|
||||
event.server.runCommandSilent(
|
||||
`diminv pool ${dimId} gameMode ${dimension.gamemode}`,
|
||||
);
|
||||
event.server.runCommandSilent(
|
||||
`diminv pool ${dimId} progressAdvancements false`,
|
||||
);
|
||||
event.server.runCommandSilent(
|
||||
`diminv pool ${dimId} incrementStatistics false`,
|
||||
);
|
||||
});
|
||||
event.server.scheduleInTicks(
|
||||
20,
|
||||
/** @type {any} */ (
|
||||
() => {
|
||||
event.server.runCommandSilent(`diminv pool ${dimId} create`);
|
||||
event.server.runCommandSilent(
|
||||
`diminv pool ${dimId} dimension ${dimension.id} assign`,
|
||||
);
|
||||
event.server.runCommandSilent(
|
||||
`diminv pool ${dimId} gameMode ${dimension.gamemode}`,
|
||||
);
|
||||
event.server.runCommandSilent(
|
||||
`diminv pool ${dimId} progressAdvancements false`,
|
||||
);
|
||||
event.server.runCommandSilent(
|
||||
`diminv pool ${dimId} incrementStatistics false`,
|
||||
);
|
||||
}
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Disable entity spawning
|
||||
EntityEvents.checkSpawn((event) => {
|
||||
if (!event.level) return;
|
||||
|
||||
config.dimensions.forEach((dimension) => {
|
||||
if (event.level.dimension.toString() === dimension.id) {
|
||||
event.cancel();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
|||
11
kubejs/server_scripts/greeting.js
Normal file
11
kubejs/server_scripts/greeting.js
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
// Shows a greeting message on player join
|
||||
PlayerEvents.loggedIn((event) => {
|
||||
const username = event.player.username;
|
||||
title(
|
||||
event.server,
|
||||
username,
|
||||
config.greeting[username]
|
||||
? config.greeting[username]
|
||||
: config.greeting.default,
|
||||
);
|
||||
});
|
||||
|
|
@ -1,24 +1,29 @@
|
|||
// Makes Tickets of Eternal Keeping not consumed on death.
|
||||
|
||||
/** @type {Object<string, ?Internal.ItemStack>} */
|
||||
const tickets = {};
|
||||
|
||||
EntityEvents.death((event) => {
|
||||
// Register ticket on player death
|
||||
EntityEvents.death("player", (event) => {
|
||||
const player = event.player;
|
||||
if (event.entity.isPlayer()) {
|
||||
tickets[player.uuid] = null;
|
||||
const uuid = String(player.uuid);
|
||||
|
||||
player.inventory.allItems.forEach((item) => {
|
||||
if (item.nbt && item.nbt.EternalKeep) tickets[player.uuid] = item.copy();
|
||||
if (
|
||||
event.entity.isPlayer() &&
|
||||
String(player.level.dimension) !== "retards:adventure"
|
||||
) {
|
||||
tickets[uuid] = null;
|
||||
|
||||
iterateInventory(player, (item) => {
|
||||
if (item.nbt && item.nbt.get("EternalKeep")) tickets[uuid] = item.copy();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Give ticket on player respawn
|
||||
PlayerEvents.respawned((event) => {
|
||||
const player = event.player;
|
||||
const uuid = String(player.uuid);
|
||||
|
||||
const ticket = tickets[player.uuid];
|
||||
|
||||
if (ticket != null) player.give(Item.of(ticket, 1));
|
||||
|
||||
tickets[player.uuid] = null;
|
||||
const ticket = tickets[uuid];
|
||||
if (ticket) player.give(Item.of(ticket, 1));
|
||||
tickets[uuid] = null;
|
||||
});
|
||||
|
|
|
|||
127
kubejs/server_scripts/lib.js
Normal file
127
kubejs/server_scripts/lib.js
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
// priority: 100
|
||||
|
||||
/**
|
||||
* Converts a hex color to RGB.
|
||||
* @param {string} hex - The hex color.
|
||||
* @returns {{r: number, g: number, b: number}} - The resulting RGB.
|
||||
*/
|
||||
function hexToRgb(hex) {
|
||||
const h = hex.replace("#", "");
|
||||
return {
|
||||
r: parseInt(h.substring(0, 2), 16),
|
||||
g: parseInt(h.substring(2, 4), 16),
|
||||
b: parseInt(h.substring(4, 6), 16),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates over a player's inventory.
|
||||
* @param {Internal.Player} player
|
||||
* @param {(item: Internal.ItemStack) => void} callback
|
||||
*/
|
||||
function iterateInventory(player, callback) {
|
||||
player.inventory.allItems.forEach(
|
||||
/** @type {any} */ (
|
||||
(/** @type {Internal.ItemStack} */ item) => {
|
||||
callback(item);
|
||||
}
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters entities in a level.
|
||||
* @param {Internal.ServerLevel} level
|
||||
* @param {(entity: Internal.Entity) => boolean} callback
|
||||
* @returns {Internal.EntityArrayList} - The filtered entities.
|
||||
*/
|
||||
function filterEntities(level, callback) {
|
||||
return level
|
||||
.getEntities()
|
||||
.filter(
|
||||
/** @type {any} */ (
|
||||
(/** @type {Internal.Entity} */ entity) => callback(entity)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a title message to a player.
|
||||
* @param {Internal.MinecraftServer} server - The server instance.
|
||||
* @param {string} username - The player's username.
|
||||
* @param {string} message - The message to send.
|
||||
*/
|
||||
function title(server, username, message) {
|
||||
server.runCommandSilent("title @a times 20 200 20");
|
||||
server.runCommandSilent(`title ${username} title ["${message}"]`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a command.
|
||||
* @param {Internal.CommandRegistryEventJS} event
|
||||
* @param {{
|
||||
* command: string,
|
||||
* operator?: boolean,
|
||||
* handler?: (ctx: Internal.CommandContext<Internal.CommandSourceStack>) => void,
|
||||
* parameters?: Array<{
|
||||
* name: string,
|
||||
* type: Internal.ArgumentTypeWrappers,
|
||||
* handler?: (ctx: Internal.CommandContext<Internal.CommandSourceStack>) => void,
|
||||
* }>
|
||||
* }} options
|
||||
*/
|
||||
function registerCommand(event, options) {
|
||||
const command = options.command;
|
||||
const operator = options.operator !== undefined ? options.operator : false;
|
||||
const parameters = options.parameters !== undefined ? options.parameters : [];
|
||||
const handler = options.handler !== undefined ? options.handler : null;
|
||||
|
||||
const cmd = event.commands.literal(command);
|
||||
if (operator)
|
||||
cmd.requires(
|
||||
/** @type {any} */ (
|
||||
(/** @type {Internal.CommandSourceStack} */ source) =>
|
||||
source.hasPermission(2)
|
||||
),
|
||||
);
|
||||
|
||||
if (handler !== null)
|
||||
cmd.executes(
|
||||
/** @type {any} */ (
|
||||
/** @param {Internal.CommandContext<Internal.CommandSourceStack>} ctx */
|
||||
(ctx) => {
|
||||
handler(ctx);
|
||||
return 1;
|
||||
}
|
||||
),
|
||||
);
|
||||
|
||||
/** @type { Internal.LiteralArgumentBuilder<Internal.CommandSourceStack> | Internal.RequiredArgumentBuilder<Internal.CommandSourceStack, any> } */
|
||||
let current = cmd;
|
||||
parameters.forEach((param, index) => {
|
||||
const name = param.name;
|
||||
const type = param.type;
|
||||
const paramHandler = param.handler;
|
||||
const arg = event.commands.argument(name, type.create(event));
|
||||
const isLast = index === parameters.length - 1;
|
||||
|
||||
const finalHandler = paramHandler ? paramHandler : isLast ? handler : null;
|
||||
|
||||
if (finalHandler) {
|
||||
arg.executes(
|
||||
/** @type {any} */ (
|
||||
/** @param {Internal.CommandContext<Internal.CommandSourceStack>} ctx */
|
||||
(ctx) => {
|
||||
finalHandler(ctx);
|
||||
return 1;
|
||||
}
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
current.then(arg);
|
||||
current = arg;
|
||||
});
|
||||
|
||||
event.register(cmd);
|
||||
}
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
ServerEvents.commandRegistry((event) => {
|
||||
const { commands: Commands, arguments: Arguments } = event;
|
||||
|
||||
// /rsapi [<player>]
|
||||
function playerInventory(player) {
|
||||
const result = [];
|
||||
|
||||
function pushItem(pos, item) {
|
||||
if (item.isEmpty()) return;
|
||||
let nbtData = {};
|
||||
try {
|
||||
if (item.nbt) {
|
||||
nbtData = JSON.parse(item.nbt.toString());
|
||||
}
|
||||
} catch (e) {
|
||||
nbtData = {};
|
||||
}
|
||||
result.push([pos, item.id, item.count, nbtData]);
|
||||
}
|
||||
|
||||
// Main inventory (27 slots)
|
||||
player.inventory.items.forEach((item, i) => {
|
||||
pushItem(["inventory", i], item);
|
||||
});
|
||||
|
||||
// Hotbar (9 slots)
|
||||
// player.inventory.hotbar.forEach((item, i) => {
|
||||
// pushItem(["hotbar", i], item);
|
||||
// });
|
||||
|
||||
console.log(result);
|
||||
return 1;
|
||||
|
||||
// Armor
|
||||
// pushItem(["armor", "head"], player.headArmorItem);
|
||||
// pushItem(["armor", "chest"], player.chestArmorItem);
|
||||
// pushItem(["armor", "legs"], player.legsArmorItem);
|
||||
// pushItem(["armor", "feet"], player.feetArmorItem);
|
||||
|
||||
// Offhand
|
||||
// pushItem(["offhand", 0], player.offHandItem);
|
||||
|
||||
// Trinkets (if present)
|
||||
if (player.trinkets) {
|
||||
player.trinkets.groups.forEach((group) => {
|
||||
group.slots.forEach((slot) => {
|
||||
slot.items.forEach((item, index) => {
|
||||
pushItem(["trinkets", group.id, slot.id, index], item);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
console.log(JSON.stringify(result));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// /rsapi
|
||||
event.register(
|
||||
Commands.literal("rsapi")
|
||||
.requires((src) => src.hasPermission(2))
|
||||
.executes((ctx) => playerInventory(ctx.source.player))
|
||||
.then(
|
||||
// /rsapi [<player>]
|
||||
Commands.argument("target", Arguments.PLAYER.create(event)).executes(
|
||||
(ctx) => playerInventory(Arguments.PLAYER.getResult(ctx, "target")),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
var _hooks = {};
|
||||
|
||||
function rsapi(event, id, data) {
|
||||
console.log(`rsapi:${id}:${JSON.stringify(data)}`);
|
||||
if (_hooks[id]) _hooks[id](event, data);
|
||||
}
|
||||
|
||||
const RSEvent = {
|
||||
on: (id, func) => {
|
||||
_hooks[id] = func;
|
||||
},
|
||||
};
|
||||
|
||||
function getData(event) {
|
||||
return {
|
||||
username: event.player ? String(event.player.username) : null,
|
||||
message: event.message ? String(event.message) : null,
|
||||
input: event.input ? String(event.input) : null,
|
||||
};
|
||||
}
|
||||
|
||||
///////////////////
|
||||
/// === API === ///
|
||||
///////////////////
|
||||
|
||||
// rsapi:event.playerJoined:"Player"
|
||||
PlayerEvents.loggedIn((event) => {
|
||||
const { username } = getData(event);
|
||||
rsapi(event, "event.playerJoined", username);
|
||||
});
|
||||
|
||||
// rsapi:event.playerLeft:"Player"
|
||||
PlayerEvents.loggedOut((event) => {
|
||||
const { username } = getData(event);
|
||||
rsapi(event, "event.playerLeft", username);
|
||||
});
|
||||
|
||||
// rsapi:event.playerChat:["Player","Message"]
|
||||
PlayerEvents.chat((event) => {
|
||||
const { username, message } = getData(event);
|
||||
rsapi(event, "event.playerChat", [username, message]);
|
||||
});
|
||||
|
||||
// rsapi:event.serverChat:"Message"
|
||||
ServerEvents.command("say", (event) => {
|
||||
const { input } = getData(event);
|
||||
rsapi(
|
||||
event,
|
||||
"event.serverChat",
|
||||
input.startsWith("say ") ? input.slice(4) : input,
|
||||
);
|
||||
});
|
||||
|
||||
// rsapi:event.playerDied:"Player"
|
||||
EntityEvents.death("player", (event) => {
|
||||
const { username } = getData(event);
|
||||
rsapi(event, "event.playerDied", username);
|
||||
});
|
||||
|
||||
/////////////////////
|
||||
/// === HOOKS === ///
|
||||
/////////////////////
|
||||
|
||||
RSEvent.on("event.playerJoined", (event, username) => {
|
||||
function title(player, message) {
|
||||
event.server.runCommandSilent("title @a times 20 200 20");
|
||||
event.server.runCommandSilent(
|
||||
"title " + player + ' title ["' + message + '"]',
|
||||
);
|
||||
}
|
||||
|
||||
if (username === "Sbebas_s") title(username, "MCFLURRY!!!!");
|
||||
else if (username === "Mark917") title(username, "CUCARACHA");
|
||||
else if (username === "Anthony_7") title(username, "onion rings");
|
||||
else if (username === "Tren_boy") title(username, "Kebab");
|
||||
else if (username === "Cheruz") title(username, "Basta\ngiocare\nnegro");
|
||||
else title(username, "Welcome");
|
||||
});
|
||||
42
kubejs/server_scripts/rsapi.js
Normal file
42
kubejs/server_scripts/rsapi.js
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
// priority: 90
|
||||
|
||||
/**
|
||||
* Runs an RSAPI callback.
|
||||
* @param {string} id
|
||||
* @param {*} data
|
||||
*/
|
||||
function rsapi(id, data) {
|
||||
console.log(`rsapi:${id}:${JSON.stringify(data)}`);
|
||||
}
|
||||
|
||||
// rsapi:event.playerJoined:"Player"
|
||||
PlayerEvents.loggedIn((event) => {
|
||||
const username = String(event.player.username);
|
||||
rsapi("event.playerJoined", username);
|
||||
});
|
||||
|
||||
// rsapi:event.playerLeft:"Player"
|
||||
PlayerEvents.loggedOut((event) => {
|
||||
const username = String(event.player.username);
|
||||
rsapi("event.playerLeft", username);
|
||||
});
|
||||
|
||||
// rsapi:event.playerChat:["Player","Message"]
|
||||
PlayerEvents.chat((event) => {
|
||||
const username = String(event.player.username);
|
||||
const message = String(event.message);
|
||||
rsapi("event.playerChat", [username, message]);
|
||||
});
|
||||
|
||||
// rsapi:event.serverChat:"Message"
|
||||
ServerEvents.command("say", (event) => {
|
||||
const input = String(event.input);
|
||||
const message = input.startsWith("say ") ? input.slice(4) : input;
|
||||
rsapi("event.serverChat", message);
|
||||
});
|
||||
|
||||
// rsapi:event.playerDied:"Player"
|
||||
EntityEvents.death("player", (event) => {
|
||||
const username = String(event.player.username);
|
||||
rsapi("event.playerDied", username);
|
||||
});
|
||||
250
kubejs/server_scripts/warzone.js
Normal file
250
kubejs/server_scripts/warzone.js
Normal file
|
|
@ -0,0 +1,250 @@
|
|||
/**
|
||||
* @type {{
|
||||
* guns: [Internal.ItemStack, Internal.ItemStack][],
|
||||
* items: Internal.ItemStack[],
|
||||
* }}
|
||||
*/
|
||||
var loot = { guns: [], items: [] };
|
||||
|
||||
/** @type {{[key: string]: number }} */
|
||||
var playerKills = {};
|
||||
/** @type {?string} */
|
||||
var playerBoss = null;
|
||||
|
||||
ServerEvents.commandRegistry((event) => {
|
||||
// /enter_warzone <target>
|
||||
registerCommand(event, {
|
||||
command: "enter_warzone",
|
||||
operator: true,
|
||||
parameters: [
|
||||
{
|
||||
name: "target",
|
||||
type: event.arguments.PLAYER,
|
||||
handler: (ctx) => {
|
||||
const server = ctx.source.server;
|
||||
const player = event.arguments.PLAYER.getResult(ctx, "target");
|
||||
|
||||
// Initialize scoreboards
|
||||
if (!server.persistentData.getBoolean("scoreboardsInitialized")) {
|
||||
server.runCommandSilent(
|
||||
`scoreboard objectives add warzone_kills dummy "Kills"`,
|
||||
);
|
||||
server.runCommandSilent(
|
||||
`scoreboard objectives setdisplay sidebar warzone_kills`,
|
||||
);
|
||||
server.runCommandSilent(
|
||||
`scoreboard objectives setdisplay belowName warzone_kills`,
|
||||
);
|
||||
server.runCommandSilent(
|
||||
`scoreboard objectives add warzone_total_kills dummy "Total Kills"`,
|
||||
);
|
||||
server.runCommandSilent(
|
||||
`scoreboard objectives setdisplay list warzone_total_kills`,
|
||||
);
|
||||
server.persistentData.putBoolean("scoreboardsInitialized", true);
|
||||
}
|
||||
|
||||
// Teleport to warzone
|
||||
server.runCommandSilent(
|
||||
`execute in retards:adventure run tp ${player.username} 424 122 552`,
|
||||
);
|
||||
|
||||
// Clear inventory
|
||||
server.runCommandSilent(`clear ${player.username}`);
|
||||
|
||||
// Initialize kill count
|
||||
const data = player.persistentData;
|
||||
if (!data.getInt("kills")) data.putInt("kills", 0);
|
||||
|
||||
// Set scoreboard kill count
|
||||
server.runCommandSilent(
|
||||
`scoreboard players set ${player.username} warzone_total_kills ${data.getInt("kills")}`,
|
||||
);
|
||||
|
||||
// Initialize kill streak
|
||||
playerKills[player.username] = 0;
|
||||
|
||||
// Set scoreboard kill streak
|
||||
server.runCommandSilent(
|
||||
`scoreboard players set ${player.username} warzone_kills 0`,
|
||||
);
|
||||
|
||||
// Toggle layout
|
||||
server.runCommandSilent(
|
||||
`fmlayout default_hud_layout false ${player.username}`,
|
||||
);
|
||||
server.runCommandSilent(
|
||||
`fmlayout warzone_hud_layout true ${player.username}`,
|
||||
);
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// /exit_warzone <target>
|
||||
registerCommand(event, {
|
||||
command: "exit_warzone",
|
||||
operator: true,
|
||||
parameters: [
|
||||
{
|
||||
name: "target",
|
||||
type: event.arguments.PLAYER,
|
||||
handler: (ctx) => {
|
||||
const server = ctx.source.server;
|
||||
const player = event.arguments.PLAYER.getResult(ctx, "target");
|
||||
|
||||
// Teleport to portal
|
||||
server.runCommandSilent(
|
||||
`execute in retards:adventure run tp ${player.username} -103 -14 -82`,
|
||||
);
|
||||
|
||||
// Clear inventory
|
||||
server.runCommandSilent(`clear ${player.username}`);
|
||||
|
||||
// Remove from scoreboards
|
||||
server.runCommandSilent(
|
||||
`scoreboard players remove ${player.username} warzone_total_kills`,
|
||||
);
|
||||
server.runCommandSilent(
|
||||
`scoreboard players remove ${player.username} warzone_kills`,
|
||||
);
|
||||
|
||||
// Toggle layout
|
||||
server.runCommandSilent(
|
||||
`fmlayout warzone_hud_layout false ${player.username}`,
|
||||
);
|
||||
server.runCommandSilent(
|
||||
`fmlayout default_hud_layout true ${player.username}`,
|
||||
);
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// /warzone_load_loot_tables
|
||||
registerCommand(event, {
|
||||
command: "warzone_load_loot_tables",
|
||||
operator: true,
|
||||
handler: (ctx) => {
|
||||
const server = ctx.source.server;
|
||||
const level = server.getLevel("retards:adventure");
|
||||
|
||||
const itemFrames = filterEntities(
|
||||
level,
|
||||
(e) => e.type === "minecraft:item_frame",
|
||||
);
|
||||
|
||||
loot = { guns: [], items: [] };
|
||||
|
||||
const isAir = (/** @type {Internal.ItemStack} */ item) =>
|
||||
item.id === "minecraft:air";
|
||||
|
||||
for (var i = 0; i < itemFrames.size(); i++) {
|
||||
var frame = itemFrames.get(i);
|
||||
if (frame.item && frame.item.id === "minecraft:copper_ingot") {
|
||||
var pos = frame.blockPosition().below();
|
||||
var block = level.getBlock(pos);
|
||||
if (block.id == "minecraft:chest") {
|
||||
console.log(pos);
|
||||
/** @type {Internal.Optional<Internal.ChestBlockEntity>} */
|
||||
var chestEntity = level.getBlockEntity(pos, "chest");
|
||||
if (chestEntity.isPresent()) {
|
||||
/** @type {Internal.ChestBlockEntity} */
|
||||
var chest = chestEntity.get();
|
||||
for (var col = 0; col < 9; col++) {
|
||||
var first = chest.getItem(col).copy();
|
||||
var second = chest.getItem(col + 9).copy();
|
||||
var third = chest.getItem(col + 18).copy();
|
||||
|
||||
if (!isAir(first) && !isAir(second))
|
||||
loot.guns.push([first, second]);
|
||||
if (!isAir(third)) loot.items.push(third);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const gunCount = loot.guns.length;
|
||||
const itemCount = loot.items.length;
|
||||
|
||||
server.runCommandSilent(
|
||||
`say Loaded ${gunCount} guns and ${itemCount} items`,
|
||||
);
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
ServerEvents.tick((event) => {
|
||||
if (event.server.tickCount % 1200 !== 0) return;
|
||||
if (event.server.tickCount % 2400 === 0)
|
||||
event.server.runCommandSilent(
|
||||
"execute in retards:adventure run effect give @a[x=424,y=-1,z=552,distance=..128] minecraft:glowing 3 1 true",
|
||||
);
|
||||
const level = event.server.getLevel("retards:adventure");
|
||||
|
||||
const itemFrames = filterEntities(
|
||||
level,
|
||||
(entity) => entity.type === "minecraft:item_frame",
|
||||
);
|
||||
|
||||
for (var i = 0; i < itemFrames.size(); i++) {
|
||||
var frame = itemFrames.get(i);
|
||||
if (frame.item && frame.item.id === "minecraft:gunpowder") {
|
||||
var pos = frame.blockPosition().above().above();
|
||||
var block = level.getBlock(pos);
|
||||
if (block.id === "minecraft:chest") {
|
||||
/** @type {Internal.Optional<Internal.ChestBlockEntity>} */
|
||||
var chestEntity = level.getBlockEntity(pos, "chest");
|
||||
if (chestEntity.isPresent()) {
|
||||
/** @type {Internal.ChestBlockEntity} */
|
||||
var chest = chestEntity.get();
|
||||
chest.clearContent();
|
||||
var { guns, items } = loot;
|
||||
if (guns.length) {
|
||||
var [gun, ammo] = guns[Math.floor(Math.random() * guns.length)];
|
||||
chest.setItem(0, gun.copy());
|
||||
chest.setItem(1, ammo.copy());
|
||||
}
|
||||
if (items.length) {
|
||||
var item = items[Math.floor(Math.random() * items.length)];
|
||||
chest.setItem(2, item.copy());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
EntityEvents.death("player", (event) => {
|
||||
const killer = event.source.player;
|
||||
const victim = event.entity;
|
||||
|
||||
if (!killer) return;
|
||||
|
||||
// Increase killer total kill count
|
||||
const data = killer.persistentData;
|
||||
data.putInt("kills", data.getInt("kills") + 1);
|
||||
event.server.runCommandSilent(
|
||||
`scoreboard players set ${killer.username} warzone_total_kills ${data.getInt("kills")}`,
|
||||
);
|
||||
|
||||
// Increase killer kill streak
|
||||
if (!playerKills[killer.username]) playerKills[killer.username] = 0;
|
||||
playerKills[killer.username]++;
|
||||
event.server.runCommandSilent(
|
||||
`scoreboard players set ${killer.username} warzone_kills ${playerKills[killer.username]}`,
|
||||
);
|
||||
|
||||
// Reset victim kill streak
|
||||
playerKills[victim.username] = 0;
|
||||
event.server.runCommandSilent(
|
||||
`scoreboard players set ${victim.username} warzone_kills 0`,
|
||||
);
|
||||
|
||||
// Update player boss
|
||||
event.server.runCommandSilent(`effect clear ${playerBoss} minecraft:glowing`);
|
||||
for (const [username, kills] of Object.entries(playerKills))
|
||||
if (!playerBoss || kills > playerKills[playerBoss]) playerBoss = username;
|
||||
event.server.runCommandSilent(`effect clear ${playerBoss} minecraft:glowing`);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue