Skip to content

Commit

Permalink
Grand nettoyage de printemps
Browse files Browse the repository at this point in the history
  • Loading branch information
kaq666 committed Apr 16, 2020
1 parent f7fc078 commit 906193b
Show file tree
Hide file tree
Showing 17 changed files with 530 additions and 485 deletions.
93 changes: 52 additions & 41 deletions src/main/java/eu/billyinc/mineralcontest/App.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package eu.billyinc.mineralcontest;

import eu.billyinc.mineralcontest.listener.SpawnListener;
import eu.billyinc.mineralcontest.model.MineralContestChest;
import eu.billyinc.mineralcontest.model.PlayerTeam;
import eu.billyinc.mineralcontest.model.Team;
import eu.billyinc.mineralcontest.model.MineralContestPlayer;
import eu.billyinc.mineralcontest.model.MineralContestTeam;
import eu.billyinc.mineralcontest.utils.FastBoard;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
Expand All @@ -16,7 +15,11 @@
import java.util.*;

import eu.billyinc.mineralcontest.command.MineralContestCommand;
import eu.billyinc.mineralcontest.listener.MineralContestListener;
import eu.billyinc.mineralcontest.listener.BlockListener;
import eu.billyinc.mineralcontest.listener.EntityListener;
import eu.billyinc.mineralcontest.listener.FurnaceListener;
import eu.billyinc.mineralcontest.listener.InventoryListener;
import eu.billyinc.mineralcontest.listener.PlayerListener;
import eu.billyinc.mineralcontest.manager.MineralContestManager;

