use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.
the class RegionEvents method playerQuit.
@EventHandler(ignoreCancelled = true)
private void playerQuit(QuitMinigameEvent event) {
if (RegionModule.getMinigameModule(event.getMinigame()) == null) {
Minigames.debugMessage(event.getMinigame() + " called region event with no RegionModule loaded... was this intended?");
return;
}
MinigamePlayer ply = event.getMinigamePlayer();
if (ply == null)
return;
Minigame mg = ply.getMinigame();
for (Region r : RegionModule.getMinigameModule(mg).getRegions()) {
if (r.hasPlayer(ply))
r.removePlayer(ply);
}
for (Node node : RegionModule.getMinigameModule(event.getMinigame()).getNodes()) {
node.execute(Triggers.getTrigger("GAME_QUIT"), event.getMinigamePlayer());
if (event.getMinigame().getPlayers().size() > 1) {
for (NodeExecutor exec : node.getExecutors()) exec.removeTrigger(event.getMinigamePlayer());
} else {
for (NodeExecutor exec : node.getExecutors()) exec.clearTriggers();
node.setEnabled(true);
}
}
for (Region region : RegionModule.getMinigameModule(event.getMinigame()).getRegions()) {
if (region.playerInRegion(ply))
region.execute(Triggers.getTrigger("GAME_QUIT"), event.getMinigamePlayer());
if (event.getMinigame().getPlayers().size() > 1) {
for (RegionExecutor exec : region.getExecutors()) exec.removeTrigger(event.getMinigamePlayer());
} else {
for (RegionExecutor exec : region.getExecutors()) {
exec.clearTriggers();
}
region.removeTickTask();
region.setEnabled(true);
}
}
}
use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.
the class EventsTest method onPlayerDisconnect.
public void onPlayerDisconnect() {
PlayerMock mock = server.addPlayer();
mock.setLocation(server.getWorld("GAMES").getSpawnLocation());
PlayerJoinEvent event = new PlayerJoinEvent(mock, "Joined the Server");
server.getPluginManager().callEvent(event);
MinigamePlayer player = plugin.getPlayerManager().getMinigamePlayer(mock);
JoinCommand command = new JoinCommand();
String[] args = { game.getName(false) };
command.onCommand(mock, game, "", args);
assertTrue(player.isInMinigame());
PlayerQuitEvent event2 = new PlayerQuitEvent(mock, "has left the game");
server.getPluginManager().callEvent(event2);
assertFalse(player.isInMinigame());
assertFalse(plugin.getPlayerManager().hasMinigamePlayer(player.getUUID()));
}
use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.
the class ScoreSign method signUse.
@Override
public boolean signUse(Sign sign, MinigamePlayer player) {
if (player.isInMinigame() && player.getPlayer().isOnGround()) {
Minigame mg = player.getMinigame();
int score = Integer.parseInt(sign.getLine(2));
if (!mg.isTeamGame()) {
if (player.hasClaimedScore(sign.getLocation())) {
player.sendMessage(MinigameUtils.getLang("sign.score.alreadyUsed"), MinigameMessageType.ERROR);
return true;
}
player.addScore(score);
mg.setScore(player, player.getScore());
player.sendInfoMessage(MinigameUtils.formStr("sign.score.addScore", score, player.getScore()));
if (mg.getMaxScore() != 0 && mg.getMaxScorePerPlayer() <= player.getScore()) {
Minigames.getPlugin().getPlayerManager().endMinigame(player);
}
player.addClaimedScore(sign.getLocation());
} else {
TeamColor steam = TeamColor.matchColor(ChatColor.stripColor(sign.getLine(3)));
Team pteam = player.getTeam();
if (steam == null || !TeamsModule.getMinigameModule(mg).hasTeam(steam) || pteam.getColor() == steam) {
if (Minigames.getPlugin().getMinigameManager().hasClaimedScore(mg, sign.getLocation(), 0)) {
player.sendMessage(MinigameUtils.getLang("sign.score.alreadyUsedTeam"), MinigameMessageType.ERROR);
return true;
}
player.addScore(score);
mg.setScore(player, player.getScore());
pteam.addScore(score);
player.sendInfoMessage(MinigameUtils.formStr("sign.score.addScoreTeam", score, pteam.getChatColor().toString() + pteam.getScore()));
Minigames.getPlugin().getMinigameManager().addClaimedScore(mg, sign.getLocation(), 0);
if (mg.getMaxScore() != 0 && mg.getMaxScorePerPlayer() <= pteam.getScore()) {
List<MinigamePlayer> winners = new ArrayList<>(pteam.getPlayers());
List<MinigamePlayer> losers = new ArrayList<>(mg.getPlayers().size() - pteam.getPlayers().size());
for (Team t : TeamsModule.getMinigameModule(mg).getTeams()) {
if (t != pteam)
losers.addAll(t.getPlayers());
}
Minigames.getPlugin().getPlayerManager().endMinigame(mg, winners, losers);
}
}
}
} else if (player.isInMinigame() && !player.getPlayer().isOnGround()) {
player.sendMessage(MinigameUtils.getLang("sign.onGround"), MinigameMessageType.ERROR);
}
return true;
}
use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.
the class MinigameTool method openMenu.
public void openMenu(MinigamePlayer player) {
Menu men = new Menu(2, "Set Tool Mode", player);
final MenuItemCustom miselect = new MenuItemCustom("Select", MinigameUtils.stringToList("Selects and area;or points visually"), Material.DIAMOND_BLOCK);
final MenuItemCustom mideselect = new MenuItemCustom("Deselect", MinigameUtils.stringToList("Deselects an;area or points"), Material.GLASS);
final MinigamePlayer fply = player;
miselect.setClick(object -> {
if (mode != null) {
mode.select(fply, minigame, TeamsModule.getMinigameModule(minigame).getTeam(team));
}
return miselect.getItem();
});
mideselect.setClick(object -> {
if (mode != null) {
mode.deselect(fply, minigame, TeamsModule.getMinigameModule(minigame).getTeam(team));
}
return mideselect.getItem();
});
men.addItem(mideselect, men.getSize() - 1);
men.addItem(miselect, men.getSize() - 2);
List<String> teams = new ArrayList<>(TeamColor.values().length + 1);
for (TeamColor col : TeamColor.values()) teams.add(MinigameUtils.capitalize(col.toString().replace("_", " ")));
teams.add("None");
men.addItem(new MenuItemToolTeam("Team", Material.PAPER, new Callback<String>() {
@Override
public String getValue() {
if (getTeam() != null)
return MinigameUtils.capitalize(getTeam().toString().replace("_", " "));
return "None";
}
@Override
public void setValue(String value) {
setTeam(TeamColor.matchColor(value.replace(" ", "_")));
}
}, teams), men.getSize() - 3);
for (ToolMode m : ToolModes.getToolModes()) {
men.addItem(new MenuItemToolMode(m.getDisplayName(), MinigameUtils.stringToList(m.getDescription()), m.getIcon(), m));
}
men.displayMenu(player);
}
use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.
the class MinigamesTest method onQuitMinigame.
@Test
public void onQuitMinigame() {
plugin.getPlayerManager().addMinigamePlayer(player);
MinigamePlayer mplayer = plugin.getPlayerManager().getMinigamePlayer(player.getUniqueId());
plugin.getPlayerManager().joinMinigame(mplayer, game, false, 0D);
player.assertLocation(lobby, 0);
Assert.assertTrue(plugin.getPlayerManager().getMinigamePlayer(player.getUniqueId()).isInMinigame());
plugin.getPlayerManager().quitMinigame(plugin.getPlayerManager().getMinigamePlayer(player), false);
player.assertLocation(quit, 0);
assertFalse(plugin.getPlayerManager().getMinigamePlayer(player.getUniqueId()).isInMinigame());
}
Aggregations