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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
|
--- a/net/minecraft/server/bossevents/CustomBossEvent.java
+++ b/net/minecraft/server/bossevents/CustomBossEvent.java
@@ -17,6 +17,10 @@
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.Mth;
import net.minecraft.world.BossEvent;
+// CraftBukkit start
+import org.bukkit.boss.KeyedBossBar;
+import org.bukkit.craftbukkit.boss.CraftKeyedBossbar;
+// CraftBukkit end
public class CustomBossEvent extends ServerBossEvent {
@@ -24,10 +28,20 @@
private final Set<UUID> players = Sets.newHashSet();
private int value;
private int max = 100;
+ // CraftBukkit start
+ private KeyedBossBar bossBar;
- public CustomBossEvent(ResourceLocation resourcelocation, Component component) {
- super(component, BossEvent.BossBarColor.WHITE, BossEvent.BossBarOverlay.PROGRESS);
- this.id = resourcelocation;
+ public KeyedBossBar getBukkitEntity() {
+ if (bossBar == null) {
+ bossBar = new CraftKeyedBossbar(this);
+ }
+ return bossBar;
+ }
+ // CraftBukkit end
+
+ public CustomBossEvent(ResourceLocation id, Component name) {
+ super(name, BossEvent.BossBarColor.WHITE, BossEvent.BossBarOverlay.PROGRESS);
+ this.id = id;
this.setProgress(0.0F);
}
@@ -36,25 +50,22 @@
}
@Override
- @Override
- public void addPlayer(ServerPlayer serverplayer) {
- super.addPlayer(serverplayer);
- this.players.add(serverplayer.getUUID());
+ public void addPlayer(ServerPlayer player) {
+ super.addPlayer(player);
+ this.players.add(player.getUUID());
}
- public void addOfflinePlayer(UUID uuid) {
- this.players.add(uuid);
+ public void addOfflinePlayer(UUID player) {
+ this.players.add(player);
}
@Override
- @Override
- public void removePlayer(ServerPlayer serverplayer) {
- super.removePlayer(serverplayer);
- this.players.remove(serverplayer.getUUID());
+ public void removePlayer(ServerPlayer player) {
+ super.removePlayer(player);
+ this.players.remove(player.getUUID());
}
@Override
- @Override
public void removeAllPlayers() {
super.removeAllPlayers();
this.players.clear();
@@ -68,23 +79,23 @@
return this.max;
}
- public void setValue(int i) {
- this.value = i;
- this.setProgress(Mth.clamp((float) i / (float) this.max, 0.0F, 1.0F));
+ public void setValue(int value) {
+ this.value = value;
+ this.setProgress(Mth.clamp((float) value / (float) this.max, 0.0F, 1.0F));
}
- public void setMax(int i) {
- this.max = i;
- this.setProgress(Mth.clamp((float) this.value / (float) i, 0.0F, 1.0F));
+ public void setMax(int max) {
+ this.max = max;
+ this.setProgress(Mth.clamp((float) this.value / (float) max, 0.0F, 1.0F));
}
public final Component getDisplayName() {
- return ComponentUtils.wrapInSquareBrackets(this.getName()).withStyle((style) -> {
- return style.withColor(this.getColor().getFormatting()).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal(this.getTextId().toString()))).withInsertion(this.getTextId().toString());
+ return ComponentUtils.wrapInSquareBrackets(this.getName()).withStyle((chatmodifier) -> {
+ return chatmodifier.withColor(this.getColor().getFormatting()).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal(this.getTextId().toString()))).withInsertion(this.getTextId().toString());
});
}
- public boolean setPlayers(Collection<ServerPlayer> collection) {
+ public boolean setPlayers(Collection<ServerPlayer> serverPlayerList) {
Set<UUID> set = Sets.newHashSet();
Set<ServerPlayer> set1 = Sets.newHashSet();
Iterator iterator = this.players.iterator();
@@ -96,13 +107,13 @@
while (iterator.hasNext()) {
uuid = (UUID) iterator.next();
flag = false;
- iterator1 = collection.iterator();
+ iterator1 = serverPlayerList.iterator();
while (true) {
if (iterator1.hasNext()) {
- ServerPlayer serverplayer = (ServerPlayer) iterator1.next();
+ ServerPlayer entityplayer = (ServerPlayer) iterator1.next();
- if (!serverplayer.getUUID().equals(uuid)) {
+ if (!entityplayer.getUUID().equals(uuid)) {
continue;
}
@@ -116,12 +127,12 @@
}
}
- iterator = collection.iterator();
+ iterator = serverPlayerList.iterator();
- ServerPlayer serverplayer1;
+ ServerPlayer entityplayer1;
while (iterator.hasNext()) {
- serverplayer1 = (ServerPlayer) iterator.next();
+ entityplayer1 = (ServerPlayer) iterator.next();
flag = false;
iterator1 = this.players.iterator();
@@ -129,7 +140,7 @@
if (iterator1.hasNext()) {
UUID uuid1 = (UUID) iterator1.next();
- if (!serverplayer1.getUUID().equals(uuid1)) {
+ if (!entityplayer1.getUUID().equals(uuid1)) {
continue;
}
@@ -137,7 +148,7 @@
}
if (!flag) {
- set1.add(serverplayer1);
+ set1.add(entityplayer1);
}
break;
}
@@ -151,13 +162,13 @@
while (true) {
if (iterator2.hasNext()) {
- ServerPlayer serverplayer2 = (ServerPlayer) iterator2.next();
+ ServerPlayer entityplayer2 = (ServerPlayer) iterator2.next();
- if (!serverplayer2.getUUID().equals(uuid)) {
+ if (!entityplayer2.getUUID().equals(uuid)) {
continue;
}
- this.removePlayer(serverplayer2);
+ this.removePlayer(entityplayer2);
}
this.players.remove(uuid);
@@ -168,69 +179,69 @@
iterator = set1.iterator();
while (iterator.hasNext()) {
- serverplayer1 = (ServerPlayer) iterator.next();
- this.addPlayer(serverplayer1);
+ entityplayer1 = (ServerPlayer) iterator.next();
+ this.addPlayer(entityplayer1);
}
return !set.isEmpty() || !set1.isEmpty();
}
public CompoundTag save() {
- CompoundTag compoundtag = new CompoundTag();
+ CompoundTag nbttagcompound = new CompoundTag();
- compoundtag.putString("Name", Component.Serializer.toJson(this.name));
- compoundtag.putBoolean("Visible", this.isVisible());
- compoundtag.putInt("Value", this.value);
- compoundtag.putInt("Max", this.max);
- compoundtag.putString("Color", this.getColor().getName());
- compoundtag.putString("Overlay", this.getOverlay().getName());
- compoundtag.putBoolean("DarkenScreen", this.shouldDarkenScreen());
- compoundtag.putBoolean("PlayBossMusic", this.shouldPlayBossMusic());
- compoundtag.putBoolean("CreateWorldFog", this.shouldCreateWorldFog());
- ListTag listtag = new ListTag();
+ nbttagcompound.putString("Name", Component.Serializer.toJson(this.name));
+ nbttagcompound.putBoolean("Visible", this.isVisible());
+ nbttagcompound.putInt("Value", this.value);
+ nbttagcompound.putInt("Max", this.max);
+ nbttagcompound.putString("Color", this.getColor().getName());
+ nbttagcompound.putString("Overlay", this.getOverlay().getName());
+ nbttagcompound.putBoolean("DarkenScreen", this.shouldDarkenScreen());
+ nbttagcompound.putBoolean("PlayBossMusic", this.shouldPlayBossMusic());
+ nbttagcompound.putBoolean("CreateWorldFog", this.shouldCreateWorldFog());
+ ListTag nbttaglist = new ListTag();
Iterator iterator = this.players.iterator();
while (iterator.hasNext()) {
UUID uuid = (UUID) iterator.next();
- listtag.add(NbtUtils.createUUID(uuid));
+ nbttaglist.add(NbtUtils.createUUID(uuid));
}
- compoundtag.put("Players", listtag);
- return compoundtag;
+ nbttagcompound.put("Players", nbttaglist);
+ return nbttagcompound;
}
- public static CustomBossEvent load(CompoundTag compoundtag, ResourceLocation resourcelocation) {
- CustomBossEvent custombossevent = new CustomBossEvent(resourcelocation, Component.Serializer.fromJson(compoundtag.getString("Name")));
+ public static CustomBossEvent load(CompoundTag nbt, ResourceLocation id) {
+ CustomBossEvent bossbattlecustom = new CustomBossEvent(id, Component.Serializer.fromJson(nbt.getString("Name")));
- custombossevent.setVisible(compoundtag.getBoolean("Visible"));
- custombossevent.setValue(compoundtag.getInt("Value"));
- custombossevent.setMax(compoundtag.getInt("Max"));
- custombossevent.setColor(BossEvent.BossBarColor.byName(compoundtag.getString("Color")));
- custombossevent.setOverlay(BossEvent.BossBarOverlay.byName(compoundtag.getString("Overlay")));
- custombossevent.setDarkenScreen(compoundtag.getBoolean("DarkenScreen"));
- custombossevent.setPlayBossMusic(compoundtag.getBoolean("PlayBossMusic"));
- custombossevent.setCreateWorldFog(compoundtag.getBoolean("CreateWorldFog"));
- ListTag listtag = compoundtag.getList("Players", 11);
- Iterator iterator = listtag.iterator();
+ bossbattlecustom.setVisible(nbt.getBoolean("Visible"));
+ bossbattlecustom.setValue(nbt.getInt("Value"));
+ bossbattlecustom.setMax(nbt.getInt("Max"));
+ bossbattlecustom.setColor(BossEvent.BossBarColor.byName(nbt.getString("Color")));
+ bossbattlecustom.setOverlay(BossEvent.BossBarOverlay.byName(nbt.getString("Overlay")));
+ bossbattlecustom.setDarkenScreen(nbt.getBoolean("DarkenScreen"));
+ bossbattlecustom.setPlayBossMusic(nbt.getBoolean("PlayBossMusic"));
+ bossbattlecustom.setCreateWorldFog(nbt.getBoolean("CreateWorldFog"));
+ ListTag nbttaglist = nbt.getList("Players", 11);
+ Iterator iterator = nbttaglist.iterator();
while (iterator.hasNext()) {
- Tag tag = (Tag) iterator.next();
+ Tag nbtbase = (Tag) iterator.next();
- custombossevent.addOfflinePlayer(NbtUtils.loadUUID(tag));
+ bossbattlecustom.addOfflinePlayer(NbtUtils.loadUUID(nbtbase));
}
- return custombossevent;
+ return bossbattlecustom;
}
- public void onPlayerConnect(ServerPlayer serverplayer) {
- if (this.players.contains(serverplayer.getUUID())) {
- this.addPlayer(serverplayer);
+ public void onPlayerConnect(ServerPlayer player) {
+ if (this.players.contains(player.getUUID())) {
+ this.addPlayer(player);
}
}
- public void onPlayerDisconnect(ServerPlayer serverplayer) {
- super.removePlayer(serverplayer);
+ public void onPlayerDisconnect(ServerPlayer player) {
+ super.removePlayer(player);
}
}
|