1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 11:15:51 +00:00

Enforce LF endings automatically (#3946)

This commit is contained in:
Phoenix-Starlight 2023-08-29 18:20:47 -07:00 committed by GitHub
parent 68edac523e
commit 67af02ce82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 275 additions and 273 deletions

2
.gitattributes vendored Normal file
View File

@ -0,0 +1,2 @@
# Automatically normalize line endings (to LF) for all text-based files.
* text=auto eol=lf

View File

@ -1,104 +1,104 @@
package io.github.thebusybiscuit.slimefun4.api.events; package io.github.thebusybiscuit.slimefun4.api.events;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode; import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode;
/** /**
* This {@link Event} is called whenever a {@link Player} tries to open the Slimefun Guide book. * This {@link Event} is called whenever a {@link Player} tries to open the Slimefun Guide book.
* *
* @author Linox * @author Linox
* *
* @see SlimefunGuideMode * @see SlimefunGuideMode
*/ */
public class SlimefunGuideOpenEvent extends Event implements Cancellable { public class SlimefunGuideOpenEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
private final Player player; private final Player player;
private final ItemStack guide; private final ItemStack guide;
private SlimefunGuideMode layout; private SlimefunGuideMode layout;
private boolean cancelled; private boolean cancelled;
public SlimefunGuideOpenEvent(@Nonnull Player p, @Nonnull ItemStack guide, @Nonnull SlimefunGuideMode layout) { public SlimefunGuideOpenEvent(@Nonnull Player p, @Nonnull ItemStack guide, @Nonnull SlimefunGuideMode layout) {
Validate.notNull(p, "The Player cannot be null"); Validate.notNull(p, "The Player cannot be null");
Validate.notNull(guide, "Guide cannot be null"); Validate.notNull(guide, "Guide cannot be null");
Validate.notNull(layout, "Layout cannot be null"); Validate.notNull(layout, "Layout cannot be null");
this.player = p; this.player = p;
this.guide = guide; this.guide = guide;
this.layout = layout; this.layout = layout;
} }
/** /**
* This returns the {@link Player} that tries to open * This returns the {@link Player} that tries to open
* the Slimefun Guide. * the Slimefun Guide.
* *
* @return The {@link Player} * @return The {@link Player}
*/ */
@Nonnull @Nonnull
public Player getPlayer() { public Player getPlayer() {
return player; return player;
} }
/** /**
* This returns the {@link ItemStack} that {@link Player} * This returns the {@link ItemStack} that {@link Player}
* tries to open the Slimefun Guide with. * tries to open the Slimefun Guide with.
* *
* @return The {@link ItemStack} * @return The {@link ItemStack}
*/ */
@Nonnull @Nonnull
public ItemStack getGuide() { public ItemStack getGuide() {
return guide; return guide;
} }
/** /**
* This returns the {@link SlimefunGuideMode} of the Slimefun Guide * This returns the {@link SlimefunGuideMode} of the Slimefun Guide
* that {@link Player} tries to open. * that {@link Player} tries to open.
* *
* @return The {@link SlimefunGuideMode} * @return The {@link SlimefunGuideMode}
*/ */
@Nonnull @Nonnull
public SlimefunGuideMode getGuideLayout() { public SlimefunGuideMode getGuideLayout() {
return layout; return layout;
} }
/** /**
* Changes the {@link SlimefunGuideMode} that was tried to be opened with. * Changes the {@link SlimefunGuideMode} that was tried to be opened with.
* *
* @param layout * @param layout
* The new {@link SlimefunGuideMode} * The new {@link SlimefunGuideMode}
*/ */
public void setGuideLayout(@Nonnull SlimefunGuideMode layout) { public void setGuideLayout(@Nonnull SlimefunGuideMode layout) {
Validate.notNull(layout, "You must specify a layout that is not-null!"); Validate.notNull(layout, "You must specify a layout that is not-null!");
this.layout = layout; this.layout = layout;
} }
@Override @Override
public boolean isCancelled() { public boolean isCancelled() {
return cancelled; return cancelled;
} }
@Override @Override
public void setCancelled(boolean cancel) { public void setCancelled(boolean cancel) {
this.cancelled = cancel; this.cancelled = cancel;
} }
@Nonnull @Nonnull
public static HandlerList getHandlerList() { public static HandlerList getHandlerList() {
return handlers; return handlers;
} }
@Nonnull @Nonnull
@Override @Override
public HandlerList getHandlers() { public HandlerList getHandlers() {
return getHandlerList(); return getHandlerList();
} }
} }

