Merge pull request #1 from FantasyPvP/dev

Spawn Tp keeps player pitch and yaw
This commit is contained in:
Dan E
2024-05-11 08:45:32 +01:00
committed by GitHub
9 changed files with 154 additions and 2 deletions
@@ -2,8 +2,11 @@ package fantasypvp.kand_smp;
import fantasypvp.kand_smp.commands.CmdLightningSword;
import fantasypvp.kand_smp.commands.CmdTeleportSpawn;
import fantasypvp.kand_smp.commands.GiveDashItemCommand;
import fantasypvp.kand_smp.commands.SetSpawnCommand;
import fantasypvp.kand_smp.events.DashItemListener;
import fantasypvp.kand_smp.events.Events;
import fantasypvp.kand_smp.items.DashItem;
import fantasypvp.kand_smp.items.LightningGear;
import fantasypvp.kand_smp.items.TrueNetherite;
import fantasypvp.kand_smp.items.Witherite;
@@ -20,10 +23,13 @@ public final class Kand_smp extends JavaPlugin {
Witherite.init();
// register listeners
getServer().getPluginManager().registerEvents(new Events(), this);
getServer().getPluginManager().registerEvents(new DashItemListener(),this);
getCommand("lightning_sword").setExecutor(new CmdLightningSword());
getCommand("spawn").setExecutor(new CmdTeleportSpawn(this));
getCommand("setSpawnTp").setExecutor(new SetSpawnCommand(this));
getCommand("dashstick").setExecutor(new GiveDashItemCommand());
getServer().broadcastMessage("§aKand SMP has been enabled!");
}
@@ -54,6 +54,9 @@ public class CmdTeleportSpawn implements CommandExecutor {
Location location = new Location(player.getWorld(), x,y,z);
location.setPitch(player.getLocation().getPitch());
location.setYaw(player.getLocation().getYaw());
player.teleport(location);
success = true;
@@ -0,0 +1,36 @@
package fantasypvp.kand_smp.commands;
import fantasypvp.kand_smp.items.DashItem;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class GiveDashItemCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
if(!(sender instanceof Player)){
sender.sendMessage("You must be a player to execute this command");
return true;
}
Player player = (Player) sender;
if(!(player.hasPermission("giveDashItem"))){
player.sendMessage(ChatColor.RED+"You don't have permission to run this command.");
return true;
}
ItemStack dashItem = new DashItem().createDashItem();
player.getInventory().addItem(dashItem);
return true;
}
}
@@ -0,0 +1,56 @@
package fantasypvp.kand_smp.events;
import fantasypvp.kand_smp.items.DashItem;
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
public class DashItemListener implements Listener {
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
ItemStack item = event.getItem(); // Get the item the player interacted with
// Check if the interaction was a right-click and the item is in the main hand
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (item != null && item.isSimilar(new DashItem().createDashItem()) && event.getHand() == EquipmentSlot.HAND) {
Location location = player.getLocation();
Vector direction = location.getDirection();
player.setVelocity(direction.multiply(5.0));
player.playSound(location, Sound.ENTITY_DRAGON_FIREBALL_EXPLODE, 1.0f, 1.0f);
World world = player.getWorld();
world.spawnParticle(Particle.EXPLOSION_HUGE, location, 1);
}
}
}
@EventHandler
public void OnEntityDamage(EntityDamageEvent event){
if(event.getEntity() instanceof Player){
Player player = (Player) event.getEntity();
ItemStack itemInMainHand = player.getInventory().getItemInMainHand();
if (itemInMainHand.isSimilar(new DashItem().createDashItem()) && event.getCause() == EntityDamageEvent.DamageCause.FALL) {
event.setCancelled(true);
}
}
}
}
@@ -12,6 +12,7 @@ import static org.bukkit.Bukkit.*;
public class Events implements Listener {
@EventHandler
public static void onPlayerJoin(org.bukkit.event.player.PlayerJoinEvent event) {
getServer().broadcastMessage("§a" + event.getPlayer().getName() + " has joined the server!");
}
@@ -0,0 +1,36 @@
package fantasypvp.kand_smp.items;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
public class DashItem extends ItemStack {
public ItemStack createDashItem(){
ItemStack item = new ItemStack(Material.STICK,1);
ItemMeta meta = item.getItemMeta();
List<String>stickLore = new ArrayList<>();
stickLore.add("Click this stick and you'll be there in a jiffy.");
stickLore.add("About this, don't get sniffy.");
meta.setLore(stickLore);
meta.setDisplayName(ChatColor.AQUA+"[Dash"+ChatColor.BLUE+" Stick]");
item.setItemMeta(meta);
return item;
}
}
@@ -76,7 +76,12 @@
# Other
## Lightning Sword
- Rename necessary?
- Rename necessary? (Zeus Staff?)
- (Critical) attacking strikes lightning on a target
- independent item
- crafted with a lightning rod, two diamonds and two nether stars
- crafted with a lightning rod, two diamonds and two nether stars
## Dash Stick
- Rename
- Right click launches player where they are looking, plays a sound and summons explosion particles
- Disables fall damage when active
+1
View File
@@ -0,0 +1 @@
lightning-sword-name:"LIGHTNING SWORD"
+8
View File
@@ -12,6 +12,11 @@ commands:
setSpawnTp:
description: Sets the world spawn tp point
usage: /setSpawnTp
dashstick:
description: gives the user a dash stick
usage: /dashstick
permissions:
lightning_sword:
description: Allows player to run /lightning_sword
@@ -19,3 +24,6 @@ permissions:
setSpawnTp:
description: allows player to run /setSpawnTp
default: op
giveDashItem:
description: allows the player to run /dashstick
default: op