Skip to content

Commit

Permalink
Merge branch 'dev/feature' into dev/Recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAbsolutionism authored Nov 6, 2024
2 parents 06d8346 + 0335ff7 commit 4b8ba57
Show file tree
Hide file tree
Showing 14 changed files with 204 additions and 266 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies {
shadow group: 'org.bstats', name: 'bstats-bukkit', version: '3.0.2'
shadow group: 'net.kyori', name: 'adventure-text-serializer-bungeecord', version: '4.3.2'

implementation group: 'io.papermc.paper', name: 'paper-api', version: '1.21-R0.1-SNAPSHOT'
implementation group: 'io.papermc.paper', name: 'paper-api', version: '1.21.3-R0.1-SNAPSHOT'
implementation group: 'com.google.code.findbugs', name: 'findbugs', version: '3.0.1'

// bundled with Minecraft 1.19.4+ for display entity transforms
Expand Down Expand Up @@ -244,7 +244,7 @@ void createTestTask(String name, String desc, String environments, int javaVersi
def java21 = 21
def java17 = 17

def latestEnv = 'java21/paper-1.21.0.json'
def latestEnv = 'java21/paper-1.21.3.json'
def latestJava = java21
def oldestJava = java17

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ org.gradle.parallel=true

groupid=ch.njol
name=skript
version=2.9.3
version=2.9.4
jarName=Skript.jar
testEnv=java21/paper-1.21.0
testEnv=java21/paper-1.21.3
testEnvJavaVersion=21
31 changes: 11 additions & 20 deletions src/main/java/ch/njol/skript/bukkitutil/HealthUtils.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
/**
* This file is part of Skript.
*
* Skript is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Skript is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Skript. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright Peter Güttinger, SkriptLang team and contributors
*/
package ch.njol.skript.bukkitutil;

import ch.njol.skript.Skript;
Expand All @@ -36,6 +18,15 @@

public class HealthUtils {

private static final Attribute MAX_HEALTH;
static {
if (Skript.isRunningMinecraft(1, 21, 3)) { // In 1.21.3, Attribute became an Interface
MAX_HEALTH = Attribute.valueOf("MAX_HEALTH");
} else {
MAX_HEALTH = (Attribute) Enum.valueOf((Class) Attribute.class, "GENERIC_MAX_HEALTH");
}
}

/**
* Get the health of an entity
* @param e Entity to get health from
Expand All @@ -62,7 +53,7 @@ public static void setHealth(Damageable e, double health) {
* @return How many hearts the entity can have at most
*/
public static double getMaxHealth(Damageable e) {
AttributeInstance attributeInstance = ((Attributable) e).getAttribute(Attribute.GENERIC_MAX_HEALTH);
AttributeInstance attributeInstance = ((Attributable) e).getAttribute(MAX_HEALTH);
assert attributeInstance != null;
return attributeInstance.getValue() / 2;
}
Expand All @@ -73,7 +64,7 @@ public static double getMaxHealth(Damageable e) {
* @param health How many hearts the entity can have at most
*/
public static void setMaxHealth(Damageable e, double health) {
AttributeInstance attributeInstance = ((Attributable) e).getAttribute(Attribute.GENERIC_MAX_HEALTH);
AttributeInstance attributeInstance = ((Attributable) e).getAttribute(MAX_HEALTH);
assert attributeInstance != null;
attributeInstance.setBaseValue(health * 2);
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,8 @@ public String toVariableNameString(final ItemStack i) {
if (BukkitUtils.registryExists("BIOME")) {
biomeClassInfo = new RegistryClassInfo<>(Biome.class, Registry.BIOME, "biome", "biomes");
} else {
biomeClassInfo = new EnumClassInfo<>(Biome.class, "biome", "biomes");
//noinspection rawtypes,unchecked
biomeClassInfo = new EnumClassInfo<>((Class) Biome.class, "biome", "biomes");
}
Classes.registerClass(biomeClassInfo
.user("biomes?")
Expand Down Expand Up @@ -1481,7 +1482,8 @@ public String toVariableNameString(EnchantmentOffer eo) {
if (BukkitUtils.registryExists("ATTRIBUTE")) {
attributeClassInfo = new RegistryClassInfo<>(Attribute.class, Registry.ATTRIBUTE, "attributetype", "attribute types");
} else {
attributeClassInfo = new EnumClassInfo<>(Attribute.class, "attributetype", "attribute types");
//noinspection rawtypes,unchecked
attributeClassInfo = new EnumClassInfo<>((Class) Attribute.class, "attributetype", "attribute types");
}
Classes.registerClass(attributeClassInfo
.user("attribute ?types?")
Expand Down
75 changes: 30 additions & 45 deletions src/main/java/ch/njol/skript/effects/EffEquip.java
Original file line number Diff line number Diff line change
@@ -1,42 +1,7 @@
/**
* This file is part of Skript.
*
* Skript is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Skript is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Skript. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright Peter Güttinger, SkriptLang team and contributors
*/
package ch.njol.skript.effects;

import ch.njol.skript.aliases.ItemData;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.entity.AbstractHorse;
import org.bukkit.entity.ChestedHorse;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Llama;
import org.bukkit.entity.Pig;
import org.bukkit.entity.Player;
import org.bukkit.entity.Steerable;
import org.bukkit.event.Event;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.LlamaInventory;
import org.jetbrains.annotations.Nullable;

import ch.njol.skript.Skript;
import ch.njol.skript.aliases.Aliases;
import ch.njol.skript.aliases.ItemData;
import ch.njol.skript.aliases.ItemType;
import ch.njol.skript.bukkitutil.PlayerUtils;
import ch.njol.skript.doc.Description;
Expand All @@ -47,26 +12,47 @@
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.entity.*;
import org.bukkit.event.Event;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.LlamaInventory;
import org.jetbrains.annotations.Nullable;

@Name("Equip")
@Description("Equips or unequips an entity with some given armor. This will replace any armor that the entity is wearing.")
@Description(
"Equips or unequips an entity with some given armor. " +
"This will replace any armor that the entity is wearing."
)
@Examples({
"equip player with diamond helmet",
"equip player with all diamond armor",
"unequip diamond chestplate from player",
"unequip all armor from player",
"unequip player's armor"
"equip player with diamond helmet",
"equip player with all diamond armor",
"unequip diamond chestplate from player",
"unequip all armor from player",
"unequip player's armor"
})
@Since("1.0, 2.7 (multiple entities, unequip)")
public class EffEquip extends Effect {

private static final ItemType HORSE_ARMOR;

static {
if (Skript.isRunningMinecraft(1, 14)) {
HORSE_ARMOR = new ItemType(Material.IRON_HORSE_ARMOR, Material.GOLDEN_HORSE_ARMOR,
Material.DIAMOND_HORSE_ARMOR, Material.LEATHER_HORSE_ARMOR);
} else {
HORSE_ARMOR = new ItemType(Material.IRON_HORSE_ARMOR, Material.GOLDEN_HORSE_ARMOR,
Material.DIAMOND_HORSE_ARMOR);
}

Skript.registerEffect(EffEquip.class,
"equip [%livingentities%] with %itemtypes%",
"make %livingentities% wear %itemtypes%",
"unequip %itemtypes% [from %livingentities%]",
"unequip %livingentities%'[s] (armor|equipment)"
);
"unequip %livingentities%'[s] (armo[u]r|equipment)");
}

@SuppressWarnings("NotNullFieldNotInitialized")
Expand Down Expand Up @@ -99,7 +85,6 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
private static ItemType LEGGINGS;
private static ItemType BOOTS;
private static ItemType CARPET;
private static final ItemType HORSE_ARMOR = new ItemType(Material.IRON_HORSE_ARMOR, Material.GOLDEN_HORSE_ARMOR, Material.DIAMOND_HORSE_ARMOR);
private static final ItemType SADDLE = new ItemType(Material.SADDLE);
private static final ItemType CHEST = new ItemType(Material.CHEST);

Expand Down
21 changes: 20 additions & 1 deletion src/main/java/ch/njol/skript/entity/BoatChestData.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@
import org.bukkit.Material;
import org.bukkit.entity.Boat;
import org.bukkit.entity.ChestBoat;
import org.bukkit.entity.boat.*;
import org.jetbrains.annotations.Nullable;

import java.util.EnumMap;
import java.util.Locale;
import java.util.Random;

public class BoatChestData extends EntityData<ChestBoat> {

private static final boolean IS_RUNNING_1_21_3 = Skript.isRunningMinecraft(1, 21, 3);
private static final EnumMap<Boat.Type, Class<? extends ChestBoat>> typeToClassMap = new EnumMap<>(Boat.Type.class);

private static final Boat.Type[] types = Boat.Type.values();

static {
Expand All @@ -31,6 +36,18 @@ public class BoatChestData extends EntityData<ChestBoat> {
patterns[boat.ordinal() + 2] = boatName;
}

if (IS_RUNNING_1_21_3) {
typeToClassMap.put(Boat.Type.OAK, OakChestBoat.class);
typeToClassMap.put(Boat.Type.SPRUCE, SpruceChestBoat.class);
typeToClassMap.put(Boat.Type.BIRCH, BirchChestBoat.class);
typeToClassMap.put(Boat.Type.JUNGLE, JungleChestBoat.class);
typeToClassMap.put(Boat.Type.ACACIA, AcaciaChestBoat.class);
typeToClassMap.put(Boat.Type.DARK_OAK, DarkOakChestBoat.class);
typeToClassMap.put(Boat.Type.MANGROVE, MangroveChestBoat.class);
typeToClassMap.put(Boat.Type.CHERRY, CherryChestBoat.class);
typeToClassMap.put(Boat.Type.BAMBOO, BambooChestRaft.class);
}

if (Skript.classExists("org.bukkit.entity.ChestBoat")) {
EntityData.register(BoatChestData.class, "chest boat", ChestBoat.class, 0, patterns);
}
Expand Down Expand Up @@ -65,7 +82,7 @@ public void set(ChestBoat entity) {
if (matchedPattern == 1) // If the type is 'any boat'.
matchedPattern += new Random().nextInt(Boat.Type.values().length); // It will spawn a random boat type in case is 'any boat'.
if (matchedPattern > 1) // 0 and 1 are excluded
entity.setBoatType(Boat.Type.values()[matchedPattern - 2]); // Removes 2 to fix the index.
entity.setBoatType(types[matchedPattern - 2]); // Removes 2 to fix the index.
}

@Override
Expand All @@ -75,6 +92,8 @@ protected boolean match(ChestBoat entity) {

@Override
public Class<? extends ChestBoat> getType() {
if (IS_RUNNING_1_21_3)
return typeToClassMap.get(types[matchedPattern - 2]);
return ChestBoat.class;
}

Expand Down
30 changes: 26 additions & 4 deletions src/main/java/ch/njol/skript/entity/BoatData.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package ch.njol.skript.entity;

import java.util.EnumMap;
import java.util.Locale;
import java.util.Random;

import ch.njol.skript.Skript;
import org.bukkit.Material;
import org.bukkit.entity.Boat;
import org.bukkit.entity.boat.*;
import ch.njol.skript.aliases.ItemType;
import ch.njol.skript.lang.Literal;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import org.jetbrains.annotations.Nullable;

public class BoatData extends EntityData<Boat> {

private static final boolean IS_RUNNING_1_21_3 = Skript.isRunningMinecraft(1, 21, 3);
private static final EnumMap<Boat.Type, Class<? extends Boat>> typeToClassMap = new EnumMap<>(Boat.Type.class);

private static final Boat.Type[] types = Boat.Type.values();

static {
Expand All @@ -28,8 +34,23 @@ public class BoatData extends EntityData<Boat> {
boatName = boat.toString().replace("_", " ").toLowerCase(Locale.ENGLISH) + " boat";
patterns[boat.ordinal() + 2] = boatName;
}

if (IS_RUNNING_1_21_3) {
typeToClassMap.put(Boat.Type.OAK, OakBoat.class);
typeToClassMap.put(Boat.Type.SPRUCE, SpruceBoat.class);
typeToClassMap.put(Boat.Type.BIRCH, BirchBoat.class);
typeToClassMap.put(Boat.Type.JUNGLE, JungleBoat.class);
typeToClassMap.put(Boat.Type.ACACIA, AcaciaBoat.class);
typeToClassMap.put(Boat.Type.DARK_OAK, DarkOakBoat.class);
typeToClassMap.put(Boat.Type.MANGROVE, MangroveBoat.class);
typeToClassMap.put(Boat.Type.CHERRY, CherryBoat.class);
typeToClassMap.put(Boat.Type.BAMBOO, BambooRaft.class);
}

EntityData.register(BoatData.class, "boat", Boat.class, 0, patterns);
}



public BoatData(){
this(0);
Expand All @@ -39,20 +60,18 @@ public BoatData(@Nullable Boat.Type type){
this(type != null ? type.ordinal() + 2 : 1);
}

private BoatData(int type){
private BoatData(int type) {
matchedPattern = type;
}

@Override
protected boolean init(Literal<?>[] exprs, int matchedPattern, ParseResult parseResult) {

return true;
}

@Override
protected boolean init(@Nullable Class<? extends Boat> clazz, @Nullable Boat entity) {
if (entity != null)

matchedPattern = 2 + entity.getBoatType().ordinal();
return true;
}
Expand All @@ -62,7 +81,7 @@ public void set(Boat entity) {
if (matchedPattern == 1) // If the type is 'any boat'.
matchedPattern += new Random().nextInt(Boat.Type.values().length); // It will spawn a random boat type in case is 'any boat'.
if (matchedPattern > 1) // 0 and 1 are excluded
entity.setBoatType(Boat.Type.values()[matchedPattern - 2]); // Removes 2 to fix the index.
entity.setBoatType(types[matchedPattern - 2]); // Removes 2 to fix the index.
}

@Override
Expand All @@ -72,6 +91,8 @@ protected boolean match(Boat entity) {

@Override
public Class<? extends Boat> getType() {
if (IS_RUNNING_1_21_3)
return typeToClassMap.get(types[matchedPattern - 2]);
return Boat.class;
}

Expand Down Expand Up @@ -115,4 +136,5 @@ public boolean isOfItemType(ItemType itemType){
}
return hashCode_i() == ordinal + 2 || (matchedPattern + ordinal == 0) || ordinal == 0;
}

}
Loading

0 comments on commit 4b8ba57

Please sign in to comment.