🚧 Add files
This commit is contained in:
39
src/main/java/org/example/firstplugin/BootLocker.java
Normal file
39
src/main/java/org/example/firstplugin/BootLocker.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package org.example.firstplugin;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class BootLocker implements CommandExecutor {
|
||||
|
||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
if(e.getRightClicked() instanceof Villager v) {
|
||||
if(v.getCustomName().equalsIgnoreCase("Boot Locker")) {
|
||||
//Do something
|
||||
//For example open an Inventory
|
||||
Inventory inv = Bukkit.createInventory(null, 27, "Boot Locker");
|
||||
|
||||
Main.getBoots().forEach(boot -> inv.addItem(boot.getBoots()));
|
||||
|
||||
p.openInventory(inv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
// Spawn a villager
|
||||
Player player = (Player) sender;
|
||||
Villager villager = player.getWorld().spawn(player.getLocation(), Villager.class);
|
||||
villager.setCustomName("Boot Locker");
|
||||
villager.setCustomNameVisible(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -2,16 +2,25 @@ package org.example.firstplugin;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerArmorStandManipulateEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
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 org.example.firstplugin.items.boots.AbstractBoots;
|
||||
import org.example.firstplugin.items.boots.MagmaBoots;
|
||||
import org.example.firstplugin.items.boots.SpongeBoots;
|
||||
import org.example.firstplugin.items.boots.WaterBoots;
|
||||
import org.example.firstplugin.items.boots.WetSpongeBoots;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -27,6 +36,9 @@ public class Main extends JavaPlugin implements Listener {
|
||||
Objects.requireNonNull(this.getCommand(boot.getCommandName())).setExecutor(boot);
|
||||
Bukkit.addRecipe(boot.getRecipe());
|
||||
}
|
||||
|
||||
BootLocker bootLocker = new BootLocker();
|
||||
Objects.requireNonNull(this.getCommand("bootlocker")).setExecutor(bootLocker);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@@ -42,7 +54,13 @@ public class Main extends JavaPlugin implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private List<AbstractBoots> getBoots() {
|
||||
@EventHandler
|
||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
BootLocker bootLocker = new BootLocker();
|
||||
//bootLocker.onPlayerInteractEntity(event);
|
||||
}
|
||||
|
||||
public static List<AbstractBoots> getBoots() {
|
||||
List<AbstractBoots> boots = new ArrayList<>();
|
||||
boots.add(new WaterBoots());
|
||||
boots.add(new MagmaBoots());
|
||||
@@ -50,4 +68,22 @@ public class Main extends JavaPlugin implements Listener {
|
||||
boots.add(new WetSpongeBoots());
|
||||
return boots;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onArmorStand(PlayerArmorStandManipulateEvent event) {
|
||||
ArmorStand armorstand = event.getRightClicked();
|
||||
Villager villager = armorstand.getWorld().spawn(armorstand.getLocation(), Villager.class);
|
||||
villager.setCustomName("Boot Locker");
|
||||
villager.setCustomNameVisible(true);
|
||||
|
||||
// Add trades
|
||||
List<MerchantRecipe> trades = new ArrayList<>();
|
||||
MerchantRecipe recipe = new MerchantRecipe(new MagmaBoots().getBoots(), Integer.MAX_VALUE);
|
||||
recipe.addIngredient(new ItemStack(Material.MAGMA_BLOCK, 4));
|
||||
recipe.addIngredient(new ItemStack(Material.EMERALD, 3));
|
||||
trades.add(recipe);
|
||||
villager.setRecipes(trades);
|
||||
|
||||
armorstand.remove();
|
||||
}
|
||||
}
|
||||
|
||||
4
src/main/java/org/example/firstplugin/items/Test.java
Normal file
4
src/main/java/org/example/firstplugin/items/Test.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package org.example.firstplugin.items;
|
||||
|
||||
public class Test {
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.example.firstplugin.items;
|
||||
package org.example.firstplugin.items.boots;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
@@ -19,7 +19,7 @@ import javax.annotation.Nonnull;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class AbstractBoots implements CommandExecutor {
|
||||
public abstract class AbstractBoots implements CommandExecutor {
|
||||
public abstract ItemStack getBoots();
|
||||
public abstract String getCommandName();
|
||||
public abstract Recipe getRecipe();
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.example.firstplugin.items;
|
||||
package org.example.firstplugin.items.boots;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Color;
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.example.firstplugin.items;
|
||||
package org.example.firstplugin.items.boots;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
@@ -47,6 +47,9 @@ public class SpongeBoots extends AbstractBoots {
|
||||
|
||||
@Override
|
||||
protected void onReplaceUnderPlayer(Player player, Material oldBlockUnderPlayer, Material newBlockUnderPlayer) {
|
||||
// Make a sponge absorb water when the player is wearing sponge boots
|
||||
|
||||
|
||||
ItemMeta meta = player.getInventory().getBoots().getItemMeta();
|
||||
meta.displayName(WET_SPONGEBOOTS_NAME);
|
||||
player.getInventory().getBoots().setItemMeta(meta);
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.example.firstplugin.items;
|
||||
package org.example.firstplugin.items.boots;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Color;
|
||||
@@ -6,6 +6,7 @@ import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
import org.example.firstplugin.items.boots.AbstractBoots;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.example.firstplugin.items;
|
||||
package org.example.firstplugin.items.boots;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -6,6 +6,8 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
import org.example.firstplugin.items.boots.AbstractBoots;
|
||||
import org.example.firstplugin.items.boots.SpongeBoots;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
@@ -25,6 +25,10 @@ commands:
|
||||
description: Gives you wet sponge boots
|
||||
usage: /<command>
|
||||
permission: firstplugin.wetspongeboots
|
||||
bootlocker:
|
||||
description: Spwans a boot locker employee
|
||||
usage: /<command>
|
||||
permission: firstplugin.bootlocker
|
||||
|
||||
permissions:
|
||||
firstplugin.waterboots:
|
||||
@@ -39,3 +43,6 @@ permissions:
|
||||
firstplugin.wetspongeboots:
|
||||
description: Allows you to use the wetspongeboots command
|
||||
default: op
|
||||
firstplugin.bootlocker:
|
||||
description: Allows you to use the bootlocker command
|
||||
default: op
|
||||
|
||||
Reference in New Issue
Block a user