Skip to content

Commit

Permalink
Merge branch 'mcMMO-Dev:master' into update
Browse files Browse the repository at this point in the history
  • Loading branch information
SrBedrock authored Nov 11, 2024
2 parents d1c1ed8 + 4cb3d31 commit 815b13b
Show file tree
Hide file tree
Showing 34 changed files with 202 additions and 183 deletions.
12 changes: 11 additions & 1 deletion Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
Version 2.2.027
Fixed Ricocheted arrows losing some data after a ricochet
Added Tridents / Crossbows to salvage.vanilla.yml config (see notes)
Fixed an issue where Folia could have all of its threads lock up effectively killing the server
Fixed concurrency issue with Folia regarding locale strings
Fixed concurrency issue with Folia regarding COTW summons
Updated 'Salvage.SubSkill.ScrapCollector.Stat' to no longer mention luck being involved
The amount of materials from salvage are no longer luck-based, you will get a deterministic amount based on damage to the item.
Fixed Ricocheted arrows losing some data after a ricochet
Changed color of locale strings for 'Repair.Listener.Anvil' to be easier to read
Changed color of locale strings for 'Salvage.Listener.Anvil' to be easier to read

NOTES:
Tridents and Crossbows are now in the salvage.vanilla.yml config, you will need to either delete this config file to regenerate it or add the entries manually.
You can check the default config file after running this mcMMO update at least once in the defaults folder at plugins\mcMMO\defaults to see what you would need to add if you want to take the manual approach

