FeelingLucky v1.0.0 Release Clean Up

Cleaned up a bunch of stuff and made the luck stat unique to the plugin rather than using the values provided by minecraft.
This commit is contained in:
Paldiu 2022-05-20 16:54:28 -05:00
parent 17f83bd9f2
commit 010fd76031
17 changed files with 28 additions and 50 deletions

View File

@ -1,16 +1,11 @@
package io.github.simplex.api;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.Player;
import java.io.Serializable;
public interface LuckContainer extends Serializable {
Attribute asAttribute();
double getNumber();
boolean isMatch(double number);
boolean isClose(double number, int range);

View File

@ -20,7 +20,7 @@ public final class BlockDrops extends AbstractListener {
Player player = event.getPlayer();
Luck luck = getHandler().getLuckContainer(player);
List<Item> items = event.getItems();
if (luck.quickRNG(luck.getPercentage()) && doesQualify("block_drops", luck.getPercentage())) {
if (luck.quickRNG(luck.getValue()) && doesQualify("block_drops", luck.getValue())) {
event.getItems().clear();
event.getItems().addAll(items.stream().map(SneakyWorker::move).toList());
}

View File

@ -37,8 +37,8 @@ public final class BonemealFullCrop extends AbstractListener {
if (action.isRightClick()
&& handItem.isSimilar(bonemeal)
&& (data instanceof Ageable crop)
&& luck.quickRNG(luck.getPercentage())
&& doesQualify("bonemeal", luck.getPercentage())) {
&& luck.quickRNG(luck.getValue())
&& doesQualify("bonemeal", luck.getValue())) {
crop.setAge(crop.getMaximumAge());
data.merge(crop);
block.setBlockData(data);

View File

@ -17,7 +17,7 @@ public final class CheatDeath extends AbstractListener {
Player player = event.getPlayer();
Luck luck = getHandler().getLuckContainer(player);
double absorption = Math.round(Luck.RNG().nextDouble(5.0, 10.0));
if (luck.quickRNG(luck.getPercentage()) && doesQualify("cheat_death", luck.getPercentage())) {
if (luck.quickRNG(luck.getValue()) && doesQualify("cheat_death", luck.getValue())) {
event.setCancelled(true);
player.setHealth(1.0);
player.setAbsorptionAmount(absorption);

View File

@ -21,7 +21,7 @@ public final class EnchantmentBoost extends AbstractListener {
List<Enchantment> enchList = enchMap.keySet().stream().toList();
Player player = event.getEnchanter();
Luck luck = getHandler().getLuckContainer(player);
if (luck.quickRNG(luck.getPercentage()) && doesQualify("enchanting", luck.getPercentage())) {
if (luck.quickRNG(luck.getValue()) && doesQualify("enchanting", luck.getValue())) {
Enchantment particular = enchList.get(Luck.RNG().nextInt(enchList.size()));
int rng = Luck.RNG().nextInt(1, 5);

View File

@ -20,7 +20,7 @@ public final class ExpBoost extends AbstractListener {
int rounded = Math.round(math);
Player player = event.getPlayer();
Luck luck = plugin.getHandler().getLuckContainer(player);
if (luck.quickRNG(luck.getPercentage()) && doesQualify("experience", luck.getPercentage())) {
if (luck.quickRNG(luck.getValue()) && doesQualify("experience", luck.getValue())) {
orb.setExperience(rounded);
}
}

View File

@ -19,7 +19,7 @@ public class GiveDamage extends AbstractListener {
&& (e.getEntity() instanceof LivingEntity)) {
double nextDmg = e.getDamage() + Luck.RNG().nextDouble(1.0, 5.0);
Luck luck = plugin.getHandler().getLuckContainer(player);
if (luck.quickRNG(luck.getPercentage())) {
if (luck.quickRNG(luck.getValue())) {
e.setDamage(nextDmg);
player.sendMessage(MiniComponent.info("Your luck has increased your damage output!"));
}

View File

@ -64,7 +64,7 @@ public class ItemDrops extends AbstractListener {
Item item = event.getItemDrop();
ItemStack stack = item.getItemStack();
int amount = stack.getAmount();
if (luck.quickRNG(luck.getPercentage()) && doesQualify("item_drops", luck.getPercentage())) {
if (luck.quickRNG(luck.getValue()) && doesQualify("item_drops", luck.getValue())) {
int rng = Luck.RNG().nextInt(2, 5);
amount += rng;
stack.setAmount(amount);

View File

@ -24,7 +24,7 @@ public class OreVein extends AbstractListener {
public void playerMine(BlockBreakEvent event) {
Player player = event.getPlayer();
Luck luck = plugin.getHandler().getLuckContainer(player);
if (luck.quickRNG(luck.getPercentage()) && event.getBlock().isValidTool(player.getInventory().getItemInMainHand())) {
if (luck.quickRNG(luck.getValue()) && event.getBlock().isValidTool(player.getInventory().getItemInMainHand())) {
getOresInArea(event.getBlock()).forEach(Block::breakNaturally);
player.sendMessage(MiniComponent.info("Your luck has let you mine all the blocks with one swing."));
}

View File

@ -26,7 +26,7 @@ public class RandomEffect extends AbstractListener {
int size = effectList.size();
PotionEffect random = effectList.get(Luck.RNG().nextInt(size - 1));
if (luck.quickRNG(luck.getPercentage()) && doesQualify("random_effect", luck.getValue())) {
if (luck.quickRNG(luck.getValue()) && doesQualify("random_effect", luck.getValue())) {
player.addPotionEffect(random);
player.sendMessage(MiniComponent.info("Thanks to luck, a random positive potion effect has been applied to you."));
}
@ -41,7 +41,7 @@ public class RandomEffect extends AbstractListener {
int size = effectList.size();
PotionEffect random = effectList.get(Luck.RNG().nextInt(size - 1));
if (luck.quickRNG(luck.getPercentage()) && doesQualify("random_effect", luck.getValue())) {
if (luck.quickRNG(luck.getValue()) && doesQualify("random_effect", luck.getValue())) {
player.addPotionEffect(random);
player.sendMessage(MiniComponent.info("Thanks to luck, a random positive potion effect has been applied to you."));
}

View File

@ -21,7 +21,7 @@ public class RestoreHunger extends AbstractListener {
Luck luck = getHandler().getLuckContainer(event.getPlayer());
PotionEffect effect = PotionEffectBuilder.newEffect().type(PotionEffectType.SATURATION).amplifier(2).duration(10).particles(false).create();
if (luck.notDefault()) {
double percentage = luck.getPercentage();
double percentage = luck.getValue();
ListBox.foods.forEach(food -> {
if (item.isSimilar(food)) {
if (luck.quickRNG(percentage) && doesQualify("restore_hunger", percentage)) {

View File

@ -25,7 +25,7 @@ public class TakeDamage extends AbstractListener {
Luck luck = getHandler().getLuckContainer(player);
if (ListBox.acceptedCauses.contains(event.getCause())) {
if (luck.notDefault()) {
double percentage = luck.getPercentage();
double percentage = luck.getValue();
/*
* If a player's luck stat is a negative number, or they are "marked",
@ -51,7 +51,7 @@ public class TakeDamage extends AbstractListener {
if (ListBox.sideCauses.contains(event.getCause())) {
if (luck.notDefault()) {
double percentage = luck.getPercentage();
double percentage = luck.getValue();
/*
* If a player's luck stat is a negative number, or they are "marked",

View File

@ -27,7 +27,7 @@ public class UnbreakableTool extends AbstractListener {
if (ItemBuilder.isTool(stack.getType())) {
if (event.getWhoClicked() instanceof Player player) {
Luck luck = getHandler().getLuckContainer(player);
if (luck.quickRNG(luck.getPercentage()) && doesQualify("unbreakable", luck.getPercentage())) {
if (luck.quickRNG(luck.getValue()) && doesQualify("unbreakable", luck.getValue())) {
meta.setUnbreakable(true);
stack.setItemMeta(meta);
inventory.setResult(stack);

View File

@ -44,7 +44,7 @@ public class VillagerInventory extends AbstractListener {
Luck luck = plugin.getHandler().getLuckContainer(event.getPlayer());
if (luck == null) return;
if (luck.quickRNG(luck.getPercentage())) {
if (luck.quickRNG(luck.getValue())) {
recipeList.add(recipe);
vil.setRecipes(recipeList);
}

View File

@ -3,7 +3,6 @@ package io.github.simplex.luck.player;
import io.github.simplex.api.LuckContainer;
import io.github.simplex.luck.FeelingLucky;
import org.bukkit.Bukkit;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
@ -41,9 +40,9 @@ public class Luck implements LuckContainer {
return new SplittableRandom();
}
public static boolean quickRNGnoMultiplier(double percentage) {
public static boolean quickRNGnoMultiplier(double value) {
double rng;
if (percentage >= 100.0) {
if (value >= 1024.0) {
rng = 1024.0; // 100% chance to trigger, obviously;
} else {
rng = RNG().nextDouble(0.0, 1024.0);
@ -51,7 +50,7 @@ public class Luck implements LuckContainer {
double actual = Math.round((rng / 1024.0) * 100);
return (percentage >= actual);
return (value >= actual);
}
public FeelingLucky getPlugin() {
@ -70,24 +69,14 @@ public class Luck implements LuckContainer {
return markedPlayers.contains(player);
}
@Override
public Attribute asAttribute() {
return Attribute.GENERIC_LUCK;
}
@Override
public double getNumber() {
return associatedPlayer().getAttribute(asAttribute()).getValue();
}
@Override
public boolean isMatch(double number) {
return getNumber() == number;
return getValue() == number;
}
@Override
public boolean isClose(double number, int range) {
return ((getNumber() - range <= number) && (number <= getNumber() + range));
return ((getValue() - range <= number) && (number <= getValue() + range));
}
@Override
@ -100,9 +89,9 @@ public class Luck implements LuckContainer {
return player;
}
public boolean quickRNG(double percentage) {
public boolean quickRNG(double value) {
double rng;
if (percentage >= 100.0) {
if (value >= 1024.0) {
rng = 1024.0; // 100% chance to trigger, obviously;
} else {
rng = RNG().nextDouble(0.0, 1024.0);
@ -111,10 +100,10 @@ public class Luck implements LuckContainer {
double actual = Math.round((rng / 1024) * 100);
if (multiplier() > 1.0) {
return ((percentage * multiplier()) >= actual);
return ((value * multiplier()) >= actual);
}
return (percentage >= actual);
return (value >= actual);
}
public void reset() {
@ -128,7 +117,6 @@ public class Luck implements LuckContainer {
public void setValue(double value) {
BASE_VALUE = value;
player.getAttribute(Attribute.GENERIC_LUCK).setBaseValue(value);
plugin.getConfigMap().get(associatedPlayer().getUniqueId()).setLuck(value);
Bukkit.getPluginManager().callEvent(event);
}
@ -162,7 +150,7 @@ public class Luck implements LuckContainer {
}
public double getDefaultValue() {
return player.getAttribute(Attribute.GENERIC_LUCK).getDefaultValue();
return 0;
}
public void addTo(double value) {
@ -181,10 +169,6 @@ public class Luck implements LuckContainer {
setValue(getValue() + value);
}
public double getPercentage() {
return getValue() - getDefaultValue();
}
public boolean notDefault() {
return getValue() != getDefaultValue();
}

View File

@ -29,7 +29,7 @@ public class PlayerConfig {
File file = new File(dataFolder, player.getUniqueId() + ".yml");
if (!file.exists()) {
String name = "username: " + player.getName();
String luck = "luck: " + player.getAttribute(Attribute.GENERIC_LUCK).getDefaultValue();
String luck = "luck: " + 0;
String multiplier = "multiplier: " + 1.0;
SneakyWorker.sneakyTry(() -> {

View File

@ -8,7 +8,6 @@ import io.github.simplex.luck.player.PlayerConfig;
import org.bukkit.Bukkit;
import org.bukkit.command.*;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -143,7 +142,7 @@ public class LuckCMD extends Command implements TabCompleter, PluginIdentifiable
if ((sender instanceof Player player) && player.hasPermission("luck.default")) {
if (args[0].equalsIgnoreCase("info")) {
Luck luck = plugin.getHandler().getLuckContainer(player);
player.sendMessage(MiniComponent.info("Your Luck: " + luck.getPercentage()));
player.sendMessage(MiniComponent.info("Your Luck: " + luck.getValue()));
return true;
}
} else if (sender instanceof ConsoleCommandSender) {