FeelingLucky v1.3.0

This update will entail providing spigot support.
This is currently incomplete.
This commit is contained in:
Paldiu 2022-06-15 09:35:35 -05:00
parent 661b7bd6a7
commit 0ad60075da
11 changed files with 91 additions and 21 deletions

View File

@ -1,5 +1,6 @@
plugins {
id 'java'
id 'com.github.johnrengelman.shadow' version '7.1.0'
}
group = 'io.github.simplex'
@ -9,10 +10,19 @@ repositories {
mavenCentral()
maven { url = uri("https://s01.oss.sonatype.org/content/groups/public/") }
maven { url = uri("https://papermc.io/repo/repository/maven-public/")}
maven { url = uri("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")}
}
dependencies {
compileOnly("org.spigotmc:spigot-api:1.19-R0.1-SNAPSHOT")
compileOnly("io.papermc.paper:paper-api:1.19-R0.1-SNAPSHOT")
shadow("org.jetbrains:annotations:16.0.2")
shadow("net.kyori:adventure-api:4.11.0")
shadow("io.papermc:paperlib:1.0.7")
}
shadowJar {
relocate("io.papermc.lib", "io.github.simplex.paperlib")
}
def targetJavaVersion = 17

View File

@ -21,17 +21,17 @@ public class MiniComponent {
}
@Contract("_ -> new")
public static Component info(String content) {
public static String info(String content) {
return new MiniComponent(content).color(ChatColor.GREEN).send();
}
@Contract("_ -> new")
public static Component warn(String content) {
public static String warn(String content) {
return new MiniComponent(content).color(ChatColor.YELLOW).decorate(TextDecoration.ITALIC).send();
}
@Contract("_ -> new")
public static Component err(String content) {
public static String err(String content) {
return new MiniComponent(content).color(ChatColor.RED).decorate(TextDecoration.BOLD).send();
}
@ -45,7 +45,7 @@ public class MiniComponent {
return this;
}
public Component send() {
public String send() {
if (color == null) {
if (decoration == null) return Component.empty().content(content);

View File

@ -7,11 +7,14 @@ import io.github.simplex.luck.util.LuckCMD;
import io.github.simplex.luck.util.RegenerateConfigCMD;
import io.github.simplex.luck.util.SpecialFootItem;
import io.github.simplex.metrics.Metrics;
import io.papermc.lib.PaperLib;
import org.bukkit.command.CommandMap;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@ -24,11 +27,17 @@ public final class FeelingLucky extends JavaPlugin {
private PlayerHandler handler;
private Config config;
private CommandMap commandMap = null;
public Map<UUID, PlayerConfig> getConfigMap() {
return configMap;
}
@Override
public void onLoad() {
if (!PaperLib.isPaper()) PaperLib.suggestPaper(this);
}
@Override
public void onEnable() {
getLogger().info("Initializing metrics...");
@ -41,7 +50,9 @@ public final class FeelingLucky extends JavaPlugin {
loadPlayerConfigurations();
getLogger().info("Attempting to load the main configuration...");
config = new Config(this);
getLogger().info("Main Config loaded successfully! Loading commands...");
getLogger().info("Main Config loaded successfully! Attempting to open the CommandMap...");
initCommandMap();
getLogger().info("Command Map successfully initialized! Attempting to register the commands...");
new LuckCMD(this);
new RegenerateConfigCMD(this);
getLogger().info("Successfully loaded all commands!");
@ -58,6 +69,16 @@ public final class FeelingLucky extends JavaPlugin {
getLogger().info("Complete! Goodbye! :)");
}
private void initCommandMap() {
try {
Field f = getServer().getClass().getDeclaredField("commandMap");
f.setAccessible(true);
commandMap = (CommandMap) f.get(getServer());
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
}
private void loadPlayerConfigurations() {
if (!playerDirectory.exists()) {
getLogger().info("No directory exists. Creating...");
@ -84,7 +105,6 @@ public final class FeelingLucky extends JavaPlugin {
new BonemealFullCrop(this);
new CheatDeath(this);
new EnchantmentBoost(this);
new ExpBoost(this);
new GiveDamage(this);
new HideCheck(this);
new IllOmen(this);
@ -97,6 +117,10 @@ public final class FeelingLucky extends JavaPlugin {
new TakeDamage(this);
new UnbreakableTool(this);
new VillagerInventory(this);
if (PaperLib.isPaper()) {
new ExpBoost(this);
}
}
public PlayerHandler getHandler() {
@ -113,7 +137,8 @@ public final class FeelingLucky extends JavaPlugin {
return specialFootItem;
}
@Nullable
public CommandMap getCommandMap() {
return getServer().getCommandMap();
return commandMap;
}
}

View File

@ -1,6 +1,5 @@
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;

View File

@ -1,7 +1,6 @@
package io.github.simplex.luck.listener;
import io.github.simplex.lib.ItemBuilder;
import io.github.simplex.lib.MiniComponent;
import io.github.simplex.luck.FeelingLucky;
import io.github.simplex.luck.player.Luck;
import org.bukkit.Material;
@ -35,7 +34,7 @@ public final class BonemealFullCrop extends AbstractListener {
BlockData data = block.getBlockData();
if (action.isRightClick()
if ((action.equals(Action.RIGHT_CLICK_AIR) || action.equals(Action.RIGHT_CLICK_BLOCK))
&& handItem.isSimilar(bonemeal)
&& (data instanceof Ageable crop)
&& luck.quickRNG(luck.getValue())

View File

@ -2,8 +2,10 @@ package io.github.simplex.luck.listener;
import io.github.simplex.lib.MiniComponent;
import io.github.simplex.luck.FeelingLucky;
import io.github.simplex.luck.player.CancellablePlayerDeathEvent;
import io.github.simplex.luck.player.Luck;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.PlayerDeathEvent;
@ -14,8 +16,8 @@ public final class CheatDeath extends AbstractListener {
}
@EventHandler
public void cheatDeath(PlayerDeathEvent event) {
Player player = event.getPlayer();
public void cheatDeath(CancellablePlayerDeathEvent event) {
Player player = event.getEntity();
Luck luck = getHandler().getLuckContainer(player);
double absorption = Math.round(Luck.RNG().nextDouble(5.0, 10.0));
if (luck.quickRNG(luck.getValue()) && doesQualify("cheat_death", luck.getValue())) {

View File

@ -1,6 +1,5 @@
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;

View File

@ -5,6 +5,7 @@ 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.Mob;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
@ -15,7 +16,7 @@ import org.bukkit.event.player.PlayerToggleSneakEvent;
import java.util.*;
public class HideCheck extends AbstractListener {
public Map<Player, List<Entity>> entityMapList = new HashMap<>();
public Map<Player, List<Mob>> entityMapList = new HashMap<>();
public HideCheck(FeelingLucky plugin) {
super(plugin);
@ -30,8 +31,8 @@ public class HideCheck extends AbstractListener {
@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() ?
if (event.getEntity() instanceof Mob entity) {
List<Mob> buffer = entityMapList.get(player).isEmpty() ?
new ArrayList<>() : entityMapList.get(player);
buffer.add(entity);
entityMapList.replace(player, buffer);
@ -46,9 +47,7 @@ public class HideCheck extends AbstractListener {
Luck luck = plugin.getHandler().getLuckContainer(player);
if (luck.quickRNG(luck.getValue()) && doesQualify("hide_check", luck.getValue())) {
entityMapList.get(player).forEach(e -> {
e.getTrackedPlayers().remove(player);
});
entityMapList.get(player).forEach(e -> e.getTarget().remove());
player.sendMessage(MiniComponent.info("Your luck has hidden you from sight."));
}
}

View File

@ -25,7 +25,7 @@ public class OreVein extends AbstractListener {
public void playerMine(BlockBreakEvent event) {
Player player = event.getPlayer();
Luck luck = plugin.getHandler().getLuckContainer(player);
if (luck.quickRNG(luck.getValue()) && doesQualify("ore_vein", luck.getValue()) && event.getBlock().isValidTool(player.getInventory().getItemInMainHand())) {
if (luck.quickRNG(luck.getValue()) && doesQualify("ore_vein", luck.getValue()) && event.getBlock().isPreferredTool(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."));
}

View File

@ -42,7 +42,8 @@ public final class PlayerListener extends AbstractListener {
return;
}
if (action.isRightClick() && player.getInventory().getItemInMainHand().getType().equals(foot.getType())) {
if ((action.equals(Action.RIGHT_CLICK_AIR) || action.equals(Action.RIGHT_CLICK_BLOCK))
&& player.getInventory().getItemInMainHand().getType().equals(foot.getType())) {
if (foot.getItemMeta().equals(special.meta()) || foot.equals(special.get())) {
luck.setMultiplier(luck.multiplier() + 0.1);
player.sendMessage(MiniComponent.info("Your luck multiplier has increased by 0.1!"));

View File

@ -0,0 +1,36 @@
package io.github.simplex.luck.player;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class CancellablePlayerDeathEvent extends PlayerDeathEvent implements Cancellable {
private boolean cancelled = false;
public CancellablePlayerDeathEvent(@NotNull Player player, @NotNull List<ItemStack> drops, int droppedExp, @Nullable String deathMessage) {
super(player, drops, droppedExp, deathMessage);
}
public CancellablePlayerDeathEvent(@NotNull Player player, @NotNull List<ItemStack> drops, int droppedExp, int newExp, @Nullable String deathMessage) {
super(player, drops, droppedExp, newExp, deathMessage);
}
public CancellablePlayerDeathEvent(@NotNull Player player, @NotNull List<ItemStack> drops, int droppedExp, int newExp, int newTotalExp, int newLevel, @Nullable String deathMessage) {
super(player, drops, droppedExp, newExp, newTotalExp, newLevel, deathMessage);
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancel) {
cancelled = cancel;
}
}