Implement basketball features in the hub and begin setting up coordinates
This commit is contained in:
parent
5ecfaef413
commit
0eac157701
@ -235,7 +235,7 @@ public class HubManager extends MiniClientPlugin<HubClient>
|
||||
_treasureManager = new TreasureManager(_plugin, clientManager, serverStatusManager, donationManager, _inventoryManager, petManager, _gadgetManager, _blockRestore, hologramManager, statsManager, _bonusManager.getRewardManager());
|
||||
CosmeticManager cosmetics = new CosmeticManager(_plugin, clientManager, donationManager, _inventoryManager, _gadgetManager, _mountManager, petManager, _treasureManager, boosterManager);
|
||||
|
||||
_mavericksManager = new MavericksManager(plugin, cosmetics, hologramManager);
|
||||
_mavericksManager = new MavericksManager(plugin, cosmetics, hologramManager, this);
|
||||
|
||||
new SoccerManager(this, _gadgetManager);
|
||||
new KothManager(this, _gadgetManager);
|
||||
|
@ -5,6 +5,20 @@ import java.util.List;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
import java.util.function.Function;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.common.util.BukkitFuture;
|
||||
import mineplex.core.cosmetic.CosmeticManager;
|
||||
import mineplex.core.hologram.HologramManager;
|
||||
import mineplex.core.mavericks.DisplaySlot;
|
||||
import mineplex.core.mavericks.MavericksApprovedRepository;
|
||||
import mineplex.core.mavericks.MavericksApprovedWrapper;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.hub.HubManager;
|
||||
import mineplex.hub.modules.mavericks.MavericksPortalManager;
|
||||
import mineplex.hub.modules.mavericks.MavericksWorldManager;
|
||||
import mineplex.hub.modules.mavericks.basketball.BasketballManager;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
@ -30,18 +44,6 @@ import org.bukkit.event.world.ChunkUnloadEvent;
|
||||
import org.bukkit.event.world.StructureGrowEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.spigotmc.event.entity.EntityMountEvent;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.common.util.BukkitFuture;
|
||||
import mineplex.core.cosmetic.CosmeticManager;
|
||||
import mineplex.core.hologram.HologramManager;
|
||||
import mineplex.core.mavericks.DisplaySlot;
|
||||
import mineplex.core.mavericks.MavericksApprovedRepository;
|
||||
import mineplex.core.mavericks.MavericksApprovedWrapper;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.hub.modules.mavericks.MavericksPortalManager;
|
||||
import mineplex.hub.modules.mavericks.MavericksWorldManager;
|
||||
/**
|
||||
* A manager to handle all mavericks related content in the hub. Holds the mavericks portal manager in addition to handle
|
||||
* the rotation of the "best of" builds from Mavericks Master Builders.
|
||||
@ -58,7 +60,7 @@ public class MavericksManager extends MiniPlugin
|
||||
|
||||
private List<DisplaySlot> _displaySlots = new ArrayList<>();
|
||||
|
||||
public MavericksManager(JavaPlugin plugin, CosmeticManager cosmeticManager, HologramManager hologramManager)
|
||||
public MavericksManager(JavaPlugin plugin, CosmeticManager cosmeticManager, HologramManager hologramManager, HubManager hub)
|
||||
{
|
||||
super("Mavericks", plugin);
|
||||
|
||||
@ -66,6 +68,8 @@ public class MavericksManager extends MiniPlugin
|
||||
_portalManager = new MavericksPortalManager(plugin, _worldManager, cosmeticManager);
|
||||
_repoApproved = new MavericksApprovedRepository();
|
||||
|
||||
new BasketballManager(plugin, _worldManager, hub);
|
||||
|
||||
_displaySlots.add(new DisplaySlot(new Location(_worldManager.getWorld(), -41, 24, 237), hologramManager));
|
||||
_displaySlots.add(new DisplaySlot(new Location(_worldManager.getWorld(), 19, 24, 237), hologramManager));
|
||||
}
|
||||
|
@ -0,0 +1,624 @@
|
||||
package mineplex.hub.modules.mavericks.basketball;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.core.common.util.UtilEnt;
|
||||
import mineplex.core.common.util.UtilInv;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilParticle;
|
||||
import mineplex.core.common.util.UtilParticle.ParticleType;
|
||||
import mineplex.core.common.util.UtilParticle.ViewDist;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilTextBottom;
|
||||
import mineplex.core.common.util.UtilTextMiddle;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.hub.HubManager;
|
||||
import net.minecraft.server.v1_8_R3.BlockPosition;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Slime;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public class BasketballGame implements Listener
|
||||
{
|
||||
private HubManager _hub;
|
||||
private World _world;
|
||||
private List<Player> _players = Lists.newArrayList();
|
||||
private Entity _ball;
|
||||
private Player _dribbling;
|
||||
private ThrowData _throwData;
|
||||
|
||||
private static final double THREE_POINTER_DISTANCE = 27;
|
||||
|
||||
private boolean _frozen = false;
|
||||
private long _lastDribbleAnim = 0;
|
||||
private long _lastDribbleMove = 0;
|
||||
private long _start;
|
||||
|
||||
private HashMap<BasketballTeam, Block> _hoops = new HashMap<>();
|
||||
|
||||
private double _maxX = 0;
|
||||
private double _minX = 0;
|
||||
private double _maxZ = 0;
|
||||
private double _minZ = 0;
|
||||
|
||||
private double _velocity = -7;
|
||||
|
||||
private int _redScore;
|
||||
private int _blueScore;
|
||||
|
||||
public BasketballGame(JavaPlugin plugin, HubManager hub, World world)
|
||||
{
|
||||
_hub = hub;
|
||||
_world = world;
|
||||
setupMap();
|
||||
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||
beginGame();
|
||||
_start = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
//PRIVATE NON-VOID
|
||||
private Entity spawnBall(Location loc)
|
||||
{
|
||||
_velocity = -7;
|
||||
Entity e = loc.getWorld().spawnEntity(loc, EntityType.SLIME);
|
||||
UtilEnt.Vegetate(e, true);
|
||||
UtilEnt.ghost(e, true, false);
|
||||
((Slime)e).setSize(1);
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
private BasketballTeam getTeam(Player player)
|
||||
{
|
||||
if (player.getInventory().getHelmet() == null || player.getInventory().getHelmet().getType() != Material.LEATHER_HELMET)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Color color = ((LeatherArmorMeta)player.getInventory().getHelmet()).getColor();
|
||||
return BasketballTeam.getFromColor(color);
|
||||
}
|
||||
|
||||
private boolean checkCatching()
|
||||
{
|
||||
if (_ball != null)
|
||||
{
|
||||
for (Player player : _players)
|
||||
{
|
||||
if (UtilMath.offset(player, _ball) <= 1.5)
|
||||
{
|
||||
if (Recharge.Instance.usable(player, "Catch Ball", false))
|
||||
{
|
||||
catchBall(player);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private int getWorth(Location start, Location hoop)
|
||||
{
|
||||
if (UtilMath.offset2d(start, hoop) >= THREE_POINTER_DISTANCE)
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
//PRIVATE VOID
|
||||
private void reboundBall()
|
||||
{
|
||||
if (_ball == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Vector vec = _ball.getVelocity();
|
||||
//Rebound Y
|
||||
if (UtilEnt.isGrounded(_ball))
|
||||
{
|
||||
if (vec.getY() < 0)
|
||||
{
|
||||
vec.setY(_ball.getVelocity().getY() * _velocity);
|
||||
_velocity = Math.max(0, _velocity - .5);
|
||||
}
|
||||
}
|
||||
|
||||
if (!UtilEnt.isGrounded(_ball))
|
||||
{
|
||||
vec.setY(vec.getY() - 0.08);
|
||||
}
|
||||
|
||||
//Rebound X
|
||||
if ((vec.getX() > 0 && _ball.getLocation().getX() >= _maxX) || (vec.getX() < 0 && _ball.getLocation().getX() <= _minX))
|
||||
{
|
||||
vec.setX(vec.getX() * -1);
|
||||
|
||||
vec = vec.multiply(0.9);
|
||||
}
|
||||
|
||||
//Rebound Z
|
||||
if ((vec.getZ() > 0 && _ball.getLocation().getZ() >= _maxZ) || (vec.getZ() < 0 && _ball.getLocation().getZ() <= _minZ))
|
||||
{
|
||||
vec.setZ(vec.getZ() * -1);
|
||||
|
||||
vec = vec.multiply(0.9);
|
||||
}
|
||||
|
||||
_ball.setVelocity(vec);
|
||||
}
|
||||
|
||||
private void spawnNeutralBall()
|
||||
{
|
||||
Location loc = DataLoc.CENTER_COURT.getLocation(_world);
|
||||
_ball = spawnBall(loc);
|
||||
}
|
||||
|
||||
private void throwBall(Player origin, boolean right)
|
||||
{
|
||||
Entity e = spawnBall(origin.getEyeLocation());
|
||||
|
||||
double power = 1.7;
|
||||
if (right)
|
||||
{
|
||||
power = 3.1;
|
||||
}
|
||||
e.setVelocity(origin.getEyeLocation().getDirection().normalize().multiply(power));
|
||||
|
||||
Recharge.Instance.use(origin, "Catch Ball", 3000, false, false, false);
|
||||
_ball = e;
|
||||
|
||||
if (_dribbling != null)
|
||||
{
|
||||
UtilInv.removeAll(_dribbling, Material.SLIME_BALL, (byte)0);
|
||||
_dribbling = null;
|
||||
}
|
||||
|
||||
_throwData = new ThrowData(origin, getTeam(origin));
|
||||
}
|
||||
|
||||
private void catchBall(Player player)
|
||||
{
|
||||
_lastDribbleMove = System.currentTimeMillis();
|
||||
_dribbling = player;
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
_dribbling.getInventory().setItem(i, new ItemBuilder(Material.SLIME_BALL).setTitle(C.cGold + "Basketball").build());
|
||||
}
|
||||
_ball.remove();
|
||||
_ball = null;
|
||||
_throwData = null;
|
||||
}
|
||||
|
||||
private void setupMap()
|
||||
{
|
||||
Block redHoop = DataLoc.RED_HOOP.getLocation(_world).getBlock();
|
||||
redHoop.setType(Material.WEB);
|
||||
Block blueHoop = DataLoc.BLUE_HOOP.getLocation(_world).getBlock();
|
||||
blueHoop.setType(Material.WEB);
|
||||
|
||||
_hoops.put(BasketballTeam.RED, redHoop);
|
||||
_hoops.put(BasketballTeam.BLUE, blueHoop);
|
||||
|
||||
_maxX = DataLoc.CORNER_MAX.getLocation(_world).getX();
|
||||
_minX = DataLoc.CORNER_MIN.getLocation(_world).getX();
|
||||
_maxZ = DataLoc.CORNER_MAX.getLocation(_world).getZ();
|
||||
_minZ = DataLoc.CORNER_MIN.getLocation(_world).getZ();
|
||||
}
|
||||
|
||||
private void beginGame()
|
||||
{
|
||||
spawnNeutralBall();
|
||||
_ball.setVelocity(_ball.getVelocity().add(new Vector(0, 1.5, 0)));
|
||||
}
|
||||
|
||||
private void stealBall(Player to, Player from)
|
||||
{
|
||||
Recharge.Instance.use(to, "ThrowBall", 1500, false, false, false);
|
||||
_lastDribbleMove = System.currentTimeMillis();
|
||||
_dribbling = to;
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
to.getInventory().setItem(i, new ItemBuilder(Material.SLIME_BALL).setTitle(C.cGold + "Basketball").build());
|
||||
}
|
||||
UtilInv.removeAll(from, Material.SLIME_BALL, (byte)0);
|
||||
for (Player player : _players)
|
||||
{
|
||||
UtilPlayer.message(player, F.main("Game", getTeam(to).getChatColor() + to.getName() + C.cGray + " has stolen the ball from " + getTeam(from).getChatColor() + from.getName() + C.cGray + "!"));
|
||||
}
|
||||
}
|
||||
|
||||
private void score(BasketballTeam team, Location hoop)
|
||||
{
|
||||
int points = getWorth(_throwData.getThrowOrigin(), hoop);
|
||||
if (team == BasketballTeam.RED)
|
||||
{
|
||||
_redScore += points;
|
||||
}
|
||||
else if (team == BasketballTeam.BLUE)
|
||||
{
|
||||
_blueScore += points;
|
||||
}
|
||||
UtilTextMiddle.display(team.getName() + " has scored!", BasketballTeam.RED.getChatColor() + "" + _redScore + C.cWhite + " - " + BasketballTeam.BLUE.getChatColor() + _blueScore, 0, 20 * 2, 0, _players.toArray(new Player[] {}));
|
||||
_ball.remove();
|
||||
_ball = null;
|
||||
_throwData = null;
|
||||
|
||||
BasketballTeam other = getOtherTeam(team);
|
||||
List<Player> teamD = Lists.newArrayList();
|
||||
List<Player> teamO = Lists.newArrayList();
|
||||
|
||||
for (Player player : _players)
|
||||
{
|
||||
if (getTeam(player) == team)
|
||||
{
|
||||
teamO.add(player);
|
||||
}
|
||||
else
|
||||
{
|
||||
teamD.add(player);
|
||||
}
|
||||
}
|
||||
|
||||
//Select player to get ball
|
||||
Player carrier = teamD.get(new Random().nextInt(teamD.size()));
|
||||
|
||||
for (int i = 0; i < teamD.size(); i++)
|
||||
{
|
||||
Player player = teamD.get(i);
|
||||
if (carrier.getEntityId() != player.getEntityId())
|
||||
{
|
||||
Location loc = null;
|
||||
int locId = i;
|
||||
if (other == BasketballTeam.BLUE)
|
||||
{
|
||||
locId = Math.min(DataLoc.BLUE_SCORE_SPAWN.getLocations(_world).length - 1, locId);
|
||||
loc = DataLoc.BLUE_SCORE_SPAWN.getLocations(_world)[locId];
|
||||
}
|
||||
else if (other == BasketballTeam.RED)
|
||||
{
|
||||
locId = Math.min(DataLoc.RED_SCORE_SPAWN.getLocations(_world).length - 1, locId);
|
||||
loc = DataLoc.RED_SCORE_SPAWN.getLocations(_world)[locId];
|
||||
}
|
||||
|
||||
if (loc != null)
|
||||
{
|
||||
player.teleport(loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < teamO.size(); i++)
|
||||
{
|
||||
Player player = teamO.get(i);
|
||||
int locId = Math.min(i, team.getSpawns(_world).length);
|
||||
player.teleport(team.getSpawns(_world)[locId]);
|
||||
}
|
||||
|
||||
Location teleport = DataLoc.BLUE_HOOP.getLocation(_world);
|
||||
if (other == BasketballTeam.RED)
|
||||
teleport = DataLoc.RED_UNDER_HOOP.getLocation(_world);
|
||||
|
||||
teleport.setPitch(UtilAlg.GetPitch(UtilAlg.getTrajectory(teleport, DataLoc.CENTER_COURT.getLocation(_world))));
|
||||
teleport.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(teleport, DataLoc.CENTER_COURT.getLocation(_world))));
|
||||
carrier.teleport(teleport);
|
||||
|
||||
_lastDribbleMove = System.currentTimeMillis();
|
||||
_dribbling = carrier;
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
_dribbling.getInventory().setItem(i, new ItemBuilder(Material.SLIME_BALL).setTitle(C.cGold + "Basketball").build());
|
||||
}
|
||||
}
|
||||
|
||||
private void checkScoring()
|
||||
{
|
||||
if (_ball == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (BasketballTeam team : _hoops.keySet())
|
||||
{
|
||||
Location check = _hoops.get(team).getLocation().add(.5, 0, .5);
|
||||
|
||||
if (UtilMath.offset(check, _ball.getLocation()) <= .9)
|
||||
{
|
||||
score(getOtherTeam(team), check);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void dribble()
|
||||
{
|
||||
if (_dribbling == null)
|
||||
{
|
||||
_lastDribbleAnim = System.currentTimeMillis();
|
||||
return;
|
||||
}
|
||||
|
||||
UtilTextBottom.display(C.cRed + "You have the ball!", _dribbling);
|
||||
UtilParticle.PlayParticleToAll(ParticleType.HAPPY_VILLAGER, _dribbling.getEyeLocation(), new Random().nextFloat(), new Random().nextFloat(), new Random().nextFloat(), 0, 1, ViewDist.MAX);
|
||||
|
||||
if (System.currentTimeMillis() - _lastDribbleAnim > 333)
|
||||
{
|
||||
_lastDribbleAnim = System.currentTimeMillis();
|
||||
Item item = _dribbling.getWorld().dropItem(_dribbling.getLocation(), new ItemStack(Material.SLIME_BALL));
|
||||
item.setPickupDelay(Integer.MAX_VALUE);
|
||||
Bukkit.getScheduler().runTaskLater(_hub.getPlugin(), () -> {
|
||||
item.remove();
|
||||
}, 7);
|
||||
}
|
||||
}
|
||||
|
||||
//PUBLIC NON-VOID
|
||||
public long getGameAge()
|
||||
{
|
||||
return System.currentTimeMillis() - _start;
|
||||
}
|
||||
|
||||
public boolean isOutOfBounds(Location loc, boolean ball)
|
||||
{
|
||||
if (ball)
|
||||
{
|
||||
if ((loc.getX() - 1) > _maxX || (loc.getX() + 1) < _minX)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if ((loc.getZ() - 1) > _maxZ || (loc.getZ() + 1) < _minZ)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (loc.getX() >= _maxX || loc.getX() <= _minX)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (loc.getZ() >= _maxZ || loc.getZ() <= _minZ)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public Entity getBall()
|
||||
{
|
||||
return _ball;
|
||||
}
|
||||
|
||||
/**
|
||||
* Quickly searches for the opposite team of the one given
|
||||
* @param team The team to check
|
||||
* @return The opposite team
|
||||
*/
|
||||
public BasketballTeam getOtherTeam(BasketballTeam team)
|
||||
{
|
||||
if (team == BasketballTeam.RED)
|
||||
{
|
||||
return BasketballTeam.BLUE;
|
||||
}
|
||||
if (team == BasketballTeam.BLUE)
|
||||
{
|
||||
return BasketballTeam.RED;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Player> getPlayers()
|
||||
{
|
||||
return _players;
|
||||
}
|
||||
|
||||
//PUBLIC VOID
|
||||
public void end()
|
||||
{
|
||||
HandlerList.unregisterAll(this);
|
||||
if (_ball != null)
|
||||
{
|
||||
_ball.remove();
|
||||
}
|
||||
if (_dribbling != null)
|
||||
{
|
||||
UtilInv.removeAll(_dribbling, Material.SLIME_BALL, (byte)0);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onSwipe(EntityDamageByEntityEvent event)
|
||||
{
|
||||
if (_frozen)
|
||||
return;
|
||||
|
||||
if (!(event.getEntity() instanceof Player) || !(event.getDamager() instanceof Player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_players.contains((Player)event.getEntity()) || !_players.contains((Player)event.getDamager()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player)event.getDamager();
|
||||
Player target = (Player)event.getEntity();
|
||||
|
||||
if (_dribbling != null && getTeam(player) != getTeam(target) && target.getEntityId() == _dribbling.getEntityId())
|
||||
{
|
||||
if (Recharge.Instance.usable(player, "Steal Ball", true))
|
||||
{
|
||||
Recharge.Instance.use(player, "Steal Ball", 1000 * 5, true, false, false);
|
||||
if (new Random().nextDouble() <= .15)
|
||||
{
|
||||
stealBall(player, target);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.sendMessage(F.main("Game", "Your steal attempt failed!"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onThrow(PlayerInteractEvent event)
|
||||
{
|
||||
if (_frozen)
|
||||
return;
|
||||
|
||||
if (_dribbling != null && event.getPlayer().getEntityId() == _dribbling.getEntityId() && Recharge.Instance.usable(_dribbling, "ThrowBall", false))
|
||||
{
|
||||
throwBall(event.getPlayer(), event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler
|
||||
public void onUpdate(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() == UpdateType.FASTEST)
|
||||
{
|
||||
for (Player player : _players)
|
||||
{
|
||||
CraftPlayer cp = (CraftPlayer)player;
|
||||
for (int x = (int)Math.floor(cp.getHandle().getBoundingBox().a + 0.001); x <= (int)Math.floor(cp.getHandle().getBoundingBox().d - 0.001); x++)
|
||||
{
|
||||
for (int y = (int)Math.floor(cp.getHandle().getBoundingBox().b + 0.001); y <= (int)Math.floor(cp.getHandle().getBoundingBox().e - 0.001); y++)
|
||||
{
|
||||
for (int z = (int)Math.floor(cp.getHandle().getBoundingBox().c + 0.001); z <= (int)Math.floor(cp.getHandle().getBoundingBox().f - 0.001); z++)
|
||||
{
|
||||
CraftWorld world = (CraftWorld)_world;
|
||||
if (net.minecraft.server.v1_8_R3.Block.getId(world.getHandle().getType(new BlockPosition(x, y, z)).getBlock()) == Material.WEB.getId())
|
||||
{
|
||||
player.teleport(new Location(player.getWorld(), x, y - 2, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_dribbling != null && !_dribbling.isOnline())
|
||||
{
|
||||
_dribbling = null;
|
||||
spawnNeutralBall();
|
||||
}
|
||||
|
||||
if (_ball != null)
|
||||
{
|
||||
if (isOutOfBounds(_ball.getLocation(), true))
|
||||
{
|
||||
if (_ball.hasMetadata("Respawn"))
|
||||
{
|
||||
if (UtilTime.elapsed(_ball.getMetadata("Respawn").get(0).asLong(), 2000))
|
||||
{
|
||||
_ball.removeMetadata("Respawn", _hub.getPlugin());
|
||||
_ball.setVelocity(UtilAlg.getTrajectory(_ball.getLocation(), DataLoc.CENTER_COURT.getLocation(_world)));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_ball.setMetadata("Respawn", new FixedMetadataValue(_hub.getPlugin(), System.currentTimeMillis()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_ball.hasMetadata("Respawn"))
|
||||
{
|
||||
_ball.removeMetadata("Respawn", _hub.getPlugin());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
reboundBall();
|
||||
|
||||
if (!checkCatching())
|
||||
{
|
||||
checkScoring();
|
||||
}
|
||||
|
||||
dribble();
|
||||
|
||||
if (_dribbling != null)
|
||||
{
|
||||
if (UtilTime.elapsed(_lastDribbleMove, 15000))
|
||||
{
|
||||
throwBall(_dribbling, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onMove(PlayerMoveEvent event)
|
||||
{
|
||||
if (!_players.contains(event.getPlayer()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (UtilMath.offset2d(event.getFrom(), event.getTo()) <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_frozen)
|
||||
{
|
||||
event.setTo(event.getFrom());
|
||||
return;
|
||||
}
|
||||
|
||||
if (isOutOfBounds(event.getTo(), false))
|
||||
{
|
||||
event.getPlayer().teleport(event.getFrom());
|
||||
Vector bounce = UtilAlg.getTrajectory(event.getTo(), DataLoc.CENTER_COURT.getLocation(_world));
|
||||
event.getPlayer().setVelocity(bounce.normalize());
|
||||
event.getPlayer().sendMessage(F.main("Game", "You aren't allowed to go out of bounds!"));
|
||||
}
|
||||
if (_dribbling != null && event.getPlayer().getEntityId() == _dribbling.getEntityId())
|
||||
{
|
||||
_lastDribbleMove = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,311 @@
|
||||
package mineplex.hub.modules.mavericks.basketball;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilAction;
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.event.StackerEvent;
|
||||
import mineplex.core.gadget.event.GadgetEnableEvent;
|
||||
import mineplex.core.gadget.event.GadgetSelectLocationEvent;
|
||||
import mineplex.core.gadget.gadgets.outfit.OutfitTeam;
|
||||
import mineplex.core.gadget.types.Gadget;
|
||||
import mineplex.core.gadget.types.GadgetType;
|
||||
import mineplex.core.mount.event.MountActivateEvent;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.hub.HubManager;
|
||||
import mineplex.hub.modules.mavericks.MavericksWorldManager;
|
||||
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Bat;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Firework;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.entity.WitherSkull;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerVelocityEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public class BasketballManager extends MiniPlugin
|
||||
{
|
||||
private HubManager _hubManager;
|
||||
private MavericksWorldManager _world;
|
||||
private ArrayList<OutfitTeam> _teamArmor = Lists.newArrayList();
|
||||
private BasketballGame _game;
|
||||
|
||||
public BasketballManager(JavaPlugin plugin, MavericksWorldManager world, HubManager hub)
|
||||
{
|
||||
super("Basketball Manager", plugin);
|
||||
_world = world;
|
||||
_hubManager = hub;
|
||||
|
||||
for (Gadget outfit : hub.GetGadget().getGadgets(GadgetType.COSTUME))
|
||||
{
|
||||
if (outfit instanceof OutfitTeam)
|
||||
{
|
||||
_teamArmor.add((OutfitTeam)outfit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable()
|
||||
{
|
||||
if (_game != null)
|
||||
{
|
||||
_game.end();
|
||||
_game = null;
|
||||
}
|
||||
}
|
||||
|
||||
public Color getTeamColor(Player player)
|
||||
{
|
||||
//All pieces are always same color!
|
||||
for (OutfitTeam outfit : _teamArmor)
|
||||
{
|
||||
if (outfit.isActive(player))
|
||||
return outfit.getTeamColor(player);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean inPlayerArena(Entity entity)
|
||||
{
|
||||
if(!entity.getWorld().equals(_world.getWorld()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Location loc = entity.getLocation();
|
||||
|
||||
return (loc.getX() > DataLoc.CORNER_MIN.getLocation(_world.getWorld()).getX() && loc.getX() < DataLoc.CORNER_MAX.getLocation(_world.getWorld()).getX()) && (loc.getZ() > DataLoc.CORNER_MIN.getLocation(_world.getWorld()).getZ() && loc.getZ() < DataLoc.CORNER_MAX.getLocation(_world.getWorld()).getZ());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void clean(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.FASTER)
|
||||
return;
|
||||
|
||||
for (Entity ent : _world.getWorld().getEntities())
|
||||
{
|
||||
if (ent instanceof Player)
|
||||
continue;
|
||||
|
||||
if (_game != null && _game.getBall() != null && _game.getBall().equals(ent))
|
||||
continue;
|
||||
|
||||
if (inPlayerArena(ent))
|
||||
{
|
||||
if (ent instanceof Bat || ent instanceof WitherSkull || ent instanceof TNTPrimed || ent instanceof Firework)
|
||||
{
|
||||
ent.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
Location bounce = UtilAlg.getMidpoint(DataLoc.CORNER_MAX.getLocation(_world.getWorld()), DataLoc.CORNER_MIN.getLocation(_world.getWorld()));
|
||||
bounce.setY(Math.min(DataLoc.CORNER_MAX.getLocation(_world.getWorld()).getY(), DataLoc.CORNER_MIN.getLocation(_world.getWorld()).getY()));
|
||||
|
||||
Entity bottom = ent;
|
||||
if (bottom.getVehicle() != null)
|
||||
bottom = bottom.getVehicle();
|
||||
|
||||
UtilAction.velocity(bottom, UtilAlg.getTrajectory(bounce, ent.getLocation()), 1, false, 0, 0.4, 1, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (_game != null && _game.getGameAge() > 5000 && _game.getPlayers().size() < 1)
|
||||
{
|
||||
_game.end();
|
||||
_game = null;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void joinLeaveGame(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.TICK)
|
||||
return;
|
||||
|
||||
for (Player player : UtilServer.getPlayers())
|
||||
{
|
||||
if (_game != null && _game.getPlayers().contains(player))
|
||||
{
|
||||
if (!inPlayerArena(player))
|
||||
{
|
||||
setBasketballMode(player, false, null);
|
||||
continue;
|
||||
}
|
||||
|
||||
//Took armor off
|
||||
Color color = getTeamColor(player);
|
||||
if (color == null || (color != Color.RED && color != Color.AQUA))
|
||||
{
|
||||
setBasketballMode(player, false, null);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (inPlayerArena(player))
|
||||
{
|
||||
Color color = getTeamColor(player);
|
||||
|
||||
if (color != null && (color == BasketballTeam.RED.getColor() || color == BasketballTeam.BLUE.getColor()) && _game == null)
|
||||
{
|
||||
_game = new BasketballGame(getPlugin(), _hubManager, _world.getWorld());
|
||||
}
|
||||
|
||||
//Join
|
||||
if (color != null && (color == Color.RED || color == Color.AQUA) && _game != null && _game.getPlayers().size() < 10)
|
||||
{
|
||||
setBasketballMode(player, true, color);
|
||||
}
|
||||
//Eject
|
||||
else
|
||||
{
|
||||
Location bounce = UtilAlg.getMidpoint(DataLoc.CORNER_MAX.getLocation(_world.getWorld()), DataLoc.CORNER_MIN.getLocation(_world.getWorld()));
|
||||
bounce.setY(Math.min(DataLoc.CORNER_MAX.getLocation(_world.getWorld()).getY(), DataLoc.CORNER_MIN.getLocation(_world.getWorld()).getY()));
|
||||
|
||||
Entity bottom = player;
|
||||
if (bottom.getVehicle() != null)
|
||||
bottom = bottom.getVehicle();
|
||||
|
||||
UtilAction.velocity(bottom, UtilAlg.getTrajectory2d(bounce, player.getLocation()), 1, false, 0, 0.8, 1, true);
|
||||
|
||||
if (Recharge.Instance.use(player, "Basketball Eject", 5000, false, false))
|
||||
{
|
||||
if (_game == null || (_game != null && _game.getPlayers().size() < 10))
|
||||
{
|
||||
UtilPlayer.message(player, F.main("Slimeball", "You must be wearing Red/Blue Team Outfit."));
|
||||
UtilPlayer.message(player, F.main("Slimeball", "Type " + F.elem("/team red") + " or " + F.elem("/team blue") + "!"));
|
||||
}
|
||||
else
|
||||
{
|
||||
UtilPlayer.message(player, F.main("Slimeball", "The game is currently full!"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setBasketballMode(Player player, boolean enabled, Color color)
|
||||
{
|
||||
if (_game == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (enabled)
|
||||
{
|
||||
_game.getPlayers().add(player);
|
||||
|
||||
if (color == null)
|
||||
UtilPlayer.message(player, F.main("Basketball", "You have entered " + F.elem("Basketball Mode") + "."));
|
||||
else if (color == Color.RED)
|
||||
UtilPlayer.message(player, F.main("Basketball", "You have joined " + F.elem(C.cRed + "Red Basketball Team") + "."));
|
||||
else if (color == Color.AQUA)
|
||||
UtilPlayer.message(player, F.main("Basketball", "You have joined " + F.elem(C.cAqua + "Blue Basketball Team") + "."));
|
||||
|
||||
ArrayList<String> outfit = new ArrayList<String>();
|
||||
outfit.add("Team Helmet");
|
||||
outfit.add("Team Shirt");
|
||||
outfit.add("Team Pants");
|
||||
outfit.add("Team Boots");
|
||||
|
||||
_hubManager.GetGadget().disableAll(player, outfit);
|
||||
_hubManager.GetMount().DisableAll(player);
|
||||
_hubManager.getPetManager().disableAll(player);
|
||||
}
|
||||
else
|
||||
{
|
||||
_game.getPlayers().remove(player);
|
||||
UtilPlayer.message(player, F.main("Parkour", "You have exited " + F.elem("Basketball Mode") + "."));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void disableGadgets(GadgetEnableEvent event)
|
||||
{
|
||||
if (_game != null && _game.getPlayers().contains(event.getPlayer()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void disableMounts(MountActivateEvent event)
|
||||
{
|
||||
if (_game != null && _game.getPlayers().contains(event.getPlayer()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void playerGrabSlime(PlayerInteractEntityEvent event)
|
||||
{
|
||||
if (_game != null && _game.getPlayers().contains(event.getPlayer()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
if (_game != null && _game.getBall() != null && event.getRightClicked().equals(_game.getBall()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void disableStacker(StackerEvent event)
|
||||
{
|
||||
if (_game != null && _game.getPlayers().contains(event.getEntity()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void disableGuardianLazer(GadgetSelectLocationEvent event)
|
||||
{
|
||||
if (_game != null && !_game.isOutOfBounds(event.getLocation(), false))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void disableVelocity(PlayerVelocityEvent event)
|
||||
{
|
||||
// Disable velocity but allow double jumping.
|
||||
|
||||
if (_game != null && _game.getPlayers().contains(event.getPlayer()) && !_hubManager.getJumpManager().hasDoubleJumped(event.getPlayer()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerQuit(PlayerQuitEvent event)
|
||||
{
|
||||
if (_game != null)
|
||||
{
|
||||
_game.getPlayers().remove(event.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package mineplex.hub.modules.mavericks.basketball;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
public enum BasketballTeam
|
||||
{
|
||||
RED(Color.RED, ChatColor.RED, "Red", DataLoc.RED_SPAWNS),
|
||||
BLUE(Color.AQUA, ChatColor.AQUA, "Blue", DataLoc.BLUE_SPAWNS)
|
||||
;
|
||||
|
||||
private Color _color;
|
||||
private ChatColor _cColor;
|
||||
private String _name;
|
||||
private DataLoc _spawns;
|
||||
|
||||
private BasketballTeam(Color color, ChatColor cColor, String name, DataLoc spawns)
|
||||
{
|
||||
_color = color;
|
||||
_cColor = cColor;
|
||||
_name = name;
|
||||
_spawns = spawns;
|
||||
}
|
||||
|
||||
public Color getColor()
|
||||
{
|
||||
return _color;
|
||||
}
|
||||
|
||||
public ChatColor getChatColor()
|
||||
{
|
||||
return _cColor;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return _cColor + _name + " Team";
|
||||
}
|
||||
|
||||
public Location[] getSpawns(World world)
|
||||
{
|
||||
return _spawns.getLocations(world);
|
||||
}
|
||||
|
||||
public static BasketballTeam getFromColor(Color color)
|
||||
{
|
||||
for (BasketballTeam team : BasketballTeam.values())
|
||||
{
|
||||
if (team.getColor() == color)
|
||||
{
|
||||
return team;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package mineplex.hub.modules.mavericks.basketball;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
/**
|
||||
* Enum for easy references to data location keys
|
||||
*/
|
||||
public enum DataLoc
|
||||
{
|
||||
RED_HOOP(0, 0, 0),
|
||||
BLUE_HOOP(0, 0, 0),
|
||||
CENTER_COURT(0, 8, -1),
|
||||
CORNER_MIN(-24, 8, -47),
|
||||
CORNER_MAX(24, 8, 45),
|
||||
RED_SCORE_SPAWN(0, 0, 0),
|
||||
RED_UNDER_HOOP(0, 0, 0),
|
||||
BLUE_SCORE_SPAWN(0, 0, 0),
|
||||
BLUE_UNDER_HOOP(0, 0, 0),
|
||||
RED_SPAWNS(new Double[] {}, new Double[] {}, new Double[] {}),
|
||||
BLUE_SPAWNS(new Double[] {}, new Double[] {}, new Double[] {})
|
||||
;
|
||||
|
||||
private Double[] _x, _y, _z;
|
||||
|
||||
private DataLoc(Double[] x, Double[] y, Double[] z)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_z = z;
|
||||
}
|
||||
|
||||
private DataLoc(double x, double y, double z)
|
||||
{
|
||||
this(new Double[] {x}, new Double[] {y}, new Double[] {z});
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the Locations bound to this DataLoc
|
||||
* @param world The world to input this DataLoc's coordinates into
|
||||
* @return The Locations for this DataLoc
|
||||
*/
|
||||
public Location[] getLocations(World world)
|
||||
{
|
||||
Location[] array = new Location[_x.length];
|
||||
|
||||
for (int i = 0; i < _x.length; i++)
|
||||
{
|
||||
array[i] = new Location(world, _x[i], _y[i], _z[i]);
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the first Location bound to this DataLoc
|
||||
* @param world The world to input this DataLoc's coordinates into
|
||||
* @return The first Location for this DataLoc
|
||||
*/
|
||||
public Location getLocation(World world)
|
||||
{
|
||||
if (getLocations(world).length < 1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return getLocations(world)[0];
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package mineplex.hub.modules.mavericks.basketball;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Data class to store information about the last throw of a ball
|
||||
*/
|
||||
public class ThrowData
|
||||
{
|
||||
private BasketballTeam _team;
|
||||
private Location _location;
|
||||
|
||||
public ThrowData(Player thrower, BasketballTeam team)
|
||||
{
|
||||
_team = team;
|
||||
_location = thrower.getEyeLocation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Request the player who threw the ball
|
||||
* @return The player who threw the ball
|
||||
*/
|
||||
public BasketballTeam getThrower()
|
||||
{
|
||||
return _team;
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests the location where the ball was thrown from
|
||||
* @return The origin location of the throw
|
||||
*/
|
||||
public Location getThrowOrigin()
|
||||
{
|
||||
return _location;
|
||||
}
|
||||
}
|
@ -369,9 +369,9 @@ public class Basketball extends TeamGame
|
||||
|
||||
for (GameTeam team : _hoops.keySet())
|
||||
{
|
||||
Location check = _hoops.get(team).getLocation();
|
||||
Location check = _hoops.get(team).getLocation().add(.5, 0, .5);
|
||||
|
||||
if (UtilMath.offset(check, _ball.getLocation()) <= 1.3)
|
||||
if (UtilMath.offset(check, _ball.getLocation()) <= .9)
|
||||
{
|
||||
score(getOtherTeam(team), check);
|
||||
return;
|
||||
@ -514,6 +514,11 @@ public class Basketball extends TeamGame
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IsPlaying((Player)event.getEntity()) || !IsPlaying((Player)event.getDamager()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player)event.getDamager();
|
||||
Player target = (Player)event.getEntity();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user