Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
CJCrafter authored Aug 26, 2024
2 parents 046e449 + 4b1626c commit 604e761
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ default boolean tryUseTotemOfUndying(@NotNull LivingEntity entity) {
}

/**
* Creates an {@link EntityExplodeEvent} with the given parameters. This is used because Spigot
* does not have a backwards compatible constructor for this event.
* Creates an {@link EntityExplodeEvent} with the given parameters. This is used because Spigot does
* not have a backwards compatible constructor for this event.
*
* @param entity The non-null entity that is causing the explosion.
* @param location The non-null location of the explosion.
Expand All @@ -203,8 +203,7 @@ default boolean tryUseTotemOfUndying(@NotNull LivingEntity entity) {
@NotNull Location location,
@NotNull List<Block> blocks,
float yield,
boolean breakBlocks
) {
boolean breakBlocks) {
return new EntityExplodeEvent(entity, location, blocks, yield);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,6 @@ public ItemStack serializeWithoutRecipe(@NotNull SerializeData data) throws Seri
itemMeta.setCustomModelData(data.of("Custom_Model_Data").assertExists().getInt());
}

boolean hideFlags = data.of("Hide_Flags").getBool(false);
if (hideFlags) {
itemMeta.addItemFlags(ItemFlag.values());
}

if (data.has("Max_Stack_Size")) {
if (!MinecraftVersions.TRAILS_AND_TAILS.get(5).isAtLeast()) {
throw data.exception("Max_Stack_Size", "Tried to use max stack size before MC 1.20.5!",
Expand Down Expand Up @@ -295,6 +290,15 @@ public ItemStack serializeWithoutRecipe(@NotNull SerializeData data) throws Seri
}
}

// Add flags after attributes due to a bug introduced in Spigot 1.20.5, see
// https://github.com/PaperMC/Paper/issues/10693
boolean hideFlags = data.of("Hide_Flags").getBool(false);
if (hideFlags) {
ItemMeta temp = itemStack.getItemMeta();
temp.addItemFlags(ItemFlag.values());
itemStack.setItemMeta(temp);
}

String owningPlayer = data.of("Skull_Owning_Player").assertType(String.class).get(null);
if (owningPlayer != null) {
try {
Expand All @@ -316,7 +320,7 @@ public ItemStack serializeWithoutRecipe(@NotNull SerializeData data) throws Seri
// https://textures.minecraft.net/texture/a0564817fcc8dd51bc1957c0b7ea142db687dd6f1caafd35bb4dcfee592421c"
// https://www.spigotmc.org/threads/create-a-skull-item-stack-with-a-custom-texture-base64.82416/
if (uuid != null && url != null) {
//XSkull.of(itemMeta).profile(XSkull.SkullInputType.UUID, id).apply();
// XSkull.of(itemMeta).profile(XSkull.SkullInputType.UUID, id).apply();
XSkull.of(skullMeta).profile(XSkull.SkullInputType.TEXTURE_URL, url).apply();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,26 @@ public Registry(@NotNull String registryName) {
* @throws IllegalArgumentException If a duplicate key is found.
*/
@Contract("_ -> this")
@NotNull public Registry<T> add(@NotNull T item) {
public @NotNull Registry<T> add(@NotNull T item) {
return add(item, false);
}

/**
* Adds the given serializer to this registry. Keys are not case-sensitive, so be careful to avoid
* duplicate keys.
*
* @param item The non-null item to add.
* @param ignoreDuplicates If true, the method will not throw an exception if a duplicate key is
* found.
* @return A non-null reference to this (builder-pattern).
* @throws IllegalArgumentException If a duplicate key is found.
*/
@Contract("_,_ -> this")
public @NotNull Registry<T> add(@NotNull T item, boolean ignoreDuplicates) {
String key = toKey(item.getKey());
T existing = registry.get(key);

if (existing != null) {
if (existing != null && !ignoreDuplicates) {
MechanicsCore.debug.warn("Overriding '" + existing + "' with '" + item + "' in " + registryName + " registry");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public enum AttributeType {
PLAYER_SUBMERGED_MINING_SPEED(new UUID(2872L, 894628L), "player.submerged_mining_speed"),
PLAYER_SWEEPING_DAMAGE_RATIO(new UUID(2872L, 894627L), "player.sweeping_damage_ratio");


private final UUID uuid;
private final String minecraftName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ object MinecraftVersions {
val TRICKY_TRIALS =
Update(1, 21) {
add(Version(it, 0, 1)) // 1.21
add(Version(it, 1, 1)) // 1.21.1
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void damage(EntityDamageByEntityEvent e) {
return;

// MythicMobs damage skill support. Holding a gun while dealing damage normally triggers this
if (victim.hasMetadata("doing-skill-damage"))
if (victim.hasMetadata("skill-damage"))
return;

EntityDamageEvent.DamageCause cause = e.getCause();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ public void dropItem(PlayerDropItemEvent e) {
if (mainWeapon == null && offWeapon == null)
return;

// If players are dead, don't do anything... This cancel can sometimes let players keep their weapons
// If players are dead, don't do anything... This cancel can sometimes let players keep their
// weapons
if (!player.isDead()) {
boolean cancelMainHand = mainWeapon != null && getConfigurations().getBool(mainWeapon + ".Info.Cancel.Drop_Item");
boolean cancelOffHand = offWeapon != null && getConfigurations().getBool(offWeapon + ".Info.Cancel.Drop_Item");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,7 @@ public void explode(LivingEntity cause, Location origin, WeaponProjectile projec
// explicitly depending on WeaponMechanics.
if (blockDamage != null && !blocks.isEmpty() && !getBasicConfigurations().getBool("Disable_Entity_Explode_Event")) {
EntityExplodeEvent entityExplodeEvent = CompatibilityAPI.getEntityCompatibility().createEntityExplodeEvent(
projectile.getShooter(), origin, blocks, 5, !blocks.isEmpty()
);
projectile.getShooter(), origin, blocks, 5, !blocks.isEmpty());
Bukkit.getPluginManager().callEvent(entityExplodeEvent);
if (entityExplodeEvent.isCancelled())
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package me.deecaad.weaponmechanics.weapon.info;

import me.deecaad.core.file.Configuration;
import me.deecaad.core.file.SerializeData;
import me.deecaad.core.file.SerializerException;
import me.deecaad.core.file.serializers.ItemSerializer;
import me.deecaad.core.utils.StringUtil;
import me.deecaad.weaponmechanics.WeaponMechanics;
import me.deecaad.weaponmechanics.utils.CustomTag;
import me.deecaad.weaponmechanics.weapon.shoot.SelectiveFireState;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;

/**
Expand Down Expand Up @@ -43,6 +46,15 @@ public String getKeyword() {

String weaponTitle = data.key.split("\\.")[0];

// Saving display name and lore for use in WeaponMechanicsPlus to auto update items
Configuration config = WeaponMechanics.getConfigurations();
config.set(weaponTitle + ".Info.Weapon_Item.Name", "<!italic>" + data.of("Name").assertExists().getAdventure());
List<String> unparsedLore = ((List<String>) data.of("Lore").assertExists().get())
.stream()
.map(line -> "<!italic>" + StringUtil.colorAdventure(line))
.toList();
config.set(weaponTitle + ".Info.Weapon_Item.Lore", unparsedLore);

// Ensure the weapon title uses the correct format, mostly for other plugin compatibility
Pattern pattern = Pattern.compile("[A-Za-z0-9_]+");
if (!pattern.matcher(weaponTitle).matches()) {
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Versions of the 2 plugins stored in this repo.
mechanicsCoreVersion=3.4.8
weaponMechanicsVersion=3.4.9
mechanicsCoreVersion=3.4.9
weaponMechanicsVersion=3.4.10

# Version of the resource pack
resourcePackVersion=2.1.2
Expand Down

0 comments on commit 604e761

Please sign in to comment.