mirror of
https://github.com/SimplexDevelopment/FeelingLucky.git
synced 2024-11-22 01:45:02 +00:00
FeelingLucky v1.0 RELEASE
This commit is contained in:
parent
10d7a4ed98
commit
17f83bd9f2
@ -3,7 +3,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = 'io.github.simplex'
|
group = 'io.github.simplex'
|
||||||
version = 'Beta-1.0.1'
|
version = 'Beta-1.0.2'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
@ -59,14 +59,17 @@ public final class FeelingLucky extends JavaPlugin {
|
|||||||
|
|
||||||
private void loadPlayerConfigurations() {
|
private void loadPlayerConfigurations() {
|
||||||
if (!playerDirectory.exists()) {
|
if (!playerDirectory.exists()) {
|
||||||
|
getLogger().info("No directory exists. Creating...");
|
||||||
playerDirectory.mkdirs();
|
playerDirectory.mkdirs();
|
||||||
|
getLogger().info("Created new directory \"FeelingLucky/players\".");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
File[] files = playerDirectory.listFiles();
|
File[] files = playerDirectory.listFiles();
|
||||||
if (files != null) {
|
if (files != null) {
|
||||||
Arrays.stream(files).forEach(file -> {
|
Arrays.stream(files).forEach(file -> {
|
||||||
UUID uuid = UUID.fromString(file.getName().split("\\.")[0]);
|
UUID uuid = UUID.fromString(file.getName().split("\\.")[0]);
|
||||||
configMap.put(uuid, PlayerConfig.loadFrom(this, file));
|
configMap.put(uuid, PlayerConfig.initFrom(this, file));
|
||||||
});
|
});
|
||||||
configMap.forEach((u, pc) -> pc.load());
|
configMap.forEach((u, pc) -> pc.load());
|
||||||
getLogger().info("Successfully loaded all configurations!");
|
getLogger().info("Successfully loaded all configurations!");
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
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;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
|
|
||||||
|
public class GiveDamage extends AbstractListener {
|
||||||
|
public GiveDamage(FeelingLucky plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void playerAttack(EntityDamageByEntityEvent e) {
|
||||||
|
if ((e.getDamager() instanceof Player player)
|
||||||
|
&& (e.getEntity() instanceof LivingEntity)) {
|
||||||
|
double nextDmg = e.getDamage() + Luck.RNG().nextDouble(1.0, 5.0);
|
||||||
|
Luck luck = plugin.getHandler().getLuckContainer(player);
|
||||||
|
if (luck.quickRNG(luck.getPercentage())) {
|
||||||
|
e.setDamage(nextDmg);
|
||||||
|
player.sendMessage(MiniComponent.info("Your luck has increased your damage output!"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
51
src/main/java/io/github/simplex/luck/listener/OreVein.java
Normal file
51
src/main/java/io/github/simplex/luck/listener/OreVein.java
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
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.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Tag;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
|
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
public class OreVein extends AbstractListener {
|
||||||
|
|
||||||
|
public OreVein(FeelingLucky plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void playerMine(BlockBreakEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
Luck luck = plugin.getHandler().getLuckContainer(player);
|
||||||
|
if (luck.quickRNG(luck.getPercentage()) && event.getBlock().isValidTool(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."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Stream<Block> getOresInArea(Block block) {
|
||||||
|
Stream.Builder<Block> streamBuilder = Stream.builder();
|
||||||
|
Location start = block.getLocation();
|
||||||
|
World world = block.getWorld();
|
||||||
|
Stream<Tag<Material>> materialStream = Stream.of(Tag.COAL_ORES, Tag.COPPER_ORES, Tag.DIAMOND_ORES, Tag.GOLD_ORES, Tag.IRON_ORES, Tag.EMERALD_ORES, Tag.LAPIS_ORES, Tag.REDSTONE_ORES);
|
||||||
|
for (int x = start.getBlockX() - 15; x <= start.getBlockX() + 15; x++) {
|
||||||
|
for (int y = start.getBlockY() - 15; y <= start.getBlockY() + 15; y++) {
|
||||||
|
for (int z = start.getBlockZ() - 15; z <= start.getBlockZ() + 15; z++) {
|
||||||
|
Location location = new Location(world, x, y, z);
|
||||||
|
Material blockType = location.getBlock().getType();
|
||||||
|
if (materialStream.anyMatch(o -> o.isTagged(blockType))) {
|
||||||
|
streamBuilder.add(location.getBlock());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return streamBuilder.build();
|
||||||
|
}
|
||||||
|
}
|
@ -64,7 +64,7 @@ public class PlayerConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Contract("_, _ -> new")
|
@Contract("_, _ -> new")
|
||||||
public static PlayerConfig loadFrom(FeelingLucky plugin, File file) {
|
public static PlayerConfig initFrom(FeelingLucky plugin, File file) {
|
||||||
return new PlayerConfig(plugin, file);
|
return new PlayerConfig(plugin, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ public class SneakyWorker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Class[] getClasses(String packageName) throws ClassNotFoundException, IOException {
|
public static Class<?>[] getClasses(String packageName) throws ClassNotFoundException, IOException {
|
||||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||||
assert classLoader != null;
|
assert classLoader != null;
|
||||||
String path = packageName.replace(".", "/");
|
String path = packageName.replace(".", "/");
|
||||||
@ -43,11 +43,11 @@ public class SneakyWorker {
|
|||||||
URL resource = resources.nextElement();
|
URL resource = resources.nextElement();
|
||||||
dirs.add(new File(resource.getFile()));
|
dirs.add(new File(resource.getFile()));
|
||||||
}
|
}
|
||||||
ArrayList<Class> classes = new ArrayList<>();
|
ArrayList<Class<?>> classes = new ArrayList<>();
|
||||||
for (File directory : dirs) {
|
for (File directory : dirs) {
|
||||||
classes.addAll(findClasses(directory, packageName));
|
classes.addAll(findClasses(directory, packageName));
|
||||||
}
|
}
|
||||||
return classes.toArray(new Class[classes.size()]);
|
return classes.toArray(new Class<?>[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<Class<?>> findClasses(File directory, String packageName) throws ClassNotFoundException {
|
private static List<Class<?>> findClasses(File directory, String packageName) throws ClassNotFoundException {
|
||||||
|
Loading…
Reference in New Issue
Block a user