Skip to content

Commit

Permalink
v8.7.0
Browse files Browse the repository at this point in the history
XMaterial
Fixed YELLOW_GLAZED_TERRACOTTA, SILVER_GLAZED_TERRACOTTA, END_STONE_BRICK_STAIRS and a lot slabs for outdated servers.
Fixed potion / splash potion checks in 1.8.8

XEntity
Added support for two illager methods. Patrol leader and join raid.
All options that represent a color are named to "color" and all options that represent a variant/type are renamed to variant.
All the "type" options are now renamed to "variant"

XItemStack
They now support editing itemstacks rather than constructing them from scratch.
The "glow" option will now automatically enable HIDE_ENCHANTS flag.
Removed \n single line support for lore. If you genuinely want to break line just use a simple list. There's no reason to use \n instead.
It no longer translates colors automatically. It'll use the passed function translator instead.

ActionBar
Added a format for configuring ActionBar time from the message string itself. Note that you need to use the new method (which is just plugin,player,string) for this to work.

ReflectionUtils
Fixed a version detection error in 1.13
  • Loading branch information
CryptoMorin committed Mar 8, 2022
1 parent a9324ac commit 3646858
Show file tree
Hide file tree
Showing 6 changed files with 246 additions and 132 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.cryptomorin</groupId>
<artifactId>XSeries</artifactId>
<version>8.6.2</version>
<version>8.7.0</version>

<name>XSeries</name>
<description>A set of utilities for Minecraft plugins</description>
Expand Down Expand Up @@ -63,7 +63,7 @@

<properties>
<!-- Latest version -->
<spigotVersion>1.18.1-R0.1-SNAPSHOT</spigotVersion>
<spigotVersion>1.18.2-R0.1-SNAPSHOT</spigotVersion>
</properties>

