mirror of
https://github.com/SimplexDevelopment/FeelingLucky.git
synced 2024-11-25 03:15:01 +00:00
Beta 20220411-SNAPSHOT
Changelog: - Added ExpBoost feature - Added Special Rabbit Foot, which increases a user's luck multiplier. - Added ItemBuilder and MiniComponent library classes - Removed Messages#builder in favor of MiniComponent
This commit is contained in:
parent
ea50032a89
commit
899768819e
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -3,7 +3,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = 'io.github.simplex'
|
||||
version = 'Alpha-1.0-RC03'
|
||||
version = 'Alpha-1.0'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
@ -1,5 +1,5 @@
|
||||
name: FeelingLucky
|
||||
version: 'Alpha-1.0-RC03'
|
||||
version: 'Alpha-1.0'
|
||||
author: SimplexDevelopment
|
||||
main: io.github.simplex.luck.FeelingLucky
|
||||
api-version: 1.18
|
||||
|
62
src/main/java/io/github/simplex/lib/ItemBuilder.java
Normal file
62
src/main/java/io/github/simplex/lib/ItemBuilder.java
Normal file
@ -0,0 +1,62 @@
|
||||
package io.github.simplex.lib;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public final class ItemBuilder {
|
||||
private final ItemStack stack;
|
||||
private final ItemMeta meta;
|
||||
|
||||
public ItemBuilder(Material material) {
|
||||
this.stack = new ItemStack(material);
|
||||
this.meta = stack.getItemMeta();
|
||||
}
|
||||
|
||||
@Contract("_ -> new")
|
||||
public static ItemBuilder of(Material material) {
|
||||
return new ItemBuilder(material);
|
||||
}
|
||||
|
||||
public ItemBuilder setName(String name) {
|
||||
meta.displayName(MiniComponent.of(name).send());
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder setAmount(int amount) {
|
||||
stack.setAmount(amount);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder setLore(String... lore) {
|
||||
List<Component> components = new ArrayList<>();
|
||||
Arrays.stream(lore).forEach(entry -> components.add(MiniComponent.of(entry).send()));
|
||||
meta.lore(components);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemStack build() {
|
||||
stack.setItemMeta(meta);
|
||||
return stack;
|
||||
}
|
||||
|
||||
private Component component(String content, TextColor color, TextDecoration decoration) {
|
||||
return Component.empty().content(content).decorate(decoration).color(color);
|
||||
}
|
||||
|
||||
private Component component(String content, TextColor color) {
|
||||
return Component.empty().content(content).color(color);
|
||||
}
|
||||
|
||||
private Component component(String content) {
|
||||
return Component.empty().content(content);
|
||||
}
|
||||
}
|
@ -3,13 +3,15 @@ package io.github.simplex.lib;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public enum Messages {
|
||||
|
||||
NOT_FROM_CONSOLE(builder("This command may only be used in game.", null, null)),
|
||||
NO_PERMISSION(builder("You do not have permission to use this command.", TextColor.color(255, 0, 0), TextDecoration.ITALIC));
|
||||
NOT_FROM_CONSOLE(MiniComponent.of("This command may only be used in game.").send()),
|
||||
NO_PERMISSION(MiniComponent
|
||||
.of("You do not have permission to use this command.")
|
||||
.color(TextColor.color(255, 0, 0))
|
||||
.decorate(TextDecoration.ITALIC)
|
||||
.send());
|
||||
|
||||
private final Component message;
|
||||
|
||||
@ -20,16 +22,4 @@ public enum Messages {
|
||||
public Component get() {
|
||||
return message;
|
||||
}
|
||||
|
||||
private static Component builder(@NotNull String message, @Nullable TextColor color, @Nullable TextDecoration decoration) {
|
||||
if (color == null) {
|
||||
if (decoration == null) return Component.empty().content(message);
|
||||
|
||||
return Component.empty().content(message).decoration(decoration, TextDecoration.State.TRUE);
|
||||
}
|
||||
|
||||
if (decoration == null) return Component.empty().content(message).color(color);
|
||||
|
||||
return Component.empty().content(message).color(color).decoration(decoration, TextDecoration.State.TRUE);
|
||||
}
|
||||
}
|
||||
|
43
src/main/java/io/github/simplex/lib/MiniComponent.java
Normal file
43
src/main/java/io/github/simplex/lib/MiniComponent.java
Normal file
@ -0,0 +1,43 @@
|
||||
package io.github.simplex.lib;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
|
||||
public class MiniComponent {
|
||||
private final String content;
|
||||
private TextDecoration decoration = null;
|
||||
private TextColor color = null;
|
||||
|
||||
@Contract("_ -> new")
|
||||
public static MiniComponent of(String content) {
|
||||
return new MiniComponent(content);
|
||||
}
|
||||
|
||||
public MiniComponent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public MiniComponent decorate(TextDecoration decoration) {
|
||||
this.decoration = decoration;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MiniComponent color(TextColor color) {
|
||||
this.color = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Component send() {
|
||||
if (color == null) {
|
||||
if (decoration == null) return Component.empty().content(content);
|
||||
|
||||
return Component.empty().content(content).decoration(decoration, TextDecoration.State.TRUE);
|
||||
}
|
||||
|
||||
if (decoration == null) return Component.empty().content(content).color(color);
|
||||
|
||||
return Component.empty().content(content).decorate(decoration).color(color);
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ 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.LuckCMD;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
@ -33,6 +34,7 @@ public final class FeelingLucky extends JavaPlugin {
|
||||
new TakeDamage(this);
|
||||
new RestoreHunger(this);
|
||||
new EnchantmentBoost(this);
|
||||
new ExpBoost(this);
|
||||
getLogger().info("Registration complete! Attempting to load all player configuration files...");
|
||||
|
||||
File[] files = getDataFolder().listFiles();
|
||||
|
@ -1,9 +1,8 @@
|
||||
package io.github.simplex.luck.listener;
|
||||
|
||||
import io.github.simplex.luck.FeelingLucky;
|
||||
import io.github.simplex.luck.SneakyWorker;
|
||||
import io.github.simplex.luck.util.SneakyWorker;
|
||||
import io.github.simplex.luck.player.Luck;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
29
src/main/java/io/github/simplex/luck/listener/ExpBoost.java
Normal file
29
src/main/java/io/github/simplex/luck/listener/ExpBoost.java
Normal file
@ -0,0 +1,29 @@
|
||||
package io.github.simplex.luck.listener;
|
||||
|
||||
import com.destroystokyo.paper.event.player.PlayerPickupExperienceEvent;
|
||||
import io.github.simplex.luck.FeelingLucky;
|
||||
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 ExpBoost(FeelingLucky plugin) {
|
||||
this.plugin = plugin;
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void boostExperienceGain(PlayerPickupExperienceEvent event) {
|
||||
ExperienceOrb orb = event.getExperienceOrb();
|
||||
int n = orb.getExperience();
|
||||
int math = (5 * n ^ 2) / (2 * n + 4);
|
||||
int rounded = Math.round(math);
|
||||
Player player = event.getPlayer();
|
||||
Luck luck = plugin.handler.getLuckContainer(player);
|
||||
if (luck.quickRNG(luck.getPercentage())) {
|
||||
orb.setExperience(rounded);
|
||||
}
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package io.github.simplex.luck.listener;
|
||||
|
||||
import io.github.simplex.luck.FeelingLucky;
|
||||
import io.github.simplex.luck.player.Luck;
|
||||
import io.github.simplex.luck.util.SpecialFootItem;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
@ -26,9 +27,13 @@ public record PlayerListener(FeelingLucky plugin) implements Listener {
|
||||
public void rabbitFoot(PlayerInteractEvent event) {
|
||||
Action action = event.getAction();
|
||||
ItemStack foot = new ItemStack(Material.RABBIT_FOOT);
|
||||
SpecialFootItem special = new SpecialFootItem();
|
||||
Player player = event.getPlayer();
|
||||
Luck luck = plugin.handler.getLuckContainer(player);
|
||||
if (action.isRightClick() && player.getInventory().getItemInMainHand().isSimilar(foot)) {
|
||||
if (foot.getItemMeta().equals(special.meta()) || foot.equals(special.get())) {
|
||||
luck.setMultiplier(luck.multiplier() + 1);
|
||||
}
|
||||
double rng = Luck.RNG().nextDouble(2.0, 5.0);
|
||||
player.getInventory().remove(player.getInventory().getItemInMainHand());
|
||||
luck.addTo(rng);
|
||||
|
@ -2,9 +2,8 @@ package io.github.simplex.luck.listener;
|
||||
|
||||
import io.github.simplex.lib.PotionEffectBuilder;
|
||||
import io.github.simplex.luck.FeelingLucky;
|
||||
import io.github.simplex.luck.ListBox;
|
||||
import io.github.simplex.luck.util.ListBox;
|
||||
import io.github.simplex.luck.player.Luck;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerItemConsumeEvent;
|
||||
|
@ -2,10 +2,9 @@ package io.github.simplex.luck.listener;
|
||||
|
||||
import io.github.simplex.lib.PotionEffectBuilder;
|
||||
import io.github.simplex.luck.FeelingLucky;
|
||||
import io.github.simplex.luck.ListBox;
|
||||
import io.github.simplex.luck.util.ListBox;
|
||||
import io.github.simplex.luck.player.Luck;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
@ -15,11 +15,11 @@ import java.util.SplittableRandom;
|
||||
@SuppressWarnings("all")
|
||||
public class Luck implements LuckContainer {
|
||||
private final Player player;
|
||||
private final double multiplier;
|
||||
private final PlayerLuckChangeEvent event;
|
||||
private final FeelingLucky plugin;
|
||||
private final List<Player> markedPlayers = new ArrayList<>();
|
||||
private double BASE_VALUE;
|
||||
private double multiplier;
|
||||
|
||||
public Luck(FeelingLucky plugin, Player player) {
|
||||
this(plugin, player, 1.0);
|
||||
@ -132,6 +132,11 @@ public class Luck implements LuckContainer {
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
}
|
||||
|
||||
public void setMultiplier(double multiplier) {
|
||||
this.multiplier = multiplier;
|
||||
plugin.getConfigMap().get(associatedPlayer().getUniqueId()).setMultiplier(multiplier);
|
||||
}
|
||||
|
||||
public double getDefaultValue() {
|
||||
return player.getAttribute(Attribute.GENERIC_LUCK).getDefaultValue();
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package io.github.simplex.luck.player;
|
||||
|
||||
import io.github.simplex.luck.FeelingLucky;
|
||||
import io.github.simplex.luck.SneakyWorker;
|
||||
import io.github.simplex.luck.util.SneakyWorker;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -50,9 +50,6 @@ public class PlayerConfig {
|
||||
config.set("luck", plugin.handler.getLuckContainer(player).getDefaultValue());
|
||||
config.set("multiplier", "1.0");
|
||||
save();
|
||||
} else if (!tempUsername.equalsIgnoreCase(player.getName())) {
|
||||
config.set("username", player.getName());
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,11 +77,21 @@ public class PlayerConfig {
|
||||
load();
|
||||
}
|
||||
|
||||
public void setUsername(String name) {
|
||||
config.set("username", name);
|
||||
save();
|
||||
}
|
||||
|
||||
public void setLuck(double luck) {
|
||||
config.set("luck", luck);
|
||||
save();
|
||||
}
|
||||
|
||||
public void setMultiplier(double multiplier) {
|
||||
config.set("multiplier", multiplier);
|
||||
save();
|
||||
}
|
||||
|
||||
public YamlConfiguration getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package io.github.simplex.luck;
|
||||
package io.github.simplex.luck.util;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
@ -1,6 +1,7 @@
|
||||
package io.github.simplex.luck;
|
||||
package io.github.simplex.luck.util;
|
||||
|
||||
import io.github.simplex.lib.Messages;
|
||||
import io.github.simplex.luck.FeelingLucky;
|
||||
import io.github.simplex.luck.player.Luck;
|
||||
import io.github.simplex.luck.player.PlayerConfig;
|
||||
import net.kyori.adventure.text.Component;
|
@ -1,4 +1,4 @@
|
||||
package io.github.simplex.luck;
|
||||
package io.github.simplex.luck.util;
|
||||
|
||||
import io.github.simplex.luck.player.Luck;
|
||||
import org.bukkit.Bukkit;
|
@ -0,0 +1,26 @@
|
||||
package io.github.simplex.luck.util;
|
||||
|
||||
import io.github.simplex.lib.ItemBuilder;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public class SpecialFootItem {
|
||||
public final ItemStack stack;
|
||||
|
||||
public 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.")
|
||||
.build();
|
||||
}
|
||||
|
||||
public ItemStack get() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
public ItemMeta meta() {
|
||||
return stack.getItemMeta();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user