use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.
the class ToolCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
MinigamePlayer player = Minigames.plugin.pdata.getMinigamePlayer((Player) sender);
if (args == null) {
MinigameUtils.giveMinigameTool(player);
} else if (MinigameUtils.hasMinigameTool(player)) {
if (args[0].equalsIgnoreCase("minigame") && args.length == 2) {
if (Minigames.plugin.mdata.hasMinigame(args[1])) {
MinigameTool tool;
Minigame mg = Minigames.plugin.mdata.getMinigame(args[1]);
if (!MinigameUtils.hasMinigameTool(player))
tool = MinigameUtils.giveMinigameTool(player);
else
tool = MinigameUtils.getMinigameTool(player);
tool.setMinigame(mg);
} else {
sender.sendMessage(ChatColor.RED + "No Minigame found by the name \"" + args[1] + "\"");
}
} else if (args[0].equalsIgnoreCase("select")) {
MinigameTool tool;
if (!MinigameUtils.hasMinigameTool(player))
tool = MinigameUtils.giveMinigameTool(player);
else
tool = MinigameUtils.getMinigameTool(player);
if (tool.getMinigame() != null && tool.getMode() != null) {
tool.getMode().select(player, tool.getMinigame(), TeamsModule.getMinigameModule(tool.getMinigame()).getTeam(tool.getTeam()));
} else if (tool.getMode() == null)
sender.sendMessage(ChatColor.RED + "You must have a mode selected to select anything!");
else
sender.sendMessage(ChatColor.RED + "You must have a valid Minigame selected to use this tool!");
} else if (args[0].equalsIgnoreCase("deselect")) {
MinigameTool tool;
if (!MinigameUtils.hasMinigameTool(player))
tool = MinigameUtils.giveMinigameTool(player);
else
tool = MinigameUtils.getMinigameTool(player);
if (tool.getMinigame() != null && tool.getMode() != null) {
tool.getMode().deselect(player, tool.getMinigame(), TeamsModule.getMinigameModule(tool.getMinigame()).getTeam(tool.getTeam()));
} else if (tool.getMode() == null)
sender.sendMessage(ChatColor.RED + "You must have a mode selected to deselect anything!");
else
sender.sendMessage(ChatColor.RED + "You must have a valid Minigame selected to use this tool!");
} else if (args[0].equalsIgnoreCase("team") && args.length == 2) {
if (TeamColor.matchColor(args[1]) != null || args[1].equalsIgnoreCase("none")) {
MinigameTool tool;
if (!MinigameUtils.hasMinigameTool(player))
tool = MinigameUtils.giveMinigameTool(player);
else
tool = MinigameUtils.getMinigameTool(player);
if (args[1].equalsIgnoreCase("none"))
tool.setTeam(null);
else
tool.setTeam(TeamColor.matchColor(args[1]));
sender.sendMessage(ChatColor.GRAY + "Set the tools team to " + args[1]);
} else {
sender.sendMessage(ChatColor.RED + args[1] + " is not a valid team color!");
}
} else if (ToolModes.getToolMode(args[0]) != null) {
MinigameTool tool;
if (!MinigameUtils.hasMinigameTool(player))
tool = MinigameUtils.giveMinigameTool(player);
else
tool = MinigameUtils.getMinigameTool(player);
tool.setMode(ToolModes.getToolMode(args[0]));
sender.sendMessage(ChatColor.GRAY + "Set the tools mode to '" + tool.getMode().getName().toLowerCase().replace("_", " ") + "'");
} else {
return false;
}
} else {
sender.sendMessage(ChatColor.RED + "You must have a Minigame Tool! Type \"/minigame tool\" to recieve one.");
}
return true;
}
use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.
the class DeleteCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
if (args != null) {
Minigame mgm = plugin.mdata.getMinigame(args[0]);
if (mgm != null) {
File save = new File(plugin.getDataFolder() + "/minigames/" + mgm.getName(false));
if (save.exists() && save.isDirectory()) {
if (save.list().length == 0) {
save.delete();
} else {
for (String file : save.list()) {
File nfile = new File(save, file);
nfile.delete();
}
save.delete();
}
List<String> ls = plugin.getConfig().getStringList("minigames");
ls.remove(mgm.getName(false));
plugin.getConfig().set("minigames", ls);
plugin.mdata.removeMinigame(mgm.getName(false));
plugin.saveConfig();
sender.sendMessage(ChatColor.RED + "The minigame " + mgm.getName(false) + " has been removed");
}
}
return true;
}
return false;
}
use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.
the class SaveCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
if (args != null) {
if (plugin.mdata.hasMinigame(args[0])) {
Minigame mg = plugin.mdata.getMinigame(args[0]);
mg.saveMinigame();
sender.sendMessage(ChatColor.GRAY + mg.getName(false) + " has been saved.");
} else {
sender.sendMessage(ChatColor.RED + "There is no Minigame by the name: " + args[0]);
}
return true;
}
return false;
}
use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.
the class JoinCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
Player player = (Player) sender;
if (args != null) {
Minigame mgm = plugin.mdata.getMinigame(args[0]);
if (mgm != null && (!mgm.getUsePermissions() || player.hasPermission("minigame.join." + mgm.getName(false).toLowerCase()))) {
if (!plugin.pdata.getMinigamePlayer(player).isInMinigame()) {
sender.sendMessage(ChatColor.GREEN + MinigameUtils.formStr("command.join.joining", mgm.getName(false)));
plugin.pdata.joinMinigame(plugin.pdata.getMinigamePlayer(player), mgm, false, 0.0);
} else {
player.sendMessage(ChatColor.RED + MinigameUtils.getLang("command.join.alreadyPlaying"));
}
} else if (mgm != null && mgm.getUsePermissions()) {
player.sendMessage(ChatColor.RED + MinigameUtils.formStr("command.join.noMinigamePermission", "minigame.join." + mgm.getName(false).toLowerCase()));
} else {
player.sendMessage(ChatColor.RED + MinigameUtils.getLang("minigame.error.noMinigame"));
}
return true;
}
return false;
}
use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.
the class PlayerKillsMechanic method playerAttackPlayer.
@EventHandler
private void playerAttackPlayer(PlayerDeathEvent event) {
MinigamePlayer ply = pdata.getMinigamePlayer(event.getEntity());
if (ply == null)
return;
Minigame mgm = ply.getMinigame();
if (ply.isInMinigame() && mgm.getMechanicName().equals("kills")) {
MinigamePlayer attacker = null;
if (ply.getPlayer().getKiller() != null) {
attacker = pdata.getMinigamePlayer(ply.getPlayer().getKiller());
if (attacker == ply) {
return;
}
} else {
return;
}
if (!mgm.equals(attacker.getMinigame())) {
return;
}
if (ply.getTeam() == null) {
attacker.addScore();
mgm.setScore(attacker, attacker.getScore());
if (mgm.getMaxScore() != 0 && attacker.getScore() >= mgm.getMaxScorePerPlayer()) {
List<MinigamePlayer> losers = new ArrayList<MinigamePlayer>(mgm.getPlayers().size() - 1);
List<MinigamePlayer> winner = new ArrayList<MinigamePlayer>(1);
winner.add(attacker);
for (MinigamePlayer player : mgm.getPlayers()) {
if (player != attacker)
losers.add(player);
}
pdata.endMinigame(mgm, winner, losers);
}
} else {
Team team = ply.getTeam();
Team ateam = attacker.getTeam();
if (team != ateam) {
attacker.addScore();
mgm.setScore(attacker, attacker.getScore());
ateam.addScore();
if (mgm.getMaxScore() != 0 && mgm.getMaxScorePerPlayer() <= ateam.getScore()) {
mdata.sendMinigameMessage(mgm, MinigameUtils.formStr("player.kills.finalKill", attacker.getName(), ply.getName()), null, null);
List<MinigamePlayer> w = new ArrayList<MinigamePlayer>(ateam.getPlayers());
List<MinigamePlayer> l = new ArrayList<MinigamePlayer>(mgm.getPlayers().size() - ateam.getPlayers().size());
for (Team t : TeamsModule.getMinigameModule(mgm).getTeams()) {
if (t != ateam)
l.addAll(t.getPlayers());
}
plugin.pdata.endMinigame(mgm, w, l);
}
}
}
}
}
Aggregations