Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ConfiguredProperty for documenting "magic" values consistently #293

Merged
merged 8 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,22 @@ for older versions. This is done by using yarn's docusaurus version command:
yarn docusaurus docs:version:paper "1.20"
```

## Magic Value Handling

When writing documentation, it is important to avoid using "magic values" in the documentation. This may be slightly less
obscure than in code, but it is still important to avoid using them. For example, these values may end up being used in
multiple places, and if they change, it is important to change them in all places. This is why it is important to use
our ConfiguredProperty component to embed these values into the documentation. An example of this would be:

```jsx
<ConfiguredProperty propertyKey="RECOMMENDED_PAPER_JAVA" />
```

This will embed the value of the property into the documentation, and if it changes, it will be changed in all places.

These values are stored in the `config-spec/properties/properties.json` file. If you need to add a new property, you can
add it to this file, and it will be available to use in the documentation.

## Code of Conduct

Contributors are expected to follow the [Community Guidelines](https://papermc.io/community/guidelines) of the PaperMC organization in all
Expand Down
4 changes: 4 additions & 0 deletions config-specs/properties/properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"MIN_VELOCITY_JAVA": "17",
"RECOMMENDED_PAPER_JAVA": "21"
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ description: How to get started with downloading and setting up a Paper server.

:::tip

With the release of Minecraft 1.18, Paper now requires **Java 17** to run. We recommend using **Java 21**, which [is easy to download and install](/misc/java-install).
With the release of Minecraft 1.18, Paper now requires **Java 17** to run. We recommend using
**Java <ConfiguredProperty propertyKey="RECOMMENDED_PAPER_JAVA" />**, which [is easy to download and install](/misc/java-install).

:::

| Paper Version | Recommended Java Version |
olijeffers0n marked this conversation as resolved.
Show resolved Hide resolved
|----------------|--------------------------|
| 1.8 to 1.11 | Java 8 |
| 1.12 to 1.16.4 | Java 11 |
| 1.16.5 | Java 16 |
| 1.17.1-1.18.1+ | Java 21 |
| Paper Version | Recommended Java Version |
|----------------|------------------------------------------------------------------|
| 1.8 to 1.11 | Java 8 |
| 1.12 to 1.16.4 | Java 11 |
| 1.16.5 | Java 16 |
| 1.17.1-1.18.1+ | Java <ConfiguredProperty propertyKey="RECOMMENDED_PAPER_JAVA" /> |

## Downloading Paper

Expand Down
4 changes: 2 additions & 2 deletions docs/velocity/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Velocity is the ridiculously scalable, flexible Minecraft proxy.
## Getting started

It is simple to get started with Velocity. Get started with our
[Getting Started guide](admin/getting-started/README.md).
[Getting Started guide](admin/getting-started/README.mdx).

## I need help

Expand All @@ -19,7 +19,7 @@ We have put a lot of effort into documenting Velocity as much as possible with o
our coverage will continue to expand. We strongly encourage you to check the sidebar of the docs for
relevant resources. Helping yourself using the resources in these docs saves all of us time.

We recommend you visit the [frequently-asked questions](admin/getting-started/faq.md) to begin your
We recommend you visit the [frequently-asked questions](admin/getting-started/faq.mdx) to begin your
search. Most common issues with Velocity are answered there.

Please do not be offended if we respond to your question linking back here. Asking us a question
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This page covers how to install and set up a minimal configuration of Velocity.
## Installing Java

Velocity is written in Java, so if you do not already have Java installed, you will need to install
it before you continue. Velocity requires Java 17 or newer. See our
it before you continue. Velocity requires Java <ConfiguredProperty propertyKey="MIN_VELOCITY_JAVA" /> or newer. See our
[java installation guide](/misc/java-install) for detailed instructions.

## Downloading Velocity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ many of these questions from the user perspective.

## What version of Java does Velocity require?

Velocity 3.3.x requires Java 17 or above.
Velocity 3.3.x requires Java <ConfiguredProperty propertyKey="MIN_VELOCITY_JAVA" /> or above.

## Where can I find Velocity plugins?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ IDEA is recommended.
- Open your IDE
- Click `Create New Project` or the equivalent
- Select either `Gradle` or `Maven`
- Make sure your **Project JDK** is Java 11 or later
- Make sure your **Project JDK** is Java <ConfiguredProperty propertyKey="MIN_VELOCITY_JAVA" /> or later
- **Finish** the dialog and open the project.

Now we have created our project, we need configure our build system.
Expand Down Expand Up @@ -174,7 +174,7 @@ You will be asked to provide some information about your project.
| **Group ID** | The group ID of your project. This is used for Maven and Gradle. This is usually your domain name in reverse. If you don't know what you should put here, you can use something like `io.github.<yourname>` or if you don't have GitHub you can just use `me.<yourname>`. |
| **Artifact ID** | The artifact ID of your project. This is used for Maven and Gradle. This is usually the name of your project. This is usually the same as the `Name` field. |
| **Version** | The version of your project. This is used for Maven and Gradle. This is usually `1.0-SNAPSHOT` and does not really matter for now. |
| **JDK** | The JDK you want to use. This can be anything from Java 11 and above. |
| **JDK** | The JDK you want to use. This can be anything from Java <ConfiguredProperty propertyKey="MIN_VELOCITY_JAVA" /> and above. |

Now you can click on the `Create` button and IntelliJ will create the project for you.
If everything went well, you should see something like this:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ document very carefully**.

## Minimum supported Java version bump

Velocity 3.3.x now requires Java 17 and above.
Velocity 3.3.x now requires Java <ConfiguredProperty propertyKey="MIN_VELOCITY_JAVA" /> and above.

## Removal of legacy dependencies

Expand Down
20 changes: 20 additions & 0 deletions src/components/ConfiguredProperty.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import configuredProperties from '@site/config-specs/properties/properties.json';

const CONFIGURED_PROPERTY_NAMES = Object.keys(configuredProperties);

export function isConfiguredProperty(propertyKey: string): boolean {
olijeffers0n marked this conversation as resolved.
Show resolved Hide resolved
return CONFIGURED_PROPERTY_NAMES.includes(propertyKey);
}

export function getConfiguredProperty(propertyKey: string): string {
olijeffers0n marked this conversation as resolved.
Show resolved Hide resolved
return configuredProperties[propertyKey];
}

export default function ConfiguredProperty({ propertyKey }) {
olijeffers0n marked this conversation as resolved.
Show resolved Hide resolved

if (!isConfiguredProperty(propertyKey)) {
return null;
}

return getConfiguredProperty(propertyKey);
}
12 changes: 7 additions & 5 deletions src/theme/MDXComponents.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import { Icon } from '@iconify/react';
import MDXComponents from '@theme-original/MDXComponents';
import TabItem from "@theme/TabItem";
import Tabs from "@theme/Tabs";
import VersionFormattedCode from '../components/VersionFormattedCode';
import SoftwareVersion from "../components/SoftwareVersion";
import VersionedJavaDocLink from "../components/VersionedJavaDocLink";
import TabItem from '@theme/TabItem';
import Tabs from '@theme/Tabs';
import VersionFormattedCode from '@site/src/components/VersionFormattedCode';
import SoftwareVersion from '@site/src/components/SoftwareVersion';
import VersionedJavaDocLink from '../components/VersionedJavaDocLink';
import ConfiguredProperty from '@site/src/components/ConfiguredProperty';

export default {
// Re-use the default mapping
Expand All @@ -16,5 +17,6 @@ export default {
VersionFormattedCode,
SoftwareVersion,
VersionedJavaDocLink,
ConfiguredProperty,
Icon: Icon,
};