Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Bunnky committed Oct 25, 2024
1 parent 777749f commit f747703
Show file tree
Hide file tree
Showing 39 changed files with 3,578 additions and 76 deletions.
30 changes: 27 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>16</source>
<target>16</target>
<source>21</source>
<target>21</target>
<compilerArgs>--enable-preview</compilerArgs>
</configuration>
</plugin>
</plugins>
Expand All @@ -89,51 +90,74 @@
</build>

<dependencies>

<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.20.6-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.20.6-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.github.Slimefun</groupId>
<artifactId>Slimefun4</artifactId>
<version>e02a0f61d1</version>
<version>RC-37</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>io.github.baked-libs</groupId>
<artifactId>dough-api</artifactId>
<version>1.2.0</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>3.0.2</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
<version>3.0.1u2</version>
</dependency>

<dependency>
<groupId>io.papermc</groupId>
<artifactId>paperlib</artifactId>
<version>1.0.8</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>23.0.0</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
</dependency>

<dependency>
<groupId>net.guizhanss</groupId>
<artifactId>GuizhanLib-api</artifactId>
<version>1.8.1</version>
<scope>compile</scope>
</dependency>

</dependencies>
</project>
27 changes: 15 additions & 12 deletions src/main/java/me/bunnky/idreamofeasy/IDreamOfEasy.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.libraries.dough.updater.BlobBuildUpdater;
import me.bunnky.idreamofeasy.slimefun.Setup;
import me.bunnky.idreamofeasy.slimefun.listener.IdolListener;
import me.bunnky.idreamofeasy.slimefun.listener.MagnetoidListener;
import me.bunnky.idreamofeasy.slimefun.setup.Setup;
import org.bstats.bukkit.Metrics;
import org.bukkit.plugin.java.JavaPlugin;

Expand All @@ -26,25 +28,27 @@ public IDreamOfEasy() {
public void onEnable() {
instance = this;

if (!Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_20)) {
getLogger().warning("IDOE requires version 1.20+");
getServer().getPluginManager().disablePlugin(this);
}

getLogger().info(" ┳ ┳┓┳┓┏┓┏┓┳┳┓ ┏┓┏┓ ┏┓┏┓┏┓┓┏ ");
getLogger().info(" ┃ ┃┃┣┫┣ ┣┫┃┃┃ ┃┃┣ ┣ ┣┫┗┓┗┫ ");
getLogger().info(" ┻ ┻┛┛┗┗┛┛┗┛ ┗ ┗┛┻ ┗┛┛┗┗┛┗┛ ");
getLogger().info(" by Bunnky ");

getLogger().info(" IDOE by Bunnky ");
saveDefaultConfig();
tryUpdate();

setupMetrics();
tryUpdate();

Setup.setup();
setupMetrics();

if (!Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_20)) {
getLogger().warning("IDOE only support 1.20+, disabling.");
getServer().getPluginManager().disablePlugin(this);
}
new MagnetoidListener(this);
new IdolListener(this);
}

