mirror of
https://github.com/SimplexDevelopment/FeelingLucky.git
synced 2025-07-04 11:06:43 +00:00
Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
661b7bd6a7 | |||
639bf09e48 | |||
8b3486a269 | |||
94b6067f97 | |||
0b07bd9da2 | |||
400687733f | |||
c7a168ede1 |
32
.github/workflows/codacy-analysis.yml
vendored
Normal file
32
.github/workflows/codacy-analysis.yml
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
name: Codacy Security Scan
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "master", "main" ]
|
||||
pull_request:
|
||||
branches: [ "master", "main" ]
|
||||
|
||||
jobs:
|
||||
codacy-security-scan:
|
||||
name: Codacy Security Scan
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@main
|
||||
|
||||
- name: Run Codacy Analysis CLI
|
||||
uses: codacy/codacy-analysis-cli-action@master
|
||||
with:
|
||||
output: results.sarif
|
||||
format: sarif
|
||||
# Adjust severity of non-security issues
|
||||
gh-code-scanning-compat: true
|
||||
# Force 0 exit code to allow SARIF file generation
|
||||
# This will handover control about PR rejection to the GitHub side
|
||||
max-allowed-issues: 2147483647
|
||||
|
||||
# Upload the SARIF file generated in the previous step
|
||||
- name: Upload SARIF results file
|
||||
uses: github/codeql-action/upload-sarif@main
|
||||
with:
|
||||
sarif_file: results.sarif
|
@ -1,4 +1,4 @@
|
||||
# <center>FeelingLucky v1.2.0</center>
|
||||
# <center>FeelingLucky v1.2.0 - A luck driven mechanics plugin.</center>
|
||||
|
||||
## <center><u><span style="color:blue">Plugin Description:</u></center>
|
||||
|
||||
@ -17,12 +17,13 @@ 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.
|
||||
Server owners and/or individuals with console access can run /rgc to regenerate the main configuration file in the case that there are values missing, corrupted, or invalid.
|
||||
|
||||
## <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><span style="color:red">Note: Paper is REQUIRED for this plugin to run. Spigot is not supported, however Spigot support is currently in progress.</center></span>
|
||||
|
||||
### <center>Note: If you are migrating from an Alpha build, the plugin configuration folder will need to be regenerated.</center>
|
||||
|
||||
|
@ -3,7 +3,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = 'io.github.simplex'
|
||||
version = '1.2.0'
|
||||
version = '1.2.1'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
@ -4,10 +4,16 @@ import io.github.simplex.api.LuckContainer;
|
||||
import io.github.simplex.luck.FeelingLucky;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public class Luck implements LuckContainer {
|
||||
@ -34,10 +40,16 @@ public class Luck implements LuckContainer {
|
||||
event = new PlayerLuckChangeEvent(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* This creates a new instance of a pseudorandom number generator based off entropy provided by the operating system.
|
||||
* This will allow for a much purer randomization, due to entropy being different for each call.
|
||||
*
|
||||
* @return A new instance of SecureRandom. Each time this method is called a new instance is created to provide maximum variation with entropic calculations.
|
||||
*/
|
||||
@Contract(pure = true,
|
||||
value = "-> new")
|
||||
public static @NotNull SplittableRandom RNG() {
|
||||
return new SplittableRandom();
|
||||
public static @NotNull SecureRandom RNG() {
|
||||
return new SecureRandom(SecureRandom.getSeed(20));
|
||||
}
|
||||
|
||||
public static boolean quickRNGnoMultiplier(double value) {
|
||||
@ -53,6 +65,10 @@ public class Luck implements LuckContainer {
|
||||
return (value >= actual);
|
||||
}
|
||||
|
||||
public boolean playerHasLuckPE() {
|
||||
return player.hasPotionEffect(PotionEffectType.LUCK);
|
||||
}
|
||||
|
||||
public FeelingLucky getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
@ -89,6 +105,12 @@ public class Luck implements LuckContainer {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Quickly calculate whether or not the player has enough luck to trigger the condition.
|
||||
*
|
||||
* @param value The players luck value.
|
||||
* @return True if the player meets the criteria, false if they do not.
|
||||
*/
|
||||
public boolean quickRNG(double value) {
|
||||
double rng;
|
||||
if (value >= 1024.0) {
|
||||
@ -97,13 +119,19 @@ public class Luck implements LuckContainer {
|
||||
rng = RNG().nextDouble(0.0, 1024.0);
|
||||
}
|
||||
|
||||
AtomicReference<Double> multiplier = new AtomicReference<>(multiplier());
|
||||
double actual = Math.round((rng / 1024) * 100);
|
||||
double newVal = Math.round((value / 1024) * 100);
|
||||
|
||||
if (multiplier() > 1.0) {
|
||||
return ((value * multiplier()) >= actual);
|
||||
if (playerHasLuckPE()) {
|
||||
player.getActivePotionEffects()
|
||||
.stream()
|
||||
.filter(p -> p.getType().equals(PotionEffectType.LUCK))
|
||||
.findFirst()
|
||||
.ifPresent(p -> multiplier.updateAndGet(v -> (v + p.getAmplifier())));
|
||||
}
|
||||
|
||||
return (value >= actual);
|
||||
return ((newVal * multiplier.get()) >= actual);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
|
Reference in New Issue
Block a user