Skip to content

Commit

Permalink
Merge pull request #700 from ShaneBeee/dev/patch
Browse files Browse the repository at this point in the history
Dev/Patch - future update
  • Loading branch information
ShaneBeee authored Aug 18, 2024
2 parents a89697a + 6909d48 commit 91790dd
Show file tree
Hide file tree
Showing 15 changed files with 417 additions and 34 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ repositories {

dependencies {
// Paper
compileOnly("io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT")
compileOnly("io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT")

// Skript
compileOnly(group: 'com.github.SkriptLang', name: 'Skript', version: '2.8.7') {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/shanebeestudios/skbee/AddonLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ private void loadTextElements() {
Util.logLoading("&5Text Component Elements &cdisabled via config");
return;
}
if (!Skript.classExists("net.kyori.adventure.text.Component")) {
if (!Skript.classExists("io.papermc.paper.event.player.AsyncChatEvent")) {
Util.logLoading("&5Text Component Elements &cdisabled");
Util.logLoading("&7- Text components require a PaperMC server.");
return;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/shanebeestudios/skbee/api/bound/Bound.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public Bound copy(Bound bound, String id) {
Location greaterCorner = bound.getGreaterCorner().clone();
Bound newBound = new Bound(lesserCorner, greaterCorner, id, bound.isTemporary());
newBound.setOwners(bound.getOwners());
newBound.setMembers(bound.getOwners());
newBound.setMembers(bound.getMembers());
newBound.setBoundingBox(bound.getBoundingBox().clone());
newBound.values = bound.values;
return newBound;
Expand Down Expand Up @@ -377,7 +377,7 @@ public List<UUID> getOwners() {
* @param owners Owners to set
*/
public void setOwners(List<UUID> owners) {
this.owners = owners;
this.owners = new ArrayList<>(owners);
}

/**
Expand Down Expand Up @@ -422,7 +422,7 @@ public List<UUID> getMembers() {
* @param members Members to set
*/
public void setMembers(List<UUID> members) {
this.members = members;
this.members = new ArrayList<>(members);
}

/**
Expand Down
17 changes: 15 additions & 2 deletions src/main/java/com/shanebeestudios/skbee/api/nbt/NBTApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,11 @@ public static void removeFromTag(@NotNull String tag, @NotNull NBTCompound compo
byteArray = ArrayUtils.remove(byteArray, index);
}
}
compound.setByteArray(tag, byteArray);
if (byteArray.length > 0) {
compound.setByteArray(tag, byteArray);
} else {
compound.removeKey(tag);
}
}
}
case NBTTagIntArray -> {
Expand All @@ -631,7 +635,11 @@ public static void removeFromTag(@NotNull String tag, @NotNull NBTCompound compo
intArray = ArrayUtils.remove(intArray, index);
}
}
compound.setIntArray(tag, intArray);
if (intArray.length > 0) {
compound.setIntArray(tag, intArray);
} else {
compound.removeKey(tag);
}
}
}
case NBTTagIntList -> {
Expand All @@ -640,6 +648,7 @@ public static void removeFromTag(@NotNull String tag, @NotNull NBTCompound compo
for (Object o : object)
if (o instanceof Number number)
intList.remove((Object) number.intValue());
if (intList.isEmpty()) compound.removeKey(tag);
}
}
case NBTTagLongList -> {
Expand All @@ -648,6 +657,7 @@ public static void removeFromTag(@NotNull String tag, @NotNull NBTCompound compo
for (Object o : object)
if (o instanceof Number number)
longList.remove(number.longValue());
if (longList.isEmpty()) compound.removeKey(tag);
}
}
case NBTTagFloatList -> {
Expand All @@ -656,6 +666,7 @@ public static void removeFromTag(@NotNull String tag, @NotNull NBTCompound compo
for (Object o : object)
if (o instanceof Number number)
floatList.remove(number.floatValue());
if (floatList.isEmpty()) compound.removeKey(tag);
}
}
case NBTTagDoubleList -> {
Expand All @@ -664,6 +675,7 @@ public static void removeFromTag(@NotNull String tag, @NotNull NBTCompound compo
for (Object o : object)
if (o instanceof Number number)
doubleList.remove(number.doubleValue());
if (doubleList.isEmpty()) compound.removeKey(tag);
}
}
case NBTTagStringList -> {
Expand All @@ -672,6 +684,7 @@ public static void removeFromTag(@NotNull String tag, @NotNull NBTCompound compo
for (Object o : object)
if (o instanceof String string)
stringList.remove(string);
if (stringList.isEmpty()) compound.removeKey(tag);
}
}
case NBTTagCompoundList -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ public class NBTCustomItemStack extends NBTContainer {

private final ItemStack originalItemStack;
private final boolean isCustomData;
private final boolean isFull;

public NBTCustomItemStack(ItemStack itemStack, boolean isCustomData, boolean isVanilla, boolean isFull) {
super(getInitialContainer(itemStack, isCustomData, isVanilla, isFull).toString());
this.originalItemStack = itemStack;
this.isCustomData = isCustomData;
this.isFull = isFull;
}

private static NBTCompound getInitialContainer(ItemStack itemStack, boolean isCustomData, boolean isVanilla, boolean isFull) {
Expand All @@ -46,6 +48,7 @@ private static NBTCompound getContainer(NBTCompound itemContainer, boolean isCus
@Override
protected void saveCompound() {
super.saveCompound();
if (this.isFull) return;
NBTContainer originalItemContainer = NBTItem.convertItemtoNBT(this.originalItemStack.clone());
NBTCompound components = getContainer(originalItemContainer, this.isCustomData, false);
components.clearNBT();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ch.njol.skript.util.ColorRGB;
import ch.njol.skript.util.SkriptColor;
import ch.njol.skript.util.slot.Slot;
import com.shanebeestudios.skbee.SkBee;
import com.shanebeestudios.skbee.api.util.ChatUtil;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.identity.Identity;
Expand Down Expand Up @@ -47,15 +48,17 @@
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.PatternSyntaxException;

/**
* Wrapper for {@link Component Adventure API Components}
*/
@SuppressWarnings({"PatternValidation"})
@SuppressWarnings({"PatternValidation", "CallToPrintStackTrace"})
public class ComponentWrapper {

// STATIC
private static final boolean HAS_SIDES = Skript.classExists("org.bukkit.block.sign.SignSide");
private static final boolean DEBUG = SkBee.getPlugin().getPluginConfig().SETTINGS_DEBUG;
/**
* Check if ItemMeta supports 'itemName' ('item_name' component
*/
Expand Down Expand Up @@ -424,18 +427,26 @@ public String getInsertion() {
*/
@SuppressWarnings("LanguageMismatch")
public void replace(String text, ComponentWrapper replacement) {
this.component = this.component.replaceText(c -> c.match(text).replacement(replacement.component));
try {
this.component = this.component.replaceText(c -> c.match(text).replacement(replacement.component));
} catch (PatternSyntaxException ex) {
if (DEBUG) ex.printStackTrace();
}
}

/**
* Rpelace a string with a string
* Replace a string with a string
*
* @param text String to replace
* @param replacement To replace with
*/
@SuppressWarnings("LanguageMismatch")
public void replace(String text, String replacement) {
this.component = this.component.replaceText(c -> c.match(text).replacement(replacement));
try {
this.component = this.component.replaceText(c -> c.match(text).replacement(replacement));
} catch (PatternSyntaxException ex) {
if (DEBUG) ex.printStackTrace();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.shanebeestudios.skbee.elements.other.effects;

import ch.njol.skript.Skript;
import ch.njol.skript.aliases.ItemType;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import org.bukkit.block.Block;
import org.bukkit.event.Event;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

@Name("Break Blocks with Effects")
@Description({"Breaks blocks as if a player had broken them. Will drop items, play particles and sounds. Requires PaperMC.",
"Optionally you can trigger it to drop experience as well.",
"Optionally you can include an item which is used to determine which drops the block will drop."})
@Examples({"break blocks in radius 2 around target block with effects",
"break {_blocks::*} with effects and with xp",
"break {_blocks::*} with effects and with xp using player's tool"})
@Since("INSERT VERSION")
public class EffBreakBlocksWithEffects extends Effect {

private static final boolean HAS_EFFECTS = Skript.methodExists(Block.class, "breakNaturally", boolean.class, boolean.class);

static {
Skript.registerEffect(EffBreakBlocksWithEffects.class,
"break %blocks% [naturally] with effects [exp:[and] with (experience|exp|xp)] [using %-itemtype%]");
}

private boolean exp;
private Expression<Block> blocks;
private Expression<ItemType> itemType;

@SuppressWarnings({"NullableProblems", "unchecked"})
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
if (!HAS_EFFECTS) {
Skript.error("'break %blocks% with effects' requires PaperMC. Use Skript's 'break %blocks%' effect instead.");
return false;
}
this.exp = parseResult.hasTag("exp");
this.blocks = (Expression<Block>) exprs[0];
this.itemType = (Expression<ItemType>) exprs[1];
return true;
}

@SuppressWarnings("NullableProblems")
@Override
protected void execute(Event event) {
ItemStack itemStack = null;
if (this.itemType != null) {
ItemType it = this.itemType.getSingle(event);
if (it != null) itemStack = it.getRandom();
}

for (Block block : this.blocks.getArray(event)) {
if (itemStack != null) block.breakNaturally(itemStack, true, this.exp);
else block.breakNaturally(true, this.exp);
}
}

@Override
public @NotNull String toString(Event e, boolean d) {
String blocks = this.blocks.toString(e, d);
String xp = this.exp ? " and with experience" : "";
String it = this.itemType != null ? (" using " + this.itemType.toString(e, d)) : "";
return "break " + blocks + " naturally with effects" + xp + it;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.shanebeestudios.skbee.elements.other.expressions;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

@Name("Chunks Within Locations")
@Description("Get a list of all chunks within 2 locations.")
@Examples({"loop all chunks within {_l1} and {_l2}:",
"refresh all chunks within {_l1} and {_l2}"})
@Since("INSERT VERSION")
public class ExprChunksWithinCuboid extends SimpleExpression<Chunk> {

static {
Skript.registerExpression(ExprChunksWithinCuboid.class, Chunk.class, ExpressionType.COMBINED,
"all chunks within %location% and %location%");
}

private Expression<Location> loc1, loc2;

@SuppressWarnings({"NullableProblems", "unchecked"})
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
this.loc1 = (Expression<Location>) exprs[0];
this.loc2 = (Expression<Location>) exprs[1];
return true;
}

@SuppressWarnings("NullableProblems")
@Override
protected Chunk @Nullable [] get(Event event) {
Location loc1 = this.loc1.getSingle(event);
Location loc2 = this.loc2.getSingle(event);
if (loc1 == null || loc2 == null) return null;

World world = loc1.getWorld();
if (world != loc2.getWorld()) return null;

List<Chunk> chunks = new ArrayList<>();
int minX = Math.min(loc1.getBlockX(), loc2.getBlockX()) >> 4;
int minZ = Math.min(loc1.getBlockZ(), loc2.getBlockZ()) >> 4;
int maxX = (Math.max(loc1.getBlockX(), loc2.getBlockX()) + 1) >> 4;
int maxZ = (Math.max(loc1.getBlockZ(), loc2.getBlockZ()) + 1) >> 4;
for (int x = minX; x <= maxX; x++) {
for (int z = minZ; z <= maxZ; z++) {
chunks.add(world.getChunkAt(x, z, false));
}
}

Iterator<Entity> e;

return chunks.toArray(new Chunk[0]);
}

@Override
public boolean isSingle() {
return false;
}

@Override
public @NotNull Class<? extends Chunk> getReturnType() {
return Chunk.class;
}

@Override
public @NotNull String toString(Event e, boolean d) {
return "all chunks within " + this.loc1.toString(e, d) + " and " + this.loc2.toString(e, d);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
import java.util.ArrayList;
import java.util.List;

@Name("LootTable - Lootables")
@Name("LootTable - LootTable of Lootable")
@Description({"Get/set/delete the LootTable of a lootable object such as a block or entity.",
"`with seed` = Provide an optional seed for loot generation otherwise will randomly generate."})
"`with seed` = Provide an optional seed for loot generation otherwise will randomly generate."})
@Examples({"set {_lootTable} to loottable of target block",
"set loottable of target block to loottable from key \"minecraft:chests/ancient_city\""})
"set loottable of target block to loottable from key \"minecraft:chests/ancient_city\""})
@Since("3.4.0")
public class ExprLootTableObject extends SimpleExpression<LootTable> {

static {
Skript.registerExpression(ExprLootTableObject.class, LootTable.class, ExpressionType.COMBINED,
"loot[ ]table of %blocks/entities% [with seed %-number%]");
"loot[ ]table of %blocks/entities% [with seed %-number%]");
}

private Expression<?> objects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
itemType.setItemMeta(itemMeta);
} else if (object instanceof LivingEntity entity) {
AttributeInstance attributeInstance = entity.getAttribute(attribute);
if (attributeInstance == null) continue;
if (!EntityUtils.hasAttributeModifier(entity, attribute, attributeModifier)) {
if (this.trans) {
attributeInstance.addTransientModifier(attributeModifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public boolean canParse(@NotNull ParseContext context) {

@Override
public @NotNull String toString(LootTable lootTable, int flags) {
return "LootTable{" + lootTable.getKey() + "}";
return lootTable.getKey().toString();
}

@Override
Expand Down
Loading

0 comments on commit 91790dd

Please sign in to comment.