feat: Add core functionality for chests and farming mechanics

- Implemented ChestsManager to handle player interactions with custom chests.
- Created CustomMaterial class to define custom materials with properties.
- Developed EventManager for handling chat events (currently empty).
- Introduced Farm class to manage block breaking and item drops with custom logic.
- Added utility methods in Utils class for random element selection and block manipulation.
- Created Model class for managing 3D model commands.
- Defined plugin.yml for command registration and permissions.
This commit is contained in:
2026-02-23 18:22:42 +01:00
parent 60f6e2a052
commit ea42ca1e9a
20 changed files with 486 additions and 0 deletions

3
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "automatic"
}

34
pom.xml Normal file
View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>be.thedrewen</groupId>
<artifactId>endariel</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<repositories>
<!-- This adds the Spigot Maven repository to the build -->
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<!--This adds the Spigot API artifact to the build -->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.21.7-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,52 @@
package be.thedrewen;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.plugin.java.JavaPlugin;
import be.thedrewen.commands.Models;
import be.thedrewen.src.ChestsManager;
import be.thedrewen.src.EventManager;
import be.thedrewen.src.Farm;
public class Main extends JavaPlugin{
public static String prefix = "§b[§aEndariel§b]§a ";
// Custom
public Farm farm;
public Models models;
public ChestsManager chestsManager;
// set
public World world;
@Override
public void onEnable() {
this.getServer().getConsoleSender().sendMessage(prefix+"Plugin chargé !");
// Events
this.getServer().getPluginManager().registerEvents(new EventManager(), this);
// Custom
farm = new Farm(this);
this.getServer().getPluginManager().registerEvents(farm, this);
models = new Models(this);
this.getServer().getPluginManager().registerEvents(models, this);
this.getCommand("models").setExecutor(models);
chestsManager = new ChestsManager(this);
this.getServer().getPluginManager().registerEvents(chestsManager, this);
// set
world = Bukkit.getWorld("world");
}
@Override
public void onDisable() {
this.getServer().getConsoleSender().sendMessage(prefix+"Plugin déchargé !");
}
}
// e.getEntity().getWorld().spawnParticle(Particle.CLOUD, p, 1, 0, 0, 0,0);

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,43 @@
package be.thedrewen.src;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Chest;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
import be.thedrewen.Main;
public class ChestsManager implements Listener {
private Main main;
public ChestsManager(Main main) {
this.main = main;
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent e) {
if(e.getClickedBlock() != null) {
Block block = e.getClickedBlock();
Player player = e.getPlayer();
if(block.getType() == Material.CHEST) {
Chest chest = (Chest) block.getState();
if(chest.getCustomName() != null && chest.getCustomName().equalsIgnoreCase("chest_home")) {
e.setCancelled(true);
Inventory inv = Bukkit.createInventory(chest, 54);
player.openInventory(inv);
}
}
}
}
}

View File

@@ -0,0 +1,22 @@
package be.thedrewen.src;
import org.bukkit.Material;
public class CustomMaterial {
public Material type;
public String name;
private boolean replacable = true;
public CustomMaterial(Material type, String name, boolean replacable) {
this.type = type;
this.name = name;
this.replacable = replacable;
}
public boolean isReplacable() {
return replacable;
}
}

View File

@@ -0,0 +1,12 @@
package be.thedrewen.src;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
public class EventManager implements Listener{
@EventHandler
public void onChatSend(AsyncPlayerChatEvent e) {
}
}

View File

