began working on blockshop mechanic

This commit is contained in:
kai ohara 2025-02-13 18:04:12 -05:00
parent d311394be0
commit 5422c9cbe3
52 changed files with 336 additions and 20 deletions

Binary file not shown.

Binary file not shown.

View File

@ -26,5 +26,15 @@
<option name="name" value="sonatype" />
<option name="url" value="https://oss.sonatype.org/content/groups/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="maven" />
<option name="name" value="maven" />
<option name="url" value="https://hub.spigotmc.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="maven" />
<option name="name" value="maven" />
<option name="url" value="https://jitpack.io" />
</remote-repository>
</component>
</project>

View File

@ -3,7 +3,7 @@ plugins {
}
group = 'com.newt-tech'
version = '1.10-RELEASE'
version = '1.11-RELEASE'
repositories {
mavenCentral()
@ -15,10 +15,14 @@ repositories {
name = "sonatype"
url = "https://oss.sonatype.org/content/groups/public/"
}
maven { url 'https://jitpack.io' }
}
dependencies {
compileOnly("io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT")
compileOnly("com.github.MilkBowl:VaultAPI:1.7") {
exclude group: 'org.bukkit', module: 'bukkit' // Exclude bukkit dependency
}
}
def targetJavaVersion = 21

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,34 @@
# config.yml
shop:
categories:
- name: "Building Blocks"
items:
- material: "STONE"
price: 1
display_name: "Stone"
- material: "WOOD"
price: 2
display_name: "Wood"
- material: "BRICK"
price: 3
display_name: "Brick"
- name: "Decorative Blocks"
items:
- material: "LANTERN"
price: 5
display_name: "Lantern"
- material: "PAINTING"
price: 10
display_name: "Painting"
- name: "Tools"
items:
- material: "WOODEN_SWORD"
price: 10
display_name: "Wooden Sword"
- material: "IRON_SWORD"
price: 20
display_name: "Iron Sword"
pagination:
max_items_per_page: 45 # Max items to display per page

View File

@ -1,9 +1,10 @@
name: CoswayUtil
version: '1.10-RELEASE'
version: '1.11-RELEASE'
main: CoswayUtil.CoswayUtil
description: "utility plugin for Cosway servers, a yescraft network server"
api-version: '1.21'
author: "Newt_00"
depend: [Vault]
website: "ycs.Newt-Tech.com"
commands:
scale:
@ -22,6 +23,18 @@ commands:
usage: "/getwand"
permission: CoswayUtil.wand
launchstick:
description: give player a stick to use for launching themselves
usage: /launchstick
description: "give player a stick to use for launching themselves"
usage: "/launchstick"
permission: CoswayUtil.launchStick
rapidbow:
description: "gives player a rapid fire bow"
usage: "/rapidbow"
permission: CoswayUtil.rapidBow
shopbook:
description: "gives player shop book"
usage: "/shopbook"
permission: CoswayUtil.shop
blockshop:
description: "opens block shop"
usage: "/blockshop"
permission: CoswayUtil.shop

View File

