SteamWar/MissileWars
Archiviert
13
0

Add distribute items on team leave #34

Manuell gemergt
YoyoNow hat 4 Commits von Fix_Player_Team_Leave nach master 2021-04-04 17:17:47 +02:00 zusammengeführt

Datei anzeigen

@ -36,149 +36,158 @@ import java.util.Objects;
import java.util.Set;
public class MWTeam {
private static final ItemStack bow = new ItemStack(Material.BOW);
private static final ItemStack bow = new ItemStack(Material.BOW);
static {
ItemMeta bowMeta = Objects.requireNonNull(bow.getItemMeta());
bowMeta.addEnchant(Enchantment.ARROW_FIRE, 1, true);
bowMeta.addEnchant(Enchantment.ARROW_KNOCKBACK, 1, true);
bowMeta.addEnchant(Enchantment.KNOCKBACK, 1, true);
bowMeta.addEnchant(Enchantment.DAMAGE_ALL, 2, true);
bowMeta.setUnbreakable(true);
bow.setItemMeta(bowMeta);
}
static {
ItemMeta bowMeta = Objects.requireNonNull(bow.getItemMeta());
bowMeta.addEnchant(Enchantment.ARROW_FIRE, 1, true);
bowMeta.addEnchant(Enchantment.ARROW_KNOCKBACK, 1, true);
bowMeta.addEnchant(Enchantment.KNOCKBACK, 1, true);
bowMeta.addEnchant(Enchantment.DAMAGE_ALL, 2, true);
bowMeta.setUnbreakable(true);
bow.setItemMeta(bowMeta);
}
private final ChatColor color;
private final String teamName;
private final Team sbteam; //scoreboard-Team
private final Location spawn;
private final int portalZ;
private final ChatColor color;
private final String teamName;
private final Team sbteam; //scoreboard-Team
private final Location spawn;
private final int portalZ;
private final LinkedList<Player> players = new LinkedList<>();
private final Set<Player> openInvitations = new HashSet<>();
private final LinkedList<Player> players = new LinkedList<>();
private final Set<Player> openInvitations = new HashSet<>();
MWTeam(ChatColor color, Location spawn, String teamName, int portalZ) {
this.teamName = teamName;
this.color = color;
this.spawn = spawn;
this.portalZ = portalZ;
if(FightScoreboard.getScoreboard().getTeam(teamName) == null)
MWTeam(ChatColor color, Location spawn, String teamName, int portalZ) {
this.teamName = teamName;
this.color = color;
this.spawn = spawn;
this.portalZ = portalZ;
if(FightScoreboard.getScoreboard().getTeam(teamName) == null)
sbteam = FightScoreboard.getScoreboard().registerNewTeam(teamName);
else
sbteam = FightScoreboard.getScoreboard().getTeam(teamName);
assert sbteam != null;
sbteam.setAllowFriendlyFire(false);
sbteam.setColor(color);
}
}
public void givePlayerItem(ItemStack item) {
Player p = players.removeFirst();
players.addLast(p);
public void givePlayerItem(ItemStack item) {
Player p = players.removeFirst();
players.addLast(p);
Inventory inventory = p.getInventory();
for (int i = 0; i <= 35; i++) { //35 is the last normal inventory slot
ItemStack itemStack = inventory.getItem(i);
if (itemStack != null && itemStack.isSimilar(item) && itemStack.getAmount() != itemStack.getMaxStackSize()) {
itemStack.setAmount(itemStack.getAmount() + item.getAmount());
inventory.setItem(i, itemStack);
p.updateInventory();
return;
}
}
Inventory inventory = p.getInventory();
for (int i = 0; i <= 35; i++) { //35 is the last normal inventory slot
ItemStack itemStack = inventory.getItem(i);
if (itemStack != null && itemStack.isSimilar(item) && itemStack.getAmount() != itemStack.getMaxStackSize()) {
itemStack.setAmount(itemStack.getAmount() + item.getAmount());
inventory.setItem(i, itemStack);
p.updateInventory();
return;
}
}
for (int i = 0; i <= 35; i++) { //35 is the last normal inventory slot
ItemStack itemStack = inventory.getItem(i);
if (itemStack == null || itemStack.getType().equals(Material.AIR)) {
inventory.setItem(i, item);
p.updateInventory();
return;
}
}
}
for (int i = 0; i <= 35; i++) { //35 is the last normal inventory slot
ItemStack itemStack = inventory.getItem(i);
if (itemStack == null || itemStack.getType().equals(Material.AIR)) {
inventory.setItem(i, item);
p.updateInventory();
return;
}
}
}
public void teamScoreboard(Objective objective) {
players.forEach(p -> objective.getScore(getColorCode() + p.getName()).setScore(1));
}
public void teamScoreboard(Objective objective) {
players.forEach(p -> objective.getScore(getColorCode() + p.getName()).setScore(1));
}
public int size() {
return players.size();
}
public int size() {
return players.size();
}
public int getPortalZ() {
return portalZ;
}
public int getPortalZ() {
return portalZ;
}
public Location getSpawn(){
return spawn;
}
public Location getSpawn(){
return spawn;
}
public void join(Player p) {
players.add(p);
p.teleport(spawn);
p.setGameMode(GameMode.SURVIVAL);
p.getInventory().setItem(0, bow);
sbteam.addPlayer(p);
p.setDisplayName(color + p.getName());
if (MissileWars.getFightState() == FightState.WAITING && !enemy().players.isEmpty())
MissileWars.startRound();
public void join(Player p) {
players.add(p);
p.teleport(spawn);
p.setGameMode(GameMode.SURVIVAL);
p.getInventory().setItem(0, bow);
sbteam.addPlayer(p);
p.setDisplayName(color + p.getName());
if (MissileWars.getFightState() == FightState.WAITING && !enemy().players.isEmpty())
MissileWars.startRound();
if (!Config.test())
Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), () -> new TablistNamePacket(SteamwarUser.get(p.getUniqueId()).getId(), color + p.getName()).send(p), 5);
}
if (!Config.test())
Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), () -> new TablistNamePacket(SteamwarUser.get(p.getUniqueId()).getId(), color + p.getName()).send(p), 5);
}
public void leave(Player p) {
if (!players.contains(p)) return;
public void leave(Player p) {
if (!players.contains(p)) return;
players.remove(p);
p.setDisplayName("§7" + p.getName());
sbteam.removePlayer(p);
if (players.isEmpty() && MissileWars.getFightState() == FightState.FIGHTING)
MissileWars.end(WinReasons.NO_ENEMY, enemy());
players.remove(p);
for (ItemStack stack : p.getInventory().getContents()) {
if (stack == null) continue;
if (stack.getType() == Material.AIR) continue;
if (stack.isSimilar(bow)) continue;
givePlayerItem(stack);
}
if (!Config.test())
new TablistNamePacket(SteamwarUser.get(p.getUniqueId()).getId(), "§7§o" + p.getName()).send(p);
}
p.getInventory().clear();
public void invitePlayer(Player p) {
if (enemy().openInvitations.contains(p)) return;
openInvitations.add(p);
}
p.setDisplayName("§7" + p.getName());
sbteam.removePlayer(p);
if (players.isEmpty() && MissileWars.getFightState() == FightState.FIGHTING)
MissileWars.end(WinReasons.NO_ENEMY, enemy());
public void acceptInvite(Player p) {
removeInvitations(p);
join(p);
}
if (!Config.test())
new TablistNamePacket(SteamwarUser.get(p.getUniqueId()).getId(), "§7§o" + p.getName()).send(p);
}
private MWTeam enemy() {
if (this == MissileWars.getRedTeam())
return MissileWars.getBlueTeam();
public void invitePlayer(Player p) {
if (enemy().openInvitations.contains(p)) return;
openInvitations.add(p);
}
return MissileWars.getRedTeam();
}
public void acceptInvite(Player p) {
removeInvitations(p);
join(p);
}
public String getColorCode(){
return "§" + color.getChar();
}
private MWTeam enemy() {
if (this == MissileWars.getRedTeam())
return MissileWars.getBlueTeam();
public boolean hasPlayer(Player p) {
return players.contains(p);
}
return MissileWars.getRedTeam();
}
public boolean hasInvite(Player p) {
return openInvitations.contains(p);
}
public String getColorCode(){
return "§" + color.getChar();
}
public String getColoredName() {
return color.toString() + teamName;
}
public boolean hasPlayer(Player p) {
return players.contains(p);
}
public LinkedList<Player> getPlayers() {
return players;
}
public boolean hasInvite(Player p) {
return openInvitations.contains(p);
}
public static void removeInvitations(Player p) {
MissileWars.getRedTeam().openInvitations.remove(p);
MissileWars.getBlueTeam().openInvitations.remove(p);
}
public String getColoredName() {
return color.toString() + teamName;
}
public LinkedList<Player> getPlayers() {
return players;
}
public static void removeInvitations(Player p) {
MissileWars.getRedTeam().openInvitations.remove(p);
MissileWars.getBlueTeam().openInvitations.remove(p);
}
}