Initial commit
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
package de.craftix.arenafight;
|
||||
|
||||
import de.craftix.arenafight.utils.*;
|
||||
import de.craftix.arenafight.utils.kit.KitAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameRule;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Main extends JavaPlugin {
|
||||
|
||||
private static Main instance;
|
||||
private static Setup setup;
|
||||
public static Gamestate state;
|
||||
|
||||
public static ArrayList<Player> inGame = new ArrayList<>();
|
||||
public static ArrayList<Player> spec = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
state = Gamestate.LOBBY;
|
||||
MySQL.connect();
|
||||
createTables();
|
||||
setup = new Setup(getInstance());
|
||||
KitAPI.setup();
|
||||
Wave.setup();
|
||||
|
||||
Gamemanager.setArena(Arena.getAllArenas().get(0));
|
||||
Location lobbyLoc = setup.getLobby();
|
||||
if (lobbyLoc != null){
|
||||
World lobby = lobbyLoc.getWorld();
|
||||
lobby.setMonsterSpawnLimit(100);
|
||||
lobby.setAnimalSpawnLimit(100);
|
||||
lobby.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false);
|
||||
lobby.setGameRule(GameRule.DO_WEATHER_CYCLE, false);
|
||||
lobby.setGameRule(GameRule.DO_MOB_SPAWNING, false);
|
||||
lobby.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false);
|
||||
lobby.setGameRule(GameRule.RANDOM_TICK_SPEED, 0);
|
||||
lobby.setTime(6000);
|
||||
for (Entity e : lobby.getEntities()) if (!(e instanceof Player)) e.remove();
|
||||
}
|
||||
|
||||
Stats.Setup();
|
||||
|
||||
getCommand("setup").setExecutor(setup);
|
||||
getCommand("addarena").setExecutor(setup);
|
||||
getCommand("delarena").setExecutor(setup);
|
||||
getCommand("setlobby").setExecutor(setup);
|
||||
getCommand("stats").setExecutor(new Stats(null));
|
||||
|
||||
PluginManager pm = Bukkit.getPluginManager();
|
||||
pm.registerEvents(setup, getInstance());
|
||||
pm.registerEvents(new Lobbymanager(), this);
|
||||
pm.registerEvents(new Gamemanager(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
MySQL.disconnect();
|
||||
for (Player p : Bukkit.getOnlinePlayers()) p.kickPlayer("§cServer restart");
|
||||
}
|
||||
|
||||
public static Main getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static Setup getSetup() {
|
||||
return setup;
|
||||
}
|
||||
|
||||
private void createTables(){
|
||||
//Arenas = Name, ID, Type, Location | Types: 1 = lobby, 2 = spawn, 3 = spec, 4 = MobSpawn
|
||||
MySQL.insert("CREATE TABLE IF NOT EXISTS Arenas (Name VARCHAR(100), ID INT(10), Type INT(10), x VARCHAR(100), y VARCHAR(100), z VARCHAR(100), yaw VARCHAR(100), pitch VARCHAR(100), world VARCHAR(100))");
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
package de.craftix.arenafight.utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Arena {
|
||||
|
||||
public static boolean checkName(String name){
|
||||
try {
|
||||
ResultSet rs = MySQL.getData("SELECT * FROM Arenas WHERE Name = \"" + name + "\"");
|
||||
rs.next();
|
||||
String test = rs.getString("Name");
|
||||
if (test != null) return false;
|
||||
}catch (Exception e){}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static int getNextID(){
|
||||
try {
|
||||
ResultSet rs = MySQL.getData("SELECT * FROM Arenas");
|
||||
ArrayList<Integer> ids = new ArrayList<>();
|
||||
while (rs.next()){
|
||||
ids.add(rs.getInt("ID"));
|
||||
}
|
||||
int id = 0;
|
||||
while (ids.contains(id)) id++;
|
||||
return id;
|
||||
}catch (Exception e) {}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static class ArenaTile {
|
||||
public String name;
|
||||
public int id;
|
||||
public int type;
|
||||
public Location loc;
|
||||
|
||||
public ArenaTile() {}
|
||||
public ArenaTile(String name, int id, int type, Location loc){
|
||||
this.name = name;
|
||||
this.id = id;
|
||||
this.type = type;
|
||||
this.loc = loc;
|
||||
}
|
||||
}
|
||||
|
||||
public static Arena getArena(String name){
|
||||
try {
|
||||
ResultSet rs = MySQL.getData("SELECT * FROM Arenas WHERE Name = \"" + name + "\"");
|
||||
ArrayList<ArenaTile> tiles = new ArrayList<>();
|
||||
while (rs.next()){
|
||||
ArenaTile tile = new ArenaTile();
|
||||
tile.name = rs.getString("Name");
|
||||
tile.id = rs.getInt("ID");
|
||||
tile.type = rs.getInt("Type");
|
||||
String x = rs.getString("x");
|
||||
String y = rs.getString("y");
|
||||
String z = rs.getString("z");
|
||||
String yaw = rs.getString("yaw");
|
||||
String pitch = rs.getString("pitch");
|
||||
String world = rs.getString("world");
|
||||
tile.loc = new Location(Bukkit.getWorld(world), Double.parseDouble(x), Double.parseDouble(y), Double.parseDouble(z), Float.parseFloat(yaw), Float.parseFloat(pitch));
|
||||
tiles.add(tile);
|
||||
}
|
||||
Arena arena = new Arena();
|
||||
arena.name = tiles.get(0).name;
|
||||
arena.id = tiles.get(0).id;
|
||||
for (ArenaTile tile : tiles){
|
||||
if (tile.type == 2){ //Spawn
|
||||
arena.spawn = tile.loc;
|
||||
}else if (tile.type == 3) { //Spectator
|
||||
arena.spec = tile.loc;
|
||||
}else if (tile.type == 4) { //MobSpawn
|
||||
arena.mobSpawns.add(tile.loc);
|
||||
}
|
||||
}
|
||||
return arena;
|
||||
}catch (Exception e) {}
|
||||
return null;
|
||||
}
|
||||
public static Arena getArena(int id){
|
||||
try {
|
||||
ResultSet rs = MySQL.getData("SELECT * FROM Arenas WHERE ID = " + id);
|
||||
ArrayList<ArenaTile> tiles = new ArrayList<>();
|
||||
while (rs.next()){
|
||||
ArenaTile tile = new ArenaTile();
|
||||
tile.name = rs.getString("Name");
|
||||
tile.id = rs.getInt("ID");
|
||||
tile.type = rs.getInt("Type");
|
||||
String x = rs.getString("x");
|
||||
String y = rs.getString("y");
|
||||
String z = rs.getString("z");
|
||||
String yaw = rs.getString("yaw");
|
||||
String pitch = rs.getString("pitch");
|
||||
String world = rs.getString("world");
|
||||
tile.loc = new Location(Bukkit.getWorld(world), Double.parseDouble(x), Double.parseDouble(y), Double.parseDouble(z), Float.parseFloat(yaw), Float.parseFloat(pitch));
|
||||
tiles.add(tile);
|
||||
}
|
||||
Arena arena = new Arena();
|
||||
arena.name = tiles.get(0).name;
|
||||
arena.id = tiles.get(0).id;
|
||||
for (ArenaTile tile : tiles){
|
||||
if (tile.type == 2){ //Spawn
|
||||
arena.spawn = tile.loc;
|
||||
}else if (tile.type == 3) { //Spectator
|
||||
arena.spec = tile.loc;
|
||||
}else if (tile.type == 4) { //MobSpawn
|
||||
arena.mobSpawns.add(tile.loc);
|
||||
}
|
||||
}
|
||||
return arena;
|
||||
}catch (Exception e) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ArrayList<Arena> getAllArenas(){
|
||||
try {
|
||||
ResultSet rs = MySQL.getData("SELECT * FROM Arenas");
|
||||
ArrayList<Integer> ids = new ArrayList<>();
|
||||
ArrayList<Arena> arenas = new ArrayList<>();
|
||||
while (rs.next()){
|
||||
if (rs.getInt("Type") == -1) continue;
|
||||
int id = rs.getInt("ID");
|
||||
if (ids.contains(id)) continue;
|
||||
ids.add(id);
|
||||
}
|
||||
for (int id : ids){
|
||||
arenas.add(getArena(id));
|
||||
}
|
||||
return arenas;
|
||||
}catch (Exception e) {}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
|
||||
public String name;
|
||||
public Integer id;
|
||||
public Location spawn;
|
||||
public Location spec;
|
||||
public ArrayList<Location> mobSpawns = new ArrayList<>();
|
||||
public ArrayList<Player> players = new ArrayList<>();
|
||||
public ArrayList<Player> spectators = new ArrayList<>();
|
||||
|
||||
public void delete(){
|
||||
MySQL.insert("DELETE FROM Arenas WHERE ID = " + id);
|
||||
}
|
||||
|
||||
public void save(){
|
||||
ArrayList<ArenaTile> tiles = convertToTiles();
|
||||
for (ArenaTile tile : tiles){
|
||||
String qry1 = "INSERT INTO Arenas (Name, ID, Type, x, y, z, yaw, pitch, world) VALUES (\"" + tile.name + "\", " + tile.id + ", " + tile.type + ", \"";
|
||||
String qry2 = tile.loc.getX() + "\", \"" + tile.loc.getY() + "\", \"" + tile.loc.getZ() + "\", \"" + tile.loc.getYaw() + "\", \"" + tile.loc.getPitch() + "\", \"";
|
||||
MySQL.insert(qry1 + qry2 + tile.loc.getWorld().getName() + "\")");
|
||||
}
|
||||
}
|
||||
|
||||
private ArrayList<ArenaTile> convertToTiles(){
|
||||
ArrayList<ArenaTile> tiles = new ArrayList<>();
|
||||
tiles.add(new ArenaTile(name, id, 2, spawn));
|
||||
tiles.add(new ArenaTile(name, id, 3, spec));
|
||||
for (Location loc : mobSpawns) tiles.add(new ArenaTile(name, id, 4, loc));
|
||||
return tiles;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
package de.craftix.arenafight.utils;
|
||||
|
||||
import de.craftix.arenafight.Main;
|
||||
import de.craftix.arenafight.utils.kit.Kit;
|
||||
import de.craftix.arenafight.utils.kit.KitAPI;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Gamemanager implements Listener {
|
||||
|
||||
public static HashMap<Player, Kit> playerKits = new HashMap<>();
|
||||
public static HashMap<Player, Integer> playerDeaths = new HashMap<>();
|
||||
private static Arena usedArena = null;
|
||||
public static int difficulty;
|
||||
private static ArrayList<Wave> waves = (ArrayList<Wave>) Wave.waves.clone();
|
||||
private static Wave currentWave;
|
||||
|
||||
public static Arena getRunningGame(){
|
||||
return usedArena;
|
||||
}
|
||||
|
||||
public static void setArena(Arena arena){usedArena = arena;}
|
||||
|
||||
public static void startGame(Arena arena){
|
||||
World world = arena.spawn.getWorld();
|
||||
world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false);
|
||||
world.setGameRule(GameRule.DO_WEATHER_CYCLE, false);
|
||||
world.setGameRule(GameRule.DO_MOB_SPAWNING, false);
|
||||
world.setGameRule(GameRule.RANDOM_TICK_SPEED, 0);
|
||||
world.setGameRule(GameRule.DO_FIRE_TICK, false);
|
||||
for (Entity e : world.getEntities()){
|
||||
if (!(e instanceof Player)) e.remove();
|
||||
}
|
||||
for (Player p : Main.inGame) {
|
||||
KitAPI.preparePlayer(p, playerKits.get(p));
|
||||
p.setPlayerTime(6000, false);
|
||||
Stats stats = Stats.getStats(p);
|
||||
stats.playedGames++;
|
||||
Stats.setStats(stats);
|
||||
}
|
||||
world.setTime(18000);
|
||||
world.setPVP(false);
|
||||
Wave wave = getNewWave();
|
||||
wave.summonWave(arena);
|
||||
currentWave = wave;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDeath(EntityDeathEvent e){
|
||||
if (Main.state != Gamestate.INGAME) return;
|
||||
if (currentWave.summonedEntities.contains(e.getEntity())){
|
||||
e.setDroppedExp(0);
|
||||
e.getDrops().clear();
|
||||
Player p = e.getEntity().getKiller();
|
||||
Stats stats = Stats.getStats(p);
|
||||
stats.kills++;
|
||||
Stats.setStats(stats);
|
||||
currentWave.summonedEntities.remove(e.getEntity());
|
||||
if (currentWave.summonedEntities.size() == 0){
|
||||
for (Player all : Main.inGame){
|
||||
Stats s = Stats.getStats(all);
|
||||
s.survivedWaves++;
|
||||
Stats.setStats(s);
|
||||
}
|
||||
Wave wave = getNewWave();
|
||||
if (wave == null){
|
||||
handleWinning();
|
||||
return;
|
||||
}
|
||||
wave.summonWave(usedArena);
|
||||
currentWave = wave;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDeathPlayer(PlayerDeathEvent e){
|
||||
Player p = e.getEntity();
|
||||
e.setKeepInventory(true);
|
||||
e.setDroppedExp(0);
|
||||
e.getDrops().clear();
|
||||
Stats stats = Stats.getStats(p);
|
||||
stats.deaths++;
|
||||
Stats.setStats(stats);
|
||||
if (difficulty == 0){
|
||||
int deaths = 0;
|
||||
try {deaths = playerDeaths.get(p) + 1;}
|
||||
catch (Exception exception) {}
|
||||
playerDeaths.remove(p);
|
||||
playerDeaths.put(p, deaths);
|
||||
if (deaths >= 3){
|
||||
p.getInventory().clear();
|
||||
p.setGameMode(GameMode.SPECTATOR);
|
||||
Main.inGame.remove(p);
|
||||
Main.spec.add(p);
|
||||
}else {
|
||||
p.teleport(usedArena.spawn);
|
||||
}
|
||||
if (Main.inGame.size() == 0){
|
||||
handleLoosing();
|
||||
}
|
||||
}else {
|
||||
p.getInventory().clear();
|
||||
p.setGameMode(GameMode.SPECTATOR);
|
||||
Main.inGame.remove(p);
|
||||
Main.spec.add(p);
|
||||
if (Main.inGame.size() == 0){
|
||||
handleLoosing();
|
||||
}
|
||||
}
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
p.spigot().respawn();
|
||||
}
|
||||
}, 20);
|
||||
}
|
||||
|
||||
private static Wave getNewWave(){
|
||||
if (waves.size() == 0) return null;
|
||||
Wave wave = waves.get(0);
|
||||
waves.remove(0);
|
||||
return wave;
|
||||
}
|
||||
|
||||
private static void handleWinning(){
|
||||
for (Player p : Main.inGame) {
|
||||
p.playSound(p.getLocation(), Sound.UI_TOAST_CHALLENGE_COMPLETE, SoundCategory.MASTER, 100, 1);
|
||||
p.sendTitle("§aHerzlichen Glückwunsch", "§aDu hast alle Wellen überstanden", 10, 200, 10);
|
||||
Stats stats = Stats.getStats(p);
|
||||
stats.wins++;
|
||||
Stats.setStats(stats);
|
||||
p.setPlayerTime(6000, false);
|
||||
}
|
||||
Lobbymanager.endGame();
|
||||
}
|
||||
|
||||
private static void handleLoosing(){
|
||||
for (Player p : Bukkit.getOnlinePlayers()) p.sendMessage("§cDu hast den Angriff der Monster nicht überstanden!");
|
||||
Lobbymanager.endGame();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package de.craftix.arenafight.utils;
|
||||
|
||||
public enum Gamestate {
|
||||
LOBBY,
|
||||
INGAME,
|
||||
RESTART
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package de.craftix.arenafight.utils;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ItemBuilder {
|
||||
|
||||
public Material material;
|
||||
public String name;
|
||||
public int amount = 1;
|
||||
public HashMap<Enchantment, Integer> enchantments = new HashMap<>();
|
||||
public boolean unbreakable = false;
|
||||
public ArrayList<String> lore = new ArrayList<>();
|
||||
|
||||
public ItemBuilder(Material mat){
|
||||
material = mat;
|
||||
}
|
||||
|
||||
public ItemBuilder(Material mat, int amount){
|
||||
material = mat;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public ItemBuilder setName(String name){
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder addEnchantment(Enchantment e, int level){
|
||||
enchantments.put(e, level);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder setUnbreakable(boolean value){
|
||||
unbreakable = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder setLore(String... lore){
|
||||
for (String s : lore){
|
||||
this.lore.add(s);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemStack create(){
|
||||
ItemStack item = new ItemStack(material, amount);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
for (Enchantment e : enchantments.keySet()){
|
||||
meta.addEnchant(e, enchantments.get(e), true);
|
||||
}
|
||||
meta.setLore(lore);
|
||||
meta.setDisplayName(name);
|
||||
meta.setUnbreakable(unbreakable);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,331 @@
|
||||
package de.craftix.arenafight.utils;
|
||||
|
||||
import de.craftix.arenafight.Main;
|
||||
import de.craftix.arenafight.utils.kit.Kit;
|
||||
import de.craftix.arenafight.utils.kit.KitAPI;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.EntityPickupItemEvent;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class Lobbymanager implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e){
|
||||
Stats.createStats(e.getPlayer());
|
||||
if (Main.state == Gamestate.LOBBY){
|
||||
e.getPlayer().setGameMode(GameMode.SURVIVAL);
|
||||
e.getPlayer().setHealth(20);
|
||||
e.getPlayer().setSaturation(5);
|
||||
e.getPlayer().setFoodLevel(20);
|
||||
Location lobby = Main.getSetup().getLobby();
|
||||
if (lobby != null) e.getPlayer().teleport(lobby);
|
||||
Main.inGame.add(e.getPlayer());
|
||||
e.setJoinMessage("§aDer Spieler §6" + e.getPlayer().getDisplayName() + " §ahat das Spiel betreten!");
|
||||
checkPlayerAmount(false);
|
||||
giveItems(e.getPlayer());
|
||||
Gamemanager.playerKits.put(e.getPlayer(), KitAPI.getKits().get(0));
|
||||
}
|
||||
if (Main.state == Gamestate.RESTART){
|
||||
e.setJoinMessage(null);
|
||||
e.getPlayer().kickPlayer("§cServer restart!");
|
||||
}
|
||||
if (Main.state == Gamestate.INGAME){
|
||||
e.setJoinMessage(null);
|
||||
e.getPlayer().setGameMode(GameMode.SPECTATOR);
|
||||
e.getPlayer().teleport(Gamemanager.getRunningGame().spec);
|
||||
Main.spec.add(e.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent e){
|
||||
if (Main.inGame.contains(e.getPlayer())){
|
||||
e.setQuitMessage("§aDer Spieler §6" + e.getPlayer().getDisplayName() + " §ahat das Spiel verlassen!");
|
||||
Main.inGame.remove(e.getPlayer());
|
||||
if (Main.state == Gamestate.INGAME && Main.inGame.size() == 0) Bukkit.getServer().shutdown();
|
||||
}else {
|
||||
Main.spec.remove(e.getPlayer());
|
||||
e.setQuitMessage(null);
|
||||
}
|
||||
}
|
||||
|
||||
private static int lobbyID;
|
||||
private static boolean isStarting = false;
|
||||
|
||||
private static void checkPlayerAmount(boolean start){
|
||||
if (isStarting) return;
|
||||
if (Main.inGame.size() >= 4 || start == true){
|
||||
isStarting = true;
|
||||
lobbyID = Bukkit.getScheduler().scheduleSyncRepeatingTask(Main.getInstance(), new Runnable() {
|
||||
private int maxTimer = 30;
|
||||
private int ramTimer = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
int sec = maxTimer - ramTimer;
|
||||
switch (sec){
|
||||
case 30: case 15: case 10: case 5: case 4: case 3: case 2: case 1:
|
||||
for (Player all : Main.inGame) all.sendMessage("§aDas Spiel beginnt in §6" + sec + " §aSekunden");
|
||||
break;
|
||||
}
|
||||
if (sec == 0){
|
||||
startGame();
|
||||
}
|
||||
ramTimer++;
|
||||
}
|
||||
}, 20, 20);
|
||||
}
|
||||
}
|
||||
|
||||
private static void giveItems(Player p){
|
||||
p.getInventory().setHelmet(null);
|
||||
p.getInventory().setChestplate(null);
|
||||
p.getInventory().setLeggings(null);
|
||||
p.getInventory().setBoots(null);
|
||||
p.getInventory().clear();
|
||||
ItemStack kit = new ItemBuilder(Material.DIAMOND_SWORD).setName("§aKlasse wählen").create();
|
||||
ItemStack map = new ItemBuilder(Material.GRASS_BLOCK).setName("§aMap wählen").create();
|
||||
ItemStack start = new ItemBuilder(Material.EMERALD).setName("§aSpiel starten").create();
|
||||
ItemStack difficulty = new ItemBuilder(Material.TOTEM_OF_UNDYING).setName("§aSchwierigkeitsgrad").create();
|
||||
p.getInventory().setItem(1, kit);
|
||||
p.getInventory().setItem(3, map);
|
||||
p.getInventory().setItem(5, start);
|
||||
p.getInventory().setItem(7, difficulty);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInteract(PlayerInteractEvent e){
|
||||
if (Main.state != Gamestate.LOBBY) return;
|
||||
if (e.getItem() == null) return;
|
||||
switch (e.getItem().getType()){
|
||||
case DIAMOND_SWORD:
|
||||
openKitGUI(e.getPlayer());
|
||||
break;
|
||||
case GRASS_BLOCK:
|
||||
if (isStarting){
|
||||
e.getPlayer().sendMessage("§aDas Spiel startet bereits, du kannst jetzt nichts mehr einstellen!");
|
||||
break;
|
||||
}
|
||||
openMapGUI(e.getPlayer());
|
||||
break;
|
||||
|
||||
case EMERALD:
|
||||
checkPlayerAmount(true);
|
||||
break;
|
||||
case TOTEM_OF_UNDYING:
|
||||
if (isStarting){
|
||||
e.getPlayer().sendMessage("§aDas Spiel startet bereits, du kannst jetzt nichts mehr einstellen!");
|
||||
break;
|
||||
}
|
||||
openDiffGUI(e.getPlayer());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static final String kitGUI = "§aKit wählen";
|
||||
private static final String mapGUI = "§aMap wählen";
|
||||
private static final String diffGUI = "§aSchwierigkeitsgrad";
|
||||
|
||||
private static void openKitGUI(Player p){
|
||||
Inventory inv = Bukkit.createInventory(null, 3*9, kitGUI);
|
||||
for (int i = 0; i < inv.getSize(); i++){
|
||||
inv.setItem(i, new ItemBuilder(Material.GRAY_STAINED_GLASS_PANE).setName(" ").create());
|
||||
}
|
||||
int slot = 0;
|
||||
for (Kit kit : KitAPI.getKits()){
|
||||
ItemBuilder builder = new ItemBuilder(kit.invMat).setName(kit.name);
|
||||
String helmet = "§7- §a" + kit.helmet.getType();
|
||||
builder.setLore(helmet);
|
||||
for (Enchantment e : kit.helmet.getEnchantments().keySet()){
|
||||
builder.setLore(" §7- §a" + e.getKey().getKey().replaceAll("minecraft:", "") + " - " + kit.helmet.getEnchantments().get(e));
|
||||
}
|
||||
String chestplate = "§7- §a" + kit.chestplate.getType();
|
||||
builder.setLore(chestplate);
|
||||
for (Enchantment e : kit.chestplate.getEnchantments().keySet()){
|
||||
builder.setLore(" §7- §a" + e.getKey().getKey().replaceAll("minecraft:", "") + " - " + kit.chestplate.getEnchantments().get(e));
|
||||
}
|
||||
String leggins = "§7- §a" + kit.leggins.getType();
|
||||
builder.setLore(leggins);
|
||||
for (Enchantment e : kit.leggins.getEnchantments().keySet()){
|
||||
builder.setLore(" §7- §a" + e.getKey().getKey().replaceAll("minecraft:", "") + " - " + kit.leggins.getEnchantments().get(e));
|
||||
}
|
||||
String boots = "§7- §a" + kit.boots.getType();
|
||||
builder.setLore(boots);
|
||||
for (Enchantment e : kit.boots.getEnchantments().keySet()){
|
||||
builder.setLore(" §7- §a" + e.getKey().getKey().replaceAll("minecraft:", "") + " - " + kit.boots.getEnchantments().get(e));
|
||||
}
|
||||
for (ItemStack i : kit.items.values()){
|
||||
builder.setLore("§7- §a" + i.getType());
|
||||
for (Enchantment e : i.getEnchantments().keySet()){
|
||||
builder.setLore(" §7- §a" + e.getKey().getKey().replaceAll("minecraft:", "") + " - " + i.getEnchantments().get(e));
|
||||
}
|
||||
}
|
||||
inv.setItem(slot, builder.create());
|
||||
slot++;
|
||||
}
|
||||
p.openInventory(inv);
|
||||
}
|
||||
|
||||
private static void openMapGUI(Player p){
|
||||
Inventory inv = Bukkit.createInventory(null, 3*9, mapGUI);
|
||||
for (int i = 0; i < inv.getSize(); i++){
|
||||
inv.setItem(i, new ItemBuilder(Material.GRAY_STAINED_GLASS_PANE).setName(" ").create());
|
||||
}
|
||||
int slot = 0;
|
||||
for (Arena arena : Arena.getAllArenas()){
|
||||
if (arena == null) continue;
|
||||
inv.setItem(slot, new ItemBuilder(Material.GRASS_BLOCK).setName(arena.name).create());
|
||||
slot++;
|
||||
}
|
||||
p.openInventory(inv);
|
||||
}
|
||||
|
||||
private static void openDiffGUI(Player p){
|
||||
Inventory inv = Bukkit.createInventory(null, 3*9, diffGUI);
|
||||
for (int i = 0; i < inv.getSize(); i++){
|
||||
inv.setItem(i, new ItemBuilder(Material.GRAY_STAINED_GLASS_PANE).setName(" ").create());
|
||||
}
|
||||
inv.setItem(10, new ItemBuilder(Material.IRON_INGOT).setName("§aEinfach").setLore("§7- §a3 Leben", "§7- §aKein Hunger").create());
|
||||
inv.setItem(13, new ItemBuilder(Material.DIAMOND).setName("§eNormal").setLore("§7- §e1 Leben", "§7- §eKein Hunger").create());
|
||||
inv.setItem(16, new ItemBuilder(Material.NETHER_STAR).setName("§4Schwer").setLore("§7- §41 Leben", "§7- §4Hunger").create());
|
||||
p.openInventory(inv);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInvClick(InventoryClickEvent e){
|
||||
Player p = (Player) e.getWhoClicked();
|
||||
if (e.getClickedInventory() == null) return;
|
||||
if (e.getCurrentItem() == null) return;
|
||||
if (e.getView().getTitle().equals(kitGUI)){
|
||||
e.setCancelled(true);
|
||||
if (e.getCurrentItem().getType().equals(Material.GRAY_STAINED_GLASS_PANE)) return;
|
||||
p.closeInventory();
|
||||
Kit kit;
|
||||
kit = KitAPI.getKit(e.getCurrentItem().getItemMeta().getDisplayName());
|
||||
Gamemanager.playerKits.remove(p);
|
||||
Gamemanager.playerKits.put(p, kit);
|
||||
p.sendMessage("§aDu hast das Kit §6" + kit.name + " §aausgewählt");
|
||||
}else if (e.getView().getTitle().equals(mapGUI)){
|
||||
e.setCancelled(true);
|
||||
if (e.getCurrentItem().getType().equals(Material.GRAY_STAINED_GLASS_PANE)) return;
|
||||
p.closeInventory();
|
||||
Arena arena;
|
||||
arena = Arena.getArena(e.getCurrentItem().getItemMeta().getDisplayName());
|
||||
Gamemanager.setArena(arena);
|
||||
p.sendMessage("§aDu hast die Map §6" + arena.name + " §aausgewählt");
|
||||
}else if (e.getView().getTitle().equals(diffGUI)){
|
||||
e.setCancelled(true);
|
||||
switch (e.getCurrentItem().getType()){
|
||||
case IRON_INGOT:
|
||||
Gamemanager.difficulty = 0;
|
||||
break;
|
||||
case DIAMOND:
|
||||
Gamemanager.difficulty = 1;
|
||||
break;
|
||||
case NETHER_STAR:
|
||||
Gamemanager.difficulty = 2;
|
||||
break;
|
||||
}
|
||||
p.closeInventory();
|
||||
p.sendMessage("§aDu hast den Modus §r" + e.getCurrentItem().getItemMeta().getDisplayName() + " §agewählt!");
|
||||
}
|
||||
}
|
||||
|
||||
private static void startGame(){
|
||||
Bukkit.getScheduler().cancelTask(lobbyID);
|
||||
Main.state = Gamestate.INGAME;
|
||||
Arena arena = Gamemanager.getRunningGame();
|
||||
for (Player all : Main.inGame) {
|
||||
all.teleport(arena.spawn);
|
||||
all.sendMessage("§aEinstellungen:");
|
||||
all.sendMessage("§aMap: §6" + arena.name);
|
||||
if (Gamemanager.difficulty == 0){
|
||||
all.sendMessage("§aSchwierigkeitsgrad: §6Einfach");
|
||||
}else if (Gamemanager.difficulty == 1){
|
||||
all.sendMessage("§aSchwierigkeitsgrad: §6Normal");
|
||||
}else if (Gamemanager.difficulty == 2){
|
||||
all.sendMessage("§aSchwierigkeitsgrad: §6Schwer");
|
||||
}
|
||||
}
|
||||
Gamemanager.startGame(arena);
|
||||
}
|
||||
|
||||
public static void endGame(){
|
||||
Main.state = Gamestate.RESTART;
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
p.teleport(Main.getSetup().getLobby());
|
||||
p.setGameMode(GameMode.SURVIVAL);
|
||||
}
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(Main.getInstance(), new Runnable() {
|
||||
private int maxTimer = 10;
|
||||
private int ramTimer = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
int sec = maxTimer - ramTimer;
|
||||
switch (sec){
|
||||
case 10: case 5: case 4: case 3: case 2: case 1:
|
||||
for (Player p : Bukkit.getOnlinePlayers()) p.sendMessage("§aDer Server stoppt in §6" + sec + " §aSekunden!");
|
||||
}
|
||||
if (sec <= 0) Bukkit.getServer().shutdown();
|
||||
ramTimer++;
|
||||
}
|
||||
}, 20, 20);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onBuild(BlockPlaceEvent e){
|
||||
if (Main.state != Gamestate.INGAME) e.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBreak(BlockBreakEvent e){
|
||||
if (Main.state != Gamestate.INGAME) e.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDamage(EntityDamageEvent e){
|
||||
if (Main.state != Gamestate.INGAME) e.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockExplode(EntityExplodeEvent e){
|
||||
e.blockList().clear();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onFood(FoodLevelChangeEvent e){
|
||||
if (Main.state == Gamestate.INGAME && Gamemanager.difficulty == 2) return;
|
||||
e.setCancelled(true);
|
||||
Player p = (Player) e.getEntity();
|
||||
p.setFoodLevel(20);
|
||||
p.setSaturation(5);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDrop(PlayerDropItemEvent e){
|
||||
if (Main.state != Gamestate.INGAME) e.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPickUp(EntityPickupItemEvent e){
|
||||
if (Main.state != Gamestate.INGAME) e.setCancelled(true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package de.craftix.arenafight.utils;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class MySQL {
|
||||
|
||||
public static final String server = "localhost";
|
||||
public static final Integer port = 3306;
|
||||
public static final String db = "leon";
|
||||
public static final String user = "leon";
|
||||
public static final String pass = "1234567890";
|
||||
private static Connection con = null;
|
||||
|
||||
public static boolean connect(){
|
||||
String conString = "jdbc:mysql://" + server + ":" + port + "/" + db;
|
||||
try {
|
||||
con = DriverManager.getConnection(conString, user, pass);
|
||||
System.out.println("[ArenaFight] MySQL connected");
|
||||
return true;
|
||||
}catch (SQLException e){
|
||||
System.out.println("[ArenaFight] MySQL connection failed");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean disconnect(){
|
||||
if (!isConnected()) return true;
|
||||
try {
|
||||
con.close();
|
||||
con = null;
|
||||
System.out.println("[ArenaFight] MySQL disconnected");
|
||||
return true;
|
||||
}catch (SQLException e){
|
||||
System.out.println("[ArenaFight] MySQL disconnecting failed");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isConnected(){
|
||||
if (con == null) return false;
|
||||
else return true;
|
||||
}
|
||||
|
||||
public static void insert(String qry){
|
||||
try {
|
||||
con.prepareStatement(qry).executeUpdate();
|
||||
}catch (SQLException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static ResultSet getData(String qry){
|
||||
try {
|
||||
return con.prepareStatement(qry).executeQuery();
|
||||
}catch (SQLException e){
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
package de.craftix.arenafight.utils;
|
||||
|
||||
import de.craftix.arenafight.Main;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
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.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Setup implements Listener, CommandExecutor {
|
||||
|
||||
private static Main plugin;
|
||||
public Setup(Main pl){
|
||||
plugin = pl;
|
||||
}
|
||||
|
||||
public ArrayList<Arena> setupArenas = new ArrayList<>();
|
||||
public HashMap<Player, Arena> setupPlayers = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command c, String s, String[] args) {
|
||||
if (!(sender instanceof Player)) return true;
|
||||
if (!sender.hasPermission("arenafight.setup")) return true;
|
||||
Player p = (Player)sender;
|
||||
|
||||
//addarena
|
||||
if (c.getName().equals("addarena")){
|
||||
if (args.length != 1) return true;
|
||||
if (Arena.checkName(args[0])){
|
||||
Arena arena = new Arena();
|
||||
arena.name = args[0];
|
||||
arena.id = Arena.getNextID();
|
||||
setupArenas.add(arena);
|
||||
p.sendMessage("§aDie Arena §6" + arena.name + " §awurde erfolgreich erstellt!");
|
||||
}else {
|
||||
p.sendMessage("§cDieser Name ist bereits vergeben!");
|
||||
}
|
||||
}
|
||||
|
||||
//delarena
|
||||
if (c.getName().equals("delarena")){
|
||||
if (args.length != 1) return true;
|
||||
Arena arena = Arena.getArena(args[0]);
|
||||
if (arena != null){
|
||||
arena.delete();
|
||||
p.sendMessage("§aDie Arena §6" + arena.name + " §awurde gelöscht!");
|
||||
}else p.sendMessage("§cDiese Arena existiert nicht!");
|
||||
}
|
||||
|
||||
//setup
|
||||
if (c.getName().equals("setup")){
|
||||
if (args.length != 1) return true;
|
||||
Arena arena = null;
|
||||
for (Arena all : setupArenas){
|
||||
if (all.name.equalsIgnoreCase(args[0])) arena = all;
|
||||
}
|
||||
if (arena != null){
|
||||
if (setupPlayers.containsKey(p)){
|
||||
setupPlayers.remove(p);
|
||||
p.getInventory().clear();
|
||||
arena.save();
|
||||
p.sendMessage("§aSetup abgeschlossen!");
|
||||
}else {
|
||||
giveInv(p);
|
||||
setupPlayers.put(p, arena);
|
||||
p.sendMessage("§aSetup für §6" + arena.name + " §agestartet!");
|
||||
}
|
||||
}else p.sendMessage("§cDiese Arena existiert nicht");
|
||||
}
|
||||
|
||||
//setlobby
|
||||
if (c.getName().equals("setlobby")){
|
||||
Location l = p.getLocation();
|
||||
MySQL.insert("DELETE FROM Arenas WHERE ID = -1");
|
||||
MySQL.insert("INSERT INTO Arenas (Type, x, y, z, yaw, pitch, world) VALUES (0, \"" + l.getX() + "\", \"" + l.getY() + "\", \"" + l.getZ() + "\", \"" + l.getYaw() + "\", \"" + l.getPitch() + "\", \"" + l.getWorld().getName() + "\")");
|
||||
p.sendMessage("§aDie Lobby wurde gesetzt");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void giveInv(Player p){
|
||||
p.getInventory().clear();
|
||||
p.getInventory().setItem(1, new ItemBuilder(Material.DIAMOND).setName("Spawn").create());
|
||||
p.getInventory().setItem(2, new ItemBuilder(Material.GLASS_PANE).setName("Spectator").create());
|
||||
p.getInventory().setItem(3, new ItemBuilder(Material.ROTTEN_FLESH).setName("Monsterspawn").create());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInteract(PlayerInteractEvent event){
|
||||
if (!setupPlayers.containsKey(event.getPlayer())) return;
|
||||
event.setCancelled(true);
|
||||
Arena arena = setupPlayers.get(event.getPlayer());
|
||||
Player p = event.getPlayer();
|
||||
|
||||
switch (p.getInventory().getHeldItemSlot()){
|
||||
case 1:
|
||||
arena.spawn = p.getLocation();
|
||||
break;
|
||||
case 2:
|
||||
arena.spec = p.getLocation();
|
||||
break;
|
||||
case 3:
|
||||
arena.mobSpawns.add(p.getLocation());
|
||||
}
|
||||
|
||||
p.sendMessage("§aPosition hinzugefügt!");
|
||||
}
|
||||
|
||||
public Location getLobby(){
|
||||
try {
|
||||
ResultSet rs = MySQL.getData("SELECT * FROM Arenas WHERE Type = 0");
|
||||
if (rs.next()){
|
||||
String x = rs.getString("x");
|
||||
String y = rs.getString("y");
|
||||
String z = rs.getString("z");
|
||||
String yaw = rs.getString("yaw");
|
||||
String pitch = rs.getString("pitch");
|
||||
String world = rs.getString("world");
|
||||
return new Location(Bukkit.getWorld(world), Double.parseDouble(x), Double.parseDouble(y), Double.parseDouble(z), Float.parseFloat(yaw), Float.parseFloat(pitch));
|
||||
}
|
||||
}catch (Exception ignored) {}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package de.craftix.arenafight.utils;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
|
||||
public class Stats implements CommandExecutor {
|
||||
|
||||
public static void Setup(){
|
||||
MySQL.insert("CREATE TABLE IF NOT EXISTS Stats (UUID VARCHAR(100), Kills INT(10), Deaths INT(10), SW INT(10), PG INT(10), Wins INT(10))");
|
||||
}
|
||||
|
||||
public static Stats getStats(Player p){
|
||||
try {
|
||||
ResultSet rs = MySQL.getData("SELECT * FROM Stats WHERE UUID = \"" + p.getUniqueId().toString() + "\"");
|
||||
rs.next();
|
||||
Stats stats = new Stats(p);
|
||||
stats.kills = rs.getInt("Kills");
|
||||
stats.deaths = rs.getInt("Deaths");
|
||||
stats.survivedWaves = rs.getInt("SW");
|
||||
stats.playedGames = rs.getInt("PG");
|
||||
stats.wins = rs.getInt("Wins");
|
||||
return stats;
|
||||
}catch (Exception e) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void setStats(Stats stats){
|
||||
MySQL.insert("DELETE FROM Stats WHERE UUID = \"" + stats.p.getUniqueId().toString() + "\"");
|
||||
String qry1 = "INSERT INTO Stats (UUID, Kills, Deaths, SW, PG, Wins) VALUES (\"" + stats.p.getUniqueId().toString() + "\", ";
|
||||
String qry2 = stats.kills + ", " + stats.deaths + ", " + stats.survivedWaves + ", " + stats.playedGames + ", " + stats.wins + ")";
|
||||
MySQL.insert(qry1 + qry2);
|
||||
}
|
||||
|
||||
public static void createStats(Player p){
|
||||
if (getStats(p) == null) setStats(new Stats(p));
|
||||
}
|
||||
|
||||
|
||||
//nonStatic
|
||||
public Player p;
|
||||
public int kills = 0;
|
||||
public int deaths = 0;
|
||||
public int survivedWaves = 0;
|
||||
public int playedGames = 0;
|
||||
public int wins = 0;
|
||||
|
||||
public Stats(Player p){
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
|
||||
if (!(sender instanceof Player)) return true;
|
||||
Player p = (Player) sender;
|
||||
createStats(p);
|
||||
Stats stats = getStats(p);
|
||||
System.out.println(stats);
|
||||
p.sendMessage("§a--------------§6Stats§a--------------");
|
||||
p.sendMessage("§aKills: §6" + stats.kills);
|
||||
p.sendMessage("§aTode: §6" + stats.deaths);
|
||||
p.sendMessage("§aÜberlebte Wellen: §6" + stats.survivedWaves);
|
||||
p.sendMessage("§aGespielte Spiele: §6" + stats.playedGames);
|
||||
p.sendMessage("§aGewonnene Spiele: §6" + stats.wins);
|
||||
p.sendMessage("§a---------------------------------");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package de.craftix.arenafight.utils;
|
||||
|
||||
import de.craftix.arenafight.Main;
|
||||
import net.minecraft.server.v1_16_R3.EnumItemSlot;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
public class Wave {
|
||||
|
||||
//static
|
||||
public static ArrayList<Wave> waves = new ArrayList<>();
|
||||
|
||||
public static void setup(){
|
||||
//test
|
||||
Wave test = new Wave();
|
||||
ItemStack hand = new ItemBuilder(Material.DIAMOND_SWORD).addEnchantment(Enchantment.DAMAGE_ALL, 1).create();
|
||||
ItemStack helmet = new ItemBuilder(Material.DIAMOND_HELMET).create();
|
||||
test.addEntity(EntityType.ZOMBIE, 0).setHand(hand).setArmor(helmet, null, null, null).saveEntity();
|
||||
test.save();
|
||||
//test 2
|
||||
Wave test2 = new Wave();
|
||||
ItemStack hand2 = new ItemBuilder(Material.DIAMOND_SWORD).addEnchantment(Enchantment.DAMAGE_ALL, 5).create();
|
||||
ItemStack helmet2 = new ItemBuilder(Material.DIAMOND_HELMET).addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 4).create();
|
||||
ItemStack chestplate2 = new ItemBuilder(Material.DIAMOND_CHESTPLATE).addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 4).create();
|
||||
ItemStack leggins2 = new ItemBuilder(Material.DIAMOND_LEGGINGS).addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 4).create();
|
||||
ItemStack boots2 = new ItemBuilder(Material.DIAMOND_BOOTS).addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 4).create();
|
||||
test2.addEntity(EntityType.ZOMBIE, 0).setHand(hand2).setArmor(helmet2, chestplate2, leggins2, boots2).saveEntity().setTime(18000);
|
||||
test2.save();
|
||||
}
|
||||
|
||||
//nonStatic
|
||||
|
||||
class WaveEntity{
|
||||
public ItemStack helmet;
|
||||
public ItemStack chestplate;
|
||||
public ItemStack leggins;
|
||||
public ItemStack boots;
|
||||
public ItemStack hand;
|
||||
public EntityType type;
|
||||
public Integer id;
|
||||
private Wave wave;
|
||||
|
||||
public WaveEntity(Wave wave, EntityType type, int id){
|
||||
this.wave = wave;
|
||||
this.type = type;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public WaveEntity setArmor(ItemStack helmet, ItemStack chestplate, ItemStack leggins, ItemStack boots){
|
||||
this.helmet = helmet;
|
||||
this.chestplate = chestplate;
|
||||
this.leggins = leggins;
|
||||
this.boots = boots;
|
||||
return this;
|
||||
}
|
||||
|
||||
public WaveEntity setHand(ItemStack hand){
|
||||
this.hand = hand;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Wave saveEntity(){
|
||||
entities.add(this);
|
||||
return wave;
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<WaveEntity> entities = new ArrayList<>();
|
||||
|
||||
public void save(){
|
||||
waves.add(this);
|
||||
}
|
||||
|
||||
public WaveEntity addEntity(EntityType type, int id){
|
||||
return new WaveEntity(this, type, id);
|
||||
}
|
||||
|
||||
public Wave setTime(Integer time){
|
||||
this.time = time;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArrayList<LivingEntity> summonedEntities = new ArrayList<>();
|
||||
|
||||
public int time = 6000;
|
||||
|
||||
public void summonWave(Arena arena){
|
||||
for (Player p : Main.inGame) p.setPlayerTime(time, false);
|
||||
for (WaveEntity e : entities){
|
||||
Location spawn = arena.mobSpawns.get(new Random().nextInt(arena.mobSpawns.size() - 1));
|
||||
CraftLivingEntity entity = (CraftLivingEntity) spawn.getWorld().spawnEntity(spawn, e.type);
|
||||
entity.getHandle().setSlot(EnumItemSlot.MAINHAND, CraftItemStack.asNMSCopy(e.hand));
|
||||
entity.getHandle().setSlot(EnumItemSlot.FEET, CraftItemStack.asNMSCopy(e.boots));
|
||||
entity.getHandle().setSlot(EnumItemSlot.LEGS, CraftItemStack.asNMSCopy(e.leggins));
|
||||
entity.getHandle().setSlot(EnumItemSlot.CHEST, CraftItemStack.asNMSCopy(e.chestplate));
|
||||
entity.getHandle().setSlot(EnumItemSlot.HEAD, CraftItemStack.asNMSCopy(e.helmet));
|
||||
summonedEntities.add(entity);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package de.craftix.arenafight.utils.kit;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Kit {
|
||||
|
||||
public String name;
|
||||
public ItemStack helmet;
|
||||
public ItemStack chestplate;
|
||||
public ItemStack leggins;
|
||||
public ItemStack boots;
|
||||
public HashMap<Integer, ItemStack> items = new HashMap<>();
|
||||
public Material invMat;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package de.craftix.arenafight.utils.kit;
|
||||
|
||||
import de.craftix.arenafight.utils.Gamemanager;
|
||||
import de.craftix.arenafight.utils.ItemBuilder;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class KitAPI {
|
||||
|
||||
private static ArrayList<Kit> kits = new ArrayList<>();
|
||||
|
||||
public static ArrayList<Kit> getKits() {
|
||||
return kits;
|
||||
}
|
||||
|
||||
public static Kit getKit(String name){
|
||||
for (Kit kit : kits){
|
||||
if (kit.name.equalsIgnoreCase(name)) return kit;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void addKit(Kit kit){
|
||||
kits.add(kit);
|
||||
}
|
||||
|
||||
public static void preparePlayer(Player p, Kit kit){
|
||||
p.getInventory().clear();
|
||||
p.getInventory().setBoots(kit.boots);
|
||||
p.getInventory().setLeggings(kit.leggins);
|
||||
p.getInventory().setChestplate(kit.chestplate);
|
||||
p.getInventory().setHelmet(kit.helmet);
|
||||
for (int slot : kit.items.keySet()){
|
||||
p.getInventory().setItem(slot, kit.items.get(slot));
|
||||
}
|
||||
if (Gamemanager.difficulty == 2){
|
||||
p.getInventory().addItem(new ItemStack(Material.COOKED_BEEF, 32));
|
||||
}
|
||||
}
|
||||
|
||||
public static void setup(){
|
||||
//Assasine
|
||||
ItemStack aHelmet = new ItemBuilder(Material.LEATHER_HELMET).addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1).setUnbreakable(true).create();
|
||||
ItemStack aChestplate = new ItemBuilder(Material.LEATHER_CHESTPLATE).addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1).setUnbreakable(true).create();
|
||||
ItemStack aLeggins = new ItemBuilder(Material.LEATHER_LEGGINGS).addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1).setUnbreakable(true).create();
|
||||
ItemStack aBoots = new ItemBuilder(Material.LEATHER_BOOTS).addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1).setUnbreakable(true).create();
|
||||
ItemStack aSword = new ItemBuilder(Material.DIAMOND_SWORD).addEnchantment(Enchantment.DAMAGE_ALL, 3).setUnbreakable(true).create();
|
||||
ItemStack aShield = new ItemBuilder(Material.SHIELD).setUnbreakable(true).create();
|
||||
addKit(new KitAPI("Assasine").setArmor(aHelmet, aChestplate, aLeggins, aBoots).setItem(0, aSword).setItem(40, aShield).createKit(Material.DIAMOND_SWORD));
|
||||
//Sniper
|
||||
ItemStack sSword = new ItemBuilder(Material.WOODEN_SWORD).addEnchantment(Enchantment.DURABILITY, 1).create();
|
||||
ItemStack sBow = new ItemBuilder(Material.BOW).addEnchantment(Enchantment.ARROW_INFINITE, 1).addEnchantment(Enchantment.ARROW_DAMAGE, 3).create();
|
||||
ItemStack sArrow = new ItemStack(Material.ARROW);
|
||||
ItemStack sHelmet = new ItemBuilder(Material.CHAINMAIL_HELMET).addEnchantment(Enchantment.PROTECTION_PROJECTILE, 4).setUnbreakable(true).create();
|
||||
ItemStack sChestplate = new ItemBuilder(Material.CHAINMAIL_CHESTPLATE).addEnchantment(Enchantment.PROTECTION_PROJECTILE, 4).setUnbreakable(true).create();
|
||||
ItemStack sLeggins = new ItemBuilder(Material.CHAINMAIL_LEGGINGS).addEnchantment(Enchantment.PROTECTION_PROJECTILE, 4).setUnbreakable(true).create();
|
||||
ItemStack sBoots = new ItemBuilder(Material.CHAINMAIL_BOOTS).addEnchantment(Enchantment.PROTECTION_PROJECTILE, 4).setUnbreakable(true).create();
|
||||
addKit(new KitAPI("Sniper").setArmor(sHelmet, sChestplate, sLeggins, sBoots).setItem(0, sSword).setItem(1, sBow).setItem(9, sArrow).createKit(Material.BOW));
|
||||
//Tank
|
||||
ItemStack tHelmet = new ItemBuilder(Material.DIAMOND_HELMET).addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 2).setUnbreakable(true).create();
|
||||
ItemStack tChestplate = new ItemBuilder(Material.DIAMOND_CHESTPLATE).addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 2).setUnbreakable(true).create();
|
||||
ItemStack tLeggins = new ItemBuilder(Material.DIAMOND_LEGGINGS).addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 2).setUnbreakable(true).create();
|
||||
ItemStack tBoots = new ItemBuilder(Material.DIAMOND_BOOTS).addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 2).setUnbreakable(true).create();
|
||||
ItemStack tSword = new ItemBuilder(Material.IRON_SWORD).addEnchantment(Enchantment.DAMAGE_ALL, 2).setUnbreakable(true).create();
|
||||
ItemStack tShield = new ItemBuilder(Material.SHIELD).setUnbreakable(true).create();
|
||||
ItemStack tTNT = new ItemBuilder(Material.TNT, 32).create();
|
||||
ItemStack tFNS = new ItemBuilder(Material.FLINT_AND_STEEL).setUnbreakable(true).create();
|
||||
addKit(new KitAPI("Tank").setArmor(tHelmet, tChestplate, tLeggins, tBoots).setItem(0, tSword).setItem(1, tTNT).setItem(2, tFNS).setItem(40, tShield).createKit(Material.DIAMOND_CHESTPLATE));
|
||||
}
|
||||
|
||||
//nonStatic
|
||||
public String name;
|
||||
public ItemStack helmet;
|
||||
public ItemStack chestplate;
|
||||
public ItemStack leggins;
|
||||
public ItemStack boots;
|
||||
public HashMap<Integer, ItemStack> items = new HashMap<>();
|
||||
|
||||
public KitAPI(String name){
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public KitAPI setArmor(ItemStack helmet, ItemStack chestplate, ItemStack leggins, ItemStack boots){
|
||||
this.helmet = helmet;
|
||||
this.chestplate = chestplate;
|
||||
this.leggins = leggins;
|
||||
this.boots = boots;
|
||||
return this;
|
||||
}
|
||||
|
||||
public KitAPI setItem (int slot, ItemStack item){
|
||||
items.put(slot, item);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Kit createKit(Material mat){
|
||||
Kit kit = new Kit();
|
||||
kit.helmet = helmet;
|
||||
kit.chestplate = chestplate;
|
||||
kit.leggins = leggins;
|
||||
kit.boots = boots;
|
||||
kit.name = name;
|
||||
kit.items = items;
|
||||
kit.invMat = mat;
|
||||
return kit;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user