mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-06 07:21:32 +01:00
Annotations for the advancement API
This commit is contained in:
parent
826533e5ee
commit
247a328a09
@ -6,6 +6,8 @@ import net.minestom.server.item.ItemStack;
|
|||||||
import net.minestom.server.item.Material;
|
import net.minestom.server.item.Material;
|
||||||
import net.minestom.server.network.packet.server.play.AdvancementsPacket;
|
import net.minestom.server.network.packet.server.play.AdvancementsPacket;
|
||||||
import net.minestom.server.network.player.PlayerConnection;
|
import net.minestom.server.network.player.PlayerConnection;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@ -39,8 +41,8 @@ public class Advancement {
|
|||||||
// Packet
|
// Packet
|
||||||
private AdvancementsPacket.Criteria criteria;
|
private AdvancementsPacket.Criteria criteria;
|
||||||
|
|
||||||
public Advancement(ColoredText title, ColoredText description,
|
public Advancement(@NotNull ColoredText title, ColoredText description,
|
||||||
ItemStack icon, FrameType frameType,
|
@NotNull ItemStack icon, @NotNull FrameType frameType,
|
||||||
float x, float y) {
|
float x, float y) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
@ -50,8 +52,8 @@ public class Advancement {
|
|||||||
this.y = y;
|
this.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Advancement(ColoredText title, ColoredText description,
|
public Advancement(@NotNull ColoredText title, @NotNull ColoredText description,
|
||||||
Material icon, FrameType frameType,
|
@NotNull Material icon, @NotNull FrameType frameType,
|
||||||
float x, float y) {
|
float x, float y) {
|
||||||
this(title, description, new ItemStack(icon, (byte) 1), frameType, x, y);
|
this(title, description, new ItemStack(icon, (byte) 1), frameType, x, y);
|
||||||
}
|
}
|
||||||
@ -80,13 +82,14 @@ public class Advancement {
|
|||||||
/**
|
/**
|
||||||
* Gets the advancement tab linked to this advancement.
|
* Gets the advancement tab linked to this advancement.
|
||||||
*
|
*
|
||||||
* @return the {@link AdvancementTab} linked to this advancement
|
* @return the {@link AdvancementTab} linked to this advancement, null if not linked to anything yet
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public AdvancementTab getTab() {
|
public AdvancementTab getTab() {
|
||||||
return tab;
|
return tab;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setTab(AdvancementTab tab) {
|
protected void setTab(@NotNull AdvancementTab tab) {
|
||||||
this.tab = tab;
|
this.tab = tab;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,6 +98,7 @@ public class Advancement {
|
|||||||
*
|
*
|
||||||
* @return the advancement title
|
* @return the advancement title
|
||||||
*/
|
*/
|
||||||
|
@NotNull
|
||||||
public ColoredText getTitle() {
|
public ColoredText getTitle() {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
@ -104,7 +108,7 @@ public class Advancement {
|
|||||||
*
|
*
|
||||||
* @param title the new title
|
* @param title the new title
|
||||||
*/
|
*/
|
||||||
public void setTitle(ColoredText title) {
|
public void setTitle(@NotNull ColoredText title) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
@ -114,6 +118,7 @@ public class Advancement {
|
|||||||
*
|
*
|
||||||
* @return the description title
|
* @return the description title
|
||||||
*/
|
*/
|
||||||
|
@NotNull
|
||||||
public ColoredText getDescription() {
|
public ColoredText getDescription() {
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
@ -123,7 +128,7 @@ public class Advancement {
|
|||||||
*
|
*
|
||||||
* @param description the new description
|
* @param description the new description
|
||||||
*/
|
*/
|
||||||
public void setDescription(ColoredText description) {
|
public void setDescription(@NotNull ColoredText description) {
|
||||||
this.description = description;
|
this.description = description;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
@ -133,6 +138,7 @@ public class Advancement {
|
|||||||
*
|
*
|
||||||
* @return the advancement icon
|
* @return the advancement icon
|
||||||
*/
|
*/
|
||||||
|
@NotNull
|
||||||
public ItemStack getIcon() {
|
public ItemStack getIcon() {
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
@ -142,7 +148,7 @@ public class Advancement {
|
|||||||
*
|
*
|
||||||
* @param icon the new advancement icon
|
* @param icon the new advancement icon
|
||||||
*/
|
*/
|
||||||
public void setIcon(ItemStack icon) {
|
public void setIcon(@NotNull ItemStack icon) {
|
||||||
this.icon = icon;
|
this.icon = icon;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
@ -182,6 +188,7 @@ public class Advancement {
|
|||||||
*
|
*
|
||||||
* @return this advancement frame type
|
* @return this advancement frame type
|
||||||
*/
|
*/
|
||||||
|
@NotNull
|
||||||
public FrameType getFrameType() {
|
public FrameType getFrameType() {
|
||||||
return frameType;
|
return frameType;
|
||||||
}
|
}
|
||||||
@ -271,6 +278,7 @@ public class Advancement {
|
|||||||
*
|
*
|
||||||
* @return the advancement parent, null for {@link AdvancementRoot}
|
* @return the advancement parent, null for {@link AdvancementRoot}
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
protected Advancement getParent() {
|
protected Advancement getParent() {
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
@ -279,6 +287,7 @@ public class Advancement {
|
|||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
protected AdvancementsPacket.ProgressMapping toProgressMapping() {
|
protected AdvancementsPacket.ProgressMapping toProgressMapping() {
|
||||||
AdvancementsPacket.ProgressMapping progressMapping = new AdvancementsPacket.ProgressMapping();
|
AdvancementsPacket.ProgressMapping progressMapping = new AdvancementsPacket.ProgressMapping();
|
||||||
{
|
{
|
||||||
@ -291,6 +300,7 @@ public class Advancement {
|
|||||||
return progressMapping;
|
return progressMapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
protected AdvancementsPacket.DisplayData toDisplayData() {
|
protected AdvancementsPacket.DisplayData toDisplayData() {
|
||||||
AdvancementsPacket.DisplayData displayData = new AdvancementsPacket.DisplayData();
|
AdvancementsPacket.DisplayData displayData = new AdvancementsPacket.DisplayData();
|
||||||
displayData.x = x;
|
displayData.x = x;
|
||||||
@ -311,6 +321,7 @@ public class Advancement {
|
|||||||
*
|
*
|
||||||
* @return the mapping of this advancement
|
* @return the mapping of this advancement
|
||||||
*/
|
*/
|
||||||
|
@NotNull
|
||||||
protected AdvancementsPacket.AdvancementMapping toMapping() {
|
protected AdvancementsPacket.AdvancementMapping toMapping() {
|
||||||
AdvancementsPacket.AdvancementMapping mapping = new AdvancementsPacket.AdvancementMapping();
|
AdvancementsPacket.AdvancementMapping mapping = new AdvancementsPacket.AdvancementMapping();
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package net.minestom.server.advancements;
|
package net.minestom.server.advancements;
|
||||||
|
|
||||||
import net.minestom.server.utils.validate.Check;
|
import net.minestom.server.utils.validate.Check;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -13,6 +15,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
*/
|
*/
|
||||||
public class AdvancementManager {
|
public class AdvancementManager {
|
||||||
|
|
||||||
|
// root identifier TO its advancement tab
|
||||||
private final Map<String, AdvancementTab> advancementTabMap = new ConcurrentHashMap<>();
|
private final Map<String, AdvancementTab> advancementTabMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,7 +26,8 @@ public class AdvancementManager {
|
|||||||
* @return the newly created {@link AdvancementTab}
|
* @return the newly created {@link AdvancementTab}
|
||||||
* @throws IllegalStateException if a tab with the identifier {@code rootIdentifier} already exists
|
* @throws IllegalStateException if a tab with the identifier {@code rootIdentifier} already exists
|
||||||
*/
|
*/
|
||||||
public AdvancementTab createTab(String rootIdentifier, AdvancementRoot root) {
|
@NotNull
|
||||||
|
public AdvancementTab createTab(@NotNull String rootIdentifier, @NotNull AdvancementRoot root) {
|
||||||
Check.stateCondition(advancementTabMap.containsKey(rootIdentifier),
|
Check.stateCondition(advancementTabMap.containsKey(rootIdentifier),
|
||||||
"A tab with the identifier '" + rootIdentifier + "' already exists");
|
"A tab with the identifier '" + rootIdentifier + "' already exists");
|
||||||
final AdvancementTab advancementTab = new AdvancementTab(rootIdentifier, root);
|
final AdvancementTab advancementTab = new AdvancementTab(rootIdentifier, root);
|
||||||
@ -37,7 +41,8 @@ public class AdvancementManager {
|
|||||||
* @param rootIdentifier the root identifier of the tab
|
* @param rootIdentifier the root identifier of the tab
|
||||||
* @return the {@link AdvancementTab} associated with the identifier, null if not any
|
* @return the {@link AdvancementTab} associated with the identifier, null if not any
|
||||||
*/
|
*/
|
||||||
public AdvancementTab getTab(String rootIdentifier) {
|
@Nullable
|
||||||
|
public AdvancementTab getTab(@NotNull String rootIdentifier) {
|
||||||
return advancementTabMap.get(rootIdentifier);
|
return advancementTabMap.get(rootIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,6 +51,7 @@ public class AdvancementManager {
|
|||||||
*
|
*
|
||||||
* @return the collection containing all created {@link AdvancementTab}
|
* @return the collection containing all created {@link AdvancementTab}
|
||||||
*/
|
*/
|
||||||
|
@NotNull
|
||||||
public Collection<AdvancementTab> getTabs() {
|
public Collection<AdvancementTab> getTabs() {
|
||||||
return advancementTabMap.values();
|
return advancementTabMap.values();
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ public class BossBar implements Viewable {
|
|||||||
* @param color the boss bar color
|
* @param color the boss bar color
|
||||||
* @param division the boss bar division
|
* @param division the boss bar division
|
||||||
*/
|
*/
|
||||||
public BossBar(ColoredText title, @NotNull BarColor color, @NotNull BarDivision division) {
|
public BossBar(@NotNull ColoredText title, @NotNull BarColor color, @NotNull BarDivision division) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
this.division = division;
|
this.division = division;
|
||||||
@ -96,6 +96,7 @@ public class BossBar implements Viewable {
|
|||||||
*
|
*
|
||||||
* @return the current title of the bossbar
|
* @return the current title of the bossbar
|
||||||
*/
|
*/
|
||||||
|
@NotNull
|
||||||
public ColoredText getTitle() {
|
public ColoredText getTitle() {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
@ -105,7 +106,7 @@ public class BossBar implements Viewable {
|
|||||||
*
|
*
|
||||||
* @param title the new title of the bossbar
|
* @param title the new title of the bossbar
|
||||||
*/
|
*/
|
||||||
public void setTitle(ColoredText title) {
|
public void setTitle(@NotNull ColoredText title) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
updateTitle();
|
updateTitle();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user