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.network.packet.server.play.AdvancementsPacket;
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@ -39,8 +41,8 @@ public class Advancement {
|
||||
// Packet
|
||||
private AdvancementsPacket.Criteria criteria;
|
||||
|
||||
public Advancement(ColoredText title, ColoredText description,
|
||||
ItemStack icon, FrameType frameType,
|
||||
public Advancement(@NotNull ColoredText title, ColoredText description,
|
||||
@NotNull ItemStack icon, @NotNull FrameType frameType,
|
||||
float x, float y) {
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
@ -50,8 +52,8 @@ public class Advancement {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public Advancement(ColoredText title, ColoredText description,
|
||||
Material icon, FrameType frameType,
|
||||
public Advancement(@NotNull ColoredText title, @NotNull ColoredText description,
|
||||
@NotNull Material icon, @NotNull FrameType frameType,
|
||||
float x, float 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.
|
||||
*
|
||||
* @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() {
|
||||
return tab;
|
||||
}
|
||||
|
||||
protected void setTab(AdvancementTab tab) {
|
||||
protected void setTab(@NotNull AdvancementTab tab) {
|
||||
this.tab = tab;
|
||||
}
|
||||
|
||||
@ -95,6 +98,7 @@ public class Advancement {
|
||||
*
|
||||
* @return the advancement title
|
||||
*/
|
||||
@NotNull
|
||||
public ColoredText getTitle() {
|
||||
return title;
|
||||
}
|
||||
@ -104,7 +108,7 @@ public class Advancement {
|
||||
*
|
||||
* @param title the new title
|
||||
*/
|
||||
public void setTitle(ColoredText title) {
|
||||
public void setTitle(@NotNull ColoredText title) {
|
||||
this.title = title;
|
||||
update();
|
||||
}
|
||||
@ -114,6 +118,7 @@ public class Advancement {
|
||||
*
|
||||
* @return the description title
|
||||
*/
|
||||
@NotNull
|
||||
public ColoredText getDescription() {
|
||||
return description;
|
||||
}
|
||||
@ -123,7 +128,7 @@ public class Advancement {
|
||||
*
|
||||
* @param description the new description
|
||||
*/
|
||||
public void setDescription(ColoredText description) {
|
||||
public void setDescription(@NotNull ColoredText description) {
|
||||
this.description = description;
|
||||
update();
|
||||
}
|
||||
@ -133,6 +138,7 @@ public class Advancement {
|
||||
*
|
||||
* @return the advancement icon
|
||||
*/
|
||||
@NotNull
|
||||
public ItemStack getIcon() {
|
||||
return icon;
|
||||
}
|
||||
@ -142,7 +148,7 @@ public class Advancement {
|
||||
*
|
||||
* @param icon the new advancement icon
|
||||
*/
|
||||
public void setIcon(ItemStack icon) {
|
||||
public void setIcon(@NotNull ItemStack icon) {
|
||||
this.icon = icon;
|
||||
update();
|
||||
}
|
||||
@ -182,6 +188,7 @@ public class Advancement {
|
||||
*
|
||||
* @return this advancement frame type
|
||||
*/
|
||||
@NotNull
|
||||
public FrameType getFrameType() {
|
||||
return frameType;
|
||||
}
|
||||
@ -271,6 +278,7 @@ public class Advancement {
|
||||
*
|
||||
* @return the advancement parent, null for {@link AdvancementRoot}
|
||||
*/
|
||||
@Nullable
|
||||
protected Advancement getParent() {
|
||||
return parent;
|
||||
}
|
||||
@ -279,6 +287,7 @@ public class Advancement {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected AdvancementsPacket.ProgressMapping toProgressMapping() {
|
||||
AdvancementsPacket.ProgressMapping progressMapping = new AdvancementsPacket.ProgressMapping();
|
||||
{
|
||||
@ -291,6 +300,7 @@ public class Advancement {
|
||||
return progressMapping;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected AdvancementsPacket.DisplayData toDisplayData() {
|
||||
AdvancementsPacket.DisplayData displayData = new AdvancementsPacket.DisplayData();
|
||||
displayData.x = x;
|
||||
@ -311,6 +321,7 @@ public class Advancement {
|
||||
*
|
||||
* @return the mapping of this advancement
|
||||
*/
|
||||
@NotNull
|
||||
protected AdvancementsPacket.AdvancementMapping toMapping() {
|
||||
AdvancementsPacket.AdvancementMapping mapping = new AdvancementsPacket.AdvancementMapping();
|
||||
{
|
||||
|
@ -1,6 +1,8 @@
|
||||
package net.minestom.server.advancements;
|
||||
|
||||
import net.minestom.server.utils.validate.Check;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
@ -13,6 +15,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
*/
|
||||
public class AdvancementManager {
|
||||
|
||||
// root identifier TO its advancement tab
|
||||
private final Map<String, AdvancementTab> advancementTabMap = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
@ -23,7 +26,8 @@ public class AdvancementManager {
|
||||
* @return the newly created {@link AdvancementTab}
|
||||
* @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),
|
||||
"A tab with the identifier '" + rootIdentifier + "' already exists");
|
||||
final AdvancementTab advancementTab = new AdvancementTab(rootIdentifier, root);
|
||||
@ -37,7 +41,8 @@ public class AdvancementManager {
|
||||
* @param rootIdentifier the root identifier of the tab
|
||||
* @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);
|
||||
}
|
||||
|
||||
@ -46,6 +51,7 @@ public class AdvancementManager {
|
||||
*
|
||||
* @return the collection containing all created {@link AdvancementTab}
|
||||
*/
|
||||
@NotNull
|
||||
public Collection<AdvancementTab> getTabs() {
|
||||
return advancementTabMap.values();
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ public class BossBar implements Viewable {
|
||||
* @param color the boss bar color
|
||||
* @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.color = color;
|
||||
this.division = division;
|
||||
@ -96,6 +96,7 @@ public class BossBar implements Viewable {
|
||||
*
|
||||
* @return the current title of the bossbar
|
||||
*/
|
||||
@NotNull
|
||||
public ColoredText getTitle() {
|
||||
return title;
|
||||
}
|
||||
@ -105,7 +106,7 @@ public class BossBar implements Viewable {
|
||||
*
|
||||
* @param title the new title of the bossbar
|
||||
*/
|
||||
public void setTitle(ColoredText title) {
|
||||
public void setTitle(@NotNull ColoredText title) {
|
||||
this.title = title;
|
||||
updateTitle();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user