mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
[CI skip] Refactoring
This commit is contained in:
parent
3f5fb7c7a7
commit
ec8eed58f9
19
pom.xml
19
pom.xml
@ -9,10 +9,11 @@
|
||||
|
||||
<!-- Our default version will be UNOFFICIAL, this will prevent auto updates -->
|
||||
<!-- from overriding our local test file -->
|
||||
<version>4.8-UNOFFICIAL</version>
|
||||
<version>4.9-UNOFFICIAL</version>
|
||||
<inceptionYear>2013</inceptionYear>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<!-- Project Info -->
|
||||
<description>Slimefun is a Spigot/Paper plugin that simulates a modpack-like atmosphere by adding over 500 new items and recipes to your Minecraft Server.</description>
|
||||
<url>https://github.com/Slimefun/Slimefun4</url>
|
||||
|
||||
@ -33,11 +34,13 @@
|
||||
<sonar.coverage.jacoco.xmlReportPaths>target/site/jacoco/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
|
||||
</properties>
|
||||
|
||||
<!-- Bug Tracker -->
|
||||
<issueManagement>
|
||||
<system>GitHub Issues</system>
|
||||
<url>https://github.com/Slimefun/Slimefun4/issues</url>
|
||||
</issueManagement>
|
||||
|
||||
<!-- License -->
|
||||
<licenses>
|
||||
<license>
|
||||
<name>GNU General Public License v3.0</name>
|
||||
@ -46,6 +49,7 @@
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<!-- The repositories which host our dependencies -->
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
@ -77,11 +81,13 @@
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<!-- Build settings -->
|
||||
<build>
|
||||
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
|
||||
<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
|
||||
<defaultGoal>clean package</defaultGoal>
|
||||
|
||||
<!-- The name of the final jar -->
|
||||
<finalName>${project.name} v${project.version}</finalName>
|
||||
|
||||
<plugins>
|
||||
@ -104,6 +110,7 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.2.1</version>
|
||||
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
@ -119,6 +126,11 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.0.0-M5</version>
|
||||
|
||||
<configuration>
|
||||
<junitArtifactName>org.junit.jupiter:junit-jupiter</junitArtifactName>
|
||||
<trimStackTrace>false</trimStackTrace>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!-- Sonarcloud Scanner -->
|
||||
@ -137,6 +149,7 @@
|
||||
<executions>
|
||||
<execution>
|
||||
<id>prepare</id>
|
||||
|
||||
<goals>
|
||||
<goal>prepare-agent</goal>
|
||||
</goals>
|
||||
@ -145,6 +158,7 @@
|
||||
<execution>
|
||||
<id>report</id>
|
||||
<phase>test</phase>
|
||||
|
||||
<goals>
|
||||
<goal>report</goal>
|
||||
</goals>
|
||||
@ -159,8 +173,7 @@
|
||||
<version>3.2.4</version>
|
||||
|
||||
<configuration>
|
||||
|
||||
<!-- Shade dependencies into the output jar -->
|
||||
<!-- Relocate these to avoid clashes and conflicts -->
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>io.github.thebusybiscuit.cscorelib2</pattern>
|
||||
|
@ -35,6 +35,9 @@ import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||
* an {@link ErrorReport} instead.
|
||||
* Error reports get saved in the plugin folder.
|
||||
*
|
||||
* @param <T>
|
||||
* The type of {@link Throwable} which has spawned this {@link ErrorReport}
|
||||
*
|
||||
* @author TheBusyBiscuit
|
||||
*
|
||||
*/
|
||||
@ -222,6 +225,16 @@ public class ErrorReport<T extends Throwable> {
|
||||
return newFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* This helper method wraps the given {@link Runnable} into a try-catch block.
|
||||
* When an {@link Exception} occurs, a new {@link ErrorReport} will be generated using
|
||||
* the provided {@link Function}.
|
||||
*
|
||||
* @param function
|
||||
* The {@link Function} to generate a new {@link ErrorReport}
|
||||
* @param runnable
|
||||
* The code to execute
|
||||
*/
|
||||
public static void tryCatch(@Nonnull Function<Exception, ErrorReport<Exception>> function, @Nonnull Runnable runnable) {
|
||||
try {
|
||||
runnable.run();
|
||||
|
@ -34,10 +34,10 @@ public class AncientAltarCraftEvent extends PlayerEvent implements Cancellable {
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* @param block
|
||||
* The altar {@link Block}
|
||||
* @param output
|
||||
* The {@link ItemStack} that would be dropped by the ritual
|
||||
* @param block
|
||||
* The altar {@link Block}
|
||||
* @param player
|
||||
* The {@link Player} that started the ritual.
|
||||
*/
|
||||
|
@ -12,6 +12,9 @@ import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
|
||||
* This variation of {@link ItemSetting} allows you to allow {@link Enum} constants to be
|
||||
* used for {@link ItemSetting} validation.
|
||||
*
|
||||
* @param <T>
|
||||
* The {@link Enum} type
|
||||
*
|
||||
* @author TheBusyBiscuit
|
||||
*
|
||||
* @see ItemSetting
|
||||
@ -41,6 +44,7 @@ public class EnumSetting<T extends Enum<T>> extends ItemSetting<String> {
|
||||
*
|
||||
* @return An array of allowed {@link Enum} constants
|
||||
*/
|
||||
@Nonnull
|
||||
public T[] getAllowedValues() {
|
||||
return enumClass.getEnumConstants();
|
||||
}
|
||||
@ -50,6 +54,7 @@ public class EnumSetting<T extends Enum<T>> extends ItemSetting<String> {
|
||||
*
|
||||
* @return The value as an {@link Enum} constant
|
||||
*/
|
||||
@Nonnull
|
||||
public T getAsEnumConstant() {
|
||||
return Enum.valueOf(enumClass, getValue());
|
||||
}
|
||||
|
@ -140,6 +140,7 @@ public final class SlimefunRegistry {
|
||||
automaticallyLoadItems = mode;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public List<Category> getCategories() {
|
||||
return categories;
|
||||
}
|
||||
@ -149,6 +150,7 @@ public final class SlimefunRegistry {
|
||||
*
|
||||
* @return A {@link List} containing every {@link SlimefunItem}
|
||||
*/
|
||||
@Nonnull
|
||||
public List<SlimefunItem> getAllSlimefunItems() {
|
||||
return slimefunItems;
|
||||
}
|
||||
@ -158,18 +160,22 @@ public final class SlimefunRegistry {
|
||||
*
|
||||
* @return A {@link List} containing every enabled {@link SlimefunItem}
|
||||
*/
|
||||
@Nonnull
|
||||
public List<SlimefunItem> getEnabledSlimefunItems() {
|
||||
return enabledItems;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public List<Research> getResearches() {
|
||||
return researches;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public Set<UUID> getCurrentlyResearchingPlayers() {
|
||||
return researchingPlayers;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public List<String> getResearchRanks() {
|
||||
return researchRanks;
|
||||
}
|
||||
@ -194,6 +200,7 @@ public final class SlimefunRegistry {
|
||||
return researchFireworks;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public List<MultiBlock> getMultiBlocks() {
|
||||
return multiblocks;
|
||||
}
|
||||
@ -226,6 +233,7 @@ public final class SlimefunRegistry {
|
||||
*
|
||||
* @return The {@link Map} of custom mob drops
|
||||
*/
|
||||
@Nonnull
|
||||
public Map<EntityType, Set<ItemStack>> getMobDrops() {
|
||||
return mobDrops;
|
||||
}
|
||||
@ -236,50 +244,62 @@ public final class SlimefunRegistry {
|
||||
*
|
||||
* @return A {@link Set} of bartering drops
|
||||
*/
|
||||
@Nonnull
|
||||
public Set<ItemStack> getBarteringDrops() {
|
||||
return barterDrops;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public Set<SlimefunItem> getRadioactiveItems() {
|
||||
return radioactive;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public Set<String> getTickerBlocks() {
|
||||
return tickers;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public Map<String, SlimefunItem> getSlimefunItemIds() {
|
||||
return slimefunIds;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public Map<String, BlockMenuPreset> getMenuPresets() {
|
||||
return blockMenuPresets;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public Map<String, UniversalBlockMenu> getUniversalInventories() {
|
||||
return universalInventories;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public Map<UUID, PlayerProfile> getPlayerProfiles() {
|
||||
return profiles;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public Map<Class<? extends ItemHandler>, Set<ItemHandler>> getPublicItemHandlers() {
|
||||
return globalItemHandlers;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public Map<String, SlimefunBlockHandler> getBlockHandlers() {
|
||||
return blockHandlers;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public Map<String, BlockStorage> getWorlds() {
|
||||
return worlds;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public Map<String, BlockInfoConfig> getChunks() {
|
||||
return chunks;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public KeyMap<GEOResource> getGEOResources() {
|
||||
return geoResources;
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ public abstract class FlexCategory extends Category {
|
||||
|
||||
@Override
|
||||
public final boolean isHidden(@Nonnull Player p) {
|
||||
/**
|
||||
/*
|
||||
* We can stop this method right here.
|
||||
* We provide a custom method with more parameters for this.
|
||||
* See isVisible(...)
|
||||
|
@ -149,12 +149,13 @@ public class LockedCategory extends Category {
|
||||
* The {@link Player} to check
|
||||
* @param profile
|
||||
* The {@link PlayerProfile} that belongs to the given {@link Player}
|
||||
*
|
||||
* @return Whether the {@link Player} has fully completed all parent categories, otherwise false
|
||||
*/
|
||||
public boolean hasUnlocked(@Nonnull Player p, @Nonnull PlayerProfile profile) {
|
||||
for (Category category : parents) {
|
||||
for (SlimefunItem item : category.getItems()) {
|
||||
/**
|
||||
/*
|
||||
* Should probably be replaced with Slimefun.hasUnlocked(...)
|
||||
* However this will result in better performance because we don't
|
||||
* request the PlayerProfile everytime
|
||||
|
@ -19,7 +19,7 @@ class GuideCommand extends SubCommand {
|
||||
public void onExecute(CommandSender sender, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
if (sender.hasPermission("slimefun.command.guide")) {
|
||||
SlimefunGuideMode design = SlimefunGuide.getDefaultLayout();
|
||||
SlimefunGuideMode design = SlimefunGuide.getDefaultMode();
|
||||
((Player) sender).getInventory().addItem(SlimefunGuide.getItem(design).clone());
|
||||
} else {
|
||||
SlimefunPlugin.getLocalization().sendMessage(sender, "messages.no-permission", true);
|
||||
|
@ -9,6 +9,7 @@ import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
|
||||
import io.github.thebusybiscuit.slimefun4.core.commands.SlimefunCommand;
|
||||
import io.github.thebusybiscuit.slimefun4.core.commands.SubCommand;
|
||||
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide;
|
||||
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
|
||||
class SearchCommand extends SubCommand {
|
||||
@ -23,7 +24,7 @@ class SearchCommand extends SubCommand {
|
||||
if (sender.hasPermission("slimefun.command.search")) {
|
||||
if (args.length > 1) {
|
||||
String query = String.join(" ", Arrays.copyOfRange(args, 1, args.length));
|
||||
PlayerProfile.get((Player) sender, profile -> SlimefunGuide.openSearch(profile, query, true, true));
|
||||
PlayerProfile.get((Player) sender, profile -> SlimefunGuide.openSearch(profile, query, SlimefunGuideMode.SURVIVAL_MODE, true));
|
||||
} else {
|
||||
SlimefunPlugin.getLocalization().sendMessage(sender, "messages.usage", true, msg -> msg.replace("%usage%", "/sf search <SearchTerm>"));
|
||||
}
|
||||
|
@ -71,31 +71,26 @@ public final class SlimefunGuide {
|
||||
}
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
private static void openMainMenuAsync(Player player, SlimefunGuideMode layout, int selectedPage) {
|
||||
if (!PlayerProfile.get(player, profile -> SlimefunPlugin.runSync(() -> openMainMenu(profile, layout, selectedPage)))) {
|
||||
private static void openMainMenuAsync(Player player, SlimefunGuideMode mode, int selectedPage) {
|
||||
if (!PlayerProfile.get(player, profile -> SlimefunPlugin.runSync(() -> openMainMenu(profile, mode, selectedPage)))) {
|
||||
SlimefunPlugin.getLocalization().sendMessage(player, "messages.opening-guide");
|
||||
}
|
||||
}
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public static void openMainMenu(PlayerProfile profile, SlimefunGuideMode layout, int selectedPage) {
|
||||
SlimefunPlugin.getRegistry().getSlimefunGuide(layout).openMainMenu(profile, selectedPage);
|
||||
public static void openMainMenu(PlayerProfile profile, SlimefunGuideMode mode, int selectedPage) {
|
||||
SlimefunPlugin.getRegistry().getSlimefunGuide(mode).openMainMenu(profile, selectedPage);
|
||||
}
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public static void openCategory(PlayerProfile profile, Category category, SlimefunGuideMode layout, int selectedPage) {
|
||||
SlimefunPlugin.getRegistry().getSlimefunGuide(layout).openCategory(profile, category, selectedPage);
|
||||
public static void openCategory(PlayerProfile profile, Category category, SlimefunGuideMode mode, int selectedPage) {
|
||||
SlimefunPlugin.getRegistry().getSlimefunGuide(mode).openCategory(profile, category, selectedPage);
|
||||
}
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public static void openSearch(PlayerProfile profile, String input, boolean survival, boolean addToHistory) {
|
||||
SlimefunGuideImplementation layout = SlimefunPlugin.getRegistry().getSlimefunGuide(SlimefunGuideMode.SURVIVAL_MODE);
|
||||
|
||||
if (!survival) {
|
||||
layout = SlimefunPlugin.getRegistry().getSlimefunGuide(SlimefunGuideMode.CHEAT_MODE);
|
||||
}
|
||||
|
||||
layout.openSearch(profile, input, addToHistory);
|
||||
public static void openSearch(PlayerProfile profile, String input, SlimefunGuideMode mode, boolean addToHistory) {
|
||||
SlimefunGuideImplementation guide = SlimefunPlugin.getRegistry().getSlimefunGuide(mode);
|
||||
guide.openSearch(profile, input, addToHistory);
|
||||
}
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
@ -127,13 +122,13 @@ public final class SlimefunGuide {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default layout for the Slimefun guide.
|
||||
* Get the default mode for the Slimefun guide.
|
||||
* Currently this is only {@link SlimefunGuideMode#SURVIVAL_MODE}.
|
||||
*
|
||||
* @return The default {@link SlimefunGuideLayout}.
|
||||
* @return The default {@link SlimefunGuideMode}.
|
||||
*/
|
||||
@Nonnull
|
||||
public static SlimefunGuideMode getDefaultLayout() {
|
||||
public static SlimefunGuideMode getDefaultMode() {
|
||||
return SlimefunGuideMode.SURVIVAL_MODE;
|
||||
}
|
||||
}
|
||||
|
@ -570,7 +570,7 @@ public class SurvivalSlimefunGuide implements SlimefunGuideImplementation {
|
||||
pl.closeInventory();
|
||||
|
||||
SlimefunPlugin.getLocalization().sendMessage(pl, "guide.search.message");
|
||||
ChatInput.waitForPlayer(SlimefunPlugin.instance(), pl, msg -> SlimefunGuide.openSearch(profile, msg, isSurvivalMode(), isSurvivalMode()));
|
||||
ChatInput.waitForPlayer(SlimefunPlugin.instance(), pl, msg -> SlimefunGuide.openSearch(profile, msg, getMode(), isSurvivalMode()));
|
||||
|
||||
return false;
|
||||
});
|
||||
|
@ -105,7 +105,6 @@ public class StomperBoots extends SlimefunItem {
|
||||
* @return If the entity can move.
|
||||
*/
|
||||
protected boolean canPush(@Nonnull Player player, @Nonnull LivingEntity entity) {
|
||||
return entity.isValid() && !entity.getUniqueId().equals(player.getUniqueId())
|
||||
&& entity.isCollidable() && entity.hasGravity();
|
||||
return entity.isValid() && !entity.getUniqueId().equals(player.getUniqueId()) && entity.isCollidable() && entity.hasGravity();
|
||||
}
|
||||
}
|
||||
|
@ -52,8 +52,7 @@ public class MultiTool extends SlimefunItem implements Rechargeable {
|
||||
if (index >= modes.size()) {
|
||||
index = 0;
|
||||
}
|
||||
}
|
||||
while (index != i && !modes.get(index).isEnabled());
|
||||
} while (index != i && !modes.get(index).isEnabled());
|
||||
|
||||
return index;
|
||||
}
|
||||
|
@ -67,12 +67,13 @@ public class BlockListener implements Listener {
|
||||
SlimefunItem sfItem = BlockStorage.check(block);
|
||||
|
||||
if (sfItem != null) {
|
||||
/* Temp fix for #2636
|
||||
for (ItemStack item : sfItem.getDrops()) {
|
||||
if (item != null && !item.getType().isAir()) {
|
||||
block.getWorld().dropItemNaturally(block.getLocation(), item);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Temp fix for #2636
|
||||
* for (ItemStack item : sfItem.getDrops()) {
|
||||
* if (item != null && !item.getType().isAir()) {
|
||||
* block.getWorld().dropItemNaturally(block.getLocation(), item);
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
BlockStorage.clearBlockInfo(block);
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class SlimefunGuideListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
SlimefunGuideMode type = SlimefunGuide.getDefaultLayout();
|
||||
SlimefunGuideMode type = SlimefunGuide.getDefaultMode();
|
||||
p.getInventory().addItem(SlimefunGuide.getItem(type).clone());
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ class TestSlimefunGuideListener {
|
||||
PlayerJoinEvent event = new PlayerJoinEvent(player, "CanIHazGuide has joined and wants sum guide");
|
||||
listener.onJoin(event);
|
||||
|
||||
ItemStack guide = SlimefunGuide.getItem(SlimefunGuide.getDefaultLayout());
|
||||
ItemStack guide = SlimefunGuide.getItem(SlimefunGuide.getDefaultMode());
|
||||
Assertions.assertEquals(!hasPlayedBefore && giveSlimefunGuide, hasSlimefunGuide(player, guide));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user