Skip to content

Commit

Permalink
Merge branch '1.21.1-wither' into 1.21.3
Browse files Browse the repository at this point in the history
  • Loading branch information
MATRIX-feather committed Nov 13, 2024
2 parents 2ddbf14 + 5b67a82 commit 8e97587
Show file tree
Hide file tree
Showing 28 changed files with 328 additions and 163 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project_version=1.4.0.alpha2
project_version=1.4.0.alpha3

# FM Protocols
protocols_version=b15c1841
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import xyz.nifeather.morph.MorphManager;
import xyz.nifeather.morph.MorphPluginObject;
import xyz.nifeather.morph.abilities.impl.*;
import xyz.nifeather.morph.abilities.impl.dmgReduce.ReduceFallDamageAbility;
import xyz.nifeather.morph.abilities.impl.dmgReduce.ReduceMagicDamageAbility;
import xyz.nifeather.morph.abilities.impl.dmgReduce.ReduceWitherDamageAbility;
import xyz.nifeather.morph.abilities.impl.potion.*;
import xyz.nifeather.morph.abilities.impl.onAttack.ExtraKnockbackAbility;
import xyz.nifeather.morph.abilities.impl.onAttack.PotionOnAttackAbility;
Expand Down Expand Up @@ -96,6 +99,7 @@ private void load()
new NoFallDamageAbility(),
new ReduceFallDamageAbility(),
new ReduceMagicDamageAbility(),
new ReduceWitherDamageAbility(),
new SmallJumpBoostAbility(),
new SnowyAbility(),
new SpeedBoostAbility(),
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/xyz/nifeather/morph/abilities/AbilityType.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public class AbilityType

public static final NamespacedKey HAS_FEATHER_FALLING = new NamespacedKey(nameSpace, "feather_falling");
public static final NamespacedKey NO_FALL_DAMAGE = new NamespacedKey(nameSpace, "no_fall_damage");
public static final NamespacedKey REDUCES_FALL_DAMAGE = new NamespacedKey(nameSpace, "reduce_fall_damage");
public static final NamespacedKey REDUCES_MAGIC_DAMAGE = new NamespacedKey(nameSpace, "reduce_magic_damage");
public static final NamespacedKey SNOWY = new NamespacedKey(nameSpace, "snowy");
public static final NamespacedKey WARDEN_LESS_AWARE = new NamespacedKey(nameSpace, "warden_less_aware");
public static final NamespacedKey WARDEN = new NamespacedKey(nameSpace, "warden");
Expand All @@ -34,4 +32,8 @@ public class AbilityType
public static final NamespacedKey DRYOUT_IN_AIR = new NamespacedKey(nameSpace, "dryout_in_air");
public static final NamespacedKey POTION_ON_ATTACK = new NamespacedKey(nameSpace, "potion_on_attack");
public static final NamespacedKey SPIDER = new NamespacedKey(nameSpace, "spider");

public static final NamespacedKey REDUCES_FALL_DAMAGE = new NamespacedKey(nameSpace, "reduce_fall_damage");
public static final NamespacedKey REDUCES_MAGIC_DAMAGE = new NamespacedKey(nameSpace, "reduce_magic_damage");
public static final NamespacedKey REDUCES_WITHER_DAMAGE = new NamespacedKey(nameSpace, "reduce_wither_damage");
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ public boolean applyToPlayer(Player player, DisguiseState state)
var operationType = modifierOption.operationType.toBukkitOperation();
if (operationType == null)
{
logger.warn("");
return false;
logger.warn("Modifier operation not set for attribute %s of disguise %s, ignoring...".formatted(
modifierOption.attributeName, state.getDisguiseIdentifier()
));
continue;
}

var modifier = new AttributeModifier(modifierKey, modifierOption.value,
operationType, EquipmentSlotGroup.ANY);
var modifier = new AttributeModifier(modifierKey, modifierOption.value, operationType);

