Added Team system & Guis

This commit is contained in:
BunSLaPatate
2018-09-14 22:21:30 +02:00
parent 2714efbba3
commit f369ead3ab
17 changed files with 562 additions and 97 deletions

View File

@@ -1,8 +1,10 @@
package net.berrygames.witchrush;
import net.berrygames.witchrush.game.GameState;
import net.berrygames.witchrush.tools.ItemFactory;
import net.berrygames.witchrush.tools.Locations;
import org.bukkit.Color;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@@ -47,6 +49,16 @@ public class WitchPlayer {
}
public void sendWaitingStuff() {
player.getInventory().setItem(8, new ItemFactory(Material.BED)
.withName("§cRetour au Hub !")
.withColor(DyeColor.RED)
.done());
player.getInventory().setItem(4, new ItemFactory(Material.ARMOR_STAND)
.withName("§dTeams")
.done());
}
public void sendGameScoreboard(){
}
@@ -102,5 +114,4 @@ public class WitchPlayer {
static {
WitchPlayer.witchMap = new HashMap<>();
}
}

View File

@@ -3,6 +3,7 @@ package net.berrygames.witchrush;
import net.berrygames.witchrush.commands.CommandsManager;
import net.berrygames.witchrush.game.GameState;
import net.berrygames.witchrush.listeners.ListenersManager;
import net.berrygames.witchrush.team.TeamManager;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
@@ -13,12 +14,14 @@ public class WitchRush extends JavaPlugin {
private static WitchRush instance;
private GameState gameState;
private TeamManager teamManager;
@Override
public void onEnable() {
instance = this;
this.gameState = GameState.WAITING;
this.teamManager = new TeamManager();
new CommandsManager().register(this);
new ListenersManager().register(this);
@@ -51,6 +54,9 @@ public class WitchRush extends JavaPlugin {
public GameState getState(){
return this.gameState;
}
public TeamManager getTeamManager() {
return teamManager;
}
public static WitchRush get() {
return instance;

View File

@@ -1,8 +1,9 @@
package net.berrygames.witchrush.commands.admins;
import net.berrygames.witchrush.tools.SpawnPNJ;
import net.berrygames.witchrush.team.TeamInfos;
import net.berrygames.witchrush.tools.PNJSpawner;
import net.berrygames.witchrush.tools.Locations;
import net.berrygames.witchrush.tools.SpawnWitch;
import net.berrygames.witchrush.tools.WitchBoss;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@@ -12,26 +13,27 @@ public class TestCMD implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(args[0].equals("shop")){
//Spawn SHOP
new SpawnPNJ("S bleu", Locations.SHOP_BLEU.getLocation()).spawn();
new SpawnPNJ("S rouge", Locations.SHOP_ROUGE.getLocation()).spawn();
new SpawnPNJ("S vert", Locations.SHOP_VERT.getLocation()).spawn();
new SpawnPNJ("S jaune", Locations.SHOP_JAUNE.getLocation()).spawn();
//Spawn SHOP
new PNJSpawner("§6§lSHOP", TeamInfos.BLEU, Locations.SHOP_BLEU.getLocation());
new PNJSpawner("§6§lSHOP", TeamInfos.ROUGE, Locations.SHOP_ROUGE.getLocation());
new PNJSpawner("§6§lSHOP", TeamInfos.VERT, Locations.SHOP_VERT.getLocation());
new PNJSpawner("§6§lSHOP", TeamInfos.JAUNE, Locations.SHOP_JAUNE.getLocation());
}
if(args[0].equals("up")){
//Spawn UPGRADE
new SpawnPNJ("U bleu", Locations.UPGRADE_BLEU.getLocation()).spawn();
new SpawnPNJ("U rouge", Locations.UPGRADE_ROUGE.getLocation()).spawn();
new SpawnPNJ("U vert", Locations.UPGRADE_VERT.getLocation()).spawn();
new SpawnPNJ("U jaune", Locations.UPGRADE_JAUNE.getLocation()).spawn();
new PNJSpawner("§b§LUPGRADE", TeamInfos.JAUNE, Locations.UPGRADE_BLEU.getLocation());
new PNJSpawner("§b§LUPGRADE", TeamInfos.ROUGE, Locations.UPGRADE_ROUGE.getLocation());
new PNJSpawner("§b§LUPGRADE", TeamInfos.VERT, Locations.UPGRADE_VERT.getLocation());
new PNJSpawner("§b§LUPGRADE", TeamInfos.JAUNE, Locations.UPGRADE_JAUNE.getLocation());
}
if(args[0].equals("w")){
new SpawnWitch("W Rouge", Locations.WITCH_ROUGE.getLocation()).spawn();
new SpawnWitch("W Bleu", Locations.WITCH_BLEU.getLocation()).spawn();
new SpawnWitch("W Vert", Locations.WITCH_VERT.getLocation()).spawn();
new SpawnWitch("W Jaune", Locations.WITCH_JAUNE.getLocation()).spawn();
new WitchBoss(TeamInfos.ROUGE, Locations.WITCH_ROUGE.getLocation());
new WitchBoss(TeamInfos.BLEU, Locations.WITCH_BLEU.getLocation());
new WitchBoss(TeamInfos.VERT, Locations.WITCH_VERT.getLocation());
new WitchBoss(TeamInfos.JAUNE, Locations.WITCH_JAUNE.getLocation());
}
return false;

View File

@@ -1,8 +1,9 @@
package net.berrygames.witchrush.game;
import net.berrygames.witchrush.WitchRush;
import net.berrygames.witchrush.team.TeamInfos;
import net.berrygames.witchrush.tools.Locations;
import net.berrygames.witchrush.tools.SpawnWitch;
import net.berrygames.witchrush.tools.WitchBoss;
import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitRunnable;
@@ -18,10 +19,10 @@ public class NoPVPTask extends BukkitRunnable {
WitchRush.get().setState(GameState.PVP);
Bukkit.broadcastMessage(WitchRush.prefix()+"Les §6Witchs §dsont apparues, §d§nBonne chance à vous !");
new SpawnWitch("W", Locations.WITCH_ROUGE.getLocation()).spawn();
new SpawnWitch("W", Locations.WITCH_BLEU.getLocation()).spawn();
new SpawnWitch("W", Locations.WITCH_VERT.getLocation()).spawn();
new SpawnWitch("W", Locations.WITCH_JAUNE.getLocation()).spawn();
new WitchBoss(TeamInfos.ROUGE, Locations.WITCH_ROUGE.getLocation());
new WitchBoss(TeamInfos.BLEU, Locations.WITCH_BLEU.getLocation());
new WitchBoss(TeamInfos.VERT, Locations.WITCH_VERT.getLocation());
new WitchBoss(TeamInfos.JAUNE, Locations.WITCH_JAUNE.getLocation());
cancel();
}
timer--;

View File

@@ -2,8 +2,9 @@ package net.berrygames.witchrush.game;
import net.berrygames.witchrush.WitchPlayer;
import net.berrygames.witchrush.WitchRush;
import net.berrygames.witchrush.team.TeamInfos;
import net.berrygames.witchrush.tools.Locations;
import net.berrygames.witchrush.tools.SpawnPNJ;
import net.berrygames.witchrush.tools.PNJSpawner;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
@@ -33,16 +34,16 @@ public class StartTask extends BukkitRunnable {
//TP Player
//Spawn SHOP
new SpawnPNJ("S", Locations.SHOP_BLEU.getLocation()).spawn();
new SpawnPNJ("S", Locations.SHOP_ROUGE.getLocation()).spawn();
new SpawnPNJ("S", Locations.SHOP_VERT.getLocation()).spawn();
new SpawnPNJ("S", Locations.SHOP_JAUNE.getLocation()).spawn();
new PNJSpawner("§6§lSHOP", TeamInfos.BLEU, Locations.SHOP_BLEU.getLocation());
new PNJSpawner("§6§lSHOP", TeamInfos.ROUGE, Locations.SHOP_ROUGE.getLocation());
new PNJSpawner("§6§lSHOP", TeamInfos.VERT, Locations.SHOP_VERT.getLocation());
new PNJSpawner("§6§lSHOP", TeamInfos.JAUNE, Locations.SHOP_JAUNE.getLocation());
//Spawn UPGRADE
new SpawnPNJ("U", Locations.UPGRADE_BLEU.getLocation()).spawn();
new SpawnPNJ("U", Locations.UPGRADE_ROUGE.getLocation()).spawn();
new SpawnPNJ("U", Locations.UPGRADE_VERT.getLocation()).spawn();
new SpawnPNJ("U", Locations.UPGRADE_JAUNE.getLocation()).spawn();
new PNJSpawner("§b§LUPGRADE", TeamInfos.JAUNE, Locations.UPGRADE_BLEU.getLocation());
new PNJSpawner("§b§LUPGRADE", TeamInfos.ROUGE, Locations.UPGRADE_ROUGE.getLocation());
new PNJSpawner("§b§LUPGRADE", TeamInfos.VERT, Locations.UPGRADE_VERT.getLocation());
new PNJSpawner("§b§LUPGRADE", TeamInfos.JAUNE, Locations.UPGRADE_JAUNE.getLocation());
}

View File

@@ -3,6 +3,8 @@ package net.berrygames.witchrush.listeners.players;
import net.berrygames.witchrush.WitchPlayer;
import net.berrygames.witchrush.WitchRush;
import net.berrygames.witchrush.game.GameState;
import net.berrygames.witchrush.team.TeamInfos;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@@ -16,8 +18,27 @@ public class ChatEvent implements Listener {
WitchPlayer witchPlayer = WitchPlayer.get(player);
if(WitchRush.get().getState().equals(GameState.WAITING) || WitchRush.get().getState().equals(GameState.STARTING)){
//
e.setFormat("§7[§6Global§7] §e%1$s §7» §f%2$s");
} else if(witchPlayer.isSpectator()){
for(WitchPlayer pls : WitchPlayer.getwitchMap().values()){
if(pls.isSpectator()){
e.setFormat("§7[Spectateur] §8%1$s §7» §e%2$s");
}
}
} else {
String message = e.getMessage();
if(message.toLowerCase().startsWith("!")){
e.setFormat("§7[§6Global§7] §e%1$s §7» §f%2$s");
} else {
e.setCancelled(true);
Bukkit.getOnlinePlayers().forEach(playerOnline -> {
final TeamInfos teamInfos = WitchRush.get().getTeamManager().getPlayerTeam(player);
if(WitchRush.get().getTeamManager().getPlayerTeam(playerOnline).equals(teamInfos)){
playerOnline.sendMessage("§7["+teamInfos.getChatColor()+teamInfos.getTeamName()+"§7] §e"
+player.getDisplayName()+"§7» §f"+message.replaceFirst("!",""));
}
});
}
}
}

View File

@@ -3,7 +3,9 @@ package net.berrygames.witchrush.listeners.players;
import net.berrygames.witchrush.WitchPlayer;
import net.berrygames.witchrush.WitchRush;
import net.berrygames.witchrush.game.GameState;
import net.berrygames.witchrush.team.TeamInfos;
import net.berrygames.witchrush.tools.DeadPlayer;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@@ -22,15 +24,25 @@ public class DeathEvent implements Listener {
e.setDeathMessage(null);
player.kickPlayer("ENFAIT TOI T'ES FORT PCQ NORMALEMENT YA PAS CA");
} else {
e.setDeathMessage(WitchRush.prefix()+"§e"+player.getName()+"§d a été tué par §e"+ killer.getName());
new DeadPlayer(player);
player.setHealth(20);
if(killer.getType().equals(EntityType.PLAYER)){
TeamInfos team = WitchRush.get().getTeamManager().getPlayerTeam(player);
e.setDeathMessage(WitchRush.prefix()+team.getChatColor()+player.getName()+"§d a été tué par "+team.getChatColor()+ killer.getName());
new DeadPlayer(player);
player.setHealth(20);
killer.sendMessage("§dVous avez tué §e"+player.getName());
witchKiller.setKills(witchKiller.getKills()+1);
killer.sendMessage("§dVous avez tué §e"+player.getName());
witchKiller.setKills(witchKiller.getKills()+1);
player.sendMessage("§e"+killer.getName()+" §dvous avez tué");
witchPlayer.setDeath(witchPlayer.getDeath()+1);
player.sendMessage("§e"+killer.getName()+" §dvous avez tué");
witchPlayer.setDeath(witchPlayer.getDeath()+1);
} else {
TeamInfos team = WitchRush.get().getTeamManager().getPlayerTeam(player);
e.setDeathMessage(WitchRush.prefix()+team.getChatColor()+player.getName()+"§d est mort");
new DeadPlayer(player);
player.setHealth(20);
player.sendMessage("§d Vous êtes mort !");
witchPlayer.setDeath(witchPlayer.getDeath()+1);
}
}
}

View File

@@ -1,15 +1,26 @@
package net.berrygames.witchrush.listeners.players;
import net.berrygames.witchrush.WitchPlayer;
import net.berrygames.witchrush.WitchRush;
import net.berrygames.witchrush.game.GameState;
import net.berrygames.witchrush.team.TeamInfos;
import net.berrygames.witchrush.team.TeamManager;
import net.berrygames.witchrush.team.TeamsMenu;
import org.bukkit.Sound;
import org.bukkit.entity.EntityType;
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.EntityDamageByBlockEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
public class InteractEvent implements Listener {
@@ -27,6 +38,13 @@ public class InteractEvent implements Listener {
}
}
@EventHandler
public void drop(PlayerDropItemEvent e){
if(WitchRush.get().getState().equals(GameState.WAITING) || WitchRush.get().getState().equals(GameState.STARTING)){
e.setCancelled(true);
}
}
@EventHandler
public void pvp(EntityDamageByEntityEvent e){
if(WitchRush.get().getState().equals(GameState.WAITING) || WitchRush.get().getState().equals(GameState.STARTING)){
@@ -55,4 +73,75 @@ public class InteractEvent implements Listener {
}
}
@EventHandler
public void click(PlayerInteractEvent e){
Player player = e.getPlayer();
WitchPlayer witchPlayer = WitchPlayer.get(player);
Action action = e.getAction();
ItemStack item = e.getItem();
e.setCancelled(true);
if(action.equals(Action.RIGHT_CLICK_AIR) || action.equals(Action.RIGHT_CLICK_BLOCK)){
switch (item.getType()){
case ARMOR_STAND:
new TeamsMenu(player);
break;
case BED:
player.sendMessage("retour au hub soon");
break;
default:break;
}
}
}
@EventHandler
public void inventoryClick(InventoryClickEvent e){
Player player = (Player) e.getWhoClicked();
WitchPlayer witchPlayer = WitchPlayer.get(player);
ItemStack item = e.getCurrentItem();
Inventory inv = e.getClickedInventory();
TeamManager teamManager = WitchRush.get().getTeamManager();
if(!inv.getTitle().equals(WitchRush.prefix()+" Teams")) return;
e.setCancelled(true);
switch (item.getType()){
case WOOL:
final TeamInfos teamInfos = TeamInfos.getTeamInfosByShortData(e.getCurrentItem().getDurability());
if (teamManager.isPlayerInTeam(player, teamInfos)) {
player.sendMessage(WitchRush.prefix()+"Vous êtes déjà dans cette team !");
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1.0f, 1.0f);
player.closeInventory();
return;
}
if (teamManager.teamIsFull(teamInfos)) {
player.sendMessage(WitchRush.prefix()+"L'équipe est pleine !");
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1.0f, 1.0f);
player.closeInventory();
return;
}
teamManager.removePlayerAllTeam(player);
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_YES, 1.0f, 1.0f);
teamManager.addPlayerTeam(player, teamInfos);
TeamInfos infos1 = teamManager.getPlayerTeam(player);
player.sendMessage(WitchRush.prefix()+"Vous avez rejoint la team "+infos1.getChatColor()+infos1.getTeamName());
player.closeInventory();
break;
case BARRIER:
player.closeInventory();
break;
case DOUBLE_PLANT:
if (teamManager.playerHaveTeam(player)) {
player.sendMessage(WitchRush.prefix()+"Vous êtes déjà dans une équipe !");
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1.0f, 1.0f);
player.closeInventory();
return;
}
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_YES, 1.0f, 1.0f);
teamManager.addPlayerInRandomTeam(player);
TeamInfos infos2 = teamManager.getPlayerTeam(player);
player.sendMessage(WitchRush.prefix()+"Vous avez rejoint la team "+infos2.getChatColor()+infos2.getTeamName());
player.closeInventory();
break;
}
}
}

