-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
52d3d59
commit 6eabebd
Showing
6 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/elementalmp4/command/admin/EnableBillyCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/elementalmp4/listener/VillagerInteractionListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters