From 67af02ce82071e6bd5214548f43bccd508da6b8d Mon Sep 17 00:00:00 2001 From: Phoenix-Starlight <64714532+Phoenix-Starlight@users.noreply.github.com> Date: Tue, 29 Aug 2023 18:20:47 -0700 Subject: [PATCH] Enforce LF endings automatically (#3946) --- .gitattributes | 2 + .../api/events/SlimefunGuideOpenEvent.java | 208 +++++++------- .../core/attributes/RandomMobDrop.java | 70 ++--- .../core/handlers/RainbowTickHandler.java | 268 +++++++++--------- 4 files changed, 275 insertions(+), 273 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..0be416846 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Automatically normalize line endings (to LF) for all text-based files. +* text=auto eol=lf diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/SlimefunGuideOpenEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/SlimefunGuideOpenEvent.java index f4892242a..ecf46a531 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/SlimefunGuideOpenEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/SlimefunGuideOpenEvent.java @@ -1,104 +1,104 @@ -package io.github.thebusybiscuit.slimefun4.api.events; - -import javax.annotation.Nonnull; - -import org.apache.commons.lang.Validate; -import org.bukkit.entity.Player; -import org.bukkit.event.Cancellable; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; -import org.bukkit.inventory.ItemStack; - -import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode; - -/** - * This {@link Event} is called whenever a {@link Player} tries to open the Slimefun Guide book. - * - * @author Linox - * - * @see SlimefunGuideMode - */ -public class SlimefunGuideOpenEvent extends Event implements Cancellable { - - private static final HandlerList handlers = new HandlerList(); - - private final Player player; - private final ItemStack guide; - private SlimefunGuideMode layout; - private boolean cancelled; - - public SlimefunGuideOpenEvent(@Nonnull Player p, @Nonnull ItemStack guide, @Nonnull SlimefunGuideMode layout) { - Validate.notNull(p, "The Player cannot be null"); - Validate.notNull(guide, "Guide cannot be null"); - Validate.notNull(layout, "Layout cannot be null"); - this.player = p; - this.guide = guide; - this.layout = layout; - } - - /** - * This returns the {@link Player} that tries to open - * the Slimefun Guide. - * - * @return The {@link Player} - */ - @Nonnull - public Player getPlayer() { - return player; - } - - /** - * This returns the {@link ItemStack} that {@link Player} - * tries to open the Slimefun Guide with. - * - * @return The {@link ItemStack} - */ - @Nonnull - public ItemStack getGuide() { - return guide; - } - - /** - * This returns the {@link SlimefunGuideMode} of the Slimefun Guide - * that {@link Player} tries to open. - * - * @return The {@link SlimefunGuideMode} - */ - @Nonnull - public SlimefunGuideMode getGuideLayout() { - return layout; - } - - /** - * Changes the {@link SlimefunGuideMode} that was tried to be opened with. - * - * @param layout - * The new {@link SlimefunGuideMode} - */ - public void setGuideLayout(@Nonnull SlimefunGuideMode layout) { - Validate.notNull(layout, "You must specify a layout that is not-null!"); - this.layout = layout; - } - - @Override - public boolean isCancelled() { - return cancelled; - } - - @Override - public void setCancelled(boolean cancel) { - this.cancelled = cancel; - } - - @Nonnull - public static HandlerList getHandlerList() { - return handlers; - } - - @Nonnull - @Override - public HandlerList getHandlers() { - return getHandlerList(); - } - -} +package io.github.thebusybiscuit.slimefun4.api.events; + +import javax.annotation.Nonnull; + +import org.apache.commons.lang.Validate; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.bukkit.inventory.ItemStack; + +import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode; + +/** + * This {@link Event} is called whenever a {@link Player} tries to open the Slimefun Guide book. + * + * @author Linox + * + * @see SlimefunGuideMode + */ +public class SlimefunGuideOpenEvent extends Event implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + + private final Player player; + private final ItemStack guide; + private SlimefunGuideMode layout; + private boolean cancelled; + + public SlimefunGuideOpenEvent(@Nonnull Player p, @Nonnull ItemStack guide, @Nonnull SlimefunGuideMode layout) { + Validate.notNull(p, "The Player cannot be null"); + Validate.notNull(guide, "Guide cannot be null"); + Validate.notNull(layout, "Layout cannot be null"); + this.player = p; + this.guide = guide; + this.layout = layout; + } + + /** + * This returns the {@link Player} that tries to open + * the Slimefun Guide. + * + * @return The {@link Player} + */ + @Nonnull + public Player getPlayer() { + return player; + } + + /** + * This returns the {@link ItemStack} that {@link Player} + * tries to open the Slimefun Guide with. + * + * @return The {@link ItemStack} + */ + @Nonnull + public ItemStack getGuide() { + return guide; + } + + /** + * This returns the {@link SlimefunGuideMode} of the Slimefun Guide + * that {@link Player} tries to open. + * + * @return The {@link SlimefunGuideMode} + */ + @Nonnull + public SlimefunGuideMode getGuideLayout() { + return layout; + } + + /** + * Changes the {@link SlimefunGuideMode} that was tried to be opened with. + * + * @param layout + * The new {@link SlimefunGuideMode} + */ + public void setGuideLayout(@Nonnull SlimefunGuideMode layout) { + Validate.notNull(layout, "You must specify a layout that is not-null!"); + this.layout = layout; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } + + @Nonnull + public static HandlerList getHandlerList() { + return handlers; + } + + @Nonnull + @Override + public HandlerList getHandlers() { + return getHandlerList(); + } + +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/RandomMobDrop.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/RandomMobDrop.java index 964376039..a0e51fe32 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/RandomMobDrop.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/RandomMobDrop.java @@ -1,35 +1,35 @@ -package io.github.thebusybiscuit.slimefun4.core.attributes; - -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.event.entity.EntityDeathEvent; - -import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; -import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; -import io.github.thebusybiscuit.slimefun4.implementation.items.misc.BasicCircuitBoard; -import io.github.thebusybiscuit.slimefun4.implementation.listeners.entity.MobDropListener; - -/** - * This interface, when attached to a {@link SlimefunItem}, provides an easy method for adding - * a % chance to drop for an {@link SlimefunItem} on {@link EntityDeathEvent}, this chance is 0-100 - * and used in conjunction with the {@link RecipeType#MOB_DROP}. - * - * @author dNiym - * - * @see BasicCircuitBoard - * @see MobDropListener - * @see PiglinBarterDrop - * - */ -public interface RandomMobDrop extends ItemAttribute { - - /** - * Implement this method to make the object have a variable chance of being - * added to the dropList when {@link EntityType} specified in - * the {@link RecipeType#MOB_DROP} is killed by the {@link Player}. - * - * @return The integer chance (0-100%) {@link SlimefunItem} has to drop. - */ - int getMobDropChance(); - -} +package io.github.thebusybiscuit.slimefun4.core.attributes; + +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.event.entity.EntityDeathEvent; + +import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; +import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; +import io.github.thebusybiscuit.slimefun4.implementation.items.misc.BasicCircuitBoard; +import io.github.thebusybiscuit.slimefun4.implementation.listeners.entity.MobDropListener; + +/** + * This interface, when attached to a {@link SlimefunItem}, provides an easy method for adding + * a % chance to drop for an {@link SlimefunItem} on {@link EntityDeathEvent}, this chance is 0-100 + * and used in conjunction with the {@link RecipeType#MOB_DROP}. + * + * @author dNiym + * + * @see BasicCircuitBoard + * @see MobDropListener + * @see PiglinBarterDrop + * + */ +public interface RandomMobDrop extends ItemAttribute { + + /** + * Implement this method to make the object have a variable chance of being + * added to the dropList when {@link EntityType} specified in + * the {@link RecipeType#MOB_DROP} is killed by the {@link Player}. + * + * @return The integer chance (0-100%) {@link SlimefunItem} has to drop. + */ + int getMobDropChance(); + +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/RainbowTickHandler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/RainbowTickHandler.java index 38900d852..6fa656f6d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/RainbowTickHandler.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/RainbowTickHandler.java @@ -1,134 +1,134 @@ -package io.github.thebusybiscuit.slimefun4.core.handlers; - -import java.util.Arrays; -import java.util.List; - -import javax.annotation.Nonnull; - -import org.apache.commons.lang.Validate; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.data.BlockData; -import org.bukkit.block.data.type.GlassPane; - -import io.github.bakedlibs.dough.collections.LoopIterator; -import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; -import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; -import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; -import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.RainbowBlock; -import io.github.thebusybiscuit.slimefun4.utils.ColoredMaterial; - -import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; -import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker; - -/** - * This is a {@link BlockTicker} that is exclusively used for Rainbow blocks. - * On every tick it cycles through the {@link LoopIterator} and chooses the next {@link Material} - * and sets itself to that. - * - * @author TheBusyBiscuit - * - * @see RainbowBlock - * - */ -public class RainbowTickHandler extends BlockTicker { - - private final LoopIterator iterator; - private final boolean glassPanes; - private Material material; - - public RainbowTickHandler(@Nonnull List materials) { - Validate.noNullElements(materials, "A RainbowTicker cannot have a Material that is null!"); - - if (materials.isEmpty()) { - throw new IllegalArgumentException("A RainbowTicker must have at least one Material associated with it!"); - } - - glassPanes = containsGlassPanes(materials); - iterator = new LoopIterator<>(materials); - material = iterator.next(); - } - - public RainbowTickHandler(@Nonnull Material... materials) { - this(Arrays.asList(materials)); - } - - public RainbowTickHandler(@Nonnull ColoredMaterial material) { - this(material.asList()); - } - - /** - * This method checks whether a given {@link Material} array contains any {@link Material} - * that would result in a {@link GlassPane} {@link BlockData}. - * This is done to save performance, so we don't have to validate {@link BlockData} at - * runtime. - * - * @param materials - * The {@link Material} Array to check - * - * @return Whether the array contained any {@link GlassPane} materials - */ - private boolean containsGlassPanes(@Nonnull List materials) { - if (Slimefun.getMinecraftVersion() == MinecraftVersion.UNIT_TEST) { - // BlockData is not available to us during Unit Tests :/ - return false; - } - - for (Material type : materials) { - /* - This BlockData is purely virtual and only created on startup, it should have - no impact on performance, in fact it should save performance as it preloads - the data but also saves heavy calls for other Materials - */ - if (type.createBlockData() instanceof GlassPane) { - return true; - } - } - - return false; - } - - @Override - public void tick(Block b, SlimefunItem item, Config data) { - if (b.getType().isAir()) { - /* - The block was broken, setting the Material now would result in a - duplication glitch - */ - return; - } - - if (glassPanes) { - BlockData blockData = b.getBlockData(); - - if (blockData instanceof GlassPane previousData) { - BlockData block = material.createBlockData(bd -> { - if (bd instanceof GlassPane nextData) { - nextData.setWaterlogged(previousData.isWaterlogged()); - - for (BlockFace face : previousData.getAllowedFaces()) { - nextData.setFace(face, previousData.hasFace(face)); - } - } - }); - - b.setBlockData(block, false); - return; - } - } - - b.setType(material, false); - } - - @Override - public void uniqueTick() { - material = iterator.next(); - } - - @Override - public boolean isSynchronized() { - return true; - } - -} +package io.github.thebusybiscuit.slimefun4.core.handlers; + +import java.util.Arrays; +import java.util.List; + +import javax.annotation.Nonnull; + +import org.apache.commons.lang.Validate; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.type.GlassPane; + +import io.github.bakedlibs.dough.collections.LoopIterator; +import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; +import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; +import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; +import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.RainbowBlock; +import io.github.thebusybiscuit.slimefun4.utils.ColoredMaterial; + +import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; +import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker; + +/** + * This is a {@link BlockTicker} that is exclusively used for Rainbow blocks. + * On every tick it cycles through the {@link LoopIterator} and chooses the next {@link Material} + * and sets itself to that. + * + * @author TheBusyBiscuit + * + * @see RainbowBlock + * + */ +public class RainbowTickHandler extends BlockTicker { + + private final LoopIterator iterator; + private final boolean glassPanes; + private Material material; + + public RainbowTickHandler(@Nonnull List materials) { + Validate.noNullElements(materials, "A RainbowTicker cannot have a Material that is null!"); + + if (materials.isEmpty()) { + throw new IllegalArgumentException("A RainbowTicker must have at least one Material associated with it!"); + } + + glassPanes = containsGlassPanes(materials); + iterator = new LoopIterator<>(materials); + material = iterator.next(); + } + + public RainbowTickHandler(@Nonnull Material... materials) { + this(Arrays.asList(materials)); + } + + public RainbowTickHandler(@Nonnull ColoredMaterial material) { + this(material.asList()); + } + + /** + * This method checks whether a given {@link Material} array contains any {@link Material} + * that would result in a {@link GlassPane} {@link BlockData}. + * This is done to save performance, so we don't have to validate {@link BlockData} at + * runtime. + * + * @param materials + * The {@link Material} Array to check + * + * @return Whether the array contained any {@link GlassPane} materials + */ + private boolean containsGlassPanes(@Nonnull List materials) { + if (Slimefun.getMinecraftVersion() == MinecraftVersion.UNIT_TEST) { + // BlockData is not available to us during Unit Tests :/ + return false; + } + + for (Material type : materials) { + /* + This BlockData is purely virtual and only created on startup, it should have + no impact on performance, in fact it should save performance as it preloads + the data but also saves heavy calls for other Materials + */ + if (type.createBlockData() instanceof GlassPane) { + return true; + } + } + + return false; + } + + @Override + public void tick(Block b, SlimefunItem item, Config data) { + if (b.getType().isAir()) { + /* + The block was broken, setting the Material now would result in a + duplication glitch + */ + return; + } + + if (glassPanes) { + BlockData blockData = b.getBlockData(); + + if (blockData instanceof GlassPane previousData) { + BlockData block = material.createBlockData(bd -> { + if (bd instanceof GlassPane nextData) { + nextData.setWaterlogged(previousData.isWaterlogged()); + + for (BlockFace face : previousData.getAllowedFaces()) { + nextData.setFace(face, previousData.hasFace(face)); + } + } + }); + + b.setBlockData(block, false); + return; + } + } + + b.setType(material, false); + } + + @Override + public void uniqueTick() { + material = iterator.next(); + } + + @Override + public boolean isSynchronized() { + return true; + } + +}