mirror of
https://github.com/songoda/SongodaCore.git
synced 2025-01-10 17:57:41 +01:00
Adds 1.18 support and some unit tests (#30)
Merge pull request #30 from songoda/dev-without-breaking-changes
This commit is contained in:
commit
41d6df6205
2
.github/workflows/maven.yml
vendored
2
.github/workflows/maven.yml
vendored
@ -17,7 +17,7 @@ jobs:
|
||||
# Setup Java
|
||||
- uses: actions/setup-java@v2
|
||||
with:
|
||||
java-version: 16
|
||||
java-version: 17
|
||||
distribution: adopt
|
||||
|
||||
# Checkout project files
|
||||
|
2
.github/workflows/sonarcloud.yml
vendored
2
.github/workflows/sonarcloud.yml
vendored
@ -14,7 +14,7 @@ jobs:
|
||||
# Setup Java
|
||||
- uses: actions/setup-java@v2
|
||||
with:
|
||||
java-version: 16
|
||||
java-version: 17
|
||||
distribution: adopt
|
||||
|
||||
# Checkout project files
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.5.14</version>
|
||||
<version>2.6.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -18,7 +18,8 @@
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.17-R0.1-SNAPSHOT</version>
|
||||
<version>1.18-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -1419,6 +1419,7 @@ public enum CompatibleMaterial {
|
||||
if (usesCompatibility()) {
|
||||
return compatibleMaterial.getItem();
|
||||
}
|
||||
|
||||
return data != null ? new ItemStack(material, amount, data) : new ItemStack(material);
|
||||
}
|
||||
|
||||
@ -1470,7 +1471,7 @@ public enum CompatibleMaterial {
|
||||
* @return LegacyMaterial or null if none found
|
||||
*/
|
||||
public static CompatibleMaterial getMaterial(String name) {
|
||||
return name == null ? null : lookupMap.get(name.toUpperCase());
|
||||
return getMaterial(name, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1495,18 +1496,22 @@ public enum CompatibleMaterial {
|
||||
* @return LegacyMaterial or null if none found
|
||||
*/
|
||||
public static CompatibleMaterial getMaterial(Material mat) {
|
||||
if (mat == null)
|
||||
if (mat == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (useLegacy) {
|
||||
CompatibleMaterial compatibleMaterial = lookupMap.get(mat.name() + ":0");
|
||||
if (compatibleMaterial != null)
|
||||
if (compatibleMaterial != null) {
|
||||
return compatibleMaterial;
|
||||
}
|
||||
}
|
||||
|
||||
return lookupMap.get(mat.name());
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup a Material by Itemstack.
|
||||
* Lookup a Material by ItemStack.
|
||||
*
|
||||
* @param item item to lookup
|
||||
*
|
||||
@ -1802,6 +1807,7 @@ public enum CompatibleMaterial {
|
||||
switch (this) {
|
||||
case STRING:
|
||||
return true;
|
||||
|
||||
case ACACIA_DOOR:
|
||||
case BIRCH_DOOR:
|
||||
case DARK_OAK_DOOR:
|
||||
@ -1853,6 +1859,7 @@ public enum CompatibleMaterial {
|
||||
case CAKE:
|
||||
case COMPARATOR:
|
||||
return usesLegacy();
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@ -1881,7 +1888,14 @@ public enum CompatibleMaterial {
|
||||
|
||||
/**
|
||||
* Check if the material is a block and does not block any light
|
||||
*
|
||||
* @return True if this material is a block and does not block any light
|
||||
*
|
||||
* @see Material#isTransparent()
|
||||
* @deprecated currently does not have an implementation which is well
|
||||
* linked to the underlying server. Contributions welcome.
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isTransparent() {
|
||||
return material != null && material.isTransparent();
|
||||
}
|
||||
@ -1920,6 +1934,7 @@ public enum CompatibleMaterial {
|
||||
case ACACIA_STAIRS:
|
||||
case ACACIA_TRAPDOOR:
|
||||
case ACACIA_WOOD:
|
||||
case AZALEA:
|
||||
case BAMBOO:
|
||||
case BARREL:
|
||||
case BIRCH_BOAT:
|
||||
@ -1979,6 +1994,7 @@ public enum CompatibleMaterial {
|
||||
case DRIED_KELP_BLOCK:
|
||||
case FISHING_ROD:
|
||||
case FLETCHING_TABLE:
|
||||
case FLOWERING_AZALEA:
|
||||
case GRAY_BANNER:
|
||||
case GRAY_CARPET:
|
||||
case GRAY_WOOL:
|
||||
@ -2320,23 +2336,31 @@ public enum CompatibleMaterial {
|
||||
public boolean isItem() {
|
||||
// this function is not implemented in some older versions, so we need this here...
|
||||
switch (this) {
|
||||
case CAVE_AIR:
|
||||
case VOID_AIR:
|
||||
case ACACIA_WALL_SIGN:
|
||||
case ATTACHED_MELON_STEM:
|
||||
case ATTACHED_PUMPKIN_STEM:
|
||||
case BAMBOO_SAPLING:
|
||||
case BEETROOTS:
|
||||
case BIG_DRIPLEAF_STEM:
|
||||
case BIRCH_WALL_SIGN:
|
||||
case BLACK_CANDLE_CAKE:
|
||||
case BLACK_WALL_BANNER:
|
||||
case BLUE_CANDLE_CAKE:
|
||||
case BLUE_WALL_BANNER:
|
||||
case BRAIN_CORAL_WALL_FAN:
|
||||
case BROWN_CANDLE_CAKE:
|
||||
case BROWN_WALL_BANNER:
|
||||
case BUBBLE_COLUMN:
|
||||
case BUBBLE_CORAL_WALL_FAN:
|
||||
case CANDLE_CAKE:
|
||||
case CARROTS:
|
||||
case CAVE_AIR:
|
||||
case CAVE_VINES:
|
||||
case CAVE_VINES_PLANT:
|
||||
case COCOA:
|
||||
case CREEPER_WALL_HEAD:
|
||||
case CRIMSON_WALL_SIGN:
|
||||
case CYAN_CANDLE_CAKE:
|
||||
case CYAN_WALL_BANNER:
|
||||
case DARK_OAK_WALL_SIGN:
|
||||
case DEAD_BRAIN_CORAL_WALL_FAN:
|
||||
@ -2350,27 +2374,37 @@ public enum CompatibleMaterial {
|
||||
case FIRE:
|
||||
case FIRE_CORAL_WALL_FAN:
|
||||
case FROSTED_ICE:
|
||||
case GRAY_CANDLE_CAKE:
|
||||
case GRAY_WALL_BANNER:
|
||||
case GREEN_CANDLE_CAKE:
|
||||
case GREEN_WALL_BANNER:
|
||||
case HORN_CORAL_WALL_FAN:
|
||||
case JUNGLE_WALL_SIGN:
|
||||
case KELP_PLANT:
|
||||
case LAVA:
|
||||
case LAVA_CAULDRON:
|
||||
case LIGHT_BLUE_CANDLE_CAKE:
|
||||
case LIGHT_BLUE_WALL_BANNER:
|
||||
case LIGHT_GRAY_CANDLE_CAKE:
|
||||
case LIGHT_GRAY_WALL_BANNER:
|
||||
case LIME_CANDLE_CAKE:
|
||||
case LIME_WALL_BANNER:
|
||||
case MAGENTA_CANDLE_CAKE:
|
||||
case MAGENTA_WALL_BANNER:
|
||||
case MELON_STEM:
|
||||
case MOVING_PISTON:
|
||||
case NETHER_PORTAL:
|
||||
case OAK_WALL_SIGN:
|
||||
case ORANGE_CANDLE_CAKE:
|
||||
case ORANGE_WALL_BANNER:
|
||||
case PINK_CANDLE_CAKE:
|
||||
case PINK_WALL_BANNER:
|
||||
case PISTON_HEAD:
|
||||
case PLAYER_WALL_HEAD:
|
||||
case POTATOES:
|
||||
case POTTED_ACACIA_SAPLING:
|
||||
case POTTED_ALLIUM:
|
||||
case POTTED_AZALEA_BUSH:
|
||||
case POTTED_AZURE_BLUET:
|
||||
case POTTED_BAMBOO:
|
||||
case POTTED_BIRCH_SAPLING:
|
||||
@ -2378,10 +2412,13 @@ public enum CompatibleMaterial {
|
||||
case POTTED_BROWN_MUSHROOM:
|
||||
case POTTED_CACTUS:
|
||||
case POTTED_CORNFLOWER:
|
||||
case POTTED_CRIMSON_FUNGUS:
|
||||
case POTTED_CRIMSON_ROOTS:
|
||||
case POTTED_DANDELION:
|
||||
case POTTED_DARK_OAK_SAPLING:
|
||||
case POTTED_DEAD_BUSH:
|
||||
case POTTED_FERN:
|
||||
case POTTED_FLOWERING_AZALEA_BUSH:
|
||||
case POTTED_JUNGLE_SAPLING:
|
||||
case POTTED_LILY_OF_THE_VALLEY:
|
||||
case POTTED_OAK_SAPLING:
|
||||
@ -2392,26 +2429,42 @@ public enum CompatibleMaterial {
|
||||
case POTTED_RED_MUSHROOM:
|
||||
case POTTED_RED_TULIP:
|
||||
case POTTED_SPRUCE_SAPLING:
|
||||
case POTTED_WARPED_FUNGUS:
|
||||
case POTTED_WARPED_ROOTS:
|
||||
case POTTED_WHITE_TULIP:
|
||||
case POTTED_WITHER_ROSE:
|
||||
case POWDER_SNOW:
|
||||
case POWDER_SNOW_CAULDRON:
|
||||
case PUMPKIN_STEM:
|
||||
case PURPLE_CANDLE_CAKE:
|
||||
case PURPLE_WALL_BANNER:
|
||||
case REDSTONE_WALL_TORCH:
|
||||
case REDSTONE_WIRE:
|
||||
case RED_CANDLE_CAKE:
|
||||
case RED_WALL_BANNER:
|
||||
case SKELETON_WALL_SKULL:
|
||||
case SOUL_FIRE:
|
||||
case SOUL_WALL_TORCH:
|
||||
case SPRUCE_WALL_SIGN:
|
||||
case SWEET_BERRY_BUSH:
|
||||
case TALL_SEAGRASS:
|
||||
case TRIPWIRE:
|
||||
case TUBE_CORAL_WALL_FAN:
|
||||
case TWISTING_VINES_PLANT:
|
||||
case VOID_AIR:
|
||||
case WALL_TORCH:
|
||||
case WARPED_WALL_SIGN:
|
||||
case WATER:
|
||||
case WATER_CAULDRON:
|
||||
case WEEPING_VINES_PLANT:
|
||||
case WHITE_CANDLE_CAKE:
|
||||
case WHITE_WALL_BANNER:
|
||||
case WITHER_SKELETON_WALL_SKULL:
|
||||
case YELLOW_CANDLE_CAKE:
|
||||
case YELLOW_WALL_BANNER:
|
||||
case ZOMBIE_WALL_HEAD:
|
||||
return false;
|
||||
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
@ -2450,21 +2503,32 @@ public enum CompatibleMaterial {
|
||||
case BIRCH_WALL_SIGN:
|
||||
case BLACKSTONE_STAIRS:
|
||||
case BLACK_BED:
|
||||
case BLACK_CANDLE:
|
||||
case BLACK_CANDLE_CAKE:
|
||||
case BLACK_SHULKER_BOX:
|
||||
case BLAST_FURNACE:
|
||||
case BLUE_BED:
|
||||
case BLUE_CANDLE:
|
||||
case BLUE_CANDLE_CAKE:
|
||||
case BLUE_SHULKER_BOX:
|
||||
case BREWING_STAND:
|
||||
case BRICK_STAIRS:
|
||||
case BROWN_BED:
|
||||
case BROWN_CANDLE:
|
||||
case BROWN_CANDLE_CAKE:
|
||||
case BROWN_SHULKER_BOX:
|
||||
case CAKE:
|
||||
case CAMPFIRE:
|
||||
case CANDLE:
|
||||
case CANDLE_CAKE:
|
||||
case CARTOGRAPHY_TABLE:
|
||||
case CAULDRON:
|
||||
case CAVE_VINES:
|
||||
case CAVE_VINES_PLANT:
|
||||
case CHAIN_COMMAND_BLOCK:
|
||||
case CHEST:
|
||||
case CHIPPED_ANVIL:
|
||||
case COBBLED_DEEPSLATE_STAIRS:
|
||||
case COBBLESTONE_STAIRS:
|
||||
case COMMAND_BLOCK:
|
||||
case COMPARATOR:
|
||||
@ -2478,7 +2542,10 @@ public enum CompatibleMaterial {
|
||||
case CRIMSON_STAIRS:
|
||||
case CRIMSON_TRAPDOOR:
|
||||
case CRIMSON_WALL_SIGN:
|
||||
case CUT_COPPER_STAIRS:
|
||||
case CYAN_BED:
|
||||
case CYAN_CANDLE:
|
||||
case CYAN_CANDLE_CAKE:
|
||||
case CYAN_SHULKER_BOX:
|
||||
case DAMAGED_ANVIL:
|
||||
case DARK_OAK_BUTTON:
|
||||
@ -2491,6 +2558,9 @@ public enum CompatibleMaterial {
|
||||
case DARK_OAK_WALL_SIGN:
|
||||
case DARK_PRISMARINE_STAIRS:
|
||||
case DAYLIGHT_DETECTOR:
|
||||
case DEEPSLATE_BRICK_STAIRS:
|
||||
case DEEPSLATE_REDSTONE_ORE:
|
||||
case DEEPSLATE_TILE_STAIRS:
|
||||
case DIORITE_STAIRS:
|
||||
case DISPENSER:
|
||||
case DRAGON_EGG:
|
||||
@ -2498,13 +2568,18 @@ public enum CompatibleMaterial {
|
||||
case ENCHANTING_TABLE:
|
||||
case ENDER_CHEST:
|
||||
case END_STONE_BRICK_STAIRS:
|
||||
case EXPOSED_CUT_COPPER_STAIRS:
|
||||
case FLETCHING_TABLE:
|
||||
case FLOWER_POT:
|
||||
case FURNACE:
|
||||
case GRANITE_STAIRS:
|
||||
case GRAY_BED:
|
||||
case GRAY_CANDLE:
|
||||
case GRAY_CANDLE_CAKE:
|
||||
case GRAY_SHULKER_BOX:
|
||||
case GREEN_BED:
|
||||
case GREEN_CANDLE:
|
||||
case GREEN_CANDLE_CAKE:
|
||||
case GREEN_SHULKER_BOX:
|
||||
case GRINDSTONE:
|
||||
case HOPPER:
|
||||
@ -2520,16 +2595,26 @@ public enum CompatibleMaterial {
|
||||
case JUNGLE_STAIRS:
|
||||
case JUNGLE_TRAPDOOR:
|
||||
case JUNGLE_WALL_SIGN:
|
||||
case LAVA_CAULDRON:
|
||||
case LECTERN:
|
||||
case LEVER:
|
||||
case LIGHT:
|
||||
case LIGHT_BLUE_BED:
|
||||
case LIGHT_BLUE_CANDLE:
|
||||
case LIGHT_BLUE_CANDLE_CAKE:
|
||||
case LIGHT_BLUE_SHULKER_BOX:
|
||||
case LIGHT_GRAY_BED:
|
||||
case LIGHT_GRAY_CANDLE:
|
||||
case LIGHT_GRAY_CANDLE_CAKE:
|
||||
case LIGHT_GRAY_SHULKER_BOX:
|
||||
case LIME_BED:
|
||||
case LIME_CANDLE:
|
||||
case LIME_CANDLE_CAKE:
|
||||
case LIME_SHULKER_BOX:
|
||||
case LOOM:
|
||||
case MAGENTA_BED:
|
||||
case MAGENTA_CANDLE:
|
||||
case MAGENTA_CANDLE_CAKE:
|
||||
case MAGENTA_SHULKER_BOX:
|
||||
case MOSSY_COBBLESTONE_STAIRS:
|
||||
case MOSSY_STONE_BRICK_STAIRS:
|
||||
@ -2546,17 +2631,24 @@ public enum CompatibleMaterial {
|
||||
case OAK_TRAPDOOR:
|
||||
case OAK_WALL_SIGN:
|
||||
case ORANGE_BED:
|
||||
case ORANGE_CANDLE:
|
||||
case ORANGE_CANDLE_CAKE:
|
||||
case ORANGE_SHULKER_BOX:
|
||||
case OXIDIZED_CUT_COPPER_STAIRS:
|
||||
case PINK_BED:
|
||||
case PINK_CANDLE:
|
||||
case PINK_CANDLE_CAKE:
|
||||
case PINK_SHULKER_BOX:
|
||||
case POLISHED_ANDESITE_STAIRS:
|
||||
case POLISHED_BLACKSTONE_BRICK_STAIRS:
|
||||
case POLISHED_BLACKSTONE_BUTTON:
|
||||
case POLISHED_BLACKSTONE_STAIRS:
|
||||
case POLISHED_DEEPSLATE_STAIRS:
|
||||
case POLISHED_DIORITE_STAIRS:
|
||||
case POLISHED_GRANITE_STAIRS:
|
||||
case POTTED_ACACIA_SAPLING:
|
||||
case POTTED_ALLIUM:
|
||||
case POTTED_AZALEA_BUSH:
|
||||
case POTTED_AZURE_BLUET:
|
||||
case POTTED_BAMBOO:
|
||||
case POTTED_BIRCH_SAPLING:
|
||||
@ -2570,6 +2662,7 @@ public enum CompatibleMaterial {
|
||||
case POTTED_DARK_OAK_SAPLING:
|
||||
case POTTED_DEAD_BUSH:
|
||||
case POTTED_FERN:
|
||||
case POTTED_FLOWERING_AZALEA_BUSH:
|
||||
case POTTED_JUNGLE_SAPLING:
|
||||
case POTTED_LILY_OF_THE_VALLEY:
|
||||
case POTTED_OAK_SAPLING:
|
||||
@ -2584,16 +2677,21 @@ public enum CompatibleMaterial {
|
||||
case POTTED_WARPED_ROOTS:
|
||||
case POTTED_WHITE_TULIP:
|
||||
case POTTED_WITHER_ROSE:
|
||||
case POWDER_SNOW_CAULDRON:
|
||||
case PRISMARINE_BRICK_STAIRS:
|
||||
case PRISMARINE_STAIRS:
|
||||
case PUMPKIN:
|
||||
case PURPLE_BED:
|
||||
case PURPLE_CANDLE:
|
||||
case PURPLE_CANDLE_CAKE:
|
||||
case PURPLE_SHULKER_BOX:
|
||||
case PURPUR_STAIRS:
|
||||
case QUARTZ_STAIRS:
|
||||
case REDSTONE_ORE:
|
||||
case REDSTONE_WIRE:
|
||||
case RED_BED:
|
||||
case RED_CANDLE:
|
||||
case RED_CANDLE_CAKE:
|
||||
case RED_NETHER_BRICK_STAIRS:
|
||||
case RED_SANDSTONE_STAIRS:
|
||||
case RED_SHULKER_BOX:
|
||||
@ -2632,11 +2730,22 @@ public enum CompatibleMaterial {
|
||||
case WARPED_STAIRS:
|
||||
case WARPED_TRAPDOOR:
|
||||
case WARPED_WALL_SIGN:
|
||||
case WATER_CAULDRON:
|
||||
case WAXED_CUT_COPPER_STAIRS:
|
||||
case WAXED_EXPOSED_CUT_COPPER_STAIRS:
|
||||
case WAXED_OXIDIZED_CUT_COPPER_STAIRS:
|
||||
case WAXED_WEATHERED_CUT_COPPER_STAIRS:
|
||||
case WEATHERED_CUT_COPPER_STAIRS:
|
||||
case WHITE_BED:
|
||||
case WHITE_CANDLE:
|
||||
case WHITE_CANDLE_CAKE:
|
||||
case WHITE_SHULKER_BOX:
|
||||
case YELLOW_BED:
|
||||
case YELLOW_CANDLE:
|
||||
case YELLOW_CANDLE_CAKE:
|
||||
case YELLOW_SHULKER_BOX:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import org.bukkit.Color;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -209,10 +210,11 @@ public class CompatibleParticleHandler {
|
||||
|
||||
public static void spawnParticles(ParticleType type, Location location, int count) {
|
||||
if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_8)) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
float xx = (float) (1 * (Math.random() - Math.random()));
|
||||
float yy = (float) (1 * (Math.random() - Math.random()));
|
||||
float zz = (float) (1 * (Math.random() - Math.random()));
|
||||
|
||||
Location at = location.clone().add(xx, yy, zz);
|
||||
LegacyParticleEffects.createParticle(at, type.compatibleEffect);
|
||||
}
|
||||
@ -223,7 +225,7 @@ public class CompatibleParticleHandler {
|
||||
|
||||
public static void spawnParticles(ParticleType type, Location location, int count, double offsetX, double offsetY, double offsetZ) {
|
||||
if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_8)) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
float xx = (float) (offsetX * (Math.random() - Math.random()));
|
||||
float yy = (float) (offsetY * (Math.random() - Math.random()));
|
||||
float zz = (float) (offsetZ * (Math.random() - Math.random()));
|
||||
@ -281,12 +283,13 @@ public class CompatibleParticleHandler {
|
||||
float xx = (float) (radius * (Math.random() - Math.random()));
|
||||
float yy = (float) (radius * (Math.random() - Math.random()));
|
||||
float zz = (float) (radius * (Math.random() - Math.random()));
|
||||
if (player == null)
|
||||
if (player == null) {
|
||||
location.getWorld().spawnParticle(Particle.REDSTONE, location, count, xx, yy, zz, 1, new Particle.DustOptions(Color.fromBGR(blue, green, red), size));
|
||||
else
|
||||
} else {
|
||||
player.spawnParticle(Particle.REDSTONE, location, count, xx, yy, zz, 1, new Particle.DustOptions(Color.fromBGR(blue, green, red), size));
|
||||
}
|
||||
} else if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9)) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
float xx = (float) (radius * (Math.random() - Math.random()));
|
||||
float yy = (float) (radius * (Math.random() - Math.random()));
|
||||
float zz = (float) (radius * (Math.random() - Math.random()));
|
||||
@ -298,10 +301,11 @@ public class CompatibleParticleHandler {
|
||||
}
|
||||
} else {
|
||||
// WE NEED MAGIC!
|
||||
for (int i = 0; i < count; i++) {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
float xx = (float) (radius * (Math.random() - Math.random()));
|
||||
float yy = (float) (radius * (Math.random() - Math.random()));
|
||||
float zz = (float) (radius * (Math.random() - Math.random()));
|
||||
|
||||
Location at = location.clone().add(xx, yy, zz);
|
||||
LegacyParticleEffects.createParticle(at, LegacyParticleEffects.Type.REDSTONE,
|
||||
red / 255F, green / 255F, blue / 255F, 1F,
|
||||
@ -310,16 +314,18 @@ public class CompatibleParticleHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public static void bonemealSmoke(Location l) {
|
||||
final org.bukkit.World w = l.getWorld();
|
||||
w.playEffect(l, Effect.SMOKE, BlockFace.SOUTH_EAST);
|
||||
w.playEffect(l, Effect.SMOKE, BlockFace.SOUTH);
|
||||
w.playEffect(l, Effect.SMOKE, BlockFace.SOUTH_WEST);
|
||||
w.playEffect(l, Effect.SMOKE, BlockFace.EAST);
|
||||
w.playEffect(l, Effect.SMOKE, BlockFace.SELF);
|
||||
w.playEffect(l, Effect.SMOKE, BlockFace.WEST);
|
||||
w.playEffect(l, Effect.SMOKE, BlockFace.NORTH_EAST);
|
||||
w.playEffect(l, Effect.SMOKE, BlockFace.NORTH);
|
||||
w.playEffect(l, Effect.SMOKE, BlockFace.NORTH_WEST);
|
||||
public static void bonemealSmoke(Location loc) {
|
||||
World world = loc.getWorld();
|
||||
assert world != null;
|
||||
|
||||
world.playEffect(loc, Effect.SMOKE, BlockFace.SOUTH_EAST);
|
||||
world.playEffect(loc, Effect.SMOKE, BlockFace.SOUTH);
|
||||
world.playEffect(loc, Effect.SMOKE, BlockFace.SOUTH_WEST);
|
||||
world.playEffect(loc, Effect.SMOKE, BlockFace.EAST);
|
||||
world.playEffect(loc, Effect.SMOKE, BlockFace.SELF);
|
||||
world.playEffect(loc, Effect.SMOKE, BlockFace.WEST);
|
||||
world.playEffect(loc, Effect.SMOKE, BlockFace.NORTH_EAST);
|
||||
world.playEffect(loc, Effect.SMOKE, BlockFace.NORTH);
|
||||
world.playEffect(loc, Effect.SMOKE, BlockFace.NORTH_WEST);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* TODO: Probably recode to be similar to CompatibleMaterial
|
||||
*
|
||||
* Sounds that are compatible with server versions 1.7+ <br>
|
||||
* TODO: This needs work.
|
||||
* Finished 1.8, finished 1.9 blocks, resume with 1.9 entities<br>
|
||||
@ -1218,9 +1220,9 @@ public enum CompatibleSound {
|
||||
WEATHER_RAIN("AMBIENCE_RAIN"),
|
||||
WEATHER_RAIN_ABOVE;
|
||||
|
||||
protected /*final*/ Sound sound;
|
||||
protected /*final*/ boolean compatibilityMode;
|
||||
protected static final boolean DEBUG = false;
|
||||
private /* final */ Sound sound;
|
||||
private /* final */ boolean compatibilityMode;
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
CompatibleSound() {
|
||||
// This could get risky, since we haven't finished this
|
||||
@ -1239,7 +1241,7 @@ public enum CompatibleSound {
|
||||
compatibilityMode = find == null;
|
||||
}
|
||||
|
||||
// if the sound ony ever changed from 1.8 -> 1.9
|
||||
// if the sound only ever changed from 1.8 -> 1.9
|
||||
CompatibleSound(String compatibility_18) {
|
||||
try {
|
||||
compatibilityMode = false;
|
||||
@ -1272,6 +1274,7 @@ public enum CompatibleSound {
|
||||
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
Sound find = null;
|
||||
for (Sound s : Sound.values()) {
|
||||
if (s.name().equals(name())) {
|
||||
@ -1279,6 +1282,7 @@ public enum CompatibleSound {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
sound = find;
|
||||
compatibilityMode = find == null;
|
||||
}
|
||||
@ -1288,7 +1292,6 @@ public enum CompatibleSound {
|
||||
if (ServerVersion.isServerVersionAtLeast(minVersion)) {
|
||||
// should be good to use this sound
|
||||
sound = Sound.valueOf(name());
|
||||
compatibilityMode = false;
|
||||
} else {
|
||||
for (Version v : versions) {
|
||||
if (v.sound != null && ServerVersion.isServerVersionAtLeast(v.version)) {
|
||||
@ -1297,11 +1300,13 @@ public enum CompatibleSound {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
sound = null;
|
||||
compatibilityMode = false;
|
||||
}
|
||||
|
||||
compatibilityMode = false;
|
||||
} catch (Exception ex) {
|
||||
System.err.println("ERROR loading " + name() + " (" + minVersion);
|
||||
System.err.println("ERROR loading " + name() + " (" + minVersion + ")");
|
||||
for (Version v : versions) {
|
||||
System.err.println(v.version + " - " + v.sound);
|
||||
}
|
||||
@ -1311,66 +1316,67 @@ public enum CompatibleSound {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Bukkit API sound that matches this sound
|
||||
* Returns the appropriate Bukkit API sound or tries to find a sane alternative,
|
||||
* if the server does not support that sound
|
||||
*
|
||||
* @return Returns either the matching sound or a similar sound
|
||||
* @return Either the matching sound or a similar sound
|
||||
*/
|
||||
public Sound getSound() {
|
||||
return sound != null ? sound : UI_BUTTON_CLICK.sound;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a sound to a specific player
|
||||
* Sends a sound to a specific player
|
||||
*
|
||||
* @param sendTo player to send the sound to
|
||||
* @param player The player to play the sound for
|
||||
*/
|
||||
public void play(Player sendTo) {
|
||||
sendTo.playSound(sendTo.getLocation(), getSound(), 1F, 1F);
|
||||
public void play(Player player) {
|
||||
player.playSound(player.getLocation(), getSound(), 1F, 1F);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a sound to a specific player
|
||||
*
|
||||
* @param player player to send the sound to
|
||||
* @param volume The volume of the sound (1 is 100%)
|
||||
* @param pitch The pitch of the sound (for notchian clients: between 0.5 and 2.0)
|
||||
*/
|
||||
public void play(Player player, float volume, float pitch) {
|
||||
player.playSound(player.getLocation(), getSound(), volume, pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a sound to a specific player
|
||||
*
|
||||
* @param sendTo player to send the sound to
|
||||
* @param volume the volume of the sound
|
||||
* @param pitch the pitch of the sound
|
||||
* @param player The player to play the sound for
|
||||
* @param location Where the sound should come from
|
||||
* @param volume The volume of the sound (1 is 100%)
|
||||
* * @param pitch The pitch of the sound (for notchian clients: between 0.5 and 2.0)
|
||||
*/
|
||||
public void play(Player sendTo, float volume, float pitch) {
|
||||
sendTo.playSound(sendTo.getLocation(), getSound(), volume, pitch);
|
||||
public void play(Player player, Location location, float volume, float pitch) {
|
||||
player.playSound(location, getSound(), volume, pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a sound to a specific player
|
||||
* Plays a sound in a given world
|
||||
*
|
||||
* @param sendTo player to send the sound to
|
||||
* @param location where the sound should come from
|
||||
* @param volume the volume of the sound
|
||||
* @param pitch the pitch of the sound
|
||||
* @param world The world to play the sound in
|
||||
* @param location Where the sound should come from
|
||||
* @param volume The volume of the sound (1 is 100%)
|
||||
* @param pitch The pitch of the sound (for notchian clients: between 0.5 and 2.0)
|
||||
*/
|
||||
public void play(Player sendTo, Location location, float volume, float pitch) {
|
||||
sendTo.playSound(sendTo.getLocation(), getSound(), volume, pitch);
|
||||
public void play(World world, Location location, float volume, float pitch) {
|
||||
world.playSound(location, getSound(), volume, pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Play a sound in a world
|
||||
* Stop a currently active sound from playing for a player (Only supporter on 1.10 servers or newer)
|
||||
*
|
||||
* @param sendTo world to send the sound to
|
||||
* @param location where the sound should come from
|
||||
* @param volume the volume of the sound
|
||||
* @param pitch the pitch of the sound
|
||||
* @param player The player to stop the sound for
|
||||
*/
|
||||
public void play(World sendTo, Location location, float volume, float pitch) {
|
||||
sendTo.playSound(location, getSound(), volume, pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop a currently active sound from playing for a player
|
||||
*
|
||||
* @param sendTo player to stop the sound for
|
||||
*/
|
||||
public void stop(Player sendTo) {
|
||||
public void stop(Player player) {
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_10)) {
|
||||
sendTo.stopSound(getSound());
|
||||
player.stopSound(getSound());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1400,7 +1406,6 @@ public enum CompatibleSound {
|
||||
}
|
||||
|
||||
private static class Version {
|
||||
|
||||
final ServerVersion version;
|
||||
final String sound;
|
||||
final boolean compatibilityMode;
|
||||
|
@ -4,12 +4,16 @@ import org.apache.commons.lang.ArrayUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public enum ServerProject {
|
||||
UNKNOWN, CRAFTBUKKIT, SPIGOT, PAPER, TACO, GLOWSTONE;
|
||||
UNKNOWN, CRAFTBUKKIT, SPIGOT, PAPER, TACO, GLOWSTONE, MOCK_BUKKIT;
|
||||
private final static ServerProject serverProject = checkProject();
|
||||
|
||||
private static ServerProject checkProject() {
|
||||
String serverPath = Bukkit.getServer().getClass().getName();
|
||||
|
||||
if (serverPath.equals("be.seeseemelk.mockbukkit.ServerMock")) {
|
||||
return MOCK_BUKKIT;
|
||||
}
|
||||
|
||||
if (serverPath.contains("glowstone")) {
|
||||
return GLOWSTONE;
|
||||
}
|
||||
|
@ -6,10 +6,30 @@ import org.bukkit.Bukkit;
|
||||
public enum ServerVersion {
|
||||
UNKNOWN, V1_7, V1_8, V1_9, V1_10, V1_11, V1_12, V1_13, V1_14, V1_15, V1_16, V1_17, V1_18, V1_19, V1_20, V1_21;
|
||||
|
||||
private final static String serverPackagePath = Bukkit.getServer().getClass().getPackage().getName();
|
||||
private final static String serverPackageVersion = serverPackagePath.substring(serverPackagePath.lastIndexOf('.') + 1);
|
||||
private final static String serverReleaseVersion = serverPackageVersion.indexOf('R') != -1 ? serverPackageVersion.substring(serverPackageVersion.indexOf('R') + 1) : "";
|
||||
private final static ServerVersion serverVersion = getVersion();
|
||||
private final static String serverPackagePath;
|
||||
private final static String serverPackageVersion;
|
||||
private final static String serverReleaseVersion;
|
||||
private final static ServerVersion serverVersion;
|
||||
private final static boolean isMocked;
|
||||
|
||||
static {
|
||||
String srvPackage = Bukkit.getServer().getClass().getPackage().getName();
|
||||
isMocked = srvPackage.equals("be.seeseemelk.mockbukkit");
|
||||
|
||||
if (isMocked) {
|
||||
String packageVersionShard = "v" + Bukkit.getServer().getBukkitVersion().replace('.', '_') + "_R0";
|
||||
|
||||
serverPackagePath = "org.bukkit.craftbukkit." + packageVersionShard;
|
||||
serverPackageVersion = packageVersionShard;
|
||||
serverReleaseVersion = "0";
|
||||
} else {
|
||||
serverPackagePath = srvPackage;
|
||||
serverPackageVersion = serverPackagePath.substring(serverPackagePath.lastIndexOf('.') + 1);
|
||||
serverReleaseVersion = serverPackageVersion.indexOf('R') != -1 ? serverPackageVersion.substring(serverPackageVersion.indexOf('R') + 1) : "";
|
||||
}
|
||||
|
||||
serverVersion = getVersion();
|
||||
}
|
||||
|
||||
private static ServerVersion getVersion() {
|
||||
for (ServerVersion version : values()) {
|
||||
|
@ -0,0 +1,32 @@
|
||||
package com.songoda.core.compatibility.bukkit;
|
||||
|
||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import com.songoda.core.compatibility.CompatibleSound;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
class CompatibleSoundTest {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
MockBukkit.mock();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
MockBukkit.unmock();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled("CompatibleSound class needs some work beforehand")
|
||||
void getSound() {
|
||||
for (CompatibleSound compatibleSound : CompatibleSound.values()) {
|
||||
assertNotNull(compatibleSound.getSound());
|
||||
|
||||
// compatibleSound.usesCompatibility()
|
||||
}
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.5.14</version>
|
||||
<version>2.6.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -210,6 +210,12 @@
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>SongodaCore-NMS-v1_18_R1</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- End NMS -->
|
||||
|
||||
<!-- Start Plugin Hooks -->
|
||||
|
@ -53,7 +53,7 @@ public class SongodaCore {
|
||||
/**
|
||||
* @since coreRevision 6
|
||||
*/
|
||||
private final static String coreVersion = "2.5.14";
|
||||
private final static String coreVersion = "2.6.0";
|
||||
|
||||
/**
|
||||
* This is specific to the website api
|
||||
|
@ -97,6 +97,11 @@ public class NmsManager {
|
||||
nbt = new com.songoda.core.nms.v1_17_R1.nbt.NBTCoreImpl();
|
||||
world = new com.songoda.core.nms.v1_17_R1.world.WorldCoreImpl();
|
||||
break;
|
||||
case "v1_18_R1":
|
||||
anvil = new com.songoda.core.nms.v1_18_R1.anvil.AnvilCore();
|
||||
nbt = new com.songoda.core.nms.v1_18_R1.nbt.NBTCoreImpl();
|
||||
world = new com.songoda.core.nms.v1_18_R1.world.WorldCoreImpl();
|
||||
break;
|
||||
default:
|
||||
Logger.getLogger(NmsManager.class.getName()).log(Level.SEVERE, "Failed to load NMS for this server version: version {0} not found", serverPackageVersion);
|
||||
|
||||
|
@ -0,0 +1,86 @@
|
||||
package com.songoda.core.compatibility.material;
|
||||
|
||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
class CompatibleMaterialTest {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
MockBukkit.mock();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
MockBukkit.unmock();
|
||||
}
|
||||
|
||||
@Test
|
||||
void getMaterialForNull() {
|
||||
assertNull(CompatibleMaterial.getMaterial((Material) null));
|
||||
assertNull(CompatibleMaterial.getMaterial((ItemStack) null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getMaterialForAllBukkitMaterials() {
|
||||
Map<CompatibleMaterial, Material> returnedMaterials = new HashMap<>(Material.values().length);
|
||||
for (Material bukkitMaterial : Material.values()) {
|
||||
CompatibleMaterial compatibleMaterial = CompatibleMaterial.getMaterial(bukkitMaterial);
|
||||
|
||||
if (bukkitMaterial.name().startsWith("LEGACY_")) {
|
||||
assertNull(compatibleMaterial);
|
||||
continue;
|
||||
}
|
||||
assertNotNull(compatibleMaterial, () -> "Could not get an CompatibleMaterial for Material." + bukkitMaterial.name());
|
||||
assertEquals(bukkitMaterial, compatibleMaterial.getMaterial());
|
||||
assertEquals(compatibleMaterial, CompatibleMaterial.getMaterial(bukkitMaterial.name()));
|
||||
|
||||
assertFalse(returnedMaterials.containsKey(compatibleMaterial),
|
||||
() -> String.format("Assertion failed when converting Material.%s to CompatibleMaterial.%s: " +
|
||||
"CompatibleMaterial.%1$s has already been returned for Material.%3$s previously",
|
||||
bukkitMaterial.name(),
|
||||
compatibleMaterial.name(),
|
||||
returnedMaterials.get(compatibleMaterial).name()
|
||||
));
|
||||
|
||||
assertEquals(bukkitMaterial.isAir(), compatibleMaterial.isAir(), getMaterialPropertyAssertionError(compatibleMaterial, "Air"));
|
||||
assertEquals(bukkitMaterial.isBlock(), compatibleMaterial.isBlock(), getMaterialPropertyAssertionError(compatibleMaterial, "Block"));
|
||||
assertEquals(bukkitMaterial.isBurnable(), compatibleMaterial.isBurnable(), getMaterialPropertyAssertionError(compatibleMaterial, "Burnable"));
|
||||
assertEquals(bukkitMaterial.isEdible(), compatibleMaterial.isEdible(), getMaterialPropertyAssertionError(compatibleMaterial, "Edible"));
|
||||
assertEquals(bukkitMaterial.isFlammable(), compatibleMaterial.isFlammable(), getMaterialPropertyAssertionError(compatibleMaterial, "Flammable"));
|
||||
assertEquals(bukkitMaterial.isFuel(), compatibleMaterial.isFuel(), getMaterialPropertyAssertionError(compatibleMaterial, "Fuel"));
|
||||
assertEquals(bukkitMaterial.isInteractable(), compatibleMaterial.isInteractable(), getMaterialPropertyAssertionError(compatibleMaterial, "Interactable"));
|
||||
assertEquals(bukkitMaterial.isItem(), compatibleMaterial.isItem(), getMaterialPropertyAssertionError(compatibleMaterial, "Item"));
|
||||
assertEquals(bukkitMaterial.isOccluding(), compatibleMaterial.isOccluding(), getMaterialPropertyAssertionError(compatibleMaterial, "Occluding"));
|
||||
assertEquals(bukkitMaterial.isSolid(), compatibleMaterial.isSolid(), getMaterialPropertyAssertionError(compatibleMaterial, "Solid"));
|
||||
assertEquals(bukkitMaterial.isTransparent(), compatibleMaterial.isTransparent(), getMaterialPropertyAssertionError(compatibleMaterial, "Transparent"));
|
||||
|
||||
assertFalse(compatibleMaterial.usesCompatibility());
|
||||
assertFalse(compatibleMaterial.usesData());
|
||||
assertEquals(-1, compatibleMaterial.getData());
|
||||
|
||||
ItemStack compatibleItem = compatibleMaterial.getItem();
|
||||
assertEquals(bukkitMaterial, compatibleItem.getType());
|
||||
assertEquals(compatibleMaterial, CompatibleMaterial.getMaterial(compatibleItem));
|
||||
|
||||
returnedMaterials.put(compatibleMaterial, bukkitMaterial);
|
||||
}
|
||||
}
|
||||
|
||||
private Supplier<String> getMaterialPropertyAssertionError(CompatibleMaterial compatibleMaterial, String propertyName) {
|
||||
return () -> String.format("Expected CompatibleMaterial.%s to be '%s'", compatibleMaterial.name(), propertyName);
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.5.14</version>
|
||||
<version>2.6.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.5.14</version>
|
||||
<version>2.6.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.5.14</version>
|
||||
<version>2.6.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.5.14</version>
|
||||
<version>2.6.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.5.14</version>
|
||||
<version>2.6.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.5.14</version>
|
||||
<version>2.6.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.5.14</version>
|
||||
<version>2.6.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.5.14</version>
|
||||
<version>2.6.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.5.14</version>
|
||||
<version>2.6.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.5.14</version>
|
||||
<version>2.6.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.5.14</version>
|
||||
<version>2.6.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.5.14</version>
|
||||
<version>2.6.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
42
NMS/NMS-v1_18_R1/pom.xml
Normal file
42
NMS/NMS-v1_18_R1/pom.xml
Normal file
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.6.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<java.release>17</java.release>
|
||||
</properties>
|
||||
|
||||
<artifactId>SongodaCore-NMS-v1_18_R1</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.18</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>SongodaCore-NMS-API</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>SongodaCore-Compatibility</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -0,0 +1,21 @@
|
||||
package com.songoda.core.nms.v1_18_R1.anvil;
|
||||
|
||||
import com.songoda.core.nms.anvil.CustomAnvil;
|
||||
import net.minecraft.server.level.EntityPlayer;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
public class AnvilCore implements com.songoda.core.nms.anvil.AnvilCore {
|
||||
@Override
|
||||
public CustomAnvil createAnvil(Player player) {
|
||||
EntityPlayer p = ((CraftPlayer) player).getHandle();
|
||||
return new AnvilView(p.nextContainerCounter(), p, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomAnvil createAnvil(Player player, InventoryHolder holder) {
|
||||
EntityPlayer p = ((CraftPlayer) player).getHandle();
|
||||
return new AnvilView(p.nextContainerCounter(), p, holder);
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.songoda.core.nms.v1_18_R1.anvil;
|
||||
|
||||
import net.minecraft.world.IInventory;
|
||||
import net.minecraft.world.inventory.ContainerAnvil;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryAnvil;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
public class AnvilInventoryCustom extends CraftInventoryAnvil {
|
||||
final InventoryHolder holder;
|
||||
|
||||
public AnvilInventoryCustom(InventoryHolder holder, Location location, IInventory inventory, IInventory resultInventory, ContainerAnvil container) {
|
||||
super(location, inventory, resultInventory, container);
|
||||
|
||||
this.holder = holder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryHolder getHolder() {
|
||||
return holder;
|
||||
}
|
||||
}
|
@ -0,0 +1,214 @@
|
||||
package com.songoda.core.nms.v1_18_R1.anvil;
|
||||
|
||||
import com.songoda.core.nms.anvil.CustomAnvil;
|
||||
import com.songoda.core.nms.anvil.methods.AnvilTextChange;
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.network.chat.ChatMessage;
|
||||
import net.minecraft.network.protocol.game.PacketPlayOutOpenWindow;
|
||||
import net.minecraft.server.level.EntityPlayer;
|
||||
import net.minecraft.world.IInventory;
|
||||
import net.minecraft.world.entity.player.EntityHuman;
|
||||
import net.minecraft.world.inventory.Container;
|
||||
import net.minecraft.world.inventory.ContainerAccess;
|
||||
import net.minecraft.world.inventory.ContainerAnvil;
|
||||
import net.minecraft.world.inventory.ContainerAnvilAbstract;
|
||||
import net.minecraft.world.inventory.Containers;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryView;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class AnvilView extends ContainerAnvil implements CustomAnvil {
|
||||
private final EntityPlayer entity;
|
||||
private final Inventory inventory;
|
||||
private String customTitle = "Repairing";
|
||||
private int cost = -1;
|
||||
private boolean canUse = true;
|
||||
private AnvilTextChange textChange;
|
||||
|
||||
// used for setting custom inventory
|
||||
static Field mc_ContainerAnvil_repairInventory; // subcontainer with only the result
|
||||
static Field mc_ContainerAnvil_resultInventory; // full inventory
|
||||
static Field mc_ContainerAnvil_bukkitEntity;
|
||||
|
||||
static {
|
||||
try {
|
||||
mc_ContainerAnvil_repairInventory = ContainerAnvilAbstract.class.getDeclaredField("p");
|
||||
mc_ContainerAnvil_repairInventory.setAccessible(true);
|
||||
|
||||
mc_ContainerAnvil_resultInventory = ContainerAnvilAbstract.class.getDeclaredField("o");
|
||||
mc_ContainerAnvil_resultInventory.setAccessible(true);
|
||||
|
||||
mc_ContainerAnvil_bukkitEntity = ContainerAnvil.class.getDeclaredField("bukkitEntity");
|
||||
mc_ContainerAnvil_bukkitEntity.setAccessible(true);
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Setup Error", ex);
|
||||
}
|
||||
}
|
||||
|
||||
// 1.14 also introduced a title field, also private, which can only be set once and can't be checked
|
||||
static Field mc_Container_title;
|
||||
|
||||
static {
|
||||
try {
|
||||
mc_Container_title = Container.class.getDeclaredField("title");
|
||||
mc_Container_title.setAccessible(true);
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Setup Error", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public AnvilView(int id, EntityPlayer entity, InventoryHolder holder) {
|
||||
super(entity.nextContainerCounter(), entity.fq(), ContainerAccess.a(entity.t, new BlockPosition(0, 0, 0)));
|
||||
|
||||
this.setTitle(new ChatMessage(customTitle != null ? customTitle : ""));
|
||||
this.checkReachable = false;
|
||||
this.entity = entity;
|
||||
|
||||
if (holder != null) {
|
||||
this.inventory = getBukkitView(entity, holder).getTopInventory();
|
||||
} else {
|
||||
this.inventory = getBukkitView().getTopInventory();
|
||||
}
|
||||
}
|
||||
|
||||
public CraftInventoryView getBukkitView(EntityHuman player, InventoryHolder holder) {
|
||||
try {
|
||||
AnvilInventoryCustom craftInventory = new AnvilInventoryCustom(holder,
|
||||
new Location(entity.t.getWorld(), 0, 0, 0),
|
||||
(IInventory) mc_ContainerAnvil_repairInventory.get(this),
|
||||
(IInventory) mc_ContainerAnvil_resultInventory.get(this), this);
|
||||
CraftInventoryView view = new CraftInventoryView(player.getBukkitEntity(), craftInventory, this);
|
||||
mc_ContainerAnvil_bukkitEntity.set(this, view);
|
||||
|
||||
return view;
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Setup Error", ex);
|
||||
}
|
||||
|
||||
return getBukkitView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean a(EntityHuman entityhuman) {
|
||||
return canUse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void e() {
|
||||
super.e();
|
||||
|
||||
if (cost >= 0) {
|
||||
this.setLevelCost(cost);
|
||||
}
|
||||
|
||||
textChange.onChange();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
e();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRenameText() {
|
||||
return this.v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRenameText(String text) {
|
||||
this.a(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnChange(AnvilTextChange handler) {
|
||||
textChange = handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCustomTitle() {
|
||||
return customTitle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomTitle(String title) {
|
||||
this.customTitle = title;
|
||||
|
||||
try {
|
||||
mc_Container_title.set(this, new ChatMessage(customTitle != null ? customTitle : ""));
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Error", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLevelCost(int cost) {
|
||||
this.cost = cost;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLevelCost() {
|
||||
if (cost >= 0) {
|
||||
return cost;
|
||||
}
|
||||
|
||||
return this.getLevelCost();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCanUse(boolean bool) {
|
||||
this.canUse = bool;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getLeftInput() {
|
||||
return inventory.getItem(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getRightInput() {
|
||||
return inventory.getItem(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getOutput() {
|
||||
return inventory.getItem(2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLeftInput(ItemStack item) {
|
||||
inventory.setItem(0, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRightInput(ItemStack item) {
|
||||
inventory.setItem(1, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOutput(ItemStack item) {
|
||||
inventory.setItem(2, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
// Send the packet
|
||||
entity.b.a(new PacketPlayOutOpenWindow(j, Containers.h, new ChatMessage(customTitle != null ? customTitle : "")));
|
||||
|
||||
// Set their active container to this anvil
|
||||
entity.bW = this;
|
||||
|
||||
// Add the slot listener
|
||||
entity.a(entity.bW);
|
||||
}
|
||||
}
|
@ -0,0 +1,210 @@
|
||||
package com.songoda.core.nms.v1_18_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTCompound;
|
||||
import com.songoda.core.nms.nbt.NBTObject;
|
||||
import net.minecraft.nbt.NBTCompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class NBTCompoundImpl implements NBTCompound {
|
||||
protected NBTTagCompound compound;
|
||||
|
||||
protected NBTCompoundImpl(NBTTagCompound compound) {
|
||||
this.compound = compound;
|
||||
}
|
||||
|
||||
public NBTCompoundImpl() {
|
||||
this.compound = new NBTTagCompound();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTCompound set(String tag, String s) {
|
||||
compound.a(tag, s);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTCompound set(String tag, boolean b) {
|
||||
compound.a(tag, b);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTCompound set(String tag, int i) {
|
||||
compound.a(tag, i);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTCompound set(String tag, double i) {
|
||||
compound.a(tag, i);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTCompound set(String tag, long l) {
|
||||
compound.a(tag, l);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTCompound set(String tag, short s) {
|
||||
compound.a(tag, s);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTCompound set(String tag, byte b) {
|
||||
compound.a(tag, b);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTCompound set(String tag, int[] i) {
|
||||
compound.a(tag, i);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTCompound set(String tag, byte[] b) {
|
||||
compound.a(tag, b);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTCompound set(String tag, UUID u) {
|
||||
compound.a(tag, u);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTCompound remove(String tag) {
|
||||
compound.r(tag);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean has(String tag) {
|
||||
return compound.e(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTObject getNBTObject(String tag) {
|
||||
return new NBTObjectImpl(compound, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(String tag) {
|
||||
return getNBTObject(tag).asString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(String tag) {
|
||||
return getNBTObject(tag).asBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInt(String tag) {
|
||||
return getNBTObject(tag).asInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDouble(String tag) {
|
||||
return getNBTObject(tag).asDouble();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLong(String tag) {
|
||||
return getNBTObject(tag).asLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getShort(String tag) {
|
||||
return getNBTObject(tag).asShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getByte(String tag) {
|
||||
return getNBTObject(tag).asByte();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getIntArray(String tag) {
|
||||
return getNBTObject(tag).asIntArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getByteArray(String tag) {
|
||||
return getNBTObject(tag).asByteArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTCompound getCompound(String tag) {
|
||||
if (has(tag)) {
|
||||
return getNBTObject(tag).asCompound();
|
||||
}
|
||||
|
||||
NBTTagCompound newCompound = new NBTTagCompound();
|
||||
compound.a(tag, newCompound);
|
||||
return new NBTCompoundImpl(newCompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getKeys() {
|
||||
return compound.d();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getKeys(String tag) {
|
||||
return compound.p(tag).d();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] serialize(String... exclusions) {
|
||||
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ObjectOutputStream dataOutput = new ObjectOutputStream(outputStream)) {
|
||||
addExtras();
|
||||
NBTTagCompound compound = this.compound.g();
|
||||
|
||||
for (String exclusion : exclusions) {
|
||||
compound.r(exclusion);
|
||||
}
|
||||
|
||||
NBTCompressedStreamTools.a(compound, (OutputStream) dataOutput);
|
||||
|
||||
return outputStream.toByteArray();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deSerialize(byte[] serialized) {
|
||||
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(serialized);
|
||||
ObjectInputStream dataInput = new ObjectInputStream(inputStream)) {
|
||||
compound = NBTCompressedStreamTools.a((InputStream) dataInput);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtras() {
|
||||
// None
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return compound.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.songoda.core.nms.v1_18_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTCore;
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class NBTCoreImpl implements NBTCore {
|
||||
@Override
|
||||
public NBTItem of(ItemStack item) {
|
||||
return new NBTItemImpl(CraftItemStack.asNMSCopy(item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTItem newItem() {
|
||||
return new NBTItemImpl(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTEntity of(Entity entity) {
|
||||
net.minecraft.world.entity.Entity nmsEntity = ((CraftEntity) entity).getHandle();
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nmsEntity.f(nbt);
|
||||
|
||||
return new NBTEntityImpl(nbt, nmsEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTEntity newEntity() {
|
||||
return new NBTEntityImpl(new NBTTagCompound(), null);
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package com.songoda.core.nms.v1_18_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.core.IRegistry;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityTypes;
|
||||
import net.minecraft.world.entity.EnumMobSpawn;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.CraftWorld;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity {
|
||||
private Entity nmsEntity;
|
||||
|
||||
public NBTEntityImpl(NBTTagCompound entityNBT, Entity nmsEntity) {
|
||||
super(entityNBT);
|
||||
|
||||
this.nmsEntity = nmsEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity spawn(Location location) {
|
||||
String entityType = getNBTObject("entity_type").asString();
|
||||
|
||||
Optional<EntityTypes<?>> optionalEntity = EntityTypes.a(entityType);
|
||||
if (optionalEntity.isPresent()) {
|
||||
assert location.getWorld() != null;
|
||||
|
||||
Entity spawned = optionalEntity.get().a(
|
||||
((CraftWorld) location.getWorld()).getHandle(),
|
||||
compound,
|
||||
null,
|
||||
null,
|
||||
new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()),
|
||||
EnumMobSpawn.n,
|
||||
true,
|
||||
false
|
||||
);
|
||||
|
||||
if (spawned != null) {
|
||||
spawned.g(compound);
|
||||
org.bukkit.entity.Entity entity = spawned.getBukkitEntity();
|
||||
entity.teleport(location);
|
||||
nmsEntity = spawned;
|
||||
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity reSpawn(Location location) {
|
||||
nmsEntity.ah();
|
||||
return spawn(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtras() {
|
||||
compound.a("entity_type", IRegistry.Z.b(nmsEntity.ad()).toString());
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.songoda.core.nms.v1_18_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class NBTItemImpl extends NBTCompoundImpl implements NBTItem {
|
||||
private final net.minecraft.world.item.ItemStack nmsItem;
|
||||
|
||||
public NBTItemImpl(net.minecraft.world.item.ItemStack nmsItem) {
|
||||
super(nmsItem != null && nmsItem.r() ? nmsItem.s() : new NBTTagCompound());
|
||||
|
||||
this.nmsItem = nmsItem;
|
||||
}
|
||||
|
||||
public ItemStack finish() {
|
||||
if (nmsItem == null) {
|
||||
return CraftItemStack.asBukkitCopy(net.minecraft.world.item.ItemStack.a(compound));
|
||||
}
|
||||
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package com.songoda.core.nms.v1_18_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTCompound;
|
||||
import com.songoda.core.nms.nbt.NBTObject;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class NBTObjectImpl implements NBTObject {
|
||||
private final NBTTagCompound compound;
|
||||
private final String tag;
|
||||
|
||||
public NBTObjectImpl(NBTTagCompound compound, String tag) {
|
||||
this.compound = compound;
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return compound.l(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBoolean() {
|
||||
return compound.q(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return compound.h(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return compound.k(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return compound.i(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return compound.g(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return compound.f(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return compound.n(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return compound.m(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTCompound asCompound() {
|
||||
return new NBTCompoundImpl(compound.p(tag));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getKeys() {
|
||||
return compound.d();
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.songoda.core.nms.v1_18_R1.world;
|
||||
|
||||
import com.songoda.core.nms.world.SItemStack;
|
||||
import net.minecraft.core.particles.ParticleParamItem;
|
||||
import net.minecraft.core.particles.Particles;
|
||||
import net.minecraft.server.level.EntityPlayer;
|
||||
import net.minecraft.world.phys.Vec3D;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class SItemStackImpl implements SItemStack {
|
||||
private final ItemStack item;
|
||||
|
||||
public SItemStackImpl(ItemStack item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakItem(Player player, int amount) {
|
||||
EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
|
||||
|
||||
for (int i = 0; i < amount; ++i) {
|
||||
Vec3D vec3d = new Vec3D(((double) random.nextFloat() - 0.5D) * 0.1D, Math.random() * 0.1D + 0.1D, 0.0D);
|
||||
vec3d = vec3d.a(-entityPlayer.dn() * 0.017453292F);
|
||||
vec3d = vec3d.b(-entityPlayer.dm() * 0.017453292F);
|
||||
|
||||
double d0 = (double) (-random.nextFloat()) * 0.6D - 0.3D;
|
||||
|
||||
Vec3D vec3d1 = new Vec3D(((double) random.nextFloat() - 0.5D) * 0.3D, d0, 0.6D);
|
||||
vec3d1 = vec3d1.a(-entityPlayer.dn() * 0.017453292F);
|
||||
vec3d1 = vec3d1.b(-entityPlayer.dm() * 0.017453292F);
|
||||
vec3d1 = vec3d1.b(entityPlayer.dc(), entityPlayer.dg(), entityPlayer.di());
|
||||
|
||||
entityPlayer.t.a(new ParticleParamItem(Particles.J, CraftItemStack.asNMSCopy(item)), vec3d1.b, vec3d1.c, vec3d1.d, vec3d.b, vec3d.c + 0.05D, vec3d.d);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,136 @@
|
||||
package com.songoda.core.nms.v1_18_R1.world;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.CompatibleParticleHandler;
|
||||
import com.songoda.core.nms.world.SSpawner;
|
||||
import com.songoda.core.nms.world.SpawnedEntity;
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.level.WorldServer;
|
||||
import net.minecraft.world.DifficultyDamageScaler;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityInsentient;
|
||||
import net.minecraft.world.entity.EntityTypes;
|
||||
import net.minecraft.world.entity.EnumMobSpawn;
|
||||
import net.minecraft.world.level.MobSpawnerData;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.CraftWorld;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class SSpawnerImpl implements SSpawner {
|
||||
private final Location spawnerLocation;
|
||||
|
||||
public SSpawnerImpl(Location location) {
|
||||
this.spawnerLocation = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity(EntityType type, Location spawnerLocation) {
|
||||
return spawnEntity(type, "EXPLOSION_NORMAL", null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
|
||||
Set<CompatibleMaterial> canSpawnOn) {
|
||||
MobSpawnerData data = new MobSpawnerData();
|
||||
NBTTagCompound compound = data.a();
|
||||
|
||||
String name = type.name().toLowerCase().replace("snowman", "snow_golem")
|
||||
.replace("mushroom_cow", "mooshroom");
|
||||
compound.a("id", "minecraft:" + name);
|
||||
|
||||
short spawnRange = 4;
|
||||
for (int i = 0; i < 50; i++) {
|
||||
assert spawnerLocation.getWorld() != null;
|
||||
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
|
||||
|
||||
Random random = world.r_();
|
||||
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
|
||||
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||
|
||||
Optional<Entity> optionalEntity = EntityTypes.a(compound, world);
|
||||
if (optionalEntity.isEmpty()) continue;
|
||||
|
||||
Entity entity = optionalEntity.get();
|
||||
entity.e(x, y, z);
|
||||
|
||||
BlockPosition position = entity.cW();
|
||||
DifficultyDamageScaler damageScaler = world.d_(position);
|
||||
|
||||
if (!(entity instanceof EntityInsentient entityInsentient)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
|
||||
|
||||
if (!canSpawn(world, entityInsentient, spot, canSpawnOn)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
entityInsentient.a(world, damageScaler, EnumMobSpawn.c, null, null);
|
||||
|
||||
LivingEntity craftEntity = (LivingEntity) entity.getBukkitEntity();
|
||||
|
||||
if (spawned != null && !spawned.onSpawn(craftEntity)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (particleType != null) {
|
||||
float xx = (float) (0 + (Math.random() * 1));
|
||||
float yy = (float) (0 + (Math.random() * 2));
|
||||
float zz = (float) (0 + (Math.random() * 1));
|
||||
|
||||
CompatibleParticleHandler.spawnParticles(CompatibleParticleHandler.ParticleType.getParticle(particleType),
|
||||
spot, 5, xx, yy, zz, 0);
|
||||
}
|
||||
|
||||
world.addFreshEntity(entity, CreatureSpawnEvent.SpawnReason.SPAWNER);
|
||||
|
||||
spot.setYaw(random.nextFloat() * 360.0F);
|
||||
craftEntity.teleport(spot);
|
||||
|
||||
return craftEntity;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location,
|
||||
Set<CompatibleMaterial> canSpawnOn) {
|
||||
if (!world.a(entityInsentient, entityInsentient.cw())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
|
||||
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
|
||||
|
||||
if (spawnedIn == null || spawnedOn == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!spawnedIn.isAir() &&
|
||||
spawnedIn != CompatibleMaterial.WATER &&
|
||||
!spawnedIn.name().contains("PRESSURE") &&
|
||||
!spawnedIn.name().contains("SLAB")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (CompatibleMaterial material : canSpawnOn) {
|
||||
if (material == null) continue;
|
||||
|
||||
if (spawnedOn.equals(material) || material.isAir()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.songoda.core.nms.v1_18_R1.world;
|
||||
|
||||
import com.songoda.core.nms.world.SWorld;
|
||||
import net.minecraft.server.level.WorldServer;
|
||||
import net.minecraft.world.level.entity.LevelEntityGetter;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.CraftWorld;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SWorldImpl implements SWorld {
|
||||
private final World world;
|
||||
|
||||
public SWorldImpl(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LivingEntity> getLivingEntities() {
|
||||
List<LivingEntity> result = new ArrayList<>();
|
||||
|
||||
WorldServer worldServer = ((CraftWorld) world).getHandle();
|
||||
LevelEntityGetter<net.minecraft.world.entity.Entity> entities = worldServer.P.d();
|
||||
|
||||
entities.a().forEach((mcEnt) -> {
|
||||
org.bukkit.entity.Entity bukkitEntity = mcEnt.getBukkitEntity();
|
||||
|
||||
if (bukkitEntity instanceof LivingEntity && bukkitEntity.isValid()) {
|
||||
result.add((LivingEntity) bukkitEntity);
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
package com.songoda.core.nms.v1_18_R1.world;
|
||||
|
||||
import com.songoda.core.nms.ReflectionUtils;
|
||||
import com.songoda.core.nms.v1_18_R1.world.spawner.BBaseSpawnerImpl;
|
||||
import com.songoda.core.nms.world.BBaseSpawner;
|
||||
import com.songoda.core.nms.world.SItemStack;
|
||||
import com.songoda.core.nms.world.SSpawner;
|
||||
import com.songoda.core.nms.world.SWorld;
|
||||
import com.songoda.core.nms.world.WorldCore;
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.server.level.WorldServer;
|
||||
import net.minecraft.util.profiling.GameProfilerFiller;
|
||||
import net.minecraft.world.level.ChunkCoordIntPair;
|
||||
import net.minecraft.world.level.MobSpawnerAbstract;
|
||||
import net.minecraft.world.level.block.state.IBlockData;
|
||||
import net.minecraft.world.level.chunk.Chunk;
|
||||
import net.minecraft.world.level.chunk.ChunkSection;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.CraftChunk;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class WorldCoreImpl implements WorldCore {
|
||||
@Override
|
||||
public SSpawner getSpawner(CreatureSpawner spawner) {
|
||||
return new SSpawnerImpl(spawner.getLocation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SSpawner getSpawner(Location location) {
|
||||
return new SSpawnerImpl(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SItemStack getItemStack(ItemStack item) {
|
||||
return new SItemStackImpl(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SWorld getWorld(World world) {
|
||||
return new SWorldImpl(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BBaseSpawner getBaseSpawner(CreatureSpawner spawner) throws NoSuchFieldException, IllegalAccessException {
|
||||
Object cTileEntity = ReflectionUtils.getFieldValue(spawner, "tileEntity");
|
||||
|
||||
return new BBaseSpawnerImpl(spawner, (MobSpawnerAbstract) ReflectionUtils.getFieldValue(cTileEntity, "a"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method is based on {@link WorldServer#a(Chunk, int)}.
|
||||
*/
|
||||
@Override
|
||||
public void randomTickChunk(org.bukkit.Chunk bukkitChunk, int tickAmount) {
|
||||
Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
|
||||
WorldServer world = chunk.q;
|
||||
|
||||
ChunkCoordIntPair chunkcoordintpair = chunk.f();
|
||||
int j = chunkcoordintpair.d();
|
||||
int k = chunkcoordintpair.e();
|
||||
|
||||
GameProfilerFiller gameprofilerfiller = world.ab();
|
||||
gameprofilerfiller.b("tickBlocks");
|
||||
if (tickAmount > 0) {
|
||||
ChunkSection[] achunksection = chunk.d();
|
||||
int l = achunksection.length;
|
||||
|
||||
for (ChunkSection chunksection : achunksection) {
|
||||
if (chunksection.d()) {
|
||||
int j1 = chunksection.g();
|
||||
|
||||
for (int k1 = 0; k1 < tickAmount; ++k1) {
|
||||
BlockPosition blockposition2 = world.a(j, j1, k, 15);
|
||||
gameprofilerfiller.a("randomTick");
|
||||
IBlockData iblockdata1 = chunksection.a(blockposition2.u() - j, blockposition2.v() - j1, blockposition2.w() - k);
|
||||
if (iblockdata1.o()) {
|
||||
iblockdata1.b(world, blockposition2, world.w);
|
||||
}
|
||||
|
||||
Fluid fluid = iblockdata1.n();
|
||||
if (fluid.f()) {
|
||||
fluid.b(world, blockposition2, world.w);
|
||||
}
|
||||
|
||||
gameprofilerfiller.c();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gameprofilerfiller.c();
|
||||
}
|
||||
}
|
@ -0,0 +1,190 @@
|
||||
package com.songoda.core.nms.v1_18_R1.world.spawner;
|
||||
|
||||
import com.songoda.core.nms.world.BBaseSpawner;
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.server.level.WorldServer;
|
||||
import net.minecraft.world.EnumDifficulty;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityInsentient;
|
||||
import net.minecraft.world.entity.EntityPositionTypes;
|
||||
import net.minecraft.world.entity.EntityTypes;
|
||||
import net.minecraft.world.entity.EnumMobSpawn;
|
||||
import net.minecraft.world.level.EnumSkyBlock;
|
||||
import net.minecraft.world.level.MobSpawnerAbstract;
|
||||
import net.minecraft.world.level.MobSpawnerData;
|
||||
import net.minecraft.world.level.World;
|
||||
import net.minecraft.world.phys.AxisAlignedBB;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.block.CraftCreatureSpawner;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.event.CraftEventFactory;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
|
||||
public class BBaseSpawnerImpl implements BBaseSpawner {
|
||||
private final CreatureSpawner bukkitSpawner;
|
||||
private final MobSpawnerAbstract spawner;
|
||||
|
||||
private static final Random spawnerFieldO = new Random(); // Field o in MobSpawnerAbstract is private - We use one random for *all* our spawners (should be fine, right?)
|
||||
|
||||
public BBaseSpawnerImpl(CreatureSpawner bukkitSpawner, MobSpawnerAbstract spawner) {
|
||||
this.bukkitSpawner = bukkitSpawner;
|
||||
this.spawner = spawner;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is based on {@link MobSpawnerAbstract#b(World, BlockPosition)}.
|
||||
*/
|
||||
@SuppressWarnings("JavadocReference")
|
||||
@Override
|
||||
public boolean isNearPlayer() {
|
||||
BlockPosition bPos = getBlockPosition();
|
||||
|
||||
return getWorld().a((double) bPos.u() + 0.5D, (double) bPos.v() + 0.5D, (double) bPos.w() + 0.5D, this.spawner.m);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is based on {@link MobSpawnerAbstract#a(WorldServer, BlockPosition)}.
|
||||
*/
|
||||
@Override
|
||||
public void tick() {
|
||||
WorldServer world = getWorld();
|
||||
BlockPosition bPos = getBlockPosition();
|
||||
|
||||
if (this.spawner.c == -1) {
|
||||
this.delay(world, bPos);
|
||||
}
|
||||
|
||||
if (this.spawner.c > 0) {
|
||||
--this.spawner.c;
|
||||
return;
|
||||
}
|
||||
|
||||
boolean flag = false;
|
||||
int i = 0;
|
||||
|
||||
while (true) {
|
||||
if (i >= this.spawner.j) {
|
||||
if (flag) {
|
||||
this.delay(world, bPos);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
NBTTagCompound nbttagcompound = this.spawner.e.a();
|
||||
Optional<EntityTypes<?>> optional = EntityTypes.a(nbttagcompound);
|
||||
if (optional.isEmpty()) {
|
||||
this.delay(world, bPos);
|
||||
return;
|
||||
}
|
||||
|
||||
NBTTagList nbttaglist = nbttagcompound.c("Pos", 6);
|
||||
int j = nbttaglist.size();
|
||||
double d0 = j >= 1 ? nbttaglist.h(0) : (double) bPos.u() + (world.w.nextDouble() - world.w.nextDouble()) * (double) this.spawner.n + 0.5D;
|
||||
double d1 = j >= 2 ? nbttaglist.h(1) : (double) (bPos.v() + world.w.nextInt(3) - 1);
|
||||
double d2 = j >= 3 ? nbttaglist.h(2) : (double) bPos.w() + (world.w.nextDouble() - world.w.nextDouble()) * (double) this.spawner.n + 0.5D;
|
||||
if (world.b(optional.get().a(d0, d1, d2))) {
|
||||
label128:
|
||||
{
|
||||
BlockPosition blockposition1 = new BlockPosition(d0, d1, d2);
|
||||
if (this.spawner.e.b().isPresent()) {
|
||||
if (!optional.get().f().d() && world.af() == EnumDifficulty.a) {
|
||||
break label128;
|
||||
}
|
||||
|
||||
MobSpawnerData.a mobspawnerdata_a = this.spawner.e.b().get();
|
||||
if (!mobspawnerdata_a.a().a(world.a(EnumSkyBlock.b, blockposition1)) || !mobspawnerdata_a.b().a(world.a(EnumSkyBlock.a, blockposition1))) {
|
||||
break label128;
|
||||
}
|
||||
} else if (!EntityPositionTypes.a((EntityTypes<?>) optional.get(), world, EnumMobSpawn.c, blockposition1, world.r_())) {
|
||||
break label128;
|
||||
}
|
||||
|
||||
Entity entity = EntityTypes.a(nbttagcompound, world, (entity1) -> {
|
||||
entity1.b(d0, d1, d2, entity1.dm(), entity1.dn());
|
||||
return entity1;
|
||||
});
|
||||
if (entity == null) {
|
||||
this.delay(world, bPos);
|
||||
return;
|
||||
}
|
||||
|
||||
int k = world.a(entity.getClass(), (new AxisAlignedBB(bPos.u(), bPos.v(), bPos.w(), bPos.u() + 1, bPos.v() + 1, bPos.w() + 1)).g(this.spawner.n)).size();
|
||||
if (k >= this.spawner.l) {
|
||||
this.delay(world, bPos);
|
||||
return;
|
||||
}
|
||||
|
||||
entity.b(entity.dc(), entity.de(), entity.di(), world.w.nextFloat() * 360.0F, 0.0F);
|
||||
if (entity instanceof EntityInsentient entityinsentient) {
|
||||
if (this.spawner.e.b().isEmpty() && !entityinsentient.a(world, EnumMobSpawn.c) || !entityinsentient.a(world)) {
|
||||
break label128;
|
||||
}
|
||||
|
||||
if (this.spawner.e.a().e() == 1 && this.spawner.e.a().b("id", 8)) {
|
||||
((EntityInsentient) entity).a(world, world.d_(entity.cW()), EnumMobSpawn.c, null, null);
|
||||
}
|
||||
|
||||
if (entityinsentient.t.spigotConfig.nerfSpawnerMobs) {
|
||||
entityinsentient.aware = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (CraftEventFactory.callSpawnerSpawnEvent(entity, bPos).isCancelled()) {
|
||||
Entity vehicle = entity.cN();
|
||||
if (vehicle != null) {
|
||||
vehicle.ah();
|
||||
}
|
||||
|
||||
for (Entity passenger : entity.cJ()) {
|
||||
passenger.ah();
|
||||
}
|
||||
} else {
|
||||
if (!world.tryAddFreshEntityWithPassengers(entity, CreatureSpawnEvent.SpawnReason.SPAWNER)) {
|
||||
this.delay(world, bPos);
|
||||
return;
|
||||
}
|
||||
|
||||
world.c(2004, bPos, 0);
|
||||
if (entity instanceof EntityInsentient) {
|
||||
((EntityInsentient) entity).L();
|
||||
}
|
||||
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is based on {@link MobSpawnerAbstract#c(World, BlockPosition)}.
|
||||
*/
|
||||
@SuppressWarnings("JavadocReference")
|
||||
private void delay(WorldServer world, BlockPosition bPos) {
|
||||
if (this.spawner.i <= this.spawner.h) {
|
||||
this.spawner.c = this.spawner.h;
|
||||
} else {
|
||||
this.spawner.c = this.spawner.h + spawnerFieldO.nextInt(this.spawner.i - this.spawner.h);
|
||||
}
|
||||
|
||||
this.spawner.d.b(spawnerFieldO).ifPresent((weightedentry_b) -> {
|
||||
this.spawner.a(world, bPos, weightedentry_b.b());
|
||||
});
|
||||
this.spawner.a(world, bPos, 1);
|
||||
}
|
||||
|
||||
private WorldServer getWorld() {
|
||||
return ((CraftWorld) this.bukkitSpawner.getWorld()).getHandle();
|
||||
}
|
||||
|
||||
private BlockPosition getBlockPosition() {
|
||||
return ((CraftCreatureSpawner) this.bukkitSpawner).getPosition();
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.5.14</version>
|
||||
<version>2.6.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.5.14</version>
|
||||
<version>2.6.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.5.14</version>
|
||||
<version>2.6.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.5.14</version>
|
||||
<version>2.6.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.5.14</version>
|
||||
<version>2.6.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
3
pom.xml
3
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>2.5.14</version>
|
||||
<version>2.6.0</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<!-- Run 'mvn versions:set -DgenerateBackupPoms=false -DnewVersion=X.Y.Z' to update version recursively -->
|
||||
@ -44,6 +44,7 @@
|
||||
<module>NMS/NMS-v1_16_R2</module>
|
||||
<module>NMS/NMS-v1_16_R3</module>
|
||||
<module>NMS/NMS-v1_17_R1</module>
|
||||
<module>NMS/NMS-v1_18_R1</module>
|
||||
</modules>
|
||||
|
||||
<issueManagement>
|
||||
|
Loading…
Reference in New Issue
Block a user