Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
Version 2.2.050
Further improved compatibility with Excellent Enchants
Minimum supported Minecraft version raised to 1.20.4 (see notes)
Improved Spears damage detection (see notes)
Spear abilities can now trigger from off-hand attacks with the Spear
Further improved compatibility with Excellent Enchants (fixed more errors)

NOTES:
From 2.2.050 onwards, mcMMO will require Minecraft versions 1.20.4 or newer.
Every now and then I raise the minimum supported Minecraft version to reduce maintenance burden of supporting older versions.
mcMMO no longer monitors PlayerAnimationEvent, it turns out Spigot has a DamageType just for Spear damage, avoiding the need to track player arm swings.

Version 2.2.049
Combat abilities work with spear in off-hand again (see notes)
Expand Down
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</scm>

<properties>
<!-- <spigot.version>1.19-R0.1-SNAPSHOT</spigot.version>-->
<!-- <spigot.version>1.20.4-R0.1-SNAPSHOT</spigot.version>-->
<spigot.version>1.21.11-R0.1-SNAPSHOT</spigot.version>
<kyori.adventure.version>4.23.0</kyori.adventure.version>
<kyori.adventure.platform.version>4.4.1-SNAPSHOT</kyori.adventure.platform.version>
Expand Down Expand Up @@ -417,11 +417,11 @@
<version>3.0.2</version>
<scope>compile</scope>
</dependency>
<!-- <dependency>-->
<!-- <groupId>io.papermc.paper</groupId>-->
<!-- <artifactId>paper-api</artifactId>-->
<!-- <version>1.21.8-R0.1-SNAPSHOT</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>io.papermc.paper</groupId>-->
<!-- <artifactId>paper-api</artifactId>-->
<!-- <version>1.21.11-R0.1-SNAPSHOT</version>-->
<!-- </dependency>-->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
import org.jetbrains.annotations.VisibleForTesting;

public class McMMOPlayer implements Identified {
private static final long NO_SWING = 0L;
private final @NotNull Identity identity;

//Hacky fix for now, redesign later
Expand All @@ -98,7 +97,6 @@ public class McMMOPlayer implements Identified {
private Party invite;
private Party allianceInvite;
private int itemShareModifier;
private long lastSwingTimestamp = NO_SWING;

private PartyTeleportRecord ptpRecord;

Expand Down Expand Up @@ -1281,11 +1279,4 @@ public void setChatMode(@NotNull ChatChannel chatChannel) {
this.chatChannel = chatChannel;
}

public long getLastSwingTimestamp() {
return lastSwingTimestamp;
}

public void setLastSwingTimestamp(long lastSwingTimestamp) {
this.lastSwingTimestamp = lastSwingTimestamp;
}
}
21 changes: 0 additions & 21 deletions src/main/java/com/gmail/nossr50/listeners/PlayerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@
import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerAnimationEvent;
import org.bukkit.event.player.PlayerAnimationType;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
Expand Down Expand Up @@ -1123,23 +1121,4 @@ public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
SkillUtils.removeAbilityBuff(event.getMainHandItem());
SkillUtils.removeAbilityBuff(event.getOffHandItem());
}

