Skip to content

Commit

Permalink
Update to 1.20.4 (#931)
Browse files Browse the repository at this point in the history
* chore(stubbing): Stub new Methods

* Material.GRASS -> Material.SHORT_GRASS

* Implementation of enchantmentmock (#934)

* Implementation of enchantmentmock

* Add unit tests to EnchantmentMock

* Update src/main/java/be/seeseemelk/mockbukkit/enchantments/EnchantmentMock.java

Co-authored-by: thelooter <evekolb2204@gmail.com>

* Update EnchantmentMockTest.java

---------

Co-authored-by: thelooter <evekolb2204@gmail.com>

* Change default material for world to be GRASS_BLOCK

* Potionfixes + remove duplicate class (#935)

* MockPotionEffectType take its data from json

* (Remove duplicate class)

* Fix formatting

* Remove console spam

* Fix some codesmells

* Update EnchantmentMock.java

* Remove and fix invalid tests

* minecraft:grass -> minecraft:short_grass

* Small patches

* Stub some methods

* Fix invalid test

* Stub some merthods

---------

Co-authored-by: Thorinwasher <ragnarlol96@gmail.com>
Co-authored-by: Thorinwasher <37477983+Thorinwasher@users.noreply.github.com>
  • Loading branch information
3 people committed Jan 7, 2024
1 parent a3c5579 commit f521e33
Show file tree
Hide file tree
Showing 39 changed files with 5,817 additions and 1,398 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
paper.api.version=1.20
paper.api.full-version=1.20.2-R0.1-SNAPSHOT
paper.api.full-version=1.20.4-R0.1-SNAPSHOT
mockbukkit.version=
21 changes: 18 additions & 3 deletions src/main/java/be/seeseemelk/mockbukkit/RegistryMock.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package be.seeseemelk.mockbukkit;

import be.seeseemelk.mockbukkit.enchantments.EnchantmentMock;
import be.seeseemelk.mockbukkit.generator.structure.StructureMock;
import be.seeseemelk.mockbukkit.generator.structure.StructureTypeMock;
import be.seeseemelk.mockbukkit.inventory.meta.trim.TrimMaterialMock;
import be.seeseemelk.mockbukkit.inventory.meta.trim.TrimPatternMock;
import be.seeseemelk.mockbukkit.potion.MockPotionEffectType;
import com.google.common.base.Preconditions;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
Expand All @@ -15,10 +17,12 @@
import org.bukkit.MusicInstrument;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.generator.structure.Structure;
import org.bukkit.generator.structure.StructureType;
import org.bukkit.inventory.meta.trim.TrimMaterial;
import org.bukkit.inventory.meta.trim.TrimPattern;
import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -102,7 +106,18 @@ else if (tClass == GameEvent.class)
{
return GameEventMock::new;
}
else throw new UnimplementedOperationException();
else if (tClass == Enchantment.class)
{
return EnchantmentMock::new;
}
else if (tClass == PotionEffectType.class)
{
return MockPotionEffectType::new;
}
else
{
throw new UnimplementedOperationException();
}
}

public static <T extends Keyed> Registry<?> createRegistry(Class<T> tClass)
Expand Down Expand Up @@ -170,9 +185,9 @@ private static Registry<?> getValue(Field a)

private static List<Class<? extends Keyed>> getOutlierKeyedClasses()
{
return List.of(Structure.class,
return List.of(Structure.class, PotionEffectType.class,
StructureType.class, TrimMaterial.class, TrimPattern.class,
MusicInstrument.class, GameEvent.class);
MusicInstrument.class, GameEvent.class, Enchantment.class);
}

@Override
Expand Down
88 changes: 17 additions & 71 deletions src/main/java/be/seeseemelk/mockbukkit/ServerMock.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import be.seeseemelk.mockbukkit.command.MessageTarget;
import be.seeseemelk.mockbukkit.command.MockCommandMap;
import be.seeseemelk.mockbukkit.configuration.ServerConfiguration;
import be.seeseemelk.mockbukkit.enchantments.EnchantmentsMock;
import be.seeseemelk.mockbukkit.entity.EntityMock;
import be.seeseemelk.mockbukkit.entity.PlayerMock;
import be.seeseemelk.mockbukkit.entity.PlayerMockFactory;
Expand Down Expand Up @@ -38,7 +37,6 @@
import be.seeseemelk.mockbukkit.inventory.meta.ItemMetaMock;
import be.seeseemelk.mockbukkit.map.MapViewMock;
import be.seeseemelk.mockbukkit.plugin.PluginManagerMock;
import be.seeseemelk.mockbukkit.potion.MockPotionEffectType;
import be.seeseemelk.mockbukkit.profile.PlayerProfileMock;
import be.seeseemelk.mockbukkit.scheduler.BukkitSchedulerMock;
import be.seeseemelk.mockbukkit.scheduler.paper.FoliaAsyncScheduler;
Expand Down Expand Up @@ -71,7 +69,6 @@
import org.bukkit.BanList;
import org.bukkit.BanList.Type;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.GameMode;
import org.bukkit.Keyed;
import org.bukkit.Location;
Expand All @@ -80,6 +77,7 @@
import org.bukkit.OfflinePlayer;
import org.bukkit.Registry;
import org.bukkit.Server;
import org.bukkit.ServerTickManager;
import org.bukkit.StructureType;
import org.bukkit.Tag;
import org.bukkit.Warning.WarningState;
Expand Down Expand Up @@ -124,7 +122,6 @@
import org.bukkit.plugin.messaging.Messenger;
import org.bukkit.plugin.messaging.StandardMessenger;
import org.bukkit.potion.PotionBrewer;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scoreboard.Criteria;
import org.bukkit.structure.StructureManager;
import org.jetbrains.annotations.NotNull;
Expand All @@ -151,7 +148,6 @@
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
Expand Down Expand Up @@ -215,11 +211,8 @@ public ServerMock()
{
ServerMock.registerSerializables();

// Register default Minecraft Potion Effect Types
createPotionEffectTypes();
TagsMock.loadDefaultTags(this, true);
InternalTag.loadInternalTags();
EnchantmentsMock.registerDefaultEnchantments();

try
{
Expand Down Expand Up @@ -458,10 +451,11 @@ public void addWorld(WorldMock world)
/**
* Removes a mocked world from this server.
*
* @param world The world to remove.
* @param world The world to remove.
* @return true if the world was removed, otherwise false.
*/
public boolean removeWorld(WorldMock world) {
public boolean removeWorld(WorldMock world)
{
AsyncCatcher.catchOp("world remove");
return worlds.remove(world);
}
Expand Down Expand Up @@ -1183,10 +1177,12 @@ public int getPort()

/**
* Sets the server listen port.
*
* @param port The server listen port.
* @see ServerMock#getPort()
*/
public void setPort(int port) {
public void setPort(int port)
{
this.serverConfiguration.setServerPort(port);
}

Expand Down Expand Up @@ -1215,6 +1211,7 @@ public void setViewDistance(int viewDistance)

/**
* Sets the server listen IP.
*
* @param serverIp The server listen IP.
* @see ServerMock#getIp()
*/
Expand Down Expand Up @@ -1293,11 +1290,19 @@ public boolean getAllowNether()
}

@Override
@Deprecated(since = "1.19")
public @NotNull DataPackManager getDataPackManager()
{
throw new UnimplementedOperationException();
}

@Override
public @NotNull ServerTickManager getServerTickManager()
{
// TODO Auto-generated method stub
throw new UnimplementedOperationException();
}

/**
* Sets whether the Nether should be allowed.
*
Expand Down Expand Up @@ -2101,66 +2106,6 @@ public <T extends Keyed> Tag<T> getTag(String registryKey, NamespacedKey key, Cl
return null;
}

/**
* This registers Minecrafts default {@link PotionEffectType PotionEffectTypes}. It also prevents any new effects to
* be created afterwards.
*/
private void createPotionEffectTypes()
{
for (PotionEffectType type : PotionEffectType.values())
{
// We probably already registered all Potion Effects
// otherwise this would be null
if (type != null)
{
// This is not perfect, but it works.
return;
}
}

registerPotionEffectType(1, "SPEED", false, 8171462);
registerPotionEffectType(2, "SLOWNESS", false, 5926017);
registerPotionEffectType(3, "HASTE", false, 14270531);
registerPotionEffectType(4, "MINING_FATIGUE", false, 4866583);
registerPotionEffectType(5, "STRENGTH", false, 9643043);
registerPotionEffectType(6, "INSTANT_HEALTH", true, 16262179);
registerPotionEffectType(7, "INSTANT_DAMAGE", true, 4393481);
registerPotionEffectType(8, "JUMP_BOOST", false, 2293580);
registerPotionEffectType(9, "NAUSEA", false, 5578058);
registerPotionEffectType(10, "REGENERATION", false, 13458603);
registerPotionEffectType(11, "RESISTANCE", false, 10044730);
registerPotionEffectType(12, "FIRE_RESISTANCE", false, 14981690);
registerPotionEffectType(13, "WATER_BREATHING", false, 3035801);
registerPotionEffectType(14, "INVISIBILITY", false, 8356754);
registerPotionEffectType(15, "BLINDNESS", false, 2039587);
registerPotionEffectType(16, "NIGHT_VISION", false, 2039713);
registerPotionEffectType(17, "HUNGER", false, 5797459);
registerPotionEffectType(18, "WEAKNESS", false, 4738376);
registerPotionEffectType(19, "POISON", false, 5149489);
registerPotionEffectType(20, "WITHER", false, 3484199);
registerPotionEffectType(21, "HEALTH_BOOST", false, 16284963);
registerPotionEffectType(22, "ABSORPTION", false, 2445989);
registerPotionEffectType(23, "SATURATION", true, 16262179);
registerPotionEffectType(24, "GLOWING", false, 9740385);
registerPotionEffectType(25, "LEVITATION", false, 13565951);
registerPotionEffectType(26, "LUCK", false, 3381504);
registerPotionEffectType(27, "UNLUCK", false, 12624973);
registerPotionEffectType(28, "SLOW_FALLING", false, 16773073);
registerPotionEffectType(29, "CONDUIT_POWER", false, 1950417);
registerPotionEffectType(30, "DOLPHINS_GRACE", false, 8954814);
registerPotionEffectType(31, "BAD_OMEN", false, 745784);
registerPotionEffectType(32, "HERO_OF_THE_VILLAGE", false, 4521796);
registerPotionEffectType(33, "DARKNESS", false, 2696993);
PotionEffectType.stopAcceptingRegistrations();
}

private void registerPotionEffectType(int id, @NotNull String name, boolean instant, int rgb)
{
NamespacedKey key = NamespacedKey.minecraft(name.toLowerCase(Locale.ROOT));
PotionEffectType type = new MockPotionEffectType(key, id, name, instant, Color.fromRGB(rgb));
PotionEffectType.registerPotionEffectType(type);
}

@Override
public LootTable getLootTable(NamespacedKey key)
{
Expand Down Expand Up @@ -2622,6 +2567,7 @@ public boolean isOwnedByCurrentRegion(@NotNull Entity entity)

/**
* Exposes the {@link ServerConfiguration} of this {@link ServerMock}.
*
* @return The {@link ServerConfiguration} of this {@link ServerMock}.
*/
public @NotNull ServerConfiguration getServerConfiguration()
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/be/seeseemelk/mockbukkit/WorldMock.java
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ public WorldMock(Material defaultBlock, int grassHeight)
*/
public WorldMock()
{
this(Material.GRASS, 4);
this(Material.GRASS_BLOCK, 4);
}

/**
Expand Down Expand Up @@ -1505,6 +1505,13 @@ else if (entity instanceof Projectile)
return entities;
}

@Override
public <T extends Entity> @NotNull T createEntity(@NotNull Location location, @NotNull Class<T> aClass)
{
// TODO Auto-generated method stub
throw new UnimplementedOperationException();
}

@Override
public @NotNull CompletableFuture<Chunk> getChunkAtAsync(int x, int z, boolean gen, boolean urgent)
{
Expand Down Expand Up @@ -2546,6 +2553,13 @@ public Location locateNearestStructure(Location origin, StructureType structureT
throw new UnimplementedOperationException();
}

@Override
public <T extends Entity> @NotNull T addEntity(@NotNull T t)
{
// TODO Auto-generated method stub
throw new UnimplementedOperationException();
}

@Override
@Deprecated(forRemoval = true)
@ApiStatus.ScheduledForRemoval(inVersion = "1.21")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import be.seeseemelk.mockbukkit.UnimplementedOperationException;
import com.destroystokyo.paper.MaterialTags;
import com.google.common.base.Preconditions;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.SoundGroup;
Expand Down Expand Up @@ -225,6 +226,13 @@ public boolean isFaceSturdy(@NotNull BlockFace face, @NotNull BlockSupport suppo
throw new UnimplementedOperationException();
}

@Override
public @NotNull Color getMapColor()
{
// TODO Auto-generated method stub
throw new UnimplementedOperationException();
}

@Override
public @NotNull Material getPlacementMaterial()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package be.seeseemelk.mockbukkit.block.state;

import be.seeseemelk.mockbukkit.UnimplementedOperationException;
import com.google.common.base.Preconditions;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.block.spawner.SpawnRule;
import org.bukkit.block.spawner.SpawnerEntry;
import org.bukkit.entity.EntitySnapshot;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;

/**
Expand Down Expand Up @@ -193,6 +200,48 @@ public void setSpawnRange(int spawnRange)
this.spawnRange = spawnRange;
}

@Override
public @NotNull List<SpawnerEntry> getPotentialSpawns()
{
// TODO Auto-generated method stub
throw new UnimplementedOperationException();
}

@Override
public void setPotentialSpawns(@NotNull Collection<SpawnerEntry> entries)
{
// TODO Auto-generated method stub
throw new UnimplementedOperationException();
}

@Override
public void addPotentialSpawn(@NotNull SpawnerEntry spawnerEntry)
{
// TODO Auto-generated method stub
throw new UnimplementedOperationException();
}

@Override
public void addPotentialSpawn(@NotNull EntitySnapshot snapshot, int weight, @Nullable SpawnRule spawnRule)
{
// TODO Auto-generated method stub
throw new UnimplementedOperationException();
}

@Override
public void setSpawnedEntity(@NotNull EntitySnapshot snapshot)
{
// TODO Auto-generated method stub
throw new UnimplementedOperationException();
}

@Override
public @Nullable EntitySnapshot getSpawnedEntity()
{
// TODO Auto-generated method stub
throw new UnimplementedOperationException();
}

@Override
public boolean isActivated()
{
Expand Down

0 comments on commit f521e33

Please sign in to comment.