use of org.bukkit.Location in project Minigames by AddstarMC.
the class TreasureHuntMechanic method timerTick.
@EventHandler
private void timerTick(MinigameTimerTickEvent event) {
if (event.getMinigame().getType() != MinigameType.GLOBAL && !event.getMinigame().getMechanicName().equals(getMechanic()))
return;
Minigame mgm = event.getMinigame();
TreasureHuntModule thm = TreasureHuntModule.getMinigameModule(mgm);
if (!thm.hasTreasureLocation() || thm.isTreasureFound())
return;
int time = event.getTimeLeft();
int hintTime1 = event.getMinigame().getTimer() - 1;
int hintTime2 = (int) (event.getMinigame().getTimer() * 0.75);
int hintTime3 = (int) (event.getMinigame().getTimer() * 0.50);
int hintTime4 = (int) (event.getMinigame().getTimer() * 0.25);
Location block = thm.getTreasureLocation();
if (time == hintTime1) {
double dfcx = 0.0;
double dfcz = 0.0;
String xdir = null;
String zdir = null;
if (mgm.getStartLocations().get(0).getX() > block.getX()) {
dfcx = mgm.getStartLocations().get(0).getX() - block.getX();
xdir = MinigameUtils.getLang("minigame.treasurehunt.hint1.west");
} else {
dfcx = block.getX() - mgm.getStartLocations().get(0).getX();
xdir = MinigameUtils.getLang("minigame.treasurehunt.hint1.east");
}
if (mgm.getStartLocations().get(0).getZ() > block.getZ()) {
dfcz = mgm.getStartLocations().get(0).getZ() - block.getZ();
zdir = MinigameUtils.getLang("minigame.treasurehunt.hint1.north");
} else {
dfcz = block.getZ() - mgm.getStartLocations().get(0).getZ();
zdir = MinigameUtils.getLang("minigame.treasurehunt.hint1.south");
}
String dir = null;
if (dfcz > dfcx) {
if (dfcx > dfcz / 2) {
dir = zdir + xdir.toLowerCase();
} else {
dir = zdir;
}
} else {
if (dfcz > dfcx / 2) {
dir = zdir + xdir.toLowerCase();
} else {
dir = xdir;
}
}
String hint = MinigameUtils.formStr("minigame.treasurehunt.hint1.hint", mgm.getName(true), dir, thm.getLocation());
MinigameUtils.broadcast(hint, mgm, "minigame.treasure.announce");
thm.addHint(ChatColor.GRAY + hint);
} else if (time == hintTime2) {
block.setY(block.getY() - 1);
String hint = MinigameUtils.formStr("minigame.treasurehunt.hint2", mgm.getName(true), block.getBlock().getType().toString().toLowerCase().replace("_", " "));
MinigameUtils.broadcast(hint, mgm, "minigame.treasure.announce");
thm.addHint(ChatColor.GRAY + hint);
block.setY(block.getY() + 1);
} else if (time == hintTime3) {
int height = block.getBlockY();
String dir;
int dist;
if (height > 62) {
dist = height - 62;
dir = MinigameUtils.getLang("minigame.treasurehunt.hint3.above");
} else {
dist = 62 - height;
dir = MinigameUtils.getLang("minigame.treasurehunt.hint3.below");
}
String hint = MinigameUtils.formStr("minigame.treasurehunt.hint3.hint", mgm.getName(true), dist, dir);
MinigameUtils.broadcast(hint, mgm, "minigame.treasure.announce");
thm.addHint(ChatColor.GRAY + hint);
} else if (time == hintTime4) {
String hint = MinigameUtils.formStr("minigame.treasurehunt.hint4", mgm.getName(true), block.getBlock().getBiome().toString().toLowerCase().replace("_", " "));
MinigameUtils.broadcast(hint, mgm, "minigame.treasure.announce");
thm.addHint(ChatColor.GRAY + hint);
}
}
use of org.bukkit.Location in project Minigames by AddstarMC.
the class MultiplayerType method playerRespawn.
/*----------------*/
/*-----EVENTS-----*/
/*----------------*/
@EventHandler(priority = EventPriority.HIGHEST)
public void playerRespawn(PlayerRespawnEvent event) {
final MinigamePlayer ply = pdata.getMinigamePlayer(event.getPlayer());
if (ply.isInMinigame() && ply.getMinigame().getType() == MinigameType.MULTIPLAYER) {
Minigame mg = ply.getMinigame();
Location respawnPos;
if (ply.getMinigame().isTeamGame()) {
Team team = ply.getTeam();
if (mg.hasStarted() && !ply.isLatejoining()) {
if (mg.isAllowedMPCheckpoints() && ply.hasCheckpoint()) {
respawnPos = ply.getCheckpoint();
} else {
List<Location> starts = new ArrayList<Location>();
if (TeamsModule.getMinigameModule(mg).hasTeamStartLocations()) {
starts.addAll(team.getStartLocations());
ply.getLoadout().equiptLoadout(ply);
} else {
starts.addAll(mg.getStartLocations());
}
Collections.shuffle(starts);
respawnPos = starts.get(0);
}
ply.getLoadout().equiptLoadout(ply);
} else {
respawnPos = mg.getLobbyPosition();
}
} else {
if (mg.hasStarted() && !ply.isLatejoining()) {
if (mg.isAllowedMPCheckpoints() && ply.hasCheckpoint()) {
respawnPos = ply.getCheckpoint();
} else {
List<Location> starts = new ArrayList<Location>();
starts.addAll(mg.getStartLocations());
Collections.shuffle(starts);
respawnPos = starts.get(0);
}
ply.getLoadout().equiptLoadout(ply);
} else {
respawnPos = mg.getLobbyPosition();
}
}
event.setRespawnLocation(respawnPos);
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
ply.getPlayer().setNoDamageTicks(60);
}
});
}
}
use of org.bukkit.Location in project Minigames by AddstarMC.
the class TreasureHuntMechanic method removeTreasure.
public static void removeTreasure(Minigame minigame) {
TreasureHuntModule thm = TreasureHuntModule.getMinigameModule(minigame);
thm.clearHints();
if (thm.hasTreasureLocation()) {
Location old = thm.getTreasureLocation();
boolean loaded = false;
Chunk c = null;
if (!old.getWorld().isChunkInUse(old.getChunk().getX(), old.getChunk().getZ())) {
old.getChunk().load();
loaded = true;
c = old.getChunk();
}
if (old.getBlock().getState() instanceof Chest) {
Chest chest = (Chest) old.getBlock().getState();
chest.getInventory().clear();
}
old.getBlock().setType(Material.AIR);
if (loaded && !c.getWorld().isChunkInUse(c.getX(), c.getZ())) {
c.unload();
}
thm.setTreasureLocation(null);
}
}
use of org.bukkit.Location in project Minigames by AddstarMC.
the class SetBlockAction method executeRegionAction.
@SuppressWarnings("deprecation")
@Override
public void executeRegionAction(MinigamePlayer player, Region region) {
Location temp = region.getFirstPoint();
for (int y = region.getFirstPoint().getBlockY(); y <= region.getSecondPoint().getBlockY(); y++) {
temp.setY(y);
for (int x = region.getFirstPoint().getBlockX(); x <= region.getSecondPoint().getBlockX(); x++) {
temp.setX(x);
for (int z = region.getFirstPoint().getBlockZ(); z <= region.getSecondPoint().getBlockZ(); z++) {
temp.setZ(z);
BlockState bs = temp.getBlock().getState();
bs.setType(Material.getMaterial(type.getFlag()));
if (usedur.getFlag()) {
bs.getData().setData(dur.getFlag().byteValue());
}
bs.update(true);
}
}
}
}
use of org.bukkit.Location in project Minigames by AddstarMC.
the class SetRegionCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
if (args != null) {
MinigamePlayer ply = Minigames.plugin.pdata.getMinigamePlayer((Player) sender);
RegionModule rmod = RegionModule.getMinigameModule(minigame);
if (args.length == 2) {
if (args[0].equalsIgnoreCase("select")) {
Location ploc = ply.getLocation();
ploc.setY(ploc.getY() - 1);
if (args[1].equals("1")) {
Location p2 = ply.getSelectionPoints()[1];
ply.clearSelection();
ply.setSelection(ploc, p2);
ply.sendMessage(ChatColor.GRAY + "Point 1 selected");
} else {
Location p2 = ply.getSelectionPoints()[0];
ply.clearSelection();
ply.setSelection(p2, ploc);
ply.sendMessage(ChatColor.GRAY + "Point 2 selected");
}
return true;
} else if (args[0].equalsIgnoreCase("create")) {
if (ply.hasSelection()) {
String name = args[1];
rmod.addRegion(name, new Region(name, ply.getSelectionPoints()[0], ply.getSelectionPoints()[1]));
ply.clearSelection();
ply.sendMessage(ChatColor.GRAY + "Created new region for " + minigame.getName(false) + " named " + name);
} else {
ply.sendMessage(ChatColor.RED + "You have not made a selection!");
}
return true;
} else if (args[0].equalsIgnoreCase("delete")) {
if (rmod.hasRegion(args[1])) {
rmod.removeRegion(args[1]);
ply.sendMessage(ChatColor.GRAY + "Removed the region named " + args[1] + " from " + minigame.getName(false));
} else {
ply.sendMessage(ChatColor.GRAY + "No region by the name " + args[1] + " was found in " + minigame.getName(false));
}
return true;
}
} else if (args.length == 1) {
if (args[0].equalsIgnoreCase("modify")) {
rmod.displayMenu(ply, null);
return true;
}
}
}
return false;
}
Aggregations