/**
Expand All @@ -25,9 +28,8 @@
*/
public class App extends JavaPlugin {

private List<Team> teams = new ArrayList<Team>();
private List<MineralContestTeam> teams = new ArrayList<MineralContestTeam>();
private final Map<UUID, FastBoard> boards = new HashMap<>();
private final Map<UUID, PlayerTeam> playerTeamMap = new HashMap<>();
private GameState gameState = GameState.WAITING;

@Override
Expand All @@ -37,8 +39,13 @@ public void onEnable() {
MineralContestManager.setApp(this);

this.getCommand("mc").setExecutor(new MineralContestCommand());
this.getServer().getPluginManager().registerEvents(new SpawnListener(), this);
this.getServer().getPluginManager().registerEvents(new MineralContestListener(), this);

this.getServer().getPluginManager().registerEvents(new BlockListener(), this);
this.getServer().getPluginManager().registerEvents(new EntityListener(), this);
this.getServer().getPluginManager().registerEvents(new FurnaceListener(), this);
this.getServer().getPluginManager().registerEvents(new InventoryListener(), this);
this.getServer().getPluginManager().registerEvents(new PlayerListener(), this);

this.registerTeams();
}

Expand All @@ -51,21 +58,21 @@ public void onDisable() {
}

private void registerTeams() {
this.teams.add(new Team("Team Bleue", ChatColor.BLUE, new Location(Bukkit.getServer().getWorld("World"),-352, 65, -342, 180f, 1.9f)));
this.teams.add(new Team("Team Jaune", ChatColor.YELLOW, new Location(Bukkit.getServer().getWorld("World"),-233, 65, -342, 90f, 1.5f)));
this.teams.add(new Team("Team Rouge", ChatColor.RED, new Location(Bukkit.getServer().getWorld("World"),-278, 65, -387, -90f, 0f)));
this.teams.add(new MineralContestTeam("Team Bleue", ChatColor.BLUE, new Location(Bukkit.getServer().getWorld("World"),-352, 65, -342, 180f, 1.9f)));
this.teams.add(new MineralContestTeam("Team Jaune", ChatColor.YELLOW, new Location(Bukkit.getServer().getWorld("World"),-233, 65, -342, 90f, 1.5f)));
this.teams.add(new MineralContestTeam("Team Rouge", ChatColor.RED, new Location(Bukkit.getServer().getWorld("World"),-278, 65, -387, -90f, 0f)));
}

public Team getTeamByName(String name) {
for (Team team : this.teams) {
public MineralContestTeam getTeamByName(String name) {
for (MineralContestTeam team : this.teams) {
if (team.getName().equals(name)) {
return team;
}
}
return null;
}

public List<Team> getTeams() {
public List<MineralContestTeam> getTeams() {
return teams;
}

Expand All @@ -92,31 +99,35 @@ public Map<UUID, FastBoard> getBoards() {
return boards;
}

public Map<UUID, PlayerTeam> getPlayerTeamMap() {
return playerTeamMap;
}

public void updateScoreBoards(int timer) {
for (FastBoard board : this.getBoards().values()) {
PlayerTeam playerTeam = this.getPlayerTeamMap().get(board.getPlayer().getUniqueId());
Collection<String> lines = new ArrayList<>();

int minutes = ~~((timer % 3600) / 60);
int secondes = ~~timer % 60;

if (secondes < 10) {
lines.add("Timer : " + minutes + ":" + "0" + secondes);
} else {
lines.add("Timer : " + minutes + ":" + secondes);
}

for (Player player : playerTeam.getTeam().getPlayers()) {
int score = this.getInventoryValue(player);
lines.add(player.getDisplayName() + ": " + score + " Points");
lines.add("");
MineralContestPlayer mineralContestPlayer = MineralContestManager.getMineralContestPlayerManager().getMineralContestPlayerByUUID(board.getPlayer().getUniqueId());
if (mineralContestPlayer instanceof MineralContestPlayer) {
MineralContestTeam mineralContestTeam = MineralContestManager.getApp().getTeamByName(mineralContestPlayer.getTeamName());
System.out.println(mineralContestPlayer.getTeamName());
if (mineralContestTeam instanceof MineralContestTeam) {
System.out.println("oh yes");
Collection<String> lines = new ArrayList<>();

int minutes = ~~((timer % 3600) / 60);
int secondes = ~~timer % 60;

if (secondes < 10) {
lines.add("Timer : " + minutes + ":" + "0" + secondes);
} else {
lines.add("Timer : " + minutes + ":" + secondes);
}

for (Player player : mineralContestTeam.getPlayers()) {
int score = this.getInventoryValue(player);
lines.add(player.getDisplayName() + ": " + score + " Points");
lines.add("");
}

lines.add("Total : " + mineralContestTeam.getScore());
board.updateLines(lines);
}
}
lines.add("Total : " + playerTeam.getTeam().getScore());
board.updateLines(lines);
}
}

Expand All @@ -131,7 +142,7 @@ public void finishGame() {
this.gameState = GameState.FINISH;
this.resetTeams();
this.boards.clear();
this.playerTeamMap.clear();
MineralContestManager.getMineralContestPlayerManager().getPlayers().clear();
}

private int getInventoryValue(Player player) {
Expand Down Expand Up @@ -167,15 +178,15 @@ public int getItemStackValue(ItemStack itemStack) {
}

public void resetTeams() {
for (Team team : this.teams) {
for (MineralContestTeam team : this.teams) {
team.getPlayers().clear();
}
}

public Team getWinners() {
public MineralContestTeam getWinners() {
int max = 0;
Team winners = this.teams.get(0);
for (Team team : this.teams) {
MineralContestTeam winners = this.teams.get(0);
for (MineralContestTeam team : this.teams) {
if (team.getScore() > max) {
max = team.getScore();
winners = team;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package eu.billyinc.mineralcontest.command;

import eu.billyinc.mineralcontest.GameState;
import eu.billyinc.mineralcontest.model.Team;
import eu.billyinc.mineralcontest.model.MineralContestTeam;
import eu.billyinc.mineralcontest.task.GameCycle;
import org.bukkit.*;
import org.bukkit.command.Command;
Expand All @@ -11,19 +11,13 @@

import eu.billyinc.mineralcontest.manager.MineralContestManager;
import eu.billyinc.mineralcontest.model.MineralContestChest;
import eu.billyinc.mineralcontest.model.MineralContestPlayer;

public class MineralContestCommand implements CommandExecutor {

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {

if (args[0].toLowerCase().equals("setspawn") && sender instanceof Player) {
MineralContestManager.getMineralContestGameManager().setSpawn(((Player) sender).getLocation().getBlock().getLocation());
sender.sendMessage("spawn seted!");

return true;
}

if (args[0].toLowerCase().equals("setarenalocation") && sender instanceof Player) {
MineralContestManager.getMineralContestGameManager().setArenaLocation(((Player) sender).getLocation());
sender.sendMessage("arena location seted!");
Expand All @@ -45,11 +39,11 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}

if (args[0].toLowerCase().equals("chest") && sender instanceof Player) {
if (MineralContestManager.getApp().getGameState() == GameState.PLAYING) {
MineralContestChest mcChest = new MineralContestChest(MineralContestManager.getMineralContestGameManager().getSpawn());

mcChest.drop();
}
Player player = (Player) sender;

MineralContestChest mcChest = new MineralContestChest(player.getLocation());
mcChest.drop();

return true;
}

Expand All @@ -60,7 +54,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St

if (args[0].toLowerCase().equals("setlimit") && sender instanceof Player) {
WorldBorder wb = ((Player) sender).getWorld().getWorldBorder();
wb.setCenter(MineralContestManager.getMineralContestGameManager().getSpawn());
wb.setCenter(MineralContestManager.getMineralContestGameManager().getArenaChestLocation());
wb.setSize(Integer.valueOf(args[1]));

return true;
Expand All @@ -77,9 +71,14 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
Player player = (Player) sender;

if (MineralContestManager.getMineralContestChestManager().getMineralContestArenaChest() instanceof MineralContestChest) {
Team team = MineralContestManager.getApp().getPlayerTeamMap().get(player.getUniqueId()).getTeam();
for (Player p : team.getPlayers()) {
p.teleport(MineralContestManager.getMineralContestGameManager().getArenaLocation());
MineralContestPlayer mineralContestPlayer = MineralContestManager.getMineralContestPlayerManager().getMineralContestPlayerByUUID(player.getUniqueId());
if (mineralContestPlayer instanceof MineralContestPlayer) {
MineralContestTeam mineralContestTeam = MineralContestManager.getApp().getTeamByName(mineralContestPlayer.getTeamName());
if (mineralContestTeam instanceof MineralContestTeam) {
for (Player p : mineralContestTeam.getPlayers()) {
p.teleport(MineralContestManager.getMineralContestGameManager().getArenaLocation());
}
}
}
} else {
player.sendMessage(ChatColor.RED + "L'arène n'est plus disponible");
Expand Down Expand Up @@ -112,6 +111,31 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
sender.sendMessage(ChatColor.RED + "Tu doit être opérateur du serveur pour éxécuter cette commande");
}
}

if (args[0].toLowerCase().equals("pls") && sender instanceof Player) {
Player player = (Player) sender;
MineralContestPlayer mineralContestPlayer = MineralContestManager.getMineralContestPlayerManager().getMineralContestPlayerByUUID(player.getUniqueId());
if (mineralContestPlayer instanceof MineralContestPlayer) {
sender.sendMessage(ChatColor.RED + mineralContestPlayer.getPlayer().getName() + " a pour team " + mineralContestPlayer.getTeamName());
}
}

if (args[0].toLowerCase().equals("setteamspawnlocation") && sender instanceof Player) {
if (args.length > 1 ) {
Player player = (Player) sender;
MineralContestTeam team = MineralContestManager.getApp().getTeamByName("Team " + args[1]);
if (player.isOp()) {
if (team != null) {
team.setSpawn(player.getLocation());
sender.sendMessage("Le spawn de la " + team.getName() + " à été définie sur votre position");
} else {
sender.sendMessage("Equipe introuvable : argument attendu <Jaune> pour la Team Jaune");
}
} else {
sender.sendMessage(ChatColor.RED + "Tu doit être opérateur du serveur pour éxécuter cette commande");
}
}
}

return false;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package eu.billyinc.mineralcontest.listener;

import org.bukkit.block.Chest;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;

import eu.billyinc.mineralcontest.manager.MineralContestManager;
import eu.billyinc.mineralcontest.model.MineralContestChest;

public class BlockListener implements Listener {

@EventHandler
public void onBreakChest(BlockBreakEvent e) {
if (e.getBlock().getState() instanceof Chest) {
Chest chest = (Chest) e.getBlock().getState();
if(MineralContestManager.getMineralContestChestManager().getMineralContestChestByChest(chest) instanceof MineralContestChest) {
MineralContestManager.getMineralContestChestManager().removeMineralContestChest(chest);
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package eu.billyinc.mineralcontest.listener;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;

import eu.billyinc.mineralcontest.manager.MineralContestManager;
import eu.billyinc.mineralcontest.model.MineralContestPlayer;

public class EntityListener implements Listener {

@EventHandler
public void onPlayerDamaged(EntityDamageEvent e) {
if (e.getEntity() instanceof Player) {
Player player = (Player) e.getEntity();
MineralContestPlayer mineralContestPlayer = MineralContestManager.getMineralContestPlayerManager().getMineralContestPlayerByUUID(player.getUniqueId());

player.closeInventory();
mineralContestPlayer.removeAllTasks();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package eu.billyinc.mineralcontest.listener;

import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.FurnaceSmeltEvent;

import eu.billyinc.mineralcontest.GameState;
import eu.billyinc.mineralcontest.manager.MineralContestManager;

public class FurnaceListener implements Listener {

@EventHandler
public void onFurnaceBurn(FurnaceSmeltEvent e) {
if (MineralContestManager.getApp().getGameState() == GameState.PLAYING) {
if (
e.getSource().getType().equals(Material.IRON_SWORD) ||
e.getSource().getType().equals(Material.IRON_HELMET) ||
e.getSource().getType().equals(Material.IRON_BOOTS) ||
e.getSource().getType().equals(Material.IRON_LEGGINGS) ||
e.getSource().getType().equals(Material.IRON_CHESTPLATE)
) {
e.setCancelled(true);
}
}
}

}
Loading

0 comments on commit 906193b

Please sign in to comment.