@ -1,4 +1,166 @@
package CoswayUtil;
public class shop {
import net.milkbowl.vault.economy.Economy;
import org.bukkit.*;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.*;
import org.bukkit.event.block.Action;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.*;
import org.bukkit.inventory.*;
import org.bukkit.inventory.meta.*;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import java.util.*;
public class BlockShop implements Listener {
private JavaPlugin plugin;
private final Economy economy;
private static FileConfiguration config;
private final NamespacedKey shopItemKey = new NamespacedKey("coswayutil", "block_shop_access");
public BlockShop(JavaPlugin plugin, Economy economy) {
this.plugin = plugin;
this.economy = economy;
}
// Method to create the special book (or other item) to open the shop
public static ItemStack createShopItem() {
ItemStack item = new ItemStack(Material.WRITTEN_BOOK); // Or use any other item
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(ChatColor.GREEN + "Block Shop Access");
meta.setLore(Collections.singletonList(ChatColor.GOLD + "Right click to open the shop."));
meta.getPersistentDataContainer().set(new NamespacedKey("coswayutil", "block_shop_access"), PersistentDataType.STRING, "true");
item.setItemMeta(meta);
return item;
}
public void ShopGUI(JavaPlugin plugin) {
this.plugin = plugin;
config = plugin.getConfig();
}
public static void openShop(Player player, int page) {
Inventory shopInventory = Bukkit.createInventory(null, 54, "Shop");
// Get the categories from the config
List<String> categories = config.getStringList("shop.categories");
int maxItemsPerPage = config.getInt("pagination.max_items_per_page");
int startIndex = (page - 1) * maxItemsPerPage;
int endIndex = startIndex + maxItemsPerPage;
// Loop through the categories
for (String categoryName : categories) {
List<ItemStack> items = loadItemsFromCategory(categoryName);
// Calculate the correct number of items for pagination
for (int i = startIndex; i < endIndex && i < items.size(); i++) {
ItemStack item = items.get(i);
shopInventory.addItem(item);
}
}
// Show inventory to the player
player.openInventory(shopInventory);
}
private static List<ItemStack> loadItemsFromCategory(String category) {
List<ItemStack> items = new ArrayList<>();
// Load items for the category from the config
List<String> itemList = config.getStringList("shop.categories." + category + ".items");
for (String item : itemList) {
String materialName = config.getString("shop.categories." + category + ".items." + item + ".material");
Material material = Material.getMaterial(materialName.toUpperCase());
int price = config.getInt("shop.categories." + category + ".items." + item + ".price");
String displayName = config.getString("shop.categories." + category + ".items." + item + ".display_name");
if (material != null) {
ItemStack itemStack = new ItemStack(material);
ItemMeta meta = itemStack.getItemMeta();
if (meta != null) {
meta.setDisplayName(displayName);
List<String> lore = new ArrayList<>();
lore.add(ChatColor.GOLD + "Price: " + price + " coins");
meta.setLore(lore);
itemStack.setItemMeta(meta);
items.add(itemStack);
}
}
}
return items;
}
// Helper method to add items to the shop
private void addItemToShop(Inventory shop, Material material, String displayName, double price) {
ItemStack item = new ItemStack(material);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(displayName);
meta.setLore(Collections.singletonList(ChatColor.GOLD + "Price: " + price + " currency"));
item.setItemMeta(meta);
shop.addItem(item);
}
// Handle item right-click to open the shop
@EventHandler
public void onItemUse(PlayerInteractEvent event) {
Player player = event.getPlayer();
ItemStack item = player.getInventory().getItemInMainHand();
if (item != null && item.hasItemMeta() && item.getItemMeta().getPersistentDataContainer().has(shopItemKey, PersistentDataType.STRING)) {
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
openShop(player,1);
event.setCancelled(true); // Prevent default interaction
}
}
}
// Handle purchases from the shop
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked();
InventoryView clickedInventory = event.getWhoClicked().getOpenInventory();
if (clickedInventory.getTitle().equals(ChatColor.DARK_GREEN + "Block Shop")) {
event.setCancelled(true); // Prevent item from being moved
ItemStack clickedItem = event.getCurrentItem();
if (clickedItem != null && clickedItem.getType() != Material.AIR) {
double price = getPrice(clickedItem);
if (economy.has(player, price)) {
economy.withdrawPlayer(player, price);
player.getInventory().addItem(clickedItem);
player.sendMessage(ChatColor.GREEN + "You bought " + clickedItem.getType() + " for " + price + " currency.");
} else {
player.sendMessage(ChatColor.RED + "You don't have enough currency to buy this.");
}
}
}
}
// Helper method to retrieve the price of an item (can be customized to use a config file for prices)
private double getPrice(ItemStack item) {
// For simplicity, we assign prices based on material name, you can use a config file for more flexibility
switch (item.getType()) {
case STONE: return 10;
case DIRT: return 5;
case OAK_PLANKS: return 15;
case BRICKS: return 20;
default: return 0;
}
}
// Register the block shop commands and events
public void register() {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
}

View File