public void setupMetrics (){
public void setupMetrics() {
Metrics metrics = new Metrics(this, 23610);
}

Expand All @@ -65,8 +69,7 @@ public static IDreamOfEasy getInstance() {
}

@Override
public void onDisable() {
}
public void onDisable() {}

@Override
public String getBugTrackerURL() {
Expand Down
61 changes: 0 additions & 61 deletions src/main/java/me/bunnky/idreamofeasy/slimefun/Setup.java

This file was deleted.

148 changes: 148 additions & 0 deletions src/main/java/me/bunnky/idreamofeasy/slimefun/items/BiomeCompass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package me.bunnky.idreamofeasy.slimefun.items;

import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent;
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.api.items.settings.IntRangeSetting;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.bunnky.idreamofeasy.utils.IDOEUtility;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.SoundCategory;
import org.bukkit.block.Biome;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/*
A useful tool that points players toward the nearest biome of their choice, aiding exploration.
*/

public class BiomeCompass extends SimpleSlimefunItem<ItemUseHandler> {

private final ItemSetting<Integer> r = new IntRangeSetting(this, "range", 1, 100, Integer.MAX_VALUE);

private static final int COOLDOWN_TICKS = 200; // 10 Seconds
private Biome[] biomes;

private Map<Player, Integer> playerBiomeSelection = new HashMap<>();
private Map<Player, Map<Biome, List<Location>>> playerBiomeCache = new HashMap<>();
private Map<Player, Map<Biome, Location>> playerDiscoveredBiomes = new HashMap<>();

public BiomeCompass(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(itemGroup, item, recipeType, recipe);
addItemSetting(r);
IDOEUtility.setGlow(item);

this.biomes = Biome.values();
}

@Override
public @NotNull ItemUseHandler getItemHandler() {
return this::onRightClick;
}

@EventHandler(priority = EventPriority.LOWEST)
private void onRightClick(@NotNull PlayerRightClickEvent e) {
Player p = e.getPlayer();

int selectedBiomeIndex = playerBiomeSelection.getOrDefault(p, 0);

if (p.hasCooldown(Material.COMPASS)) {
p.sendMessage("§cYou must wait before using this again!");
return;
}

if (p.isSneaking()) {
if (e.getInteractEvent().getClickedBlock() == null) {
selectedBiomeIndex = (selectedBiomeIndex + 1) % biomes.length;
playerBiomeSelection.put(p, selectedBiomeIndex);
} else {
selectedBiomeIndex = (selectedBiomeIndex - 1 + biomes.length) % biomes.length;
playerBiomeSelection.put(p, selectedBiomeIndex);
}
p.sendMessage("§eSelected biome: " + ChatColor.GOLD + biomes[selectedBiomeIndex].name());
return;
}

Location closestBiomeLocation = findClosestBiome(p, p.getLocation(), biomes[selectedBiomeIndex]);
if (closestBiomeLocation != null) {
p.setCompassTarget(closestBiomeLocation);
double distance = p.getLocation().distance(closestBiomeLocation);
p.sendMessage("§aFound " + ChatColor.GREEN + biomes[selectedBiomeIndex].name() + " §abiome, " + ChatColor.GREEN + (int) distance + " §ablocks away!");
Map<Biome, Location> playerDiscovered = playerDiscoveredBiomes.computeIfAbsent(p, k -> new HashMap<>());
playerDiscovered.put(biomes[selectedBiomeIndex], closestBiomeLocation);
p.setCooldown(Material.COMPASS, COOLDOWN_TICKS);
p.playSound(p, Sound.ENTITY_PLAYER_LEVELUP, SoundCategory.PLAYERS, 0.5F, 2F);
} else {
p.sendMessage("§cNo " + ChatColor.DARK_RED + biomes[selectedBiomeIndex].name() + " §cbiome nearby.");
p.setCooldown(Material.COMPASS, COOLDOWN_TICKS);
p.playSound(p, Sound.BLOCK_ANVIL_LAND, SoundCategory.PLAYERS, 0.4F, 1F);
}

p.spawnParticle(Particle.EFFECT, p.getLocation().add(0.5, 0.5, 0.5), 30, 0.3, 0.3, 0.3, 0.05);
}

private Location findClosestBiome(Player player, Location playerLocation, Biome targetBiome) {
List<Location> foundLocations = new ArrayList<>();
int radius = r.getValue();

for (int x = -radius; x <= radius; x++) {
for (int z = -radius; z <= radius; z++) {
int biomeX = playerLocation.getBlockX() + x;
int biomeZ = playerLocation.getBlockZ() + z;
Biome biome = playerLocation.getWorld().getBiome(biomeX, biomeZ);
if (biome == targetBiome) {
Location foundLocation = new Location(playerLocation.getWorld(), biomeX, playerLocation.getWorld().getHighestBlockYAt(biomeX, biomeZ), biomeZ);
foundLocations.add(foundLocation);
}
}
}

if (!foundLocations.isEmpty()) {
Location closestNewBiome = foundLocations.get(0);
Map<Biome, List<Location>> playerCache = playerBiomeCache.computeIfAbsent(player, k -> new HashMap<>());
playerCache.computeIfAbsent(targetBiome, k -> new ArrayList<>()).add(closestNewBiome);

return closestNewBiome;
}

Map<Biome, List<Location>> playerCache = playerBiomeCache.computeIfAbsent(player, k -> new HashMap<>());
List<Location> cachedLocations = playerCache.get(targetBiome);

if (cachedLocations != null) {
Location closestCached = null;
double closestCachedDistance = Double.MAX_VALUE;

for (Location loc : cachedLocations) {
double distance = loc.distance(playerLocation);
if (distance < closestCachedDistance) {
closestCachedDistance = distance;
closestCached = loc;
}
}

return closestCached;
}
return null;
}

public static int getRange() {
return Slimefun.getItemCfg().getOrSetDefault("IDOE_BIOMECOMPASS.range", 100);
}
}
Loading

0 comments on commit f747703

Please sign in to comment.