Jump to content

Recommended Posts

Posted

Hello, this is the first time I create a plugin, but I encountered an error I can not fix. This is a plugin for Tekkit Classic 1.2.5. Also, if you have other suggestions about my plugin, please post them below.
Stacktrace:

19.04 11:52:45 [server] SEVERE null
19.04 11:52:45 [server] INFO org.bukkit.command.CommandException: Unhandled exception executing command 'splegg' in plugin Dwarvencraftmc v6.0.0
19.04 11:52:45 [server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42)
19.04 11:52:45 [server] INFO at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:166)
19.04 11:52:45 [server] INFO at forge.bukkit.ForgeCommandMap.dispatch(ForgeCommandMap.java:55)
19.04 11:52:45 [server] INFO at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:664)
19.04 11:52:45 [server] INFO at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.java:862)
19.04 11:52:45 [server] INFO at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:818)
19.04 11:52:45 [server] INFO at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:800)
19.04 11:52:45 [server] INFO at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:34)
19.04 11:52:45 [server] INFO at net.minecraft.server.NetworkManager.b(NetworkManager.java:262)
19.04 11:52:45 [server] INFO at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:119)
19.04 11:52:45 [server] INFO at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:97)
19.04 11:52:45 [server] INFO at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:651)
19.04 11:52:45 [server] INFO at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:525)
19.04 11:52:45 [server] INFO at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
19.04 11:52:45 [server] INFO Caused by: java.lang.NullPointerException
19.04 11:52:45 [server] INFO at me.j0ach1mmall3.Dwarvencraftmc.Main.onCommand(Main.java:197)
19.04 11:52:45 [server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
19.04 11:52:45 [server] INFO ... 13 more

 

Main.class (not everything):

package me.j0ach1mmall3.Dwarvencraftmc;



import java.util.ArrayList;

import java.util.HashMap;



import net.minecraft.server.ItemSpade;



import org.bukkit.Bukkit;

import org.bukkit.ChatColor;

import org.bukkit.Location;

import org.bukkit.Material;

import org.bukkit.World;

import org.bukkit.block.Block;

import org.bukkit.block.Sign;

import org.bukkit.command.Command;

import org.bukkit.command.CommandSender;

import org.bukkit.entity.Egg;

import org.bukkit.entity.Entity;

import org.bukkit.entity.EntityType;

import org.bukkit.entity.Item;

import org.bukkit.entity.Player;

import org.bukkit.entity.Projectile;

import org.bukkit.event.EventHandler;

import org.bukkit.event.EventPriority;

import org.bukkit.event.Listener;

import org.bukkit.event.block.Action;

import org.bukkit.event.block.SignChangeEvent;

import org.bukkit.event.entity.EntityDamageByEntityEvent;

import org.bukkit.event.entity.EntityInteractEvent;

import org.bukkit.event.entity.ItemSpawnEvent;

import org.bukkit.event.entity.PlayerDeathEvent;

import org.bukkit.event.entity.ProjectileHitEvent;

import org.bukkit.event.player.PlayerDropItemEvent;

import org.bukkit.event.player.PlayerEggThrowEvent;

import org.bukkit.event.player.PlayerInteractEvent;

import org.bukkit.event.player.PlayerJoinEvent;

import org.bukkit.event.player.PlayerQuitEvent;

import org.bukkit.inventory.ItemStack;

import org.bukkit.plugin.PluginManager;

import org.bukkit.plugin.java.JavaPlugin;

import org.bukkit.scheduler.BukkitScheduler;

import org.bukkit.util.Vector;



public class Main extends JavaPlugin implements Listener {



String SpleggTool;

String SpleggBlock;

String Border;

String VoteLink;

String DonateLink;

String WebsiteLink;

String SelectionTool;

String ArenaName;

String World;

int x1;

int y1;

int z1;

int x2 ;

int y2;

int z2;

HashMap<String, Boolean> isJoined;

ArrayList<String> joinedPlayers;

boolean inGame;

boolean inCountdown;



//ON ENABLE

public void onEnable(){

saveDefaultConfig();

reloadConfig();

PluginManager pm = getServer().getPluginManager();

pm.registerEvents(new Main(), this);

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

SpleggTool = getConfig().getString("SpleggTool");

SpleggBlock = getConfig().getString("SpleggBlock");

Border = getConfig().getString("Border").replaceAll("&", "§");

VoteLink = getConfig().getString("VoteLink").replaceAll("§", "§");

DonateLink = getConfig().getString("DonateLink").replaceAll("§", "§");

WebsiteLink = getConfig().getString("WebsiteLink").replaceAll("§", "§");

SelectionTool = getConfig().getString("SelectionTool");

ArenaName = getConfig().getString("ArenaName");

World = getConfig().getString("World");

x1 = getConfig().getInt("x1");

y1 = getConfig().getInt("y1");

z1 = getConfig().getInt("z1");

x2 = getConfig().getInt("x2");

y2 = getConfig().getInt("y2");

z2 = getConfig().getInt("z2");

HashMap<String, Boolean> isJoined = new HashMap<String, Boolean>();

ArrayList<String> joinedPlayers = new ArrayList<String>();

Boolean inGame = false;

Boolean inCountdown = false;

}

//COMMANDS

public boolean onCommand(CommandSender sender, Command cmd, String label, String[] a) {

Player p = (Player) sender;

if((cmd.getName().equalsIgnoreCase("splegg")) && (a.length != 0) && (sender instanceof Player)){

if ((a[0].equalsIgnoreCase("create")) && (a.length != 1) && p.hasPermission("dwarvencraftmc.splegg.create")){

this.getConfig().set("ArenaName", a[1]);

saveConfig();

p.sendMessage("§aDone!");

} else if((a[0].equalsIgnoreCase("create")) && (a.length == 1) && (sender instanceof Player)){ p.sendMessage("§cUsage: /splegg create [name]."); }

if (a[0].equalsIgnoreCase("info") && (p.hasPermission("dwarvencraftmc.splegg.info")) && (sender instanceof Player)){

ArenaName = getConfig().getString("ArenaName");

World = getConfig().getString("World");

x1 = getConfig().getInt("x1");

y1 = getConfig().getInt("y1");

z1 = getConfig().getInt("z1");

x2 = getConfig().getInt("x2");

y2 = getConfig().getInt("y2");

z2 = getConfig().getInt("z2");

p.sendMessage("§bArenaName: " + ChatColor.RED + ArenaName);

p.sendMessage("§bWorld: " + ChatColor.RED + World);

p.sendMessage("§bx1: " + ChatColor.RED + x1);

p.sendMessage("§by1: " + ChatColor.RED + y1);

p.sendMessage("§bz1: " + ChatColor.RED + z1);

p.sendMessage("§bx2: " + ChatColor.RED + x2);

p.sendMessage("§by2: " + ChatColor.RED + y2);

p.sendMessage("§bz2: " + ChatColor.RED + z2);

p.sendMessage("§bInGame: " + ChatColor.RED + inGame);

p.sendMessage("§bIsJoined: " + ChatColor.RED + isJoined);

}

if ((a[0].equalsIgnoreCase("remove") && (p.hasPermission("dwarvencraftmc.splegg.remove")) && (sender instanceof Player))){

this.getConfig().set("x1", 0);

this.getConfig().set("y1", 0);

this.getConfig().set("z1", 0);

this.getConfig().set("x2", 0);

this.getConfig().set("y2", 0);

this.getConfig().set("z2", 0);

this.getConfig().set("World", "world");

this.getConfig().set("ArenaName", "Default");

p.sendMessage("§aDone!");

}

if ((a[0].equalsIgnoreCase("restore") && p.hasPermission("dwarvencraftmc.splegg.restore")) && (sender instanceof Player)){

saveConfig();

x1 = getConfig().getInt("x1");

y1 = getConfig().getInt("y1");

z1 = getConfig().getInt("z1");

x2 = getConfig().getInt("x2");

y2 = getConfig().getInt("y2");

z2 = getConfig().getInt("z2");

int x = x1;

int z = z1;

p.sendMessage("§aRestoring...");

try {

if ((x1<x2) && (z1<z2)){

while ((x != x2+1) && (z != z2+1)){

while (x != x2+1){

new Location(getServer().getWorld(World), x, y1, z).getBlock().setType(Material.getMaterial(SpleggBlock));

x = x+1;

}

if ((x == x2+1) && (z != z2+1)){

z = z+1;

x = x1;

}

}

} else

if ((x1>x2) && (z1<z2)){

while ((x != x2-1) && (z != z2+1)){

while (x != x2-1){

new Location(getServer().getWorld(World), x, y1, z).getBlock().setType(Material.getMaterial(SpleggBlock));

x = x-1;

}

if ((x == x2-1) && (z != z2+1)){

z = z+1;

x = x1;

}

}

} else

if ((x1<x2) && (z1>z2)){

while ((x != x2+1) && (z != z2-1)){

while (x != x2+1){

new Location(getServer().getWorld(World), x, y1, z).getBlock().setType(Material.getMaterial(SpleggBlock));

x = x+1;

}

if ((x == x2+1) && (z != z2-1)){

z = z-1;

x = x1;

}

}

} else

if ((x1>x2) && (z1>z2)){

while ((x != x2-1) && (z != z2-1)){

while (x != x2-1){

new Location(getServer().getWorld(World), x, y1, z).getBlock().setType(Material.getMaterial(SpleggBlock));

x = x-1;

}

if ((x == x2-1) && (z != z2-1)){

z = z-1;

x = x1;

}

}

}

} catch(NullPointerException e){



}

}

if((a[0].equalsIgnoreCase("join") && p.hasPermission("dwarvencraftmc.splegg.use")) && (isJoined.get(p.getDisplayName()) == false) && (inGame == false) && (sender instanceof Player)){

isJoined.put(p.getDisplayName(), true);

saveConfig();

x1 = getConfig().getInt("x1");

y1 = getConfig().getInt("y1");

z1 = getConfig().getInt("z1");

Location l = new Location(p.getWorld(), x1+0.5, y1+1, z1+0.5);

p.teleport(l);

p.getInventory().addItem(new ItemStack(Material.getMaterial(SpleggTool), 1));

p.sendMessage("§aYou joined the Game.");

p.sendMessage("§aDo /Splegg ready when you are ready.");

} else if((a[0].equalsIgnoreCase("join") && p.hasPermission("dwarvencraftmc.splegg.use")) && (isJoined.get(p.getDisplayName()) == true) && (sender instanceof Player)){ p.sendMessage("§cYou already joined!");

} else if((a[0].equalsIgnoreCase("join") && p.hasPermission("dwarvencraftmc.splegg.use")) && (isJoined.get(p.getDisplayName()) == false) && (inGame == true) && (sender instanceof Player)){ p.sendMessage("§cThe game has already started!");}

if((a[0].equalsIgnoreCase("leave") && p.hasPermission("dwarvencraftmc.splegg.use")) && (isJoined.get(p.getDisplayName()) == true) && (inCountdown == false) && (sender instanceof Player)){

p.sendMessage("§aYou left the Game.");

isJoined.put(p.getDisplayName(), false);

p.getInventory().clear();

Bukkit.broadcastMessage("§3[Splegg] " + p.getDisplayName() + " §3left.");

try {

joinedPlayers.remove(p);

Location l = new Location(p.getWorld(), 0.5, 65, 2.5);

p.teleport(l);

if (joinedPlayers.size() > 1){

Bukkit.broadcastMessage("§3[Splegg] There are " + joinedPlayers.size() + " left.");

} else if(joinedPlayers.size() == 1){

Player joinedPlayers0 = Bukkit.getServer().getPlayer(joinedPlayers.get(0));

Bukkit.broadcastMessage("§3[Splegg] " + joinedPlayers0.getDisplayName() + " won the game!");

joinedPlayers0.getInventory().clear();

isJoined.put(joinedPlayers0.getDisplayName(), false);

joinedPlayers0.teleport(l);

joinedPlayers.remove(joinedPlayers.get(0));

Bukkit.broadcastMessage("§3[Splegg] Restoring the arena!" );

saveConfig();

x1 = getConfig().getInt("x1");

y1 = getConfig().getInt("y1");

z1 = getConfig().getInt("z1");

x2 = getConfig().getInt("x2");

y2 = getConfig().getInt("y2");

z2 = getConfig().getInt("z2");

int x = x1;

int z = z1;

if ((x1<x2) && (z1<z2)){

while ((x != x2+1) && (z != z2+1)){

while (x != x2+1){

new Location(getServer().getWorld(World), x, y1, z).getBlock().setType(Material.getMaterial(SpleggBlock));

x = x+1;

}

if ((x == x2+1) && (z != z2+1)){

z = z+1;

x = x1;

}

}

} else

if ((x1>x2) && (z1<z2)){

while ((x != x2-1) && (z != z2+1)){

while (x != x2-1){

new Location(getServer().getWorld(World), x, y1, z).getBlock().setType(Material.getMaterial(SpleggBlock));

x = x-1;

}

if ((x == x2-1) && (z != z2+1)){

z = z+1;

x = x1;

}

}

} else

if ((x1<x2) && (z1>z2)){

while ((x != x2+1) && (z != z2-1)){

while (x != x2+1){

new Location(getServer().getWorld(World), x, y1, z).getBlock().setType(Material.getMaterial(SpleggBlock));

x = x+1;

}

if ((x == x2+1) && (z != z2-1)){

z = z-1;

x = x1;

}

}

} else

if ((x1>x2) && (z1>z2)){

while ((x != x2-1) && (z != z2-1)){

while (x != x2-1){

new Location(getServer().getWorld(World), x, y1, z).getBlock().setType(Material.getMaterial(SpleggBlock));

x = x-1;

}

if ((x == x2-1) && (z != z2-1)){

z = z-1;

x = x1;

}

}

}

}

inGame = false;

} catch(NullPointerException ex){

}

}else if((a[0].equalsIgnoreCase("leave") && p.hasPermission("dwarvencraftmc.splegg.use")) && (isJoined.get(p.getDisplayName()) == false) && (sender instanceof Player)){ p.sendMessage("§cYou are not joined!");

}else if((a[0].equalsIgnoreCase("leave") && p.hasPermission("dwarvencraftmc.splegg.use")) && (isJoined.get(p.getDisplayName()) == true) && (inCountdown == true) && (sender instanceof Player)){ p.sendMessage("§cYou can not leave if the game is counting down!");}

if((a[0].equalsIgnoreCase("ready")) && p.hasPermission("dwarvencraftmc.splegg.use") && (isJoined.get(p.getDisplayName()) == true) && (sender instanceof Player)){

joinedPlayers.add(p.getName());

p.sendMessage("§aYou have been marked as ready!");

p.sendMessage("§aThere are " + joinedPlayers.size() + " player(s) ready.");

if((joinedPlayers.size() >= 2) && (inCountdown == false)){

BukkitScheduler scheduler = Bukkit.getServer().getScheduler();

inCountdown = true;

//COUNTDOWN

scheduler.scheduleSyncRepeatingTask(this, new Runnable(){

int Time = 120;

//COUNTDOWN

@Override

public void run() {

if(Time >= 0){

if(Time == 120){

Bukkit.broadcastMessage("§3[Splegg] 2 minutes left untill start.");

Time = Time-1;

} else if(Time == 60){

Bukkit.broadcastMessage("§3[Splegg] 1 minute left untill start.");

Time = Time-1;

} else if((Time <= 10) && (Time > 0)){

Bukkit.broadcastMessage("§3[Splegg] " + Time + " seconds left untill start.");

Time = Time-1;

} else if (Time == 0) {

Bukkit.broadcastMessage("§3[Splegg] The Game has started!");

inGame = true;

Time--;



} else Time = Time-1;

}

}

}, 0L, 20L);

}

}

} else if((cmd.getName().equalsIgnoreCase("Splegg")) && (a.length == 0) && (sender instanceof Player)){p.sendMessage("§cPossible Arguments: create, info, remove, join, leave, ready, restore.");}

if((cmd.getName().equalsIgnoreCase("donate")) && (p.hasPermission("dwarvencraftmc.donate")) && (sender instanceof Player)){

p.sendMessage(Border);

p.sendMessage("§cDonate at: " + ChatColor.DARK_BLUE + DonateLink);

p.sendMessage(Border);

}

if((cmd.getName().equalsIgnoreCase("vote")) && (p.hasPermission("dwarvencraftmc.vote")) && (sender instanceof Player)){

p.sendMessage(Border);

p.sendMessage("§4§lMAKE SURE YOU ARE IN THE RIGHT WORLD");

p.sendMessage("§cYou get diamonds, 16 Bronze ingots, claim blocks and money.");

p.sendMessage("§cVote at: " + ChatColor.DARK_BLUE + VoteLink);

p.sendMessage(Border);

}

if((cmd.getName().equalsIgnoreCase("website")) && (p.hasPermission("dwarvencraftmc.website")) && (sender instanceof Player)){

p.sendMessage(Border);

p.sendMessage("§cVisit our website to stay informed.");

p.sendMessage("§cWebsite: " + ChatColor.DARK_BLUE + WebsiteLink);

p.sendMessage(Border);

}

if((cmd.getName().equalsIgnoreCase("serverinfo")) && (p.hasPermission("dwarvencraftmc.serverinfo")) && (sender instanceof Player)){

p.sendMessage(Border);

p.sendMessage("§cType §1/serverinfo §cfor info about the server.");

p.sendMessage("§cType §1/vote §cto vote.");

p.sendMessage("§cType §1/donate §cto donate.");

p.sendMessage("§cType §1/website §cto view the website.");

p.sendMessage("§cType §1/ticket §cfor questions, suggestions etc.");

p.sendMessage(Border);

}

if((cmd.getName().equalsIgnoreCase("dmc-reload")) && (p.hasPermission("dwarvencraftmc.reload")) && (sender instanceof Player)){

p.sendMessage("§aConfiguration Reloaded!");

reloadConfig();

SpleggTool = getConfig().getString("SpleggTool");

SpleggBlock = getConfig().getString("SpleggBlock");

Border = getConfig().getString("Border").replaceAll("&", "§");

VoteLink = getConfig().getString("VoteLink").replaceAll("§", "§");

DonateLink = getConfig().getString("DonateLink").replaceAll("§", "§");

WebsiteLink = getConfig().getString("WebsiteLink").replaceAll("§", "§");

SelectionTool = getConfig().getString("SelectionTool");

ArenaName = getConfig().getString("ArenaName");

World = getConfig().getString("World");

x1 = getConfig().getInt("x1");

y1 = getConfig().getInt("y1");

z1 = getConfig().getInt("z1");

x2 = getConfig().getInt("x2");

y2 = getConfig().getInt("y2");

z2 = getConfig().getInt("z2");

}

if((cmd.getName().equalsIgnoreCase("help")) && (p.hasPermission("dwarvencraftmc.help")) && (sender instanceof Player)){

p.sendMessage(Border);

p.sendMessage("§cType §1/helpop §cto recieve help from online mods/admins.");

p.sendMessage("§cType §1/ticket §cto create a ticket that will be reviewed later.");

p.sendMessage("§cType §1/lwc §cto get help about container protections.");

p.sendMessage("§cType §1/plotme help §cto get help about plotme.");

p.sendMessage("§cProtect your home by right-clicking with an Golden Shovel (Survival).");

p.sendMessage(Border);

}

if(cmd.getName().equalsIgnoreCase("motd") && (sender instanceof Player)){

if(p.hasPermission("dwarvencraftmc.motd")){

p.sendMessage(Border);

p.sendMessage("§cWelcome back, " + p.getPlayerListName() + "!");

p.sendMessage("§cType §1/serverinfo §cfor info about the server.");

p.sendMessage("§cType §1/website §cto stay informed about updates.");

p.sendMessage("§cType §1/vote §cto vote and get §3§lFREE §citems!");

p.sendMessage(Border);

}

}

if((cmd.getName().equalsIgnoreCase("banneditems")) && (p.hasPermission("dwarvencraftmc.banneditems")) && (sender instanceof Player)){

p.sendMessage(Border);

p.sendMessage("§1[1]§b[ALL WORLDS]§cWireless Tracker");

p.sendMessage("§1[2]§b[PVE WORLD]§cExplosives");

p.sendMessage("§1[3]§b[PVP WORLD]§cEnderchests&EnderPouches");

p.sendMessage("§cThese are the banned items, to view the restricted items, do §1/restricteditems.");

p.sendMessage(Border);

}

if((cmd.getName().equalsIgnoreCase("restricteditems") && (p.hasPermission("dwarvencraftmc.restricteditems"))) && (sender instanceof Player)){

p.sendMessage(Border);

p.sendMessage("§1[1]§b[ALL WORLDS]§cQuarry 1 per person");

p.sendMessage("§1[2]§b[PVE WORLD]§a[Regular Dwarf]§cMining Laser");

p.sendMessage("§1[3]§b[PVE WORLD]§a[Regular Dwarf]§cMining Turtles");

p.sendMessage("§1[4]§b[ALL WORLDS]§a[Senior Dwarf]§cRing Of Arcana");

p.sendMessage("§1[5]§b[ALL WORLDS]§c[Stone Dwarf]§cHarvest Godess Band");

p.sendMessage("§1[6]§b[ALL WORLDS]§c[Iron Dwarf]§cRed Katar");

p.sendMessage("§1[7]§b[ALL WORLDS]§c[Iron Dwarf]§cRed Morningstar");

p.sendMessage("§1[8]§b[ALL WORLDS]§c[Bronze Dwarf]§cGem Armor");

p.sendMessage("§1[9]§b[ALL WORLDS]§c[Golden Dwarf]§cTeleport Pipes");

p.sendMessage("§cYou can view the ranks by doing §1/ranks.");

p.sendMessage(Border);

}

if((cmd.getName().equalsIgnoreCase("worldinfo")) && (p.hasPermission("dwarvencraftmc.worldinfo")) && (sender instanceof Player)){

String World = p.getWorld().getName();

long gameTime = p.getWorld().getTime(), hours = gameTime / 1000 + 6, minutes = (gameTime % 1000) * 60 / 1000;

p.sendMessage(Border);

p.sendMessage("§cYour world is: " + ChatColor.BLUE + World);

p.sendMessage("§cWorld Time: " + ChatColor.BLUE + hours + "h " + minutes + "m");

p.sendMessage("§cChunkloaders are patched in this world");

if(new String(World).equals("Survival")){

p.sendMessage("§cGRIEFING IS NOT ALLOWED IN THIS WORLD");

p.sendMessage("§cExplosives are banned in this world");

}

if(new String(World).equals("Creative")){

p.sendMessage("§cThere is no Nether in this world.");

}

if(new String(World).equals("Factions")){

p.sendMessage("§cThere is no Nether in this world.");

}

p.sendMessage(Border);

}

if((cmd.getName().equalsIgnoreCase("ranks")) && (p.hasPermission("dwarvencraftmc.ranks")) && (sender instanceof Player)){

p.sendMessage(Border);

p.sendMessage("§f[Dwarfling]§rYou are this when you first join.");

p.sendMessage("§a[Young Dwarf]§rYou get this after 30m of playtime.");

p.sendMessage("§2[Regular Dwarf]§rYou get this after 20h of playtime.");

p.sendMessage("§9[Senior Dwarf]§rYou get this after 50h of playtime.");

p.sendMessage("§0[Wooden Dwarf]§rYou get this after donating 5$.");

p.sendMessage("§8[Stone Dwarf]§rYou get this after donating 10$.");

p.sendMessage("§7[Iron Dwarf]§rYou get this after donating 20$.");

p.sendMessage("§6[Bronze Dwarf]§rYou get this after donating 35$.");

p.sendMessage("§e[Golden Dwarf]§rYou get this after donating 50$.");

p.sendMessage("§b[Diamond Dwarf]§rYou get this after donating 100$.");

p.sendMessage(Border);

}

return true;

}



//MOTD

@EventHandler(priority = EventPriority.LOWEST)

public void onPlayerJoin(PlayerJoinEvent e){

Player p = e.getPlayer();

if(e.getPlayer().hasPlayedBefore()){

e.setJoinMessage(ChatColor.DARK_PURPLE + "Welcome back, " + p.getPlayerListName() + ChatColor.DARK_PURPLE + " to Dwarvencraftmc!");

}

try {

if(p.hasPermission("dwarvencraftmc.motd")){

p.sendMessage(Border);

p.sendMessage("§cWelcome back, " + p.getPlayerListName() + "!");

p.sendMessage("§cType §1/serverinfo §cfor info about the server.");

p.sendMessage("§cType §1/website §cto stay informed about updates.");

p.sendMessage("§cType §1/vote §cto vote and get §3§lFREE §citems!");

p.sendMessage(Border);

isJoined.put(p.getDisplayName(), false);

}

} catch(NullPointerException ex){



}

}



//PLAYER DEATH

@EventHandler(priority = EventPriority.LOWEST)

public void onPlayerDeathEvent(PlayerDeathEvent e){

Player p = e.getEntity();

try {

if((isJoined.get(p.getDisplayName()) == true) && (inGame == true)){

e.setDeathMessage("§3[Splegg] " + p.getDisplayName() + " died.");

joinedPlayers.remove(p.getDisplayName());

Location l = new Location(p.getWorld(), 0.5, 65, 2.5);

p.teleport(l);

if (joinedPlayers.size() > 1){

Bukkit.broadcastMessage("§3[Splegg] There are " + joinedPlayers.size() + " left.");

} else if(joinedPlayers.size() == 1){

Player joinedPlayers0 = Bukkit.getServer().getPlayer(joinedPlayers.get(0));

Bukkit.broadcastMessage("§3[Splegg] " + joinedPlayers0.getDisplayName() + " won the game!");

joinedPlayers0.getInventory().clear();

isJoined.put(joinedPlayers0.getDisplayName(), false);

joinedPlayers0.teleport(l);

joinedPlayers.remove(joinedPlayers.get(0));

Bukkit.broadcastMessage("§3[Splegg] Restoring the arena!" );

saveConfig();

x1 = getConfig().getInt("x1");

y1 = getConfig().getInt("y1");

z1 = getConfig().getInt("z1");

x2 = getConfig().getInt("x2");

y2 = getConfig().getInt("y2");

z2 = getConfig().getInt("z2");

int x = x1;

int z = z1;

if ((x1<x2) && (z1<z2)){



while ((x != x2+1) && (z != z2+1)){

while (x != x2+1){

new Location(getServer().getWorld(World), x, y1, z).getBlock().setType(Material.getMaterial(SpleggBlock));

x = x+1;

}

if ((x == x2+1) && (z != z2+1)){

z = z+1;

x = x1;

}

}

} else

if ((x1>x2) && (z1<z2)){

while ((x != x2-1) && (z != z2+1)){

while (x != x2-1){

new Location(getServer().getWorld(World), x, y1, z).getBlock().setType(Material.getMaterial(SpleggBlock));

x = x-1;

}

if ((x == x2-1) && (z != z2+1)){

z = z+1;

x = x1;

}

}

} else

if ((x1<x2) && (z1>z2)){

while ((x != x2+1) && (z != z2-1)){

while (x != x2+1){

new Location(getServer().getWorld(World), x, y1, z).getBlock().setType(Material.getMaterial(SpleggBlock));

x = x+1;

}

if ((x == x2+1) && (z != z2-1)){

z = z-1;

x = x1;

}

}

} else

if ((x1>x2) && (z1>z2)){

while ((x != x2-1) && (z != z2-1)){

while (x != x2-1){

new Location(getServer().getWorld(World), x, y1, z).getBlock().setType(Material.getMaterial(SpleggBlock));

x = x-1;

}

if ((x == x2-1) && (z != z2-1)){

z = z-1;

x = x1;

}

}

}

}

}

inGame = false;

} catch(NullPointerException ex){

}

}



//PLAYER QUIT

@EventHandler(priority = EventPriority.LOWEST)

public void onPlayerLeaveEvent(PlayerQuitEvent e){

e.setQuitMessage("");

Player p = e.getPlayer();

try {

if(isJoined.get(p.getDisplayName()) == true){

Bukkit.broadcastMessage("§3[Splegg] " + p.getDisplayName() + " left.");

isJoined.put(p.getDisplayName(), false);

p.getInventory().clear();

p.sendMessage("§aYou left the Game.");

joinedPlayers.remove(p);

Location l = new Location(p.getWorld(), 0.5, 65, 2.5);

p.teleport(l);

if (joinedPlayers.size() > 1){

Bukkit.broadcastMessage("§3[Splegg] There are " + joinedPlayers.size() + " left.");

} else if(joinedPlayers.size() == 1){

Player joinedPlayers0 = Bukkit.getServer().getPlayer(joinedPlayers.get(0));

Bukkit.broadcastMessage("§3[Splegg] " + joinedPlayers0.getDisplayName() + " won the game!");

joinedPlayers0.getInventory().clear();

isJoined.put(joinedPlayers0.getDisplayName(), false);

joinedPlayers0.teleport(l);

joinedPlayers.remove(joinedPlayers.get(0));

Bukkit.broadcastMessage("§3[Splegg] Restoring the arena!" );

saveConfig();

x1 = getConfig().getInt("x1");

y1 = getConfig().getInt("y1");

z1 = getConfig().getInt("z1");

x2 = getConfig().getInt("x2");

y2 = getConfig().getInt("y2");

z2 = getConfig().getInt("z2");

int x = x1;

int z = z1;

if ((x1<x2) && (z1<z2)){

while ((x != x2+1) && (z != z2+1)){

while (x != x2+1){

new Location(getServer().getWorld(World), x, y1, z).getBlock().setType(Material.getMaterial(SpleggBlock));

x = x+1;

}

if ((x == x2+1) && (z != z2+1)){

z = z+1;

x = x1;

}

}

} else

if ((x1>x2) && (z1<z2)){

while ((x != x2-1) && (z != z2+1)){

while (x != x2-1){

new Location(getServer().getWorld(World), x, y1, z).getBlock().setType(Material.getMaterial(SpleggBlock));

x = x-1;

}

if ((x == x2-1) && (z != z2+1)){

z = z+1;

x = x1;

}

}

} else

if ((x1<x2) && (z1>z2)){

while ((x != x2+1) && (z != z2-1)){

while (x != x2+1){

new Location(getServer().getWorld(World), x, y1, z).getBlock().setType(Material.getMaterial(SpleggBlock));

x = x+1;

}

if ((x == x2+1) && (z != z2-1)){

z = z-1;

x = x1;

}

}

} else

if ((x1>x2) && (z1>z2)){

while ((x != x2-1) && (z != z2-1)){

while (x != x2-1){

new Location(getServer().getWorld(World), x, y1, z).getBlock().setType(Material.getMaterial(SpleggBlock));

x = x-1;

}

if ((x == x2-1) && (z != z2-1)){

z = z-1;

x = x1;

}

}

}

}

}

inGame = false;

} catch(NullPointerException ex){



}

}

@EventHandler(priority = EventPriority.LOWEST)

public void onPlayerDropItemEvent(PlayerDropItemEvent e){

Player p = e.getPlayer();

if ((e.getItemDrop().getItemStack().getType() == Material.getMaterial(SpleggTool)) && (!p.hasPermission("dwarvencraftmc.splegg.drop")) && (isJoined.get(p.getDisplayName()) == true)){

e.setCancelled(true);

p.sendMessage("§cYou are not allowed to drop your SpleggTool!");

}

}



//EGG LAUNCH + ARENA SELECTION

@EventHandler( priority= EventPriority.LOWEST)

public void onPlayerInteractEvent(PlayerInteractEvent e) {

Player p = e.getPlayer();

Action a = e.getAction();

Block b = e.getClickedBlock();

Material m = p.getItemInHand().getType();

Material m2 = Material.getMaterial(SpleggTool);

Material m3 = Material.getMaterial(SelectionTool);

String w = p.getWorld().getName();

if((m == m2) && (p.hasPermission("dwarvencraftmc.splegg.use")) && ((a == Action.RIGHT_CLICK_BLOCK) || (a == Action.RIGHT_CLICK_AIR)) && (isJoined.get(p.getDisplayName()) == true) && (inGame == true)){

p.launchProjectile(Egg.class);

} else if((m == m3) && (p.hasPermission("dwarvencraftmc.splegg.select")) && (a == Action.LEFT_CLICK_BLOCK)){

Location l1 = b.getLocation();

int x1 = l1.getBlockX();

this.getConfig().set("x1", x1);

int y1 = l1.getBlockY();

this.getConfig().set("y1", y1);

int z1 = l1.getBlockZ();

this.getConfig().set("z1", z1);

String world = l1.getWorld().getName();

this.getConfig().set("World", world);

saveConfig();

e.setCancelled(true);

p.sendMessage("§aYou selected the first location: x: " + x1 + " y: " + y1 + " z: " + z1 + " World: " + world);

} else if((m == m3) && (p.hasPermission("dwarvencraftmc.splegg.select")) && (a == Action.RIGHT_CLICK_BLOCK)){

Location l2 = b.getLocation();

int x2 = l2.getBlockX();

this.getConfig().set("x2", x2);

int y2 = l2.getBlockY();

this.getConfig().set("y2", y2);

int z2 = l2.getBlockZ();

this.getConfig().set("z2", z2);

String world = l2.getWorld().getName();

saveConfig();

p.sendMessage("§aYou selected the second location: x: " + x2 + " y: " + y2 + " z: " + z2 + " World: " + world);



}

}



//EGG HITS BLOCK

@EventHandler( priority= EventPriority.LOWEST)

public void onHit(ProjectileHitEvent event) {

Entity e = event.getEntity();

String w = e.getWorld().getName();

if((e.getType() == EntityType.EGG) && (new String(w).equals("Minigames")) && (inGame == true)){

Location l = e.getLocation();

Vector vec = e.getVelocity();

Location l2 = new Location(l.getWorld(), l.getX()

+ vec.getX(), l.getY() + vec.getY(), l.getZ()

+ vec.getZ());

Block b = l2.getBlock();

Material m = b.getType();

Material m2 = Material.getMaterial(SpleggBlock);

if(m == m2){

b.setType(Material.AIR);

}

}

}

}

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...