Skip to content

Commit e419ef8

Browse files
committed
Improve support for 1.8.8
1 parent e11f3d6 commit e419ef8

File tree

6 files changed

+48
-15
lines changed

6 files changed

+48
-15
lines changed

Item Creator/src/main/java/org/broken/arrow/library/itemcreator/meta/BottleEffectMeta.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.broken.arrow.library.itemcreator.meta;
22

3+
import org.broken.arrow.library.itemcreator.ItemCreator;
34
import org.broken.arrow.library.itemcreator.meta.potion.PotionTypeWrapper;
45
import org.broken.arrow.library.itemcreator.meta.potion.PotionModifier;
56
import org.broken.arrow.library.itemcreator.meta.potion.PotionsUtility;
@@ -224,6 +225,7 @@ public void setExtended(boolean extended) {
224225
*
225226
* @return the color set.
226227
*/
228+
@Nullable
227229
public ColorMeta getColorMeta() {
228230
return colorMeta;
229231
}
@@ -252,7 +254,7 @@ public void applyBottleEffects(@Nonnull final ItemMeta itemMeta) {
252254

253255
if (effects != null && !effects.isEmpty()) {
254256
final ColorMeta colorEffect = this.colorMeta;
255-
if (colorEffect != null && colorEffect.isColorSet()) {
257+
if (ItemCreator.getServerVersion() > 10.2F && colorEffect != null && colorEffect.isColorSet()) {
256258
potionMeta.setColor(colorEffect.getColor());
257259
}
258260
effects.forEach((portionEffect) -> potionMeta.addCustomEffect(portionEffect, this.override));
@@ -305,7 +307,10 @@ public static class PotionEffectWrapper {
305307
* @return Returns this class for chaining.
306308
*/
307309
public PotionEffectWrapper add(@Nonnull PotionEffectType type, final int duration, final int amplifier, final boolean ambient, final boolean particles, final boolean icon) {
308-
portionEffects.add(new PotionEffect(type, duration, amplifier, ambient, particles, icon));
310+
if (ItemCreator.getServerVersion() < 13.0F)
311+
portionEffects.add(new PotionEffect(type, duration, amplifier, ambient, particles));
312+
else
313+
portionEffects.add(new PotionEffect(type, duration, amplifier, ambient, particles, icon));
309314
return this;
310315
}
311316

Item Creator/src/main/java/org/broken/arrow/library/itemcreator/meta/ColorMeta.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public void setRgb(final int red, final int green, final int blue) {
167167
*/
168168
public void setRgb(final int alpha, final int red, final int green, final int blue) {
169169
Validate.checkBoolean(alpha < 0 || red < 0 || green < 0 || blue < 0, "You can't use negative numbers for the arbg color.");
170-
final Color colorArg = Color.fromARGB(alpha, red, green, blue);
170+
final Color colorArg = Color.fromRGB( red, green, blue); //Color.fromARGB(alpha, red, green, blue);
171171
this.setColor(colorArg);
172172
}
173173

Item Creator/src/main/java/org/broken/arrow/library/itemcreator/meta/map/BuildMapView.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ public class BuildMapView {
5050
public BuildMapView(@Nonnull final World world) {
5151
this.mapView = Bukkit.createMap(world);
5252
this.virtual = mapView.isVirtual();
53-
this.mapId = mapView.getId();
53+
try {
54+
this.mapId = mapView.getId();
55+
} catch (NoSuchMethodError e) {
56+
e.printStackTrace();
57+
}
5458
this.world = mapView.getWorld();
5559
}
5660

@@ -168,7 +172,7 @@ public List<MapRenderer> getRenderers() {
168172
* Adds a map renderer with the specified renderer and applies configuration
169173
* via the given data consumer.
170174
*
171-
* @param renderer the {@link MapRenderer} instance to add
175+
* @param renderer the {@link MapRenderer} instance to add
172176
* @param dataConsumer a consumer to configure the render data for this renderer
173177
* @return the {@link MapRendererData} instance representing the added renderer
174178
*/
@@ -285,18 +289,29 @@ public MapView build() {
285289
mapView.setCenterX(x);
286290
mapView.setCenterZ(z);
287291
mapView.setScale(scale);
288-
mapView.setTrackingPosition(trackingPosition);
289-
mapView.setUnlimitedTracking(unlimited);
292+
try {
293+
mapView.setTrackingPosition(trackingPosition);
294+
} catch (NoSuchMethodError e) {
295+
e.printStackTrace();
296+
}
297+
try {
298+
mapView.setUnlimitedTracking(unlimited);
299+
} catch (NoSuchMethodError e) {
300+
e.printStackTrace();
301+
}
302+
try {
290303
mapView.setLocked(locked);
291-
304+
} catch (NoSuchMethodError e) {
305+
e.printStackTrace();
306+
}
292307
for (MapRenderer renderer : mapView.getRenderers()) {
293308
mapView.removeRenderer(renderer);
294309
}
295310

296311
// Add renderers from your data
297312
if (!renderers.isEmpty()) {
298313
for (MapRendererData data : renderers) {
299-
mapView.addRenderer(data.getMapRenderer());
314+
mapView.addRenderer(data.getMapRenderer());
300315
}
301316
}
302317
return mapView;

Item Creator/src/main/java/org/broken/arrow/library/itemcreator/meta/potion/PotionTypeWrapper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ public static PotionTypeWrapper findPotionByType(final PotionType bukkitPotionTy
263263
*/
264264
@Nullable
265265
public static PotionTypeWrapper findPotionByName(final String name) {
266+
if (name == null) return null;
267+
266268
String bukkitPortion = name.toUpperCase();
267269
PotionTypeWrapper potionTypeWrapper = POTION_TYPE_NAME.get(bukkitPortion);
268270
if (potionTypeWrapper != null)
@@ -290,7 +292,7 @@ public static PotionTypeWrapper findPotionByName(final String name) {
290292
* @return the corresponding {@link PotionType}, or {@code null} if not found.
291293
*/
292294
@Nullable
293-
public static PotionType findPotionTypeByName(String bukkitPotionType) {
295+
public static PotionType findPotionTypeByName(final String bukkitPotionType) {
294296
String bukkitPotion = bukkitPotionType.toUpperCase();
295297
PotionTypeWrapper potionByName = findPotionByName(bukkitPotion);
296298
if (potionByName != null)

Item Creator/src/main/java/org/broken/arrow/library/itemcreator/serialization/itemstack/SerializeItem.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,17 @@ private static void retrievePotionMeta(final ItemMeta meta, final SerializeItem
421421
data.potionEffects = new BottleEffectMeta();
422422
if (potionMeta.hasCustomEffects())
423423
potionMeta.getCustomEffects().forEach(data.potionEffects::addPotionEffects);
424-
if (potionMeta.hasColor())
424+
425+
if (ItemCreator.getServerVersion() < 9.0F)
426+
return;
427+
428+
if (ItemCreator.getServerVersion() > 10.2F && potionMeta.hasColor())
425429
data.potionEffects.setBottleColor(colorMeta -> colorMeta.setRgb(potionMeta.getColor()));
426-
data.potionEffects.setPotionData(PotionTypeWrapper.findPotionByType(potionMeta.getBasePotionType()));
430+
431+
if (ItemCreator.getServerVersion() < 13.0F)
432+
data.potionEffects.setPotionData(PotionTypeWrapper.findPotionByType(potionMeta.getBasePotionData().getType()));
433+
else
434+
data.potionEffects.setPotionData(PotionTypeWrapper.findPotionByType(potionMeta.getBasePotionType()));
427435
}
428436
}
429437

Item Creator/src/main/java/org/broken/arrow/library/itemcreator/serialization/typeadapter/BottleEffectMetaAdapter.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.google.gson.TypeAdapter;
44
import com.google.gson.stream.JsonReader;
55
import com.google.gson.stream.JsonWriter;
6+
import org.broken.arrow.library.itemcreator.ItemCreator;
67
import org.broken.arrow.library.itemcreator.meta.BottleEffectMeta;
78
import org.broken.arrow.library.itemcreator.serialization.jsonhelper.JsonReaderHelper;
89
import org.broken.arrow.library.itemcreator.serialization.jsonhelper.JsonWriterHelper;
@@ -42,14 +43,15 @@ public void write(final JsonWriter out, final BottleEffectMeta value) throws IOE
4243
json.value("is_water_bottle", value.isWaterBottle());
4344
json.value("is_upgraded", value.isUpgraded());
4445
json.value("is_extended", value.isExtended());
45-
json.value("color", value.getColorMeta().toRgb());
46+
json.value("color", value.getColorMeta() == null ? 0 : value.getColorMeta().toRgb());
4647
json.forEachObject("potion_effects", value.getPotionEffects(), potionEffect -> {
4748
json.value("type", potionEffect.getType().getName());
4849
json.value("duration", potionEffect.getDuration());
4950
json.value("amplifier", potionEffect.getAmplifier());
5051
json.value("is_ambient", potionEffect.isAmbient());
5152
json.value("has_particles", potionEffect.hasParticles());
52-
json.value("has_icon", potionEffect.hasIcon());
53+
if(ItemCreator.getServerVersion() > 12.2F)
54+
json.value("has_icon", potionEffect.hasIcon());
5355
});
5456
json.finish();
5557
}
@@ -87,7 +89,8 @@ public BottleEffectMeta read(final JsonReader in) throws IOException {
8789
break;
8890
case "color":
8991
final int color = reader.nextInt();
90-
meta.setBottleColor(colorMeta -> colorMeta.setRgb(color));
92+
if (color > 0)
93+
meta.setBottleColor(colorMeta -> colorMeta.setRgb(color));
9194
break;
9295
case "potion_effects":
9396
setPotionEffects(reader, meta);

0 commit comments

Comments
 (0)