Beta 20220422-SNAPSHOT

Changelog:
 - Added a configuration with editable rarity values and rarity types for the different events that can occur, to give the end user more control over how often players receive the effects.
- Modified listeners to use the respective Configuration values.
- Added the ability to reload a specific player configuration with /luck reload -p <player_name>
- Added the ability to reload the main configuration using /luck reload -m
- Added an integrity checker to validate the main configuration on boot.
This commit is contained in:
Paldiu 2022-04-22 19:25:02 -05:00
parent 6119180b0b
commit 330fd278b7
18 changed files with 280 additions and 93 deletions

View File

@ -0,0 +1,91 @@
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;
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;
public class Config extends YamlConfiguration {
private final FeelingLucky plugin;
private File configFile;
public Config(FeelingLucky plugin) {
this.plugin = plugin;
File dataFolder = plugin.getDataFolder();
if (!dataFolder.exists()) dataFolder.mkdirs();
File configFile = new File(dataFolder, "config.yml");
if (!configFile.exists()) {
SneakyWorker.sneakyTry(configFile::createNewFile);
plugin.saveResource("config.yml", true);
}
this.configFile = configFile;
load();
if (validateIntegrity()) {
File newFile = new File(plugin.getDataFolder(), "config.yml");
SneakyWorker.sneakyTry(() -> {
Files.delete(Path.of(plugin.getDataFolder().getPath()));
newFile.createNewFile();
plugin.saveResource("config.yml", true);
});
this.configFile = newFile;
load();
}
}
public void save() {
SneakyWorker.sneakyTry(() -> save(configFile));
}
public void load() {
SneakyWorker.sneakyTry(() -> load(configFile));
}
public void reload() {
save();
load();
}
public boolean validateIntegrity() {
for (String key : getKeys(false)) {
if (!configEntries.contains(key)) {
plugin.getLogger().severe("The contents of your configuration file is corrupted! Regenerating a new configuration file...");
return true;
}
}
return false;
}
public AbstractListener.Rarity getRarity(String name) {
return AbstractListener.Rarity.valueOf(getString(name));
}
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");
}};
}

View File

