Skip to content

Commit

Permalink
Merge remote-tracking branch 'Slimefun/master'
Browse files Browse the repository at this point in the history
DEV - 1131
  • Loading branch information
xMikux committed Jan 19, 2024
2 parents 55ef3fc + 7c917c3 commit 2b9b049
Show file tree
Hide file tree
Showing 24 changed files with 532 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/discord-webhook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
architecture: x64

- name: Cache Maven packages
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/maven-compiler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
architecture: x64

- name: Cache Maven packages
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
architecture: x64

- name: Cache Maven packages
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/.settings/
/.idea/
/.vscode/
/data-store/
/data-storage/

dependency-reduced-pom.xml

Expand Down
71 changes: 71 additions & 0 deletions docs/sop/update.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Update Procedure

Date: 2024-01-15
Last updated: 2024-01-15

## Goal

This SOP will go over updating Slimefun to the newest Minecraft version, most of this will only apply to major versions, but we have also seen minor versions break things. So please read through the whole SOP and make sure you do everything applicable.

## Updating

### Updating Bukkit/Spigot

The first step is just updating Spigot in the pom.xml. This should only be done in 2 cases:
* There's a new major version (well, MC major - 1.19 -> 1.20 is a major)
* There was a change within MC or Bukkit/Spigot that broke the API

To update the Spigot version, you will need to go to the `pom.xml` and find the `spigot.version` property, this will be within the `properties` property. Simply make this the MC version (e.g. `1.20` or in the case of minor `1.20.4`).

Once updated, **make sure to run a build** to check for compilation failures with `mvn clean package -DskipTests=true`. We will go over the tests next.

### Updating tests

The next step is making sure our tests are still working correctly as is. This can be done by running `mvn test` and verifying that all tests pass correctly without any failures or errors.

If there are any failures you will need to investigate these, it's best to run them one at a time, so you don't have the potential for cross-test contamination. If you find any issues with the tests, please fix them and make sure to add a comment to the PR explaining why the test was changed.

If you need any help fixing tests feel free to join the [Discord](https://discord.gg/slimefun).

Once all the tests are passed, check to see if there's a new version of [MockBukkit](https://github.com/MockBukkit/MockBukkit), this is the framework handling the Bukkit side of our tests. There very well may not be a new version, they usually lag updates a bit. If not, that's perfectly ok, just make sure to note it on the PR.

### Testing in game

The final and most important step is testing this in game. While I'd love for our tests to be perfect, they are not (especially if MockBukkit hasn't had an update yet). We need to ensure that everything is working in-game before we can ship a new version release.

To do this, you will need to build the plugin with `mvn clean package` and then copy the jar from `target/` to your server's `plugins/` folder. Once you've done this, start the server. You will want to test various things but the things we always want covered are:
* Commands, verify running a few commands work
* `/sf versions`
* `/sf cheat`
* `/sf search`
* Items, verify you can use a few items (you can grab these from `/sf cheat`)
* Wind staff
* One of the talismans
* One of the backpacks
* Blocks, verify you can place, break and ensure they all work
* Ancient altar
* Ore washer
* Coal generator

