use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.
the class Events method entityDamageEntity.
@EventHandler(priority = EventPriority.LOWEST)
private void entityDamageEntity(EntityDamageByEntityEvent event) {
if (event.getEntity() instanceof Player && event.getDamager() instanceof Snowball) {
MinigamePlayer ply = pdata.getMinigamePlayer((Player) event.getEntity());
if (ply == null)
return;
Snowball sb = (Snowball) event.getDamager();
if (ply.isInMinigame() && ply.getMinigame().hasPaintBallMode()) {
if (sb.getShooter() instanceof Player) {
MinigamePlayer shooter = pdata.getMinigamePlayer((Player) sb.getShooter());
Minigame mgm = ply.getMinigame();
if (shooter == null)
return;
if (shooter.isInMinigame() && shooter.getMinigame().equals(ply.getMinigame())) {
if (!shooter.canPvP()) {
event.setCancelled(true);
return;
}
Team plyTeam = ply.getTeam();
Team atcTeam = shooter.getTeam();
if (!mgm.isTeamGame() || plyTeam != atcTeam) {
int damage = mgm.getPaintBallDamage();
event.setDamage(damage);
}
}
}
}
} else if (event.getEntity() instanceof Player && event.getDamager() instanceof Player) {
MinigamePlayer ply = pdata.getMinigamePlayer((Player) event.getDamager());
if (ply == null)
return;
if (ply.isInMinigame() && !ply.canPvP())
event.setCancelled(true);
else if (ply.isInMinigame() && ply.getMinigame().getState() == MinigameState.ENDED && GameOverModule.getMinigameModule(ply.getMinigame()).isHumiliationMode() && GameOverModule.getMinigameModule(ply.getMinigame()).getLosers().contains(ply)) {
event.setCancelled(true);
}
} else if (event.getEntity() instanceof Player && event.getDamager() instanceof Arrow) {
Arrow arrow = (Arrow) event.getDamager();
if (arrow.getShooter() instanceof Player) {
Player ply = (Player) arrow.getShooter();
MinigamePlayer mgpl = pdata.getMinigamePlayer(ply);
if (mgpl == null)
return;
if (mgpl.isInMinigame() && !mgpl.canPvP())
event.setCancelled(true);
}
}
}
use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.
the class Events method onPlayerDeath.
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerDeath(PlayerDeathEvent event) {
final MinigamePlayer ply = pdata.getMinigamePlayer(event.getEntity().getPlayer());
if (ply == null)
return;
if (ply.isInMinigame()) {
Minigame mgm = ply.getMinigame();
if (!mgm.hasDeathDrops()) {
event.getDrops().clear();
}
String msg = "";
msg = event.getDeathMessage();
event.setDeathMessage(null);
event.setDroppedExp(0);
ply.addDeath();
ply.addRevert();
pdata.partyMode(ply);
if (ply.getPlayer().getKiller() != null) {
MinigamePlayer killer = pdata.getMinigamePlayer(ply.getPlayer().getKiller());
if (killer != null)
killer.addKill();
}
if (!msg.equals("")) {
mdata.sendMinigameMessage(mgm, msg, "error", null);
}
if (mgm.getState() == MinigameState.STARTED) {
if (mgm.getLives() > 0 && mgm.getLives() <= ply.getDeaths()) {
ply.sendMessage(MinigameUtils.getLang("player.quit.plyOutOfLives"), "error");
if (!event.getDrops().isEmpty() && mgm.getPlayers().size() == 1) {
event.getDrops().clear();
}
pdata.quitMinigame(ply, false);
} else if (mgm.getLives() > 0) {
ply.sendMessage(MinigameUtils.formStr("minigame.livesLeft", mgm.getLives() - ply.getDeaths()), null);
}
} else if (mgm.getState() == MinigameState.ENDED) {
plugin.pdata.quitMinigame(ply, true);
}
}
}
use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.
the class Events method playerInterract.
@EventHandler
public void playerInterract(PlayerInteractEvent event) {
MinigamePlayer ply = pdata.getMinigamePlayer(event.getPlayer());
if (ply == null)
return;
if (ply.isInMinigame() && !ply.canInteract()) {
event.setCancelled(true);
return;
}
if (event.getClickedBlock() != null && event.getClickedBlock().getType() == Material.DRAGON_EGG) {
if (!ply.getMinigame().allowDragonEggTeleport()) {
event.setCancelled(true);
return;
}
}
if (event.getAction() == Action.LEFT_CLICK_BLOCK && event.getPlayer().hasPermission("minigame.sign.use.details")) {
Block cblock = event.getClickedBlock();
if (cblock.getState() instanceof Sign && !event.isCancelled()) {
Sign sign = (Sign) cblock.getState();
if (sign.getLine(0).equalsIgnoreCase(ChatColor.DARK_BLUE + "[Minigame]")) {
if ((sign.getLine(1).equalsIgnoreCase(ChatColor.GREEN + "Join") || sign.getLine(1).equalsIgnoreCase(ChatColor.GREEN + "Bet")) && !ply.isInMinigame()) {
Minigame mgm = mdata.getMinigame(sign.getLine(2));
if (mgm != null && (!mgm.getUsePermissions() || event.getPlayer().hasPermission("minigame.join." + mgm.getName(false).toLowerCase()))) {
if (!mgm.isEnabled()) {
event.getPlayer().sendMessage(ChatColor.AQUA + "[Minigames] " + ChatColor.WHITE + MinigameUtils.getLang("minigame.error.notEnabled"));
} else {
event.getPlayer().sendMessage(ChatColor.GREEN + MinigameUtils.getLang("minigame.info.description"));
String status = ChatColor.AQUA + MinigameUtils.getLang("minigame.info.status.title");
if (!mgm.hasPlayers()) {
status += " " + ChatColor.GREEN + MinigameUtils.getLang("minigame.info.status.empty");
} else if (mgm.getMpTimer() == null || mgm.getMpTimer().getPlayerWaitTimeLeft() > 0) {
status += " " + ChatColor.GREEN + MinigameUtils.getLang("minigame.info.status.waitingForPlayers");
} else {
status += " " + ChatColor.RED + MinigameUtils.getLang("minigame.info.status.started");
}
if (mgm.getType() != MinigameType.SINGLEPLAYER) {
event.getPlayer().sendMessage(status);
if (mgm.canLateJoin())
event.getPlayer().sendMessage(ChatColor.AQUA + MinigameUtils.getLang("minigame.info.lateJoin.msg") + " " + ChatColor.GREEN + MinigameUtils.getLang("minigame.info.lateJoin.enabled"));
else
event.getPlayer().sendMessage(ChatColor.AQUA + MinigameUtils.getLang("minigame.info.lateJoin.msg") + " " + ChatColor.RED + MinigameUtils.getLang("minigame.info.lateJoin.disabled"));
}
if (mgm.getMinigameTimer() != null) {
event.getPlayer().sendMessage(ChatColor.AQUA + "Time left: " + MinigameUtils.convertTime(mgm.getMinigameTimer().getTimeLeft()));
}
if (mgm.isTeamGame()) {
String sc = "";
int c = 0;
for (Team t : TeamsModule.getMinigameModule(mgm).getTeams()) {
c++;
sc += t.getColor().getColor().toString() + " " + t.getScore() + ChatColor.WHITE;
if (c != TeamsModule.getMinigameModule(mgm).getTeams().size()) {
sc += " : ";
}
}
event.getPlayer().sendMessage(ChatColor.AQUA + MinigameUtils.getLang("minigame.info.score") + sc);
}
String playerCount = ChatColor.AQUA + MinigameUtils.getLang("minigame.info.playerCount") + " " + ChatColor.GRAY;
String players = ChatColor.AQUA + MinigameUtils.getLang("minigame.info.players.msg") + " ";
if (mgm.hasPlayers()) {
playerCount += mgm.getPlayers().size();
if (mgm.getType() != MinigameType.SINGLEPLAYER) {
playerCount += "/" + mgm.getMaxPlayers();
}
List<String> plyList = new ArrayList<String>();
for (MinigamePlayer pl : mgm.getPlayers()) {
plyList.add(pl.getName());
}
players += MinigameUtils.listToString(plyList);
} else {
playerCount += "0";
if (mgm.getType() != MinigameType.SINGLEPLAYER) {
playerCount += "/" + mgm.getMaxPlayers();
}
players += ChatColor.GRAY + MinigameUtils.getLang("minigame.info.players.none");
}
event.getPlayer().sendMessage(playerCount);
event.getPlayer().sendMessage(players);
}
} else if (mgm == null) {
event.getPlayer().sendMessage(ChatColor.RED + "[Minigames] " + ChatColor.WHITE + MinigameUtils.getLang("minigame.error.noMinigame"));
} else if (mgm.getUsePermissions()) {
event.getPlayer().sendMessage(ChatColor.RED + "[Minigames] " + ChatColor.WHITE + MinigameUtils.formStr("minigame.error.noPermission", "minigame.join." + mgm.getName(false).toLowerCase()));
}
}
}
}
}
ItemStack item = event.getItem();
if (item != null && MinigameUtils.isMinigameTool(item) && ply.getPlayer().hasPermission("minigame.tool")) {
MinigameTool tool = new MinigameTool(item);
event.setCancelled(true);
if (event.getPlayer().isSneaking() && (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
tool.openMenu(ply);
event.setCancelled(true);
} else if (event.getClickedBlock() != null && (event.getClickedBlock().getType() == Material.WALL_SIGN || event.getClickedBlock().getType() == Material.SIGN_POST)) {
Sign sign = (Sign) event.getClickedBlock().getState();
if (ChatColor.stripColor(sign.getLine(0)).equalsIgnoreCase("[Minigame]") && ChatColor.stripColor(sign.getLine(1)).equalsIgnoreCase("Join")) {
Minigame minigame = mdata.getMinigame(sign.getLine(2));
tool.setMinigame(minigame);
ply.sendMessage("Tools Minigame has been set to " + minigame, null);
event.setCancelled(true);
}
} else if (tool.getMode() != null && tool.getMinigame() != null) {
Minigame mg = tool.getMinigame();
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
tool.getMode().onRightClick(ply, mg, TeamsModule.getMinigameModule(mg).getTeam(tool.getTeam()), event);
} else if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
tool.getMode().onLeftClick(ply, mg, TeamsModule.getMinigameModule(mg).getTeam(tool.getTeam()), event);
}
} else if (tool.getMinigame() == null) {
ply.sendMessage("Please select a minigame. Click on the join sign, or /mg tool minigame <minigame>", null);
} else if (tool.getMode() == null) {
ply.sendMessage("Please select a tool mode. Shift + Right click", null);
}
}
//Spectator disables:
if (ply.isInMinigame() && pdata.getMinigamePlayer(event.getPlayer()).getMinigame().isSpectator(pdata.getMinigamePlayer(event.getPlayer()))) {
event.setCancelled(true);
}
}
use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.
the class EditCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
if (args != null) {
if (plugin.mdata.hasMinigame(args[0])) {
Minigame mgm = plugin.mdata.getMinigame(args[0]);
mgm.displayMenu(plugin.pdata.getMinigamePlayer((Player) sender));
// Menu menu = new Menu(6, "Edit: " + mgm.getName(), plugin.pdata.getMinigamePlayer((Player)sender));
// int slot = 0;
// for(MenuItem item : mgm.getMenuItems()){
// menu.addItem(item, slot);
// slot++;
// }
// menu.displayMenu(plugin.pdata.getMinigamePlayer((Player)sender));
} 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 EnableAllCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
MinigameData mdata = Minigames.plugin.mdata;
List<Minigame> minigames = new ArrayList<Minigame>(mdata.getAllMinigames().values());
if (args != null) {
for (String arg : args) {
if (mdata.hasMinigame(arg))
minigames.remove(mdata.getMinigame(arg));
else
sender.sendMessage(ChatColor.RED + "No Minigame found by the name \"" + arg + "\"; Ignoring...");
}
}
for (Minigame mg : minigames) {
mg.setEnabled(true);
}
sender.sendMessage(ChatColor.GRAY + String.valueOf(minigames.size()) + " Minigames enabled!");
return true;
}
Aggregations