mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-18 18:55:48 +00:00
Enforce LF endings automatically (#3946)
This commit is contained in:
parent
68edac523e
commit
67af02ce82
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
# Automatically normalize line endings (to LF) for all text-based files.
|
||||
* text=auto eol=lf
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
}
|
||||
|
@ -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<Material> iterator;
|
||||
private final boolean glassPanes;
|
||||
private Material material;
|
||||
|
||||
public RainbowTickHandler(@Nonnull List<Material> 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<Material> 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<Material> iterator;
|
||||
private final boolean glassPanes;
|
||||
private Material material;
|
||||
|
||||
public RainbowTickHandler(@Nonnull List<Material> 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<Material> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user