It is important to verify heads are still working (part of the energy network and the coal generator). If head skins are not loading, consider it as a bug: try figuring out what the issue is, and ask in the [Discord](https://discord.gg/slimefun) if you are not sure what the cause may be.

Also make sure to verify that there are no errors in the console, any errors here should be investigated and fixed.

If you find any issues, please fix them and make sure to add a comment to the PR explaining why the fix was needed.

> **Note**
> An issue here usually means that we need to update Dough. If this is the case, please open a PR to Dough and then update the Dough version in the `pom.xml` to the new version. Once you've done this, make sure to run a build to verify everything is working correctly.
### Final steps

Once you've verified everything is working, you can go ahead and open the PR. We will get to this as soon as we can :)

While the PR is open, make sure to verify the E2E tests are passing, and you should also verify the output of these. If the E2E tests look good then finally we will update these.

#### Updating E2E tests

**This is only needed in a major version**

In the `e2e-testing.yml` file you will need to update the matrix strategy, please add the latest version of the old major (e.g. if 1.21 came out, add 1.20.x where x is the latest released version). If MC is requiring a new Java version make sure that is updated too in the `latest` version.

Once updated, push and re-verify that the E2E tests are still passing.
44 changes: 26 additions & 18 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<maven.compiler.target>16</maven.compiler.target>

<!-- Spigot properties -->
<spigot.version>1.20</spigot.version>
<spigot.version>1.20.4</spigot.version>
<spigot.javadocs>https://hub.spigotmc.org/javadocs/spigot/</spigot.javadocs>

<!-- Default settings for sonarcloud.io -->
Expand Down Expand Up @@ -334,13 +334,7 @@
</build>

<dependencies>
<!-- Hard dependencies -->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>${spigot.version}-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>


<!-- Development dependencies -->
<dependency>
Expand All @@ -355,7 +349,7 @@
<dependency>
<groupId>com.github.baked-libs.dough</groupId>
<artifactId>dough-api</artifactId>
<version>c4231a4d1a</version>
<version>fcdbd45aa0</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -389,7 +383,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.8.0</version>
<version>5.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -398,10 +392,11 @@
<version>2.0.9</version>
<scope>test</scope>
</dependency>
<!-- This needs to be before Spigot because MockBukkit will fail otherwise. -->
<dependency>
<groupId>com.github.seeseemelk</groupId>
<artifactId>MockBukkit-v1.18</artifactId>
<version>2.0.0</version>
<artifactId>MockBukkit-v1.20</artifactId>
<version>3.65.0</version>
<scope>test</scope>

<exclusions>
Expand Down Expand Up @@ -513,18 +508,31 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.mojang</groupId>
<artifactId>authlib</artifactId>
<version>1.5.25</version>
<scope>provided</scope>
</dependency>
<!-- TODO: Remove this dependency -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>${spigot.version}-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.mojang</groupId>
<artifactId>authlib</artifactId>
<version>6.0.52</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<!-- We don't need any of the dependencies -->
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.github.thebusybiscuit.slimefun4.api.events;

import javax.annotation.Nonnull;

import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;

import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;


/**
* This {@link Event} is fired after {@link Slimefun} finishes loading the
* {@link SlimefunItem} registry. We recommend listening to this event if you
* want to register recipes using items from other addons.
*
* @author ProfElements
*/
public class SlimefunItemRegistryFinalizedEvent extends Event {

private static final HandlerList handlers = new HandlerList();

public SlimefunItemRegistryFinalizedEvent() {}

@Nonnull
public static HandlerList getHandlerList() {
return handlers;
}

@Nonnull
@Override
public HandlerList getHandlers() {
return getHandlerList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

import io.github.thebusybiscuit.slimefun4.storage.Storage;
import io.github.thebusybiscuit.slimefun4.storage.backend.legacy.LegacyStorage;
Expand All @@ -29,7 +28,6 @@
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.java.JavaPluginLoader;
import org.bukkit.scheduler.BukkitTask;

import io.github.bakedlibs.dough.config.Config;
Expand Down Expand Up @@ -120,17 +118,16 @@
import io.github.thebusybiscuit.slimefun4.implementation.setup.PostSetup;
import io.github.thebusybiscuit.slimefun4.implementation.setup.ResearchSetup;
import io.github.thebusybiscuit.slimefun4.implementation.setup.SlimefunItemSetup;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.SlimefunStartupTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.TickerTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.armor.RadiationTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.armor.RainbowArmorTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.armor.SlimefunArmorTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.armor.SolarHelmetTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.SlimefunStartupTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.TickerTask;
import io.github.thebusybiscuit.slimefun4.integrations.IntegrationsManager;
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag;
import io.papermc.lib.PaperLib;

import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.MenuListener;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.inventory.UniversalBlockMenu;
Expand All @@ -141,7 +138,7 @@
*
* @author TheBusyBiscuit
*/
public final class Slimefun extends JavaPlugin implements SlimefunAddon {
public class Slimefun extends JavaPlugin implements SlimefunAddon {

/**
* This is the Java version we recommend server owners to use.
Expand Down Expand Up @@ -209,30 +206,17 @@ public final class Slimefun extends JavaPlugin implements SlimefunAddon {
private final SlimefunBowListener bowListener = new SlimefunBowListener();

/**
* Our default constructor for {@link Slimefun}.
* This constructor is invoked by Bukkit and within unit tests.
* Therefore we need to figure out if we're within unit tests or not.
*/
public Slimefun() {
super();
}

/**
* This constructor is invoked in Unit Test environments only.
*
* @param loader
* Our {@link JavaPluginLoader}
* @param description
* A {@link PluginDescriptionFile}
* @param dataFolder
* The data folder
* @param file
* A {@link File} for this {@link Plugin}
*/
@ParametersAreNonnullByDefault
public Slimefun(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) {
super(loader, description, dataFolder, file);

// This is only invoked during a Unit Test
minecraftVersion = MinecraftVersion.UNIT_TEST;
// Check that we got loaded by MockBukkit rather than Bukkit's loader
// TODO: This is very much a hack and we can hopefully move to a more native way in the future
if (getClassLoader().getClass().getPackageName().startsWith("be.seeseemelk.mockbukkit")) {
minecraftVersion = MinecraftVersion.UNIT_TEST;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.bukkit.block.BlockState;
import org.bukkit.block.data.BlockData;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand All @@ -41,6 +42,7 @@
import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag;

import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;

/**
* The {@link BlockListener} is responsible for listening to the {@link BlockPlaceEvent}
Expand Down Expand Up @@ -178,7 +180,7 @@ public void onBlockBreak(BlockBreakEvent e) {
dropItems(e, drops);

// Checks for vanilla sensitive blocks everywhere
checkForSensitiveBlocks(e.getBlock(), 0, e.isDropItems());
// checkForSensitiveBlocks(e.getBlock(), 0, e.isDropItems());
}
}

Expand Down Expand Up @@ -220,6 +222,16 @@ private void callBlockHandler(BlockBreakEvent e, ItemStack item, List<ItemStack>
}

drops.addAll(sfItem.getDrops());
// Partial fix for #4087 - We don't want the inventory to be usable post break, close it for anyone still inside
// The main fix is in SlimefunItemInteractListener preventing opening to begin with
// Close the inventory for all viewers of this block
BlockMenu inventory = BlockStorage.getInventory(e.getBlock());
if (inventory != null) {
for (HumanEntity human : new ArrayList<>(inventory.toInventory().getViewers())) {
human.closeInventory();
}
}
// Remove the block data
BlockStorage.clearBlockInfo(e.getBlock());
}
}
Expand Down Expand Up @@ -306,8 +318,7 @@ private void checkForSensitiveBlockAbove(Player player, Block block, ItemStack i
// Disabled for now due to #4069 - Servers crashing due to this check
// There is additionally a second bug with `getMaxChainedNeighborUpdates` not existing in 1.17
@ParametersAreNonnullByDefault
private void checkForSensitiveBlocks(Block block, Integer count, boolean isDropItems) {
/*
private void checkForSensitiveBlocks(Block block, int count, boolean isDropItems) {
if (count >= Bukkit.getServer().getMaxChainedNeighborUpdates()) {
return;
}
Expand All @@ -329,7 +340,6 @@ private void checkForSensitiveBlocks(Block block, Integer count, boolean isDropI
// Set the BlockData back: this makes it so containers and spawners drop correctly. This is a hacky fix.
block.setBlockData(state.getBlockData(), false);
state.update(true, false);
*/
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ public void onRightClick(PlayerInteractEvent e) {
return;
}

// Fixes #4087 - Prevents players from interacting with a block that is about to be deleted
// We especially don't want to open inventories as that can cause duplication
if (e.getClickedBlock() != null && Slimefun.getTickerTask().isDeletedSoon(e.getClickedBlock().getLocation())) {
e.setCancelled(true);
return;
}

// Fire our custom Event
PlayerRightClickEvent event = new PlayerRightClickEvent(e);
Bukkit.getPluginManager().callEvent(event);
Expand Down
Loading

0 comments on commit 2b9b049

Please sign in to comment.