Implement Alien Event service calls on Hub/Arcade
This commit is contained in:
parent
a134c1da5c
commit
fd1cd148cb
@ -0,0 +1,57 @@
|
||||
package mineplex.core.common.api.mothership;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import mineplex.core.common.api.ApiHost;
|
||||
import mineplex.core.common.api.ApiWebCall;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
|
||||
public class Mothership
|
||||
{
|
||||
private static final ApiWebCall API_BASE = new ApiWebCall("http://" + ApiHost.getAPIHost("MOTHERSHIP").getHost() + ":" + ApiHost.getAPIHost("MOTHERSHIP").getPort() + "/");
|
||||
|
||||
public static void addPlayer(UUID uuid, Runnable afterward)
|
||||
{
|
||||
UtilServer.runAsync(() ->
|
||||
{
|
||||
Boolean response = API_BASE.get("addPlayer/" + uuid.toString(), Boolean.class);
|
||||
if (response == null)
|
||||
{
|
||||
System.out.println("!!! Issue adding player to Mothership server !!!");
|
||||
}
|
||||
UtilServer.runSync(afterward);
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean isWhitelisted(UUID uuid)
|
||||
{
|
||||
if (Bukkit.isPrimaryThread())
|
||||
{
|
||||
throw new IllegalStateException("This method MUST NOT be called from the main thread!");
|
||||
}
|
||||
|
||||
Boolean response = API_BASE.get("getPlayer/" + uuid.toString(), Boolean.class);
|
||||
if (response == null)
|
||||
{
|
||||
System.out.println("!!! Issue retrieving player whitelist status. Allowing them in anyway! !!!");
|
||||
}
|
||||
return response == null || response;
|
||||
}
|
||||
|
||||
public static boolean shouldStartEvent()
|
||||
{
|
||||
if (Bukkit.isPrimaryThread())
|
||||
{
|
||||
throw new IllegalStateException("This method MUST NOT be called from the main thread");
|
||||
}
|
||||
|
||||
Boolean response = API_BASE.get("startEvent/" + UtilServer.getRegion().toString() + "/" + UtilServer.getServerName(), Boolean.class);
|
||||
if (response == null)
|
||||
{
|
||||
System.out.println("!!! Issue checking whether server should start event. Keeping event disabled! !!!");
|
||||
}
|
||||
return response != null && response;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package mineplex.core.common.api.mothership;
|
||||
|
||||
import mineplex.serverdata.commands.ServerCommand;
|
||||
|
||||
public class MothershipCommand extends ServerCommand
|
||||
{
|
||||
private Action action;
|
||||
|
||||
public Action getAction()
|
||||
{
|
||||
return action;
|
||||
}
|
||||
|
||||
public enum Action
|
||||
{
|
||||
CLEANUP, START
|
||||
}
|
||||
}
|
@ -1,29 +1,10 @@
|
||||
package mineplex.hub.modules;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||
import mineplex.core.achievement.Achievement;
|
||||
import mineplex.core.blockrestore.BlockRestore;
|
||||
import mineplex.core.command.CommandBase;
|
||||
import mineplex.core.common.Pair;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.block.schematic.Schematic;
|
||||
import mineplex.core.common.block.schematic.SchematicData;
|
||||
import mineplex.core.common.block.schematic.UtilSchematic;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.core.common.util.UtilBlock;
|
||||
import mineplex.core.common.util.UtilEnt;
|
||||
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.UtilTextMiddle;
|
||||
import mineplex.core.creature.Creature;
|
||||
import mineplex.core.stats.StatsManager;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.core.utils.UtilVariant;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Location;
|
||||
@ -44,10 +25,35 @@ import org.bukkit.event.player.PlayerInteractAtEntityEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.BlockVector;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import mineplex.core.Managers;
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||
import mineplex.core.achievement.Achievement;
|
||||
import mineplex.core.blockrestore.BlockRestore;
|
||||
import mineplex.core.command.CommandBase;
|
||||
import mineplex.core.common.Pair;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.api.mothership.Mothership;
|
||||
import mineplex.core.common.api.mothership.MothershipCommand;
|
||||
import mineplex.core.common.block.schematic.Schematic;
|
||||
import mineplex.core.common.block.schematic.SchematicData;
|
||||
import mineplex.core.common.block.schematic.UtilSchematic;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.core.common.util.UtilBlock;
|
||||
import mineplex.core.common.util.UtilEnt;
|
||||
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.UtilTextMiddle;
|
||||
import mineplex.core.creature.Creature;
|
||||
import mineplex.core.stats.StatsManager;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.core.utils.UtilVariant;
|
||||
import mineplex.hub.server.ServerManager;
|
||||
import mineplex.serverdata.commands.ServerCommandManager;
|
||||
|
||||
@ReflectivelyCreateMiniPlugin
|
||||
public class AlienInvasion extends MiniPlugin
|
||||
@ -105,6 +111,7 @@ public class AlienInvasion extends MiniPlugin
|
||||
private final BlockRestore _restore;
|
||||
private final Creature _creature;
|
||||
private final StatsManager _stats;
|
||||
private final ServerManager _serverManager;
|
||||
|
||||
private final World _world;
|
||||
|
||||
@ -124,6 +131,7 @@ public class AlienInvasion extends MiniPlugin
|
||||
_restore = require(BlockRestore.class);
|
||||
_creature = require(Creature.class);
|
||||
_stats = require(StatsManager.class);
|
||||
_serverManager = Managers.get(ServerManager.class);
|
||||
|
||||
_world = Bukkit.getWorld("world");
|
||||
|
||||
@ -147,10 +155,39 @@ public class AlienInvasion extends MiniPlugin
|
||||
stopAnimation();
|
||||
}
|
||||
});
|
||||
ServerCommandManager.getInstance().registerCommandType("mothership", MothershipCommand.class, command ->
|
||||
{
|
||||
switch (command.getAction())
|
||||
{
|
||||
case START:
|
||||
if (Mothership.shouldStartEvent())
|
||||
{
|
||||
runSync(this::startAnimation);
|
||||
}
|
||||
break;
|
||||
|
||||
case CLEANUP:
|
||||
runSync(this::stopAnimation);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
runAsync(() ->
|
||||
{
|
||||
if (Mothership.shouldStartEvent())
|
||||
{
|
||||
runSync(this::startAnimation);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void startAnimation()
|
||||
{
|
||||
if (_active)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_schematic = UtilSchematic.loadSchematic(new File(SCHEMATIC_PATH));
|
||||
@ -176,11 +213,16 @@ public class AlienInvasion extends MiniPlugin
|
||||
|
||||
public void sendPlayerToInstance(Player player)
|
||||
{
|
||||
player.sendMessage("Imagine you are being sent to a game server, ooooo spooky");
|
||||
Mothership.addPlayer(player.getUniqueId(), () -> _serverManager.selectServer(player, "UFO"));
|
||||
}
|
||||
|
||||
public void stopAnimation()
|
||||
{
|
||||
if (!_active)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_active = false;
|
||||
|
||||
for (Block block : _ufoBlocks)
|
||||
|
@ -1,21 +1,13 @@
|
||||
package nautilus.game.arcade.game.games.alieninvasion;
|
||||
|
||||
import mineplex.core.common.Pair;
|
||||
import mineplex.core.common.util.*;
|
||||
import mineplex.core.titles.tracks.Track;
|
||||
import mineplex.core.titles.tracks.TrackManager;
|
||||
import mineplex.core.titles.tracks.award.AlienInvasionTrack;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.core.utils.UtilVariant;
|
||||
import nautilus.game.arcade.ArcadeManager;
|
||||
import nautilus.game.arcade.GameType;
|
||||
import nautilus.game.arcade.events.GameStateChangeEvent;
|
||||
import nautilus.game.arcade.game.SoloGame;
|
||||
import nautilus.game.arcade.game.games.alieninvasion.kit.KitPlayer;
|
||||
import nautilus.game.arcade.game.games.dragonescape.DragonScore;
|
||||
import nautilus.game.arcade.game.modules.compass.CompassModule;
|
||||
import nautilus.game.arcade.kit.Kit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -26,12 +18,34 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import mineplex.core.common.Pair;
|
||||
import mineplex.core.common.api.mothership.Mothership;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.titles.tracks.Track;
|
||||
import mineplex.core.titles.tracks.TrackManager;
|
||||
import mineplex.core.titles.tracks.award.AlienInvasionTrack;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.core.utils.UtilVariant;
|
||||
|
||||
import nautilus.game.arcade.ArcadeManager;
|
||||
import nautilus.game.arcade.GameType;
|
||||
import nautilus.game.arcade.events.GameStateChangeEvent;
|
||||
import nautilus.game.arcade.game.SoloGame;
|
||||
import nautilus.game.arcade.game.games.alieninvasion.kit.KitPlayer;
|
||||
import nautilus.game.arcade.game.games.dragonescape.DragonScore;
|
||||
import nautilus.game.arcade.game.modules.compass.CompassModule;
|
||||
import nautilus.game.arcade.kit.Kit;
|
||||
|
||||
public class AlienInvasion extends SoloGame
|
||||
{
|
||||
@ -83,6 +97,15 @@ public class AlienInvasion extends SoloGame
|
||||
.register(this);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(AsyncPlayerPreLoginEvent event)
|
||||
{
|
||||
if (!Mothership.isWhitelisted(event.getUniqueId()))
|
||||
{
|
||||
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_WHITELIST, "You must join by finding a UFO!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@EventHandler
|
||||
public void ScoreboardUpdate(UpdateEvent event)
|
||||
|
Loading…
Reference in New Issue
Block a user