@ -3,10 +3,9 @@ package io.github.simplex.luck;
import io.github.simplex.luck.listener.*;
import io.github.simplex.luck.player.PlayerConfig;
import io.github.simplex.luck.player.PlayerHandler;
import io.github.simplex.luck.util.CooldownTimer;
import io.github.simplex.luck.util.LuckCMD;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.util.Arrays;
@ -18,6 +17,7 @@ public final class FeelingLucky extends JavaPlugin {
private final Map<UUID, PlayerConfig> configMap = new HashMap<>();
private PlayerHandler handler;
private Config config;
public Map<UUID, PlayerConfig> getConfigMap() {
return configMap;
@ -30,21 +30,26 @@ public final class FeelingLucky extends JavaPlugin {
getLogger().info("Initialization complete! Attempting to register the Listeners...");
registerListeners();
getLogger().info("Registration complete! Attempting to load all player configuration files...");
loadConfigurations();
Bukkit.getLogger().info("Attempting to load the Luck command...");
loadPlayerConfigurations();
getLogger().info("Attempting to load the main configuration...");
config = new Config(this);
getLogger().info("Main Config loaded successfully! Attempting to load the Luck command...");
new LuckCMD(this);
Bukkit.getLogger().info("Successfully loaded the Luck command!");
getLogger().info("Successfully loaded the Luck command!");
Bukkit.getLogger().info("Successfully initialized!");
getLogger().info("Successfully initialized!");
}
@Override
public void onDisable() {
Bukkit.getLogger().info("Saving all player configurations...");
getLogger().info("Saving all player configurations...");
configMap.values().forEach(PlayerConfig::save);
getLogger().info("Complete! Saving the main config...");
config.save();
getLogger().info("Complete! Goodbye! :)");
}
private void loadConfigurations() {
private void loadPlayerConfigurations() {
File[] files = getDataFolder().listFiles();
if (files != null) {
Arrays.stream(files).forEach(file -> {
@ -76,4 +81,10 @@ public final class FeelingLucky extends JavaPlugin {
public PlayerHandler getHandler() {
return handler;
}
@Override
@NotNull
public Config getConfig() {
return config;
}
}

View File

@ -0,0 +1,46 @@
package io.github.simplex.luck.listener;
import io.github.simplex.luck.Config;
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) {
this.plugin = plugin;
this.config = plugin.getConfig();
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
protected PlayerHandler getHandler() {
return plugin.getHandler();
}
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.");
}
}

View File

@ -6,22 +6,21 @@ import io.github.simplex.luck.util.SneakyWorker;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockDropItemEvent;
import java.util.List;
public record BlockDrops(FeelingLucky plugin) implements Listener {
public BlockDrops {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
public final class BlockDrops extends AbstractListener {
public BlockDrops(FeelingLucky plugin) {
super(plugin);
}
@EventHandler
public void extraBlockDrops(BlockDropItemEvent event) {
Player player = event.getPlayer();
Luck luck = plugin.getHandler().getLuckContainer(player);
Luck luck = getHandler().getLuckContainer(player);
List<Item> items = event.getItems();
if (luck.quickRNG(luck.getPercentage())) {
if (luck.quickRNG(luck.getPercentage()) && doesQualify("block_drops", luck.getPercentage())) {
items.forEach(SneakyWorker::move);
}
}

View File

@ -10,14 +10,13 @@ import org.bukkit.block.data.Ageable;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
public record BonemealFullCrop(FeelingLucky plugin) implements Listener {
public BonemealFullCrop {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
public final class BonemealFullCrop extends AbstractListener {
public BonemealFullCrop(FeelingLucky plugin) {
super(plugin);
}
@EventHandler
@ -25,7 +24,7 @@ public record BonemealFullCrop(FeelingLucky plugin) implements Listener {
Player player = event.getPlayer();
Action action = event.getAction();
ItemStack bonemeal = ItemBuilder.of(Material.BONE_MEAL).build();
Luck luck = plugin.getHandler().getLuckContainer(player);
Luck luck = getHandler().getLuckContainer(player);
ItemStack handItem = event.getItem();
if (handItem == null) return;
@ -38,12 +37,12 @@ public record BonemealFullCrop(FeelingLucky plugin) implements Listener {
if (action.isRightClick()
&& handItem.isSimilar(bonemeal)
&& (data instanceof Ageable crop)
&& luck.quickRNG(luck.getPercentage())) {
&& luck.quickRNG(luck.getPercentage())
&& doesQualify("bonemeal", luck.getPercentage())) {
crop.setAge(crop.getMaximumAge());
data.merge(crop);
block.setBlockData(data);
player.sendMessage(MiniComponent.info("You got lucky and your crops grew to maturity."));
}
}
}

View File

@ -5,26 +5,23 @@ 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.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
public record CheatDeath(FeelingLucky plugin) implements Listener {
public final class CheatDeath extends AbstractListener {
public CheatDeath(FeelingLucky plugin) {
this.plugin = plugin;
plugin.getServer().getPluginManager().registerEvents(this, plugin);
super(plugin);
}
@EventHandler
public void cheatDeath(PlayerDeathEvent event) {
Player player = event.getPlayer();
Luck luck = plugin.getHandler().getLuckContainer(player);
Luck luck = getHandler().getLuckContainer(player);
double absorption = Math.round(Luck.RNG().nextDouble(5.0, 10.0));
if (luck.quickRNG(luck.getPercentage())) {
if (luck.quickRNG(luck.getPercentage()) && doesQualify("cheat_death", luck.getPercentage())) {
event.setCancelled(true);
player.setHealth(1.0);
player.setAbsorptionAmount(absorption);
player.sendMessage(MiniComponent.of("You got lucky and cheated death!").send());
}
}
}

View File

@ -5,16 +5,14 @@ import io.github.simplex.luck.player.Luck;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.enchantment.EnchantItemEvent;
import java.util.List;
import java.util.Map;
public record EnchantmentBoost(FeelingLucky plugin) implements Listener {
public final class EnchantmentBoost extends AbstractListener {
public EnchantmentBoost(FeelingLucky plugin) {
this.plugin = plugin;
plugin.getServer().getPluginManager().registerEvents(this, plugin);
super(plugin);
}
@EventHandler
@ -22,8 +20,8 @@ public record EnchantmentBoost(FeelingLucky plugin) implements Listener {
Map<Enchantment, Integer> enchMap = event.getEnchantsToAdd();
List<Enchantment> enchList = enchMap.keySet().stream().toList();
Player player = event.getEnchanter();
Luck luck = plugin.getHandler().getLuckContainer(player);
if (luck.quickRNG(luck.getPercentage())) {
Luck luck = getHandler().getLuckContainer(player);
if (luck.quickRNG(luck.getPercentage()) && doesQualify("enchanting", luck.getPercentage())) {
Enchantment particular = enchList.get(Luck.RNG().nextInt(enchList.size()));
int rng = Luck.RNG().nextInt(1, 5);
@ -34,4 +32,8 @@ public record EnchantmentBoost(FeelingLucky plugin) implements Listener {
enchMap.replace(particular, enchMap.get(particular) + rng);
}
}
public FeelingLucky plugin() {
return plugin;
}
}

View File

@ -6,12 +6,10 @@ import io.github.simplex.luck.player.Luck;
import org.bukkit.entity.ExperienceOrb;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public record ExpBoost(FeelingLucky plugin) implements Listener {
public final class ExpBoost extends AbstractListener {
public ExpBoost(FeelingLucky plugin) {
this.plugin = plugin;
plugin.getServer().getPluginManager().registerEvents(this, plugin);
super(plugin);
}
@EventHandler
@ -22,7 +20,7 @@ public record ExpBoost(FeelingLucky plugin) implements Listener {
int rounded = Math.round(math);
Player player = event.getPlayer();
Luck luck = plugin.getHandler().getLuckContainer(player);
if (luck.quickRNG(luck.getPercentage())) {
if (luck.quickRNG(luck.getPercentage()) && doesQualify("experience", luck.getPercentage())) {
orb.setExperience(rounded);
}
}

View File

@ -5,23 +5,22 @@ 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.event.Listener;
import org.bukkit.event.entity.EntityPotionEffectEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
public record IllOmen(FeelingLucky plugin) implements Listener {
public IllOmen {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
public class IllOmen extends AbstractListener {
public IllOmen(FeelingLucky plugin) {
super(plugin);
}
@EventHandler
public void reconnectCheck(PlayerJoinEvent event) {
Player player = event.getPlayer();
PotionEffectType type = PotionEffectType.BAD_OMEN;
Luck luck = plugin.getHandler().getLuckContainer(player);
Luck luck = getHandler().getLuckContainer(player);
if (player.hasPotionEffect(type)) {
luck.cache();

View File

@ -7,8 +7,8 @@ import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityDropItemEvent;
import org.bukkit.inventory.ItemStack;
@ -16,13 +16,12 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class ItemDrops implements Listener {
public class ItemDrops extends AbstractListener {
private final Map<UUID, Player> entityPlayerMap = new HashMap<>();
private final FeelingLucky plugin;
private boolean canAffect = false;
public ItemDrops(FeelingLucky plugin) {
this.plugin = plugin;
plugin.getServer().getPluginManager().registerEvents(this, plugin);
super(plugin);
}
@EventHandler
@ -39,16 +38,17 @@ public class ItemDrops implements Listener {
return;
}
if (entity instanceof Witch witch) {
if (Luck.quickRNGnoMultiplier(33.0)) {
Location location = witch.getLocation();
World world = location.getWorld();
Item item = world.dropItemNaturally(location, new ItemStack(Material.RABBIT_FOOT, 1));
new EntityDropItemEvent(witch, item).callEvent();
}
entityPlayerMap.put(entity.getUniqueId(), player);
}
@EventHandler
public void checkForDroppedItems(EntityDeathEvent event) {
if (event.getEntity() instanceof Player) {
canAffect = false;
return;
}
entityPlayerMap.put(entity.getUniqueId(), player);
canAffect = event.getDrops().isEmpty();
}
@EventHandler
@ -57,12 +57,14 @@ public class ItemDrops implements Listener {
if (entityPlayerMap.get(entity.getUniqueId()) == null) return;
if (!canAffect) return;
Player player = entityPlayerMap.get(entity.getUniqueId());
Luck luck = plugin.getHandler().getLuckContainer(player);
Luck luck = getHandler().getLuckContainer(player);
Item item = event.getItemDrop();
ItemStack stack = item.getItemStack();
int amount = stack.getAmount();
if (luck.quickRNG(luck.getPercentage())) {
if (luck.quickRNG(luck.getPercentage()) && doesQualify("item_drops", luck.getPercentage())) {
int rng = Luck.RNG().nextInt(2, 5);
amount += rng;
stack.setAmount(amount);

View File

@ -22,14 +22,12 @@ import org.bukkit.inventory.ItemStack;
import java.util.Objects;
public final class PlayerListener implements Listener {
private final FeelingLucky plugin;
public final class PlayerListener extends AbstractListener {
private final CooldownTimer timer;
public PlayerListener(FeelingLucky plugin) {
this.plugin = plugin;
super(plugin);
this.timer = new CooldownTimer();
Bukkit.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler
@ -38,7 +36,7 @@ public final class PlayerListener implements Listener {
ItemStack foot = new ItemStack(Material.RABBIT_FOOT);
SpecialFootItem special = new SpecialFootItem();
Player player = event.getPlayer();
Luck luck = plugin.getHandler().getLuckContainer(player);
Luck luck = getHandler().getLuckContainer(player);
if (timer.onCooldown(player)) {
player.sendMessage(MiniComponent.err("That feature can only be used once every 30 seconds."));

View File

@ -5,27 +5,26 @@ import io.github.simplex.luck.FeelingLucky;
import io.github.simplex.luck.player.Luck;
import io.github.simplex.luck.util.ListBox;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
public record RestoreHunger(FeelingLucky plugin) implements Listener {
public RestoreHunger {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
public class RestoreHunger extends AbstractListener {
public RestoreHunger(FeelingLucky plugin) {
super(plugin);
}
@EventHandler
public void restoreHunger(PlayerItemConsumeEvent event) {
ItemStack item = event.getItem();
Luck luck = plugin.getHandler().getLuckContainer(event.getPlayer());
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();
ListBox.foods.forEach(food -> {
if (item.isSimilar(food)) {
if (luck.quickRNG(percentage)) {
if (luck.quickRNG(percentage) && doesQualify("restore_hunger", percentage)) {
event.getPlayer().setExhaustion(event.getPlayer().getExhaustion() + 2);
event.getPlayer().addPotionEffect(effect);
}

View File

@ -8,12 +8,11 @@ import net.kyori.adventure.text.Component;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
public record TakeDamage(FeelingLucky plugin) implements Listener {
public TakeDamage {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
public class TakeDamage extends AbstractListener {
public TakeDamage(FeelingLucky plugin) {
super(plugin);
}
@EventHandler
@ -23,7 +22,7 @@ public record TakeDamage(FeelingLucky plugin) implements Listener {
return;
}
Player player = (Player) event.getEntity();
Luck luck = plugin.getHandler().getLuckContainer(player);
Luck luck = getHandler().getLuckContainer(player);
if (ListBox.acceptedCauses.contains(event.getCause())) {
if (luck.notDefault()) {
double percentage = luck.getPercentage();
@ -42,7 +41,7 @@ public record TakeDamage(FeelingLucky plugin) implements Listener {
return;
}
if (luck.quickRNG(percentage)) {
if (luck.quickRNG(percentage) && doesQualify("take_damage", percentage)) {
event.setCancelled(true);
player.damage(event.getDamage() / 2);
player.sendMessage(Component.empty().content("You got lucky and took less damage."));
@ -67,7 +66,7 @@ public record TakeDamage(FeelingLucky plugin) implements Listener {
return;
}
if (luck.quickRNG(percentage)) {
if (luck.quickRNG(percentage) && doesQualify("take_damage", percentage)) {
event.setCancelled(true);
player.getActivePotionEffects().removeIf(p -> ListBox.potionEffects.contains(p.getType()));
player.setFireTicks(0);

View File

@ -6,15 +6,14 @@ 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.event.Listener;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.inventory.CraftingInventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
public record UnbreakableTool(FeelingLucky plugin) implements Listener {
public UnbreakableTool {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
public class UnbreakableTool extends AbstractListener {
public UnbreakableTool(FeelingLucky plugin) {
super(plugin);
}
@EventHandler
@ -27,8 +26,8 @@ public record UnbreakableTool(FeelingLucky plugin) implements Listener {
if (ItemBuilder.isTool(stack.getType())) {
if (event.getWhoClicked() instanceof Player player) {
Luck luck = plugin.getHandler().getLuckContainer(player);
if (luck.quickRNG(luck.getPercentage())) {
Luck luck = getHandler().getLuckContainer(player);
if (luck.quickRNG(luck.getPercentage()) && doesQualify("unbreakable", luck.getPercentage())) {
meta.setUnbreakable(true);
stack.setItemMeta(meta);
inventory.setResult(stack);

View File

@ -15,14 +15,12 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class VillagerInventory implements Listener {
public class VillagerInventory extends AbstractListener {
private final SpecialFootItem foot = new SpecialFootItem();
private final MerchantRecipe recipe = new MerchantRecipe(foot.get(), 0, 2, true);
private final FeelingLucky plugin;
public VillagerInventory(FeelingLucky plugin) {
this.plugin = plugin;
super(plugin);
recipe.setIngredients(Arrays.asList(
ItemBuilder.of(Material.EMERALD).build(),
@ -32,8 +30,6 @@ public class VillagerInventory implements Listener {
recipe.setPriceMultiplier(1.25F);
recipe.setVillagerExperience(25);
recipe.setSpecialPrice(4);
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler

View File

@ -2,6 +2,8 @@ package io.github.simplex.luck.player;
import io.github.simplex.luck.FeelingLucky;
import io.github.simplex.luck.util.SneakyWorker;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.attribute.Attribute;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
@ -11,16 +13,18 @@ import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.nio.charset.StandardCharsets;
import java.util.UUID;
public class PlayerConfig {
private final File configFile;
private final FeelingLucky plugin;
private final OfflinePlayer player;
private volatile YamlConfiguration config;
@SuppressWarnings("ResultOfMethodCallIgnored")
public PlayerConfig(FeelingLucky plugin, Player player) {
this.plugin = plugin;
File dataFolder = plugin.getDataFolder();
this.player = player;
if (!plugin.getDataFolder().exists()) plugin.getDataFolder().mkdirs();
File dataFolder = new File(plugin.getDataFolder(), "players");
if (!dataFolder.exists()) dataFolder.mkdirs();
File file = new File(dataFolder, player.getUniqueId() + ".yml");
if (!file.exists()) {
@ -54,8 +58,8 @@ public class PlayerConfig {
}
protected PlayerConfig(FeelingLucky plugin, File file) {
this.plugin = plugin;
this.configFile = file;
this.player = Bukkit.getOfflinePlayer(UUID.fromString(file.getName().split("\\.")[0]));
config = YamlConfiguration.loadConfiguration(configFile);
}
@ -77,6 +81,10 @@ public class PlayerConfig {
load();
}
public OfflinePlayer getPlayer() {
return player;
}
public void setUsername(String name) {
config.set("username", name);
save();

View File

@ -16,6 +16,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class LuckCMD extends Command implements TabCompleter {
private final FeelingLucky plugin;
@ -33,6 +34,19 @@ public class LuckCMD extends Command implements TabCompleter {
if (args.length == 3) {
if ((sender instanceof ConsoleCommandSender) || sender.hasPermission("luck.admin")) {
if (args[0].equalsIgnoreCase("reload") && args[1].equalsIgnoreCase("-p")) {
Player player = Bukkit.getPlayer(args[2]);
if (player == null) {
sender.sendMessage(Messages.NO_PLAYER.get());
return true;
}
UUID uuid = player.getUniqueId();
PlayerConfig config = plugin.getConfigMap().get(uuid);
config.reload();
sender.sendMessage(MiniComponent.info("Successfully reloaded " + player.getName() + "'s configuration file."));
return true;
}
Player player = Bukkit.getPlayer(args[1]);
double amount = Double.parseDouble(args[2]);
@ -80,6 +94,10 @@ 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")) {
}
if (args[0].equalsIgnoreCase("info")) {
Player player = Bukkit.getPlayer(args[1]);

View File

@ -0,0 +1,26 @@
# These entries are for the minimum amount of luck required for the event to actually trigger.
# These work in addition to the RNG generator,
# meaning both the RNG and this condition must be met for the event to trigger.
# 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
# The following entries are for the rarity level of each event trigger.
# This will determine which rarity chance to use which ensures players
# The following values are accepted: NONE, LOW, MED, HIGH
# - None implies that there is no rarity chance attributed to that feature.
# These entries are case-sensitive.
block_drops: LOW
bonemeal: LOW
cheat_death: MED
enchanting: HIGH
experience: HIGH
item_drops: LOW
random_effect: HIGH
restore_hunger: MED
take_damage: MED
unbreakable: HIGH