@ -7,6 +7,7 @@ import org.bukkit.block.BlockState;
import org.bukkit.block.data.type.LightningRod;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Monster;
import org.bukkit.event.EventHandler;
@ -30,7 +31,7 @@ import org.jetbrains.annotations.NotNull;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.block.data.type.RespawnAnchor;
import CoswayUtil.GravityGauntletCommand;
import net.milkbowl.vault.economy.Economy;
import java.util.HashMap;
import java.util.Map;
@ -38,9 +39,13 @@ import java.util.Map;
public final class CoswayUtil extends JavaPlugin implements Listener {
private Economy economy;
private FileConfiguration config;
@Override
public void onEnable() {
// Create or load the configuration file
saveDefaultConfig(); // This creates the config file if it doesn't exist.
config = getConfig(); // Get the loaded configuration
serverMessage(ColorKey("&aaw sheit here we go again...."));
Bukkit.getPluginManager().registerEvents(new AnchorShield(), this);
// Start the detection loop when the plugin is enabled
@ -73,6 +78,16 @@ public final class CoswayUtil extends JavaPlugin implements Listener {
new TotemShield(this);
// Register the ShadowStep listener
new MobLevitationWand(this);
if (!setupEconomy()) {
getLogger().severe("Vault not found or no economy provider found.");
getServer().getPluginManager().disablePlugin(this);
return;
}
new BlockShop(this, economy).register();
new BlockShop(this, economy);
new RapidFireBow(this);
getServer().getPluginManager().registerEvents(new RapidFireBow(this), this);
getServer().getPluginManager().registerEvents(new ShadowStep(this), this);
//register levitation wand
Bukkit.getPluginManager().registerEvents(new MobLevitationWand(this), this);
@ -84,11 +99,17 @@ public final class CoswayUtil extends JavaPlugin implements Listener {
this.getCommand("gravitygauntlet").setExecutor(new GravityGauntletCommand());
this.getCommand("getwand").setExecutor(new GiveWandCommand());
getServer().getPluginManager().registerEvents(new LaunchStick(this), this);
}
private boolean setupEconomy() {
// Setup Vault economy (make sure it's enabled and available)
if (getServer().getPluginManager().getPlugin("Vault") != null) {
economy = getServer().getServicesManager().getRegistration(Economy.class).getProvider();
return economy != null;
}
return false;
}
@Override
public void onDisable() {
serverMessage(ColorKey("&cim dead, im alive but im dead...."));
@ -104,6 +125,12 @@ public final class CoswayUtil extends JavaPlugin implements Listener {
if (cmd.getName().equalsIgnoreCase("launchstick") && sender instanceof Player player) {
player.getInventory().addItem(LaunchStick.createLaunchStick());
}
if (cmd.getName().equalsIgnoreCase("blockshop") && sender instanceof Player player) {
BlockShop.openShop(player,1);
}
if (cmd.getName().equalsIgnoreCase("shopbook") && sender instanceof Player player) {
player.getInventory().addItem(BlockShop.createShopItem());
}
if (cmd.getName().equalsIgnoreCase("throw") && sender instanceof Player player) {
Player Target = getNearestPlayer(player,10);
if(Target == null) {

View File

@ -1,12 +1,16 @@
package CoswayUtil;
import org.bukkit.*;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
@ -25,6 +29,16 @@ public class RapidFireBow implements Listener {
public RapidFireBow(CoswayUtil plugin) {
this.plugin = plugin;
}
public void removeGroundedArrows() {
for (World world : Bukkit.getWorlds()) {
for (Arrow arrow : world.getEntitiesByClass(Arrow.class)) {
if (arrow.isOnGround()) {
arrow.remove();
}
}
}
}
@EventHandler
public void onRightClick(PlayerInteractEvent event) {
@ -37,6 +51,8 @@ public class RapidFireBow implements Listener {
// If the player is already shooting, do nothing
if (shootingTasks.containsKey(player.getUniqueId())) return;
// Start firing arrows every tick
BukkitRunnable task = new BukkitRunnable() {
@Override
@ -62,8 +78,14 @@ public class RapidFireBow implements Listener {
shootingTasks.put(player.getUniqueId(), task);
}
// Stop shooting when the player switches item or swaps hands
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
public void onItemSwitch(PlayerItemHeldEvent event) {
stopShooting(event.getPlayer());
}
@EventHandler
public void onSwapHands(PlayerSwapHandItemsEvent event) {
stopShooting(event.getPlayer());
}
@ -83,6 +105,7 @@ public class RapidFireBow implements Listener {
if (shootingTasks.containsKey(playerId)) {
shootingTasks.get(playerId).cancel();
shootingTasks.remove(playerId);
removeGroundedArrows();
}
}
@ -90,7 +113,7 @@ public class RapidFireBow implements Listener {
ItemStack bow = new ItemStack(Material.BOW);
ItemMeta meta = bow.getItemMeta();
meta.setDisplayName(ChatColor.GOLD + "Rapid-Fire Bow");
meta.setLore(Collections.singletonList(ChatColor.RED + "Hold Right-Click to unleash rapid arrows!"));
meta.setLore(Collections.singletonList(ChatColor.RED + "Press Right-Click to unleash rapid arrows! Switch hands to stop."));
meta.getPersistentDataContainer().set(new NamespacedKey("coswayutil", "rapid_fire_bow"), PersistentDataType.STRING, "true");
bow.setItemMeta(meta);
return bow;

View File

@ -0,0 +1,34 @@
# config.yml
shop:
categories:
- name: "Building Blocks"
items:
- material: "STONE"
price: 1
display_name: "Stone"
- material: "WOOD"
price: 2
display_name: "Wood"
- material: "BRICK"
price: 3
display_name: "Brick"
- name: "Decorative Blocks"
items:
- material: "LANTERN"
price: 5
display_name: "Lantern"
- material: "PAINTING"
price: 10
display_name: "Painting"
- name: "Tools"
items:
- material: "WOODEN_SWORD"
price: 10
display_name: "Wooden Sword"
- material: "IRON_SWORD"
price: 20
display_name: "Iron Sword"
pagination:
max_items_per_page: 45 # Max items to display per page

View File

@ -4,6 +4,7 @@ main: CoswayUtil.CoswayUtil
description: "utility plugin for Cosway servers, a yescraft network server"
api-version: '1.21'
author: "Newt_00"
depend: [Vault]
website: "ycs.Newt-Tech.com"
commands:
scale:
@ -22,10 +23,18 @@ commands:
usage: "/getwand"
permission: CoswayUtil.wand
launchstick:
description: give player a stick to use for launching themselves
usage: /launchstick
description: "give player a stick to use for launching themselves"
usage: "/launchstick"
permission: CoswayUtil.launchStick
rapidbow:
description: gives player a rapid fire bow
usage: /rapidbow
description: "gives player a rapid fire bow"
usage: "/rapidbow"
permission: CoswayUtil.rapidBow
shopbook:
description: "gives player shop book"
usage: "/shopbook"
permission: CoswayUtil.shop
blockshop:
description: "opens block shop"
usage: "/blockshop"
permission: CoswayUtil.shop