Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 1.13.0 #29

Merged
merged 41 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
3544c3b
Version 1.11.1
tastybento Jul 6, 2021
4e9c944
Remove unused location setting
tastybento Jul 31, 2021
bb50aed
Clean up code.
tastybento Jul 31, 2021
c5cff4d
Fixed test.
tastybento Jul 31, 2021
9af70f5
Build against BentoBox 1.18 API
tastybento Oct 2, 2021
8713115
Not allow null.
tastybento Mar 20, 2022
737e493
Remove useless eq invocation
tastybento Mar 20, 2022
1c31ebd
Fixes major bug in InvSwitcher addon (#22)
BONNe May 6, 2022
f439c07
Merge branch 'develop' of https://github.com/BentoBoxWorld/InvSwitche…
tastybento Feb 10, 2023
aeaeb84
Remove unused method
tastybento Feb 10, 2023
79c1dc2
Version up
tastybento Feb 10, 2023
cd66b14
Added InventoryStorage test class.
tastybento Feb 10, 2023
a5e7074
Update github script
tastybento Feb 10, 2023
236995a
Added PlayerListener test class
tastybento Feb 10, 2023
fc1df94
Added InvSwitcher test
tastybento Feb 10, 2023
7916948
Clean up test class
tastybento Feb 10, 2023
ae2c1ac
Chnaged package name and fixed onDisable() test
tastybento Feb 10, 2023
0b4f5fe
Minor refactor to reduce complexity.
tastybento Feb 10, 2023
60937c6
Refactored to reduce complexity
tastybento Feb 10, 2023
6114ee2
Remove unneeded default
tastybento Feb 10, 2023
098b9b1
Code clean up from IntelliJ
tastybento Feb 10, 2023
fdf98e7
Remove unused default
tastybento Feb 10, 2023
b845ad7
Remove nesting.
tastybento Feb 10, 2023
8b1f31d
Even less complexity!
tastybento Feb 10, 2023
3a90f38
Redid Store test class
tastybento Feb 11, 2023
bec429f
Completed cache test.
tastybento Feb 11, 2023
be91754
Updated dependencies
tastybento Apr 15, 2023
242c719
Update Github Action build script
tastybento Jun 24, 2023
2b153f7
Added distribution required for Github Action
tastybento Jun 24, 2023
8649f28
Update Jacoco
tastybento Jul 11, 2023
ee5bf51
Update pom.xml
tastybento Jul 11, 2023
1f3fe23
Update to BentoBox 2.0.0
tastybento Nov 12, 2023
590fad3
Update to 1.20.3
tastybento Dec 6, 2023
ac2369d
Version 1.13.0
tastybento Jul 2, 2024
915348c
Remove constants that were causing lag at start.
tastybento Jul 2, 2024
582102b
Updated some POM items
tastybento Jul 2, 2024
95e87a2
Merge branch 'master' into develop
tastybento Jul 5, 2024
3c98138
Replace PowerMockito with Mockito 5 (#28)
tastybento Jul 5, 2024
813142b
Update GitHub Build script to Java 21
tastybento Jul 5, 2024
f627a5a
Try different build script for GitHub Action
tastybento Jul 5, 2024
2101886
Use the silent runner
tastybento Jul 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: 17
distribution: 'temurin'
java-version: 21
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
Expand All @@ -35,4 +35,5 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
MAVEN_OPTS: "-XX:+EnableDynamicAgentLoading"
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
30 changes: 15 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>17</java.version>
<java.version>21</java.version>
<!-- Non-minecraft related dependencies -->
<powermock.version>2.0.9</powermock.version>
<mockito.version>5.12.0</mockito.version>
<!-- More visible way how to change dependency versions -->
<spigot.version>1.20.3-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>2.0.0-SNAPSHOT</bentobox.version>
<spigot.version>1.20.4-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>2.4.1-SNAPSHOT</bentobox.version>
<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>
<!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number>
<!-- This allows to change between versions. -->
<build.version>1.12.0</build.version>
<build.version>1.13.0</build.version>
<!-- Sonar Cloud -->
<sonar.projectKey>BentoBoxWorld_addon-invSwitcher</sonar.projectKey>
<sonar.organization>bentobox-world</sonar.organization>
Expand Down Expand Up @@ -142,19 +142,19 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.11.2</version>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>5.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>${powermock.version}</version>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -202,15 +202,15 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<version>3.13.0</version>
<configuration>
<release>${java.version}</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<version>3.3.0</version>
<configuration>
<argLine>
${argLine}
Expand Down Expand Up @@ -283,7 +283,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.10</version>
<version>0.8.12</version>
<configuration>
<append>true</append>
<excludes>
Expand Down
26 changes: 14 additions & 12 deletions src/main/java/com/wasteofplastic/invswitcher/Store.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017 - 2021 tastybento
* Copyright (c) 2017 - 2024 tastybento
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -58,11 +58,6 @@
public class Store {
private static final CharSequence THE_END = "_the_end";
private static final CharSequence NETHER = "_nether";
@SuppressWarnings("deprecation")
private static final List<Material> BLOCKS = Arrays.stream(Material.values()).filter(Material::isBlock).filter(m -> !m.isLegacy()).toList();
@SuppressWarnings("deprecation")
private static final List<Material> ITEMS = Arrays.stream(Material.values()).filter(Material::isItem).filter(m -> !m.isLegacy()).toList();
private static final List<EntityType> LIVING_ENTITIES = Arrays.stream(EntityType.values()).filter(EntityType::isAlive).toList();
private final Database<InventoryStorage> database;
private final Map<UUID, InventoryStorage> cache;
private final InvSwitcher addon;
Expand Down Expand Up @@ -265,21 +260,24 @@ private void saveStats(InventoryStorage store, Player player, String worldName)
Map<EntityType, Integer> entMap;
switch (s.getType()) {
case BLOCK -> {
map = BLOCKS.stream().filter(m -> player.getStatistic(s, m) > 0)
map = Arrays.stream(Material.values()).filter(Material::isBlock).filter(m -> !m.isLegacy())
.filter(m -> player.getStatistic(s, m) > 0)
.collect(Collectors.toMap(k -> k, v -> player.getStatistic(s, v)));
if (!map.isEmpty()) {
store.getBlockStats(worldName).put(s, map);
}
}
case ITEM -> {
map = ITEMS.stream().filter(m -> player.getStatistic(s, m) > 0)
map = Arrays.stream(Material.values()).filter(Material::isItem).filter(m -> !m.isLegacy())
.filter(m -> player.getStatistic(s, m) > 0)
.collect(Collectors.toMap(k -> k, v -> player.getStatistic(s, v)));
if (!map.isEmpty()) {
store.getItemStats(worldName).put(s, map);
}
}
case ENTITY -> {
entMap = LIVING_ENTITIES.stream().filter(m -> player.getStatistic(s, m) > 0)
entMap = Arrays.stream(EntityType.values()).filter(EntityType::isAlive)
.filter(m -> player.getStatistic(s, m) > 0)
.collect(Collectors.toMap(k -> k, v -> player.getStatistic(s, v)));
if (!entMap.isEmpty()) {
store.getEntityStats(worldName).put(s, entMap);
Expand Down Expand Up @@ -364,11 +362,15 @@ private void resetAdv(Player player) {
}
}

@SuppressWarnings("deprecation")
private void resetStats(Player player, Statistic s) {
switch (s.getType()) {
case BLOCK -> BLOCKS.forEach(m -> player.setStatistic(s, m, 0));
case ITEM -> ITEMS.forEach(m -> player.setStatistic(s, m, 0));
case ENTITY -> LIVING_ENTITIES.forEach(en -> player.setStatistic(s, en, 0));
case BLOCK -> Arrays.stream(Material.values()).filter(Material::isBlock).filter(m -> !m.isLegacy())
.forEach(m -> player.setStatistic(s, m, 0));
case ITEM -> Arrays.stream(Material.values()).filter(Material::isItem).filter(m -> !m.isLegacy())
.forEach(m -> player.setStatistic(s, m, 0));
case ENTITY ->
Arrays.stream(EntityType.values()).filter(EntityType::isAlive).forEach(en -> player.setStatistic(s, en, 0));
case UNTYPED -> player.setStatistic(s, 0);
}
}
Expand Down
63 changes: 39 additions & 24 deletions src/test/java/com/wasteofplastic/invswitcher/InvSwitcherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand All @@ -15,6 +16,7 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Field;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -34,10 +36,9 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;

import com.wasteofplastic.invswitcher.listeners.PlayerListener;

Expand All @@ -52,8 +53,7 @@
* @author tastybento
*
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({Bukkit.class, BentoBox.class})
@RunWith(MockitoJUnitRunner.class)
public class InvSwitcherTest {

private static File jFile;
Expand Down Expand Up @@ -95,11 +95,20 @@ public static void beforeClass() throws IOException {
}

/**
* @throws SecurityException
* @throws NoSuchFieldException
* @throws IllegalAccessException
* @throws IllegalArgumentException
*/
@Before
public void setUp() {
public void setUp()
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
// Set up plugin
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
// Use reflection to set the private static field "instance" in BentoBox
Field instanceField = BentoBox.class.getDeclaredField("instance");

instanceField.setAccessible(true);
instanceField.set(null, plugin);
when(plugin.getLogger()).thenReturn(Logger.getAnonymousLogger());

// The database type has to be created one line before the thenReturn() to work!
Expand All @@ -117,10 +126,6 @@ public void setUp() {
// Addons manager
when(plugin.getAddonsManager()).thenReturn(am);

// Bukkit
PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getWorld(anyString())).thenReturn(world);

// World
when(world.getName()).thenReturn("bskyblock-world");
}
Expand Down Expand Up @@ -165,12 +170,17 @@ public void testOnEnable() {
*/
@Test
public void testOnDisable() {
addon.onLoad();
addon.getSettings().setWorlds(Set.of("bskyblock-world"));
addon.allLoaded();
addon.onDisable();
PowerMockito.verifyStatic(Bukkit.class);
Bukkit.getOnlinePlayers();
// Mock the static method
try (MockedStatic<Bukkit> mockedBukkit = mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS)) {
when(Bukkit.getWorld(anyString())).thenReturn(world);
// Run code to test
addon.onLoad();
addon.getSettings().setWorlds(Set.of("bskyblock-world"));
addon.allLoaded();
addon.onDisable();
// Verify that the static method was never called
mockedBukkit.verify(() -> Bukkit.getOnlinePlayers());
}
}

/**
Expand All @@ -188,12 +198,17 @@ public void testOnLoad() {
*/
@Test
public void testAllLoaded() {
addon.onLoad();
addon.getSettings().setWorlds(Set.of("bskyblock-world"));
addon.allLoaded();
verify(plugin).log("[InvSwitcher] Hooking into the following worlds:");
verify(plugin, times(3)).log("[InvSwitcher] bskyblock-world");
verify(am).registerListener(eq(addon), any(PlayerListener.class));
// Mock the static method
try (MockedStatic<Bukkit> mockedBukkit = mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS)) {
when(Bukkit.getWorld(anyString())).thenReturn(world);
// Run code to test
addon.onLoad();
addon.getSettings().setWorlds(Set.of("bskyblock-world"));
addon.allLoaded();
verify(plugin).log("[InvSwitcher] Hooking into the following worlds:");
verify(plugin, times(3)).log("[InvSwitcher] bskyblock-world");
verify(am).registerListener(eq(addon), any(PlayerListener.class));
}

}

Expand Down
Loading
Loading