mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-01 05:58:00 +01:00
Comments + advancement fix
This commit is contained in:
parent
b066e1b78f
commit
b339312222
@ -238,6 +238,13 @@ public class PlayerInit {
|
||||
tab.addViewer(player);
|
||||
|
||||
root.setTitle(ColoredText.of("test ttlechange"));
|
||||
|
||||
Advancement advancement2 = new Advancement(ColoredText.of("adv"), ColoredText.of("desc"),
|
||||
Material.GOLD_BLOCK, FrameType.CHALLENGE, 3, 0)
|
||||
.showToast(true).setHidden(false);
|
||||
tab.createAdvancement("second2", advancement2, root);
|
||||
|
||||
|
||||
//player.getPlayerConnection().sendPacket(tab.removePacket());
|
||||
}
|
||||
});
|
||||
|
@ -153,7 +153,40 @@ public class Advancement {
|
||||
}
|
||||
|
||||
/**
|
||||
* Update this advancement value when a field is modified
|
||||
* Get the packet used to add this advancement to the already existing tab
|
||||
*
|
||||
* @return the packet to add this advancement
|
||||
*/
|
||||
protected AdvancementsPacket getUpdatePacket() {
|
||||
AdvancementsPacket advancementsPacket = new AdvancementsPacket();
|
||||
advancementsPacket.resetAdvancements = false;
|
||||
|
||||
AdvancementsPacket.AdvancementMapping mapping = new AdvancementsPacket.AdvancementMapping();
|
||||
{
|
||||
AdvancementsPacket.Advancement adv = new AdvancementsPacket.Advancement();
|
||||
mapping.key = getIdentifier();
|
||||
mapping.value = adv;
|
||||
|
||||
final Advancement parent = getParent();
|
||||
if (parent != null) {
|
||||
final String parentIdentifier = parent.getIdentifier();
|
||||
adv.parentIdentifier = parentIdentifier;
|
||||
}
|
||||
|
||||
adv.displayData = toDisplayData();
|
||||
adv.criterions = new String[]{};
|
||||
adv.requirements = new AdvancementsPacket.Requirement[]{};
|
||||
}
|
||||
|
||||
advancementsPacket.identifiersToRemove = new String[]{};
|
||||
advancementsPacket.advancementMappings = new AdvancementsPacket.AdvancementMapping[]{mapping};
|
||||
advancementsPacket.progressMappings = new AdvancementsPacket.ProgressMapping[]{};
|
||||
|
||||
return advancementsPacket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send update to all tab viewers if one of the advancement value changes
|
||||
*/
|
||||
protected void update() {
|
||||
if (tab != null) {
|
||||
|
@ -31,10 +31,27 @@ public class AdvancementTab implements Viewable {
|
||||
this.removeBuffer = PacketUtils.writePacket(removePacket);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and add an advancement into this tab
|
||||
*
|
||||
* @param identifier the unique identifier
|
||||
* @param advancement the advancement to add
|
||||
* @param parent the parent of this advancement, it cannot be null
|
||||
*/
|
||||
public void createAdvancement(String identifier, Advancement advancement, Advancement parent) {
|
||||
Check.argCondition(identifier == null, "the advancement identifier cannot be null");
|
||||
Check.stateCondition(!advancementMap.containsKey(parent),
|
||||
"You tried to set a parent which doesn't exist or isn't registered");
|
||||
cacheAdvancement(identifier, advancement, parent);
|
||||
sendPacketToViewers(advancement.getUpdatePacket());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the packet buffer
|
||||
*/
|
||||
protected void updatePacket() {
|
||||
this.createBuffer = PacketUtils.writePacket(createPacket());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -75,6 +92,13 @@ public class AdvancementTab implements Viewable {
|
||||
return advancementsPacket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache an advancement
|
||||
*
|
||||
* @param identifier the identifier of the advancement
|
||||
* @param advancement the advancement
|
||||
* @param parent the parent of this advancement
|
||||
*/
|
||||
private void cacheAdvancement(String identifier, Advancement advancement, Advancement parent) {
|
||||
Check.stateCondition(advancement.getTab() != null,
|
||||
"You tried to add an advancement already linked to a tab");
|
||||
@ -82,6 +106,8 @@ public class AdvancementTab implements Viewable {
|
||||
advancement.setIdentifier(identifier);
|
||||
advancement.setParent(parent);
|
||||
this.advancementMap.put(advancement, parent);
|
||||
|
||||
updatePacket();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -94,7 +120,7 @@ public class AdvancementTab implements Viewable {
|
||||
final PlayerConnection playerConnection = player.getPlayerConnection();
|
||||
|
||||
// Send the tab to the player
|
||||
playerConnection.sendPacket(createPacket());
|
||||
playerConnection.sendPacket(createBuffer, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user