<dependencies>
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/cryptomorin/xseries/ReflectionUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,16 @@ public final class ReflectionUtils {
String found = null;
for (Package pack : Package.getPackages()) {
String name = pack.getName();
if (name.startsWith("org.bukkit.craftbukkit.v") // .v because there are other packages.
// As a protection for forge+bukkit implementation that tend to mix versions.
// The real CraftPlayer should exist in the package.
// Note: Doesn't seem to function properly. Will need to separate the version
// handler for NMS and CraftBukkit for softwares like catmc.
&& name.endsWith("entity")) {

// .v because there are other packages.
if (name.startsWith("org.bukkit.craftbukkit.v")) {
found = pack.getName().split("\\.")[3];

// Just a final guard to make sure it finds this important class.
// As a protection for forge+bukkit implementation that tend to mix versions.
// The real CraftPlayer should exist in the package.
// Note: Doesn't seem to function properly. Will need to separate the version
// handler for NMS and CraftBukkit for softwares like catmc.
try {
Class.forName("org.bukkit.craftbukkit." + found + ".entity.CraftPlayer");
break;
Expand Down
152 changes: 84 additions & 68 deletions src/main/java/com/cryptomorin/xseries/XEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public static Entity edit(@Nonnull Entity entity, @Nonnull ConfigurationSection
if (sheared) sheep.setSheared(true);
} else if (living instanceof Rabbit) {
Rabbit rabbit = (Rabbit) living;
rabbit.setRabbitType(Enums.getIfPresent(Rabbit.Type.class, config.getString("rabbit-type")).or(Rabbit.Type.WHITE));
rabbit.setRabbitType(Enums.getIfPresent(Rabbit.Type.class, config.getString("color")).or(Rabbit.Type.WHITE));
} else if (living instanceof Bat) {
Bat bat = (Bat) living;
if (!config.getBoolean("awake")) bat.setAwake(false);
Expand All @@ -340,73 +340,23 @@ public static Entity edit(@Nonnull Entity entity, @Nonnull ConfigurationSection
} else if (XMaterial.supports(12)) {
if (living instanceof Parrot) {
Parrot parrot = (Parrot) living;
parrot.setVariant(Enums.getIfPresent(Parrot.Variant.class, config.getString("variant")).or(Parrot.Variant.RED));
} else if (XMaterial.supports(13)) {
if (living instanceof Husk) {
Husk husk = (Husk) living;
husk.setConversionTime(config.getInt("conversion-time"));
} else if (living instanceof Vex) {
Vex vex = (Vex) living;
vex.setCharging(config.getBoolean("charging"));
} else if (living instanceof PufferFish) {
PufferFish pufferFish = (PufferFish) living;
pufferFish.setPuffState(config.getInt("puff-state"));
} else if (living instanceof TropicalFish) {
TropicalFish tropicalFish = (TropicalFish) living;
tropicalFish.setBodyColor(Enums.getIfPresent(DyeColor.class, config.getString("color")).or(DyeColor.WHITE));
tropicalFish.setPattern(Enums.getIfPresent(TropicalFish.Pattern.class, config.getString("pattern")).or(TropicalFish.Pattern.BETTY));
tropicalFish.setPatternColor(Enums.getIfPresent(DyeColor.class, config.getString("pattern-color")).or(DyeColor.WHITE));
} else if (living instanceof EnderDragon) {
EnderDragon dragon = (EnderDragon) living;
dragon.setPhase(Enums.getIfPresent(EnderDragon.Phase.class, config.getString("phase")).or(EnderDragon.Phase.ROAR_BEFORE_ATTACK));
} else if (living instanceof Phantom) {
Phantom phantom = (Phantom) living;
phantom.setSize(config.getInt("size"));
} else if (XMaterial.supports(14)) {
if (living instanceof Cat) {
Cat cat = (Cat) living;
cat.setCatType(Enums.getIfPresent(Cat.Type.class, config.getString("cat-type")).or(Cat.Type.TABBY));
cat.setCollarColor(Enums.getIfPresent(DyeColor.class, config.getString("color")).or(DyeColor.GREEN));
} else if (living instanceof Fox) {
Fox fox = (Fox) living;
fox.setCrouching(config.getBoolean("crouching"));
fox.setSleeping(config.getBoolean("sleeping"));
fox.setFoxType(Enums.getIfPresent(Fox.Type.class, config.getString("type")).or(Fox.Type.RED));
} else if (living instanceof Panda) {
Panda panda = (Panda) living;
panda.setHiddenGene(Enums.getIfPresent(Panda.Gene.class, config.getString("hidden-gene")).or(Panda.Gene.PLAYFUL));
panda.setMainGene(Enums.getIfPresent(Panda.Gene.class, config.getString("main-gene")).or(Panda.Gene.NORMAL));
} else if (living instanceof MushroomCow) {
MushroomCow mooshroom = (MushroomCow) living;
mooshroom.setVariant(Enums.getIfPresent(MushroomCow.Variant.class, config.getString("variant")).or(MushroomCow.Variant.RED));
} else if (XMaterial.supports(15)) {
if (living instanceof Bee) {
Bee bee = (Bee) living;
// Anger time ticks.
bee.setAnger(config.getInt("anger") * 20);
bee.setHasNectar(config.getBoolean("nectar"));
bee.setHasStung(config.getBoolean("stung"));
bee.setCannotEnterHiveTicks(config.getInt("disallow-hive") * 20);
} else if (XMaterial.supports(16)) {
if (living instanceof Hoglin) {
Hoglin hoglin = (Hoglin) living;
hoglin.setConversionTime(config.getInt("conversation") * 20);
hoglin.setImmuneToZombification(config.getBoolean("zombification-immunity"));
hoglin.setIsAbleToBeHunted(config.getBoolean("can-be-hunted"));
} else if (living instanceof Piglin) {
// Idk why Spigot did this...
Piglin piglin = (Piglin) living;
piglin.setConversionTime(config.getInt("conversation") * 20);
piglin.setImmuneToZombification(config.getBoolean("zombification-immunity"));
} else if (living instanceof Strider) {
Strider strider = (Strider) living;
strider.setShivering(config.getBoolean("shivering"));
}

if (XMaterial.supports(17)) handleSeventeen(entity, config);
}
}
parrot.setVariant(Enums.getIfPresent(Parrot.Variant.class, config.getString("color")).or(Parrot.Variant.RED));
}

if (XMaterial.supports(13)) thirteen(entity, config);
if (XMaterial.supports(14)) fourteen(entity, config);
if (XMaterial.supports(15)) {
if (living instanceof Bee) {
Bee bee = (Bee) living;
// Anger time ticks.
bee.setAnger(config.getInt("anger") * 20);
bee.setHasNectar(config.getBoolean("nectar"));
bee.setHasStung(config.getBoolean("stung"));
bee.setCannotEnterHiveTicks(config.getInt("disallow-hive") * 20);
}

if (XMaterial.supports(16)) sixteen(entity, config);
if (XMaterial.supports(17)) seventeen(entity, config);
}
}
}
Expand All @@ -429,10 +379,76 @@ public static Entity edit(@Nonnull Entity entity, @Nonnull ConfigurationSection
return entity;
}

private static void fourteen(Entity entity, ConfigurationSection config) {
if (entity instanceof Raider) {
// Illagers were added in 1.11 but the concept of raids and patrols were added in 1.14
Raider raider = (Raider) entity;
if (config.isSet("can-join-raid")) raider.setCanJoinRaid(config.getBoolean("can-join-raid"));
if (config.isSet("is-patrol-leader")) raider.setCanJoinRaid(config.getBoolean("is-patrol-leader"));
} else if (entity instanceof Cat) {
Cat cat = (Cat) entity;
cat.setCatType(Enums.getIfPresent(Cat.Type.class, config.getString("variant")).or(Cat.Type.TABBY));
cat.setCollarColor(Enums.getIfPresent(DyeColor.class, config.getString("color")).or(DyeColor.GREEN));
} else if (entity instanceof Fox) {
Fox fox = (Fox) entity;
fox.setCrouching(config.getBoolean("crouching"));
fox.setSleeping(config.getBoolean("sleeping"));
fox.setFoxType(Enums.getIfPresent(Fox.Type.class, config.getString("color")).or(Fox.Type.RED));
} else if (entity instanceof Panda) {
Panda panda = (Panda) entity;
panda.setHiddenGene(Enums.getIfPresent(Panda.Gene.class, config.getString("hidden-gene")).or(Panda.Gene.PLAYFUL));
panda.setMainGene(Enums.getIfPresent(Panda.Gene.class, config.getString("main-gene")).or(Panda.Gene.NORMAL));
} else if (entity instanceof MushroomCow) {
MushroomCow mooshroom = (MushroomCow) entity;
mooshroom.setVariant(Enums.getIfPresent(MushroomCow.Variant.class, config.getString("color")).or(MushroomCow.Variant.RED));
}
}

private static void thirteen(Entity entity, ConfigurationSection config) {
if (entity instanceof Husk) {
Husk husk = (Husk) entity;
husk.setConversionTime(config.getInt("conversion-time"));
} else if (entity instanceof Vex) {
Vex vex = (Vex) entity;
vex.setCharging(config.getBoolean("charging"));
} else if (entity instanceof PufferFish) {
PufferFish pufferFish = (PufferFish) entity;
pufferFish.setPuffState(config.getInt("puff-state"));
} else if (entity instanceof TropicalFish) {
TropicalFish tropicalFish = (TropicalFish) entity;
tropicalFish.setBodyColor(Enums.getIfPresent(DyeColor.class, config.getString("color")).or(DyeColor.WHITE));
tropicalFish.setPattern(Enums.getIfPresent(TropicalFish.Pattern.class, config.getString("pattern")).or(TropicalFish.Pattern.BETTY));
tropicalFish.setPatternColor(Enums.getIfPresent(DyeColor.class, config.getString("pattern-color")).or(DyeColor.WHITE));
} else if (entity instanceof EnderDragon) {
EnderDragon dragon = (EnderDragon) entity;
dragon.setPhase(Enums.getIfPresent(EnderDragon.Phase.class, config.getString("phase")).or(EnderDragon.Phase.ROAR_BEFORE_ATTACK));
} else if (entity instanceof Phantom) {
Phantom phantom = (Phantom) entity;
phantom.setSize(config.getInt("size"));
}
}

private static void sixteen(Entity entity, ConfigurationSection config) {
if (entity instanceof Hoglin) {
Hoglin hoglin = (Hoglin) entity;
hoglin.setConversionTime(config.getInt("conversation") * 20);
hoglin.setImmuneToZombification(config.getBoolean("zombification-immunity"));
hoglin.setIsAbleToBeHunted(config.getBoolean("can-be-hunted"));
} else if (entity instanceof Piglin) {
// Idk why Spigot did this...
Piglin piglin = (Piglin) entity;
piglin.setConversionTime(config.getInt("conversation") * 20);
piglin.setImmuneToZombification(config.getBoolean("zombification-immunity"));
} else if (entity instanceof Strider) {
Strider strider = (Strider) entity;
strider.setShivering(config.getBoolean("shivering"));
}
}

/**
* AXOLOTL - GLOW_ITEM_FRAME - GLOW_SQUID - GOAT - MARKER
*/
private static boolean handleSeventeen(Entity entity, ConfigurationSection config) {
private static boolean seventeen(Entity entity, ConfigurationSection config) {
if (entity instanceof Axolotl) {
Axolotl axolotl = (Axolotl) entity;
String variantStr = config.getString("variant");
Expand Down
Loading

0 comments on commit 3646858

Please sign in to comment.