View File

@@ -31,6 +31,7 @@ public class PlayerJoin implements Listener {
player.setLevel(0);
player.setHealth(20);
player.setFoodLevel(20);
witchPlayer.sendWaitingStuff();
witchPlayer.teleportPlayer();
witchPlayer.sendGameScoreboard();

View File

@@ -1,4 +1,56 @@
package net.berrygames.witchrush.team;
public enum TeamInfos {
VERT("Vert", "Vert", "§a", (short)13),
BLEU("Bleu", "Bleu", "§b", (short)11),
JAUNE("Jaune", "Jaune", "§e", (short)4),
ROUGE("Rouge", "Rouge", "§c", (short)14),
;
private String IDName;
private String teamName;
private String chatColor;
private short dataClay;
TeamInfos(String IDName, String teamName, String chatColor, short dataClay) {
this.IDName = IDName;
this.teamName = teamName;
this.chatColor = chatColor;
this.dataClay = dataClay;
}
public String getIDName() {
return IDName;
}
public String getTeamName() {
return teamName;
}
public String getChatColor() {
return chatColor;
}
public short getDataClay() {
return dataClay;
}
public static TeamInfos getTeamInfosByIDName(final String ID) {
for (final TeamInfos teamInfos : values()) {
if (teamInfos.getIDName().equalsIgnoreCase(ID)) {
return teamInfos;
}
}
return null;
}
public static TeamInfos getTeamInfosByShortData(final short data) {
for (final TeamInfos teamInfos : values()) {
if (teamInfos.getDataClay() == data) {
return teamInfos;
}
}
return null;
}
}

View File

@@ -1,7 +1,106 @@
package net.berrygames.witchrush.team;
import net.berrygames.witchrush.tools.WitchBoss;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class TeamManager {
private Map<TeamInfos, List<Player>> playerTeamList;
private Map<TeamInfos, WitchBoss> bossEntityMap;
public TeamManager() {
this.playerTeamList = new HashMap<>();
this.bossEntityMap = new HashMap<>();
}
public void addPlayerTeam(final Player player, final TeamInfos teamInfos) {
if (this.playerTeamList.get(teamInfos) == null) {
this.playerTeamList.put(teamInfos, new ArrayList<Player>());
}
if (!this.teamIsFull(teamInfos)) {
this.removePlayerAllTeam(player);
this.playerTeamList.get(teamInfos).add(player);
}
}
public void removePlayerAllTeam(final Player player){
for (final TeamInfos teamInfos : TeamInfos.values()) {
if (this.playerTeamList.get(teamInfos) != null && this.playerTeamList.get(teamInfos).contains(player)) {
this.playerTeamList.get(teamInfos).remove(player);
}
}
}
public void removePlayerTeam(final Player player, final TeamInfos teamInfos) {
if (this.playerTeamList.get(teamInfos) != null && this.playerTeamList.get(teamInfos).contains(player)) {
this.playerTeamList.get(teamInfos).remove(player);
}
}
public void addPlayerInRandomTeam(final Player player) {
}
public boolean isPlayerInTeam(final Player player, final TeamInfos teamInfos) {
return this.playerTeamList.get(teamInfos) != null && this.playerTeamList.get(teamInfos).contains(player);
}
public boolean playerHaveTeam(final Player player) {
for (final TeamInfos teamInfos : TeamInfos.values()) {
if (this.playerTeamList.get(teamInfos) != null && this.playerTeamList.get(teamInfos).contains(player)) {
return true;
}
}
return false;
}
public boolean teamIsFull(final TeamInfos teamInfos) {
return this.playerTeamList.get(teamInfos) != null && this.playerTeamList.get(teamInfos).size() >= this.getPlayerTeamLimit();
}
public TeamInfos getPlayerTeam(final Player player) {
for (final TeamInfos teamInfos : TeamInfos.values()) {
if (this.playerTeamList.get(teamInfos) != null && this.playerTeamList.get(teamInfos).contains(player)) {
return teamInfos;
}
}
return null;
}
public Integer getTeamPlayerCount(final TeamInfos teamInfos) {
if (this.playerTeamList.get(teamInfos) != null) {
return this.playerTeamList.get(teamInfos).size();
}
return 0;
}
public List<Player> getPlayerTeamList(final TeamInfos teamInfos) {
if (this.playerTeamList.get(teamInfos) != null) {
return this.playerTeamList.get(teamInfos);
}
return new ArrayList<Player>();
}
public Integer getPlayerTeamLimit() {
return 4;
}
public WitchBoss getTeamBoss(final TeamInfos teamInfos) {
return this.bossEntityMap.get(teamInfos);
}
public Map<TeamInfos, List<Player>> getPlayerTeamList() {
return this.playerTeamList;
}
public Map<TeamInfos, WitchBoss> getBossEntityMap() {
return this.bossEntityMap;
}
}

View File

@@ -0,0 +1,41 @@
package net.berrygames.witchrush.team;
import net.berrygames.witchrush.WitchRush;
import net.berrygames.witchrush.tools.ItemFactory;
import org.bukkit.Bukkit;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
public class TeamsMenu {
private Player player;
private Inventory inventory;
public TeamsMenu(Player player) {
this.player = player;
inventory = Bukkit.createInventory(null, 4 * 9, WitchRush.prefix()+" Teams");
for(int i = 0; i < 9; i++){
inventory.setItem(i, new ItemFactory(Material.STAINED_GLASS_PANE).withName("").withColor(DyeColor.PURPLE).done());
}
for(int i = 27; i < 36; i++){
inventory.setItem(i, new ItemFactory(Material.STAINED_GLASS_PANE).withName("").withColor(DyeColor.PURPLE).done());
}
inventory.setItem(9, new ItemFactory(Material.STAINED_GLASS_PANE).withName("").withColor(DyeColor.PURPLE).done());
inventory.setItem(17, new ItemFactory(Material.STAINED_GLASS_PANE).withName("").withColor(DyeColor.PURPLE).done());
inventory.setItem(18, new ItemFactory(Material.STAINED_GLASS_PANE).withName("").withColor(DyeColor.PURPLE).done());
inventory.setItem(26, new ItemFactory(Material.STAINED_GLASS_PANE).withName("").withColor(DyeColor.PURPLE).done());
inventory.setItem(22, new ItemFactory(Material.DOUBLE_PLANT).withName("§dTeam Random").done());
inventory.setItem(12, new ItemFactory(Material.WOOL).withColor(DyeColor.GREEN).withName("§aVert").done());
inventory.setItem(14, new ItemFactory(Material.WOOL).withColor(DyeColor.YELLOW).withName("§eJaune").done());
inventory.setItem(20, new ItemFactory(Material.WOOL).withColor(DyeColor.BLUE).withName("§bBleu").done());
inventory.setItem(24, new ItemFactory(Material.WOOL).withColor(DyeColor.RED).withName("§cRouge").done());
inventory.setItem(31, new ItemFactory(Material.BARRIER).withName("§cFermer").done());
player.openInventory(inventory);
}
}

View File

@@ -0,0 +1,92 @@
package net.berrygames.witchrush.tools;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.potion.PotionEffect;
import java.util.Arrays;
import java.util.List;
public class ItemFactory {
private ItemStack item;
public ItemFactory(final ItemStack item) {
this.item = item;
}
public ItemFactory(final Material mat) {
this.item = new ItemStack(mat);
}
public ItemFactory(final Material mat, final int amount) {
this.item = new ItemStack(mat, amount);
}
public ItemFactory withName(final String name) {
final ItemMeta meta = this.item.getItemMeta();
meta.setDisplayName(name);
this.item.setItemMeta(meta);
return this;
}
public ItemFactory withLore(final String... lore) {
final ItemMeta meta = this.item.getItemMeta();
meta.setLore((List) Arrays.asList(lore));
this.item.setItemMeta(meta);
return this;
}
public ItemFactory withColor(final DyeColor color) {
this.item.setDurability((short)color.getWoolData());
return this;
}
public ItemFactory withOwner(final String owner) {
if (this.item.getType().equals((Object)Material.SKULL_ITEM)) {
this.item.setDurability((short)3);
final SkullMeta m = (SkullMeta)this.item.getItemMeta();
m.setOwner(owner);
this.item.setItemMeta((ItemMeta)m);
}
return this;
}
public ItemFactory withAmount(final int amount) {
this.item.setAmount(amount);
return this;
}
public ItemFactory withEnchant(final Enchantment e, final int lvl) {
final ItemMeta m = this.item.getItemMeta();
m.addEnchant(e, lvl, true);
this.item.setItemMeta(m);
return this;
}
public ItemFactory withEffect(final PotionEffect e) {
if (!this.item.getType().equals((Object)Material.POTION)) {
return this;
}
final PotionMeta pm = (PotionMeta)this.item.getItemMeta();
pm.addCustomEffect(e, true);
this.item.setItemMeta((ItemMeta)pm);
return this;
}
public ItemFactory addFlag(final ItemFlag... f) {
this.item.getItemMeta().removeItemFlags(f);
return this;
}
public ItemStack done() {
return this.item;
}
}

View File

@@ -0,0 +1,51 @@
package net.berrygames.witchrush.tools;
import net.berrygames.witchrush.team.TeamInfos;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Villager;
public class PNJSpawner {
private TeamInfos teamInfos;
private Location location;
private Villager villager;
private double life;
private String name;
public PNJSpawner(String name, final TeamInfos teamInfos, final Location location) {
this.teamInfos = teamInfos;
this.location = location;
this.villager = (Villager) Bukkit.getWorld("world").spawnEntity(location, EntityType.VILLAGER);
this.life = 100;
this.villager.setMaxHealth(this.life);
this.villager.setHealth(this.life);
this.name = name;
this.villager.setCustomName(this.name);
this.villager.setCustomNameVisible(true);
this.villager.setAI(false);
this.villager.setCanPickupItems(false);
this.villager.setCollidable(false);
}
public TeamInfos getTeamInfos() {
return this.teamInfos;
}
public Location getLocation() {
return this.location;
}
public Villager getvillager() {
return this.villager;
}
public double getLife() {
return this.life;
}
public String getName() {
return name;
}
}

View File

@@ -1,31 +0,0 @@
package net.berrygames.witchrush.tools;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Villager;
public class SpawnPNJ {
private Villager villager;
private String name;
private Location location;
public SpawnPNJ(String name, Location location) {
this.name = name;
this.location = location;
}
public void spawn(){
this.villager = Bukkit.getWorld("world").spawn(location, Villager.class, v ->{
v.setAI(false);
v.setCustomName(name);
v.setCustomNameVisible(true);
v.setSilent(true);
v.setGravity(false);
v.setInvulnerable(true);
});
}
}

View File

@@ -1,29 +0,0 @@
package net.berrygames.witchrush.tools;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Witch;
public class SpawnWitch {
private Witch witch;
private String name;
private Location location;
public SpawnWitch(String name, Location location) {
this.name = name;
this.location = location;
}
public void spawn(){
this.witch = Bukkit.getWorld("world").spawn(location, Witch.class, w ->{
w.setAI(false);
w.setCustomName(name);
w.setCustomNameVisible(true);
w.setSilent(true);
w.setGravity(false);
});
}
}

View File

@@ -0,0 +1,46 @@
package net.berrygames.witchrush.tools;
import net.berrygames.witchrush.team.TeamInfos;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Witch;
public class WitchBoss {
private TeamInfos teamInfos;
private Location location;
private Witch witch;
private double life;
public WitchBoss(final TeamInfos teamInfos, final Location location) {
this.teamInfos = teamInfos;
this.location = location;
this.witch = (Witch) Bukkit.getWorld("world").spawnEntity(location, EntityType.WITCH);
this.life = 100;
this.witch.setMaxHealth(this.life);
this.witch.setHealth(this.life);
this.witch.setCustomNameVisible(false);
this.witch.setAI(false);
this.witch.setCanPickupItems(false);
this.witch.setCollidable(false);
}
public TeamInfos getTeamInfos() {
return this.teamInfos;
}
public Location getLocation() {
return this.location;
}
public Witch getWitch() {
return this.witch;
}
public double getLife() {
return this.life;
}
}