Update to Minecraft 1.20.2

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2023-09-22 02:40:00 +10:00
parent 193398c0ff
commit 8a3c8cfcd4
238 changed files with 2448 additions and 2344 deletions

View File

@@ -46,6 +46,7 @@ import java.util.stream.Collectors;
import javax.imageio.ImageIO;
import jline.console.ConsoleReader;
import net.minecraft.advancements.Advancement;
import net.minecraft.advancements.AdvancementHolder;
import net.minecraft.commands.CommandDispatcher;
import net.minecraft.commands.CommandListenerWrapper;
import net.minecraft.commands.arguments.ArgumentEntity;
@@ -95,6 +96,7 @@ import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemWorldMap;
import net.minecraft.world.item.crafting.IRecipe;
import net.minecraft.world.item.crafting.RecipeCrafting;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.item.crafting.RecipeRepair;
import net.minecraft.world.item.crafting.Recipes;
import net.minecraft.world.item.enchantment.Enchantments;
@@ -187,6 +189,7 @@ import org.bukkit.craftbukkit.metadata.PlayerMetadataStore;
import org.bukkit.craftbukkit.metadata.WorldMetadataStore;
import org.bukkit.craftbukkit.packs.CraftDataPackManager;
import org.bukkit.craftbukkit.potion.CraftPotionBrewer;
import org.bukkit.craftbukkit.profile.CraftGameProfile;
import org.bukkit.craftbukkit.profile.CraftPlayerProfile;
import org.bukkit.craftbukkit.scheduler.CraftScheduler;
import org.bukkit.craftbukkit.scoreboard.CraftCriteria;
@@ -1319,7 +1322,7 @@ public final class CraftServer implements Server {
public Recipe getRecipe(NamespacedKey recipeKey) {
Preconditions.checkArgument(recipeKey != null, "NamespacedKey recipeKey cannot be null");
return getServer().getRecipeManager().byKey(CraftNamespacedKey.toMinecraft(recipeKey)).map(IRecipe::toBukkitRecipe).orElse(null);
return getServer().getRecipeManager().byKey(CraftNamespacedKey.toMinecraft(recipeKey)).map(RecipeHolder::toBukkitRecipe).orElse(null);
}
@Override
@@ -1343,7 +1346,7 @@ public final class CraftServer implements Server {
};
InventoryCrafting inventoryCrafting = new TransientCraftingContainer(container, 3, 3);
return getNMSRecipe(craftingMatrix, inventoryCrafting, (CraftWorld) world).map(IRecipe::toBukkitRecipe).orElse(null);
return getNMSRecipe(craftingMatrix, inventoryCrafting, (CraftWorld) world).map(RecipeHolder::toBukkitRecipe).orElse(null);
}
@Override
@@ -1359,20 +1362,20 @@ public final class CraftServer implements Server {
InventoryCrafting inventoryCrafting = container.craftSlots;
InventoryCraftResult craftResult = container.resultSlots;
Optional<RecipeCrafting> recipe = getNMSRecipe(craftingMatrix, inventoryCrafting, craftWorld);
Optional<RecipeHolder<RecipeCrafting>> recipe = getNMSRecipe(craftingMatrix, inventoryCrafting, craftWorld);
// Generate the resulting ItemStack from the Crafting Matrix
net.minecraft.world.item.ItemStack itemstack = net.minecraft.world.item.ItemStack.EMPTY;
if (recipe.isPresent()) {
RecipeCrafting recipeCrafting = recipe.get();
RecipeHolder<RecipeCrafting> recipeCrafting = recipe.get();
if (craftResult.setRecipeUsed(craftWorld.getHandle(), craftPlayer.getHandle(), recipeCrafting)) {
itemstack = recipeCrafting.assemble(inventoryCrafting, craftWorld.getHandle().registryAccess());
itemstack = recipeCrafting.value().assemble(inventoryCrafting, craftWorld.getHandle().registryAccess());
}
}
// Call Bukkit event to check for matrix/result changes.
net.minecraft.world.item.ItemStack result = CraftEventFactory.callPreCraftEvent(inventoryCrafting, craftResult, itemstack, container.getBukkitView(), recipe.orElse(null) instanceof RecipeRepair);
net.minecraft.world.item.ItemStack result = CraftEventFactory.callPreCraftEvent(inventoryCrafting, craftResult, itemstack, container.getBukkitView(), recipe.map(RecipeHolder::toBukkitRecipe).orElse(null) instanceof RecipeRepair);
// Set the resulting matrix items
for (int i = 0; i < craftingMatrix.length; i++) {
@@ -1383,7 +1386,7 @@ public final class CraftServer implements Server {
return CraftItemStack.asBukkitCopy(result);
}
private Optional<RecipeCrafting> getNMSRecipe(ItemStack[] craftingMatrix, InventoryCrafting inventoryCrafting, CraftWorld world) {
private Optional<RecipeHolder<RecipeCrafting>> getNMSRecipe(ItemStack[] craftingMatrix, InventoryCrafting inventoryCrafting, CraftWorld world) {
Preconditions.checkArgument(craftingMatrix != null, "craftingMatrix must not be null");
Preconditions.checkArgument(craftingMatrix.length == 9, "craftingMatrix must be an array of length 9");
Preconditions.checkArgument(world != null, "world must not be null");
@@ -1673,7 +1676,7 @@ public final class CraftServer implements Server {
if (result == null) {
result = offlinePlayers.get(id);
if (result == null) {
result = new CraftOfflinePlayer(this, new GameProfile(id, null));
result = new CraftOfflinePlayer(this, new CraftGameProfile(id, null));
offlinePlayers.put(id, result);
}
} else {
@@ -2198,16 +2201,16 @@ public final class CraftServer implements Server {
public org.bukkit.advancement.Advancement getAdvancement(NamespacedKey key) {
Preconditions.checkArgument(key != null, "NamespacedKey key cannot be null");
Advancement advancement = console.getAdvancements().getAdvancement(CraftNamespacedKey.toMinecraft(key));
return (advancement == null) ? null : advancement.bukkit;
AdvancementHolder advancement = console.getAdvancements().get(CraftNamespacedKey.toMinecraft(key));
return (advancement == null) ? null : advancement.toBukkit();
}
@Override
public Iterator<org.bukkit.advancement.Advancement> advancementIterator() {
return Iterators.unmodifiableIterator(Iterators.transform(console.getAdvancements().getAllAdvancements().iterator(), new Function<Advancement, org.bukkit.advancement.Advancement>() {
return Iterators.unmodifiableIterator(Iterators.transform(console.getAdvancements().getAllAdvancements().iterator(), new Function<AdvancementHolder, org.bukkit.advancement.Advancement>() {
@Override
public org.bukkit.advancement.Advancement apply(Advancement advancement) {
return advancement.bukkit;
public org.bukkit.advancement.Advancement apply(AdvancementHolder advancement) {
return advancement.toBukkit();
}
}));
}

View File

@@ -200,11 +200,11 @@ public class Main {
useConsole = false;
}
if (false && Main.class.getPackage().getImplementationVendor() != null && System.getProperty("IReallyKnowWhatIAmDoingISwear") == null) {
if (Main.class.getPackage().getImplementationVendor() != null && System.getProperty("IReallyKnowWhatIAmDoingISwear") == null) {
Date buildDate = new Date(Integer.parseInt(Main.class.getPackage().getImplementationVendor()) * 1000L);
Calendar deadline = Calendar.getInstance();
deadline.add(Calendar.DAY_OF_YEAR, -21);
deadline.add(Calendar.DAY_OF_YEAR, -3);
if (buildDate.before(deadline.getTime())) {
System.err.println("*** Error, this build is outdated ***");
System.err.println("*** Please download a new build as per instructions from https://www.spigotmc.org/go/outdated-spigot ***");

View File

@@ -2,39 +2,39 @@ package org.bukkit.craftbukkit.advancement;
import java.util.Collection;
import java.util.Collections;
import net.minecraft.advancements.Advancement;
import net.minecraft.advancements.AdvancementHolder;
import org.bukkit.NamespacedKey;
import org.bukkit.advancement.AdvancementDisplay;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
public class CraftAdvancement implements org.bukkit.advancement.Advancement {
private final Advancement handle;
private final AdvancementHolder handle;
public CraftAdvancement(Advancement handle) {
public CraftAdvancement(AdvancementHolder handle) {
this.handle = handle;
}
public Advancement getHandle() {
public AdvancementHolder getHandle() {
return handle;
}
@Override
public NamespacedKey getKey() {
return CraftNamespacedKey.fromMinecraft(handle.getId());
return CraftNamespacedKey.fromMinecraft(handle.id());
}
@Override
public Collection<String> getCriteria() {
return Collections.unmodifiableCollection(handle.getCriteria().keySet());
return Collections.unmodifiableCollection(handle.value().criteria().keySet());
}
@Override
public AdvancementDisplay getDisplay() {
if (handle.getDisplay() == null) {
if (handle.value().display().isEmpty()) {
return null;
}
return new CraftAdvancementDisplay(handle.getDisplay());
return new CraftAdvancementDisplay(handle.value().display().get());
}
}

View File

@@ -44,7 +44,7 @@ public class CraftAdvancementProgress implements AdvancementProgress {
@Override
public Date getDateAwarded(String criteria) {
CriterionProgress criterion = handle.getCriterion(criteria);
return (criterion == null) ? null : criterion.getObtained();
return (criterion == null) ? null : Date.from(criterion.getObtained());
}
@Override

View File

@@ -1,15 +1,14 @@
package org.bukkit.craftbukkit.block;
import com.google.common.base.Preconditions;
import java.util.ArrayList;
import java.util.Collection;
import net.minecraft.world.ChestLock;
import net.minecraft.world.effect.MobEffectList;
import net.minecraft.world.entity.player.EntityHuman;
import net.minecraft.world.level.block.entity.TileEntity;
import net.minecraft.world.level.block.entity.TileEntityBeacon;
import org.bukkit.World;
import org.bukkit.block.Beacon;
import org.bukkit.craftbukkit.potion.CraftPotionEffectType;
import org.bukkit.craftbukkit.util.CraftChatMessage;
import org.bukkit.entity.LivingEntity;
import org.bukkit.potion.PotionEffect;
@@ -55,7 +54,7 @@ public class CraftBeacon extends CraftBlockEntityState<TileEntityBeacon> impleme
@Override
public void setPrimaryEffect(PotionEffectType effect) {
this.getSnapshot().primaryPower = (effect != null) ? MobEffectList.byId(effect.getId()) : null;
this.getSnapshot().primaryPower = (effect != null) ? CraftPotionEffectType.bukkitToMinecraft(effect) : null;
}
@Override
@@ -65,7 +64,7 @@ public class CraftBeacon extends CraftBlockEntityState<TileEntityBeacon> impleme
@Override
public void setSecondaryEffect(PotionEffectType effect) {
this.getSnapshot().secondaryPower = (effect != null) ? MobEffectList.byId(effect.getId()) : null;
this.getSnapshot().secondaryPower = (effect != null) ? CraftPotionEffectType.bukkitToMinecraft(effect) : null;
}
@Override

View File

@@ -26,13 +26,13 @@ public class CraftDecoratedPot extends CraftBlockEntityState<DecoratedPotBlockEn
Preconditions.checkArgument(sherd == null || sherd == Material.BRICK || Tag.ITEMS_DECORATED_POT_SHERDS.isTagged(sherd), "sherd is not a valid sherd material: %s", sherd);
Item sherdItem = (sherd != null) ? CraftMagicNumbers.getItem(sherd) : Items.BRICK;
DecoratedPotBlockEntity.a decorations = getSnapshot().getDecorations(); // PAIL rename Decorations
DecoratedPotBlockEntity.Decoration decorations = getSnapshot().getDecorations();
switch (face) {
case BACK -> getSnapshot().decorations = new DecoratedPotBlockEntity.a(sherdItem, decorations.left(), decorations.right(), decorations.front());
case LEFT -> getSnapshot().decorations = new DecoratedPotBlockEntity.a(decorations.back(), sherdItem, decorations.right(), decorations.front());
case RIGHT -> getSnapshot().decorations = new DecoratedPotBlockEntity.a(decorations.back(), decorations.left(), sherdItem, decorations.front());
case FRONT -> getSnapshot().decorations = new DecoratedPotBlockEntity.a(decorations.back(), decorations.left(), decorations.right(), sherdItem);
case BACK -> getSnapshot().decorations = new DecoratedPotBlockEntity.Decoration(sherdItem, decorations.left(), decorations.right(), decorations.front());
case LEFT -> getSnapshot().decorations = new DecoratedPotBlockEntity.Decoration(decorations.back(), sherdItem, decorations.right(), decorations.front());
case RIGHT -> getSnapshot().decorations = new DecoratedPotBlockEntity.Decoration(decorations.back(), decorations.left(), sherdItem, decorations.front());
case FRONT -> getSnapshot().decorations = new DecoratedPotBlockEntity.Decoration(decorations.back(), decorations.left(), decorations.right(), sherdItem);
default -> throw new IllegalArgumentException("Unexpected value: " + face);
}
}
@@ -41,7 +41,7 @@ public class CraftDecoratedPot extends CraftBlockEntityState<DecoratedPotBlockEn
public Material getSherd(Side face) {
Preconditions.checkArgument(face != null, "face must not be null");
DecoratedPotBlockEntity.a decorations = getSnapshot().getDecorations(); // PAIL rename Decorations
DecoratedPotBlockEntity.Decoration decorations = getSnapshot().getDecorations();
Item sherdItem = switch (face) {
case BACK -> decorations.back();
case LEFT -> decorations.left();
@@ -55,7 +55,7 @@ public class CraftDecoratedPot extends CraftBlockEntityState<DecoratedPotBlockEn
@Override
public Map<Side, Material> getSherds() {
DecoratedPotBlockEntity.a decorations = getSnapshot().getDecorations(); // PAIL rename Decorations
DecoratedPotBlockEntity.Decoration decorations = getSnapshot().getDecorations();
Map<Side, Material> sherds = new EnumMap<>(Side.class);
sherds.put(Side.BACK, CraftMagicNumbers.getMaterial(decorations.back()));

View File

@@ -1,6 +1,5 @@
package org.bukkit.craftbukkit.block;
import com.google.common.base.Preconditions;
import net.minecraft.world.level.block.BlockDispenser;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.TileEntityDispenser;
@@ -53,7 +52,7 @@ public class CraftDispenser extends CraftLootable<TileEntityDispenser> implement
CraftWorld world = (CraftWorld) this.getWorld();
BlockDispenser dispense = (BlockDispenser) Blocks.DISPENSER;
dispense.dispenseFrom(world.getHandle(), this.getPosition());
dispense.dispenseFrom(world.getHandle(), this.getHandle(), this.getPosition());
return true;
} else {
return false;

View File

@@ -1,6 +1,5 @@
package org.bukkit.craftbukkit.block;
import com.google.common.base.Preconditions;
import net.minecraft.world.level.block.BlockDropper;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.TileEntityDropper;
@@ -40,7 +39,7 @@ public class CraftDropper extends CraftLootable<TileEntityDropper> implements Dr
CraftWorld world = (CraftWorld) this.getWorld();
BlockDropper drop = (BlockDropper) Blocks.DROPPER;
drop.dispenseFrom(world.getHandle(), this.getPosition());
drop.dispenseFrom(world.getHandle(), this.getHandle(), this.getPosition());
}
}
}

View File

@@ -16,6 +16,7 @@ import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Directional;
import org.bukkit.block.data.Rotatable;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.craftbukkit.profile.CraftGameProfile;
import org.bukkit.craftbukkit.profile.CraftPlayerProfile;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.profile.PlayerProfile;
@@ -102,7 +103,7 @@ public class CraftSkull extends CraftBlockEntityState<TileEntitySkull> implement
if (player instanceof CraftPlayer) {
this.profile = ((CraftPlayer) player).getProfile();
} else {
this.profile = new GameProfile(player.getUniqueId(), player.getName());
this.profile = new CraftGameProfile(player.getUniqueId(), player.getName());
}
}

View File

@@ -13,6 +13,7 @@ import org.bukkit.Color;
import org.bukkit.Particle;
import org.bukkit.craftbukkit.CraftParticle;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.potion.CraftPotionEffectType;
import org.bukkit.craftbukkit.potion.CraftPotionUtil;
import org.bukkit.entity.AreaEffectCloud;
import org.bukkit.entity.LivingEntity;
@@ -134,10 +135,10 @@ public class CraftAreaEffectCloud extends CraftEntity implements AreaEffectCloud
@Override
public boolean addCustomEffect(PotionEffect effect, boolean override) {
int effectId = effect.getType().getId();
MobEffectList minecraft = CraftPotionEffectType.bukkitToMinecraft(effect.getType());
MobEffect existing = null;
for (MobEffect mobEffect : getHandle().effects) {
if (MobEffectList.getId(mobEffect.getEffect()) == effectId) {
if (mobEffect.getEffect() == minecraft) {
existing = mobEffect;
}
}
@@ -184,10 +185,10 @@ public class CraftAreaEffectCloud extends CraftEntity implements AreaEffectCloud
@Override
public boolean removeCustomEffect(PotionEffectType effect) {
int effectId = effect.getId();
MobEffectList minecraft = CraftPotionEffectType.bukkitToMinecraft(effect);
MobEffect existing = null;
for (MobEffect mobEffect : getHandle().effects) {
if (MobEffectList.getId(mobEffect.getEffect()) == effectId) {
if (mobEffect.getEffect() == minecraft) {
existing = mobEffect;
}
}

View File

@@ -45,12 +45,12 @@ public class CraftDisplay extends CraftEntity implements Display {
@Override
public int getInterpolationDuration() {
return getHandle().getInterpolationDuration();
return getHandle().getTransformationInterpolationDuration();
}
@Override
public void setInterpolationDuration(int duration) {
getHandle().setInterpolationDuration(duration);
getHandle().setTransformationInterpolationDuration(duration);
}
@Override
@@ -105,12 +105,12 @@ public class CraftDisplay extends CraftEntity implements Display {
@Override
public int getInterpolationDelay() {
return getHandle().getInterpolationDelay();
return getHandle().getTransformationInterpolationDelay();
}
@Override
public void setInterpolationDelay(int ticks) {
getHandle().setInterpolationDelay(ticks);
getHandle().setTransformationInterpolationDelay(ticks);
}
@Override

View File

@@ -7,7 +7,6 @@ import com.google.common.collect.Lists;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import net.minecraft.core.Position;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.chat.IChatBaseComponent;
@@ -545,7 +544,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
if (location.getWorld() != null && !location.getWorld().equals(getWorld())) {
// Prevent teleportation to an other world during world generation
Preconditions.checkState(!entity.generation, "Cannot teleport entity to an other world during world generation");
entity.teleportTo(((CraftWorld) location.getWorld()).getHandle(), CraftLocation.toPosition(location));
entity.teleportTo(((CraftWorld) location.getWorld()).getHandle(), CraftLocation.toVec3D(location));
return true;
}

View File

@@ -24,6 +24,7 @@ import net.minecraft.world.inventory.Containers;
import net.minecraft.world.item.ItemCooldown;
import net.minecraft.world.item.crafting.CraftingManager;
import net.minecraft.world.item.crafting.IRecipe;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.item.trading.IMerchant;
import net.minecraft.world.level.block.BlockBed;
import net.minecraft.world.level.block.BlockEnchantmentTable;
@@ -540,12 +541,12 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
return ImmutableSet.of();
}
private Collection<IRecipe<?>> bukkitKeysToMinecraftRecipes(Collection<NamespacedKey> recipeKeys) {
Collection<IRecipe<?>> recipes = new ArrayList<>();
private Collection<RecipeHolder<?>> bukkitKeysToMinecraftRecipes(Collection<NamespacedKey> recipeKeys) {
Collection<RecipeHolder<?>> recipes = new ArrayList<>();
CraftingManager manager = getHandle().level().getServer().getRecipeManager();
for (NamespacedKey recipeKey : recipeKeys) {
Optional<? extends IRecipe<?>> recipe = manager.byKey(CraftNamespacedKey.toMinecraft(recipeKey));
Optional<? extends RecipeHolder<?>> recipe = manager.byKey(CraftNamespacedKey.toMinecraft(recipeKey));
if (!recipe.isPresent()) {
continue;
}

View File

@@ -56,6 +56,7 @@ import org.bukkit.craftbukkit.entity.memory.CraftMemoryKey;
import org.bukkit.craftbukkit.entity.memory.CraftMemoryMapper;
import org.bukkit.craftbukkit.inventory.CraftEntityEquipment;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.potion.CraftPotionEffectType;
import org.bukkit.craftbukkit.potion.CraftPotionUtil;
import org.bukkit.entity.AbstractArrow;
import org.bukkit.entity.Arrow;
@@ -373,7 +374,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
@Override
public boolean addPotionEffect(PotionEffect effect, boolean force) {
getHandle().addEffect(new MobEffect(MobEffectList.byId(effect.getType().getId()), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles()), EntityPotionEffectEvent.Cause.PLUGIN);
getHandle().addEffect(new MobEffect(CraftPotionEffectType.bukkitToMinecraft(effect.getType()), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles()), EntityPotionEffectEvent.Cause.PLUGIN);
return true;
}
@@ -388,25 +389,25 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
@Override
public boolean hasPotionEffect(PotionEffectType type) {
return getHandle().hasEffect(MobEffectList.byId(type.getId()));
return getHandle().hasEffect(CraftPotionEffectType.bukkitToMinecraft(type));
}
@Override
public PotionEffect getPotionEffect(PotionEffectType type) {
MobEffect handle = getHandle().getEffect(MobEffectList.byId(type.getId()));
return (handle == null) ? null : new PotionEffect(PotionEffectType.getById(MobEffectList.getId(handle.getEffect())), handle.getDuration(), handle.getAmplifier(), handle.isAmbient(), handle.isVisible());
MobEffect handle = getHandle().getEffect(CraftPotionEffectType.bukkitToMinecraft(type));
return (handle == null) ? null : new PotionEffect(CraftPotionEffectType.minecraftToBukkit(handle.getEffect()), handle.getDuration(), handle.getAmplifier(), handle.isAmbient(), handle.isVisible());
}
@Override
public void removePotionEffect(PotionEffectType type) {
getHandle().removeEffect(MobEffectList.byId(type.getId()), EntityPotionEffectEvent.Cause.PLUGIN);
getHandle().removeEffect(CraftPotionEffectType.bukkitToMinecraft(type), EntityPotionEffectEvent.Cause.PLUGIN);
}
@Override
public Collection<PotionEffect> getActivePotionEffects() {
List<PotionEffect> effects = new ArrayList<PotionEffect>();
for (MobEffect handle : getHandle().activeEffects.values()) {
effects.add(new PotionEffect(PotionEffectType.getById(MobEffectList.getId(handle.getEffect())), handle.getDuration(), handle.getAmplifier(), handle.isAmbient(), handle.isVisible()));
effects.add(new PotionEffect(CraftPotionEffectType.minecraftToBukkit(handle.getEffect()), handle.getDuration(), handle.getAmplifier(), handle.isAmbient(), handle.isVisible()));
}
return effects;
}

View File

@@ -41,6 +41,9 @@ import net.minecraft.network.PacketDataSerializer;
import net.minecraft.network.chat.IChatBaseComponent;
import net.minecraft.network.chat.PlayerChatMessage;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
import net.minecraft.network.protocol.common.ClientboundResourcePackPacket;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.network.protocol.game.ClientboundClearTitlesPacket;
import net.minecraft.network.protocol.game.ClientboundCustomChatCompletionsPacket;
import net.minecraft.network.protocol.game.ClientboundHurtAnimationPacket;
@@ -56,7 +59,6 @@ import net.minecraft.network.protocol.game.ClientboundSetTitleTextPacket;
import net.minecraft.network.protocol.game.ClientboundSetTitlesAnimationPacket;
import net.minecraft.network.protocol.game.PacketPlayOutBlockBreakAnimation;
import net.minecraft.network.protocol.game.PacketPlayOutBlockChange;
import net.minecraft.network.protocol.game.PacketPlayOutCustomPayload;
import net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment;
import net.minecraft.network.protocol.game.PacketPlayOutEntitySound;
import net.minecraft.network.protocol.game.PacketPlayOutExperience;
@@ -1659,12 +1661,26 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
if (getHandle().connection == null) return;
if (channels.contains(channel)) {
channel = StandardMessenger.validateAndCorrectChannel(channel);
PacketPlayOutCustomPayload packet = new PacketPlayOutCustomPayload(new MinecraftKey(channel), new PacketDataSerializer(Unpooled.wrappedBuffer(message)));
getHandle().connection.send(packet);
MinecraftKey id = new MinecraftKey(StandardMessenger.validateAndCorrectChannel(channel));
sendCustomPayload(id, message);
}
}
private void sendCustomPayload(MinecraftKey id, byte[] message) {
ClientboundCustomPayloadPacket packet = new ClientboundCustomPayloadPacket(new CustomPacketPayload() {
@Override
public void write(PacketDataSerializer pds) {
pds.writeBytes(message);
}
@Override
public MinecraftKey id() {
return id;
}
});
getHandle().connection.send(packet);
}
@Override
public void setTexturePack(String url) {
setResourcePack(url);
@@ -1697,9 +1713,9 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
if (hash != null) {
Preconditions.checkArgument(hash.length == 20, "Resource pack hash should be 20 bytes long but was %s", hash.length);
getHandle().sendTexturePack(url, BaseEncoding.base16().lowerCase().encode(hash), force, CraftChatMessage.fromStringOrNull(prompt, true));
getHandle().connection.send(new ClientboundResourcePackPacket(url, BaseEncoding.base16().lowerCase().encode(hash), force, CraftChatMessage.fromStringOrNull(prompt, true)));
} else {
getHandle().sendTexturePack(url, "", force, CraftChatMessage.fromStringOrNull(prompt, true));
getHandle().connection.send(new ClientboundResourcePackPacket(url, "", force, CraftChatMessage.fromStringOrNull(prompt, true)));
}
}
@@ -1739,7 +1755,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
}
getHandle().connection.send(new PacketPlayOutCustomPayload(new MinecraftKey("register"), new PacketDataSerializer(Unpooled.wrappedBuffer(stream.toByteArray()))));
sendCustomPayload(new MinecraftKey("register"), stream.toByteArray());
}
}
@@ -2085,17 +2101,17 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@Override
public int getClientViewDistance() {
return (getHandle().clientViewDistance == null) ? Bukkit.getViewDistance() : getHandle().clientViewDistance;
return (getHandle().requestedViewDistance() == 0) ? Bukkit.getViewDistance() : getHandle().requestedViewDistance();
}
@Override
public int getPing() {
return getHandle().latency;
return getHandle().connection.latency();
}
@Override
public String getLocale() {
return getHandle().locale;
return getHandle().language;
}
@Override

View File

@@ -10,6 +10,7 @@ import net.minecraft.world.effect.MobEffectList;
import net.minecraft.world.entity.projectile.EntityTippedArrow;
import org.bukkit.Color;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.potion.CraftPotionEffectType;
import org.bukkit.craftbukkit.potion.CraftPotionUtil;
import org.bukkit.entity.Arrow;
import org.bukkit.potion.PotionData;
@@ -34,10 +35,10 @@ public class CraftTippedArrow extends CraftArrow implements Arrow {
@Override
public boolean addCustomEffect(PotionEffect effect, boolean override) {
int effectId = effect.getType().getId();
MobEffectList minecraft = CraftPotionEffectType.bukkitToMinecraft(effect.getType());
MobEffect existing = null;
for (MobEffect mobEffect : getHandle().effects) {
if (MobEffectList.getId(mobEffect.getEffect()) == effectId) {
if (mobEffect.getEffect() == minecraft) {
existing = mobEffect;
}
}
@@ -84,10 +85,10 @@ public class CraftTippedArrow extends CraftArrow implements Arrow {
@Override
public boolean removeCustomEffect(PotionEffectType effect) {
int effectId = effect.getId();
MobEffectList minecraft = CraftPotionEffectType.bukkitToMinecraft(effect);
MobEffect existing = null;
for (MobEffect mobEffect : getHandle().effects) {
if (MobEffectList.getId(mobEffect.getEffect()) == effectId) {
if (mobEffect.getEffect() == minecraft) {
existing = mobEffect;
}
}

View File

@@ -6,6 +6,8 @@ import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.mojang.datafixers.util.Either;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumMap;
@@ -899,9 +901,9 @@ public class CraftEventFactory {
/**
* Server methods
*/
public static ServerListPingEvent callServerListPingEvent(Server craftServer, InetAddress address, String motd, int numPlayers, int maxPlayers) {
ServerListPingEvent event = new ServerListPingEvent("", address, motd, numPlayers, maxPlayers);
craftServer.getPluginManager().callEvent(event);
public static ServerListPingEvent callServerListPingEvent(SocketAddress address, String motd, int numPlayers, int maxPlayers) {
ServerListPingEvent event = new ServerListPingEvent("", ((InetSocketAddress) address).getAddress(), motd, numPlayers, maxPlayers);
Bukkit.getServer().getPluginManager().callEvent(event);
return event;
}

View File

@@ -1,6 +1,7 @@
package org.bukkit.craftbukkit.inventory;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.item.crafting.RecipeHolder;
import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.inventory.BlastingRecipe;
@@ -26,6 +27,6 @@ public class CraftBlastingRecipe extends BlastingRecipe implements CraftRecipe {
public void addToCraftingManager() {
ItemStack result = this.getResult();
MinecraftServer.getServer().getRecipeManager().addRecipe(new net.minecraft.world.item.crafting.RecipeBlasting(CraftNamespacedKey.toMinecraft(this.getKey()), this.getGroup(), CraftRecipe.getCategory(this.getCategory()), toNMS(this.getInputChoice(), true), CraftItemStack.asNMSCopy(result), getExperience(), getCookingTime()));
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.RecipeBlasting(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), toNMS(this.getInputChoice(), true), CraftItemStack.asNMSCopy(result), getExperience(), getCookingTime())));
}
}

View File

@@ -1,6 +1,7 @@
package org.bukkit.craftbukkit.inventory;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.item.crafting.RecipeHolder;
import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.inventory.CampfireRecipe;
@@ -26,6 +27,6 @@ public class CraftCampfireRecipe extends CampfireRecipe implements CraftRecipe {
public void addToCraftingManager() {
ItemStack result = this.getResult();
MinecraftServer.getServer().getRecipeManager().addRecipe(new net.minecraft.world.item.crafting.RecipeCampfire(CraftNamespacedKey.toMinecraft(this.getKey()), this.getGroup(), CraftRecipe.getCategory(this.getCategory()), toNMS(this.getInputChoice(), true), CraftItemStack.asNMSCopy(result), getExperience(), getCookingTime()));
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.RecipeCampfire(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), toNMS(this.getInputChoice(), true), CraftItemStack.asNMSCopy(result), getExperience(), getCookingTime())));
}
}

View File

@@ -3,6 +3,7 @@ package org.bukkit.craftbukkit.inventory;
import net.minecraft.core.IRegistryCustom;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.item.crafting.IRecipeComplex;
import net.minecraft.world.item.crafting.RecipeHolder;
import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.inventory.ComplexRecipe;
@@ -10,9 +11,11 @@ import org.bukkit.inventory.ItemStack;
public class CraftComplexRecipe implements CraftRecipe, ComplexRecipe {
private final NamespacedKey key;
private final IRecipeComplex recipe;
public CraftComplexRecipe(IRecipeComplex recipe) {
public CraftComplexRecipe(NamespacedKey key, IRecipeComplex recipe) {
this.key = key;
this.recipe = recipe;
}
@@ -23,11 +26,11 @@ public class CraftComplexRecipe implements CraftRecipe, ComplexRecipe {
@Override
public NamespacedKey getKey() {
return CraftNamespacedKey.fromMinecraft(recipe.getId());
return key;
}
@Override
public void addToCraftingManager() {
MinecraftServer.getServer().getRecipeManager().addRecipe(recipe);
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(key), recipe));
}
}

View File

@@ -1,6 +1,7 @@
package org.bukkit.craftbukkit.inventory;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.item.crafting.RecipeHolder;
import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.inventory.FurnaceRecipe;
@@ -26,6 +27,6 @@ public class CraftFurnaceRecipe extends FurnaceRecipe implements CraftRecipe {
public void addToCraftingManager() {
ItemStack result = this.getResult();
MinecraftServer.getServer().getRecipeManager().addRecipe(new net.minecraft.world.item.crafting.FurnaceRecipe(CraftNamespacedKey.toMinecraft(this.getKey()), this.getGroup(), CraftRecipe.getCategory(this.getCategory()), toNMS(this.getInputChoice(), true), CraftItemStack.asNMSCopy(result), getExperience(), getCookingTime()));
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.FurnaceRecipe(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), toNMS(this.getInputChoice(), true), CraftItemStack.asNMSCopy(result), getExperience(), getCookingTime())));
}
}

View File

@@ -4,7 +4,7 @@ import com.google.common.base.Preconditions;
import java.util.Arrays;
import java.util.List;
import net.minecraft.world.IInventory;
import net.minecraft.world.item.crafting.IRecipe;
import net.minecraft.world.item.crafting.RecipeHolder;
import org.bukkit.inventory.CraftingInventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
@@ -115,7 +115,7 @@ public class CraftInventoryCrafting extends CraftInventory implements CraftingIn
@Override
public Recipe getRecipe() {
IRecipe recipe = getInventory().getCurrentRecipe();
RecipeHolder<?> recipe = getInventory().getCurrentRecipe();
return recipe == null ? null : recipe.toBukkitRecipe();
}
}

View File

@@ -2,7 +2,7 @@ package org.bukkit.craftbukkit.inventory;
import net.minecraft.world.IInventory;
import net.minecraft.world.inventory.InventoryCraftResult;
import net.minecraft.world.item.crafting.IRecipe;
import net.minecraft.world.item.crafting.RecipeHolder;
import org.bukkit.Location;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
@@ -39,7 +39,7 @@ public class CraftInventorySmithing extends CraftResultInventory implements Smit
@Override
public Recipe getRecipe() {
IRecipe recipe = getResultInventory().getRecipeUsed();
RecipeHolder<?> recipe = getResultInventory().getRecipeUsed();
return (recipe == null) ? null : recipe.toBukkitRecipe();
}
}

View File

@@ -13,6 +13,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.configuration.serialization.DelegateDeserialization;
import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta;
import org.bukkit.craftbukkit.potion.CraftPotionUtil;
@@ -33,14 +34,14 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
Material.TIPPED_ARROW
);
static final ItemMetaKey AMPLIFIER = new ItemMetaKey("Amplifier", "amplifier");
static final ItemMetaKey AMBIENT = new ItemMetaKey("Ambient", "ambient");
static final ItemMetaKey DURATION = new ItemMetaKey("Duration", "duration");
static final ItemMetaKey SHOW_PARTICLES = new ItemMetaKey("ShowParticles", "has-particles");
static final ItemMetaKey SHOW_ICON = new ItemMetaKey("ShowIcon", "has-icon");
static final ItemMetaKey POTION_EFFECTS = new ItemMetaKey("CustomPotionEffects", "custom-effects");
static final ItemMetaKey AMPLIFIER = new ItemMetaKey("amplifier", "amplifier");
static final ItemMetaKey AMBIENT = new ItemMetaKey("ambient", "ambient");
static final ItemMetaKey DURATION = new ItemMetaKey("duration", "duration");
static final ItemMetaKey SHOW_PARTICLES = new ItemMetaKey("show_particles", "has-particles");
static final ItemMetaKey SHOW_ICON = new ItemMetaKey("show_icon", "has-icon");
static final ItemMetaKey POTION_EFFECTS = new ItemMetaKey("custom_potion_effects", "custom-effects");
static final ItemMetaKey POTION_COLOR = new ItemMetaKey("CustomPotionColor", "custom-color");
static final ItemMetaKey ID = new ItemMetaKey("Id", "potion-id");
static final ItemMetaKey ID = new ItemMetaKey("id", "potion-id");
static final ItemMetaKey DEFAULT_POTION = new ItemMetaKey("Potion", "potion-type");
// Having an initial "state" in ItemMeta seems bit dirty but the UNCRAFTABLE potion type
@@ -80,7 +81,7 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
for (int i = 0; i < length; i++) {
NBTTagCompound effect = list.getCompound(i);
PotionEffectType type = PotionEffectType.getById(effect.getByte(ID.NBT));
PotionEffectType type = PotionEffectType.getByKey(NamespacedKey.fromString(effect.getString(ID.NBT)));
// SPIGOT-4047: Vanilla just disregards these
if (type == null) {
continue;
@@ -132,7 +133,7 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
for (PotionEffect effect : customEffects) {
NBTTagCompound effectData = new NBTTagCompound();
effectData.putByte(ID.NBT, (byte) effect.getType().getId());
effectData.putString(ID.NBT, effect.getType().getKey().toString());
effectData.putByte(AMPLIFIER.NBT, (byte) effect.getAmplifier());
effectData.putInt(DURATION.NBT, effect.getDuration());
effectData.putBoolean(AMBIENT.NBT, effect.isAmbient());

View File

@@ -18,6 +18,7 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.serialization.DelegateDeserialization;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta;
import org.bukkit.craftbukkit.profile.CraftGameProfile;
import org.bukkit.craftbukkit.profile.CraftPlayerProfile;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
@@ -74,7 +75,7 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
if (tag.contains(SKULL_OWNER.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND)) {
this.setProfile(GameProfileSerializer.readGameProfile(tag.getCompound(SKULL_OWNER.NBT)));
} else if (tag.contains(SKULL_OWNER.NBT, CraftMagicNumbers.NBT.TAG_STRING) && !tag.getString(SKULL_OWNER.NBT).isEmpty()) {
this.setProfile(new GameProfile(null, tag.getString(SKULL_OWNER.NBT)));
this.setProfile(new CraftGameProfile(null, tag.getString(SKULL_OWNER.NBT)));
}
if (tag.contains(BLOCK_ENTITY_TAG.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND)) {
@@ -142,9 +143,11 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
// SPIGOT-6558: Set initial textures
tag.put(SKULL_OWNER.NBT, serializedProfile);
// Fill in textures
TileEntitySkull.updateGameprofile(profile, (filledProfile) -> {
setProfile(filledProfile);
tag.put(SKULL_OWNER.NBT, serializedProfile);
TileEntitySkull.fillProfileTextures(profile).thenAccept((optional) -> {
optional.ifPresent((filledProfile) -> {
setProfile(filledProfile);
tag.put(SKULL_OWNER.NBT, serializedProfile);
});
});
}
@@ -208,7 +211,7 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
if (name == null) {
setProfile(null);
} else {
setProfile(new GameProfile(null, name));
setProfile(new CraftGameProfile(null, name));
}
return true;
@@ -221,7 +224,7 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
} else if (owner instanceof CraftPlayer) {
setProfile(((CraftPlayer) owner).getProfile());
} else {
setProfile(new GameProfile(owner.getUniqueId(), owner.getName()));
setProfile(new CraftGameProfile(owner.getUniqueId(), owner.getName()));
}
return true;

View File

@@ -10,6 +10,7 @@ import java.util.Map;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.configuration.serialization.DelegateDeserialization;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.inventory.meta.SuspiciousStewMeta;
@@ -21,7 +22,7 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious
static final ItemMetaKey DURATION = new ItemMetaKey("EffectDuration", "duration");
static final ItemMetaKey EFFECTS = new ItemMetaKey("Effects", "effects");
static final ItemMetaKey ID = new ItemMetaKey("EffectId", "id");
static final ItemMetaKey ID = new ItemMetaKey("id", "id");
private List<PotionEffect> customEffects;
@@ -44,7 +45,7 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious
for (int i = 0; i < length; i++) {
NBTTagCompound effect = list.getCompound(i);
PotionEffectType type = PotionEffectType.getById(effect.getByte(ID.NBT));
PotionEffectType type = PotionEffectType.getByKey(NamespacedKey.fromString(effect.getString(ID.NBT)));
if (type == null) {
continue;
}
@@ -78,7 +79,7 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious
for (PotionEffect effect : customEffects) {
NBTTagCompound effectData = new NBTTagCompound();
effectData.putByte(ID.NBT, ((byte) effect.getType().getId()));
effectData.putString(ID.NBT, effect.getType().getKey().toString());
effectData.putInt(DURATION.NBT, effect.getDuration());
effectList.add(effectData);
}

View File

@@ -3,7 +3,7 @@ package org.bukkit.craftbukkit.inventory;
import java.util.Map;
import net.minecraft.core.NonNullList;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.item.crafting.CraftingBookCategory;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.item.crafting.RecipeItemStack;
import net.minecraft.world.item.crafting.ShapedRecipes;
import org.bukkit.NamespacedKey;
@@ -20,8 +20,8 @@ public class CraftShapedRecipe extends ShapedRecipe implements CraftRecipe {
super(key, result);
}
public CraftShapedRecipe(ItemStack result, ShapedRecipes recipe) {
this(CraftNamespacedKey.fromMinecraft(recipe.getId()), result);
public CraftShapedRecipe(NamespacedKey key, ItemStack result, ShapedRecipes recipe) {
this(key, result);
this.recipe = recipe;
}
@@ -57,6 +57,6 @@ public class CraftShapedRecipe extends ShapedRecipe implements CraftRecipe {
data.set(i * width + j, toNMS(ingred.get(row.charAt(j)), false));
}
}
MinecraftServer.getServer().getRecipeManager().addRecipe(new ShapedRecipes(CraftNamespacedKey.toMinecraft(this.getKey()), this.getGroup(), CraftRecipe.getCategory(this.getCategory()), width, shape.length, data, CraftItemStack.asNMSCopy(this.getResult())));
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new ShapedRecipes(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), width, shape.length, data, CraftItemStack.asNMSCopy(this.getResult()))));
}
}

View File

@@ -3,6 +3,7 @@ package org.bukkit.craftbukkit.inventory;
import java.util.List;
import net.minecraft.core.NonNullList;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.item.crafting.RecipeItemStack;
import net.minecraft.world.item.crafting.ShapelessRecipes;
import org.bukkit.NamespacedKey;
@@ -19,8 +20,8 @@ public class CraftShapelessRecipe extends ShapelessRecipe implements CraftRecipe
super(key, result);
}
public CraftShapelessRecipe(ItemStack result, ShapelessRecipes recipe) {
this(CraftNamespacedKey.fromMinecraft(recipe.getId()), result);
public CraftShapelessRecipe(NamespacedKey key, ItemStack result, ShapelessRecipes recipe) {
this(key, result);
this.recipe = recipe;
}
@@ -45,6 +46,6 @@ public class CraftShapelessRecipe extends ShapelessRecipe implements CraftRecipe
data.set(i, toNMS(ingred.get(i), true));
}
MinecraftServer.getServer().getRecipeManager().addRecipe(new ShapelessRecipes(CraftNamespacedKey.toMinecraft(this.getKey()), this.getGroup(), CraftRecipe.getCategory(this.getCategory()), CraftItemStack.asNMSCopy(this.getResult()), data));
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new ShapelessRecipes(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), CraftItemStack.asNMSCopy(this.getResult()), data)));
}
}

View File

@@ -1,6 +1,7 @@
package org.bukkit.craftbukkit.inventory;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.item.crafting.RecipeHolder;
import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.inventory.ItemStack;
@@ -24,6 +25,6 @@ public class CraftSmithingTransformRecipe extends SmithingTransformRecipe implem
public void addToCraftingManager() {
ItemStack result = this.getResult();
MinecraftServer.getServer().getRecipeManager().addRecipe(new net.minecraft.world.item.crafting.SmithingTransformRecipe(CraftNamespacedKey.toMinecraft(this.getKey()), toNMS(this.getTemplate(), true), toNMS(this.getBase(), true), toNMS(this.getAddition(), true), CraftItemStack.asNMSCopy(result)));
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.SmithingTransformRecipe(toNMS(this.getTemplate(), true), toNMS(this.getBase(), true), toNMS(this.getAddition(), true), CraftItemStack.asNMSCopy(result))));
}
}

View File

@@ -1,6 +1,7 @@
package org.bukkit.craftbukkit.inventory;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.item.crafting.RecipeHolder;
import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.inventory.RecipeChoice;
@@ -22,6 +23,6 @@ public class CraftSmithingTrimRecipe extends SmithingTrimRecipe implements Craft
@Override
public void addToCraftingManager() {
MinecraftServer.getServer().getRecipeManager().addRecipe(new net.minecraft.world.item.crafting.SmithingTrimRecipe(CraftNamespacedKey.toMinecraft(this.getKey()), toNMS(this.getTemplate(), true), toNMS(this.getBase(), true), toNMS(this.getAddition(), true)));
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.SmithingTrimRecipe(toNMS(this.getTemplate(), true), toNMS(this.getBase(), true), toNMS(this.getAddition(), true))));
}
}

View File

@@ -1,6 +1,7 @@
package org.bukkit.craftbukkit.inventory;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.item.crafting.RecipeHolder;
import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.inventory.ItemStack;
@@ -26,6 +27,6 @@ public class CraftSmokingRecipe extends SmokingRecipe implements CraftRecipe {
public void addToCraftingManager() {
ItemStack result = this.getResult();
MinecraftServer.getServer().getRecipeManager().addRecipe(new net.minecraft.world.item.crafting.RecipeSmoking(CraftNamespacedKey.toMinecraft(this.getKey()), this.getGroup(), CraftRecipe.getCategory(this.getCategory()), toNMS(this.getInputChoice(), true), CraftItemStack.asNMSCopy(result), getExperience(), getCookingTime()));
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.RecipeSmoking(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), toNMS(this.getInputChoice(), true), CraftItemStack.asNMSCopy(result), getExperience(), getCookingTime())));
}
}

View File

@@ -1,6 +1,7 @@
package org.bukkit.craftbukkit.inventory;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.item.crafting.RecipeHolder;
import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.inventory.ItemStack;
@@ -25,6 +26,6 @@ public class CraftStonecuttingRecipe extends StonecuttingRecipe implements Craft
public void addToCraftingManager() {
ItemStack result = this.getResult();
MinecraftServer.getServer().getRecipeManager().addRecipe(new net.minecraft.world.item.crafting.RecipeStonecutting(CraftNamespacedKey.toMinecraft(this.getKey()), this.getGroup(), toNMS(this.getInputChoice(), true), CraftItemStack.asNMSCopy(result)));
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.RecipeStonecutting(this.getGroup(), toNMS(this.getInputChoice(), true), CraftItemStack.asNMSCopy(result))));
}
}

