This repository has been archived by the owner on Aug 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'parcel' of https://github.com/Levertion/mcfunction-lang…
…server into parcel
- Loading branch information
Showing
19 changed files
with
439 additions
and
184 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
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
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,79 @@ | ||
import { CommandErrorBuilder } from "../../brigadier/errors"; | ||
import { StringReader } from "../../brigadier/string-reader"; | ||
import { | ||
effects, | ||
enchantments, | ||
entities, | ||
particles | ||
} from "../../data/lists/statics"; | ||
import { | ||
convertToNamespace, | ||
parseNamespaceOption, | ||
ReturnHelper, | ||
stringifyNamespace | ||
} from "../../misc-functions"; | ||
import { ContextChange, Parser, ParserInfo, ReturnedInfo } from "../../types"; | ||
|
||
export class NamespaceListParser implements Parser { | ||
private readonly error: CommandErrorBuilder; | ||
private readonly options: string[]; | ||
public constructor(options: string[], errorBuilder: CommandErrorBuilder) { | ||
this.options = options; | ||
this.error = errorBuilder; | ||
} | ||
public parse( | ||
reader: StringReader, | ||
info: ParserInfo | ||
): ReturnedInfo<ContextChange> { | ||
const helper = new ReturnHelper(info); | ||
const start = reader.cursor; | ||
const result = parseNamespaceOption( | ||
reader, | ||
this.options.map((v, _) => convertToNamespace(v)) | ||
); | ||
if (helper.merge(result)) { | ||
return helper.succeed(); | ||
} else { | ||
if (result.data) { | ||
return helper | ||
.addErrors( | ||
this.error.create( | ||
start, | ||
reader.cursor, | ||
stringifyNamespace(result.data) | ||
) | ||
) | ||
.succeed(); | ||
} else { | ||
return helper.fail(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
const summonError = new CommandErrorBuilder( | ||
"entity.notFound", | ||
"Unknown entity: %s" | ||
); | ||
export const summonParser = new NamespaceListParser(entities, summonError); | ||
|
||
const enchantmentError = new CommandErrorBuilder( | ||
"enchantment.unknown", | ||
"Unknown enchantment: %s" | ||
); | ||
export const enchantmentParser = new NamespaceListParser( | ||
enchantments, | ||
enchantmentError | ||
); | ||
|
||
const mobEffectError = new CommandErrorBuilder( | ||
"effect.effectNotFound", | ||
"Unknown effect: %s" | ||
); | ||
export const mobEffectParser = new NamespaceListParser(effects, mobEffectError); | ||
|
||
const particleError = new CommandErrorBuilder( | ||
"particle.notFound", | ||
"Unknown particle: %s" | ||
); | ||
export const particleParser = new NamespaceListParser(particles, particleError); |
Oops, something went wrong.