aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-spigotflower/net/minecraft/server/PlayerAdvancements.java.patch
blob: c5f25216e9cf966e849454121eecddb9a525706c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
--- a/net/minecraft/server/PlayerAdvancements.java
+++ b/net/minecraft/server/PlayerAdvancements.java
@@ -62,21 +62,21 @@
     @Nullable
     private AdvancementHolder lastSelectedTab;
     private boolean isFirstPacket = true;
-    private final Codec<PlayerAdvancements.Data> codec;
+    private final Codec<PlayerAdvancements.a> codec;
 
-    public PlayerAdvancements(DataFixer datafixer, PlayerList playerlist, ServerAdvancementManager serveradvancementmanager, Path path, ServerPlayer serverplayer) {
-        this.playerList = playerlist;
-        this.playerSavePath = path;
-        this.player = serverplayer;
-        this.tree = serveradvancementmanager.tree();
+    public PlayerAdvancements(DataFixer dataFixer, PlayerList playerList, ServerAdvancementManager manager, Path playerSavePath, ServerPlayer player) {
+        this.playerList = playerList;
+        this.playerSavePath = playerSavePath;
+        this.player = player;
+        this.tree = manager.tree();
         boolean flag = true;
 
-        this.codec = DataFixTypes.ADVANCEMENTS.wrapCodec(PlayerAdvancements.Data.CODEC, datafixer, 1343);
-        this.load(serveradvancementmanager);
+        this.codec = DataFixTypes.ADVANCEMENTS.wrapCodec(PlayerAdvancements.a.CODEC, dataFixer, 1343);
+        this.load(manager);
     }
 
-    public void setPlayer(ServerPlayer serverplayer) {
-        this.player = serverplayer;
+    public void setPlayer(ServerPlayer player) {
+        this.player = player;
     }
 
     public void stopListening() {
@@ -90,7 +90,7 @@
 
     }
 
-    public void reload(ServerAdvancementManager serveradvancementmanager) {
+    public void reload(ServerAdvancementManager manager) {
         this.stopListening();
         this.progress.clear();
         this.visible.clear();
@@ -98,12 +98,12 @@
         this.progressChanged.clear();
         this.isFirstPacket = true;
         this.lastSelectedTab = null;
-        this.tree = serveradvancementmanager.tree();
-        this.load(serveradvancementmanager);
+        this.tree = manager.tree();
+        this.load(manager);
     }
 
-    private void registerListeners(ServerAdvancementManager serveradvancementmanager) {
-        Iterator iterator = serveradvancementmanager.getAllAdvancements().iterator();
+    private void registerListeners(ServerAdvancementManager manager) {
+        Iterator iterator = manager.getAllAdvancements().iterator();
 
         while (iterator.hasNext()) {
             AdvancementHolder advancementholder = (AdvancementHolder) iterator.next();
@@ -113,8 +113,8 @@
 
     }
 
-    private void checkForAutomaticTriggers(ServerAdvancementManager serveradvancementmanager) {
-        Iterator iterator = serveradvancementmanager.getAllAdvancements().iterator();
+    private void checkForAutomaticTriggers(ServerAdvancementManager manager) {
+        Iterator iterator = manager.getAllAdvancements().iterator();
 
         while (iterator.hasNext()) {
             AdvancementHolder advancementholder = (AdvancementHolder) iterator.next();
@@ -128,7 +128,7 @@
 
     }
 
-    private void load(ServerAdvancementManager serveradvancementmanager) {
+    private void load(ServerAdvancementManager manager) {
         if (Files.isRegularFile(this.playerSavePath, new LinkOption[0])) {
             try {
                 JsonReader jsonreader = new JsonReader(Files.newBufferedReader(this.playerSavePath, StandardCharsets.UTF_8));
@@ -136,9 +136,9 @@
                 try {
                     jsonreader.setLenient(false);
                     JsonElement jsonelement = Streams.parse(jsonreader);
-                    PlayerAdvancements.Data playeradvancements_data = (PlayerAdvancements.Data) Util.getOrThrow(this.codec.parse(JsonOps.INSTANCE, jsonelement), JsonParseException::new);
+                    PlayerAdvancements.a advancementdataplayer_a = (PlayerAdvancements.a) Util.getOrThrow(this.codec.parse(JsonOps.INSTANCE, jsonelement), JsonParseException::new);
 
-                    this.applyFrom(serveradvancementmanager, playeradvancements_data);
+                    this.applyFrom(manager, advancementdataplayer_a);
                 } catch (Throwable throwable) {
                     try {
                         jsonreader.close();
@@ -157,8 +157,8 @@
             }
         }
 
-        this.checkForAutomaticTriggers(serveradvancementmanager);
-        this.registerListeners(serveradvancementmanager);
+        this.checkForAutomaticTriggers(manager);
+        this.registerListeners(manager);
     }
 
     public void save() {
@@ -191,12 +191,13 @@
 
     }
 
-    private void applyFrom(ServerAdvancementManager serveradvancementmanager, PlayerAdvancements.Data playeradvancements_data) {
-        playeradvancements_data.forEach((resourcelocation, advancementprogress) -> {
-            AdvancementHolder advancementholder = serveradvancementmanager.get(resourcelocation);
+    private void applyFrom(ServerAdvancementManager advancementdataworld, PlayerAdvancements.a advancementdataplayer_a) {
+        advancementdataplayer_a.forEach((minecraftkey, advancementprogress) -> {
+            AdvancementHolder advancementholder = advancementdataworld.get(minecraftkey);
 
             if (advancementholder == null) {
-                PlayerAdvancements.LOGGER.warn("Ignored advancement '{}' in progress file {} - it doesn't exist anymore?", resourcelocation, this.playerSavePath);
+                if (!minecraftkey.getNamespace().equals("minecraft")) return; // CraftBukkit
+                PlayerAdvancements.LOGGER.warn("Ignored advancement '{}' in progress file {} - it doesn't exist anymore?", minecraftkey, this.playerSavePath);
             } else {
                 this.startProgress(advancementholder, advancementprogress);
                 this.progressChanged.add(advancementholder);
@@ -205,7 +206,7 @@
         });
     }
 
-    private PlayerAdvancements.Data asData() {
+    private PlayerAdvancements.a asData() {
         Map<ResourceLocation, AdvancementProgress> map = new LinkedHashMap();
 
         this.progress.forEach((advancementholder, advancementprogress) -> {
@@ -214,7 +215,7 @@
             }
 
         });
-        return new PlayerAdvancements.Data(map);
+        return new PlayerAdvancements.a(map);
     }
 
     public boolean award(AdvancementHolder advancementholder, String s) {
@@ -227,10 +228,11 @@
             this.progressChanged.add(advancementholder);
             flag = true;
             if (!flag1 && advancementprogress.isDone()) {
+                this.player.level().getCraftServer().getPluginManager().callEvent(new org.bukkit.event.player.PlayerAdvancementDoneEvent(this.player.getBukkitEntity(), advancementholder.toBukkit())); // CraftBukkit
                 advancementholder.value().rewards().grant(this.player);
-                advancementholder.value().display().ifPresent((displayinfo) -> {
-                    if (displayinfo.shouldAnnounceChat() && this.player.level().getGameRules().getBoolean(GameRules.RULE_ANNOUNCE_ADVANCEMENTS)) {
-                        this.playerList.broadcastSystemMessage(displayinfo.getType().createAnnouncement(advancementholder, this.player), false);
+                advancementholder.value().display().ifPresent((advancementdisplay) -> {
+                    if (advancementdisplay.shouldAnnounceChat() && this.player.level().getGameRules().getBoolean(GameRules.RULE_ANNOUNCE_ADVANCEMENTS)) {
+                        this.playerList.broadcastSystemMessage(advancementdisplay.getType().createAnnouncement(advancementholder, this.player), false);
                     }
 
                 });
@@ -312,7 +314,7 @@
         criterion.trigger().removePlayerListener(this, new CriterionTrigger.Listener<>(criterion.triggerInstance(), advancementholder, s));
     }
 
-    public void flushDirty(ServerPlayer serverplayer) {
+    public void flushDirty(ServerPlayer serverPlayer) {
         if (this.isFirstPacket || !this.rootsToUpdate.isEmpty() || !this.progressChanged.isEmpty()) {
             Map<ResourceLocation, AdvancementProgress> map = new HashMap();
             Set<AdvancementHolder> set = new HashSet();
@@ -338,7 +340,7 @@
 
             this.progressChanged.clear();
             if (!map.isEmpty() || !set.isEmpty() || !set1.isEmpty()) {
-                serverplayer.connection.send(new ClientboundUpdateAdvancementsPacket(this.isFirstPacket, set, set1, map));
+                serverPlayer.connection.send(new ClientboundUpdateAdvancementsPacket(this.isFirstPacket, set, set1, map));
             }
         }
 
@@ -396,9 +398,9 @@
         });
     }
 
-    private static record Data(Map<ResourceLocation, AdvancementProgress> map) {
+    private static record a(Map<ResourceLocation, AdvancementProgress> map) {
 
-        public static final Codec<PlayerAdvancements.Data> CODEC = Codec.unboundedMap(ResourceLocation.CODEC, AdvancementProgress.CODEC).xmap(PlayerAdvancements.Data::new, PlayerAdvancements.Data::map);
+        public static final Codec<PlayerAdvancements.a> CODEC = Codec.unboundedMap(ResourceLocation.CODEC, AdvancementProgress.CODEC).xmap(PlayerAdvancements.a::new, PlayerAdvancements.a::map);
 
         public void forEach(BiConsumer<ResourceLocation, AdvancementProgress> biconsumer) {
             this.map.entrySet().stream().sorted(Entry.comparingByValue()).forEach((entry) -> {