View File

@@ -6,13 +6,13 @@ import java.util.Iterator;
import java.util.Map;
import net.minecraft.resources.MinecraftKey;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.item.crafting.IRecipe;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.item.crafting.Recipes;
import org.bukkit.inventory.Recipe;
public class RecipeIterator implements Iterator<Recipe> {
private final Iterator<Map.Entry<Recipes<?>, Object2ObjectLinkedOpenHashMap<MinecraftKey, IRecipe<?>>>> recipes;
private Iterator<IRecipe<?>> current;
private final Iterator<Map.Entry<Recipes<?>, Object2ObjectLinkedOpenHashMap<MinecraftKey, RecipeHolder<?>>>> recipes;
private Iterator<RecipeHolder<?>> current;
public RecipeIterator() {
this.recipes = MinecraftServer.getServer().getRecipeManager().recipes.entrySet().iterator();

View File

@@ -42,7 +42,7 @@ public class CraftMapRenderer extends MapRenderer {
}
MapIcon decoration = worldMap.decorations.get(key);
cursors.addCursor(decoration.getX(), decoration.getY(), (byte) (decoration.getRot() & 15), decoration.getType().getIcon(), true, CraftChatMessage.fromComponent(decoration.getName()));
cursors.addCursor(decoration.x(), decoration.y(), (byte) (decoration.rot() & 15), decoration.type().getIcon(), true, CraftChatMessage.fromComponent(decoration.name()));
}
}