@EventHandler(ignoreCancelled = false, priority = EventPriority.MONITOR)
public void onPlayerAnimation(PlayerAnimationEvent event) {
if (event.getAnimationType() != PlayerAnimationType.ARM_SWING) {
return;
}

final Player player = event.getPlayer();

if (!UserManager.hasPlayerDataKey(player)) {
return;
}

final McMMOPlayer mmoPlayer = UserManager.getPlayer(player);

if (mmoPlayer != null) {
mmoPlayer.setLastSwingTimestamp(System.currentTimeMillis());
}
}
}
21 changes: 10 additions & 11 deletions src/main/java/com/gmail/nossr50/mcMMO.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,14 @@ public void onEnable() {
if (serverAPIOutdated) {
foliaLib.getScheduler().runTimer(
() -> getLogger().severe(
"You are running an outdated version of "
+ platformManager.getServerSoftware()
"You are potentially running an outdated version of your server software"
+ ", mcMMO will not work unless you update to a newer version!"),
20, 20 * 60 * 30);

if (platformManager.getServerSoftware() == ServerSoftwareType.CRAFT_BUKKIT) {
if (!getCompatibilityManager().getMinecraftGameVersion().isAtLeast(1, 20, 4)) {
foliaLib.getScheduler().runTimer(
() -> getLogger().severe(
"We have detected you are using incompatible server software, our best guess is that you are using CraftBukkit. mcMMO requires Spigot or Paper, if you are not using CraftBukkit, you will still need to update your custom server software before mcMMO will work."),
"This version of mcMMO requires at least Minecraft 1.20.4 to"
+ " function properly, please update your software or use an older version of mcMMO!"),
20, 20 * 60 * 30);
}
} else {
Expand Down Expand Up @@ -351,15 +350,15 @@ public static MaterialMapStore getMaterialMapStore() {

private void checkForOutdatedAPI() {
try {
Class<?> checkForClass = Class.forName("org.bukkit.event.block.BlockDropItemEvent");
checkForClass.getMethod("getItems");
Class<?> blockDropItemEvent = Class.forName("org.bukkit.event.block.BlockDropItemEvent");
blockDropItemEvent.getMethod("getItems");
Class.forName("net.md_5.bungee.api.chat.BaseComponent");
// 1.20.4 checks
Class<?> entityDamageEvent = Class.forName("org.bukkit.event.entity.EntityDamageEvent");
entityDamageEvent.getMethod("getDamageSource");
} catch (ClassNotFoundException | NoSuchMethodException e) {
serverAPIOutdated = true;
String software = platformManager.getServerSoftwareStr();
getLogger().severe(
"You are running an older version of " + software
+ " that is not compatible with mcMMO, update your server software!");
getLogger().severe("Your server software is missing APIs that mcMMO requires to function properly, please update your server software!");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
public class PlatformBuilder {
private MinecraftGameVersion minecraftGameVersion;
private ServerSoftwareType serverSoftwareType;

public PlatformBuilder() {

Expand All @@ -21,19 +20,8 @@ public PlatformBuilder setMinecraftGameVersion(
return this;
}

public PlatformBuilder setSoftwareType(@NotNull ServerSoftwareType softwareType) {
this.serverSoftwareType = softwareType;
return this;
}

public @Nullable Platform build() {
return switch (serverSoftwareType) {
case PAPER, SPIGOT, CRAFT_BUKKIT -> createBukkitPlatform();
default -> null;
};
}

private BukkitPlatform createBukkitPlatform() {
return new BukkitPlatform(minecraftGameVersion);
}

}
25 changes: 0 additions & 25 deletions src/main/java/com/gmail/nossr50/util/platform/PlatformManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@ public Platform getPlatform() {
}

private @Nullable Platform loadPlatform() {
ServerSoftwareType serverSoftwareType = determinePlatformType();
PlatformBuilder platformBuilder = new PlatformBuilder();
MinecraftGameVersion gameVersion = determineGameVersion(Bukkit.getBukkitVersion());

return platformBuilder
.setMinecraftGameVersion(gameVersion)
.setSoftwareType(serverSoftwareType)
.build();
}

Expand Down Expand Up @@ -68,29 +66,6 @@ public Platform getPlatform() {
return new MinecraftGameVersion(major, minor, patch);
}

//TODO: Rewrite this properly once we actually support a not-bukkit platform
private @NotNull ServerSoftwareType determinePlatformType() {
if (Bukkit.getVersion().toLowerCase(Locale.ENGLISH).contains("paper")) {
return ServerSoftwareType.PAPER;
} else if (Bukkit.getVersion().toLowerCase(Locale.ENGLISH).contains("spigot")) {
return ServerSoftwareType.SPIGOT;
} else {
return ServerSoftwareType.CRAFT_BUKKIT;
}
}

public ServerSoftwareType getServerSoftware() {
return platform.getServerSoftwareType();
}

public String getServerSoftwareStr() {
return switch (getServerSoftware()) {
case PAPER -> "Paper";
case SPIGOT -> "Spigot";
default -> "CraftBukkit";
};
}

public @Nullable CompatibilityManager getCompatibilityManager() {
return platform.getCompatibilityManager();
}
Expand Down
62 changes: 17 additions & 45 deletions src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static com.gmail.nossr50.datatypes.experience.XPGainReason.PVP;
import static com.gmail.nossr50.util.AttributeMapper.MAPPED_MOVEMENT_SPEED;
import static com.gmail.nossr50.util.ItemUtils.isSpear;
import static com.gmail.nossr50.util.MobMetadataUtils.hasMobFlag;
import static com.gmail.nossr50.util.Permissions.canUseSubSkill;
import static com.gmail.nossr50.util.skills.ProjectileUtils.isCrossbowProjectile;
Expand Down Expand Up @@ -132,11 +131,6 @@ private static void processSwordCombat(@NotNull LivingEntity target, @NotNull Pl
return;
}

// Hack to avoid other combat abilities applying to off-hand spear attacks
if (isSpear(player.getInventory().getItemInOffHand()) && isNotSwinging(mmoPlayer)) {
return;
}

SwordsManager swordsManager = mmoPlayer.getSwordsManager();
double boostedDamage = event.getDamage();

Expand Down Expand Up @@ -203,11 +197,6 @@ private static void processTridentCombatMelee(@NotNull LivingEntity target,
return;
}

// Hack to avoid other combat abilities applying to off-hand spear attacks
if (isSpear(player.getInventory().getItemInOffHand()) && isNotSwinging(mmoPlayer)) {
return;
}

final TridentsManager tridentsManager = mmoPlayer.getTridentsManager();

// if (tridentsManager.canActivateAbility()) {
Expand Down Expand Up @@ -321,11 +310,6 @@ private static void processMacesCombat(@NotNull LivingEntity target,
return;
}

// Hack to avoid other combat abilities applying to off-hand spear attacks
if (isSpear(player.getInventory().getItemInOffHand()) && isNotSwinging(mmoPlayer)) {
return;
}

final MacesManager macesManager = mmoPlayer.getMacesManager();

// Apply Limit Break DMG
Expand Down Expand Up @@ -404,11 +388,6 @@ private static void processAxeCombat(@NotNull LivingEntity target, @NotNull Play
return;
}

// Hack to avoid other combat abilities applying to off-hand spear attacks
if (isSpear(player.getInventory().getItemInOffHand()) && isNotSwinging(mmoPlayer)) {
return;
}

final AxesManager axesManager = mmoPlayer.getAxesManager();

if (axesManager.canActivateAbility()) {
Expand Down Expand Up @@ -461,11 +440,6 @@ private static void processUnarmedCombat(@NotNull LivingEntity target, @NotNull
return;
}

// Hack to avoid other combat abilities applying to off-hand spear attacks
if (isSpear(player.getInventory().getItemInOffHand()) && isNotSwinging(mmoPlayer)) {
return;
}

final UnarmedManager unarmedManager = mmoPlayer.getUnarmedManager();

if (unarmedManager.canActivateAbility()) {
Expand Down Expand Up @@ -598,8 +572,12 @@ private static void processArcheryCombat(@NotNull LivingEntity target, @NotNull
public static void processCombatAttack(@NotNull EntityDamageByEntityEvent event,
@NotNull Entity painSourceRoot,
@NotNull LivingEntity target) {
Entity painSource = event.getDamager();
EntityType entityType = painSource.getType();
final Entity painSource = event.getDamager();
final EntityType entityType = painSource.getType();
final String damageType = event.getDamageSource().getDamageType().getKey().getKey();

boolean isDamageTypeSpear =
damageType.equalsIgnoreCase("SPEAR");

if (target instanceof ArmorStand) {
return;
Expand Down Expand Up @@ -642,7 +620,7 @@ public static void processCombatAttack(@NotNull EntityDamageByEntityEvent event,
return;
}

ItemStack heldItem = player.getInventory().getItemInMainHand();
final ItemStack heldItem = player.getInventory().getItemInMainHand();

if (target instanceof Tameable) {
if (heldItem.getType() == Material.BONE) {
Expand All @@ -660,7 +638,16 @@ public static void processCombatAttack(@NotNull EntityDamageByEntityEvent event,
}
}

if (ItemUtils.isSword(heldItem)) {
if (isDamageTypeSpear) {
if (!mcMMO.p.getSkillTools()
.canCombatSkillsTrigger(PrimarySkillType.SPEARS, target)) {
return;
}
if (mcMMO.p.getSkillTools()
.doesPlayerHaveSkillPermission(player, PrimarySkillType.SPEARS)) {
processSpearsCombat(target, player, event);
}
} if (ItemUtils.isSword(heldItem)) {
if (!mcMMO.p.getSkillTools()
.canCombatSkillsTrigger(PrimarySkillType.SWORDS, target)) {
return;
Expand Down Expand Up @@ -710,15 +697,6 @@ public static void processCombatAttack(@NotNull EntityDamageByEntityEvent event,
.doesPlayerHaveSkillPermission(player, PrimarySkillType.MACES)) {
processMacesCombat(target, player, event);
}
} else if (isSpear(heldItem)) {
if (!mcMMO.p.getSkillTools()
.canCombatSkillsTrigger(PrimarySkillType.SPEARS, target)) {
return;
}
if (mcMMO.p.getSkillTools()
.doesPlayerHaveSkillPermission(player, PrimarySkillType.SPEARS)) {
processSpearsCombat(target, player, event);
}
}
} else if (entityType == EntityType.WOLF) {
Wolf wolf = (Wolf) painSource;
Expand Down Expand Up @@ -1225,10 +1203,4 @@ public static void delayArrowMetaCleanup(@NotNull AbstractArrow arrow) {
mcMMO.p.getFoliaLib().getScheduler()
.runLater(() -> ProjectileUtils.cleanupProjectileMetadata(arrow), 20 * 120);
}

public static boolean isNotSwinging(McMMOPlayer mmoPlayer) {
// If player has swung in the last second, it's extremely unlikely the damage originates
// from an off-hand spear charge attack
return mmoPlayer.getLastSwingTimestamp() + 500L < System.currentTimeMillis();
}
}