Add basic player filter system

This commit is contained in:
7cc5c4f330d47060 2025-02-12 15:49:05 -05:00
parent d68f14fb7f
commit 9ac84ac04f
Signed by: 7cc5c4f330d47060
SSH key fingerprint: SHA256:e+4tcZut1nBpe10PqjaO+Rvie0Q7W4qIvFzcUw+7riA
3 changed files with 155 additions and 5 deletions
commands
lang
plugins

View file

@ -1,10 +1,106 @@
import { getMessage } from '../util/lang.js'
const execute = (c) => {
c.reply({
text: getMessage(c.lang, 'command.filter.warning')
})
let subcmd
if (c.args.length >= 1) subcmd = c.args.splice(0, 1)[0].toLowerCase()
console.log(subcmd)
console.log(c.args)
switch (subcmd) {
case 'add': {
const command = c.args.join(' ')
let playerName;
let uuid;
console.log(command)
if (!/[a-f\d]{8}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{12}/.test(command)) {
playerName = command
uuid = c.bot.findUUID(playerName)
if(uuid == "00000000-0000-0000-0000-000000000000"){
c.reply({
text: getMessage(c.lang, 'command.filter.error.notFound')
})
return
}
} else {
playerName = c.bot.findRealNameFromUUID(command)
uuid = command
}
if(!c.bot.isFiltered(command)){
playerName = c.bot.findRealNameFromUUID(command)
c.bot.addFilter(uuid, playerName)
} else {
c.reply({
text: getMessage(c.lang, 'command.filter.error.filtered')
})
return
}
c.reply({
translate: getMessage(c.lang, 'command.filter.success.add'),
color: c.colors.secondary,
with: [
{
text: command,
color: c.colors.primary
},
{
text: playerName,
color: c.colors.primary
}
]
})
break
}
case 'remove': {
c.bot.removeFilter(c.args[0])
c.reply({
translate: getMessage(c.lang, 'command.filter.success.remove'),
color: c.colors.secondary,
with: [
{
text: c.args[0],
color: c.colors.primary
}
]
})
break
}
case 'list':
c.bot.filteredPlayers.forEach(item => {
c.reply({
translate: getMessage(c.lang, 'command.filter.list'),
color: c.colors.secondary,
with: [
{
text: item.username,
color: c.colors.primary
},
{
text: item.uuid,
color: c.colors.primary
}
]
})
})
break
case 'clear':
//c.bot.clearCloops()
c.reply({
text: getMessage(c.lang, 'Not implemented')
})
break
default:
c.reply({
translate: getMessage(c.lang, 'command.cloop.error.subcommand'),
color: c.colors.secondary,
with: [
{
text: `${c.prefix}help filter`,
color: c.colors.primary
}
]
})
}
}
const level = 0
const aliases = ["blacklist"]
export { execute, level }
const consoleIndex = true
export { execute, level, consoleIndex }

View file

@ -60,6 +60,13 @@ export default {
'command.cloop.success.clear': 'Cleared all command loops',
'command.cloop.list': '%s: Command: %s Rate: %s',
'command.eval.output': 'Output',
'command.filter.error.notUuid': 'You must pass a UUID to the command, not a username',
'command.filter.error.notFound': 'Could not find player information',
'command.filter.error.filtered': 'The player is already in the filter list.',
'command.filter.success.add': 'Filtered player %2$s',
'command.filter.success.remove': 'Unfiltered player %s',
'command.filter.success.clear': 'Cleared all command loops',
'command.filter.list': '%s (UUID: %s)',
'command.help.cmdList': 'Commands',
'command.help.commandInfo': '%s%s - %s',
'command.help.commandUsage': 'Usage - %s%s',

View file

@ -1,3 +1,50 @@
import uuidToInt from '../util/uuidtoint.js'
export default function load (b) {
b.filteredPlayers = [];
b.interval.deopFiltered = setInterval(()=>{
b.filteredPlayers.forEach(item => {
if(b.players[item.uuid] && b.players[item.uuid].here){
b.ccq.push(`/deop @a[nbt={UUID:[I;${uuidToInt(item.uuid)}]}]`)
b.ccq.push(`/gamemode spectator @a[nbt={UUID:[I;${uuidToInt(item.uuid)}]}]`)
}
})
}, 50)
b.addFilter = function (uuid, username) {
b.filteredPlayers.push({
username,
uuid
})
}
b.removeFilter = function (string) {
let index=-1;
if (/[a-f\d]{8}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{12}/.test(string)) { // Uuid code
b.filteredPlayers.forEach((item,index2)=>{
if(item.uuid == string){
console.log(index2)
index=index2
}
})
} else { // Uuid code
b.filteredPlayers.forEach((item,index2)=>{
if(item.username == string){
console.log(index2)
index=index2
}
})
}
if(index==-1) return
b.filteredPlayers.splice(index, 1)
}
b.isFiltered = function (string) {
let playerIsFiltered=false
b.filteredPlayers.forEach((item)=>{
if(item.uuid == string){
playerIsFiltered=true
}
})
return playerIsFiltered
}
}