Skip to content

Commit

Permalink
Initial beta release for 1.19, refactor a lot of stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Jun 4, 2022
1 parent 0a233d0 commit 338aa13
Show file tree
Hide file tree
Showing 60 changed files with 2,643 additions and 1,961 deletions.
1 change: 1 addition & 0 deletions .github/workflows/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ko_fi: Patbox
5 changes: 2 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
matrix:
# Use these Java versions
java: [
16 # Latest version
17 # Latest version
]
# and run on both Linux and Windows
os: [ubuntu-20.04, windows-latest]
os: [ubuntu-20.04]
runs-on: ${{ matrix.os }}
steps:
- name: checkout repository
Expand All @@ -32,7 +32,6 @@ jobs:
- name: build
run: ./gradlew build
- name: capture build artifacts
if: ${{ runner.os == 'Linux' && matrix.java == '16' }} # Only upload artifacts built from LTS java on one OS
uses: actions/upload-artifact@v2
with:
name: Artifacts
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 16
java-version: 17

- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand Down
12 changes: 5 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
plugins {
id 'fabric-loom' version '0.8-SNAPSHOT'
id 'fabric-loom' version '0.12-SNAPSHOT'
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

archivesBaseName = project.archives_base_name
version = project.mod_version
Expand Down Expand Up @@ -54,9 +54,7 @@ dependencies {
// Fabric API. This is technically optional, but you probably want it anyway.
//modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modCompileOnly("net.fabricmc.fabric-api:fabric-api:${project.fabric_version}")
modRuntime("net.fabricmc.fabric-api:fabric-api:${project.fabric_version}")

modRuntime "com.github.SuperCoder7979:databreaker:0.2.6"
modLocalRuntime("net.fabricmc.fabric-api:fabric-api:${project.fabric_version}")

// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
// You may need to force-disable transitiveness on them.
Expand All @@ -81,7 +79,7 @@ tasks.withType(JavaCompile).configureEach {
// The Minecraft launcher currently installs Java 8 for users, so your mod probably wants to target Java 8 too
// JDK 9 introduced a new way of specifying this that will make sure no newer classes or methods are used.
// We'll use that if it's available, but otherwise we'll use the older option.
it.options.release = 16
it.options.release = 17
}

java {
Expand Down
16 changes: 8 additions & 8 deletions docs/dev/adding-placeholders.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Adding placeholders
Creation of new placeholders is simple. You just need to import `eu.pb4.placeholders.PlaceholderAPI`
Creation of new placeholders is simple. You just need to import `eu.pb4.placeholders.api.Placeholders`
and call static `register` method. You only need to provide 2 arguments:

- Identifier with your mod id as namespace and path as argument name (with one additional limitation being not allowed to use `/` in it).
- A function (in form of lambda for example) that takes PlaceholderContext and returns PlaceholderResult,
- A function (in form of lambda for example) that takes PlaceholderContext and nullable string argument, returns PlaceholderResult,

Example
```
PlaceholderAPI.register(
Placeholders.register(
new Identifier("example", "placeholder"),
(ctx) -> PlaceholderResult.value(new LiteralText("Hello World!"))
(ctx, arg) -> PlaceholderResult.value(new LiteralText("Hello World!"))
);
```

Expand All @@ -19,7 +19,7 @@ It also includes few methods for checking if they are present.

Here is example for player only placeholder
```
PlaceholderAPI.register(new Identifier("player", "displayname"), (ctx) -> {
Placeholders.register(new Identifier("player", "displayname"), (ctx, arg) -> {
if (ctx.hasPlayer()) {
return PlaceholderResult.value(ctx.getPlayer().getDisplayName());
} else {
Expand All @@ -32,9 +32,9 @@ You can also add an argument to your placeholder, which removes requirement
of mostly repeated placeholders and allows degree of customisation.
Argument itself is a string, so you can parse it in any way.
```
PlaceholderAPI.register(new Identifier("server", "name_from_uuid"), (ctx) -> {
if (ctx.hasArgument()) {
return PlaceholderResult.value(ctx.getServer().getUserCache().getByUuid(UUID.fromString(ctx.getArgument())).get().getName()));
PlaceholderAPI.register(new Identifier("server", "name_from_uuid"), (ctx, arg) -> {
if (arg != null) {
return PlaceholderResult.value(ctx.server().getUserCache().getByUuid(UUID.fromString(arg)).get().getName()));
} else {
return PlaceholderResult.invalid("No argument!");
}
Expand Down
54 changes: 25 additions & 29 deletions docs/dev/parsing-placeholders.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,17 @@ So depending on your use case some of these will be more useful than others.

## Parsing global placeholders
Parsing global placeholders is really simple, as long as you have access to ServerPlayerEntity
or MinecraftServer object. You just need to simply import `eu.pb4.placeholders.PlaceholderAPI` and call
or MinecraftServer object. You just need to simply import `eu.pb4.placeholders.api.Placeholders` and call
`parseText`. This method will return fully parsed Text, which can be displayed to the user.

Example
```
// for ServerPlayerEntity
Text message = PlaceholderAPI.parseText(textInput, player);
// for Server
Text message2 = PlaceholderAPI.parseText(textInput, server);
Text message = Placeholders.parseText(textInput, PlaceholderContext.of(...));
```

Placeholders itself will use default formatting of `%category:placeholder%`.
If you want to use other formatting for them (which is recommended), you can use
`parseTextAlt(Text, ServerPlayerEntity or MinecraftServer)` for `{category:placeholder}`.
`parseText(Text, PlaceholderContext)` for `{category:placeholder}`.

## Parsing own/custom/predefined placeholders
If you want to parse your own placeholders, you can do this in 2 ways.
Expand All @@ -32,44 +28,44 @@ Example
```
ServerPlayerEntity player = something.getPlayer(); // MinecraftServer server = something.getServer()
Text inputText = new LiteralText("Hello! ${player}");
Map<String, Text> placeholders = Map.of("player", new LiteralText("You are a player!"));
Pattern pattern = PlaceholderAPI.PREDEFINED_PLACEHOLDER_PATTERN;
Text inputText = Text.literal("Hello! ${player}");
Map<String, Text> placeholders = Map.of("player", Text.literal("You are a player!"));
Pattern pattern = Placeholders.PREDEFINED_PLACEHOLDER_PATTERN;
Text output = PlaceholderAPI.parsePredefinedText(inputText, pattern, placeholders);
Text output = Placeholders.parseText(inputText, pattern, placeholders);
```

### Dynamic placeholders
In case where you want to parse placeholder with a context similar to global one, you need to
create a Map with `Identifier` (with `/` being disallowed) as a key and `PlaceholderHandler` as a value (same as adding global ones).
create a Map with `Identifier` as a key and `PlaceholderHandler` as a value (same as adding global ones).
You also will need a pattern object, which is the same as with static ones.

As opposite to global ones, you don't need to define namespace/category as it can default to minecraft one (for simpler user input).
Then you just parse it with `parseTextCustom(Text, ServerPlayerEntity or MinecraftServer, Map<String, PlaceholderHandler>, Pattern)`.
Then you just parse it with `parseText(Text, PlaceholderContext, Pattern, PlaceholderGetter)`.

Example
```
ServerPlayerEntity player = something.getPlayer(); // MinecraftServer server = something.getServer()
Text inputText = new LiteralText("Hello! ${player/blue}");
Map<Identifier, Text> placeholders = Map.of(new Identifier("player"),
(ctx) -> {
if (ctx.hasPlayer()) {
return PlaceholderResult.value(new LiteralText("You are a player!")
.setStyle(Style.EMPTY.withColor(TextColor.parse(ctx.getArgument()))));
} else {
return PlaceholderResult.value(new LiteralText("You are a server!")
.setStyle(Style.EMPTY.withColor(TextColor.parse(ctx.getArgument()))));
}
});
Pattern pattern = PlaceholderAPI.PREDEFINED_PLACEHOLDER_PATTERN;
Text output = PlaceholderAPI.parseTextCustom(inputText, player, pattern, placeholders);
// Text output = PlaceholderAPI.parseTextCustom(inputText, server, pattern, placeholders);
Text inputText = new Text.literal("Hello! ${player blue}");
PlaceholderGetter placeholders = (id) -> switch {
case "player" -> (ctx) -> {
if (ctx.hasPlayer()) {
return PlaceholderResult.value(Text.literal("You are a player!")
.setStyle(Style.EMPTY.withColor(TextColor.parse(ctx.getArgument()))));
} else {
return PlaceholderResult.value(Text.literal("You are a server!")
.setStyle(Style.EMPTY.withColor(TextColor.parse(ctx.getArgument()))));
}
});
}
Pattern pattern = Placeholders.PREDEFINED_PLACEHOLDER_PATTERN;
Text output = Placeholders.parseText(inputText, PlaceholderContext.of(player), pattern, placeholders);
```

### Preferred Patterns for static
PlaceholderAPI has few Patterns you can use, which are accessible as static objects on `PlaceholderAPI` class.
PlaceholderAPI has few Patterns you can use, which are accessible as static objects on `Placeholders` class.

* `PREDEFINED_PLACEHOLDER_PATTERN` (`${placeholder}`) - works the best in most cases, doesn't collide with other ones.
* `ALT_PLACEHOLDER_PATTERN_CUSTOM` (`{placeholder}`) - second best, but have more chance of colliding with user formatting.
Expand Down
23 changes: 5 additions & 18 deletions docs/dev/text-format.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
# Using Simplified Text Format/TextParser
[*You can read about format here!*](/user/text-format)

Usage of TextParser is simple and really customisable. You just need to import `eu.pb4.placeholders.TextParser`
and call static `parse` method for admin provided configs or `parseSafe` for player provided ones.
Usage of TextParser is simple and really customisable. You just need to import `eu.pb4.placeholders.api.TextParserUtils`
and call static `formatText` method for admin provided configs or `formatTextSafe` for player provided ones.
They both take only one String argument and output a Text object.

Example
```
String inputString = "<red>Hello <rb>World</rb>!"
Text output = TextParser.parse(inputString); // Text output = TextParser.parseSafe(inputString);
Text output = TextParserUtils.parseText(inputString);
```

## Parsing with only selected ones
If you want to only use selected tags, you can simply get map of all with `TextParser.getRegisteredTags()`
or `TextParser.getRegisteredSafeTags()`. Then you can copy these to your own Map with String keys
and `TextParser.TextFormatterHandler` values.
Then you just use them with `TextParser.parse(String, Map<String, TextFormatterHandler>)`.

Example
```
String inputString = "<red>Hello <blue>World</blue>!"
Map<String, TextParser.TextFormatterHandler> tags = Map.of("red", TextParser.getRegisteredTags().get("red"),
"blue", TextParser.getRegisteredTags().get("yellow") // renames works too!
);
Text output = TextParser.parse(inputString, tags);
```
If you want to only use selected tags, you can simply get map of all with `TextParserV1.DEFAULT.getTags()`.
Then you just use them with `TextParserUtils.parseText(String, TextParserV1.TagParserGetter)`.
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# About Placeholder API
It's a small, jij-able API that allows creation and parsing placeholders within strings and Minecraft Text Components.
Placeholders use simple format of `%modid:type%` or `%modid:type/data%`.
Placeholders use simple format of `%modid:type%` or `%modid:type data%` (`%modid:type/data%` before 1.19).
It also includes simple, general usage text format indented for simplifying user input in configs/chats/etc.

## For users
Expand Down
26 changes: 14 additions & 12 deletions docs/user/default-placeholders.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,32 @@ These placeholders are provided by default and are available for every mod using
If placeholder isn't parsed, make sure it is used in correct context, with valid arguments and
that you are using the latest version.

Before 1.19, arguments were split with `/` instead of space

## List of placeholders
### Server
- `%server:tps%` - server's tps
- `%server:tps_colored%` - colored server's tps
- `%server:mspt%` - server's mspt
- `%server:mspt_colored%` - colored server's mspt
- `%server:time%`/`%server:time/[formatting]%` - server's time
- `%server:time%`/`%server:time [formatting]%` - server's time
- `%server:version%` - server's version
- `%server:name%` - server's name
- `%server:used_ram%`/`%server:used_ram/gb%` - amount of ram used by server
- `%server:max_ram%`/`%server:max_ram/gb%` - maximal amount of ram, that can be used by server
- `%server:used_ram%`/`%server:used_ram gb%` - amount of ram used by server
- `%server:max_ram%`/`%server:max_ram gb%` - maximal amount of ram, that can be used by server
- `%server:online%` - number of online players
- `%server:max_players%` - maximal player count
- `%server:mod_version/[modid]%` - returns version of the mod
- `%server:mod_name/[modid]%` - returns name of the mod
- `%server:mod_description/[modid]%` - returns description of the mod
- `%server:mod_version [modid]%` - returns version of the mod
- `%server:mod_name [modid]%` - returns name of the mod
- `%server:mod_description [modid]%` - returns description of the mod

### World
- `%world:time%` - world's time
- `%world:time_alt%` - world's time (alternative formatting)
- `%world:day%` - world's day
- `%world:player_count%` - world's player count
- `%world:mob_count%`/`%world:mob_count/[group]%` - Shows amount of spawned mobs
- `%world:mob_cap%`/`%world:mob_cap/[group]%` - Shows maximum amount of mobs that can spawn is player's world
- `%world:mob_count%`/`%world:mob_count [group]%` - Shows amount of spawned mobs
- `%world:mob_cap%`/`%world:mob_cap [group]%` - Shows maximum amount of mobs that can spawn is player's world
- `%world:id%` - world's id
- `%world:name%` - world's name

Expand All @@ -46,10 +48,10 @@ that you are using the latest version.
- `%player:max_health%` - player's max health
- `%player:hunger%` - player's hunger
- `%player:saturation%` - player's saturation
- `%player:inventory_slot/[slot number]%` - item in player's inventory at slot
- `%player:equipment_slot/[name]%` - player's equipment at selected slot. Valid values for `[name]` are `mainhand`, `offhand`, `head`, `chest`, `legs` and `feet`
- `%player:playtime%`/`%player:playtime/[formatting]%` - player's playtime
- `%player:statistic/[statistic]%` - value of player's statistic
- `%player:inventory_slot [slot number]%` - item in player's inventory at slot
- `%player:equipment_slot [name]%` - player's equipment at selected slot. Valid values for `[name]` are `mainhand`, `offhand`, `head`, `chest`, `legs` and `feet`
- `%player:playtime%`/`%player:playtime [formatting]%` - player's playtime
- `%player:statistic [statistic]%` - value of player's statistic

Vanilla statistics:
```
Expand Down
4 changes: 2 additions & 2 deletions docs/user/general.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Usage of placeholder mostly depends on implementation of mod itself. If mod uses
(for example with Simple Text Format) you just need to add it by just writing `%placeholder%`
(or in some cases`{placeholder}`, `${placeholder}` or other format which should be provided on mods page).

Inner part of placeholder can take shape of either `category:placeholder` or `category:placeholder/argument`,
Inner part of placeholder can take shape of either `category:placeholder` or `category:placeholder argument` (`category:placeholder/argument` before 1.19),
where `category` is replaced by type (`player`, `world`, etc) or ID of the mod and `placeholder` is the placeholder itself.
Additionally, some placeholders might have additional or required argument provided after first `/` symbol. It's format
Additionally, some placeholders might have additional or required argument provided after first space. It's format
fully depend on mod providing it.

You can check list of [build in placeholders here](/users/default-placeholders)
Expand Down
Loading

0 comments on commit 338aa13

Please sign in to comment.