SinisterWands 1.0 for Bukkit 1.8-1.11

Details

  • Filename
    SinisterWands.jar
  • Uploaded by
  • Uploaded
    Apr 27, 2017
  • Size
    10.54 KB
  • Downloads
    1,173
  • MD5
    bdaa12d20a99e6c353fb18d4ef374837

Supported Bukkit Versions

  • 1.11
  • 1.10
  • 1.9
  • 1.8.1
  • 1.8

Changelog

Initial Release

 This version contains 4 wands currently.

  • Jump Wand
  • Smite Wand
  • Fireball Wand
  • Tnt Wand

Code: (Open Source)

SinisterWands.java

Formatted: https://pastebin.com/QrHLhqx0

package me.nathanthesnooper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Fireball;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.Cancellable;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;

class wandcooldowns {

public boolean[] cooldowns = new boolean[]{true,true,true,true};

}

public class SinisterWands extends JavaPlugin implements Listener {

public static final String[] wands = new String[]{"jump","smite","fireball","tnt"};
public static final String[] wandsDisplay = new String[]{"Jump", "Smite", "Fireball", "Tnt"};
HashMap<Player, wandcooldowns> hm = new HashMap<Player, wandcooldowns>();

@Override
public void onEnable () {

getLogger().info("SinisterWands is starting!");

getConfig().options().copyDefaults(true);
saveConfig();

getServer().getPluginManager().registerEvents(this, this);

}

@Override
public void onDisable () {

getLogger().info("SinisterWands is stopping!");

}

public wandcooldowns getcooldowns (Player p) {
if (hm.containsKey(p)) {
return hm.get(p);
}
hm.put(p, new wandcooldowns());
return getcooldowns(p);
}


@EventHandler
public void rClickEvent (PlayerInteractEvent event) {

Player plr = event.getPlayer();

if(!plr.getInventory().getItemInHand().equals(Material.AIR)) {
if(plr.getInventory().getItemInHand().getItemMeta().hasDisplayName() && plr.getInventory().getItemInHand().getItemMeta().hasLore()) {
for(String wandname : wands) {

if(getConfig().getString(wandname + "name").equals(plr.getInventory().getItemInHand().getItemMeta().getDisplayName())) {
if(getConfig().getString(wandname + "lore").equals(plr.getInventory().getItemInHand().getItemMeta().getLore().get(0))) {
if(wandname.equals("jump") && getcooldowns(plr).cooldowns[0]) {
getcooldowns(plr).cooldowns[0] = false;
jumpWand(plr);
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
public void run() {
getcooldowns(plr).cooldowns[0] = true;
if(getConfig().getBoolean("notifyplayers"))
plr.sendMessage(wandsDisplay[0] + " is now ready");
if(getConfig().getBoolean("notifyplayerssound"))
plr.playSound(plr.getLocation(), Sound.NOTE_PLING, 10, 1);
}
}, Math.round(getConfig().getDouble("jumpcooldown") * 20));
}
if(wandname.equals("smite") && getcooldowns(plr).cooldowns[1]) {
getcooldowns(plr).cooldowns[1] = false;
smiteWand(plr);
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
public void run() {
getcooldowns(plr).cooldowns[1] = true;
if(getConfig().getBoolean("notifyplayers"))
plr.sendMessage(wandsDisplay[1] + " is now ready");
if(getConfig().getBoolean("notifyplayerssound"))
plr.playSound(plr.getLocation(), Sound.NOTE_PLING, 10, 1);
}
}, Math.round(getConfig().getDouble("smitecooldown") * 20));
}
if(wandname.equals("fireball") && getcooldowns(plr).cooldowns[2]) {
getcooldowns(plr).cooldowns[2] = false;
fireballWand(plr);
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
public void run() {
getcooldowns(plr).cooldowns[2] = true;
if(getConfig().getBoolean("notifyplayers"))
plr.sendMessage(wandsDisplay[2] + " is now ready");
if(getConfig().getBoolean("notifyplayerssound"))
plr.playSound(plr.getLocation(), Sound.NOTE_PLING, 10, 1);
}
}, Math.round(getConfig().getDouble("fireballcooldown") * 20));
}
if(wandname.equals("tnt") && getcooldowns(plr).cooldowns[3]) {
getcooldowns(plr).cooldowns[3] = false;
tntWand(plr);
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
public void run() {
getcooldowns(plr).cooldowns[3] = true;
if(getConfig().getBoolean("notifyplayers"))
plr.sendMessage(wandsDisplay[3] + " is now ready");
if(getConfig().getBoolean("notifyplayerssound"))
plr.playSound(plr.getLocation(), Sound.NOTE_PLING, 10, 1);
}
}, Math.round(getConfig().getDouble("tntcooldown") * 20));
}
}
}

}
}
}

}