attributeInstance.removeModifier(modifierKey);
attributeInstance.addModifier(modifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@

public class BossbarAbility extends MorphAbility<BossbarOption>
{
private Bindable<Boolean> allowBossbar;
private final Bindable<Boolean> allowBossbar = new Bindable<>(false);

@Initializer
private void load(MorphConfigManager configManager)
{
allowBossbar = configManager.getBindable(Boolean.class, ConfigOption.DISPLAY_BOSSBAR);
configManager.bind(allowBossbar, ConfigOption.DISPLAY_BOSSBAR);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@ public void onPlayerTookDamage(EntityDamageEvent e)
: damage - dmgOption.getReduceAmount();

e.setDamage(Math.max(0d, damage));

if (damage <= 0d)
e.setCancelled(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ private Entity findEntity(NmsRecord record, EntityType<?> nmsType, double expand

var boundingBox = nmsType.getDimensions().makeBoundingBox(player.position());

Class<? extends Entity> classType = EntityTypeUtils.getNmsClass(bukkitType, record.nmsPlayer().getBukkitEntity().getWorld());
Class<? extends Entity> classType = EntityTypeUtils.getNmsClass(bukkitType,
record.nmsPlayer().getBukkitEntity().getWorld(),
record.nmsPlayer().getBukkitEntity().getLocation());

if (classType == null) return null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import xyz.nifeather.morph.abilities.MorphAbility;
import xyz.nifeather.morph.storage.skill.ISkillOption;

public abstract class OnAttackAbility<T extends ISkillOption> extends MorphAbility<T>
{
@EventHandler(ignoreCancelled = true)
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onEntityDamagedByEntity(EntityDamageByEntityEvent e)
{
if (!(e.getDamager() instanceof Player player)) return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package xyz.nifeather.morph.abilities.impl;
package xyz.nifeather.morph.abilities.impl.dmgReduce;

import org.bukkit.NamespacedKey;
import org.bukkit.event.entity.EntityDamageEvent;
import org.jetbrains.annotations.NotNull;
import xyz.nifeather.morph.abilities.AbilityType;
import xyz.nifeather.morph.abilities.impl.DamageReducingAbility;
import xyz.nifeather.morph.abilities.options.ReduceDamageOption;

public class ReduceFallDamageAbility extends DamageReducingAbility<ReduceDamageOption>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package xyz.nifeather.morph.abilities.impl;
package xyz.nifeather.morph.abilities.impl.dmgReduce;

import org.bukkit.NamespacedKey;
import org.bukkit.event.entity.EntityDamageEvent;
import org.jetbrains.annotations.NotNull;
import xyz.nifeather.morph.abilities.AbilityType;
import xyz.nifeather.morph.abilities.impl.DamageReducingAbility;
import xyz.nifeather.morph.abilities.options.ReduceDamageOption;

public class ReduceMagicDamageAbility extends DamageReducingAbility<ReduceDamageOption>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package xyz.nifeather.morph.abilities.impl.dmgReduce;

import org.bukkit.NamespacedKey;
import org.bukkit.event.entity.EntityDamageEvent;
import org.jetbrains.annotations.NotNull;
import xyz.nifeather.morph.abilities.AbilityType;
import xyz.nifeather.morph.abilities.impl.DamageReducingAbility;
import xyz.nifeather.morph.abilities.options.ReduceDamageOption;

public class ReduceWitherDamageAbility extends DamageReducingAbility<ReduceDamageOption>
{
@Override
protected EntityDamageEvent.DamageCause getTargetCause()
{
return EntityDamageEvent.DamageCause.WITHER;
}

@Override
protected @NotNull ReduceDamageOption createOption()
{
return new ReduceDamageOption();
}

@Override
public @NotNull NamespacedKey getIdentifier()
{
return AbilityType.REDUCES_WITHER_DAMAGE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,6 @@ public class ExtraKnockbackAbility extends OnAttackAbility<ExtraKnockbackOption>
return AbilityType.EXTRA_KNOCKBACK;
}

/*
@EventHandler
private void onGolemDmg(EntityDamageByEntityEvent e)
{
if (!(e.getDamager() instanceof CraftIronGolem craftIronGolem)) return;
if (!(e.getEntity() instanceof CraftPlayer craftPlayer)) return;
logger.info("VECTOR: %s".formatted(craftPlayer.getHandle().getDeltaMovement()));
this.addSchedule(() ->
{
logger.info("SCHED VECTOR: %s".formatted(craftPlayer.getHandle().getDeltaMovement()));
});
}
*/

@Resolved(shouldSolveImmediately = true)
private MorphManager manager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import xyz.nifeather.morph.misc.playerList.PlayerListHandler;
import xyz.nifeather.morph.network.server.MorphClientHandler;
import xyz.nifeather.morph.network.server.ServerSetEquipCommand;
import xyz.nifeather.morph.providers.disguise.VanillaDisguiseProvider;
import xyz.nifeather.morph.skills.MorphSkillHandler;
import xyz.nifeather.morph.utilities.CommonUtils;
import xyz.nifeather.morph.utilities.EntityTypeUtils;
Expand Down Expand Up @@ -414,6 +415,9 @@ public void onPlayerJoin(PlayerJoinEvent e)
if (instance == null) continue;

instance.removeModifier(AttributeModifyingAbility.modifierKey);
instance.removeModifier(VanillaDisguiseProvider.healthModifierKeyLegacy);
instance.removeModifier(VanillaDisguiseProvider.healthModifierKey);
instance.removeModifier(VanillaDisguiseProvider.healthModifierKeyVanilla);
}

this.addSchedule(() -> PlayerListHandler.instance().handle(player));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/xyz/nifeather/morph/misc/SoundHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void refreshSounds(EntityType entityType, boolean isBaby)

soundFrequency = MathUtils.clamp(0, 2, config.getBindable(Double.class, ConfigOption.AMBIENT_FREQUENCY).get());

var soundEvent = EntityTypeUtils.getAmbientSound(entityType, this.bindingPlayer.getWorld());
var soundEvent = EntityTypeUtils.getAmbientSound(entityType, this.bindingPlayer.getWorld(), this.bindingPlayer.getLocation());

var sound = soundEvent.sound();
if (sound == null) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,4 @@ public interface IPlaceholderProvider
*/
@Nullable
public String resolvePlaceholder(Player player, String params);

/**
* 获取ID的匹配模式
* @return {@link MatchMode}
*/
public MatchMode getMatchMode();
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import xiamomc.pluginbase.Managers.DependencyManager;
import xyz.nifeather.morph.misc.integrations.placeholderapi.builtin.AvaliableDisguisesProvider;
import xyz.nifeather.morph.misc.integrations.placeholderapi.builtin.StateNameProvider;
Expand All @@ -14,6 +16,7 @@
public class PlaceholderIntegration extends PlaceholderExpansion
{
private static final List<IPlaceholderProvider> providers = new ObjectArrayList<>();
private static final Logger log = LoggerFactory.getLogger(PlaceholderIntegration.class);

public PlaceholderIntegration(DependencyManager depManager)
{
Expand All @@ -26,7 +29,7 @@ public PlaceholderIntegration(DependencyManager depManager)
@Override
public @NotNull String getIdentifier()
{
return "morph";
return "feathermorph";
}

@Override
Expand All @@ -38,7 +41,7 @@ public PlaceholderIntegration(DependencyManager depManager)
@Override
public @NotNull String getVersion()
{
return "1.0.10";
return "1.4.0";
}

private void addPlaceholders(List<IPlaceholderProvider> providerList)
Expand All @@ -56,34 +59,36 @@ public boolean addPlaceholderProvider(IPlaceholderProvider provider)
if (providers.stream().anyMatch(p -> providerEquals(p, provider)))
return false;

providers.add(0, provider);
providers.addFirst(provider);
return true;
}

private boolean providerEquals(IPlaceholderProvider source, IPlaceholderProvider target)
{
if (source == null || target == null) return false;

return source.getMatchMode() == target.getMatchMode()
&& source.getPlaceholderIdentifier().equals(target.getPlaceholderIdentifier());
return source.getPlaceholderIdentifier().equals(target.getPlaceholderIdentifier());
}

private final String defaultString = "???";
private static final String defaultString = "???";

@Override
public @Nullable String onPlaceholderRequest(Player player, @NotNull String params)
public @Nullable String onPlaceholderRequest(Player player, @NotNull String param)
{
if (player == null) return defaultString;

param = param.replaceFirst(getIdentifier() + "_", "");
var paramSpilt = param.split("_", 2);

if (paramSpilt.length != 2)
return null;

var provider = providers.stream()
.filter(p -> p.getMatchMode() == MatchMode.Exact
? params.equalsIgnoreCase(p.getPlaceholderIdentifier())
: params.startsWith(p.getPlaceholderIdentifier()))
.filter(p -> p.getPlaceholderIdentifier().equalsIgnoreCase(paramSpilt[0]))
.findFirst().orElse(null);

if (provider == null) return defaultString;

var val = provider.resolvePlaceholder(player, params);
return val == null ? defaultString : val;
return provider.resolvePlaceholder(player, paramSpilt[1]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,47 @@
import xyz.nifeather.morph.interfaces.IManagePlayerData;
import xyz.nifeather.morph.messages.MessageUtils;
import xyz.nifeather.morph.misc.integrations.placeholderapi.IPlaceholderProvider;
import xyz.nifeather.morph.misc.integrations.placeholderapi.MatchMode;

public class AvaliableDisguisesProvider extends MorphPluginObject implements IPlaceholderProvider
{
@Override
public @NotNull String getPlaceholderIdentifier()
{
return "avaliable";
return "available";
}

@Resolved
private IManagePlayerData data;

@Override
public @Nullable String resolvePlaceholder(Player player, String params)
public @Nullable String resolvePlaceholder(Player player, String param)
{
var type = params.replace(getPlaceholderIdentifier(), "");
var builder = new StringBuilder();
var list = data.getAvaliableDisguisesFor(player);

var locale = MessageUtils.getServerLocale();

if (type.equalsIgnoreCase("_name"))
switch (param)
{
list.forEach(i ->
case "name" ->
{
builder.append(PlainTextComponentSerializer.plainText().serialize(i.asComponent(locale)));
list.forEach(i ->
{
builder.append(PlainTextComponentSerializer.plainText().serialize(i.asComponent(locale)));

if (list.iterator().hasNext())
builder.append(", ");
});
if (list.iterator().hasNext())
builder.append(", ");
});

return builder.toString();
}
else if (type.equalsIgnoreCase("_count"))
{
return String.valueOf(list.size());
return builder.toString();
}

case "count" ->
{
return String.valueOf(list.size());
}
}

return null;
}

@Override
public MatchMode getMatchMode()
{
return MatchMode.Prefixes;
}
}
Loading

0 comments on commit 8e97587

Please sign in to comment.