View File

@ -1,35 +1,35 @@
package io.github.thebusybiscuit.slimefun4.core.attributes; package io.github.thebusybiscuit.slimefun4.core.attributes;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityDeathEvent;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import io.github.thebusybiscuit.slimefun4.implementation.items.misc.BasicCircuitBoard; import io.github.thebusybiscuit.slimefun4.implementation.items.misc.BasicCircuitBoard;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.entity.MobDropListener; import io.github.thebusybiscuit.slimefun4.implementation.listeners.entity.MobDropListener;
/** /**
* This interface, when attached to a {@link SlimefunItem}, provides an easy method for adding * 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 * 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}. * and used in conjunction with the {@link RecipeType#MOB_DROP}.
* *
* @author dNiym * @author dNiym
* *
* @see BasicCircuitBoard * @see BasicCircuitBoard
* @see MobDropListener * @see MobDropListener
* @see PiglinBarterDrop * @see PiglinBarterDrop
* *
*/ */
public interface RandomMobDrop extends ItemAttribute { public interface RandomMobDrop extends ItemAttribute {
/** /**
* Implement this method to make the object have a variable chance of being * Implement this method to make the object have a variable chance of being
* added to the dropList when {@link EntityType} specified in * added to the dropList when {@link EntityType} specified in
* the {@link RecipeType#MOB_DROP} is killed by the {@link Player}. * the {@link RecipeType#MOB_DROP} is killed by the {@link Player}.
* *
* @return The integer chance (0-100%) {@link SlimefunItem} has to drop. * @return The integer chance (0-100%) {@link SlimefunItem} has to drop.
*/ */
int getMobDropChance(); int getMobDropChance();
} }

View File