@SuppressWarnings("deprecation")
public boolean onCommand (CommandSender sender, Command command, String alias, String[] args) {

if(sender instanceof Player) {

Player plr = ((Player) sender).getPlayer();

if(command.getName().equals("wand") && plr.isOp()) {

if(args.length == 1) {

args[0] = args[0].toLowerCase();

ItemStack[] item = new ItemStack[1];

item[0] = new ItemStack(Material.getMaterial(getConfig().getString(args[0] + "wand")), 1);

ItemMeta meta = item[0].getItemMeta();

meta.setDisplayName(getConfig().getString(args[0] + "name"));
ArrayList<String> lore = new ArrayList<String>();
lore.add(getConfig().getString(args[0] + "lore"));
meta.setLore(lore);

item[0].setItemMeta(meta);

plr.getInventory().addItem(item);

return true;

}

if(args.length == 2) {

plr = getServer().getPlayerExact(args[1]);

args[0] = args[0].toLowerCase();

ItemStack[] item = new ItemStack[1];

item[0] = new ItemStack(Material.getMaterial(getConfig().getString(args[0] + "wand")), 1);

ItemMeta meta = item[0].getItemMeta();

meta.setDisplayName(getConfig().getString(args[0] + "name"));
ArrayList<String> lore = new ArrayList<String>();
lore.add(getConfig().getString(args[0] + "lore"));
meta.setLore(lore);

item[0].setItemMeta(meta);

plr.getInventory().addItem(item);

return true;

}

if(args.length == 0) {

plr.sendMessage("\u00a7aAvaliable wands: Jump, Smite, Fireball, Tnt");
plr.sendMessage("\u00a7c[required] <optional>");
plr.sendMessage("\u00a7cUsage: /wand [wand] <Player>");

}

}

}

return false;

}

public void jumpWand(Player plr) {

plr.setVelocity(plr.getVelocity().add(plr.getLocation().getDirection().multiply(getConfig().getDouble("jumpforce"))));

}

public ArrayList<Entity> ede = new ArrayList<Entity>();

public void smiteWand (Player plr) {

Block targetblock = plr.getTargetBlock((Set<Material>)null, 50);
Location location = targetblock.getLocation();
Entity e = plr.getWorld().strikeLightning(location);

ede.add(e);

}

public void fireballWand (Player plr) {

Entity e = plr.launchProjectile(Fireball.class);
e.setVelocity(e.getLocation().getDirection().multiply(2));

ede.add(e);

}

public void tntWand (Player plr) {

Entity e = plr.getWorld().spawnEntity(plr.getLocation().add(plr.getLocation().getDirection()).add(new Vector(0,1,0)), EntityType.PRIMED_TNT);
e.setVelocity(plr.getLocation().getDirection().multiply(2));
((TNTPrimed)e).setFuseTicks(30);

ede.add(e);

}

@EventHandler
public void eLightningDamage (EntityCombustEvent event) {

if(ede.contains(event.getEntity())) {

event.setCancelled(true);

ede.remove(event.getEntity());

}

}

@EventHandler
public void eDamage (EntityDamageEvent event) {

if(ede.contains(event.getEntity())) {

event.setCancelled(true);

ede.remove(event.getEntity());

}

if(event.getEntity().getType() == EntityType.DROPPED_ITEM) {

if(getConfig().getBoolean("forceitemsave")) {

((Cancellable) event).setCancelled(true);

}

}

}

@EventHandler
public void eExplode(EntityExplodeEvent event) {

if(ede.contains(event.getEntity())) {

event.blockList().clear();

ede.remove(event.getEntity());

}

}

}