@@ -0,0 +1,93 @@
package be.thedrewen.src;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Optional;
import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.entity.TextDisplay;
import org.bukkit.entity.Display.Billboard;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import be.thedrewen.Main;
public class Farm implements Listener {
private Main main;
private ArrayList<CustomMaterial> farmableBlock = new ArrayList<>();
public Farm(Main main) {
this.main = main;
farmableBlock.add(new CustomMaterial(Material.SPRUCE_LOG, "§6Spruce Log", false));
// Minerais
farmableBlock.add(new CustomMaterial(Material.COAL_ORE, "§8Coal ore", true));
farmableBlock.add(new CustomMaterial(Material.IRON_ORE, "§fIron ore", true));
farmableBlock.add(new CustomMaterial(Material.COPPER_ORE, "§6Copper ore", true));
farmableBlock.add(new CustomMaterial(Material.GOLD_ORE, "§eGold ore", true));
farmableBlock.add(new CustomMaterial(Material.REDSTONE_ORE, "§cRedstone", true));
farmableBlock.add(new CustomMaterial(Material.LAPIS_ORE, "§1Lapis", true));
farmableBlock.add(new CustomMaterial(Material.DIAMOND_ORE, "§bDiamond", true));
farmableBlock.add(new CustomMaterial(Material.EMERALD_ORE, "§2Emerald", true));
}
@EventHandler
public void onBlockBreak(BlockBreakEvent e) {
Player player = e.getPlayer();
Block block = e.getBlock();
Location location = block.getLocation();
Collection<ItemStack> drops = block.getDrops(player.getInventory().getItemInMainHand());
if (player.getGameMode() == GameMode.SURVIVAL
&& farmableBlock.stream().anyMatch(item -> item.type.equals(block.getType()))) {
e.setCancelled(true);
Optional<CustomMaterial> customMaterial = farmableBlock.stream()
.filter(item -> item.type.equals(block.getType())).findFirst();
if (customMaterial.isPresent()) {
CustomMaterial item = customMaterial.get();
if (item.isReplacable()) {
block.setType(Material.BEDROCK);
} else {
block.setType(Material.AIR);
}
new BukkitRunnable() {
@Override
public void run() {
block.setType(item.type);
};
}.runTaskLater(main, (Utils.getRandolInteger(5, 20) * 20));
if (drops.size() > 0) {
TextDisplay t = location.getWorld().spawn(new Location(location.getWorld(),
location.getBlockX() + 0.5, location.getBlockY() + 0.5, location.getBlockZ() + 0.5),
TextDisplay.class);
t.setBillboard(Billboard.CENTER);
t.setSeeThrough(true);
ItemStack drop = drops.stream().findFirst().get();
t.setText("§a+" + drop.getAmount() + " " + item.name);
new BukkitRunnable() {
@Override
public void run() {
t.remove();
}
}.runTaskLater(main, 30L);
player.getInventory().addItem(drop);
player.playSound(location, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f);
}
}
}
}
}

View File

@@ -0,0 +1,67 @@
package be.thedrewen.src;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.components.CustomModelDataComponent;
public class Utils {
private static final Random random = new Random();
public static <T> T getRandomElement(ArrayList<T> list) {
return list.get(random.nextInt(list.size()));
}
public static Integer getRandolInteger(Integer min, Integer max) {
return random.nextInt(max - min + 1) + min;
}
public static List<Block> getBlocksBetween(Location loc1, Location loc2) {
List<Block> blocks = new ArrayList<>();
int x1 = loc1.getBlockX();
int y1 = loc1.getBlockY();
int z1 = loc1.getBlockZ();
int x2 = loc2.getBlockX();
int y2 = loc2.getBlockY();
int z2 = loc2.getBlockZ();
for (int x = Math.min(x1, x2); x <= Math.max(x1, x2); x++) {
for (int y = Math.min(y1, y2); y <= Math.max(y1, y2); y++) {
for (int z = Math.min(z1, z2); z <= Math.max(z1, z2); z++) {
blocks.add(loc1.getWorld().getBlockAt(x, y, z));
}
}
}
return blocks;
}
public static void addCustomModelDataString(ItemStack item, String name) {
ItemMeta meta = item.getItemMeta();
CustomModelDataComponent componentSword = meta.getCustomModelDataComponent();
componentSword.setStrings(Arrays.asList(name));
meta.setCustomModelDataComponent(componentSword);
item.setItemMeta(meta);
}
public static void setItemName(ItemStack item, String name) {
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(name);
item.setItemMeta(meta);
}
public static void setItemLore(ItemStack item, List<String> lores) {
ItemMeta meta = item.getItemMeta();
meta.setLore(lores);
item.setItemMeta(meta);
}
}

View File

@@ -0,0 +1,13 @@
package be.thedrewen.src.custom;
public class Model {
public String name;
public String cmd;
public String cmds;
public Model(String name, String cmd, String cmds) {
this.name = name;
this.cmd = cmd;
this.cmds = cmds;
}
}

View File

@@ -0,0 +1,18 @@
name: Endariel
main: be.thedrewen.Main
version: 1.0.0
api-version: '1.21'
commands:
test:
description: "Tester les fonctions."
usage: /test <x> <y> <z>
permission: be.thedrewen.op
models:
description: "Ui pour faire spawn des Models 3Ds."
usage: /models
permission: be.thedrewen.op
permissions:
be.thedrewen.op:
default: op

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.

18
target/classes/plugin.yml Normal file
View File

@@ -0,0 +1,18 @@
name: Endariel
main: be.thedrewen.Main
version: 1.0.0
api-version: '1.21'
commands:
test:
description: "Tester les fonctions."
usage: /test <x> <y> <z>
permission: be.thedrewen.op
models:
description: "Ui pour faire spawn des Models 3Ds."
usage: /models
permission: be.thedrewen.op
permissions:
be.thedrewen.op:
default: op