Skip to content

Commit

Permalink
Added Billy
Browse files Browse the repository at this point in the history
  • Loading branch information
ElementalMP4 committed Mar 15, 2024
1 parent 52d3d59 commit 6eabebd
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/elementalmp4/GlobalConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

public enum GlobalConfig {

TNT_EXPLODES("tnt_explodes", "true"),
TNT_EXPLODES("tnt_enabled", "true"),
COWS_EXPLODE("cows_explode", "false"),
SHEEP_SMITE("sheep_smite", "false"),
BILLY_ENABLED("billy_enabled", "false"),
PLOT_MAX_SIZE("plot_max_size", "10000");

private final String key;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/elementalmp4/SebUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public void onEnable() {
getCommand("revokepermit").setExecutor(new RevokePermitCommand());
getCommand("permits").setExecutor(new PermitsCommand());
getCommand("smite").setExecutor(new SmiteCommand());
getCommand("enablebilly").setExecutor(new EnableBillyCommand());

logger.info(ConsoleColours.YELLOW + "Registering autofill");
getCommand("namecolour").setTabCompleter(new ColourTabCompleter());
Expand All @@ -93,6 +94,7 @@ public void onEnable() {
getCommand("revokepermit").setTabCompleter(new PermitCompleter());
getCommand("permits").setTabCompleter(new PlotCompleter());
getCommand("deleteplot").setTabCompleter(new PlotCompleter());
getCommand("enablebilly").setTabCompleter(new BooleanTabCompleter());

logger.info(ConsoleColours.YELLOW + "Registering listeners");
getServer().getPluginManager().registerEvents(new ChatInterceptor(), this);
Expand All @@ -101,6 +103,7 @@ public void onEnable() {
getServer().getPluginManager().registerEvents(new ExplosionListener(), this);
getServer().getPluginManager().registerEvents(new AnimalInteractionListener(), this);
getServer().getPluginManager().registerEvents(new PlotListener(), this);
getServer().getPluginManager().registerEvents(new VillagerInteractionListener(), this);

logger.info(ConsoleColours.GREEN + "Ready!");
}
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/elementalmp4/command/admin/EnableBillyCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package main.java.elementalmp4.command.admin;

import main.java.elementalmp4.GlobalConfig;
import main.java.elementalmp4.service.GlobalConfigService;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;

import java.util.Set;

public class EnableBillyCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender commandSender, Command command, String label, String[] args) {
if (args.length == 0) {
boolean billyEnabled = GlobalConfigService.getAsBoolean(GlobalConfig.BILLY_ENABLED);
commandSender.sendMessage("Billy's Shop is currently " + format(billyEnabled));
return true;
}

if (!Set.of("true", "false").contains(args[0])) {
commandSender.sendMessage(ChatColor.RED + "You must specify true or false");
return true;
}

GlobalConfigService.set(GlobalConfig.BILLY_ENABLED, args[0]);
commandSender.sendMessage("Billy's Shop is now " + format(Boolean.parseBoolean(args[0])));
return true;
}

private String format(boolean enabled) {
return (enabled ? ChatColor.GREEN + "enabled" : ChatColor.RED + "disabled");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main.java.elementalmp4.listener;

import main.java.elementalmp4.service.MerchantService;
import org.bukkit.entity.EntityType;
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.PlayerInteractEntityEvent;

public class VillagerInteractionListener implements Listener {

@EventHandler
public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) {
if (event.getRightClicked().getType() == EntityType.VILLAGER) {
Villager villager = (Villager) event.getRightClicked();
if (villager.getProfession() == Villager.Profession.NITWIT) {
Player player = event.getPlayer();
MerchantService.showSuperSecretShop(player);
}
}
}

}
65 changes: 65 additions & 0 deletions src/main/java/elementalmp4/service/MerchantService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package main.java.elementalmp4.service;

import main.java.elementalmp4.GlobalConfig;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Merchant;
import org.bukkit.inventory.MerchantRecipe;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;

import java.util.ArrayList;
import java.util.List;

public class MerchantService {

private static final List<MerchantRecipe> BILLY_RECIPES = new ArrayList<>();

static {
//Elytra
MerchantRecipe elytra = new MerchantRecipe(new ItemStack(Material.ELYTRA), 100);
elytra.addIngredient(new ItemStack(Material.DIAMOND, 32));
elytra.addIngredient(new ItemStack(Material.NETHERITE_INGOT, 1));
BILLY_RECIPES.add(elytra);

//Firework Rockets
MerchantRecipe rockets = new MerchantRecipe(new ItemStack(Material.FIREWORK_ROCKET, 32), 100);
rockets.addIngredient(new ItemStack(Material.IRON_INGOT, 20));
BILLY_RECIPES.add(rockets);

//Netherite
MerchantRecipe netherite = new MerchantRecipe(new ItemStack(Material.NETHERITE_INGOT), 100);
netherite.addIngredient(new ItemStack(Material.EMERALD, 16));
BILLY_RECIPES.add(netherite);

//Unbreaking 3
ItemStack unbreakingBook = new ItemStack(Material.ENCHANTED_BOOK);
EnchantmentStorageMeta unbreakingMeta = (EnchantmentStorageMeta) unbreakingBook.getItemMeta();
unbreakingMeta.addStoredEnchant(Enchantment.DURABILITY, 3, true);
unbreakingBook.setItemMeta(unbreakingMeta);

MerchantRecipe unbreaking = new MerchantRecipe(unbreakingBook, 100);
unbreaking.addIngredient(new ItemStack(Material.EMERALD, 10));
BILLY_RECIPES.add(unbreaking);

//Mending
ItemStack mendingBook = new ItemStack(Material.ENCHANTED_BOOK);
EnchantmentStorageMeta mendingMeta = (EnchantmentStorageMeta) mendingBook.getItemMeta();
mendingMeta.addStoredEnchant(Enchantment.MENDING, 1, true);
mendingBook.setItemMeta(mendingMeta);

MerchantRecipe mending = new MerchantRecipe(mendingBook, 100);
mending.addIngredient(new ItemStack(Material.EMERALD, 10));
BILLY_RECIPES.add(mending);
}

public static void showSuperSecretShop(Player player) {
if (GlobalConfigService.getAsBoolean(GlobalConfig.BILLY_ENABLED)) {
Merchant merchant = Bukkit.createMerchant("Billy");
merchant.setRecipes(BILLY_RECIPES);
player.openMerchant(merchant, true);
}
}
}
4 changes: 4 additions & 0 deletions src/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ commands:
description: "Toggle whether sheep are smited when shaved"
usage: "/sheepsmite [true/false]"
permission: "sebutils.admin"
enablebilly:
description: "Toggle whether nitwit villagers will show a special item shop for difficult to acquire items"
usage: "/enablebilly [true/false]"
permission: "sebutils.admin"
smite:
description: "Smite a player"
usage: "/smite [player]"
Expand Down

0 comments on commit 6eabebd

Please sign in to comment.