use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.
the class FinishSign method signUse.
@Override
public boolean signUse(Sign sign, MinigamePlayer player) {
if (player.isInMinigame() && player.getPlayer().getInventory().getItemInMainHand().getType() == Material.AIR) {
Minigame minigame = player.getMinigame();
if (minigame.isSpectator(player) || minigame.getState() == MinigameState.ENDED) {
return false;
}
if (!minigame.getFlags().isEmpty()) {
if (player.getPlayer().isOnGround()) {
if (plugin.pdata.checkRequiredFlags(player, minigame.getName(false)).isEmpty()) {
if (sign.getLine(2).isEmpty() || sign.getLine(2).equals(player.getMinigame().getName(false))) {
if (player.getMinigame().isTeamGame()) {
List<MinigamePlayer> w = new ArrayList<MinigamePlayer>(player.getTeam().getPlayers());
List<MinigamePlayer> l = new ArrayList<MinigamePlayer>(minigame.getPlayers().size() - player.getTeam().getPlayers().size());
for (Team t : TeamsModule.getMinigameModule(minigame).getTeams()) {
if (t != player.getTeam())
l.addAll(t.getPlayers());
}
plugin.pdata.endMinigame(minigame, w, l);
} else {
if (minigame.getType() == MinigameType.MULTIPLAYER) {
List<MinigamePlayer> w = new ArrayList<MinigamePlayer>(1);
w.add(player);
List<MinigamePlayer> l = new ArrayList<MinigamePlayer>(minigame.getPlayers().size());
l.addAll(minigame.getPlayers());
l.remove(player);
plugin.pdata.endMinigame(minigame, w, l);
} else
plugin.pdata.endMinigame(player);
}
plugin.pdata.partyMode(player, 3, 10L);
}
} else {
List<String> requiredFlags = plugin.pdata.checkRequiredFlags(player, minigame.getName(false));
String flags = "";
int num = requiredFlags.size();
for (int i = 0; i < num; i++) {
flags += requiredFlags.get(i);
if (i != num - 1) {
flags += ", ";
}
}
player.sendMessage(ChatColor.AQUA + "[Minigames] " + ChatColor.WHITE + MinigameUtils.getLang("sign.finish.requireFlags"));
player.sendMessage(ChatColor.GRAY + flags);
}
}
return true;
} else {
if (player.getPlayer().isOnGround()) {
if (player.getMinigame().isTeamGame()) {
List<MinigamePlayer> w = new ArrayList<MinigamePlayer>(player.getTeam().getPlayers());
List<MinigamePlayer> l = new ArrayList<MinigamePlayer>(minigame.getPlayers().size() - player.getTeam().getPlayers().size());
for (Team t : TeamsModule.getMinigameModule(minigame).getTeams()) {
if (t != player.getTeam())
l.addAll(t.getPlayers());
}
plugin.pdata.endMinigame(minigame, w, l);
} else {
if (minigame.getType() == MinigameType.MULTIPLAYER) {
List<MinigamePlayer> w = new ArrayList<MinigamePlayer>(1);
w.add(player);
List<MinigamePlayer> l = new ArrayList<MinigamePlayer>(minigame.getPlayers().size());
l.addAll(minigame.getPlayers());
l.remove(player);
plugin.pdata.endMinigame(minigame, w, l);
} else
plugin.pdata.endMinigame(player);
}
plugin.pdata.partyMode(player);
return true;
}
}
} else if (player.getPlayer().getInventory().getItemInMainHand().getType() != Material.AIR) {
player.sendMessage(ChatColor.RED + "[Minigames] " + ChatColor.WHITE + MinigameUtils.getLang("sign.emptyHand"));
}
return false;
}
use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.
the class TeamSign method signUse.
@Override
public boolean signUse(Sign sign, MinigamePlayer player) {
if (player.isInMinigame()) {
Minigame mgm = player.getMinigame();
if (mgm.isTeamGame()) {
if (player.getTeam() != matchTeam(mgm, sign.getLine(2))) {
if (!mgm.isWaitingForPlayers() && !sign.getLine(2).equals(ChatColor.GRAY + "Neutral")) {
Team sm = null;
Team nt = matchTeam(mgm, sign.getLine(2));
if (nt != null) {
if (!nt.isFull()) {
for (Team t : TeamsModule.getMinigameModule(mgm).getTeams()) {
if (sm == null || t.getPlayers().size() < sm.getPlayers().size())
sm = t;
}
if (nt.getPlayers().size() - sm.getPlayers().size() < 1) {
MultiplayerType.switchTeam(mgm, player, nt);
plugin.mdata.sendMinigameMessage(mgm, String.format(nt.getGameAssignMessage(), player.getDisplayName(mgm.usePlayerDisplayNames()), nt.getChatColor() + nt.getDisplayName()), null, player);
player.sendMessage(String.format(nt.getAssignMessage(), nt.getChatColor() + nt.getDisplayName()), null);
} else {
player.sendMessage(ChatColor.AQUA + "[Minigames] " + ChatColor.WHITE + MinigameUtils.getLang("sign.team.noUnbalance"));
}
player.getPlayer().damage(player.getPlayer().getHealth());
} else {
player.sendMessage(MinigameUtils.getLang("player.team.full"), "error");
}
}
} else if (sign.getLine(2).equals(ChatColor.GRAY + "Neutral") || matchTeam(mgm, sign.getLine(2)) != player.getTeam()) {
Team cur = player.getTeam();
if (cur != null) {
Team nt = matchTeam(mgm, sign.getLine(2));
if (nt != null) {
if (nt.getPlayers().size() - cur.getPlayers().size() < 2) {
MultiplayerType.switchTeam(mgm, player, nt);
plugin.mdata.sendMinigameMessage(mgm, String.format(nt.getGameAssignMessage(), player.getName(), nt.getChatColor() + nt.getDisplayName()), null, player);
player.sendMessage(String.format(nt.getAssignMessage(), nt.getChatColor() + nt.getDisplayName()), null);
} else {
player.sendMessage(ChatColor.AQUA + "[Minigames] " + ChatColor.WHITE + MinigameUtils.getLang("sign.team.noUnbalance"));
}
} else {
player.removeTeam();
}
} else {
Team nt = matchTeam(mgm, sign.getLine(2));
if (nt != null) {
if (nt.getPlayers().size() < nt.getMaxPlayers()) {
MultiplayerType.switchTeam(mgm, player, nt);
plugin.mdata.sendMinigameMessage(mgm, String.format(nt.getGameAssignMessage(), player.getName(), nt.getChatColor() + nt.getDisplayName()), null, player);
player.sendMessage(String.format(nt.getAssignMessage(), nt.getChatColor() + nt.getDisplayName()), null);
} else {
player.sendMessage(ChatColor.AQUA + "[Minigames] " + ChatColor.WHITE + MinigameUtils.getLang("player.team.full"));
}
}
}
}
}
}
}
return false;
}
use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.
the class Minigames method onDisable.
public void onDisable() {
if (plugin == null) {
return;
}
PluginDescriptionFile desc = this.getDescription();
log.info(desc.getName() + " successfully disabled.");
for (Player p : getServer().getOnlinePlayers()) {
if (pdata.getMinigamePlayer(p).isInMinigame()) {
pdata.quitMinigame(pdata.getMinigamePlayer(p), true);
}
}
for (Minigame minigame : mdata.getAllMinigames().values()) {
if (minigame.getType() == MinigameType.GLOBAL && minigame.getMechanicName().equals("treasure_hunt") && minigame.isEnabled()) {
if (minigame.getMinigameTimer() != null)
minigame.getMinigameTimer().stopTimer();
TreasureHuntMechanic.removeTreasure(minigame);
}
}
for (Minigame mg : mdata.getAllMinigames().values()) {
mg.saveMinigame();
}
backend.shutdown();
// pdata.saveDCPlayers();
pdata.saveDeniedCommands();
MinigameSave globalLoadouts = new MinigameSave("globalLoadouts");
if (mdata.hasLoadouts()) {
for (String loadout : mdata.getLoadouts()) {
// }
for (Integer slot : mdata.getLoadout(loadout).getItems()) {
globalLoadouts.getConfig().set(loadout + "." + slot, mdata.getLoadout(loadout).getItem(slot));
}
if (!mdata.getLoadout(loadout).getAllPotionEffects().isEmpty()) {
for (PotionEffect eff : mdata.getLoadout(loadout).getAllPotionEffects()) {
globalLoadouts.getConfig().set(loadout + ".potions." + eff.getType().getName() + ".amp", eff.getAmplifier());
globalLoadouts.getConfig().set(loadout + ".potions." + eff.getType().getName() + ".dur", eff.getDuration());
}
} else {
globalLoadouts.getConfig().set(loadout + ".potions", null);
}
if (mdata.getLoadout(loadout).getUsePermissions()) {
globalLoadouts.getConfig().set(loadout + ".usepermissions", true);
} else {
globalLoadouts.getConfig().set(loadout + ".usepermissions", null);
}
}
} else {
globalLoadouts.getConfig().set("globalloadouts", null);
}
globalLoadouts.saveConfig();
mdata.saveRewardSigns();
}
use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.
the class Minigames method onEnable.
public void onEnable() {
try {
plugin = this;
PluginDescriptionFile desc = this.getDescription();
MinigameSave sv = new MinigameSave("lang/" + getConfig().getString("lang"));
lang = sv.getConfig();
loadLang();
lang.setDefaults(defLang);
getLogger().info("Using lang " + getConfig().getString("lang"));
String prespath = getDataFolder() + "/presets/";
String[] presets = { "spleef", "lms", "ctf", "infection" };
File pres;
for (String preset : presets) {
pres = new File(prespath + preset + ".yml");
if (!pres.exists()) {
saveResource("presets/" + preset + ".yml", false);
}
}
mdata = new MinigameData();
pdata = new PlayerData();
display = new DisplayManager();
mdata.addMinigameType(new SingleplayerType());
// mdata.addMinigameType(new FreeForAllType());
// mdata.addMinigameType(new TeamsType());
mdata.addMinigameType(new MultiplayerType());
MinigameSave completion = new MinigameSave("completion");
mdata.addConfigurationFile("completion", completion.getConfig());
getServer().getPluginManager().registerEvents(new Events(), this);
getServer().getPluginManager().registerEvents(new BasicRecorder(), this);
try {
this.getConfig().load(this.getDataFolder() + "/config.yml");
List<String> mgs = new ArrayList<String>();
if (getConfig().contains("minigames")) {
mgs = getConfig().getStringList("minigames");
}
final List<String> allMGS = new ArrayList<String>();
allMGS.addAll(mgs);
if (!mgs.isEmpty()) {
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
for (String minigame : allMGS) {
final Minigame game = new Minigame(minigame);
try {
game.loadMinigame();
mdata.addMinigame(game);
} catch (Exception e) {
getLogger().severe(ChatColor.RED.toString() + "Failed to load \"" + minigame + "\"! The configuration file may be corrupt or missing!");
e.printStackTrace();
}
}
}
}, 1L);
}
} catch (FileNotFoundException ex) {
log.info("Failed to load config, creating one.");
try {
this.getConfig().save(this.getDataFolder() + "/config.yml");
} catch (IOException e) {
log.log(Level.SEVERE, "Could not save config.yml!");
e.printStackTrace();
}
} catch (Exception e) {
log.log(Level.SEVERE, "Failed to load config!");
e.printStackTrace();
}
if (!setupEconomy()) {
getLogger().info("No Vault plugin found! You may only reward items.");
}
backend = new BackendManager(getLogger());
if (!backend.initialize(getConfig())) {
getServer().getPluginManager().disablePlugin(this);
return;
}
getConfig().options().copyDefaults(true);
saveConfig();
Calendar cal = Calendar.getInstance();
if (cal.get(Calendar.DAY_OF_MONTH) == 21 && cal.get(Calendar.MONTH) == 8 || cal.get(Calendar.DAY_OF_MONTH) == 25 && cal.get(Calendar.MONTH) == 11 || cal.get(Calendar.DAY_OF_MONTH) == 1 && cal.get(Calendar.MONTH) == 0) {
getLogger().info(ChatColor.GREEN.name() + "Party Mode enabled!");
pdata.setPartyMode(true);
}
// pdata.loadDCPlayers();
pdata.loadDeniedCommands();
MinigameSave globalLoadouts = new MinigameSave("globalLoadouts");
Set<String> keys = globalLoadouts.getConfig().getKeys(false);
for (String loadout : keys) {
mdata.addLoadout(loadout);
Set<String> items = globalLoadouts.getConfig().getConfigurationSection(loadout).getKeys(false);
// }
for (String slot : items) {
if (slot.matches("[0-9]+"))
mdata.getLoadout(loadout).addItem(globalLoadouts.getConfig().getItemStack(loadout + "." + slot), Integer.parseInt(slot));
}
if (globalLoadouts.getConfig().contains(loadout + ".potions")) {
Set<String> pots = globalLoadouts.getConfig().getConfigurationSection(loadout + ".potions").getKeys(false);
for (String eff : pots) {
if (PotionEffectType.getByName(eff) != null) {
PotionEffect effect = new PotionEffect(PotionEffectType.getByName(eff), globalLoadouts.getConfig().getInt(loadout + ".potions." + eff + ".dur"), globalLoadouts.getConfig().getInt(loadout + ".potions." + eff + ".amp"));
mdata.getLoadout(loadout).addPotionEffect(effect);
}
}
}
if (globalLoadouts.getConfig().contains(loadout + ".usepermissions")) {
mdata.getLoadout(loadout).setUsePermissions(globalLoadouts.getConfig().getBoolean(loadout + ".usepermissions"));
}
}
minigameSigns = new SignBase();
mdata.loadRewardSigns();
CommandDispatcher disp = new CommandDispatcher();
getCommand("minigame").setExecutor(disp);
getCommand("minigame").setTabCompleter(disp);
for (Player player : getServer().getOnlinePlayers()) {
pdata.addMinigamePlayer(player);
}
initMetrics();
log.info(desc.getName() + " successfully enabled.");
} catch (Throwable e) {
plugin = null;
getLogger().log(Level.SEVERE, "Failed to enable Minigames " + getDescription().getVersion() + ": ", e);
getPluginLoader().disablePlugin(this);
}
}
use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.
the class QuitCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
if (args == null && sender instanceof Player) {
MinigamePlayer player = plugin.pdata.getMinigamePlayer((Player) sender);
if (player.isInMinigame()) {
plugin.pdata.quitMinigame(player, false);
} else {
sender.sendMessage(ChatColor.RED + MinigameUtils.getLang("command.quit.notPlaying"));
}
return true;
} else if (args != null) {
Player player = null;
if (sender instanceof Player) {
player = (Player) sender;
}
if (player == null || player.hasPermission("minigame.quit.other")) {
List<Player> players = plugin.getServer().matchPlayer(args[0]);
MinigamePlayer ply = null;
if (args[0].equals("ALL")) {
if (args.length > 1) {
if (plugin.mdata.hasMinigame(args[1])) {
Minigame mg = plugin.mdata.getMinigame(args[1]);
List<MinigamePlayer> pls = new ArrayList<MinigamePlayer>(mg.getPlayers());
for (MinigamePlayer pl : pls) {
plugin.pdata.quitMinigame(pl, true);
}
sender.sendMessage(ChatColor.GRAY + MinigameUtils.formStr("command.quit.quitAllMinigame", mg.getName(true)));
} else {
sender.sendMessage(ChatColor.RED + MinigameUtils.formStr("minigame.error.noMinigameName", args[1]));
}
} else {
for (MinigamePlayer pl : plugin.getPlayerData().getAllMinigamePlayers()) {
if (pl.isInMinigame()) {
plugin.pdata.quitMinigame(pl, true);
}
}
sender.sendMessage(ChatColor.GRAY + MinigameUtils.getLang("command.quit.quitAll"));
}
return true;
} else if (players.isEmpty()) {
sender.sendMessage(ChatColor.RED + MinigameUtils.formStr("command.quit.invalidPlayer", args[0]));
return true;
} else {
ply = plugin.pdata.getMinigamePlayer(players.get(0));
}
if (ply != null && ply.isInMinigame()) {
plugin.pdata.quitMinigame(ply, false);
sender.sendMessage(ChatColor.GRAY + MinigameUtils.formStr("command.quit.quitOther", ply.getName()));
} else {
sender.sendMessage(ChatColor.RED + MinigameUtils.formStr("command.quit.invalidPlayer", args[0]));
}
} else if (player != null) {
sender.sendMessage(ChatColor.RED + MinigameUtils.getLang("command.quit.noPermissionOther"));
sender.sendMessage(ChatColor.RED + "minigame.quit.other");
}
return true;
}
return false;
}
Aggregations