mirror of
https://github.com/SimplexDevelopment/FeelingLucky.git
synced 2024-11-22 01:45:02 +00:00
[Beta] SNAPSHOT {Bug Fix} - Patch 0001
Changelog: - Fixed an issue where the integrity checker for the main config would delete the entire data folder if the config was corrupted. - Fixed an issue where the Rarity check was not working as intended; it would either return false if any Rarity other than NONE was set, and throw a new IllegalArgumentException if the switch clause exited with no return value. - Fixed an issue where the command /luck reload -m did absolutely nothing. - Fixed an issue where the proper command arguments were not being Tab Completed.
This commit is contained in:
parent
330fd278b7
commit
0488e1d6b1
@ -3,7 +3,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = 'io.github.simplex'
|
||||
version = 'Alpha-1.0'
|
||||
version = 'Beta-20220422-SNAPSHOT'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
@ -1,6 +1,5 @@
|
||||
package io.github.simplex.luck;
|
||||
|
||||
import io.github.simplex.lib.MiniComponent;
|
||||
import io.github.simplex.luck.listener.AbstractListener;
|
||||
import io.github.simplex.luck.util.SneakyWorker;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
@ -9,11 +8,26 @@ import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
public class Config extends YamlConfiguration {
|
||||
private final FeelingLucky plugin;
|
||||
private final List<String> configEntries = new ArrayList<>() {{
|
||||
add("high_rarity_chance");
|
||||
add("medium_rarity_chance");
|
||||
add("low_rarity_chance");
|
||||
add("block_drops");
|
||||
add("bonemeal");
|
||||
add("cheat_death");
|
||||
add("enchanting");
|
||||
add("experience");
|
||||
add("item_drops");
|
||||
add("random_effect");
|
||||
add("restore_hunger");
|
||||
add("take_damage");
|
||||
add("unbreakable");
|
||||
}};
|
||||
private File configFile;
|
||||
|
||||
public Config(FeelingLucky plugin) {
|
||||
@ -33,7 +47,7 @@ public class Config extends YamlConfiguration {
|
||||
if (validateIntegrity()) {
|
||||
File newFile = new File(plugin.getDataFolder(), "config.yml");
|
||||
SneakyWorker.sneakyTry(() -> {
|
||||
Files.delete(Path.of(plugin.getDataFolder().getPath()));
|
||||
Files.delete(Path.of(this.configFile.getPath()));
|
||||
newFile.createNewFile();
|
||||
plugin.saveResource("config.yml", true);
|
||||
});
|
||||
@ -72,20 +86,4 @@ public class Config extends YamlConfiguration {
|
||||
public double getChance(String path) {
|
||||
return getDouble(path);
|
||||
}
|
||||
|
||||
private List<String> configEntries = new ArrayList<>() {{
|
||||
add("high_rarity_chance");
|
||||
add("medium_rarity_chance");
|
||||
add("low_rarity_chance");
|
||||
add("block_drops");
|
||||
add("bonemeal");
|
||||
add("cheat_death");
|
||||
add("enchanting");
|
||||
add("experience");
|
||||
add("item_drops");
|
||||
add("random_effect");
|
||||
add("restore_hunger");
|
||||
add("take_damage");
|
||||
add("unbreakable");
|
||||
}};
|
||||
}
|
||||
|
@ -5,12 +5,8 @@ import io.github.simplex.luck.FeelingLucky;
|
||||
import io.github.simplex.luck.player.PlayerHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class AbstractListener implements Listener {
|
||||
protected final FeelingLucky plugin;
|
||||
protected final Map<AbstractListener, Rarity> listenerRarityMap = new HashMap<>();
|
||||
protected final Config config;
|
||||
|
||||
public AbstractListener(FeelingLucky plugin) {
|
||||
@ -23,24 +19,19 @@ public abstract class AbstractListener implements Listener {
|
||||
return plugin.getHandler();
|
||||
}
|
||||
|
||||
public boolean doesQualify(String name, double luck) {
|
||||
return switch (config.getRarity(name)) {
|
||||
case HIGH -> luck > config.getChance("high_rarity_chance");
|
||||
case MED -> luck > config.getChance("medium_rarity_chance");
|
||||
case LOW -> luck > config.getChance("low_rarity_chance");
|
||||
case NONE -> true;
|
||||
};
|
||||
}
|
||||
|
||||
public enum Rarity {
|
||||
HIGH,
|
||||
MED,
|
||||
LOW,
|
||||
NONE
|
||||
}
|
||||
|
||||
public boolean doesQualify(String name, double luck) {
|
||||
switch (config.getRarity(name)) {
|
||||
case HIGH:
|
||||
if (luck < config.getChance("high_rarity_chance")) return false;
|
||||
case MED:
|
||||
if (luck < config.getChance("medium_rarity_chance")) return false;
|
||||
case LOW:
|
||||
if (luck < config.getChance("low_rarity_chance")) return false;
|
||||
case NONE:
|
||||
return true;
|
||||
}
|
||||
throw new IllegalArgumentException("The value for the listener rarity is not a recognized rarity value.");
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,10 @@ package io.github.simplex.luck.listener;
|
||||
|
||||
import io.github.simplex.luck.FeelingLucky;
|
||||
import io.github.simplex.luck.player.Luck;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
|
@ -5,15 +5,12 @@ import io.github.simplex.luck.FeelingLucky;
|
||||
import io.github.simplex.luck.player.Luck;
|
||||
import io.github.simplex.luck.util.CooldownTimer;
|
||||
import io.github.simplex.luck.util.SpecialFootItem;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Guardian;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Witch;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
|
@ -7,7 +7,6 @@ import io.github.simplex.luck.util.SpecialFootItem;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
package io.github.simplex.luck.util;
|
||||
|
||||
import io.github.simplex.lib.MiniComponent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -10,9 +8,8 @@ import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class CooldownTimer {
|
||||
private final Map<UUID, Long> cooldowns = new HashMap<>();
|
||||
|
||||
public static final long DEFAULT_COOLDOWN = 30L;
|
||||
private final Map<UUID, Long> cooldowns = new HashMap<>();
|
||||
|
||||
public void setCooldown(UUID playerUUID, long time) {
|
||||
if (time < 1) {
|
||||
|
@ -95,7 +95,9 @@ public class LuckCMD extends Command implements TabCompleter {
|
||||
if (args.length == 2) {
|
||||
if ((sender instanceof ConsoleCommandSender) || sender.hasPermission("luck.admin")) {
|
||||
if (args[0].equalsIgnoreCase("reload") && args[1].equalsIgnoreCase("-m")) {
|
||||
|
||||
plugin.getConfig().reload();
|
||||
sender.sendMessage(MiniComponent.info("Configuration successfully reloaded."));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("info")) {
|
||||
@ -163,23 +165,22 @@ public class LuckCMD extends Command implements TabCompleter {
|
||||
List<String> playerNames = new ArrayList<>() {{
|
||||
Bukkit.getOnlinePlayers().forEach(p -> add(p.getName()));
|
||||
}};
|
||||
List<String> adminCommands = List.of("set", "reset", "give", "take");
|
||||
List<String> adminCommands = List.of("set", "reset", "give", "take", "reload");
|
||||
|
||||
if ((sender instanceof ConsoleCommandSender) || sender.hasPermission("luck.admin")) {
|
||||
completions.addAll(adminCommands);
|
||||
return completions;
|
||||
return completions.stream().filter(n -> n.startsWith(args[0])).toList();
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("info") && sender.hasPermission("luck.admin")) {
|
||||
return playerNames;
|
||||
}
|
||||
|
||||
if (completions.contains(args[1]) && sender.hasPermission("luck.admin")) {
|
||||
if (adminCommands.contains(args[0])
|
||||
&& sender.hasPermission("luck.admin")
|
||||
&& (args.length == 2)) {
|
||||
switch (args[0]) {
|
||||
case "info":
|
||||
case "reset":
|
||||
return playerNames.stream().filter(n -> n.startsWith(args[1])).toList();
|
||||
case "reload":
|
||||
return new ArrayList<>();
|
||||
return List.of("-m", "-p");
|
||||
case "give":
|
||||
case "take":
|
||||
case "set":
|
||||
@ -187,6 +188,12 @@ public class LuckCMD extends Command implements TabCompleter {
|
||||
}
|
||||
}
|
||||
|
||||
return completions;
|
||||
if (args[0].equalsIgnoreCase("reload")
|
||||
&& args[1].equalsIgnoreCase("-p")
|
||||
&& sender.hasPermission("luck.admin") && (args.length == 3)) {
|
||||
return playerNames.stream().filter(n -> n.startsWith(args[2])).toList();
|
||||
}
|
||||
|
||||
return completions.stream().filter(n -> n.startsWith(args[0])).toList();
|
||||
}
|
||||
}
|
||||
|
@ -4,9 +4,9 @@
|
||||
# These values must be in the form of doubles, as listed below.
|
||||
# The maximum amount of luck that can be attributed is 1024.0, and the minimum is -1024.0
|
||||
|
||||
high_rarity_chance: 512
|
||||
medium_rarity_chance: 128
|
||||
low_rarity_chance: 64
|
||||
high_rarity_chance: 512.0
|
||||
medium_rarity_chance: 128.0
|
||||
low_rarity_chance: 64.0
|
||||
|
||||
# The following entries are for the rarity level of each event trigger.
|
||||
# This will determine which rarity chance to use which ensures players
|
||||
|
Loading…
Reference in New Issue
Block a user