mirror of
https://github.com/SimplexDevelopment/FeelingLucky.git
synced 2025-07-04 11:06:43 +00:00
Compare commits
15 Commits
Beta-1.0-R
...
1.2.0-RC01
Author | SHA1 | Date | |
---|---|---|---|
c3d781f5b6 | |||
e6fe9e904e | |||
c383b2c546 | |||
94b9e12f45 | |||
eb80523edc | |||
355b612732 | |||
67734f3f89 | |||
4232842749 | |||
010fd76031 | |||
c50b222586 | |||
17f83bd9f2 | |||
10d7a4ed98 | |||
73e5be91eb | |||
07c4e5d50c | |||
e13ca55adf |
77
.github/workflows/codeql-analysis.yml
vendored
Normal file
77
.github/workflows/codeql-analysis.yml
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
# For most projects, this workflow file will not need changing; you simply need
|
||||
# to commit it to your repository.
|
||||
#
|
||||
# You may wish to alter this file to override the set of languages analyzed,
|
||||
# or to provide custom queries or build logic.
|
||||
#
|
||||
# ******** NOTE ********
|
||||
# We have attempted to detect the languages in your repository. Please check
|
||||
# the `language` matrix defined below to confirm you have the correct set of
|
||||
# supported CodeQL languages.
|
||||
#
|
||||
name: "CodeQL"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [ main ]
|
||||
schedule:
|
||||
- cron: '25 16 * * 4'
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [ 'java' ]
|
||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
||||
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v2
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
# By default, queries listed here will override any specified in a config file.
|
||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||
|
||||
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
|
||||
# queries: security-extended,security-and-quality
|
||||
|
||||
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v2
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
|
||||
|
||||
# If the Autobuild fails above, remove it and uncomment the following three lines.
|
||||
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
|
||||
|
||||
# - run: |
|
||||
# echo "Run, Build Application using script"
|
||||
# ./location_of_script_within_repo/buildscript.sh
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v2
|
||||
|
||||
- name: Codacy Coverage Reporter
|
||||
uses: codacy/codacy-coverage-reporter-action@v1.3.0
|
||||
|
||||
|
28
README.md
Normal file
28
README.md
Normal file
@ -0,0 +1,28 @@
|
||||
# <center>FeelingLucky Beta v1.0.2</center>
|
||||
|
||||
## <center><u><span style="color:blue">Plugin Description:</u></center>
|
||||
|
||||
### <center><u><span style="color:cyan">For All Users:</u></center>
|
||||
|
||||
<b>FeelingLucky</b> is a mechanics plugin designed to expand upon the Luck attribute which Minecraft provides.
|
||||
Each user is assigned a tangible Luck stat, which can be viewed by using <b><span style="color:violet">/luck info</color></b>.
|
||||
Users can <i>increase</i> their luck stat by using a rabbit's foot,
|
||||
or increase their luck and their luck multiplier by consuming a special rabbits foot purchased from a Butcher villager.
|
||||
<b><span style="color:red">Beware</b> though, if you take damage from guardian lasers or a witch's potion,
|
||||
there's a chance your luck will <i>decrease</i> instead.
|
||||
|
||||
### <center><u><span style="color:pink">For Administrators:</u></center>
|
||||
Admins can modify values in the configuration file, as well as modify individual user's luck stat.
|
||||
Admins can set, reset, add to, and take from player's luck stat.
|
||||
Admins can also reload the main configuration, as well as individual and all player configurations.
|
||||
For this, the command is <b><span style="color:violet">/luck reload -m</color></b> for the main config,
|
||||
<b><span style="color:violet">/luck reload</color></b> to reload all player configurations, and <b><span style="color:violet">/luck reload -p <i>PLAYER_NAME</i></span></b> to reload individual player configuration files.
|
||||
|
||||
## <center><u><span style="color:blue">Server Requirements:</u></center>
|
||||
|
||||
In order to run <b>FeelingLucky</b> v<b>1.1.0</b>, the latest version of Paper or Spigot is required.
|
||||
|
||||
#### <center><span style="color:red">Note: Paper is REQUIRED for this plugin to run. Spigot is not supported, and support for Spigot will not be added in the future.</center></span>
|
||||
|
||||
### <center>Note: If you are migrating from an Alpha build, the plugin configuration folder will need to be regenerated.</center>
|
||||
|
14
build.gradle
14
build.gradle
@ -3,22 +3,16 @@ plugins {
|
||||
}
|
||||
|
||||
group = 'io.github.simplex'
|
||||
version = 'Beta-1.0-RC01'
|
||||
version = '1.2.0-RC01'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
name = 'papermc-repo'
|
||||
url = 'https://papermc.io/repo/repository/maven-public/'
|
||||
}
|
||||
maven {
|
||||
name = 'sonatype'
|
||||
url = 'https://s01.oss.sonatype.org/content/groups/public/'
|
||||
}
|
||||
maven { url = uri("https://s01.oss.sonatype.org/content/groups/public/") }
|
||||
maven { url = uri("https://papermc.io/repo/repository/maven-public/")}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly 'io.papermc.paper:paper-api:1.18.1-R0.1-SNAPSHOT'
|
||||
compileOnly("io.papermc.paper:paper-api:1.19-R0.1-SNAPSHOT")
|
||||
}
|
||||
|
||||
def targetJavaVersion = 17
|
||||
|
@ -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);
|
||||
|
@ -5,6 +5,7 @@ import io.github.simplex.luck.player.PlayerConfig;
|
||||
import io.github.simplex.luck.player.PlayerHandler;
|
||||
import io.github.simplex.luck.util.LuckCMD;
|
||||
import io.github.simplex.luck.util.SneakyWorker;
|
||||
import io.github.simplex.luck.util.SpecialFootItem;
|
||||
import io.github.simplex.metrics.Metrics;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -18,6 +19,8 @@ import java.util.UUID;
|
||||
|
||||
public final class FeelingLucky extends JavaPlugin {
|
||||
private final Map<UUID, PlayerConfig> configMap = new HashMap<>();
|
||||
private final File playerDirectory = new File(getDataFolder(), "players");
|
||||
private final SpecialFootItem specialFootItem = new SpecialFootItem();
|
||||
|
||||
private PlayerHandler handler;
|
||||
private Config config;
|
||||
@ -55,11 +58,18 @@ public final class FeelingLucky extends JavaPlugin {
|
||||
}
|
||||
|
||||
private void loadPlayerConfigurations() {
|
||||
File[] files = getDataFolder().listFiles();
|
||||
if (!playerDirectory.exists()) {
|
||||
getLogger().info("No directory exists. Creating...");
|
||||
playerDirectory.mkdirs();
|
||||
getLogger().info("Created new directory \"FeelingLucky/players\".");
|
||||
return;
|
||||
}
|
||||
|
||||
File[] files = playerDirectory.listFiles();
|
||||
if (files != null) {
|
||||
Arrays.stream(files).forEach(file -> {
|
||||
UUID uuid = UUID.fromString(file.getName().split("\\.")[0]);
|
||||
configMap.put(uuid, PlayerConfig.loadFrom(this, file));
|
||||
configMap.put(uuid, PlayerConfig.initFrom(this, file));
|
||||
});
|
||||
configMap.forEach((u, pc) -> pc.load());
|
||||
getLogger().info("Successfully loaded all configurations!");
|
||||
@ -92,4 +102,8 @@ public final class FeelingLucky extends JavaPlugin {
|
||||
public Config getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public SpecialFootItem getFoot() {
|
||||
return specialFootItem;
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
package io.github.simplex.luck.listener;
|
||||
|
||||
import io.github.simplex.lib.MiniComponent;
|
||||
import io.github.simplex.luck.FeelingLucky;
|
||||
import io.github.simplex.luck.player.Luck;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
||||
public class GiveDamage extends AbstractListener {
|
||||
public GiveDamage(FeelingLucky plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerAttack(EntityDamageByEntityEvent e) {
|
||||
if ((e.getDamager() instanceof Player player)
|
||||
&& (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.getValue())) {
|
||||
e.setDamage(nextDmg);
|
||||
player.sendMessage(MiniComponent.info("Your luck has increased your damage output!"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
59
src/main/java/io/github/simplex/luck/listener/HideCheck.java
Normal file
59
src/main/java/io/github/simplex/luck/listener/HideCheck.java
Normal file
@ -0,0 +1,59 @@
|
||||
package io.github.simplex.luck.listener;
|
||||
|
||||
import io.github.simplex.lib.MiniComponent;
|
||||
import io.github.simplex.luck.FeelingLucky;
|
||||
import io.github.simplex.luck.player.Luck;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerToggleSneakEvent;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class HideCheck extends AbstractListener {
|
||||
public Map<Player, List<Entity>> entityMapList = new HashMap<>();
|
||||
|
||||
public HideCheck(FeelingLucky plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void initPlayerMaps(PlayerJoinEvent event) {
|
||||
entityMapList.put(event.getPlayer(), List.of());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void checkTargeting(EntityTargetLivingEntityEvent event) {
|
||||
if (event.getTarget() instanceof Player player) {
|
||||
if (event.getEntity() instanceof LivingEntity entity) {
|
||||
List<Entity> buffer = entityMapList.get(player).isEmpty() ?
|
||||
new ArrayList<>() : entityMapList.get(player);
|
||||
buffer.add(entity);
|
||||
entityMapList.replace(player, buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void checkForSneak(PlayerToggleSneakEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (!player.isSneaking()) return;
|
||||
|
||||
Luck luck = plugin.getHandler().getLuckContainer(player);
|
||||
if (luck.quickRNG(luck.getValue()) && !luck.isMarked(player)) {
|
||||
entityMapList.get(player).forEach(e -> {
|
||||
e.getTrackedPlayers().remove(player);
|
||||
});
|
||||
player.sendMessage(MiniComponent.info("Your luck has hidden you from sight."));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void removePlayerOnLeave(PlayerQuitEvent event) {
|
||||
entityMapList.remove(event.getPlayer());
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
26
src/main/java/io/github/simplex/luck/listener/JumpBoost.java
Normal file
26
src/main/java/io/github/simplex/luck/listener/JumpBoost.java
Normal file
@ -0,0 +1,26 @@
|
||||
package io.github.simplex.luck.listener;
|
||||
|
||||
import com.destroystokyo.paper.event.player.PlayerJumpEvent;
|
||||
import io.github.simplex.lib.MiniComponent;
|
||||
import io.github.simplex.luck.FeelingLucky;
|
||||
import io.github.simplex.luck.player.Luck;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class JumpBoost extends AbstractListener {
|
||||
public JumpBoost(FeelingLucky plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void detectJumping(PlayerJumpEvent event) {
|
||||
Player player = event.getPlayer(); // Player is never null; they're in game and jumping.
|
||||
Luck luck = plugin.getHandler().getLuckContainer(player);
|
||||
|
||||
if (luck.quickRNG(luck.getValue()) && !luck.isMarked(player)) {
|
||||
player.setVelocity(new Vector(0, 2, 0));
|
||||
player.sendMessage(MiniComponent.info("Your luck has boosted your jump height!"));
|
||||
}
|
||||
}
|
||||
}
|
51
src/main/java/io/github/simplex/luck/listener/OreVein.java
Normal file
51
src/main/java/io/github/simplex/luck/listener/OreVein.java
Normal file
@ -0,0 +1,51 @@
|
||||
package io.github.simplex.luck.listener;
|
||||
|
||||
import io.github.simplex.lib.MiniComponent;
|
||||
import io.github.simplex.luck.FeelingLucky;
|
||||
import io.github.simplex.luck.player.Luck;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class OreVein extends AbstractListener {
|
||||
|
||||
public OreVein(FeelingLucky plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerMine(BlockBreakEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Luck luck = plugin.getHandler().getLuckContainer(player);
|
||||
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."));
|
||||
}
|
||||
}
|
||||
|
||||
public Stream<Block> getOresInArea(Block block) {
|
||||
Stream.Builder<Block> streamBuilder = Stream.builder();
|
||||
Location start = block.getLocation();
|
||||
World world = block.getWorld();
|
||||
Stream<Tag<Material>> materialStream = Stream.of(Tag.COAL_ORES, Tag.COPPER_ORES, Tag.DIAMOND_ORES, Tag.GOLD_ORES, Tag.IRON_ORES, Tag.EMERALD_ORES, Tag.LAPIS_ORES, Tag.REDSTONE_ORES);
|
||||
for (int x = start.getBlockX() - 15; x <= start.getBlockX() + 15; x++) {
|
||||
for (int y = start.getBlockY() - 15; y <= start.getBlockY() + 15; y++) {
|
||||
for (int z = start.getBlockZ() - 15; z <= start.getBlockZ() + 15; z++) {
|
||||
Location location = new Location(world, x, y, z);
|
||||
Material blockType = location.getBlock().getType();
|
||||
if (materialStream.anyMatch(o -> o.isTagged(blockType))) {
|
||||
streamBuilder.add(location.getBlock());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return streamBuilder.build().filter(b -> b.getType().equals(block.getType()));
|
||||
}
|
||||
}
|
@ -31,7 +31,7 @@ public final class PlayerListener extends AbstractListener {
|
||||
public void rabbitFoot(PlayerInteractEvent event) {
|
||||
Action action = event.getAction();
|
||||
ItemStack foot = new ItemStack(Material.RABBIT_FOOT);
|
||||
SpecialFootItem special = new SpecialFootItem();
|
||||
SpecialFootItem special = plugin.getFoot();
|
||||
Player player = event.getPlayer();
|
||||
Luck luck = getHandler().getLuckContainer(player);
|
||||
|
||||
@ -41,10 +41,10 @@ public final class PlayerListener extends AbstractListener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.isRightClick() && player.getInventory().getItemInMainHand().isSimilar(foot)) {
|
||||
if (action.isRightClick() && player.getInventory().getItemInMainHand().getType().equals(foot.getType())) {
|
||||
if (foot.getItemMeta().equals(special.meta()) || foot.equals(special.get())) {
|
||||
luck.setMultiplier(luck.multiplier() + 1);
|
||||
player.sendMessage(MiniComponent.info("Your luck multiplier has increased by 1!"));
|
||||
luck.setMultiplier(luck.multiplier() + 0.1);
|
||||
player.sendMessage(MiniComponent.info("Your luck multiplier has increased by 0.1!"));
|
||||
}
|
||||
double rng = Luck.RNG().nextDouble(2.0, 5.0);
|
||||
player.getInventory().remove(player.getInventory().getItemInMainHand());
|
||||
@ -78,24 +78,4 @@ public final class PlayerListener extends AbstractListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) return true;
|
||||
if (obj == null || obj.getClass() != this.getClass()) return false;
|
||||
var that = (PlayerListener) obj;
|
||||
return Objects.equals(this.plugin, that.plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PlayerListener[" +
|
||||
"plugin=" + plugin + ']';
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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."));
|
||||
}
|
||||
|
@ -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)) {
|
||||
|
@ -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",
|
||||
|
@ -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);
|
||||
|
@ -15,12 +15,14 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class VillagerInventory extends AbstractListener {
|
||||
private final SpecialFootItem foot = new SpecialFootItem();
|
||||
private final MerchantRecipe recipe = new MerchantRecipe(foot.get(), 0, 2, true);
|
||||
private final MerchantRecipe recipe;
|
||||
|
||||
public VillagerInventory(FeelingLucky plugin) {
|
||||
super(plugin);
|
||||
|
||||
SpecialFootItem foot = plugin.getFoot();
|
||||
this.recipe = new MerchantRecipe(foot.get(), 0, 2, true);
|
||||
|
||||
recipe.setIngredients(Arrays.asList(
|
||||
ItemBuilder.of(Material.EMERALD).build(),
|
||||
ItemBuilder.of(Material.RABBIT_HIDE).build()
|
||||
@ -42,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);
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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(() -> {
|
||||
@ -64,7 +64,7 @@ public class PlayerConfig {
|
||||
}
|
||||
|
||||
@Contract("_, _ -> new")
|
||||
public static PlayerConfig loadFrom(FeelingLucky plugin, File file) {
|
||||
public static PlayerConfig initFrom(FeelingLucky plugin, File file) {
|
||||
return new PlayerConfig(plugin, file);
|
||||
}
|
||||
|
||||
|
@ -6,10 +6,7 @@ import io.github.simplex.luck.FeelingLucky;
|
||||
import io.github.simplex.luck.player.Luck;
|
||||
import io.github.simplex.luck.player.PlayerConfig;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -18,14 +15,14 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class LuckCMD extends Command implements TabCompleter {
|
||||
public class LuckCMD extends Command implements TabCompleter, PluginIdentifiableCommand {
|
||||
private final FeelingLucky plugin;
|
||||
|
||||
public LuckCMD(FeelingLucky plugin) {
|
||||
super("luck", "FeelingLucky main command.", "/<command> <info | set | reset | give | take> [player] [amount]", List.of());
|
||||
this.plugin = plugin;
|
||||
setPermission("luck.default");
|
||||
plugin.getServer().getCommandMap().register("luck", "FeelingLucky", this);
|
||||
register(plugin.getServer().getCommandMap());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -145,7 +142,7 @@ public class LuckCMD extends Command implements TabCompleter {
|
||||
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) {
|
||||
@ -200,4 +197,9 @@ public class LuckCMD extends Command implements TabCompleter {
|
||||
|
||||
return completions.stream().filter(n -> n.startsWith(args[0])).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull FeelingLucky getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package io.github.simplex.luck.util;
|
||||
|
||||
import io.github.simplex.luck.listener.AbstractListener;
|
||||
import io.github.simplex.luck.player.Luck;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Item;
|
||||
@ -33,7 +32,7 @@ public class SneakyWorker {
|
||||
}
|
||||
}
|
||||
|
||||
public static Class[] getClasses(String packageName) throws ClassNotFoundException, IOException {
|
||||
public static Class<?>[] getClasses(String packageName) throws ClassNotFoundException, IOException {
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
assert classLoader != null;
|
||||
String path = packageName.replace(".", "/");
|
||||
@ -43,11 +42,11 @@ public class SneakyWorker {
|
||||
URL resource = resources.nextElement();
|
||||
dirs.add(new File(resource.getFile()));
|
||||
}
|
||||
ArrayList<Class> classes = new ArrayList<>();
|
||||
ArrayList<Class<?>> classes = new ArrayList<>();
|
||||
for (File directory : dirs) {
|
||||
classes.addAll(findClasses(directory, packageName));
|
||||
}
|
||||
return classes.toArray(new Class[classes.size()]);
|
||||
return classes.toArray(new Class<?>[0]);
|
||||
}
|
||||
|
||||
private static List<Class<?>> findClasses(File directory, String packageName) throws ClassNotFoundException {
|
||||
|
@ -12,7 +12,7 @@ public class SpecialFootItem {
|
||||
stack = ItemBuilder.of(Material.RABBIT_FOOT)
|
||||
.setName("Enhanced Rabbit Foot")
|
||||
.setAmount(1).setLore("A strange energy radiates from within.",
|
||||
"This item will increase your luck multiplier by one.")
|
||||
"This item will increase your luck multiplier by 0.1.")
|
||||
.build();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user