Revert "Merge pull request #656 from CivMC/feature/pearl-health-value"

This reverts commit 1e9dfc832f, reversing
changes made to e4182132a2.
This commit is contained in:
okx-code
2024-11-25 18:48:15 +00:00
parent 1eae9fc4c3
commit 08c7abf423
5 changed files with 42 additions and 22 deletions

View File

@@ -123,6 +123,13 @@ public interface ExilePearl {
*/
int getHealth();
/**
* Gets the pearl health percent value
*
* @return The health percent value
*/
Integer getHealthPercent();
/**
* Sets the pearl health value
*

View File

@@ -11,10 +11,10 @@ public class CmdAdminSetHealth extends PearlCommand {
super(pearlApi);
this.aliases.add("sethealth");
this.setHelpShort("Sets the health value of a pearl.");
this.setHelpShort("Sets the health % value of a pearl.");
this.commandArgs.add(requiredPearlPlayer());
this.commandArgs.add(required("health", autoTab("", "Enter the desired health")));
this.commandArgs.add(required("health %", autoTab("", "Enter the desired health percent")));
this.permission = Permission.SET_HEALTH.node;
this.visibility = CommandVisibility.SECRET;
@@ -34,13 +34,17 @@ public class CmdAdminSetHealth extends PearlCommand {
return;
}
Integer health = argAsInt(1);
if (health == null) {
msg("<b>Pearl health must be an integer");
Integer arg = argAsInt(1);
if (arg == null) {
msg("<b>Pearl health must be an integer between 0 and 100.");
return;
}
pearl.setHealth(health);
msg("<g>You updated the pearl health of player %s to %d", pearl.getPlayerName(), health);
int percent = Math.min(100, Math.max(1, arg));
// calculate the actual value
int healthValue = (int) (plugin.getPearlConfig().getPearlHealthMaxValue() * ((double) percent / 100));
pearl.setHealth(healthValue);
msg("<g>You updated the pearl health of player %s to %d%%", pearl.getPlayerName(), percent);
}
}

View File

@@ -231,6 +231,17 @@ final class CoreExilePearl implements ExilePearl {
}
/**
* Gets the pearl health value
*
* @return The strength value
*/
@Override
public Integer getHealthPercent() {
return (int) Math.round(((double) health / pearlApi.getPearlConfig().getPearlHealthMaxValue()) * 100);
}
/**
* Gets the pearl health value
*

View File

@@ -71,27 +71,26 @@ final class CoreLoreGenerator implements LoreProvider {
private List<String> generateLoreInternal(ExilePearl pearl, int health, boolean addCommandHelp) {
List<String> lore = new ArrayList<String>();
Integer healthPercent = Math.min(100, Math.max(0, (int) Math.round(((double) health / config.getPearlHealthMaxValue()) * 100)));
lore.add(parse("<l>%s", pearl.getItemName()));
lore.add(parse(PlayerNameStringFormat, pearl.getPlayerName(), Integer.toString(pearl.getPearlId(), 36).toUpperCase()));
lore.add(parse("<a>Health: <n>%s%%", healthPercent.toString()));
lore.add(parse("<a>Exiled on: <n>%s", dateFormat.format(pearl.getPearledOn())));
lore.add(parse("<a>Killed by: <n>%s", pearl.getKillerName()));
if (ExilePearlPlugin.getApi().isBanStickEnabled() && BanHandler.isPlayerBanned(pearl.getPlayerId())) {
lore.add(parse("<b>Player is banned."));
}
lore.add(parse(""));
lore.add(parse("<a>Health: <n>%s/%s", health, config.getPearlHealthMaxValue()));
Set<RepairMaterial> repair = config.getRepairMaterials(pearl.getPearlType());
if (repair != null) {
for (RepairMaterial rep : repair) {
double amountPerItem = rep.getRepairAmount() / pearl.getLongTimeMultiplier();
int amountPerItem = rep.getRepairAmount();
String item = rep.getStack().getType().toString();
if (rep.getStack().hasItemMeta() && rep.getStack().getItemMeta().hasDisplayName()) {
item = rep.getStack().getItemMeta().getDisplayName();
}
int damagesPerHumanInterval = (config.getPearlHealthDecayHumanIntervalMin() / config.getPearlHealthDecayIntervalMin()) * config.getPearlHealthDecayAmount(); // intervals in a human interval * damage per
int repairsPerHumanInterval = (int) Math.ceil(damagesPerHumanInterval / amountPerItem);
int repairsPerHumanInterval = damagesPerHumanInterval / amountPerItem;
lore.add(parse("<a>Cost per %s using %s:<n> %s", config.getPearlHealthDecayHumanInterval(), item, Integer.toString(repairsPerHumanInterval)));
}
}

View File

@@ -1107,15 +1107,15 @@ public class PlayerListener implements Listener, Configurable {
return;
}
// Get the total possible repair amount and new health value
// Get the total possible repair amount. This doesn't need to be limited
// because the lore generator will cap at 100%
int repairAmount = invItems.getAmount(repairItem.getStack()) * repairItem.getRepairAmount();
repairAmount = (int) Math.ceil(repairAmount / pearl.getLongTimeMultiplier());
int newHealth = Math.min(pearlApi.getPearlConfig().getPearlHealthMaxValue(), pearl.getHealth() + repairAmount);
// Generate a new item with the updated health value as the crafting result
ItemStack resultStack = pearl.createItemStack();
ItemMeta im = resultStack.getItemMeta();
im.setLore(pearlApi.getLoreProvider().generateLoreWithModifiedHealth(pearl, newHealth));
im.setLore(pearlApi.getLoreProvider().generateLoreWithModifiedHealth(pearl, pearl.getHealth() + repairAmount));
resultStack.setItemMeta(im);
e.getInventory().setResult(resultStack);
@@ -1146,12 +1146,11 @@ public class PlayerListener implements Listener, Configurable {
// Quit if no repair items were found in the crafting inventory
if (repairItem != null) {
int maxHealth = pearlApi.getPearlConfig().getPearlHealthMaxValue();
int repairPerItem = repairItem.getRepairAmount();
int repairMatsAvailable = invItems.getAmount(repairItem.getStack());
int healthToFill = maxHealth - pearl.getHealth();
double repairPerItem = repairItem.getRepairAmount() / pearl.getLongTimeMultiplier();
int repairMatsToUse = Math.min((int) Math.ceil(healthToFill / repairPerItem), repairMatsAvailable);
int repairAmount = (int) (repairMatsToUse * repairPerItem);
int newHealth = Math.min(pearlApi.getPearlConfig().getPearlHealthMaxValue(), pearl.getHealth() + repairAmount);
int repairMatsToUse = Math.min((int) Math.ceil((maxHealth - pearl.getHealth()) / (double) repairPerItem), repairMatsAvailable);
int repairAmount = repairMatsToUse * repairPerItem;
repairAmount = (int) Math.ceil(repairAmount / pearl.getLongTimeMultiplier());
// Changing the value of the crafting items results in a dupe glitch so any remaining
// materials need to be placed back into the player's inventory.
@@ -1179,7 +1178,7 @@ public class PlayerListener implements Listener, Configurable {
inv.clear();
// Repair the pearl and update the item stack
pearl.setHealth(newHealth);
pearl.setHealth(pearl.getHealth() + repairAmount);
inv.setResult(pearl.createItemStack());
pearlApi.log("The pearl for player %s was repaired by %d points.", pearl.getPlayerName(), repairAmount);
return;