Version 2.2.026
Fixed NullPointerException on ChunkUnloadEvent
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.gmail.nossr50.mcMMO</groupId>
<artifactId>mcMMO</artifactId>
<version>2.2.027-SNAPSHOT</version>
<version>2.2.027</version>
<name>mcMMO</name>
<url>https://github.com/mcMMO-Dev/mcMMO</url>
<scm>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected List<String> statsDisplay(Player player, float skillValue, boolean has
if (canScrapCollector) {
messages.add(getStatMessage(false, true,
SubSkillType.SALVAGE_SCRAP_COLLECTOR,
String.valueOf(RankUtils.getRank(player, SubSkillType.SALVAGE_SCRAP_COLLECTOR)),
String.valueOf(SalvageManager.getSalvageLimit(player)),
RankUtils.getHighestRankStr(SubSkillType.SALVAGE_SCRAP_COLLECTOR)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.gmail.nossr50.skills.salvage.salvageables.SalvageableFactory;
import com.gmail.nossr50.util.ItemUtils;
import com.gmail.nossr50.util.LogUtils;
import com.gmail.nossr50.util.skills.SkillUtils;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
Expand All @@ -17,8 +18,6 @@
import java.util.*;
import java.util.logging.Level;

import static com.gmail.nossr50.util.skills.SkillUtils.getRepairAndSalvageQuantities;

public class SalvageConfig extends BukkitConfig {
private final HashSet<String> notSupported;
private Set<Salvageable> salvageables;
Expand All @@ -42,7 +41,6 @@ protected void loadKeys() {
Set<String> keys = section.getKeys(false);

//Original version of 1.16 support had maximum quantities that were bad, this fixes it

if (mcMMO.getUpgradeManager().shouldUpgrade(UpgradeType.FIX_NETHERITE_SALVAGE_QUANTITIES)) {
mcMMO.p.getLogger().log(Level.INFO, "Fixing incorrect Salvage quantities on Netherite gear, this will only run once...");
for (String namespacedkey : mcMMO.getMaterialMapStore().getNetheriteArmor()) {
Expand All @@ -59,7 +57,6 @@ protected void loadKeys() {
}
}


for (String key : keys) {
// Validate all the things!
List<String> reason = new ArrayList<>();
Expand All @@ -85,6 +82,8 @@ protected void loadKeys() {
salvageMaterialType = MaterialType.STONE;
} else if (ItemUtils.isStringTool(salvageItem)) {
salvageMaterialType = MaterialType.STRING;
} else if (ItemUtils.isPrismarineTool(salvageItem)) {
salvageMaterialType = MaterialType.PRISMARINE;
} else if (ItemUtils.isLeatherArmor(salvageItem)) {
salvageMaterialType = MaterialType.LEATHER;
} else if (ItemUtils.isIronArmor(salvageItem) || ItemUtils.isIronTool(salvageItem)) {
Expand Down Expand Up @@ -145,7 +144,7 @@ protected void loadKeys() {

// Maximum Quantity
int maximumQuantity = itemMaterial != null
? getRepairAndSalvageQuantities(itemMaterial, salvageMaterial)
? SkillUtils.getRepairAndSalvageQuantities(itemMaterial, salvageMaterial)
: config.getInt("Salvageables." + key + ".MaximumQuantity", 1);

if (maximumQuantity <= 0 && itemMaterial != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public enum MaterialType {
GOLD,
DIAMOND,
NETHERITE,
PRISMARINE,
OTHER;

public Material getDefaultMaterial() {
Expand Down Expand Up @@ -41,6 +42,8 @@ public Material getDefaultMaterial() {
return Material.getMaterial("NETHERITE_SCRAP");
else
return Material.DIAMOND;
case PRISMARINE:
return Material.PRISMARINE_CRYSTALS;

case OTHER:
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void onChunkUnload(ChunkUnloadEvent event) {
List<LivingEntity> matchingEntities
= mcMMO.getTransientEntityTracker().getAllTransientEntitiesInChunk(event.getChunk());
for(LivingEntity livingEntity : matchingEntities) {
mcMMO.getTransientEntityTracker().removeSummon(livingEntity, null, false);
mcMMO.getTransientEntityTracker().killSummonAndCleanMobFlags(livingEntity, null, false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ public void onEntityDeath(final EntityDeathEvent event) {
final LivingEntity entity = event.getEntity();

if (mcMMO.getTransientEntityTracker().isTransient(entity)) {
mcMMO.getTransientEntityTracker().removeSummon(entity, null, false);
mcMMO.getTransientEntityTracker().killSummonAndCleanMobFlags(entity, null, false);
}

/* WORLD BLACKLIST CHECK */
Expand Down
51 changes: 12 additions & 39 deletions src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

public class SalvageManager extends SkillManager {
private boolean placedAnvil;
private int lastClick;
private int lastClick;

public SalvageManager(McMMOPlayer mcMMOPlayer) {
super(mcMMOPlayer, PrimarySkillType.SALVAGE);
Expand Down Expand Up @@ -78,17 +78,6 @@ public void handleSalvage(Location location, ItemStack item) {
}
}

// Permissions checks on material and item types
if (!Permissions.salvageItemType(player, salvageable.getSalvageItemType())) {
NotificationManager.sendPlayerInformation(player, NotificationType.NO_PERMISSION, "mcMMO.NoPermission");
return;
}

if (!Permissions.salvageMaterialType(player, salvageable.getSalvageMaterialType())) {
NotificationManager.sendPlayerInformation(player, NotificationType.NO_PERMISSION, "mcMMO.NoPermission");
return;
}

/*int skillLevel = getSkillLevel();*/
int minimumSalvageableLevel = salvageable.getMinimumLevel();

Expand All @@ -108,7 +97,7 @@ public void handleSalvage(Location location, ItemStack item) {
return;
}

potentialSalvageYield = Math.min(potentialSalvageYield, getSalvageLimit()); // Always get at least something back, if you're capable of salvaging it.
potentialSalvageYield = Math.min(potentialSalvageYield, getSalvageLimit(getPlayer())); // Always get at least something back, if you're capable of salvaging it.

location.add(0.5, 1, 0.5);

Expand All @@ -119,36 +108,15 @@ public void handleSalvage(Location location, ItemStack item) {
enchantBook = arcaneSalvageCheck(enchants);
}

//Lottery on Salvageable Amount

int lotteryResults = 1;
int chanceOfSuccess = 99;

for(int x = 0; x < potentialSalvageYield-1; x++) {

if (ProbabilityUtil.isStaticSkillRNGSuccessful(PrimarySkillType.SALVAGE, mmoPlayer, chanceOfSuccess)) {
chanceOfSuccess-=3;
chanceOfSuccess = Math.max(chanceOfSuccess, 90);

lotteryResults+=1;
}
}

ItemStack salvageResults = new ItemStack(salvageable.getSalvageMaterial(), lotteryResults);
ItemStack salvageResults = new ItemStack(salvageable.getSalvageMaterial(), potentialSalvageYield);

//Call event
if (EventUtils.callSalvageCheckEvent(player, item, salvageResults, enchantBook).isCancelled()) {
return;
}

// We only send a confirmation message after processing the event (fixes #4694)
if (lotteryResults == potentialSalvageYield && potentialSalvageYield != 1 && RankUtils.isPlayerMaxRankInSubSkill(player, SubSkillType.SALVAGE_ARCANE_SALVAGE)) {
NotificationManager.sendPlayerInformationChatOnly(player, "Salvage.Skills.Lottery.Perfect", String.valueOf(lotteryResults), StringUtils.getPrettyMaterialString(item.getType()));
} else if (salvageable.getMaximumQuantity() == 1 || getSalvageLimit() >= salvageable.getMaximumQuantity()) {
NotificationManager.sendPlayerInformationChatOnly(player, "Salvage.Skills.Lottery.Normal", String.valueOf(lotteryResults), StringUtils.getPrettyMaterialString(item.getType()));
} else {
NotificationManager.sendPlayerInformationChatOnly(player, "Salvage.Skills.Lottery.Untrained", String.valueOf(lotteryResults), StringUtils.getPrettyMaterialString(item.getType()));
}
NotificationManager.sendPlayerInformationChatOnly(player, "Salvage.Skills.Lottery.Normal",
String.valueOf(potentialSalvageYield), StringUtils.getPrettyMaterialString(item.getType()));

player.getInventory().setItemInMainHand(new ItemStack(Material.AIR));

Expand Down Expand Up @@ -183,8 +151,13 @@ public void handleSalvage(Location location, ItemStack item) {
return Math.min((((Salvage.salvageMaxPercentage / Salvage.salvageMaxPercentageLevel) * getSkillLevel()) / 100.0D), Salvage.salvageMaxPercentage / 100.0D);
}*/

public int getSalvageLimit() {
return (RankUtils.getRank(getPlayer(), SubSkillType.SALVAGE_SCRAP_COLLECTOR));
public static int getSalvageLimit(Player player) {
if (RankUtils.getRank(player, SubSkillType.SALVAGE_SCRAP_COLLECTOR) == 1) {
return 1;
} else {
var curRank = RankUtils.getRank(player, SubSkillType.SALVAGE_SCRAP_COLLECTOR);
return curRank * 2;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.UUID;

public class TrackedTamingEntity extends CancellableRunnable {
private final @NotNull LivingEntity livingEntity;
private final @NotNull CallOfTheWildType callOfTheWildType;
private final @NotNull Player player;
private final @NotNull UUID playerUUID;

protected TrackedTamingEntity(@NotNull LivingEntity livingEntity, @NotNull CallOfTheWildType callOfTheWildType, @NotNull Player player) {
public TrackedTamingEntity(@NotNull LivingEntity livingEntity, @NotNull CallOfTheWildType callOfTheWildType,
@NotNull Player player) {
this.player = player;
this.playerUUID = player.getUniqueId();
this.callOfTheWildType = callOfTheWildType;
this.livingEntity = livingEntity;

Expand All @@ -28,7 +33,8 @@ protected TrackedTamingEntity(@NotNull LivingEntity livingEntity, @NotNull CallO

@Override
public void run() {
mcMMO.getTransientEntityTracker().removeSummon(this.getLivingEntity(), player, true);
mcMMO.getTransientEntityTracker().killSummonAndCleanMobFlags(this.getLivingEntity(), player, true);
mcMMO.getTransientEntityTracker().removeSummonFromTracker(playerUUID, this);
this.cancel();
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/gmail/nossr50/util/ItemUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@ public static boolean isStringTool(ItemStack item) {
return mcMMO.getMaterialMapStore().isStringTool(item.getType().getKey().getKey());
}

public static boolean isPrismarineTool(ItemStack item) {
return mcMMO.getMaterialMapStore().isPrismarineTool(item.getType().getKey().getKey());
}

/**
* Checks to see if an item is a gold tool.
*
Expand Down
20 changes: 18 additions & 2 deletions src/main/java/com/gmail/nossr50/util/MaterialMapStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class MaterialMapStore {
private final @NotNull HashSet<String> ironArmor;
private final @NotNull HashSet<String> ironTools;
private final @NotNull HashSet<String> stringTools;
private final @NotNull HashSet<String> prismarineTools;
private final @NotNull HashSet<String> goldArmor;
private final @NotNull HashSet<String> goldTools;
private final @NotNull HashSet<String> chainmailArmor;
Expand Down Expand Up @@ -89,6 +90,7 @@ public MaterialMapStore() {
bows = new HashSet<>();
crossbows = new HashSet<>();
stringTools = new HashSet<>();
prismarineTools = new HashSet<>();
tools = new HashSet<>();

swords = new HashSet<>();
Expand Down Expand Up @@ -462,7 +464,7 @@ private void fillTools() {
fillIronToolsWhiteList();
fillGoldToolsWhiteList();
fillDiamondToolsWhiteList();
fillnetheriteToolsWhiteList();
fillNetheriteToolsWhiteList();

fillSwords();
fillAxes();
Expand All @@ -472,6 +474,7 @@ private void fillTools() {
fillTridents();
fillMaces();
fillStringTools();
fillPrismarineTools();
fillBows();
fillCrossbows();

Expand Down Expand Up @@ -501,6 +504,11 @@ private void fillStringTools() {
stringTools.add("bow");
stringTools.add("fishing_rod");
stringTools.add("carrot_on_a_stick");
stringTools.add("crossbow");
}

private void fillPrismarineTools() {
prismarineTools.add("trident");
}

private void fillMaces() {
Expand Down Expand Up @@ -674,7 +682,7 @@ private void fillDiamondToolsWhiteList() {
diamondTools.add("diamond_shovel");
}

private void fillnetheriteToolsWhiteList() {
private void fillNetheriteToolsWhiteList() {
netheriteTools.add("netherite_sword");
netheriteTools.add("netherite_axe");
netheriteTools.add("netherite_hoe");
Expand Down Expand Up @@ -976,6 +984,14 @@ public boolean isStringTool(@NotNull String id) {
return stringTools.contains(id);
}

public boolean isPrismarineTool(@NotNull Material material) {
return isPrismarineTool(material.getKey().getKey());
}

public boolean isPrismarineTool(@NotNull String id) {
return prismarineTools.contains(id);
}

public boolean isGlass(@NotNull Material material) {
return glassBlocks.contains(material.getKey().getKey());
}
Expand Down
Loading

0 comments on commit 815b13b

Please sign in to comment.