Fix a bunch of bugs and switch to a block based egg hunt. Additionally, move some location constants to match the Easter Lobby.

This commit is contained in:
AlexTheCoder 2017-04-11 22:24:50 -04:00
parent 9a58cd792e
commit f3e6c44d9b
3 changed files with 36 additions and 29 deletions

View File

@ -25,15 +25,15 @@ public class LocationConstants
public static final Location[] CHEST_LOCATIONS = {
new Location(WORLD, 34, 72, -15),
new Location(WORLD, 23, 72, -31),
new Location(WORLD, 26, 72, -35),
new Location(WORLD, -23, 72, -31),
new Location(WORLD, -34, 72, -15)
};
//new Location(world, -25.5, 73, 19.5), new Location(world, -35.5, 69, 1.5)
public static final Location FOUNTAIN_SCHEMATIC = new Location(WORLD, -35.5, 68, 1.5);
public static final Location FOUNTAIN_LOCATION = new Location(WORLD, -24.5, 72, 24.5);
public static final Location FOUNTAIN_SCHEMATIC = new Location(WORLD, -41.5, 68, 5.5);
public static final Location FOUNTAIN_LOCATION = new Location(WORLD, -30.5, 72, 28.5);
public static Location getResetLocation(Location chestLocation)
{

View File

@ -21,6 +21,7 @@ public class EggAddCommand extends CommandBase<EasterEggHunt>
if (args.length < 1)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "Usage: /addegg <yyyy-[m]m-[d]d>"));
return;
}
Plugin.addEgg(caller, args[0]);
}

View File

@ -6,7 +6,6 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@ -14,13 +13,10 @@ import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
@ -31,6 +27,7 @@ import mineplex.core.common.currency.GlobalCurrency;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.donation.DonationManager;
import mineplex.core.hologram.Hologram;
import mineplex.core.inventory.InventoryManager;
@ -81,8 +78,8 @@ public class EasterEggHunt extends MiniDbClientPlugin<EasterEggHunter>
{
String[] coords = str.split(",");
double x = Double.parseDouble(coords[0]);
double y = Double.parseDouble(coords[0]);
double z = Double.parseDouble(coords[0]);
double y = Double.parseDouble(coords[1]);
double z = Double.parseDouble(coords[2]);
return new Vector(x, y, z);
}
@ -123,9 +120,9 @@ public class EasterEggHunt extends MiniDbClientPlugin<EasterEggHunter>
}
@EventHandler
public void interactBlock(PlayerInteractAtEntityEvent event)
public void interactBlock(PlayerInteractEvent event)
{
if (event.getRightClicked() == null)
if (event.getClickedBlock() == null)
{
return;
}
@ -134,9 +131,10 @@ public class EasterEggHunt extends MiniDbClientPlugin<EasterEggHunter>
for (EasterEgg egg : _possibleEggs)
{
if (egg.isMe(event.getRightClicked()))
if (egg.isMe(event.getClickedBlock()))
{
findEgg(player, egg.getId());
event.setCancelled(true);
break;
}
}
@ -147,7 +145,7 @@ public class EasterEggHunt extends MiniDbClientPlugin<EasterEggHunter>
{
if (event.getType() == UpdateType.SEC)
{
LocalDate currentDate = LocalDate.now(ZoneId.of("UTC"));
LocalDate currentDate = LocalDate.now();
_possibleEggs.stream().filter(EasterEgg::isSpawned).filter(egg ->
{
@ -180,6 +178,14 @@ public class EasterEggHunt extends MiniDbClientPlugin<EasterEggHunter>
ps.setString(1, vecToStr(loc));
ps.setDate(2, parsed);
ps.execute();
PreparedStatement ret = c.prepareStatement("SELECT COUNT(id) FROM easterEggs WHERE eggDate=?;");
ret.setDate(1, parsed);
ResultSet rs = ret.executeQuery();
if (rs.next())
{
UtilPlayer.message(player, F.main(getName(), "There are " + rs.getInt(1) + " eggs saved for " + date + "!"));
}
}
catch (SQLException e)
{
@ -192,7 +198,7 @@ public class EasterEggHunt extends MiniDbClientPlugin<EasterEggHunter>
{
if (Get(player).getEggs().contains(eggId))
{
UtilPlayer.message(player, F.main(getName(), "You have already found this egg!"));
UtilPlayer.message(player, F.main(getName(), "You have already found this egg! There are " + F.count(EGGS_PER_DAY - Get(player).getEggs().size()) + " more eggs to find today!"));
return;
}
player.playSound(player.getLocation(), Sound.CAT_MEOW, 1, 0.7F);
@ -255,8 +261,8 @@ public class EasterEggHunt extends MiniDbClientPlugin<EasterEggHunter>
private final Integer _id;
private final Vector _loc;
private final Date _date;
private boolean _spawned;
private Location _spawn;
private ArmorStand _stand;
private Hologram _holo;
public EasterEgg(Integer id, Vector loc, Date date)
@ -264,6 +270,7 @@ public class EasterEggHunt extends MiniDbClientPlugin<EasterEggHunter>
_id = id;
_loc = loc;
_date = date;
_spawned = false;
}
public Integer getId()
@ -278,19 +285,20 @@ public class EasterEggHunt extends MiniDbClientPlugin<EasterEggHunter>
public boolean isSpawned()
{
return _stand != null;
return _spawned;
}
public boolean isMe(Entity e)
public boolean isMe(Block block)
{
return isSpawned() && e.getEntityId() == _stand.getEntityId();
return isSpawned() && UtilWorld.locToStr(block.getLocation()).equals(UtilWorld.locToStr(_spawn.getBlock().getLocation()));
}
public void setup()
{
_spawn = _loc.toLocation(Managers.get(HubManager.class).GetSpawn().getWorld());
_stand = null;
_holo = new Hologram(Managers.get(HubManager.class).getHologram(), _spawn.clone().add(0, 1.5, 0), C.cDPurple + C.Scramble + "ABC " + C.cPurpleB + "Easter Egg Hunt" + C.cDPurple + C.Scramble + " ABC");
_spawned = false;
_holo = new Hologram(Managers.get(HubManager.class).getHologram(), _spawn.clone().add(0, 2, 0), C.cDPurple + C.Scramble + "ABC " + C.cPurpleB + "Easter Egg Hunt" + C.cDPurple + C.Scramble + " ABC");
_holo.setViewDistance(4);
_holo.stop();
}
@ -300,19 +308,17 @@ public class EasterEggHunt extends MiniDbClientPlugin<EasterEggHunter>
{
return;
}
_stand = (ArmorStand)_spawn.getWorld().spawnEntity(_spawn, EntityType.ARMOR_STAND);
_stand.setItemInHand(new ItemStack(Material.EGG));
_stand.setVisible(false);
_stand.setBasePlate(false);
_spawn.getBlock().setType(Material.DRAGON_EGG);
_holo.start();
_spawned = true;
}
public void despawn()
{
if (isSpawned())
{
_stand.remove();
_stand = null;
_spawn.getBlock().setType(Material.AIR);
_spawned = false;
_holo.stop();
}
}
@ -330,7 +336,7 @@ public class EasterEggHunt extends MiniDbClientPlugin<EasterEggHunter>
List<Integer> found = new ArrayList<>();
while (resultSet.next())
{
if (resultSet.getDate("eggDate").toLocalDate().getDayOfYear() == LocalDate.now(ZoneId.of("UTC")).getDayOfYear())
if (resultSet.getDate("eggDate").toLocalDate().getDayOfYear() == LocalDate.now().getDayOfYear())
{
found.add(resultSet.getInt("eggId"));
}