🎉 Initial Commit
This commit is contained in:
53
src/main/java/org/example/firstplugin/Main.java
Normal file
53
src/main/java/org/example/firstplugin/Main.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package org.example.firstplugin;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.example.firstplugin.items.AbstractBoots;
|
||||
import org.example.firstplugin.items.MagmaBoots;
|
||||
import org.example.firstplugin.items.SpongeBoots;
|
||||
import org.example.firstplugin.items.WaterBoots;
|
||||
import org.example.firstplugin.items.WetSpongeBoots;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Main extends JavaPlugin implements Listener {
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Bukkit.getPluginManager().registerEvents(this, this);
|
||||
|
||||
List<AbstractBoots> boots = getBoots();
|
||||
for (AbstractBoots boot : boots) {
|
||||
Objects.requireNonNull(this.getCommand(boot.getCommandName())).setExecutor(boot);
|
||||
Bukkit.addRecipe(boot.getRecipe());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
event.getPlayer().sendMessage(Component.text("Hello, " + event.getPlayer().getName() + "!"));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
List<AbstractBoots> boots = getBoots();
|
||||
for (AbstractBoots boot : boots) {
|
||||
boot.onPlayerMove(event);
|
||||
}
|
||||
}
|
||||
|
||||
private List<AbstractBoots> getBoots() {
|
||||
List<AbstractBoots> boots = new ArrayList<>();
|
||||
boots.add(new WaterBoots());
|
||||
boots.add(new MagmaBoots());
|
||||
boots.add(new SpongeBoots());
|
||||
boots.add(new WetSpongeBoots());
|
||||
return boots;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package org.example.firstplugin.items;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class AbstractBoots implements CommandExecutor {
|
||||
public abstract ItemStack getBoots();
|
||||
public abstract String getCommandName();
|
||||
public abstract Recipe getRecipe();
|
||||
protected Map<Material, Material> replaceBlockUnderPlayer() {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
protected void onReplaceUnderPlayer(Player player, Material oldMaterialUnderPlayer, Material newMaterialUnderPlayer) {}
|
||||
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
var playerBoots = player.getInventory().getBoots();
|
||||
if (playerBoots == null) {
|
||||
return;
|
||||
}
|
||||
var playerBootsWithFullDurability = playerBoots.clone();
|
||||
playerBootsWithFullDurability.setDurability((short) 0);
|
||||
|
||||
if (getBoots().equals(playerBootsWithFullDurability)) {
|
||||
Block blockUnderPlayer = getBlockUnderPlayer(player);
|
||||
if (blockUnderPlayer == null || replaceBlockUnderPlayer() == null || replaceBlockUnderPlayer().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Material blockUnderPlayerType = blockUnderPlayer.getType();
|
||||
if (replaceBlockUnderPlayer().containsKey(blockUnderPlayerType)) {
|
||||
blockUnderPlayer.setType(replaceBlockUnderPlayer().get(blockUnderPlayerType));
|
||||
onReplaceUnderPlayer(player, blockUnderPlayerType, replaceBlockUnderPlayer().get(blockUnderPlayerType));
|
||||
|
||||
if (player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE) {
|
||||
playerBoots.setDurability((short) (playerBoots.getDurability() + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (sender instanceof Player player) {
|
||||
player.getInventory().addItem(getBoots());
|
||||
}
|
||||
|
||||
// If the player (or console) uses our command correct, we can return true
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of blocks to replace under the player. The key is the block to replace, and the value is the block to replace it with.
|
||||
* @return The map of blocks to replace under the player.
|
||||
*/
|
||||
|
||||
private static Block getBlockUnderPlayer(@Nonnull Player player) {
|
||||
Location locationUnderPlayer = player.getLocation().subtract(0,0.1,0);
|
||||
if (!locationUnderPlayer.equals(locationUnderPlayer.subtract(0, 0.89, 0))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return locationUnderPlayer.getBlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a boot shaped recipe.
|
||||
* @param material The material to use for the boots.
|
||||
* @return The boot shaped recipe.
|
||||
*/
|
||||
protected ShapedRecipe getDefaultRecipe(Material material) {
|
||||
ShapedRecipe abstractBoots = new ShapedRecipe(new NamespacedKey("firstplugin", getCommandName()), getBoots());
|
||||
abstractBoots.shape(" ", "B B", "B B");
|
||||
abstractBoots.setIngredient('B', material);
|
||||
return abstractBoots;
|
||||
}
|
||||
}
|
||||
42
src/main/java/org/example/firstplugin/items/MagmaBoots.java
Normal file
42
src/main/java/org/example/firstplugin/items/MagmaBoots.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package org.example.firstplugin.items;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class MagmaBoots extends AbstractBoots {
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "magmaboots";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recipe getRecipe() {
|
||||
return getDefaultRecipe(Material.MAGMA_BLOCK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getBoots() {
|
||||
ItemStack magmaboots = new ItemStack(Material.LEATHER_BOOTS);
|
||||
LeatherArmorMeta meta = (LeatherArmorMeta) magmaboots.getItemMeta();
|
||||
meta.setColor(Color.fromRGB(255, 0, 0));
|
||||
meta.displayName(Component.text("Magma Boots"));
|
||||
magmaboots.setItemMeta(meta);
|
||||
return magmaboots;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<Material, Material> replaceBlockUnderPlayer() {
|
||||
Map<Material, Material> map = new TreeMap<>();
|
||||
map.put(Material.ICE, Material.WATER);
|
||||
map.put(Material.WATER, Material.COBBLESTONE);
|
||||
map.put(Material.WET_SPONGE, Material.SPONGE);
|
||||
return map;
|
||||
}
|
||||
}
|
||||
54
src/main/java/org/example/firstplugin/items/SpongeBoots.java
Normal file
54
src/main/java/org/example/firstplugin/items/SpongeBoots.java
Normal file
@@ -0,0 +1,54 @@
|
||||
package org.example.firstplugin.items;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class SpongeBoots extends AbstractBoots {
|
||||
public static final Color SPONGEBOOTS_COLOR = Color.fromRGB(255, 255, 0);
|
||||
public static final TextComponent SPONGEBOOTS_NAME = Component.text("Sponge Boots");
|
||||
public static final TextComponent WET_SPONGEBOOTS_NAME = Component.text("Wet Sponge Boots");
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "spongeboots";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recipe getRecipe() {
|
||||
return getDefaultRecipe(Material.SPONGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getBoots() {
|
||||
ItemStack boots = new ItemStack(Material.LEATHER_BOOTS);
|
||||
LeatherArmorMeta meta = (LeatherArmorMeta) boots.getItemMeta();
|
||||
meta.setColor(SPONGEBOOTS_COLOR);
|
||||
meta.displayName(SPONGEBOOTS_NAME);
|
||||
boots.setItemMeta(meta);
|
||||
return boots;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<Material, Material> replaceBlockUnderPlayer() {
|
||||
Map<Material, Material> map = new TreeMap<>();
|
||||
map.put(Material.WATER, Material.AIR);
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onReplaceUnderPlayer(Player player, Material oldBlockUnderPlayer, Material newBlockUnderPlayer) {
|
||||
ItemMeta meta = player.getInventory().getBoots().getItemMeta();
|
||||
meta.displayName(WET_SPONGEBOOTS_NAME);
|
||||
player.getInventory().getBoots().setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
41
src/main/java/org/example/firstplugin/items/WaterBoots.java
Normal file
41
src/main/java/org/example/firstplugin/items/WaterBoots.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package org.example.firstplugin.items;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class WaterBoots extends AbstractBoots {
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "waterboots";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recipe getRecipe() {
|
||||
return getDefaultRecipe(Material.WATER_BUCKET);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getBoots() {
|
||||
ItemStack waterboots = new ItemStack(Material.LEATHER_BOOTS);
|
||||
LeatherArmorMeta meta = (LeatherArmorMeta) waterboots.getItemMeta();
|
||||
meta.setColor(Color.fromRGB(0, 0, 255));
|
||||
meta.displayName(Component.text("Water Boots"));
|
||||
waterboots.setItemMeta(meta);
|
||||
return waterboots;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<Material, Material> replaceBlockUnderPlayer() {
|
||||
Map<Material, Material> map = new TreeMap<>();
|
||||
map.put(Material.LAVA, Material.OBSIDIAN);
|
||||
map.put(Material.SPONGE, Material.WET_SPONGE);
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package org.example.firstplugin.items;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class WetSpongeBoots extends AbstractBoots {
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "wetspongeboots";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recipe getRecipe() {
|
||||
return getDefaultRecipe(Material.WET_SPONGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getBoots() {
|
||||
ItemStack boots = new ItemStack(Material.LEATHER_BOOTS);
|
||||
LeatherArmorMeta meta = (LeatherArmorMeta) boots.getItemMeta();
|
||||
meta.setColor(SpongeBoots.SPONGEBOOTS_COLOR);
|
||||
meta.displayName(SpongeBoots.WET_SPONGEBOOTS_NAME);
|
||||
boots.setItemMeta(meta);
|
||||
return boots;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<Material, Material> replaceBlockUnderPlayer() {
|
||||
Map<Material, Material> map = new TreeMap<>();
|
||||
map.put(Material.SPONGE, Material.WET_SPONGE);
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onReplaceUnderPlayer(Player player, Material oldBlockUnderPlayer, Material newBlockUnderPlayer) {
|
||||
ItemMeta meta = player.getInventory().getBoots().getItemMeta();
|
||||
meta.displayName(SpongeBoots.SPONGEBOOTS_NAME);
|
||||
player.getInventory().getBoots().setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
41
src/main/resources/plugin.yml
Normal file
41
src/main/resources/plugin.yml
Normal file
@@ -0,0 +1,41 @@
|
||||
name: FirstPlugin
|
||||
version: 1.0.0
|
||||
main: org.example.firstplugin.Main
|
||||
description: It's my first Plugin
|
||||
author: k3y0708
|
||||
website: https://atashfaraz.de
|
||||
api-version: '1.20'
|
||||
|
||||
commands:
|
||||
waterboots:
|
||||
description: Gives you water boots
|
||||
usage: /<command>
|
||||
permission: firstplugin.waterboots
|
||||
permission-message: You are not cool enough to wear water boots. They will become steam boots if you try to wear them.
|
||||
magmaboots:
|
||||
description: Gives you magma boots
|
||||
usage: /<command>
|
||||
permission: firstplugin.magmaboots
|
||||
permission-message: You are not hot enough to wear magma boots. They will become obsidian boots if you try to wear them.
|
||||
spongeboots:
|
||||
description: Gives you sponge boots
|
||||
usage: /<command>
|
||||
permission: firstplugin.spongeboots
|
||||
wetspongeboots:
|
||||
description: Gives you wet sponge boots
|
||||
usage: /<command>
|
||||
permission: firstplugin.wetspongeboots
|
||||
|
||||
permissions:
|
||||
firstplugin.waterboots:
|
||||
description: Allows you to use the waterboots command
|
||||
default: op
|
||||
firstplugin.magmaboots:
|
||||
description: Allows you to use the magmaboots command
|
||||
default: op
|
||||
firstplugin.spongeboots:
|
||||
description: Allows you to use the spongeboots command
|
||||
default: op
|
||||
firstplugin.wetspongeboots:
|
||||
description: Allows you to use the wetspongeboots command
|
||||
default: op
|
||||
Reference in New Issue
Block a user