added illumination wand and adjusted code to better detect block faces or safe placement spots (still a W.I.P.)
This commit is contained in:
parent
11ba7404f9
commit
9e6d6d6127
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -7,11 +7,13 @@ shop:
|
||||
price: 192
|
||||
quantity: 64
|
||||
display_name: "Stone Block"
|
||||
available: true
|
||||
smooth_stone:
|
||||
material: SMOOTH_STONE
|
||||
price: 320
|
||||
quantity: 64
|
||||
display_name: "Smooth Stone"
|
||||
available: true
|
||||
wood_blocks:
|
||||
items:
|
||||
oak_planks:
|
||||
@ -19,6 +21,7 @@ shop:
|
||||
price: 960
|
||||
quantity: 64
|
||||
display_name: "Oak Planks"
|
||||
available: true
|
||||
pvp:
|
||||
items:
|
||||
iron_helmet:
|
||||
@ -26,41 +29,49 @@ shop:
|
||||
price: 110
|
||||
quantity: 1
|
||||
display_name: "Iron Helmet"
|
||||
available: true
|
||||
iron_chestplate:
|
||||
material: IRON_CHESTPLATE
|
||||
price: 176
|
||||
quantity: 1
|
||||
display_name: "Iron Chestplate"
|
||||
available: true
|
||||
iron_leggings:
|
||||
material: IRON_LEGGINGS
|
||||
price: 154
|
||||
quantity: 1
|
||||
display_name: "Iron Leggings"
|
||||
available: true
|
||||
iron_boots:
|
||||
material: IRON_BOOTS
|
||||
price: 88
|
||||
quantity: 1
|
||||
display_name: "Iron Boots"
|
||||
available: true
|
||||
iron_sword:
|
||||
material: IRON_SWORD
|
||||
price: 44
|
||||
quantity: 1
|
||||
display_name: "Iron Sword"
|
||||
available: true
|
||||
iron_PICKAXE:
|
||||
material: IRON_PICKAXE
|
||||
price: 66
|
||||
quantity: 1
|
||||
display_name: "Iron Pick"
|
||||
available: true
|
||||
iron_axe:
|
||||
material: IRON_AXE
|
||||
price: 66
|
||||
quantity: 1
|
||||
display_name: "Iron Axe"
|
||||
available: true
|
||||
iron_shovel:
|
||||
material: IRON_SHOVEL
|
||||
price: 22
|
||||
quantity: 1
|
||||
display_name: "Iron Spoon"
|
||||
available: true
|
||||
redstone:
|
||||
items:
|
||||
repeater:
|
||||
@ -68,11 +79,13 @@ shop:
|
||||
price: 900
|
||||
quantity: 18
|
||||
display_name: "Repeater"
|
||||
available: true
|
||||
redstone:
|
||||
material: REDSTONE
|
||||
price: 2048
|
||||
quantity: 64
|
||||
display_name: "Redstone Dust"
|
||||
available: true
|
||||
nether:
|
||||
items:
|
||||
obsidian:
|
||||
@ -80,6 +93,7 @@ shop:
|
||||
price: 1300
|
||||
quantity: 10
|
||||
display_name: "Obsidian"
|
||||
available: true
|
||||
utilities:
|
||||
items:
|
||||
ASK:
|
||||
@ -87,26 +101,37 @@ shop:
|
||||
price: 450000
|
||||
quantity: 1
|
||||
display_name: "Anchor Shield Kit"
|
||||
available: true
|
||||
gravity_gauntlet:
|
||||
material: KNOWLEDGE_BOOK
|
||||
price: 200000
|
||||
quantity: 1
|
||||
display_name: "Gravity Gauntlet"
|
||||
available: true
|
||||
levitation_wand:
|
||||
material: KNOWLEDGE_BOOK
|
||||
price: 1000000
|
||||
quantity: 1
|
||||
display_name: "Levitation Wand"
|
||||
available: true
|
||||
launch_stick:
|
||||
material: KNOWLEDGE_BOOK
|
||||
price: 1234567
|
||||
quantity: 1
|
||||
display_name: "Launch Stick"
|
||||
available: true
|
||||
rapid_fire_bow:
|
||||
material: KNOWLEDGE_BOOK
|
||||
price: 9000000
|
||||
quantity: 1
|
||||
display_name: "Rapid Fire Bow"
|
||||
available: true
|
||||
illumination_wand:
|
||||
material: KNOWLEDGE_BOOK
|
||||
price: 9000000
|
||||
quantity: 1
|
||||
display_name: "Illumination Wand"
|
||||
available: true
|
||||
poor: "you're too poor for that, get gooder..."
|
||||
inventory_full: "you got too much clutter, cant fit your purchase into that mess..."
|
||||
pagination:
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -103,8 +103,8 @@ public class BlockShop implements Listener {
|
||||
String materialName = config.getString("shop.categories." + category + ".items." + itemKey + ".material");
|
||||
int price = config.getInt("shop.categories." + category + ".items." + itemKey + ".price");
|
||||
String displayName = config.getString("shop.categories." + category + ".items." + itemKey + ".display_name");
|
||||
boolean locked = config.getBoolean("shop.categories." + category + ".items." + itemKey + ".available");
|
||||
if (!locked) {
|
||||
boolean available = config.getBoolean("shop.categories." + category + ".items." + itemKey + ".available");
|
||||
if (available) {
|
||||
if (materialName != null) {
|
||||
Material material = Material.matchMaterial(materialName.toUpperCase());
|
||||
if (material != null) {
|
||||
|
@ -139,9 +139,13 @@ public final class CoswayUtil extends JavaPlugin implements Listener {
|
||||
if(removeCustomKnowledgeBook(player,ChatColor.GREEN+"Rapid Fire Bow")) {
|
||||
player.getInventory().addItem(RapidFireBow.createRapidFireBow());
|
||||
}
|
||||
if(removeCustomKnowledgeBook(player,ChatColor.GREEN+"Illumination Wand")) {
|
||||
player.getInventory().addItem(IlluminationWand.getIlluminationWand());
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(this,0,2);
|
||||
new IlluminationWand(this);
|
||||
}
|
||||
|
||||
|
||||
@ -174,6 +178,9 @@ public final class CoswayUtil extends JavaPlugin implements Listener {
|
||||
if (cmd.getName().equalsIgnoreCase("shopbook") && sender instanceof Player player) {
|
||||
player.getInventory().addItem(BlockShop.createShopItem());
|
||||
}
|
||||
if (cmd.getName().equalsIgnoreCase("Illumination Wand") && sender instanceof Player player) {
|
||||
player.getInventory().addItem(IlluminationWand.getIlluminationWand());
|
||||
}
|
||||
if (cmd.getName().equalsIgnoreCase("throw") && sender instanceof Player player) {
|
||||
Player Target = getNearestPlayer(player,10);
|
||||
if(Target == null) {
|
||||
|
121
src/main/java/CoswayUtil/IlluminationWand.java
Normal file
121
src/main/java/CoswayUtil/IlluminationWand.java
Normal file
@ -0,0 +1,121 @@
|
||||
package CoswayUtil;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.type.Light;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
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.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.util.RayTraceResult;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public class IlluminationWand implements Listener {
|
||||
|
||||
private final CoswayUtil plugin;
|
||||
private final HashMap<UUID, Long> cooldowns = new HashMap<>();
|
||||
private final long COOLDOWN_TIME = 1000; // 1 second in milliseconds
|
||||
|
||||
// Constructor to accept the main plugin instance
|
||||
public IlluminationWand(CoswayUtil plugin) {
|
||||
this.plugin = plugin;
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
public static ItemStack getIlluminationWand() {
|
||||
ItemStack wand = new ItemStack(Material.CARROT_ON_A_STICK);
|
||||
ItemMeta meta = wand.getItemMeta();
|
||||
if (meta != null) {
|
||||
meta.setDisplayName(ChatColor.YELLOW + "Illumination Wand");
|
||||
meta.setLore(java.util.Arrays.asList(ChatColor.GOLD + "Right-click to place Light Blocks!", ChatColor.GRAY + "Reach: 20 blocks"));
|
||||
meta.setUnbreakable(true);
|
||||
wand.setItemMeta(meta);
|
||||
}
|
||||
return wand;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerUseWand(PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
ItemStack item = player.getInventory().getItemInMainHand();
|
||||
|
||||
if (item.getType() != Material.CARROT_ON_A_STICK || !item.hasItemMeta() ||
|
||||
!ChatColor.stripColor(item.getItemMeta().getDisplayName()).equals("Illumination Wand")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.getGameMode() != GameMode.CREATIVE) {
|
||||
if (cooldowns.containsKey(player.getUniqueId())) {
|
||||
long lastUse = cooldowns.get(player.getUniqueId());
|
||||
if (System.currentTimeMillis() - lastUse < COOLDOWN_TIME) {
|
||||
player.sendMessage(ChatColor.RED + "The wand is on cooldown!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
cooldowns.put(player.getUniqueId(), System.currentTimeMillis());
|
||||
}
|
||||
|
||||
RayTraceResult result = player.getWorld().rayTraceBlocks(
|
||||
player.getEyeLocation(), player.getEyeLocation().getDirection(), 20, FluidCollisionMode.NEVER
|
||||
);
|
||||
|
||||
if (result == null || result.getHitBlock() == null) {
|
||||
player.sendMessage(ChatColor.RED + "You must aim at a block within range!");
|
||||
return;
|
||||
}
|
||||
|
||||
Block targetBlock = player.getTargetBlockExact(20, FluidCollisionMode.NEVER); // Get the block the player is looking at (within 20 blocks)
|
||||
|
||||
// Ensure a valid block is being targeted
|
||||
if (targetBlock == null || targetBlock.getType() == Material.AIR) {
|
||||
player.sendMessage(ChatColor.RED + "You must look at a solid block to place light!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the correct face where the block should be placed
|
||||
BlockFace hitFace = event.getBlockFace();
|
||||
if (hitFace == null) {
|
||||
player.sendMessage(ChatColor.RED + "Couldn't determine block face!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the exact block where the light should be placed
|
||||
Block placeLocation = targetBlock.getRelative(hitFace);
|
||||
Location safeSpot = placeLocation.getLocation();
|
||||
|
||||
// Ensure we are not replacing a solid block
|
||||
if (!placeLocation.getType().isAir() && placeLocation.getType() != Material.WATER) {
|
||||
|
||||
Block checkUp = placeLocation.getRelative(BlockFace.UP);
|
||||
Block checkDown = placeLocation.getRelative(BlockFace.DOWN);
|
||||
|
||||
if (!checkUp.getType().isAir() && checkUp.getType() != Material.WATER) {
|
||||
if (!checkDown.getType().isAir() && checkDown.getType() != Material.WATER) {
|
||||
player.sendMessage(ChatColor.RED + "You cannot place a light inside a block!");
|
||||
return;
|
||||
} else {
|
||||
safeSpot = checkDown.getLocation();
|
||||
}
|
||||
} else {
|
||||
safeSpot = checkUp.getLocation();
|
||||
}
|
||||
}
|
||||
|
||||
// Place the light block at the correct location
|
||||
safeSpot.getBlock().setType(Material.LIGHT);
|
||||
Light lightBlock = (Light) safeSpot.getBlock().getBlockData();
|
||||
lightBlock.setLevel(15); // Set light level to max
|
||||
safeSpot.getBlock().setBlockData(lightBlock);
|
||||
|
||||
// Particle effect at the placed location
|
||||
player.getWorld().spawnParticle(Particle.END_ROD, safeSpot.add(0.5, 0.5, 0.5), 10, 0.2, 0.2, 0.2, 0);
|
||||
player.getWorld().playSound(safeSpot, Sound.BLOCK_END_PORTAL_FRAME_FILL, 1.0f, 1.5f);
|
||||
|
||||
}
|
||||
}
|
@ -126,6 +126,12 @@ shop:
|
||||
quantity: 1
|
||||
display_name: "Rapid Fire Bow"
|
||||
available: true
|
||||
illumination_wand:
|
||||
material: KNOWLEDGE_BOOK
|
||||
price: 9000000
|
||||
quantity: 1
|
||||
display_name: "Illumination Wand"
|
||||
available: true
|
||||
poor: "you're too poor for that, get gooder..."
|
||||
inventory_full: "you got too much clutter, cant fit your purchase into that mess..."
|
||||
pagination:
|
||||
|
Loading…
Reference in New Issue
Block a user