generated from xpdustry/template-plugin
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(command-cloud): Added content type parsers
- Loading branch information
Showing
13 changed files
with
383 additions
and
1 deletion.
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
39 changes: 39 additions & 0 deletions
39
...loud/src/main/java/com/xpdustry/distributor/command/cloud/parser/content/BlockParser.java
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,39 @@ | ||
/* | ||
* Distributor, a feature-rich framework for Mindustry plugins. | ||
* | ||
* Copyright (C) 2024 Xpdustry | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package com.xpdustry.distributor.command.cloud.parser.content; | ||
|
||
import mindustry.ctype.ContentType; | ||
import mindustry.world.Block; | ||
import org.incendo.cloud.component.CommandComponent; | ||
import org.incendo.cloud.parser.ParserDescriptor; | ||
|
||
public final class BlockParser<C> extends ContentParser<C, Block> { | ||
|
||
public static <C> ParserDescriptor<C, Block> blockParser() { | ||
return ParserDescriptor.of(new BlockParser<>(), Block.class); | ||
} | ||
|
||
public static <C> CommandComponent.Builder<C, Block> blockComponent() { | ||
return CommandComponent.<C, Block>builder().parser(blockParser()); | ||
} | ||
|
||
public BlockParser() { | ||
super(ContentType.block); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
...ud/src/main/java/com/xpdustry/distributor/command/cloud/parser/content/ContentParser.java
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,82 @@ | ||
/* | ||
* Distributor, a feature-rich framework for Mindustry plugins. | ||
* | ||
* Copyright (C) 2024 Xpdustry | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package com.xpdustry.distributor.command.cloud.parser.content; | ||
|
||
import com.xpdustry.distributor.command.cloud.ArcCaptionKeys; | ||
import java.util.Locale; | ||
import mindustry.Vars; | ||
import mindustry.ctype.ContentType; | ||
import mindustry.ctype.MappableContent; | ||
import org.incendo.cloud.caption.CaptionVariable; | ||
import org.incendo.cloud.context.CommandContext; | ||
import org.incendo.cloud.context.CommandInput; | ||
import org.incendo.cloud.exception.parsing.ParserException; | ||
import org.incendo.cloud.parser.ArgumentParseResult; | ||
import org.incendo.cloud.parser.ArgumentParser; | ||
|
||
public sealed class ContentParser<C, T extends MappableContent> implements ArgumentParser<C, T> | ||
permits BlockParser, ItemParser, LiquidParser, PlanetParser, StatusParser, UnitParser, WeatherParser { | ||
|
||
private final ContentType contentType; | ||
|
||
ContentParser(final ContentType contentType) { | ||
this.contentType = contentType; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public ArgumentParseResult<T> parse(final CommandContext<C> ctx, final CommandInput input) { | ||
final var name = input.readString().toLowerCase(Locale.ROOT); | ||
final var content = Vars.content.getByName(contentType, name); | ||
return (content == null) | ||
? ArgumentParseResult.failure(new ContentParseException(this.getClass(), ctx, name, contentType)) | ||
: ArgumentParseResult.success((T) content); | ||
} | ||
|
||
@SuppressWarnings("serial") | ||
public static final class ContentParseException extends ParserException { | ||
|
||
private final String input; | ||
private final ContentType contentType; | ||
|
||
@SuppressWarnings("rawtypes") | ||
public ContentParseException( | ||
final Class<? extends ContentParser> clazz, | ||
final CommandContext<?> ctx, | ||
final String input, | ||
final ContentType contentType) { | ||
super( | ||
clazz, | ||
ctx, | ||
ArcCaptionKeys.ARGUMENT_PARSE_FAILURE_CONTENT, | ||
CaptionVariable.of("input", input), | ||
CaptionVariable.of("type", contentType.name())); | ||
this.input = input; | ||
this.contentType = contentType; | ||
} | ||
|
||
public String getInput() { | ||
return input; | ||
} | ||
|
||
public ContentType getContentType() { | ||
return contentType; | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...cloud/src/main/java/com/xpdustry/distributor/command/cloud/parser/content/ItemParser.java
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,39 @@ | ||
/* | ||
* Distributor, a feature-rich framework for Mindustry plugins. | ||
* | ||
* Copyright (C) 2024 Xpdustry | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package com.xpdustry.distributor.command.cloud.parser.content; | ||
|
||
import mindustry.ctype.ContentType; | ||
import mindustry.type.Item; | ||
import org.incendo.cloud.component.CommandComponent; | ||
import org.incendo.cloud.parser.ParserDescriptor; | ||
|
||
public final class ItemParser<C> extends ContentParser<C, Item> { | ||
|
||
public static <C> ParserDescriptor<C, Item> itemParser() { | ||
return ParserDescriptor.of(new ItemParser<>(), Item.class); | ||
} | ||
|
||
public static <C> CommandComponent.Builder<C, Item> itemComponent() { | ||
return CommandComponent.<C, Item>builder().parser(itemParser()); | ||
} | ||
|
||
public ItemParser() { | ||
super(ContentType.item); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...oud/src/main/java/com/xpdustry/distributor/command/cloud/parser/content/LiquidParser.java
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,39 @@ | ||
/* | ||
* Distributor, a feature-rich framework for Mindustry plugins. | ||
* | ||
* Copyright (C) 2024 Xpdustry | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package com.xpdustry.distributor.command.cloud.parser.content; | ||
|
||
import mindustry.ctype.ContentType; | ||
import mindustry.type.Liquid; | ||
import org.incendo.cloud.component.CommandComponent; | ||
import org.incendo.cloud.parser.ParserDescriptor; | ||
|
||
public final class LiquidParser<C> extends ContentParser<C, Liquid> { | ||
|
||
public static <C> ParserDescriptor<C, Liquid> liquidParser() { | ||
return ParserDescriptor.of(new LiquidParser<>(), Liquid.class); | ||
} | ||
|
||
public static <C> CommandComponent.Builder<C, Liquid> liquidComponent() { | ||
return CommandComponent.<C, Liquid>builder().parser(liquidParser()); | ||
} | ||
|
||
public LiquidParser() { | ||
super(ContentType.liquid); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...oud/src/main/java/com/xpdustry/distributor/command/cloud/parser/content/PlanetParser.java
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,39 @@ | ||
/* | ||
* Distributor, a feature-rich framework for Mindustry plugins. | ||
* | ||
* Copyright (C) 2024 Xpdustry | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package com.xpdustry.distributor.command.cloud.parser.content; | ||
|
||
import mindustry.ctype.ContentType; | ||
import mindustry.type.Planet; | ||
import org.incendo.cloud.component.CommandComponent; | ||
import org.incendo.cloud.parser.ParserDescriptor; | ||
|
||
public final class PlanetParser<C> extends ContentParser<C, Planet> { | ||
|
||
public static <C> ParserDescriptor<C, Planet> planetParser() { | ||
return ParserDescriptor.of(new PlanetParser<>(), Planet.class); | ||
} | ||
|
||
public static <C> CommandComponent.Builder<C, Planet> planetComponent() { | ||
return CommandComponent.<C, Planet>builder().parser(planetParser()); | ||
} | ||
|
||
public PlanetParser() { | ||
super(ContentType.planet); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...oud/src/main/java/com/xpdustry/distributor/command/cloud/parser/content/StatusParser.java
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,39 @@ | ||
/* | ||
* Distributor, a feature-rich framework for Mindustry plugins. | ||
* | ||
* Copyright (C) 2024 Xpdustry | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package com.xpdustry.distributor.command.cloud.parser.content; | ||
|
||
import mindustry.ctype.ContentType; | ||
import mindustry.type.StatusEffect; | ||
import org.incendo.cloud.component.CommandComponent; | ||
import org.incendo.cloud.parser.ParserDescriptor; | ||
|
||
public final class StatusParser<C> extends ContentParser<C, StatusEffect> { | ||
|
||
public static <C> ParserDescriptor<C, StatusEffect> statusParser() { | ||
return ParserDescriptor.of(new StatusParser<>(), StatusEffect.class); | ||
} | ||
|
||
public static <C> CommandComponent.Builder<C, StatusEffect> statusComponent() { | ||
return CommandComponent.<C, StatusEffect>builder().parser(statusParser()); | ||
} | ||
|
||
public StatusParser() { | ||
super(ContentType.status); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...cloud/src/main/java/com/xpdustry/distributor/command/cloud/parser/content/UnitParser.java
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,39 @@ | ||
/* | ||
* Distributor, a feature-rich framework for Mindustry plugins. | ||
* | ||
* Copyright (C) 2024 Xpdustry | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package com.xpdustry.distributor.command.cloud.parser.content; | ||
|
||
import mindustry.ctype.ContentType; | ||
import mindustry.type.UnitType; | ||
import org.incendo.cloud.component.CommandComponent; | ||
import org.incendo.cloud.parser.ParserDescriptor; | ||
|
||
public final class UnitParser<C> extends ContentParser<C, UnitType> { | ||
|
||
public static <C> ParserDescriptor<C, UnitType> unitParser() { | ||
return ParserDescriptor.of(new UnitParser<>(), UnitType.class); | ||
} | ||
|
||
public static <C> CommandComponent.Builder<C, UnitType> unitComponent() { | ||
return CommandComponent.<C, UnitType>builder().parser(unitParser()); | ||
} | ||
|
||
public UnitParser() { | ||
super(ContentType.unit); | ||
} | ||
} |
Oops, something went wrong.