@ -1,134 +1,134 @@
package io.github.thebusybiscuit.slimefun4.core.handlers; package io.github.thebusybiscuit.slimefun4.core.handlers;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.GlassPane; import org.bukkit.block.data.type.GlassPane;
import io.github.bakedlibs.dough.collections.LoopIterator; import io.github.bakedlibs.dough.collections.LoopIterator;
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.RainbowBlock; import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.RainbowBlock;
import io.github.thebusybiscuit.slimefun4.utils.ColoredMaterial; import io.github.thebusybiscuit.slimefun4.utils.ColoredMaterial;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker; import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
/** /**
* This is a {@link BlockTicker} that is exclusively used for Rainbow blocks. * 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} * On every tick it cycles through the {@link LoopIterator} and chooses the next {@link Material}
* and sets itself to that. * and sets itself to that.
* *
* @author TheBusyBiscuit * @author TheBusyBiscuit
* *
* @see RainbowBlock * @see RainbowBlock
* *
*/ */
public class RainbowTickHandler extends BlockTicker { public class RainbowTickHandler extends BlockTicker {
private final LoopIterator<Material> iterator; private final LoopIterator<Material> iterator;
private final boolean glassPanes; private final boolean glassPanes;
private Material material; private Material material;
public RainbowTickHandler(@Nonnull List<Material> materials) { public RainbowTickHandler(@Nonnull List<Material> materials) {
Validate.noNullElements(materials, "A RainbowTicker cannot have a Material that is null!"); Validate.noNullElements(materials, "A RainbowTicker cannot have a Material that is null!");
if (materials.isEmpty()) { if (materials.isEmpty()) {
throw new IllegalArgumentException("A RainbowTicker must have at least one Material associated with it!"); throw new IllegalArgumentException("A RainbowTicker must have at least one Material associated with it!");
} }
glassPanes = containsGlassPanes(materials); glassPanes = containsGlassPanes(materials);
iterator = new LoopIterator<>(materials); iterator = new LoopIterator<>(materials);
material = iterator.next(); material = iterator.next();
} }
public RainbowTickHandler(@Nonnull Material... materials) { public RainbowTickHandler(@Nonnull Material... materials) {
this(Arrays.asList(materials)); this(Arrays.asList(materials));
} }
public RainbowTickHandler(@Nonnull ColoredMaterial material) { public RainbowTickHandler(@Nonnull ColoredMaterial material) {
this(material.asList()); this(material.asList());
} }
/** /**
* This method checks whether a given {@link Material} array contains any {@link Material} * This method checks whether a given {@link Material} array contains any {@link Material}
* that would result in a {@link GlassPane} {@link BlockData}. * 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 * This is done to save performance, so we don't have to validate {@link BlockData} at
* runtime. * runtime.
* *
* @param materials * @param materials
* The {@link Material} Array to check * The {@link Material} Array to check
* *
* @return Whether the array contained any {@link GlassPane} materials * @return Whether the array contained any {@link GlassPane} materials
*/ */
private boolean containsGlassPanes(@Nonnull List<Material> materials) { private boolean containsGlassPanes(@Nonnull List<Material> materials) {
if (Slimefun.getMinecraftVersion() == MinecraftVersion.UNIT_TEST) { if (Slimefun.getMinecraftVersion() == MinecraftVersion.UNIT_TEST) {
// BlockData is not available to us during Unit Tests :/ // BlockData is not available to us during Unit Tests :/
return false; return false;
} }
for (Material type : materials) { for (Material type : materials) {
/* /*
This BlockData is purely virtual and only created on startup, it should have 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 no impact on performance, in fact it should save performance as it preloads
the data but also saves heavy calls for other Materials the data but also saves heavy calls for other Materials
*/ */
if (type.createBlockData() instanceof GlassPane) { if (type.createBlockData() instanceof GlassPane) {
return true; return true;
} }
} }
return false; return false;
} }
@Override @Override
public void tick(Block b, SlimefunItem item, Config data) { public void tick(Block b, SlimefunItem item, Config data) {
if (b.getType().isAir()) { if (b.getType().isAir()) {
/* /*
The block was broken, setting the Material now would result in a The block was broken, setting the Material now would result in a
duplication glitch duplication glitch
*/ */
return; return;
} }
if (glassPanes) { if (glassPanes) {
BlockData blockData = b.getBlockData(); BlockData blockData = b.getBlockData();
if (blockData instanceof GlassPane previousData) { if (blockData instanceof GlassPane previousData) {
BlockData block = material.createBlockData(bd -> { BlockData block = material.createBlockData(bd -> {
if (bd instanceof GlassPane nextData) { if (bd instanceof GlassPane nextData) {
nextData.setWaterlogged(previousData.isWaterlogged()); nextData.setWaterlogged(previousData.isWaterlogged());
for (BlockFace face : previousData.getAllowedFaces()) { for (BlockFace face : previousData.getAllowedFaces()) {
nextData.setFace(face, previousData.hasFace(face)); nextData.setFace(face, previousData.hasFace(face));
} }
} }
}); });
b.setBlockData(block, false); b.setBlockData(block, false);
return; return;
} }
} }
b.setType(material, false); b.setType(material, false);
} }
@Override @Override
public void uniqueTick() { public void uniqueTick() {
material = iterator.next(); material = iterator.next();
} }
@Override @Override
public boolean isSynchronized() { public boolean isSynchronized() {
return true; return true;
} }
} }