Added Mavericks module to Hub

This commit is contained in:
xGamingDudex 2016-06-23 01:17:16 +02:00
parent 318c137aba
commit 31352a86d7
3 changed files with 229 additions and 0 deletions

View File

@ -0,0 +1,72 @@
package mineplex.hub.modules;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.event.EventHandler;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.BukkitFuture;
import mineplex.core.mavericks.MavericksApprovedRepository;
import mineplex.core.mavericks.MavericksBuildWrapper;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.hub.modules.mavericks.DisplaySlot;
import mineplex.hub.modules.mavericks.MavericksPortalManager;
public class MavericksManager extends MiniPlugin
{
private MavericksPortalManager _portalManager;
private MavericksApprovedRepository _repoApproved;
private List<DisplaySlot> _displaySlots = new ArrayList<>();
public MavericksManager(JavaPlugin plugin)
{
super("Mavericks", plugin);
_portalManager = new MavericksPortalManager(_plugin);
_repoApproved = new MavericksApprovedRepository();
}
@EventHandler
public void onUpdate(UpdateEvent event)
{
if(event.getType() != UpdateType.MIN_02) return;
_repoApproved.getToDisplay(true, _displaySlots.size(), 0).thenCompose(BukkitFuture.accept((list) ->
{
List<DisplaySlot> openSlots = new ArrayList<>();
List<MavericksBuildWrapper> undisplayedData = new ArrayList<>();
undisplayedData.addAll(list);
slots:
for(DisplaySlot slot : _displaySlots)
{
for(MavericksBuildWrapper build : list)
{
if(slot.getData().getBuildId() == build.getBuildId())
{
undisplayedData.remove(build);
continue slots;
}
}
openSlots.add(slot);
}
for(int i = 0; i < Math.min(openSlots.size(), undisplayedData.size()); i++)
{
openSlots.get(i).setData(undisplayedData.get(i));
}
}));
}
public MavericksPortalManager getPortalManager()
{
return _portalManager;
}
}

View File

@ -0,0 +1,47 @@
package mineplex.hub.modules.mavericks;
import org.bukkit.Location;
import mineplex.core.common.block.schematic.Schematic;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.mavericks.MavericksBuildWrapper;
public class DisplaySlot
{
private MavericksBuildWrapper _data;
private Location _loc;
public DisplaySlot(Location loc)
{
_loc = loc.clone();
}
public MavericksBuildWrapper getData()
{
return _data;
}
public void setData(MavericksBuildWrapper data)
{
Schematic schematic = data.getSchematic();
Location a = _loc;
Location b = _loc.clone().add(schematic.getWidth(), schematic.getHeight(), schematic.getLength());
for(int x = a.getBlockX(); x < b.getX(); x++)
{
for(int y = a.getBlockY(); y < b.getY(); y++)
{
for(int z = a.getBlockZ(); z < b.getZ(); z++)
{
UtilBlock.setQuick(a.getWorld(), x, y, z, 0, (byte) 0);
}
}
}
schematic.paste(_loc, true, false);
_data = data;
}
}

View File

@ -0,0 +1,110 @@
package mineplex.hub.modules.mavericks;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.F;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
public class MavericksPortalManager extends MiniPlugin
{
private Set<Player> _cooldown = new HashSet<>();
private Box _portalHubMavericks;
private Box _portalMavericksHub;
private Location _destHub;
private Location _destMavericks;
public MavericksPortalManager(JavaPlugin plugin)
{
super("Mavericks Teleporter", plugin);
_portalHubMavericks = new Box("world", new Vector(0, 200, 0), new Vector(10, 210, 10));
_destMavericks = new Location(Bukkit.getWorld("world"), 100, 200, 100);
_portalMavericksHub = new Box("world", new Vector(0, 100, 0), new Vector(10, 110, 10));
_destHub = new Location(Bukkit.getWorld("world"), 100, 100, 100);
}
@EventHandler
public void onUpdate(UpdateEvent event)
{
if(event.getType() != UpdateType.FASTER) return;
for(Iterator<Player> it = _cooldown.iterator(); it.hasNext();)
{
if(isInside(it.next()) == null) it.remove();
}
for(Player p : Bukkit.getOnlinePlayers())
{
if(_cooldown.contains(p)) continue;
Box box = isInside(p);
if(box == null) continue;
if(box == _portalHubMavericks)
{
p.teleport(_destMavericks);
p.sendMessage(F.main("Teleporter", "Teleported to " + F.item("mavericks") + " area."));
}
else if (box == _portalMavericksHub)
{
p.teleport(_destHub);
p.sendMessage(F.main("Teleporter", "Teleported to " + F.item("hub") + " area."));
}
p.playSound(p.getLocation(), Sound.ENDERMAN_TELEPORT, 1, 1);
_cooldown.add(p);
}
}
private Box isInside(Player player)
{
if(_portalHubMavericks.isInside(player.getLocation())) return _portalHubMavericks;
if(_portalMavericksHub.isInside(player.getLocation())) return _portalMavericksHub;
return null;
}
private static class Box
{
private Vector _min;
private Vector _max;
private String _world;
public Box(String world, Vector a, Vector b)
{
_world = world;
_min = Vector.getMinimum(a, b);
_max = Vector.getMaximum(a, b);
}
public boolean isInside(Vector v)
{
return v.isInAABB(_min, _max);
}
public boolean isInside(Location loc)
{
return loc.getWorld().getName().equals(_world) && isInside(loc.toVector());
}
}
}