View File

@@ -40,8 +40,7 @@ public class CraftDataPack implements DataPack {
@Override
public int getPackFormat() {
ResourcePackLoader.a info = ResourcePackLoader.readPackInfo(this.getRawId(), this.getHandle().resources);
return (info == null) ? 0 : info.format();
return 0;
}
@Override

View File

@@ -1,15 +1,20 @@
package org.bukkit.craftbukkit.potion;
import com.google.common.base.Preconditions;
import net.minecraft.core.IRegistry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.effect.MobEffectList;
import org.bukkit.Color;
import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.potion.PotionEffectType;
public class CraftPotionEffectType extends PotionEffectType {
private final MobEffectList handle;
public CraftPotionEffectType(MobEffectList handle) {
super(MobEffectList.getId(handle), org.bukkit.craftbukkit.util.CraftNamespacedKey.fromMinecraft(BuiltInRegistries.MOB_EFFECT.getKey(handle)));
super(BuiltInRegistries.MOB_EFFECT.getId(handle) + 1, CraftNamespacedKey.fromMinecraft(BuiltInRegistries.MOB_EFFECT.getKey(handle)));
this.handle = handle;
}
@@ -105,4 +110,22 @@ public class CraftPotionEffectType extends PotionEffectType {
public Color getColor() {
return Color.fromRGB(handle.getColor());
}
public static PotionEffectType minecraftToBukkit(MobEffectList minecraft) {
Preconditions.checkArgument(minecraft != null);
IRegistry<MobEffectList> registry = CraftRegistry.getMinecraftRegistry(Registries.MOB_EFFECT);
PotionEffectType bukkit = PotionEffectType.getByKey(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location()));
Preconditions.checkArgument(bukkit != null);
return bukkit;
}
public static MobEffectList bukkitToMinecraft(PotionEffectType bukkit) {
Preconditions.checkArgument(bukkit != null);
return CraftRegistry.getMinecraftRegistry(Registries.MOB_EFFECT)
.getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow();
}
}

View File

@@ -100,12 +100,12 @@ public class CraftPotionUtil {
}
public static MobEffect fromBukkit(PotionEffect effect) {
MobEffectList type = MobEffectList.byId(effect.getType().getId());
MobEffectList type = CraftPotionEffectType.bukkitToMinecraft(effect.getType());
return new MobEffect(type, effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles());
}
public static PotionEffect toBukkit(MobEffect effect) {
PotionEffectType type = PotionEffectType.getById(MobEffectList.getId(effect.getEffect()));
PotionEffectType type = CraftPotionEffectType.minecraftToBukkit(effect.getEffect());
int amp = effect.getAmplifier();
int duration = effect.getDuration();
boolean ambient = effect.isAmbient();
@@ -114,7 +114,7 @@ public class CraftPotionUtil {
}
public static boolean equals(MobEffectList mobEffect, PotionEffectType type) {
PotionEffectType typeV = PotionEffectType.getById(MobEffectList.getId(mobEffect));
PotionEffectType typeV = CraftPotionEffectType.minecraftToBukkit(mobEffect);
return typeV.equals(type);
}
}

View File

@@ -0,0 +1,63 @@
package org.bukkit.craftbukkit.profile;
import com.mojang.authlib.GameProfile;
import java.util.UUID;
import net.minecraft.SystemUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
public final class CraftGameProfile extends GameProfile {
private final boolean nullId;
private final boolean nullName;
public CraftGameProfile(UUID id, String name) {
super((id == null) ? SystemUtils.NIL_UUID : id, (name == null) ? "" : name);
this.nullId = (id == null);
this.nullName = (name == null);
}
@Override
public UUID getId() {
return (nullId) ? null : super.getId();
}
@Override
public String getName() {
return (nullName) ? null : super.getName();
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
GameProfile that = (GameProfile) o;
if ((this.getId() != null) ? !this.getId().equals(that.getId()) : (that.getId() != null)) {
return false;
}
if ((this.getName() != null) ? !this.getName().equals(that.getName()) : (that.getName() != null)) {
return false;
}
return true;
}
@Override
public int hashCode() {
int result = (this.getId() != null) ? this.getId().hashCode() : 0;
result = 31 * result + ((this.getName() != null) ? this.getName().hashCode() : 0);
return result;
}
@Override
public String toString() {
return new ToStringBuilder(this)
.append("id", this.getId())
.append("name", this.getName())
.append("properties", this.getProperties())
.toString();
}
}

View File

@@ -13,11 +13,15 @@ import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import net.minecraft.SystemUtils;
import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.world.level.block.entity.TileEntitySkull;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.configuration.serialization.SerializableAs;
@@ -88,7 +92,7 @@ public final class CraftPlayerProfile implements PlayerProfile {
// Assert: (property == null) || property.getName().equals(propertyName)
removeProperty(propertyName);
if (property != null) {
properties.put(property.getName(), property);
properties.put(property.name(), property);
}
}
@@ -135,7 +139,12 @@ public final class CraftPlayerProfile implements PlayerProfile {
// Look up properties such as the textures:
if (profile.getId() != null) {
GameProfile newProfile = server.getSessionService().fillProfileProperties(profile, true);
GameProfile newProfile;
try {
newProfile = TileEntitySkull.fillProfileTextures(profile).get().orElse(null); // TODO: replace with CompletableFuture
} catch (InterruptedException | ExecutionException ex) {
throw new RuntimeException("Exception filling profile textures", ex);
}
if (newProfile != null) {
profile = newProfile;
}
@@ -149,7 +158,7 @@ public final class CraftPlayerProfile implements PlayerProfile {
@Nonnull
public GameProfile buildGameProfile() {
rebuildDirtyProperties();
GameProfile profile = new GameProfile(uniqueId, name);
GameProfile profile = new CraftGameProfile(uniqueId, name);
profile.getProperties().putAll(properties);
return profile;
}
@@ -265,7 +274,7 @@ public final class CraftPlayerProfile implements PlayerProfile {
for (Object propertyData : (List<?>) map.get("properties")) {
Preconditions.checkArgument(propertyData instanceof Map, "Propertu data (%s) is not a valid Map", propertyData);
Property property = CraftProfileProperty.deserialize((Map<?, ?>) propertyData);
profile.properties.put(property.getName(), property);
profile.properties.put(property.name(), property);
}
}

View File

@@ -96,7 +96,7 @@ final class CraftPlayerTextures implements PlayerTextures {
Property property = getProperty();
if (property == null) return;
data = CraftProfileProperty.decodePropertyValue(property.getValue());
data = CraftProfileProperty.decodePropertyValue(property.value());
if (data != null) {
JsonObject texturesMap = JsonHelper.getObjectOrNull(data, "textures");
loadSkin(texturesMap);

View File

@@ -90,37 +90,37 @@ final class CraftProfileProperty {
StringBuilder builder = new StringBuilder();
builder.append("{");
builder.append("name=");
builder.append(property.getName());
builder.append(property.name());
builder.append(", value=");
builder.append(property.getValue());
builder.append(property.value());
builder.append(", signature=");
builder.append(property.getSignature());
builder.append(property.signature());
builder.append("}");
return builder.toString();
}
public static int hashCode(@Nonnull Property property) {
int result = 1;
result = 31 * result + Objects.hashCode(property.getName());
result = 31 * result + Objects.hashCode(property.getValue());
result = 31 * result + Objects.hashCode(property.getSignature());
result = 31 * result + Objects.hashCode(property.name());
result = 31 * result + Objects.hashCode(property.value());
result = 31 * result + Objects.hashCode(property.signature());
return result;
}
public static boolean equals(@Nullable Property property, @Nullable Property other) {
if (property == null || other == null) return (property == other);
if (!Objects.equals(property.getValue(), other.getValue())) return false;
if (!Objects.equals(property.getName(), other.getName())) return false;
if (!Objects.equals(property.getSignature(), other.getSignature())) return false;
if (!Objects.equals(property.value(), other.value())) return false;
if (!Objects.equals(property.name(), other.name())) return false;
if (!Objects.equals(property.signature(), other.signature())) return false;
return true;
}
public static Map<String, Object> serialize(@Nonnull Property property) {
Map<String, Object> map = new LinkedHashMap<>();
map.put("name", property.getName());
map.put("value", property.getValue());
map.put("name", property.name());
map.put("value", property.value());
if (property.hasSignature()) {
map.put("signature", property.getSignature());
map.put("signature", property.signature());
}
return map;
}

View File

@@ -3,7 +3,7 @@ package org.bukkit.craftbukkit.projectiles;
import com.google.common.base.Preconditions;
import net.minecraft.core.EnumDirection;
import net.minecraft.core.IPosition;
import net.minecraft.core.SourceBlock;
import net.minecraft.core.dispenser.SourceBlock;
import net.minecraft.server.level.WorldServer;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.EntityTypes;
@@ -24,7 +24,6 @@ import net.minecraft.world.level.block.entity.TileEntityDispenser;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.potion.CraftPotionUtil;
import org.bukkit.entity.AbstractArrow;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Egg;
@@ -66,10 +65,10 @@ public class CraftBlockProjectileSource implements BlockProjectileSource {
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
Preconditions.checkArgument(getBlock().getType() == Material.DISPENSER, "Block is no longer dispenser");
// Copied from BlockDispenser.dispense()
SourceBlock isourceblock = new SourceBlock((WorldServer) dispenserBlock.getLevel(), dispenserBlock.getBlockPos());
SourceBlock sourceblock = new SourceBlock((WorldServer) dispenserBlock.getLevel(), dispenserBlock.getBlockPos(), dispenserBlock.getBlockState(), dispenserBlock);
// Copied from DispenseBehaviorProjectile
IPosition iposition = BlockDispenser.getDispensePosition(isourceblock);
EnumDirection enumdirection = (EnumDirection) isourceblock.getBlockState().getValue(BlockDispenser.FACING);
IPosition iposition = BlockDispenser.getDispensePosition(sourceblock);
EnumDirection enumdirection = (EnumDirection) sourceblock.state().getValue(BlockDispenser.FACING);
net.minecraft.world.level.World world = dispenserBlock.getLevel();
net.minecraft.world.entity.Entity launch = null;

View File

@@ -74,13 +74,13 @@ final class CraftObjective extends CraftScoreboardComponent implements Objective
Scoreboard board = scoreboard.board;
ScoreboardObjective objective = this.objective;
for (int i = 0; i < CraftScoreboardTranslations.MAX_DISPLAY_SLOT; i++) {
for (net.minecraft.world.scores.DisplaySlot i : net.minecraft.world.scores.DisplaySlot.values()) {
if (board.getDisplayObjective(i) == objective) {
board.setDisplayObjective(i, null);
}
}
if (slot != null) {
int slotNumber = CraftScoreboardTranslations.fromBukkitSlot(slot);
net.minecraft.world.scores.DisplaySlot slotNumber = CraftScoreboardTranslations.fromBukkitSlot(slot);
board.setDisplayObjective(slotNumber, getHandle());
}
}
@@ -91,7 +91,7 @@ final class CraftObjective extends CraftScoreboardComponent implements Objective
Scoreboard board = scoreboard.board;
ScoreboardObjective objective = this.objective;
for (int i = 0; i < CraftScoreboardTranslations.MAX_DISPLAY_SLOT; i++) {
for (net.minecraft.world.scores.DisplaySlot i : net.minecraft.world.scores.DisplaySlot.values()) {
if (board.getDisplayObjective(i) == objective) {
return CraftScoreboardTranslations.toBukkitSlot(i);
}

View File

@@ -74,7 +74,7 @@ public final class CraftScoreboardManager implements ScoreboardManager {
// Old objective tracking
HashSet<ScoreboardObjective> removed = new HashSet<>();
for (int i = 0; i < 3; ++i) {
ScoreboardObjective scoreboardobjective = oldboard.getDisplayObjective(i);
ScoreboardObjective scoreboardobjective = oldboard.getDisplayObjective(net.minecraft.world.scores.DisplaySlot.BY_ID.apply(i));
if (scoreboardobjective != null && !removed.contains(scoreboardobjective)) {
entityplayer.connection.send(new PacketPlayOutScoreboardObjective(scoreboardobjective, 1));
removed.add(scoreboardobjective);

View File

@@ -1,7 +1,6 @@
package org.bukkit.craftbukkit.scoreboard;
import com.google.common.collect.ImmutableBiMap;
import net.minecraft.world.scores.Scoreboard;
import net.minecraft.world.scores.criteria.IScoreboardCriteria;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.RenderType;
@@ -9,7 +8,7 @@ import org.bukkit.scoreboard.RenderType;
final class CraftScoreboardTranslations {
static final int MAX_DISPLAY_SLOT = 19;
static final ImmutableBiMap<DisplaySlot, String> SLOTS = ImmutableBiMap.<DisplaySlot, String>builder()
.put(DisplaySlot.BELOW_NAME, "belowName")
.put(DisplaySlot.BELOW_NAME, "below_name")
.put(DisplaySlot.PLAYER_LIST, "list")
.put(DisplaySlot.SIDEBAR, "sidebar")
.put(DisplaySlot.SIDEBAR_BLACK, "sidebar.team.black")
@@ -32,12 +31,12 @@ final class CraftScoreboardTranslations {
private CraftScoreboardTranslations() {}
static DisplaySlot toBukkitSlot(int i) {
return SLOTS.inverse().get(Scoreboard.getDisplaySlotName(i));
static DisplaySlot toBukkitSlot(net.minecraft.world.scores.DisplaySlot minecraft) {
return SLOTS.inverse().get(minecraft.getSerializedName());
}
static int fromBukkitSlot(DisplaySlot slot) {
return Scoreboard.getDisplaySlotByName(SLOTS.get(slot));
static net.minecraft.world.scores.DisplaySlot fromBukkitSlot(DisplaySlot slot) {
return net.minecraft.world.scores.DisplaySlot.CODEC.byName(SLOTS.get(slot));
}
static RenderType toBukkitRender(IScoreboardCriteria.EnumScoreboardHealthDisplay display) {

View File

@@ -1,7 +1,6 @@
package org.bukkit.craftbukkit.util;
import net.minecraft.core.BlockPosition;
import net.minecraft.core.Position;
import net.minecraft.world.phys.Vec3D;
import org.bukkit.Location;
import org.bukkit.World;
@@ -37,26 +36,10 @@ public final class CraftLocation {
return new Location(world, blockPosition.getX(), blockPosition.getY(), blockPosition.getZ(), yaw, pitch);
}
public static Location toBukkit(Position position) {
return toBukkit(position, null, 0.0F, 0.0F);
}
public static Location toBukkit(Position position, World world) {
return toBukkit(position, world, 0.0F, 0.0F);
}
public static Location toBukkit(Position position, World world, float yaw, float pitch) {
return new Location(world, position.x(), position.y(), position.z(), yaw, pitch);
}
public static BlockPosition toBlockPosition(Location location) {
return new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ());
}
public static Position toPosition(Location location) {
return new Position(location.getX(), location.getY(), location.getZ());
}
public static Vec3D toVec3D(Location location) {
return new Vec3D(location.getX(), location.getY(), location.getZ());
}

View File

@@ -24,6 +24,7 @@ import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.minecraft.SharedConstants;
import net.minecraft.advancements.AdvancementHolder;
import net.minecraft.advancements.critereon.LootDeserializationContext;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.DynamicOpsNBT;
@@ -239,7 +240,7 @@ public final class CraftMagicNumbers implements UnsafeValues {
* @return string
*/
public String getMappingsVersion() {
return "bcf3dcb22ad42792794079f9443df2c0";
return "3478a65bfd04b15b431fe107b3617dfc";
}
@Override
@@ -273,9 +274,9 @@ public final class CraftMagicNumbers implements UnsafeValues {
JsonElement jsonelement = AdvancementDataWorld.GSON.fromJson(advancement, JsonElement.class);
JsonObject jsonobject = ChatDeserializer.convertToJsonObject(jsonelement, "advancement");
net.minecraft.advancements.Advancement.SerializedAdvancement nms = net.minecraft.advancements.Advancement.SerializedAdvancement.fromJson(jsonobject, new LootDeserializationContext(minecraftkey, MinecraftServer.getServer().getLootData()));
net.minecraft.advancements.Advancement nms = net.minecraft.advancements.Advancement.fromJson(jsonobject, new LootDeserializationContext(minecraftkey, MinecraftServer.getServer().getLootData()));
if (nms != null) {
MinecraftServer.getServer().getAdvancements().advancements.add(Maps.newHashMap(Collections.singletonMap(minecraftkey, nms)));
MinecraftServer.getServer().getAdvancements().advancements.put(minecraftkey, new AdvancementHolder(minecraftkey, nms));
Advancement bukkit = Bukkit.getAdvancement(key);
if (bukkit != null) {

View File

@@ -95,11 +95,11 @@ public class PlayerProfileTest {
Assert.assertEquals("Unique id is not the same", UNIQUE_ID, profile1.getUniqueId());
Assert.assertEquals("Name is not the same", NAME, profile1.getName());
CraftPlayerProfile profile2 = new CraftPlayerProfile(new GameProfile(UNIQUE_ID, null));
CraftPlayerProfile profile2 = new CraftPlayerProfile(new CraftGameProfile(UNIQUE_ID, null));
Assert.assertEquals("Unique id is not the same", UNIQUE_ID, profile2.getUniqueId());
Assert.assertEquals("Name is not null", null, profile2.getName());
CraftPlayerProfile profile3 = new CraftPlayerProfile(new GameProfile(null, NAME));
CraftPlayerProfile profile3 = new CraftPlayerProfile(new CraftGameProfile(null, NAME));
Assert.assertEquals("Unique id is not null", null, profile3.getUniqueId());
Assert.assertEquals("Name is not the same", NAME, profile3.getName());
}
@@ -123,7 +123,7 @@ public class PlayerProfileTest {
Property property = CraftPlayerProfile.getProperty(gameProfile, CraftPlayerTextures.PROPERTY_NAME);
Assert.assertNotNull("Textures property is null", property);
Assert.assertEquals("Property values are not the same", VALUE, property.getValue());
Assert.assertEquals("Property values are not the same", VALUE, property.value());
Assert.assertEquals("Names are not the same", NAME, gameProfile.getName());
Assert.assertEquals("Unique ids are not the same", UNIQUE_ID, gameProfile.getId());
Assert.assertTrue("Signature is missing", property.hasSignature());
@@ -198,17 +198,17 @@ public class PlayerProfileTest {
public void testCustomSkin() {
CraftPlayerProfile profile = new CraftPlayerProfile(UNIQUE_ID, NAME);
profile.getTextures().setSkin(SKIN);
Assert.assertEquals("profile with custom skin does not match expected value", COMPACT_VALUE, profile.getTextures().getProperty().getValue());
Assert.assertEquals("profile with custom skin does not match expected value", COMPACT_VALUE, profile.getTextures().getProperty().value());
}
@Test
public void testEquals() {
CraftPlayerProfile profile1 = buildPlayerProfile();
CraftPlayerProfile profile2 = buildPlayerProfile();
CraftPlayerProfile profile3 = new CraftPlayerProfile(new GameProfile(UNIQUE_ID, NAME));
CraftPlayerProfile profile4 = new CraftPlayerProfile(new GameProfile(UNIQUE_ID, NAME));
CraftPlayerProfile profile5 = new CraftPlayerProfile(new GameProfile(UNIQUE_ID, null));
CraftPlayerProfile profile6 = new CraftPlayerProfile(new GameProfile(null, NAME));
CraftPlayerProfile profile3 = new CraftPlayerProfile(UNIQUE_ID, NAME);
CraftPlayerProfile profile4 = new CraftPlayerProfile(UNIQUE_ID, NAME);
CraftPlayerProfile profile5 = new CraftPlayerProfile(UNIQUE_ID, null);
CraftPlayerProfile profile6 = new CraftPlayerProfile(null, NAME);
Assert.assertEquals("profile1 and profile2 are not equal", profile1, profile2);
Assert.assertEquals("profile3 and profile4 are not equal", profile3, profile4);

View File

@@ -9,6 +9,7 @@ import net.minecraft.resources.MinecraftKey;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectList;
import net.minecraft.world.item.alchemy.PotionRegistry;
import org.bukkit.craftbukkit.potion.CraftPotionEffectType;
import org.bukkit.support.AbstractTestingBase;
import org.junit.Test;
@@ -16,12 +17,11 @@ public class PotionTest extends AbstractTestingBase {
@Test
public void testEffectCompleteness() throws Throwable {
Map<PotionType, String> effects = new EnumMap(PotionType.class);
for (Object reg : BuiltInRegistries.POTION) {
List<MobEffect> eff = ((PotionRegistry) reg).getEffects();
for (PotionRegistry reg : BuiltInRegistries.POTION) {
List<MobEffect> eff = reg.getEffects();
if (eff.size() != 1) continue;
int id = MobEffectList.getId(eff.get(0).getEffect());
PotionEffectType type = PotionEffectType.getById(id);
assertNotNull(String.valueOf(id), PotionEffectType.getById(id));
PotionEffectType type = CraftPotionEffectType.minecraftToBukkit(eff.get(0).getEffect());
assertNotNull(String.valueOf(reg), type);
PotionType enumType = PotionType.getByEffect(type);
assertNotNull(type.getName(), enumType);
@@ -37,8 +37,7 @@ public class PotionTest extends AbstractTestingBase {
for (MobEffectList nms : BuiltInRegistries.MOB_EFFECT) {
MinecraftKey key = BuiltInRegistries.MOB_EFFECT.getKey(nms);
int id = MobEffectList.getId(nms);
PotionEffectType bukkit = PotionEffectType.getById(id);
PotionEffectType bukkit = CraftPotionEffectType.minecraftToBukkit(nms);
assertNotNull("No Bukkit type for " + key, bukkit);
assertFalse("No name for " + key, bukkit.getName().contains("UNKNOWN"));

View File

@@ -46,7 +46,7 @@ public abstract class AbstractTestingBase {
SharedConstants.tryDetectVersion();
DispenserRegistry.bootStrap();
// Populate available packs
ResourcePackRepository resourceRepository = new ResourcePackRepository(new ResourcePackSourceVanilla());
ResourcePackRepository resourceRepository = ResourcePackSourceVanilla.createVanillaTrustedRepository();
resourceRepository.reload();
// Set up resource manager
ResourceManager resourceManager = new ResourceManager(EnumResourcePackType.SERVER_DATA, resourceRepository.getAvailablePacks().stream().map(ResourcePackLoader::open).toList());