use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.
the class Events method onPlayerDisconnect.
@EventHandler
public void onPlayerDisconnect(PlayerQuitEvent event) {
MinigamePlayer ply = pdata.getMinigamePlayer(event.getPlayer());
if (ply.isInMinigame()) {
if (ply.getPlayer().isDead()) {
ply.getOfflineMinigamePlayer().setLoginLocation(ply.getMinigame().getQuitPosition());
ply.getOfflineMinigamePlayer().savePlayerData();
}
pdata.quitMinigame(pdata.getMinigamePlayer(event.getPlayer()), false);
} else if (ply.isRequiredQuit()) {
ply.getOfflineMinigamePlayer().setLoginLocation(ply.getQuitPos());
ply.getOfflineMinigamePlayer().savePlayerData();
}
pdata.removeMinigamePlayer(event.getPlayer());
plugin.display.removeAll(event.getPlayer());
if (Bukkit.getServer().getOnlinePlayers().isEmpty()) {
for (String mgm : mdata.getAllMinigames().keySet()) {
if (mdata.getMinigame(mgm).getType() == MinigameType.GLOBAL) {
if (mdata.getMinigame(mgm).getMinigameTimer() != null)
mdata.getMinigame(mgm).getMinigameTimer().stopTimer();
}
}
}
ply.saveClaimedRewards();
}
use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.
the class MinigameTimer method runTimer.
private void runTimer() {
time -= 1;
if (minigame.isUsingXPBarTimer()) {
float timeper = ((Integer) time).floatValue() / ((Integer) otime).floatValue();
int level = 0;
if (time / 60 > 0)
level = time / 60;
else
level = time;
for (MinigamePlayer ply : minigame.getPlayers()) {
if (timeper < 0) {
ply.getPlayer().setExp(0);
ply.getPlayer().setLevel(0);
} else {
ply.getPlayer().setExp(timeper);
ply.getPlayer().setLevel(level);
}
}
}
if (timeMsg.contains(time) && broadcastTime) {
PlayMGSound.playSound(minigame, MGSounds.getSound("timerTick"));
plugin.getMinigameManager().sendMinigameMessage(minigame, MinigameUtils.formStr("minigame.timeLeft", MinigameUtils.convertTime(time)));
}
if (time <= 0) {
Bukkit.getServer().getPluginManager().callEvent(new TimerExpireEvent(minigame));
stopTimer();
}
if (time > 0)
Bukkit.getPluginManager().callEvent(new MinigameTimerTickEvent(minigame, minigame.getMinigameTimer()));
}
use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.
the class Minigames method initMetrics.
private void initMetrics() {
this.metrics = new Metrics(this, 1190);
final Metrics.MultiLineChart chart = new Metrics.MultiLineChart("Players_in_Minigames", () -> {
final Map<String, Integer> result = new HashMap<>();
result.put("Total_Players", this.playerManager.getAllMinigamePlayers().size());
for (final MinigamePlayer pl : this.playerManager.getAllMinigamePlayers()) {
if (pl.isInMinigame()) {
int count = result.getOrDefault(pl.getMinigame().getType().getName(), 0);
result.put(pl.getMinigame().getType().getName(), count + 1);
}
}
return result;
});
final Metrics.SimpleBarChart barChart = new Metrics.SimpleBarChart("Modules_v_Servers", () -> {
final Map<String, Integer> result = new HashMap<>();
for (final Class module : this.minigameManager.getModules()) {
result.put(module.getCanonicalName(), 1);
}
return result;
});
this.metrics.addCustomChart(chart);
this.metrics.addCustomChart(barChart);
}
use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.
the class Events method onTeleportAway.
@EventHandler
public void onTeleportAway(PlayerTeleportEvent event) {
MinigamePlayer ply = pdata.getMinigamePlayer(event.getPlayer());
if (ply == null)
return;
if (ply.isInMinigame() && (event.getCause() == TeleportCause.COMMAND || event.getCause() == TeleportCause.PLUGIN || (!ply.getMinigame().isAllowedEnderpearls() && event.getCause() == TeleportCause.ENDER_PEARL))) {
if (!ply.getAllowTeleport()) {
Location from = event.getFrom();
Location to = event.getTo();
if (from.getWorld() != to.getWorld() || from.distance(to) > 2) {
event.setCancelled(true);
event.getPlayer().sendMessage(ChatColor.RED + "[Minigames] " + ChatColor.WHITE + MinigameUtils.getLang("minigame.error.noTeleport"));
}
}
}
}
use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.
the class Events method itemPickup.
@EventHandler(ignoreCancelled = true)
public void itemPickup(EntityPickupItemEvent event) {
if (event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity();
MinigamePlayer ply = pdata.getMinigamePlayer(player);
if (ply.isInMinigame()) {
Minigame mgm = ply.getMinigame();
if (!mgm.hasItemPickup() || mgm.isSpectator(ply)) {
event.setCancelled(true);
}
}
}
}
Aggregations