Humongous Hub Update
This commit is contained in:
parent
3286e5836f
commit
a9abfa4416
@ -346,7 +346,7 @@ public class UtilAlg
|
||||
return vec;
|
||||
}
|
||||
|
||||
public static Entity findClosest(Entity mid, ArrayList<Entity> locs)
|
||||
public static Entity findClosest(Entity mid, Collection<Entity> locs)
|
||||
{
|
||||
Entity bestLoc = null;
|
||||
double bestDist = 0;
|
||||
@ -365,7 +365,7 @@ public class UtilAlg
|
||||
return bestLoc;
|
||||
}
|
||||
|
||||
public static Location findClosest(Location mid, List<Location> locs)
|
||||
public static Location findClosest(Location mid, Collection<Location> locs)
|
||||
{
|
||||
Location bestLoc = null;
|
||||
double bestDist = 0;
|
||||
@ -384,7 +384,7 @@ public class UtilAlg
|
||||
return bestLoc;
|
||||
}
|
||||
|
||||
public static Location findFurthest(Location mid, List<Location> locs)
|
||||
public static Location findFurthest(Location mid, Collection<Location> locs)
|
||||
{
|
||||
Location bestLoc = null;
|
||||
double bestDist = 0;
|
||||
|
@ -57,6 +57,7 @@ import com.mineplex.spigot.ChunkAddEntityEvent;
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.PlayerSelector;
|
||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.UtilLambda;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
@ -301,7 +302,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
|
||||
if (team != null)
|
||||
{
|
||||
String name = ((DisguisePlayer) originalDisguise).getName();
|
||||
team.getEntries().removeIf(name::equals);
|
||||
team.removeEntry(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -698,7 +699,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
|
||||
@EventHandler
|
||||
public void hideNames(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.SEC)
|
||||
if (event.getType() != UpdateType.FAST)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -744,6 +745,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
|
||||
{
|
||||
team = scoreboard.registerNewTeam(HIDE_PLAYER_NAME_TEAM);
|
||||
team.setNameTagVisibility(NameTagVisibility.NEVER);
|
||||
team.setPrefix(C.cDGray);
|
||||
}
|
||||
|
||||
if (!team.hasEntry(disguisePlayer.getName()))
|
||||
|
@ -348,6 +348,11 @@ public class DisguisePlayer extends DisguiseHuman
|
||||
update(entityPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
if (hasHologram())
|
||||
{
|
||||
_hologram.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -496,7 +496,6 @@ public class PlayerDisguiseManager extends MiniPlugin implements IPacketHandler
|
||||
|
||||
require(FriendManager.class).updatePlayerStatus(disguisedProfile.getId(), null);
|
||||
require(FriendManager.class).updatePlayerStatus(originalProfile.getId(), new PlayerStatus(originalProfile.getId(), originalProfile.getName(), _serverName));
|
||||
getPreferencesManager().handlePlayerJoin(caller, true);
|
||||
|
||||
if (!sameName)
|
||||
{
|
||||
@ -599,7 +598,6 @@ public class PlayerDisguiseManager extends MiniPlugin implements IPacketHandler
|
||||
((CraftPlayer) caller).getProfile().getProperties().putAll(disguisePlayer.getProfile().getProperties());
|
||||
|
||||
storeDisguiseData(caller, caller.getName(), requestedProfile);
|
||||
getPreferencesManager().handlePlayerJoin(caller, true);
|
||||
|
||||
_disguises.put(caller.getUniqueId(), disguisePlayer);
|
||||
|
||||
@ -673,8 +671,6 @@ public class PlayerDisguiseManager extends MiniPlugin implements IPacketHandler
|
||||
require(FriendManager.class).updatePlayerStatus(disguisePlayer.getProfile().getId(),
|
||||
new PlayerStatus(disguisePlayer.getProfile().getId(), requestedUsername, _serverName));
|
||||
|
||||
getPreferencesManager().handlePlayerJoin(caller, true);
|
||||
|
||||
_disguises.put(caller.getUniqueId(), disguisePlayer);
|
||||
|
||||
UtilPlayer.message(caller, F.main("Disguise", "Disguise Active: " + ChatColor.RESET + requestedUsername));
|
||||
|
@ -1,6 +1,7 @@
|
||||
package mineplex.core.gadget.gadgets.morph;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
@ -8,6 +9,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerToggleFlightEvent;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
@ -24,13 +26,15 @@ import mineplex.core.disguise.disguises.DisguisePig;
|
||||
import mineplex.core.gadget.GadgetManager;
|
||||
import mineplex.core.gadget.gadgets.morph.managers.UtilMorph;
|
||||
import mineplex.core.gadget.types.MorphGadget;
|
||||
import mineplex.core.gadget.util.CostConstants;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
|
||||
public class MorphPig extends MorphGadget
|
||||
{
|
||||
private HashSet<Player> _double = new HashSet<Player>();
|
||||
|
||||
private final Set<Player> _double = new HashSet<>();
|
||||
|
||||
public MorphPig(GadgetManager manager)
|
||||
{
|
||||
@ -41,7 +45,7 @@ public class MorphPig extends MorphGadget
|
||||
"#" + C.cWhite + "Left Click to use Oink",
|
||||
"#" + C.cWhite + "Collide to use Pig Bounce",
|
||||
}, LineFormat.LORE),
|
||||
-10,
|
||||
CostConstants.UNLOCKED_WITH_ULTRA,
|
||||
Material.PORK, (byte) 0);
|
||||
}
|
||||
|
||||
@ -92,50 +96,43 @@ public class MorphPig extends MorphGadget
|
||||
@EventHandler
|
||||
public void Collide(PlayerToggleFlightEvent event)
|
||||
{
|
||||
_double.add(event.getPlayer());
|
||||
Recharge.Instance.useForce(event.getPlayer(), getName() + " Double Jump", 200);
|
||||
Player player = event.getPlayer();
|
||||
|
||||
_double.add(player);
|
||||
Recharge.Instance.useForce(player, getName() + " Double Jump", 200);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void Collide(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.TICK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (Player player : getActive())
|
||||
{
|
||||
//Grounded
|
||||
if (_double.contains(player))
|
||||
if (UtilEnt.isGrounded(player))
|
||||
if (Recharge.Instance.usable(player, getName() + " Double Jump"))
|
||||
_double.remove(player);
|
||||
if (UtilEnt.isGrounded(player) && Recharge.Instance.usable(player, getName() + " Double Jump"))
|
||||
{
|
||||
_double.remove(player);
|
||||
}
|
||||
|
||||
double range = 1;
|
||||
|
||||
if (_double.contains(player))
|
||||
range += 0.5;
|
||||
{
|
||||
range++;
|
||||
}
|
||||
|
||||
if (player.getVehicle() != null)
|
||||
continue;
|
||||
|
||||
if (!Recharge.Instance.usable(player, getName() + " Collide"))
|
||||
if (player.getVehicle() != null || !Recharge.Instance.usable(player, getName() + " Collide"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for (Player other : UtilServer.getPlayers())
|
||||
{
|
||||
if (other.equals(player))
|
||||
continue;
|
||||
|
||||
if (other.getVehicle() != null)
|
||||
continue;
|
||||
|
||||
if (!Recharge.Instance.usable(other, getName() + " Collide"))
|
||||
continue;
|
||||
|
||||
if (UtilMath.offset(player, other) > range)
|
||||
continue;
|
||||
|
||||
if (!Manager.selectEntity(this, other))
|
||||
if (other.equals(player) || other.getVehicle() != null || Recharge.Instance.usable(other, getName() + " Collide") || UtilMath.offsetSquared(player, other) > range || !Manager.selectEntity(this, other))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -151,14 +148,12 @@ public class MorphPig extends MorphGadget
|
||||
power = 0.6;
|
||||
height = 0.2;
|
||||
}
|
||||
|
||||
if (_double.contains(player))
|
||||
else if (_double.contains(player))
|
||||
{
|
||||
power = 1;
|
||||
height = 0.3;
|
||||
}
|
||||
|
||||
|
||||
//Velocity
|
||||
UtilAction.velocity(player, UtilAlg.getTrajectory2d(other, player), power, false, 0, height, 1, true);
|
||||
UtilAction.velocity(other, UtilAlg.getTrajectory2d(player, other), power, false, 0, height, 1, true);
|
||||
@ -175,4 +170,10 @@ public class MorphPig extends MorphGadget
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerQuit(PlayerQuitEvent event)
|
||||
{
|
||||
_double.remove(event.getPlayer());
|
||||
}
|
||||
}
|
@ -111,7 +111,6 @@ public abstract class WinEffectGadget extends Gadget
|
||||
public void runPlay()
|
||||
{
|
||||
_finish = _start + _length;
|
||||
_length += 1000;
|
||||
play();
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,32 @@
|
||||
package mineplex.core.game;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public enum GameCategory
|
||||
{
|
||||
SURVIVAL, CLASSICS, CHAMPIONS, ARCADE, EVENT, TEAM_VARIANT, EXTRA
|
||||
|
||||
CASUAL("Casual", ChatColor.AQUA),
|
||||
INTERMEDIATE("Intermediate", ChatColor.GREEN),
|
||||
HARDCORE("Hardcore", ChatColor.RED),
|
||||
EVENT("Event", ChatColor.LIGHT_PURPLE),
|
||||
NONE("None", ChatColor.GRAY);
|
||||
|
||||
private final String _name;
|
||||
private final ChatColor _chatColor;
|
||||
|
||||
GameCategory(String name, ChatColor chatColor)
|
||||
{
|
||||
_name = name;
|
||||
_chatColor = chatColor;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
public ChatColor getChatColor()
|
||||
{
|
||||
return _chatColor;
|
||||
}
|
||||
}
|
||||
|
@ -10,110 +10,110 @@ import org.bukkit.Material;
|
||||
public enum GameDisplay
|
||||
{
|
||||
//Mini
|
||||
BaconBrawl("Bacon Brawl", Material.PORK, (byte)0, GameCategory.ARCADE, 1, true),
|
||||
Barbarians("A Barbarians Life", Material.WOOD_AXE, (byte)0, GameCategory.EXTRA, 2, false),
|
||||
BaconBrawl("Bacon Brawl", Material.PORK, (byte)0, GameCategory.NONE, 1, true),
|
||||
Barbarians("A Barbarians Life", Material.WOOD_AXE, (byte)0, GameCategory.NONE, 2, false),
|
||||
BossBattles("Boss Battles", Material.SKULL_ITEM, (byte) 0, GameCategory.EVENT, 55, false),
|
||||
Bridge("The Bridges", Material.IRON_PICKAXE, (byte)0, GameCategory.SURVIVAL, 3, true),
|
||||
CastleAssault("Castle Assault", Material.DIAMOND_CHESTPLATE, (byte)0, GameCategory.CLASSICS, 67, true),
|
||||
CastleAssaultTDM("Castle Assault TDM", Material.DIAMOND_CHESTPLATE, (byte)0, GameCategory.CLASSICS, 68, false),
|
||||
CastleSiege("Castle Siege", Material.DIAMOND_CHESTPLATE, (byte)0, GameCategory.CLASSICS, 4, true),
|
||||
ChampionsDominate("Champions Domination", "Champions", Material.BEACON, (byte)0, GameCategory.CHAMPIONS, 6, true),
|
||||
ChampionsTDM("Champions TDM", "Champions", Material.GOLD_SWORD, (byte)0, GameCategory.CHAMPIONS, 5, true),
|
||||
Christmas("Christmas Chaos", Material.SNOW_BALL, (byte)0, GameCategory.CLASSICS, 8, false),
|
||||
Bridge("The Bridges", Material.IRON_PICKAXE, (byte)0, GameCategory.HARDCORE, 3, true),
|
||||
CastleAssault("Castle Assault", Material.DIAMOND_CHESTPLATE, (byte)0, GameCategory.NONE, 67, true),
|
||||
CastleAssaultTDM("Castle Assault TDM", Material.DIAMOND_CHESTPLATE, (byte)0, GameCategory.NONE, 68, false),
|
||||
CastleSiege("Castle Siege", Material.DIAMOND_CHESTPLATE, (byte)0, GameCategory.NONE, 4, true),
|
||||
ChampionsDominate("Champions Domination", "Champions", Material.BEACON, (byte)0, GameCategory.HARDCORE, 6, true),
|
||||
ChampionsTDM("Champions TDM", "Champions", Material.GOLD_SWORD, (byte)0, GameCategory.NONE, 5, true),
|
||||
Christmas("Christmas Chaos", Material.SNOW_BALL, (byte)0, GameCategory.EVENT, 8, false),
|
||||
ChristmasNew("Christmas Chaos II", Material.SNOW_BALL, (byte)0, GameCategory.EVENT, 74, false),
|
||||
DeathTag("Death Tag", Material.SKULL_ITEM, (byte)0, GameCategory.ARCADE, 9, true),
|
||||
DragonEscape("Dragon Escape", Material.DRAGON_EGG, (byte)0, GameCategory.ARCADE, 10, true),
|
||||
DragonEscapeTeams("Dragon Escape Teams", Material.DRAGON_EGG, (byte)0, GameCategory.TEAM_VARIANT, 11, false),
|
||||
DragonRiders("Dragon Riders", Material.DRAGON_EGG, (byte)0, GameCategory.ARCADE, 12, false),
|
||||
Dragons("Dragons", Material.ENDER_STONE, (byte)0, GameCategory.ARCADE, 13, true),
|
||||
DragonsTeams("Dragons Teams", Material.DRAGON_EGG, (byte)0, GameCategory.TEAM_VARIANT, 14, false),
|
||||
Draw("Draw My Thing", Material.BOOK_AND_QUILL, (byte)0, GameCategory.CLASSICS, 15, true),
|
||||
ElytraRings("Elytra Rings", Material.ELYTRA, (byte) 0, GameCategory.CLASSICS, 61, false),
|
||||
Evolution("Evolution", Material.EMERALD, (byte)0, GameCategory.ARCADE, 16, true),
|
||||
Gravity("Gravity", Material.ENDER_PORTAL_FRAME, (byte)0, GameCategory.EXTRA, 18, false),
|
||||
Halloween("Halloween Horror", Material.PUMPKIN, (byte)0, GameCategory.CLASSICS, 19, false),
|
||||
Halloween2016("Pumpkin's Revenge", Material.PUMPKIN, (byte)0, GameCategory.CLASSICS, 63, false),
|
||||
HideSeek("Block Hunt", Material.GRASS, (byte)0, GameCategory.CLASSICS, 20, true),
|
||||
HoleInTheWall("Hole in the Wall", Material.STAINED_GLASS, (byte) 2, GameCategory.ARCADE, 52, false),
|
||||
Horse("Horseback", Material.IRON_BARDING, (byte)0, GameCategory.ARCADE, 21, false),
|
||||
DeathTag("Death Tag", Material.SKULL_ITEM, (byte)0, GameCategory.NONE, 9, true),
|
||||
DragonEscape("Dragon Escape", Material.DRAGON_EGG, (byte)0, GameCategory.NONE, 10, true),
|
||||
DragonEscapeTeams("Dragon Escape Teams", Material.DRAGON_EGG, (byte)0, GameCategory.NONE, 11, false),
|
||||
DragonRiders("Dragon Riders", Material.DRAGON_EGG, (byte)0, GameCategory.NONE, 12, false),
|
||||
Dragons("Dragons", Material.ENDER_STONE, (byte)0, GameCategory.NONE, 13, true),
|
||||
DragonsTeams("Dragons Teams", Material.DRAGON_EGG, (byte)0, GameCategory.NONE, 14, false),
|
||||
Draw("Draw My Thing", Material.BOOK_AND_QUILL, (byte)0, GameCategory.CASUAL, 15, true),
|
||||
ElytraRings("Elytra Rings", Material.ELYTRA, (byte) 0, GameCategory.NONE, 61, false),
|
||||
Evolution("Evolution", Material.EMERALD, (byte)0, GameCategory.NONE, 16, true),
|
||||
Gravity("Gravity", Material.ENDER_PORTAL_FRAME, (byte)0, GameCategory.NONE, 18, false),
|
||||
Halloween("Halloween Horror", Material.PUMPKIN, (byte)0, GameCategory.EVENT, 19, false),
|
||||
Halloween2016("Pumpkin's Revenge", Material.PUMPKIN, (byte)0, GameCategory.EVENT, 63, false),
|
||||
HideSeek("Block Hunt", Material.GRASS, (byte)0, GameCategory.INTERMEDIATE, 20, true),
|
||||
HoleInTheWall("Hole in the Wall", Material.STAINED_GLASS, (byte) 2, GameCategory.NONE, 52, false),
|
||||
Horse("Horseback", Material.IRON_BARDING, (byte)0, GameCategory.NONE, 21, false),
|
||||
|
||||
Micro("Micro Battle", Material.LAVA_BUCKET, (byte)0, GameCategory.ARCADE, 24, true),
|
||||
MilkCow("Milk the Cow", Material.MILK_BUCKET, (byte)0, GameCategory.ARCADE, 27, false),
|
||||
MineStrike("MineStrike", Material.TNT, (byte)0, GameCategory.CHAMPIONS, 25, true),// Temp set to CHAMPIONS to fix UI bug
|
||||
BawkBawkBattles("Bawk Bawk Battles", Material.EGG, (byte)0, GameCategory.CLASSICS, 26, true),
|
||||
OldMineWare("Old MineWare", Material.PAPER, (byte)0, GameCategory.EXTRA, 26, false),
|
||||
Paintball("Super Paintball", Material.ENDER_PEARL, (byte)0, GameCategory.ARCADE, 28, true),
|
||||
Quiver("One in the Quiver", Material.ARROW, (byte)0, GameCategory.ARCADE, 29, true),
|
||||
QuiverTeams("One in the Quiver Teams", Material.ARROW, (byte)0, GameCategory.TEAM_VARIANT, 30, false),
|
||||
Runner("Runner", Material.LEATHER_BOOTS, (byte)0, GameCategory.ARCADE, 31, true),
|
||||
SearchAndDestroy("Search and Destroy", Material.TNT, (byte)0, GameCategory.SURVIVAL, 32, false),
|
||||
Sheep("Sheep Quest", Material.WOOL, (byte)4, GameCategory.ARCADE, 33, true),
|
||||
Micro("Micro Battle", Material.LAVA_BUCKET, (byte)0, GameCategory.CASUAL, 24, true),
|
||||
MilkCow("Milk the Cow", Material.MILK_BUCKET, (byte)0, GameCategory.NONE, 27, false),
|
||||
MineStrike("MineStrike", Material.TNT, (byte)0, GameCategory.HARDCORE, 25, true),
|
||||
BawkBawkBattles("Bawk Bawk Battles", Material.EGG, (byte)0, GameCategory.NONE, 26, true),
|
||||
OldMineWare("Old MineWare", Material.PAPER, (byte)0, GameCategory.NONE, 26, false),
|
||||
Paintball("Super Paintball", Material.ENDER_PEARL, (byte)0, GameCategory.NONE, 28, true),
|
||||
Quiver("One in the Quiver", Material.ARROW, (byte)0, GameCategory.NONE, 29, true),
|
||||
QuiverTeams("One in the Quiver Teams", Material.ARROW, (byte)0, GameCategory.NONE, 30, false),
|
||||
Runner("Runner", Material.LEATHER_BOOTS, (byte)0, GameCategory.NONE, 31, true),
|
||||
SearchAndDestroy("Search and Destroy", Material.TNT, (byte)0, GameCategory.NONE, 32, false),
|
||||
Sheep("Sheep Quest", Material.WOOL, (byte)4, GameCategory.NONE, 33, true),
|
||||
|
||||
Smash("Super Smash Mobs", Material.SKULL_ITEM, (byte)4, GameCategory.CLASSICS, 34, true),
|
||||
SmashDomination("Super Smash Mobs Domination", "Super Smash Mobs", Material.SKULL_ITEM, (byte)4, GameCategory.EXTRA, 36, false),
|
||||
SmashTeams("Super Smash Mobs Teams", "Super Smash Mobs", Material.SKULL_ITEM, (byte)4, GameCategory.TEAM_VARIANT, 35, false),
|
||||
SmashTraining("Super Smash Mobs Training", "Super Smash Mobs", Material.SKULL_ITEM, (byte)4, GameCategory.EXTRA, 34, false),
|
||||
Snake("Snake", Material.WOOL, (byte)0, GameCategory.ARCADE, 37, true),
|
||||
SneakyAssassins("Sneaky Assassins", Material.INK_SACK, (byte)0, GameCategory.ARCADE, 38, true),
|
||||
SnowFight("Snow Fight", Material.SNOW_BALL, (byte)0, GameCategory.EXTRA, 39, false),
|
||||
Spleef("Super Spleef", Material.IRON_SPADE, (byte)0, GameCategory.ARCADE, 40, true),
|
||||
SpleefTeams("Super Spleef Teams", Material.IRON_SPADE, (byte)0, GameCategory.TEAM_VARIANT, 41, false),
|
||||
SquidShooter("Squid Shooter", Material.FIREWORK_CHARGE, (byte)0, GameCategory.ARCADE, 43, false),
|
||||
Stacker("Super Stacker", Material.BOWL, (byte)0, GameCategory.ARCADE, 42, false),
|
||||
SurvivalGames("Survival Games", Material.IRON_SWORD, (byte)0, GameCategory.SURVIVAL, 22, true),
|
||||
SurvivalGamesTeams("Survival Games Teams", "Survival Games", Material.IRON_SWORD, (byte)0, GameCategory.TEAM_VARIANT, 23, false),
|
||||
Tug("Tug of Wool", Material.WHEAT, (byte)0, GameCategory.ARCADE, 44, false),
|
||||
TurfWars("Turf Wars", Material.STAINED_CLAY, (byte)14, GameCategory.ARCADE, 45, true),
|
||||
UHC("Ultra Hardcore", Material.GOLDEN_APPLE, (byte)0, GameCategory.TEAM_VARIANT, 46, true),
|
||||
UHCSolo("Ultra Hardcore Solo", "Ultra Hardcore", Material.GOLDEN_APPLE, (byte)0, GameCategory.SURVIVAL, 46, false),
|
||||
UHCSoloSpeed("Ultra Hardcore Solo Speed", "Ultra Hardcore", Material.GOLDEN_APPLE, (byte)0, GameCategory.SURVIVAL, 67, false),
|
||||
UHCTeamsSpeed("Ultra Hardcore Teams Speed", "Ultra Hardcore", Material.GOLDEN_APPLE, (byte)0, GameCategory.TEAM_VARIANT, 67, false),
|
||||
WitherAssault("Wither Assault", Material.SKULL_ITEM, (byte)1, GameCategory.ARCADE, 47, true),
|
||||
Wizards("Wizards", Material.BLAZE_ROD, (byte)0, GameCategory.SURVIVAL, 48, true),
|
||||
ZombieSurvival("Zombie Survival", Material.SKULL_ITEM, (byte)2, GameCategory.SURVIVAL, 49, false),
|
||||
Smash("Super Smash Mobs", Material.SKULL_ITEM, (byte)4, GameCategory.HARDCORE, 34, true),
|
||||
SmashDomination("Super Smash Mobs Domination", "Super Smash Mobs", Material.SKULL_ITEM, (byte)4, GameCategory.NONE, 36, false),
|
||||
SmashTeams("Super Smash Mobs Teams", "Super Smash Mobs", Material.SKULL_ITEM, (byte)4, GameCategory.NONE, 35, false),
|
||||
SmashTraining("Super Smash Mobs Training", "Super Smash Mobs", Material.SKULL_ITEM, (byte)4, GameCategory.NONE, 34, false),
|
||||
Snake("Snake", Material.WOOL, (byte)0, GameCategory.NONE, 37, true),
|
||||
SneakyAssassins("Sneaky Assassins", Material.INK_SACK, (byte)0, GameCategory.NONE, 38, true),
|
||||
SnowFight("Snow Fight", Material.SNOW_BALL, (byte)0, GameCategory.EVENT, 39, false),
|
||||
Spleef("Super Spleef", Material.IRON_SPADE, (byte)0, GameCategory.NONE, 40, true),
|
||||
SpleefTeams("Super Spleef Teams", Material.IRON_SPADE, (byte)0, GameCategory.NONE, 41, false),
|
||||
SquidShooter("Squid Shooter", Material.FIREWORK_CHARGE, (byte)0, GameCategory.NONE, 43, false),
|
||||
Stacker("Super Stacker", Material.BOWL, (byte)0, GameCategory.NONE, 42, false),
|
||||
SurvivalGames("Survival Games", Material.IRON_SWORD, (byte)0, GameCategory.INTERMEDIATE, 22, true),
|
||||
SurvivalGamesTeams("Survival Games Teams", "Survival Games", Material.IRON_SWORD, (byte)0, GameCategory.INTERMEDIATE, 23, false),
|
||||
Tug("Tug of Wool", Material.WHEAT, (byte)0, GameCategory.NONE, 44, false),
|
||||
TurfWars("Turf Wars", Material.STAINED_CLAY, (byte)14, GameCategory.CASUAL, 45, true),
|
||||
UHC("Ultra Hardcore", Material.GOLDEN_APPLE, (byte)0, GameCategory.NONE, 46, true),
|
||||
UHCSolo("Ultra Hardcore Solo", "Ultra Hardcore", Material.GOLDEN_APPLE, (byte)0, GameCategory.NONE, 46, false),
|
||||
UHCSoloSpeed("Ultra Hardcore Solo Speed", "Ultra Hardcore", Material.GOLDEN_APPLE, (byte)0, GameCategory.NONE, 67, false),
|
||||
UHCTeamsSpeed("Ultra Hardcore Teams Speed", "Ultra Hardcore", Material.GOLDEN_APPLE, (byte)0, GameCategory.NONE, 67, false),
|
||||
WitherAssault("Wither Assault", Material.SKULL_ITEM, (byte)1, GameCategory.NONE, 47, true),
|
||||
Wizards("Wizards", Material.BLAZE_ROD, (byte)0, GameCategory.NONE, 48, true),
|
||||
ZombieSurvival("Zombie Survival", Material.SKULL_ITEM, (byte)2, GameCategory.NONE, 49, false),
|
||||
|
||||
Build("Master Builders", Material.WOOD, (byte)0, GameCategory.CLASSICS, 50, true),
|
||||
BuildMavericks("Mavericks Master Builders", Material.WOOD, (byte)3, GameCategory.CLASSICS, 63, false),
|
||||
Cards("Craft Against Humanity", Material.MAP, (byte)0, GameCategory.CLASSICS, 51, false),
|
||||
Skywars("Skywars", Material.FEATHER, (byte) 0, GameCategory.SURVIVAL, 52, true),
|
||||
SkywarsTeams("Skywars Teams", "Skywars", Material.FEATHER, (byte)0, GameCategory.TEAM_VARIANT, 53, false),
|
||||
MonsterMaze("Monster Maze", Material.ROTTEN_FLESH, (byte)0, GameCategory.ARCADE, 55, true),
|
||||
MonsterLeague("Monster League", Material.MINECART, (byte)0, GameCategory.ARCADE, 56, false),
|
||||
Build("Master Builders", Material.WOOD, (byte)0, GameCategory.CASUAL, 50, true),
|
||||
BuildMavericks("Mavericks Master Builders", Material.WOOD, (byte)3, GameCategory.EVENT, 63, false),
|
||||
Cards("Craft Against Humanity", Material.MAP, (byte)0, GameCategory.NONE, 51, false),
|
||||
Skywars("Skywars", Material.FEATHER, (byte) 0, GameCategory.INTERMEDIATE, 52, true),
|
||||
SkywarsTeams("Skywars Teams", "Skywars", Material.FEATHER, (byte)0, GameCategory.INTERMEDIATE, 53, false),
|
||||
MonsterMaze("Monster Maze", Material.ROTTEN_FLESH, (byte)0, GameCategory.NONE, 55, true),
|
||||
MonsterLeague("Monster League", Material.MINECART, (byte)0, GameCategory.NONE, 56, false),
|
||||
|
||||
Lobbers("Bomb Lobbers", Material.FIREBALL, (byte) 0, GameCategory.ARCADE, 54, true),
|
||||
Lobbers("Bomb Lobbers", Material.FIREBALL, (byte) 0, GameCategory.NONE, 54, true),
|
||||
|
||||
Minecraft_League("MC League", Material.DIAMOND_SWORD, (byte)0, GameCategory.SURVIVAL, 62, false),
|
||||
Minecraft_League("MC League", Material.DIAMOND_SWORD, (byte)0, GameCategory.NONE, 62, false),
|
||||
|
||||
ChampionsCTF("Champions CTF", "Champions", Material.BANNER, DyeColor.RED.getDyeData(), GameCategory.CHAMPIONS, 56, true),
|
||||
ChampionsCTF("Champions CTF", "Champions", Material.BANNER, DyeColor.RED.getDyeData(), GameCategory.HARDCORE, 56, true),
|
||||
|
||||
BouncyBalls("Bouncy Balls", Material.SLIME_BALL, (byte)0, GameCategory.ARCADE, 57, false),
|
||||
Gladiators("Gladiators", Material.IRON_SWORD, (byte)0, GameCategory.ARCADE, 58, true),
|
||||
TypeWars("Type Wars", Material.NAME_TAG, (byte) 0, GameCategory.CLASSICS, 59, false),
|
||||
BouncyBalls("Bouncy Balls", Material.SLIME_BALL, (byte)0, GameCategory.NONE, 57, false),
|
||||
Gladiators("Gladiators", Material.IRON_SWORD, (byte)0, GameCategory.NONE, 58, true),
|
||||
TypeWars("Type Wars", Material.NAME_TAG, (byte) 0, GameCategory.NONE, 59, false),
|
||||
|
||||
SpeedBuilders("Speed Builders", Material.QUARTZ_BLOCK, (byte) 0, GameCategory.CLASSICS, 60, true),
|
||||
SpeedBuilders("Speed Builders", Material.QUARTZ_BLOCK, (byte) 0, GameCategory.INTERMEDIATE, 60, true),
|
||||
|
||||
Valentines("Valentines Vendetta", Material.LEATHER, (byte)0, GameCategory.EXTRA, 61, false),
|
||||
Valentines("Valentines Vendetta", Material.LEATHER, (byte)0, GameCategory.EVENT, 61, false),
|
||||
|
||||
Skyfall("Skyfall", Material.DIAMOND_BOOTS, (byte)0, GameCategory.SURVIVAL, 62, true),
|
||||
SkyfallTeams("Skyfall Teams", Material.DIAMOND_BOOTS, (byte)0, GameCategory.SURVIVAL, 65, false),
|
||||
Skyfall("Skyfall", Material.DIAMOND_BOOTS, (byte)0, GameCategory.NONE, 62, true),
|
||||
SkyfallTeams("Skyfall Teams", Material.DIAMOND_BOOTS, (byte)0, GameCategory.NONE, 65, false),
|
||||
|
||||
Basketball("Hoops", Material.SLIME_BALL, (byte)0, GameCategory.EXTRA, 63, false),
|
||||
Basketball("Hoops", Material.SLIME_BALL, (byte)0, GameCategory.EVENT, 63, false),
|
||||
|
||||
QuiverPayload("One in the Quiver Payload", Material.ARROW, (byte)0, GameCategory.ARCADE, 64, false),
|
||||
QuiverPayload("One in the Quiver Payload", Material.ARROW, (byte)0, GameCategory.NONE, 64, false),
|
||||
|
||||
StrikeGames("Strike Games", Material.DIAMOND_LEGGINGS, (byte) 0, GameCategory.SURVIVAL, 66, false),
|
||||
StrikeGames("Strike Games", Material.DIAMOND_LEGGINGS, (byte) 0, GameCategory.NONE, 66, false),
|
||||
|
||||
AlienInvasion("Alien Invasion", Material.ENDER_STONE, (byte) 0, GameCategory.EVENT, 69, false),
|
||||
|
||||
MOBA("Heroes of GWEN", Material.PRISMARINE, (byte)0, GameCategory.CLASSICS, 70, true),
|
||||
MOBATraining("Heroes of GWEN Training", Material.PRISMARINE, (byte)0, GameCategory.CLASSICS, 70, false),
|
||||
MOBA("Heroes of GWEN", Material.PRISMARINE, (byte)0, GameCategory.NONE, 70, true),
|
||||
MOBATraining("Heroes of GWEN Training", Material.PRISMARINE, (byte)0, GameCategory.NONE, 70, false),
|
||||
|
||||
BattleRoyale("Battle Royale", Material.DIAMOND_SWORD, (byte)0, GameCategory.EVENT, 72, false),
|
||||
|
||||
CakeWars4("Cake Wars Standard", Material.CAKE, (byte)0, GameCategory.CLASSICS, 73, true),
|
||||
CakeWarsDuos("Cake Wars Duos", Material.SUGAR, (byte)0, GameCategory.CLASSICS, 74, false),
|
||||
CakeWars4("Cake Wars Standard", Material.CAKE, (byte)0, GameCategory.INTERMEDIATE, 73, true),
|
||||
CakeWarsDuos("Cake Wars Duos", Material.SUGAR, (byte)0, GameCategory.INTERMEDIATE, 74, false),
|
||||
|
||||
GemHunters("Gem Hunters", Material.EMERALD, (byte) 0, GameCategory.SURVIVAL, 71, false),
|
||||
GemHunters("Gem Hunters", Material.EMERALD, (byte) 0, GameCategory.EVENT, 71, false),
|
||||
|
||||
Event("Mineplex Event", Material.CAKE, (byte)0, GameCategory.EVENT, 999, false),
|
||||
|
||||
@ -194,6 +194,7 @@ public enum GameDisplay
|
||||
static
|
||||
{
|
||||
Map<Integer, GameDisplay> byId = new HashMap<>();
|
||||
|
||||
for (GameDisplay gameDisplay : values())
|
||||
{
|
||||
byId.put(gameDisplay.getGameId(), gameDisplay);
|
||||
@ -205,5 +206,4 @@ public enum GameDisplay
|
||||
{
|
||||
return BY_ID.get(id);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,555 @@
|
||||
package mineplex.core.game;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraft.server.v1_8_R3.DataWatcher.WatchableObject;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityMetadata;
|
||||
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
|
||||
import mineplex.core.MiniClientPlugin;
|
||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||
import mineplex.core.account.CoreClient;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.achievement.Achievement;
|
||||
import mineplex.core.achievement.AchievementManager;
|
||||
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.UtilServer;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.donation.Donor;
|
||||
import mineplex.core.event.CustomTagEvent;
|
||||
import mineplex.core.game.kit.GameKit;
|
||||
import mineplex.core.game.kit.KitAvailability;
|
||||
import mineplex.core.game.kit.KitOperations;
|
||||
import mineplex.core.game.kit.KitRepository;
|
||||
import mineplex.core.game.kit.LegacyKit;
|
||||
import mineplex.core.game.kit.PlayerKitData;
|
||||
import mineplex.core.game.kit.event.KitNPCInteractEvent;
|
||||
import mineplex.core.game.kit.event.KitSelectEvent;
|
||||
import mineplex.core.game.kit.ui.KitMainPage;
|
||||
import mineplex.core.game.kit.ui.KitShop;
|
||||
import mineplex.core.game.kit.upgrade.KitStat;
|
||||
import mineplex.core.game.kit.upgrade.KitStatLog;
|
||||
import mineplex.core.game.kit.upgrade.LinearUpgradeTree;
|
||||
import mineplex.core.newnpc.NPC;
|
||||
import mineplex.core.newnpc.NewNPCManager;
|
||||
import mineplex.core.newnpc.event.NPCInteractEvent;
|
||||
import mineplex.core.packethandler.IPacketHandler;
|
||||
import mineplex.core.packethandler.PacketHandler;
|
||||
import mineplex.core.packethandler.PacketInfo;
|
||||
import mineplex.core.preferences.Preference;
|
||||
import mineplex.core.preferences.PreferencesManager;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
import mineplex.core.stats.event.PlayerStatsLoadedEvent;
|
||||
|
||||
@ReflectivelyCreateMiniPlugin
|
||||
public class MineplexGameManager extends MiniClientPlugin<Map<GameKit, PlayerKitData>> implements IPacketHandler
|
||||
{
|
||||
|
||||
private final AchievementManager _achievementManager;
|
||||
private final CoreClientManager _clientManager;
|
||||
private final DonationManager _donationManager;
|
||||
private final NewNPCManager _npcManager;
|
||||
private final PreferencesManager _preferencesManager;
|
||||
|
||||
private final List<GameKit> _kits;
|
||||
private final Map<NPC, GameKit> _kitNPCs;
|
||||
private final Map<Player, KitStatLog> _kitStatLog;
|
||||
|
||||
private final KitRepository _repository;
|
||||
|
||||
private final KitShop _shop;
|
||||
|
||||
private MineplexGameManager()
|
||||
{
|
||||
super("Game");
|
||||
|
||||
_achievementManager = require(AchievementManager.class);
|
||||
_clientManager = require(CoreClientManager.class);
|
||||
_donationManager = require(DonationManager.class);
|
||||
_npcManager = require(NewNPCManager.class);
|
||||
_preferencesManager = require(PreferencesManager.class);
|
||||
|
||||
require(PacketHandler.class).addPacketHandler(this, PacketPlayOutEntityMetadata.class);
|
||||
|
||||
_kits = Arrays.asList(GameKit.values());
|
||||
_kitNPCs = new HashMap<>(_kits.size());
|
||||
_kitStatLog = new HashMap<>();
|
||||
_repository = new KitRepository(this);
|
||||
_shop = new KitShop(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<GameKit, PlayerKitData> addPlayer(UUID uuid)
|
||||
{
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
public void unlock(Player player, GameKit kit)
|
||||
{
|
||||
runAsync(() ->
|
||||
{
|
||||
boolean result = new KitOperations(_repository, _clientManager.getAccountId(player))
|
||||
.unlockKit(kit.getId(), true)
|
||||
.execute();
|
||||
|
||||
if (result)
|
||||
{
|
||||
Get(player).put(kit, new PlayerKitData(false));
|
||||
setActiveKit(player, kit);
|
||||
|
||||
if (kit.getAvailability() != KitAvailability.Free)
|
||||
{
|
||||
player.sendMessage(F.main(_moduleName, "Unlocked " + F.name(kit.getFormattedName()) + "."));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
player.sendMessage(F.main(_moduleName, "There was an error processing your request for " + F.name(kit.getDisplayName()) + "."));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean isUnlocked(Player player, GameKit kit)
|
||||
{
|
||||
return kit.getAvailability() == KitAvailability.Free || _preferencesManager.get(player).isActive(Preference.UNLOCK_KITS) && _clientManager.Get(player).hasPermission(Preference.UNLOCK_KITS) || ownsKit(player, kit);
|
||||
}
|
||||
|
||||
public boolean ownsKit(Player player, GameKit kit)
|
||||
{
|
||||
return getPlayerKitData(player, kit).isPresent() || _donationManager.Get(player).ownsUnknownSalesPackage(kit.getDisplay().getKitGameName() + " " + kit.getDisplayName());
|
||||
}
|
||||
|
||||
public boolean canUnlock(Player player, GameKit kit)
|
||||
{
|
||||
switch (kit.getAvailability())
|
||||
{
|
||||
case Gem:
|
||||
return _donationManager.Get(player).getBalance(GlobalCurrency.GEM) >= kit.getCost();
|
||||
case Achievement:
|
||||
Achievement[] achievements = kit.getAchievements();
|
||||
|
||||
for (Achievement achievement : achievements)
|
||||
{
|
||||
if (_achievementManager.get(player, achievement).getLevel() < achievement.getMaxLevel())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return kit.getAvailability() == KitAvailability.Free;
|
||||
}
|
||||
|
||||
public boolean isActive(Player player, GameKit kit)
|
||||
{
|
||||
Optional<PlayerKitData> optional = getPlayerKitData(player, kit);
|
||||
|
||||
return optional.isPresent() && optional.get().isActive();
|
||||
}
|
||||
|
||||
public void setActiveKit(Player player, GameKit kit)
|
||||
{
|
||||
KitSelectEvent selectEvent = new KitSelectEvent(player, kit);
|
||||
UtilServer.CallEvent(selectEvent);
|
||||
|
||||
if (selectEvent.isCancelled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
runAsync(() ->
|
||||
{
|
||||
List<Integer> idsToDisable = _kits
|
||||
.stream()
|
||||
.filter(otherKit -> !otherKit.equals(kit) && otherKit.getDisplay().equals(kit.getDisplay()))
|
||||
.mapToInt(GameKit::getId)
|
||||
.boxed()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
boolean result = new KitOperations(_repository, _clientManager.getAccountId(player))
|
||||
.setActiveKit(kit.getId(), idsToDisable)
|
||||
.execute();
|
||||
|
||||
if (result)
|
||||
{
|
||||
for (int id : idsToDisable)
|
||||
{
|
||||
getKitFrom(id).ifPresent(otherKit -> getPlayerKitData(player, otherKit).ifPresent(kitData -> kitData.setActive(false)));
|
||||
}
|
||||
|
||||
getPlayerKitData(player, kit).ifPresent(kitData -> kitData.setActive(true));
|
||||
player.sendMessage(F.main(_moduleName, "Set " + F.name(kit.getFormattedName()) + " as your selected kit."));
|
||||
player.playSound(player.getLocation(), Sound.ORB_PICKUP, 1, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.sendMessage(F.main(_moduleName, "There was an error processing your request."));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Optional<GameKit> getActiveKit(Player player, GameDisplay display)
|
||||
{
|
||||
for (GameKit kit : _kits)
|
||||
{
|
||||
if (!kit.getDisplay().equals(display))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Optional<PlayerKitData> optional = getPlayerKitData(player, kit);
|
||||
|
||||
if (optional.isPresent() && optional.get().isActive())
|
||||
{
|
||||
return Optional.of(kit);
|
||||
}
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public int getKitStat(Player player, GameKit kit, KitStat stat)
|
||||
{
|
||||
Optional<PlayerKitData> optional = getPlayerKitData(player, kit);
|
||||
return optional.isPresent() ? optional.get().getStats().getOrDefault(stat, 0) : 0;
|
||||
}
|
||||
|
||||
public void incrementKitStat(Player player, GameKit kit, KitStat stat, int value)
|
||||
{
|
||||
if (value <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
runAsync(() ->
|
||||
{
|
||||
boolean result = new KitOperations(_repository, _clientManager.getAccountId(player))
|
||||
.incrementStat(kit.getId(), stat.getId(), value)
|
||||
.execute();
|
||||
|
||||
if (result)
|
||||
{
|
||||
getPlayerKitData(player, kit).ifPresent(kitData -> kitData.getStats().put(stat, kitData.getStats().getOrDefault(stat, 0) + value));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setKitStat(Player player, GameKit kit, KitStat stat, int value)
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
runAsync(() ->
|
||||
{
|
||||
boolean result = new KitOperations(_repository, _clientManager.getAccountId(player))
|
||||
.setStat(kit.getId(), stat.getId(), value)
|
||||
.execute();
|
||||
|
||||
if (result)
|
||||
{
|
||||
getPlayerKitData(player, kit).ifPresent(kitData -> kitData.getStats().put(stat, value));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void interactNPC(NPCInteractEvent event)
|
||||
{
|
||||
if (event.isCancelled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
NPC npc = event.getNpc();
|
||||
|
||||
getKitFrom(npc).ifPresent(kit ->
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (UtilPlayer.isSpectator(player) || !Recharge.Instance.use(player, "Kit NPC Interact", 1000, false, false))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
KitNPCInteractEvent interactEvent = new KitNPCInteractEvent(player, npc, kit);
|
||||
UtilServer.CallEvent(interactEvent);
|
||||
|
||||
if (interactEvent.isCancelled() || kit.isChampionsKit())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.isLeftClick() && !isActive(player, kit) && ownsKit(player, kit))
|
||||
{
|
||||
setActiveKit(player, kit);
|
||||
}
|
||||
else
|
||||
{
|
||||
openKitUI(player, kit);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void openKitUI(Player player, GameKit kit)
|
||||
{
|
||||
_shop.openPageForPlayer(player, new KitMainPage(this, player, kit));
|
||||
}
|
||||
|
||||
public void addKitNPC(NPC npc, GameKit kit)
|
||||
{
|
||||
_kitNPCs.put(npc, kit);
|
||||
}
|
||||
|
||||
public void clearKitNPCs()
|
||||
{
|
||||
_kitNPCs.keySet().forEach(_npcManager::deleteNPC);
|
||||
_kitNPCs.clear();
|
||||
}
|
||||
|
||||
private String getKitEntityName(Player player, GameKit kit)
|
||||
{
|
||||
CoreClient client = _clientManager.Get(player);
|
||||
Donor donor = _donationManager.Get(player);
|
||||
|
||||
String entityName = kit.getFormattedName();
|
||||
|
||||
if (!player.isOnline() || client == null || donor == null || isUnlocked(player, kit))
|
||||
{
|
||||
if (isActive(player, kit))
|
||||
{
|
||||
entityName += " ★";
|
||||
}
|
||||
|
||||
return entityName;
|
||||
}
|
||||
|
||||
switch (kit.getAvailability())
|
||||
{
|
||||
case Gem:
|
||||
entityName = kit.getAvailability().getColour() + entityName + C.Reset + " (" + GlobalCurrency.GEM.getString(kit.getCost()) + C.Reset + ")";
|
||||
break;
|
||||
case Achievement:
|
||||
entityName = kit.getAvailability().getColour() + entityName + C.Reset + " (" + C.cPurple + "Achievement Kit" + C.Reset + ")";
|
||||
break;
|
||||
}
|
||||
|
||||
return entityName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(PacketInfo packetInfo)
|
||||
{
|
||||
// Only need to handle this for 1.9+
|
||||
if (!UtilPlayer.is1_9(packetInfo.getPlayer()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PacketPlayOutEntityMetadata packet = (PacketPlayOutEntityMetadata) packetInfo.getPacket();
|
||||
|
||||
_kitNPCs.forEach((npc, kit) ->
|
||||
{
|
||||
LivingEntity entity = npc.getEntity();
|
||||
|
||||
if (entity.getEntityId() == packet.a)
|
||||
{
|
||||
for (WatchableObject watchableObject : packet.b)
|
||||
{
|
||||
if (watchableObject.getIndex().equals(net.minecraft.server.v1_8_R3.Entity.META_CUSTOMNAME))
|
||||
{
|
||||
String customName = getKitEntityName(packetInfo.getPlayer(), kit);
|
||||
|
||||
watchableObject.a(customName, customName);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void customEntityName(CustomTagEvent event)
|
||||
{
|
||||
_kitNPCs.forEach((npc, kit) ->
|
||||
{
|
||||
LivingEntity entity = npc.getEntity();
|
||||
|
||||
if (entity.getEntityId() == event.getEntityId())
|
||||
{
|
||||
String customName = getKitEntityName(event.getPlayer(), kit);
|
||||
|
||||
if (customName != null)
|
||||
{
|
||||
event.setCustomName(customName);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Optional<PlayerKitData> getPlayerKitData(Player player, GameKit kit)
|
||||
{
|
||||
return Optional.ofNullable(Get(player).get(kit));
|
||||
}
|
||||
|
||||
public Optional<GameKit> getKitFrom(int id)
|
||||
{
|
||||
return _kits
|
||||
.stream()
|
||||
.filter(kit -> kit.getId() == id)
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
private Optional<GameKit> getKitFrom(String legacyName)
|
||||
{
|
||||
return _kits
|
||||
.stream()
|
||||
.filter(kit ->
|
||||
{
|
||||
Optional<String> optional = kit.getLegacyName();
|
||||
return optional.isPresent() && optional.get().equals(legacyName);
|
||||
})
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
public Optional<GameKit> getKitFrom(NPC npc)
|
||||
{
|
||||
return Optional.ofNullable(_kitNPCs.get(npc));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void playerStatsLoad(PlayerStatsLoadedEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
Map<GameKit, PlayerKitData> dataMap = Get(player);
|
||||
|
||||
if (!dataMap.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
runAsync(() ->
|
||||
{
|
||||
if (!dataMap.isEmpty() || !player.isOnline())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int accountId = _clientManager.getAccountId(player);
|
||||
|
||||
if (accountId == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
KitOperations operations = new KitOperations(_repository, accountId);
|
||||
|
||||
player.sendMessage(F.main(_moduleName, "Converting your " + F.name("Kits") + " to our shiny new system. This will take a few seconds..."));
|
||||
|
||||
List<LegacyKit> legacyKits = _repository.getLegacyKits(player.getUniqueId());
|
||||
|
||||
if (legacyKits == null)
|
||||
{
|
||||
player.sendMessage(F.main(_moduleName, "Ruh roh scoob looks like we couldn't load your old kits."));
|
||||
return;
|
||||
}
|
||||
|
||||
legacyKits.forEach(legacyKit ->
|
||||
{
|
||||
Optional<GameKit> optional = getKitFrom(legacyKit.getId());
|
||||
|
||||
if (!optional.isPresent())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GameKit kit = optional.get();
|
||||
|
||||
if (kit.getAvailability() == KitAvailability.Gem && !ownsKit(player, kit) || kit.getAvailability() == KitAvailability.Achievement && !canUnlock(player, kit))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int xp = LinearUpgradeTree.getTotalXpForLevel(legacyKit.getKitLevel()) + legacyKit.getKitXP(), upgradeLevel = legacyKit.getKitUpgradeLevel();
|
||||
|
||||
operations.unlockKit(kit.getId(), false);
|
||||
operations.setStat(kit.getId(), KitStat.XP.getId(), xp);
|
||||
|
||||
PlayerKitData kitData = new PlayerKitData(false);
|
||||
dataMap.put(kit, kitData);
|
||||
kitData.getStats().put(KitStat.XP, xp);
|
||||
|
||||
if (upgradeLevel > 0)
|
||||
{
|
||||
operations.setStat(kit.getId(), KitStat.UPGRADE_LEVEL.getId(), upgradeLevel);
|
||||
kitData.getStats().put(KitStat.UPGRADE_LEVEL, upgradeLevel);
|
||||
}
|
||||
});
|
||||
|
||||
// Gonna keep this commented out for now just incase something terrible happens
|
||||
// if (_repository.deleteLegacyKits(player.getUniqueId()))
|
||||
// {
|
||||
operations.execute();
|
||||
|
||||
player.playSound(player.getLocation(), Sound.LEVEL_UP, 1, 1);
|
||||
player.sendMessage(F.main(_moduleName, "We're all finished. All your " + F.name("Kits") + " were successfully transferred over! You may need to rejoin/switch servers in order for all of your kit levels and upgrades to apply!"));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// player.sendMessage(F.main(_moduleName, "Ruh roh scoob looks like we couldn't delete your old kits."));
|
||||
// }
|
||||
}, 10);
|
||||
}
|
||||
|
||||
public AchievementManager getAchievementManager()
|
||||
{
|
||||
return _achievementManager;
|
||||
}
|
||||
|
||||
public CoreClientManager getClientManager()
|
||||
{
|
||||
return _clientManager;
|
||||
}
|
||||
|
||||
public DonationManager getDonationManager()
|
||||
{
|
||||
return _donationManager;
|
||||
}
|
||||
|
||||
public NewNPCManager getNpcManager()
|
||||
{
|
||||
return _npcManager;
|
||||
}
|
||||
|
||||
public List<GameKit> getKits()
|
||||
{
|
||||
return _kits;
|
||||
}
|
||||
|
||||
public Map<Player, KitStatLog> getKitStatLog()
|
||||
{
|
||||
return _kitStatLog;
|
||||
}
|
||||
|
||||
public KitShop getShop()
|
||||
{
|
||||
return _shop;
|
||||
}
|
||||
}
|
4289
Plugins/Mineplex.Core/src/mineplex/core/game/kit/GameKit.java
Normal file
4289
Plugins/Mineplex.Core/src/mineplex/core/game/kit/GameKit.java
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,26 @@
|
||||
package mineplex.core.game.kit;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public enum KitAvailability
|
||||
{
|
||||
|
||||
Free(ChatColor.YELLOW),
|
||||
Gem(ChatColor.GREEN),
|
||||
Achievement(ChatColor.LIGHT_PURPLE),
|
||||
Hide(Free._colour),
|
||||
Null(ChatColor.BLACK)
|
||||
;
|
||||
|
||||
private final ChatColor _colour;
|
||||
|
||||
KitAvailability(ChatColor colour)
|
||||
{
|
||||
_colour = colour;
|
||||
}
|
||||
|
||||
public ChatColor getColour()
|
||||
{
|
||||
return _colour;
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package mineplex.core.game.kit;
|
||||
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public class KitEntityData<T extends LivingEntity>
|
||||
{
|
||||
|
||||
private final Class<T> _classOfT;
|
||||
private final ItemStack _inHand;
|
||||
private final ItemStack[] _armour;
|
||||
private final int _variant;
|
||||
|
||||
KitEntityData(Class<T> classOfT, ItemStack inHand)
|
||||
{
|
||||
this(classOfT, inHand, null);
|
||||
}
|
||||
|
||||
KitEntityData(Class<T> classOfT, ItemStack inHand, ItemStack[] armour)
|
||||
{
|
||||
this(classOfT, inHand, armour, 0);
|
||||
}
|
||||
|
||||
KitEntityData(Class<T> classOfT, ItemStack inHand, int variant)
|
||||
{
|
||||
this(classOfT, inHand, null, variant);
|
||||
}
|
||||
|
||||
KitEntityData(Class<T> classOfT, ItemStack inHand, ItemStack[] armour, int variant)
|
||||
{
|
||||
_classOfT = classOfT;
|
||||
_inHand = inHand;
|
||||
_armour = armour;
|
||||
_variant = variant;
|
||||
|
||||
if (_armour != null)
|
||||
{
|
||||
for (ItemStack itemStack : _armour)
|
||||
{
|
||||
if (itemStack != null)
|
||||
{
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
itemMeta.spigot().setUnbreakable(true);
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Class<T> getClassOfT()
|
||||
{
|
||||
return _classOfT;
|
||||
}
|
||||
|
||||
public ItemStack getInHand()
|
||||
{
|
||||
return _inHand;
|
||||
}
|
||||
|
||||
public ItemStack[] getArmour()
|
||||
{
|
||||
return _armour;
|
||||
}
|
||||
|
||||
public int getVariant()
|
||||
{
|
||||
return _variant;
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
package mineplex.core.game.kit;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class KitOperations
|
||||
{
|
||||
|
||||
private static final String INSERT_KIT_DATA = "INSERT INTO accountKits VALUES ({0},{1},{2});";
|
||||
private static final String SET_ACTIVE_KIT = "UPDATE accountKits SET active=0 WHERE accountId={0}{2}; UPDATE accountKits SET active=1 WHERE accountId={0} AND kitId={1};";
|
||||
private static final String INCREMENT_KIT_STAT = "INSERT INTO accountKitStats VALUES({0},{1},{2},{3}) ON DUPLICATE KEY UPDATE value=value+{3};";
|
||||
private static final String SET_KIT_STAT = "INSERT INTO accountKitStats VALUES({0},{1},{2},{3}) ON DUPLICATE KEY UPDATE value={3};";
|
||||
|
||||
private final KitRepository _repository;
|
||||
private final int _accountId;
|
||||
private final String _accountIdString;
|
||||
private final StringBuilder _query;
|
||||
|
||||
public KitOperations(KitRepository repository, int accountId)
|
||||
{
|
||||
_repository = repository;
|
||||
_accountId = accountId;
|
||||
_accountIdString = String.valueOf(_accountId);
|
||||
_query = new StringBuilder(1000);
|
||||
}
|
||||
|
||||
public KitOperations unlockKit(int kitId, boolean setActive)
|
||||
{
|
||||
_query.append(INSERT_KIT_DATA
|
||||
.replace("{0}", _accountIdString)
|
||||
.replace("{1}", String.valueOf(kitId))
|
||||
.replace("{2}", String.valueOf(setActive)));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public KitOperations setActiveKit(int kitId, List<Integer> kitIdsToDisable)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
if (!kitIdsToDisable.isEmpty())
|
||||
{
|
||||
builder.append(" AND (");
|
||||
int index = 0;
|
||||
for (int kitIdDisable : kitIdsToDisable)
|
||||
{
|
||||
builder.append((index++ != 0 ? " OR " : "")).append("kitId=").append(kitIdDisable);
|
||||
}
|
||||
|
||||
builder.append(")");
|
||||
}
|
||||
|
||||
_query.append(SET_ACTIVE_KIT
|
||||
.replace("{0}", _accountIdString)
|
||||
.replace("{1}", String.valueOf(kitId))
|
||||
.replace("{2}", builder.toString()));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public KitOperations incrementStat(int kitId, int statId, int value)
|
||||
{
|
||||
_query.append(INCREMENT_KIT_STAT
|
||||
.replace("{0}", _accountIdString)
|
||||
.replace("{1}", String.valueOf(kitId))
|
||||
.replace("{2}", String.valueOf(statId))
|
||||
.replace("{3}", String.valueOf(value)));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public KitOperations setStat(int kitId, int statId, int value)
|
||||
{
|
||||
_query.append(SET_KIT_STAT
|
||||
.replace("{0}", _accountIdString)
|
||||
.replace("{1}", String.valueOf(kitId))
|
||||
.replace("{2}", String.valueOf(statId))
|
||||
.replace("{3}", String.valueOf(value)));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getAccountId()
|
||||
{
|
||||
return _accountId;
|
||||
}
|
||||
|
||||
public String getQuery()
|
||||
{
|
||||
return _query.toString();
|
||||
}
|
||||
|
||||
public boolean execute()
|
||||
{
|
||||
return _repository.executeKitOperation(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,167 @@
|
||||
package mineplex.core.game.kit;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.account.ILoginProcessor;
|
||||
import mineplex.core.common.util.EnclosedObject;
|
||||
import mineplex.core.game.MineplexGameManager;
|
||||
import mineplex.core.game.kit.upgrade.KitStat;
|
||||
import mineplex.serverdata.database.DBPool;
|
||||
import mineplex.serverdata.database.RepositoryBase;
|
||||
import mineplex.serverdata.database.column.ColumnVarChar;
|
||||
|
||||
public class KitRepository extends RepositoryBase
|
||||
{
|
||||
|
||||
private static final String GET_LEGACY_KITS = "SELECT * FROM kitProgression WHERE uuid=?";
|
||||
private static final String DELETE_LEGACY_KITS = "DELETE FROM kitProgression WHERE uuid=?";
|
||||
|
||||
public KitRepository(MineplexGameManager manager)
|
||||
{
|
||||
super(DBPool.getAccount());
|
||||
|
||||
CoreClientManager clientManager = manager.getClientManager();
|
||||
|
||||
clientManager.addStoredProcedureLoginProcessor(new ILoginProcessor()
|
||||
{
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "KitBasicInfo";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processLoginResultSet(String playerName, UUID uuid, int accountId, ResultSet resultSet) throws SQLException
|
||||
{
|
||||
Map<GameKit, PlayerKitData> kitData = manager.Get(uuid);
|
||||
|
||||
while (resultSet.next())
|
||||
{
|
||||
manager.getKitFrom(resultSet.getInt("kitId")).ifPresent(kit ->
|
||||
{
|
||||
try
|
||||
{
|
||||
kitData.put(kit, new PlayerKitData(resultSet.getBoolean("active")));
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQuery(int accountId, String uuid, String name)
|
||||
{
|
||||
return "SELECT * FROM accountKits WHERE accountId=" + accountId + ";";
|
||||
}
|
||||
});
|
||||
clientManager.addStoredProcedureLoginProcessor(new ILoginProcessor()
|
||||
{
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "KitStats";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processLoginResultSet(String playerName, UUID uuid, int accountId, ResultSet resultSet) throws SQLException
|
||||
{
|
||||
Map<GameKit, PlayerKitData> kitData = manager.Get(uuid);
|
||||
|
||||
while (resultSet.next())
|
||||
{
|
||||
manager.getKitFrom(resultSet.getInt("kitId")).ifPresent(kit ->
|
||||
{
|
||||
PlayerKitData data = kitData.get(kit);
|
||||
|
||||
if (data != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
KitStat.getById(resultSet.getInt("statId")).ifPresent(stat ->
|
||||
{
|
||||
try
|
||||
{
|
||||
data.getStats().put(stat, resultSet.getInt("value"));
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQuery(int accountId, String uuid, String name)
|
||||
{
|
||||
return "SELECT * FROM accountKitStats WHERE accountId=" + accountId + ";";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public List<LegacyKit> getLegacyKits(UUID uuid)
|
||||
{
|
||||
EnclosedObject<Boolean> success = new EnclosedObject<>(true);
|
||||
List<LegacyKit> kits = new ArrayList<>();
|
||||
|
||||
executeQuery(
|
||||
GET_LEGACY_KITS,
|
||||
resultSet ->
|
||||
{
|
||||
while (resultSet.next())
|
||||
{
|
||||
kits.add(new LegacyKit(resultSet.getString("kitId"), resultSet.getInt("xp"), resultSet.getInt("level"), resultSet.getInt("upgrade_level")));
|
||||
}
|
||||
},
|
||||
() -> success.Set(false),
|
||||
new ColumnVarChar("uuid", 36, uuid.toString())
|
||||
);
|
||||
|
||||
return success.Get() ? kits : null;
|
||||
}
|
||||
|
||||
public boolean deleteLegacyKits(UUID uuid)
|
||||
{
|
||||
EnclosedObject<Boolean> success = new EnclosedObject<>(true);
|
||||
|
||||
executeUpdate(
|
||||
DELETE_LEGACY_KITS,
|
||||
() -> success.Set(false),
|
||||
new ColumnVarChar("uuid", 36, uuid.toString())
|
||||
);
|
||||
|
||||
return success.Get();
|
||||
}
|
||||
|
||||
boolean executeKitOperation(KitOperations operations)
|
||||
{
|
||||
int accountId = operations.getAccountId();
|
||||
|
||||
if (accountId == -1 || operations.getQuery().isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
EnclosedObject<Boolean> success = new EnclosedObject<>(true);
|
||||
|
||||
executeInsert(operations.getQuery(), null, () -> success.Set(false));
|
||||
|
||||
return success.Get();
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package mineplex.core.game.kit;
|
||||
|
||||
@Deprecated
|
||||
public class LegacyKit
|
||||
{
|
||||
|
||||
private final String _id;
|
||||
private final int _kitXP, _kitLevel, _kitUpgradeLevel;
|
||||
|
||||
LegacyKit(String id, int kitXP, int kitLevel, int kitUpgradeLevel)
|
||||
{
|
||||
_id = id;
|
||||
_kitXP = kitXP;
|
||||
_kitLevel = kitLevel;
|
||||
_kitUpgradeLevel = kitUpgradeLevel;
|
||||
}
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
public int getKitXP()
|
||||
{
|
||||
return _kitXP;
|
||||
}
|
||||
|
||||
public int getKitLevel()
|
||||
{
|
||||
return _kitLevel;
|
||||
}
|
||||
|
||||
public int getKitUpgradeLevel()
|
||||
{
|
||||
return _kitUpgradeLevel;
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package mineplex.core.game.kit;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import mineplex.core.game.kit.upgrade.KitStat;
|
||||
|
||||
public class PlayerKitData
|
||||
{
|
||||
|
||||
private boolean _active;
|
||||
private final Map<KitStat, Integer> _stats;
|
||||
|
||||
public PlayerKitData(boolean active)
|
||||
{
|
||||
_active = active;
|
||||
_stats = new HashMap<>();
|
||||
}
|
||||
|
||||
public void setActive(boolean active)
|
||||
{
|
||||
_active = active;
|
||||
}
|
||||
|
||||
public boolean isActive()
|
||||
{
|
||||
return _active;
|
||||
}
|
||||
|
||||
public Map<KitStat, Integer> getStats()
|
||||
{
|
||||
return _stats;
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package mineplex.core.game.kit.event;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
import mineplex.core.game.kit.GameKit;
|
||||
import mineplex.core.newnpc.NPC;
|
||||
|
||||
public class KitNPCInteractEvent extends PlayerEvent implements Cancellable
|
||||
{
|
||||
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
private final NPC _npc;
|
||||
private final GameKit _kit;
|
||||
|
||||
private boolean _cancelled;
|
||||
|
||||
public KitNPCInteractEvent(Player who, NPC npc, GameKit kit)
|
||||
{
|
||||
super(who);
|
||||
|
||||
_npc = npc;
|
||||
_kit = kit;
|
||||
}
|
||||
|
||||
public NPC getNpc()
|
||||
{
|
||||
return _npc;
|
||||
}
|
||||
|
||||
public GameKit getKit()
|
||||
{
|
||||
return _kit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled()
|
||||
{
|
||||
return _cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled)
|
||||
{
|
||||
_cancelled = cancelled;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return getHandlerList();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package mineplex.core.game.kit.event;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
import mineplex.core.game.kit.GameKit;
|
||||
|
||||
public class KitSelectEvent extends PlayerEvent implements Cancellable
|
||||
{
|
||||
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
private final GameKit _kit;
|
||||
|
||||
private boolean _cancelled;
|
||||
|
||||
public KitSelectEvent(Player who, GameKit kit)
|
||||
{
|
||||
super(who);
|
||||
|
||||
_kit = kit;
|
||||
}
|
||||
|
||||
public GameKit getKit()
|
||||
{
|
||||
return _kit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled()
|
||||
{
|
||||
return _cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled)
|
||||
{
|
||||
_cancelled = cancelled;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return getHandlerList();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package mineplex.core.game.kit.ui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.achievement.Achievement;
|
||||
import mineplex.core.achievement.AchievementData;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.game.MineplexGameManager;
|
||||
import mineplex.core.game.kit.GameKit;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
|
||||
public class KitAchievementPage extends KitPage
|
||||
{
|
||||
|
||||
KitAchievementPage(MineplexGameManager plugin, Player player, GameKit kit)
|
||||
{
|
||||
super(plugin, player, kit, kit.getDisplayName() + " Achievements", 45);
|
||||
|
||||
buildPage();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildPage()
|
||||
{
|
||||
addBackButton();
|
||||
|
||||
Achievement[] achievements = _kit.getAchievements();
|
||||
int currentIndex = Math.max(22 - (achievements.length / 2), 18);
|
||||
|
||||
for (Achievement achievement : achievements)
|
||||
{
|
||||
AchievementData data = _plugin.getAchievementManager().get(_player, achievement);
|
||||
boolean hasUnlocked = data.getLevel() >= achievement.getMaxLevel();
|
||||
|
||||
ItemBuilder builder = new ItemBuilder(hasUnlocked ? Material.EXP_BOTTLE : Material.GLASS_BOTTLE);
|
||||
builder.setTitle((hasUnlocked ? C.cGreen : C.cRed) + achievement.getName());
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
lore.add(C.blankLine);
|
||||
|
||||
for (String line : achievement.getDesc())
|
||||
{
|
||||
lore.add(C.cWhite + line);
|
||||
}
|
||||
|
||||
if (hasUnlocked)
|
||||
{
|
||||
lore.add(C.blankLine);
|
||||
lore.add(C.cAqua + "Complete!");
|
||||
}
|
||||
|
||||
builder.addLores(lore);
|
||||
|
||||
addButtonNoAction(currentIndex++, builder.build());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,207 @@
|
||||
package mineplex.core.game.kit.ui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.currency.GlobalCurrency;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.game.MineplexGameManager;
|
||||
import mineplex.core.game.kit.GameKit;
|
||||
import mineplex.core.game.kit.KitAvailability;
|
||||
import mineplex.core.game.kit.PlayerKitData;
|
||||
import mineplex.core.game.kit.ui.processors.KitPackageProcessor;
|
||||
import mineplex.core.game.kit.upgrade.KitStat;
|
||||
import mineplex.core.game.kit.upgrade.LinearUpgradeTree;
|
||||
import mineplex.core.game.kit.upgrade.UpgradeTree;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
import mineplex.core.shop.confirmation.ConfirmationPage;
|
||||
import mineplex.core.shop.item.IButton;
|
||||
|
||||
public class KitMainPage extends KitPage
|
||||
{
|
||||
|
||||
public KitMainPage(MineplexGameManager plugin, Player player, GameKit kit)
|
||||
{
|
||||
super(plugin, player, kit, kit.getDisplayName(), 27);
|
||||
|
||||
buildPage();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildPage()
|
||||
{
|
||||
List<String> lore = new ArrayList<>(Arrays.asList(_kit.getDescription()));
|
||||
boolean unlocked = _plugin.isUnlocked(_player, _kit);
|
||||
|
||||
lore.add(0, C.blankLine);
|
||||
lore.add("");
|
||||
|
||||
if (_plugin.isActive(_player, _kit))
|
||||
{
|
||||
lore.add(C.cRed + "You already have this kit selected.");
|
||||
}
|
||||
else if (unlocked)
|
||||
{
|
||||
lore.add(C.cRedB + "Click Me " + C.cRed + "to select as your kit.");
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (_kit.getAvailability())
|
||||
{
|
||||
case Gem:
|
||||
lore.add(C.cRedB + "Click Me " + C.cRed + "to buy this kit for " + GlobalCurrency.GEM.getString(_kit.getCost()) + C.cRed + ".");
|
||||
break;
|
||||
case Achievement:
|
||||
lore.add(C.cRed + "This kit requires " + C.cPurple + _kit.getAchievements().length + " Achievements" + C.cRed + " to unlock.");
|
||||
lore.add(C.cRedB + "Click Me " + C.cRed + "to view the required achievements.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Optional<UpgradeTree> optional = _kit.getUpgradeTree();
|
||||
boolean hasUpgrades = optional.isPresent() && unlocked;
|
||||
|
||||
addButton(hasUpgrades ? 11 : 13, new ItemBuilder(_kit.getEntityData().getInHand())
|
||||
.setTitle(_kit.getFormattedName())
|
||||
.addLore(C.cWhite + "Kit Description:")
|
||||
.addLore(lore.toArray(new String[0]))
|
||||
.build(), (player, clickType) ->
|
||||
{
|
||||
if (!Recharge.Instance.use(player, "Kit Menu Interact", 500, false, false))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Kit is either unlocked or it's free
|
||||
if (_plugin.isUnlocked(player, _kit))
|
||||
{
|
||||
// If it isn't already active
|
||||
if (!_plugin.isActive(player, _kit))
|
||||
{
|
||||
// Check if the player has an entry in the database about this kit. If not unlock it.
|
||||
// This only happens with free kits on their first selection
|
||||
if (!_plugin.ownsKit(player, _kit))
|
||||
{
|
||||
_plugin.unlock(player, _kit);
|
||||
}
|
||||
else
|
||||
{
|
||||
_plugin.setActiveKit(player, _kit);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (_plugin.canUnlock(player, _kit))
|
||||
{
|
||||
MineplexGameManager plugin = _plugin;
|
||||
Runnable unlockRunnable = () -> plugin.unlock(player, _kit);
|
||||
|
||||
switch (_kit.getAvailability())
|
||||
{
|
||||
case Gem:
|
||||
_shop.openPageForPlayer(player, new ConfirmationPage<>(
|
||||
_player,
|
||||
this,
|
||||
new KitPackageProcessor(
|
||||
_plugin,
|
||||
_kit,
|
||||
_player,
|
||||
unlockRunnable
|
||||
),
|
||||
getItem(13)
|
||||
));
|
||||
break;
|
||||
default:
|
||||
unlockRunnable.run();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (_kit.getAvailability() == KitAvailability.Achievement)
|
||||
{
|
||||
_shop.openPageForPlayer(player, new KitAchievementPage(_plugin, player, _kit));
|
||||
}
|
||||
else
|
||||
{
|
||||
playDenySound(player);
|
||||
}
|
||||
});
|
||||
|
||||
if (hasUpgrades)
|
||||
{
|
||||
UpgradeTree upgradeTree = optional.get();
|
||||
Optional<PlayerKitData> kitData = _plugin.getPlayerKitData(_player, _kit);
|
||||
|
||||
if (!kitData.isPresent())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ItemBuilder builder = new ItemBuilder(Material.EXP_BOTTLE);
|
||||
IButton button;
|
||||
Map<KitStat, Integer> playerStats = kitData.get().getStats();
|
||||
|
||||
if (upgradeTree instanceof LinearUpgradeTree)
|
||||
{
|
||||
LinearUpgradeTree linearTree = (LinearUpgradeTree) upgradeTree;
|
||||
|
||||
int xp = playerStats.getOrDefault(KitStat.XP, 0);
|
||||
int level = LinearUpgradeTree.getLevel(xp);
|
||||
int upgradeLevel = playerStats.getOrDefault(KitStat.UPGRADE_LEVEL, 0);
|
||||
|
||||
builder.setTitle(C.cYellowB + "Kit Level - " + C.cGreen + level);
|
||||
builder.addLore(
|
||||
"",
|
||||
"Play games with this kit to earn experience for it",
|
||||
"and unlock special bonuses over time!"
|
||||
);
|
||||
|
||||
if (upgradeLevel > 0)
|
||||
{
|
||||
builder.addLore("", "Current Bonus: " + C.cGreen + "Rank " + upgradeLevel);
|
||||
|
||||
for (String upgrade : linearTree.getUpgrades().get(upgradeLevel - 1))
|
||||
{
|
||||
builder.addLore(upgrade);
|
||||
}
|
||||
}
|
||||
|
||||
if (upgradeLevel < linearTree.getUpgrades().size())
|
||||
{
|
||||
builder.addLore("", "Next Bonus: " + C.cRed + "Rank " + (upgradeLevel + 1));
|
||||
|
||||
for (String upgrade : linearTree.getUpgrades().get(upgradeLevel))
|
||||
{
|
||||
builder.addLore(upgrade);
|
||||
}
|
||||
|
||||
int levelsUtilUpgrade = LinearUpgradeTree.getLevelsUntilNextUpgrade(level, upgradeLevel + 1);
|
||||
|
||||
if (levelsUtilUpgrade > 0)
|
||||
{
|
||||
builder.addLore("", "You can buy the next rank in " + C.cGreen + levelsUtilUpgrade + C.cGray + " levels.");
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.addLore("", C.cGreen + "You can by the next rank upgrade!");
|
||||
}
|
||||
}
|
||||
|
||||
builder.addLore("", C.cYellowB + "Click Me " + C.cYellow + "to see all the rank unlocks for this kit.");
|
||||
|
||||
button = (player, clickType) -> _shop.openPageForPlayer(player, new KitUpgradePage(_plugin, player, _kit));
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
addButton(15, builder.build(), button);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package mineplex.core.game.kit.ui;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.game.MineplexGameManager;
|
||||
import mineplex.core.game.kit.GameKit;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.core.shop.page.ShopPageBase;
|
||||
|
||||
abstract class KitPage extends ShopPageBase<MineplexGameManager, KitShop>
|
||||
{
|
||||
|
||||
private static final ItemStack GO_BACK = new ItemBuilder(Material.BED)
|
||||
.setTitle(C.cGreen + "Go Back")
|
||||
.build();
|
||||
|
||||
protected final GameKit _kit;
|
||||
|
||||
KitPage(MineplexGameManager plugin, Player player, GameKit kit, String name)
|
||||
{
|
||||
this(plugin, player, kit, name, 29);
|
||||
}
|
||||
|
||||
KitPage(MineplexGameManager plugin, Player player, GameKit kit, String name, int size)
|
||||
{
|
||||
super(plugin, plugin.getShop(), plugin.getClientManager(), plugin.getDonationManager(), name, player, size);
|
||||
|
||||
_kit = kit;
|
||||
}
|
||||
|
||||
protected void addBackButton()
|
||||
{
|
||||
addButton(4, GO_BACK, (player, clickType) -> _plugin.openKitUI(player, _kit));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
package mineplex.core.game.kit.ui;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.game.MineplexGameManager;
|
||||
import mineplex.core.shop.ShopBase;
|
||||
import mineplex.core.shop.page.ShopPageBase;
|
||||
|
||||
public class KitShop extends ShopBase<MineplexGameManager>
|
||||
{
|
||||
|
||||
public KitShop(MineplexGameManager plugin)
|
||||
{
|
||||
super(plugin, plugin.getClientManager(), plugin.getDonationManager(), "Kit");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ShopPageBase<MineplexGameManager, ? extends ShopBase<MineplexGameManager>> buildPagesFor(Player player)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
package mineplex.core.game.kit.ui;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.currency.GlobalCurrency;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.game.MineplexGameManager;
|
||||
import mineplex.core.game.kit.GameKit;
|
||||
import mineplex.core.game.kit.ui.processors.KitUpgradeProcessor;
|
||||
import mineplex.core.game.kit.upgrade.KitStat;
|
||||
import mineplex.core.game.kit.upgrade.LinearUpgradeTree;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.core.shop.confirmation.ConfirmationPage;
|
||||
|
||||
public class KitUpgradePage extends KitPage
|
||||
{
|
||||
|
||||
KitUpgradePage(MineplexGameManager plugin, Player player, GameKit kit)
|
||||
{
|
||||
super(plugin, player, kit, kit.getDisplayName() + " Upgrades");
|
||||
|
||||
buildPage();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildPage()
|
||||
{
|
||||
addBackButton();
|
||||
|
||||
LinearUpgradeTree upgradeTree = (LinearUpgradeTree) _kit.getUpgradeTree().get();
|
||||
int currentLevel = LinearUpgradeTree.getLevel(_plugin, _player, _kit);
|
||||
int currentUpgradeLevel = LinearUpgradeTree.getUpgradeLevel(_plugin, _player, _kit);
|
||||
|
||||
int i = 0;
|
||||
int menuIndex = 11;
|
||||
boolean previousUnlock = false;
|
||||
for (String[] upgrades : upgradeTree.getUpgrades())
|
||||
{
|
||||
int displayI = i + 1;
|
||||
int upgradeAtLevel = LinearUpgradeTree.getUpgradeAtLevel(i);
|
||||
int cost = LinearUpgradeTree.getUpgradeCost(i);
|
||||
boolean unlocked = currentUpgradeLevel >= displayI;
|
||||
boolean canUnlock = !previousUnlock && LinearUpgradeTree.getLevelsUntilNextUpgrade(currentLevel, displayI) <= 0 && !unlocked && _plugin.getDonationManager().Get(_player).getBalance(GlobalCurrency.GEM) >= cost;
|
||||
ItemBuilder builder = new ItemBuilder(Material.STAINED_CLAY);
|
||||
String colour;
|
||||
|
||||
builder.addLore("");
|
||||
|
||||
if (unlocked)
|
||||
{
|
||||
colour = C.cGreenB;
|
||||
builder.addLore("Rank Unlocked");
|
||||
builder.setData((byte) 5);
|
||||
}
|
||||
else if (canUnlock)
|
||||
{
|
||||
colour = C.cPurpleB;
|
||||
builder.addLore(C.cGreen + "Rank available for purchase", C.cYellowB + "Click Me " + C.cYellow + "to buy for " + GlobalCurrency.GEM.getString(cost), "");
|
||||
builder.setData((byte) 2);
|
||||
previousUnlock = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
colour = C.cRedB;
|
||||
builder.addLore(C.cRed + "Rank Locked");
|
||||
builder.setData((byte) 3);
|
||||
}
|
||||
|
||||
builder.setTitle(colour + "Rank " + (i + 1));
|
||||
builder.addLore("Available at level " + upgradeAtLevel + (!unlocked ? " (Current Level: " + currentLevel + ")" : ""), "");
|
||||
|
||||
builder.addLore(upgrades);
|
||||
|
||||
int fMenuIndex = menuIndex;
|
||||
|
||||
addButton(menuIndex, builder.build(), (player, clickType) ->
|
||||
{
|
||||
if (canUnlock)
|
||||
{
|
||||
_shop.openPageForPlayer(player, new ConfirmationPage<>(
|
||||
_player,
|
||||
_plugin,
|
||||
_shop,
|
||||
_clientManager,
|
||||
_donationManager,
|
||||
new KitUpgradeProcessor(
|
||||
_plugin,
|
||||
_player,
|
||||
cost,
|
||||
() -> _plugin.incrementKitStat(player, _kit, KitStat.UPGRADE_LEVEL, 1)
|
||||
),
|
||||
getItem(fMenuIndex)
|
||||
));
|
||||
}
|
||||
else
|
||||
{
|
||||
playDenySound(player);
|
||||
}
|
||||
});
|
||||
|
||||
i++;
|
||||
menuIndex++;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package mineplex.core.game.kit.ui.processors;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import mineplex.core.common.currency.GlobalCurrency;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.LineFormat;
|
||||
import mineplex.core.common.util.UtilText;
|
||||
import mineplex.core.game.MineplexGameManager;
|
||||
import mineplex.core.game.kit.GameKit;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.core.shop.confirmation.ConfirmationCallback;
|
||||
import mineplex.core.shop.confirmation.ConfirmationProcessor;
|
||||
|
||||
public class KitPackageProcessor implements ConfirmationProcessor
|
||||
{
|
||||
|
||||
private final MineplexGameManager _manager;
|
||||
private final GameKit _kit;
|
||||
private final Player _player;
|
||||
private final Runnable _runAfterPurchase;
|
||||
|
||||
public KitPackageProcessor(MineplexGameManager manager, GameKit kit, Player player, Runnable runAfterPurchase)
|
||||
{
|
||||
_manager = manager;
|
||||
_kit = kit;
|
||||
_player = player;
|
||||
_runAfterPurchase = runAfterPurchase;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Inventory inventory)
|
||||
{
|
||||
String lore = GlobalCurrency.GEM.getString(_kit.getCost()) + C.cGray + " will be deducted from your account.";
|
||||
|
||||
inventory.setItem(4, new ItemBuilder(_kit.getEntityData().getInHand())
|
||||
.setTitle(_kit.getFormattedName())
|
||||
.addLore(UtilText.splitLineToArray(lore, LineFormat.LORE))
|
||||
.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(ConfirmationCallback callback)
|
||||
{
|
||||
_manager.getDonationManager().rewardCurrencyUntilSuccess(GlobalCurrency.GEM, _player, "Kit Purchase", -_kit.getCost(), success ->
|
||||
{
|
||||
if (success)
|
||||
{
|
||||
callback.resolve("Successfully unlocked " + _kit.getDisplayName());
|
||||
|
||||
if (_runAfterPurchase != null)
|
||||
{
|
||||
_runAfterPurchase.run();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
callback.reject("There was an error processing your request.");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package mineplex.core.game.kit.ui.processors;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import mineplex.core.common.currency.GlobalCurrency;
|
||||
import mineplex.core.game.MineplexGameManager;
|
||||
import mineplex.core.shop.confirmation.ConfirmationCallback;
|
||||
import mineplex.core.shop.confirmation.ConfirmationProcessor;
|
||||
|
||||
public class KitUpgradeProcessor implements ConfirmationProcessor
|
||||
{
|
||||
|
||||
private final MineplexGameManager _manager;
|
||||
private final Player _player;
|
||||
private final int _cost;
|
||||
private final Runnable _runAfterPurchase;
|
||||
|
||||
public KitUpgradeProcessor(MineplexGameManager manager, Player player, int cost, Runnable runAfterPurchase)
|
||||
{
|
||||
_manager = manager;
|
||||
_player = player;
|
||||
_cost = cost;
|
||||
_runAfterPurchase = runAfterPurchase;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Inventory inventory)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(ConfirmationCallback callback)
|
||||
{
|
||||
_manager.getDonationManager().rewardCurrencyUntilSuccess(GlobalCurrency.GEM, _player, "Kit Upgrade Purchase", -_cost, success ->
|
||||
{
|
||||
if (success)
|
||||
{
|
||||
callback.resolve("Successfully upgraded your kit!");
|
||||
|
||||
if (_runAfterPurchase != null)
|
||||
{
|
||||
_runAfterPurchase.run();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
callback.reject("There was an error processing your request.");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package mineplex.core.game.kit.upgrade;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public enum KitStat
|
||||
{
|
||||
|
||||
XP(0, "XP"),
|
||||
UPGRADE_LEVEL(1, "Upgrade Level"),
|
||||
|
||||
;
|
||||
|
||||
public static Optional<KitStat> getById(int id)
|
||||
{
|
||||
for (KitStat stats : values())
|
||||
{
|
||||
if (stats._id == id)
|
||||
{
|
||||
return Optional.of(stats);
|
||||
}
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private final int _id;
|
||||
private final String _name;
|
||||
|
||||
KitStat(int id, String name)
|
||||
{
|
||||
_id = id;
|
||||
_name = name;
|
||||
}
|
||||
|
||||
public int getId()
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package mineplex.core.game.kit.upgrade;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import mineplex.core.game.kit.GameKit;
|
||||
|
||||
public class KitStatLog
|
||||
{
|
||||
|
||||
private final Set<GameKit> _kitsUsed;
|
||||
private int _experienceEarned;
|
||||
|
||||
public KitStatLog()
|
||||
{
|
||||
_kitsUsed = new HashSet<>(2);
|
||||
}
|
||||
|
||||
public Set<GameKit> getKitsUsed()
|
||||
{
|
||||
return _kitsUsed;
|
||||
}
|
||||
|
||||
public void setExperienceEarned(int experienceEarned)
|
||||
{
|
||||
_experienceEarned = experienceEarned;
|
||||
}
|
||||
|
||||
public int getExperienceEarned()
|
||||
{
|
||||
return _experienceEarned;
|
||||
}
|
||||
}
|
@ -0,0 +1,153 @@
|
||||
package mineplex.core.game.kit.upgrade;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.game.MineplexGameManager;
|
||||
import mineplex.core.game.kit.GameKit;
|
||||
|
||||
public class LinearUpgradeTree implements UpgradeTree
|
||||
{
|
||||
|
||||
private static final int[] LEVELS;
|
||||
private static final int[] UPGRADE_AT_LEVELS;
|
||||
|
||||
static
|
||||
{
|
||||
LEVELS = new int[100];
|
||||
UPGRADE_AT_LEVELS = new int[] {5, 10, 30, 75, 100};
|
||||
|
||||
int expReq = 0;
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
expReq += 50;
|
||||
LEVELS[i] = expReq;
|
||||
}
|
||||
|
||||
for (int i = 10; i < 20; i++)
|
||||
{
|
||||
expReq += 100;
|
||||
LEVELS[i] = expReq;
|
||||
}
|
||||
|
||||
for (int i = 20; i < 40; i++)
|
||||
{
|
||||
expReq += 200;
|
||||
LEVELS[i] = expReq;
|
||||
}
|
||||
|
||||
for (int i = 40; i < 60; i++)
|
||||
{
|
||||
expReq += 300;
|
||||
LEVELS[i] = expReq;
|
||||
}
|
||||
|
||||
for (int i = 60; i < 80; i++)
|
||||
{
|
||||
expReq += 400;
|
||||
LEVELS[i] = expReq;
|
||||
}
|
||||
|
||||
for (int i = 80; i < LEVELS.length; i++)
|
||||
{
|
||||
expReq += 500;
|
||||
LEVELS[i] = expReq;
|
||||
}
|
||||
}
|
||||
|
||||
public static int getLevel(int xp)
|
||||
{
|
||||
int level = 0;
|
||||
int expReq = 0;
|
||||
|
||||
for (int xpL : LEVELS)
|
||||
{
|
||||
expReq += xpL;
|
||||
|
||||
if (xp < expReq)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
level++;
|
||||
}
|
||||
|
||||
return level;
|
||||
}
|
||||
|
||||
public static int getXpForLevel(int level)
|
||||
{
|
||||
if (level > LEVELS.length)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return LEVELS[level - 1];
|
||||
}
|
||||
|
||||
public static int getTotalXpForLevel(int level)
|
||||
{
|
||||
int expReq = 0;
|
||||
|
||||
for (int i = 1; i <= level; i++)
|
||||
{
|
||||
expReq += getXpForLevel(level);
|
||||
}
|
||||
|
||||
return expReq;
|
||||
}
|
||||
|
||||
public static int getLevelsUntilNextUpgrade(int currentLevel, int upgradeLevel)
|
||||
{
|
||||
return UPGRADE_AT_LEVELS[upgradeLevel - 1] - currentLevel;
|
||||
}
|
||||
|
||||
public static int getLevel(MineplexGameManager manager, Player player, GameKit kit)
|
||||
{
|
||||
return getLevel(getXp(manager, player, kit));
|
||||
}
|
||||
|
||||
public static int getXp(MineplexGameManager manager, Player player, GameKit kit)
|
||||
{
|
||||
return manager.getKitStat(player, kit, KitStat.XP);
|
||||
}
|
||||
|
||||
public static int getUpgradeLevel(MineplexGameManager manager, Player player, GameKit kit)
|
||||
{
|
||||
return manager.getKitStat(player, kit, KitStat.UPGRADE_LEVEL);
|
||||
}
|
||||
|
||||
public static int getUpgradeAtLevel(int index)
|
||||
{
|
||||
return UPGRADE_AT_LEVELS[index];
|
||||
}
|
||||
|
||||
public static int getUpgradeCost(int index)
|
||||
{
|
||||
return getUpgradeAtLevel(index) * 1000;
|
||||
}
|
||||
|
||||
private final List<List<String>> _upgrades;
|
||||
|
||||
public LinearUpgradeTree(String[]... upgrades)
|
||||
{
|
||||
List<List<String>> upgradesList = new ArrayList<>(upgrades.length);
|
||||
|
||||
for (String[] upgrade : upgrades)
|
||||
{
|
||||
upgradesList.add(Arrays.asList(upgrade));
|
||||
}
|
||||
|
||||
_upgrades = Collections.unmodifiableList(upgradesList);
|
||||
}
|
||||
|
||||
public List<List<String>> getUpgrades()
|
||||
{
|
||||
return _upgrades;
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package mineplex.core.game.kit.upgrade;
|
||||
|
||||
public interface UpgradeTree
|
||||
{
|
||||
}
|
@ -305,7 +305,7 @@ public class Hologram {
|
||||
{
|
||||
if ((getHologramTarget() == HologramTarget.WHITELIST) == containsPlayer(player))
|
||||
{
|
||||
if (getLocation().distance(player.getLocation()) < getViewDistance())
|
||||
if (getLocation().distanceSquared(player.getLocation()) < getViewDistance() * getViewDistance())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -1,54 +0,0 @@
|
||||
package mineplex.core.kit.evolvedkit;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
|
||||
public enum EvolvedCurrency
|
||||
{
|
||||
|
||||
LEATHER(1, "Leather", ChatColor.RED, Material.LEATHER, 4),
|
||||
GOLD(2, "Gold", ChatColor.GOLD, Material.GOLD_INGOT, 3),
|
||||
IRON(3, "Iron", ChatColor.WHITE, Material.IRON_INGOT, 1),
|
||||
DIAMOND(4, "Diamond", ChatColor.AQUA, Material.DIAMOND, 1),
|
||||
NETHER_STAR(5, "Nether Star", ChatColor.WHITE, Material.NETHER_STAR, 1);
|
||||
|
||||
private final int _id;
|
||||
private final String _name;
|
||||
private final ChatColor _colour;
|
||||
private final Material _material;
|
||||
private final int _maxPerRoll;
|
||||
|
||||
EvolvedCurrency(int id, String name, ChatColor colour, Material material, int maxPerRoll)
|
||||
{
|
||||
_id = id;
|
||||
_name = name;
|
||||
_colour = colour;
|
||||
_material = material;
|
||||
_maxPerRoll = maxPerRoll;
|
||||
}
|
||||
|
||||
public int getId()
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
public ChatColor getColour()
|
||||
{
|
||||
return _colour;
|
||||
}
|
||||
|
||||
public Material getMaterial()
|
||||
{
|
||||
return _material;
|
||||
}
|
||||
|
||||
public int getMaxPerRoll()
|
||||
{
|
||||
return _maxPerRoll;
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
package mineplex.core.kit.evolvedkit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.MiniClientPlugin;
|
||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
|
||||
@ReflectivelyCreateMiniPlugin
|
||||
public class EvolvedProgressionManager extends MiniClientPlugin<List<EvolvedTrack>>
|
||||
{
|
||||
|
||||
private final CoreClientManager _clientManager;
|
||||
private final DonationManager _donationManager;
|
||||
|
||||
private EvolvedProgressionManager()
|
||||
{
|
||||
super("Evolved Progression");
|
||||
|
||||
_clientManager = require(CoreClientManager.class);
|
||||
_donationManager = require(DonationManager.class);
|
||||
}
|
||||
|
||||
public EvolvedTrack get(Player player, String kitName)
|
||||
{
|
||||
List<EvolvedTrack> tracks = Get(player);
|
||||
|
||||
for (EvolvedTrack track : tracks)
|
||||
{
|
||||
if (track.getKitName().equals(kitName))
|
||||
{
|
||||
return track;
|
||||
}
|
||||
}
|
||||
|
||||
EvolvedTrack track = new EvolvedTrack(kitName, new HashMap<>(), new HashMap<>(), new HashMap<>());
|
||||
tracks.add(track);
|
||||
|
||||
return track;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<EvolvedTrack> addPlayer(UUID uuid)
|
||||
{
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public CoreClientManager getClientManager()
|
||||
{
|
||||
return _clientManager;
|
||||
}
|
||||
|
||||
public DonationManager getDonationManager()
|
||||
{
|
||||
return _donationManager;
|
||||
}
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
package mineplex.core.kit.evolvedkit;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
import mineplex.core.common.util.UtilItem.ItemCategory;
|
||||
|
||||
public class EvolvedTrack
|
||||
{
|
||||
|
||||
// Assigns the price of an item based on its type. Integer[] { leather, gold, iron, diamond}
|
||||
private final static Map<Material, Integer[]> ITEM_COSTS;
|
||||
|
||||
static
|
||||
{
|
||||
ITEM_COSTS = new HashMap<>();
|
||||
|
||||
ITEM_COSTS.put(Material.LEATHER_HELMET, new Integer[] {3, 0, 0, 0});
|
||||
ITEM_COSTS.put(Material.LEATHER_CHESTPLATE, new Integer[] {7, 0, 0, 0});
|
||||
ITEM_COSTS.put(Material.LEATHER_LEGGINGS, new Integer[] {5, 0, 0, 0});
|
||||
ITEM_COSTS.put(Material.LEATHER_BOOTS, new Integer[] {3, 0, 0, 0});
|
||||
|
||||
ITEM_COSTS.put(Material.GOLD_HELMET, new Integer[] {25, 8, 0, 0});
|
||||
ITEM_COSTS.put(Material.GOLD_CHESTPLATE, new Integer[] {50, 12, 0, 0});
|
||||
ITEM_COSTS.put(Material.GOLD_LEGGINGS, new Integer[] {50, 10, 0, 0});
|
||||
ITEM_COSTS.put(Material.GOLD_BOOTS, new Integer[] {25, 8, 0, 0});
|
||||
|
||||
ITEM_COSTS.put(Material.IRON_HELMET, new Integer[] {50, 0, 5, 0});
|
||||
ITEM_COSTS.put(Material.IRON_CHESTPLATE, new Integer[] {100, 0, 10, 0});
|
||||
ITEM_COSTS.put(Material.IRON_LEGGINGS, new Integer[] {100, 0, 8, 0});
|
||||
ITEM_COSTS.put(Material.IRON_BOOTS, new Integer[] {50, 0, 5, 0});
|
||||
|
||||
ITEM_COSTS.put(Material.DIAMOND_HELMET, new Integer[] {100, 0, 0, 5});
|
||||
ITEM_COSTS.put(Material.DIAMOND_CHESTPLATE, new Integer[] {250, 0, 0, 10});
|
||||
ITEM_COSTS.put(Material.DIAMOND_LEGGINGS, new Integer[] {250, 0, 0, 9});
|
||||
ITEM_COSTS.put(Material.DIAMOND_BOOTS, new Integer[] {100, 0, 0, 5});
|
||||
|
||||
ITEM_COSTS.put(Material.STONE_SWORD, new Integer[] {5, 1, 0, 0});
|
||||
ITEM_COSTS.put(Material.IRON_SWORD, new Integer[] {5, 0, 8, 0});
|
||||
ITEM_COSTS.put(Material.DIAMOND_SWORD, new Integer[] {10, 0, 0, 10});
|
||||
}
|
||||
|
||||
public static Map<Material, Integer[]> getItemCosts()
|
||||
{
|
||||
return ITEM_COSTS;
|
||||
}
|
||||
|
||||
private final String _kitName;
|
||||
private final Map<EvolvedCurrency, Integer> _currencyMap;
|
||||
private final Map<ItemCategory, Integer> _itemLevelUnlocks;
|
||||
private final Map<ItemCategory, Integer> _itemLevelEquipped;
|
||||
|
||||
public EvolvedTrack(String kitName, Map<EvolvedCurrency, Integer> currencyMap, Map<ItemCategory, Integer> itemLevelUnlocks, Map<ItemCategory, Integer> itemLevelEquipped)
|
||||
{
|
||||
_kitName = kitName;
|
||||
_currencyMap = currencyMap;
|
||||
_itemLevelUnlocks = itemLevelUnlocks;
|
||||
_itemLevelEquipped = itemLevelEquipped;
|
||||
}
|
||||
|
||||
public int incrementCurrency(EvolvedCurrency currency, int amount)
|
||||
{
|
||||
int newAmount = _currencyMap.get(currency) + amount;
|
||||
|
||||
_currencyMap.put(currency, newAmount);
|
||||
|
||||
return newAmount;
|
||||
}
|
||||
|
||||
public String getKitName()
|
||||
{
|
||||
return _kitName;
|
||||
}
|
||||
}
|
@ -1,176 +1,20 @@
|
||||
package mineplex.core.newnpc;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.inventory.EntityEquipment;
|
||||
|
||||
import mineplex.core.Managers;
|
||||
import mineplex.core.common.util.UtilEnt;
|
||||
import mineplex.core.hologram.Hologram;
|
||||
import mineplex.core.hologram.HologramManager;
|
||||
import mineplex.core.itemstack.ItemStackFactory;
|
||||
import mineplex.core.utils.UtilVariant;
|
||||
import mineplex.serverdata.database.column.Column;
|
||||
import mineplex.serverdata.database.column.ColumnByte;
|
||||
import mineplex.serverdata.database.column.ColumnDouble;
|
||||
import mineplex.serverdata.database.column.ColumnInt;
|
||||
import mineplex.serverdata.database.column.ColumnVarChar;
|
||||
|
||||
public class NPC
|
||||
public interface NPC
|
||||
{
|
||||
|
||||
private final HologramManager HOLOGRAM_MANAGER = Managers.require(HologramManager.class);
|
||||
LivingEntity spawnEntity();
|
||||
|
||||
private int _id;
|
||||
protected EntityType _entityType;
|
||||
protected String _name;
|
||||
protected Location _spawn;
|
||||
private Material _inHand;
|
||||
private byte _inHandData;
|
||||
private Material _helmet;
|
||||
private Material _chestplate;
|
||||
private Material _leggings;
|
||||
private Material _boots;
|
||||
private String _metadata;
|
||||
LivingEntity getEntity();
|
||||
|
||||
private LivingEntity _entity;
|
||||
private Hologram _nameTag;
|
||||
Hologram getNameTag();
|
||||
|
||||
public NPC(int id, EntityType entityType, String name, Location spawn, Material inHand, byte inHandData, Material helmet, Material chestplate, Material leggings, Material boots, String metadata)
|
||||
{
|
||||
_id = id;
|
||||
_entityType = entityType;
|
||||
_name = name;
|
||||
_spawn = spawn;
|
||||
_inHand = inHand;
|
||||
_inHandData = inHandData;
|
||||
_helmet = helmet;
|
||||
_chestplate = chestplate;
|
||||
_leggings = leggings;
|
||||
_boots = boots;
|
||||
_metadata = metadata;
|
||||
}
|
||||
boolean hasNameTag();
|
||||
|
||||
public LivingEntity spawnEntity()
|
||||
{
|
||||
_spawn.getChunk().load(true);
|
||||
LivingEntity entity;
|
||||
String getMetadata();
|
||||
|
||||
//TODO remove this terrible hack
|
||||
if (_name.contains("Halloween"))
|
||||
{
|
||||
entity = UtilVariant.spawnWitherSkeleton(_spawn);
|
||||
}
|
||||
else
|
||||
{
|
||||
entity = (LivingEntity) _spawn.getWorld().spawnEntity(_spawn, _entityType);
|
||||
}
|
||||
|
||||
boolean nullName = _name.equals("NULL");
|
||||
|
||||
entity.setCanPickupItems(false);
|
||||
entity.setRemoveWhenFarAway(false);
|
||||
entity.setCustomName(nullName ? null : ChatColor.translateAlternateColorCodes('&', _name));
|
||||
entity.setCustomNameVisible(!nullName);
|
||||
|
||||
EntityEquipment equipment = entity.getEquipment();
|
||||
|
||||
if (_inHand != null)
|
||||
{
|
||||
equipment.setItemInHand(ItemStackFactory.Instance.CreateStack(_inHand, _inHandData));
|
||||
}
|
||||
if (_helmet != null)
|
||||
{
|
||||
equipment.setHelmet(ItemStackFactory.Instance.CreateStack(_helmet));
|
||||
}
|
||||
if (_chestplate != null)
|
||||
{
|
||||
equipment.setChestplate(ItemStackFactory.Instance.CreateStack(_chestplate));
|
||||
}
|
||||
if (_leggings != null)
|
||||
{
|
||||
equipment.setLeggings(ItemStackFactory.Instance.CreateStack(_leggings));
|
||||
}
|
||||
if (_boots != null)
|
||||
{
|
||||
equipment.setBoots(ItemStackFactory.Instance.CreateStack(_boots));
|
||||
}
|
||||
|
||||
UtilEnt.vegetate(entity);
|
||||
UtilEnt.setFakeHead(entity, true);
|
||||
UtilEnt.CreatureLook(entity, _spawn.getPitch(), _spawn.getYaw());
|
||||
UtilEnt.ghost(entity, true, false);
|
||||
UtilEnt.silence(entity, true);
|
||||
|
||||
_entity = entity;
|
||||
return entity;
|
||||
}
|
||||
|
||||
public Hologram getNameTag()
|
||||
{
|
||||
if (_nameTag == null)
|
||||
{
|
||||
_nameTag = new Hologram(HOLOGRAM_MANAGER, _entity.getLocation().add(0, UtilEnt.getHeight(_entity), 0), true, _entity.getCustomName())
|
||||
.start();
|
||||
|
||||
_entity.setCustomNameVisible(false);
|
||||
_entity.setCustomName(null);
|
||||
}
|
||||
|
||||
return _nameTag;
|
||||
}
|
||||
|
||||
void setId(int id)
|
||||
{
|
||||
_id = id;
|
||||
}
|
||||
|
||||
public int getId()
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
public String getMetadata()
|
||||
{
|
||||
return _metadata;
|
||||
}
|
||||
|
||||
public LivingEntity getEntity()
|
||||
{
|
||||
return _entity;
|
||||
}
|
||||
|
||||
public List<Column<?>> toDatabaseQuery()
|
||||
{
|
||||
return Arrays.asList(
|
||||
new ColumnVarChar("entity_type", 32, _entityType.name()),
|
||||
new ColumnVarChar("name", 32, _name),
|
||||
new ColumnVarChar("world", 32, _spawn.getWorld().getName()),
|
||||
new ColumnDouble("x", _spawn.getBlockX() + 0.5),
|
||||
new ColumnDouble("y", _spawn.getY()),
|
||||
new ColumnDouble("z", _spawn.getBlockZ() + 0.5),
|
||||
new ColumnInt("yaw", (int) _spawn.getYaw()),
|
||||
new ColumnInt("pitch", (int) _spawn.getPitch()),
|
||||
new ColumnVarChar("in_hand", 32, _inHand == null ? "NULL" : _inHand.name()),
|
||||
new ColumnByte("in_hand_data", _inHandData),
|
||||
new ColumnVarChar("helmet", 32, _helmet == null ? "NULL" : _helmet.name()),
|
||||
new ColumnVarChar("chestplate", 32, _chestplate == null ? "NULL" : _chestplate.name()),
|
||||
new ColumnVarChar("leggings", 32, _leggings == null ? "NULL" : _leggings.name()),
|
||||
new ColumnVarChar("boots", 32, _boots == null ? "NULL" : _boots.name()),
|
||||
new ColumnVarChar("metadata", 32, _metadata),
|
||||
new ColumnVarChar("skinValue", 400, "NULL"),
|
||||
new ColumnVarChar("skinSignature", 700, "NULL")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package mineplex.core.newnpc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
@ -46,6 +48,7 @@ public class NPCBuilder
|
||||
npc = new PlayerNPC(
|
||||
-1,
|
||||
_name,
|
||||
new ArrayList<>(2),
|
||||
location,
|
||||
inHand,
|
||||
inHandData,
|
||||
@ -60,10 +63,11 @@ public class NPCBuilder
|
||||
}
|
||||
else
|
||||
{
|
||||
npc = new NPC(
|
||||
npc = new StoredNPC(
|
||||
-1,
|
||||
_type,
|
||||
_name,
|
||||
new ArrayList<>(2),
|
||||
location,
|
||||
inHand,
|
||||
inHandData,
|
||||
@ -75,7 +79,7 @@ public class NPCBuilder
|
||||
);
|
||||
}
|
||||
|
||||
manager.addNPC(npc);
|
||||
manager.addNPC(npc, true);
|
||||
}
|
||||
|
||||
public void setType(EntityType type)
|
||||
|
@ -9,7 +9,6 @@ import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -27,6 +26,11 @@ import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||
import mineplex.core.account.permissions.Permission;
|
||||
import mineplex.core.account.permissions.PermissionGroup;
|
||||
import mineplex.core.common.events.EntityVelocityChangeEvent;
|
||||
import mineplex.core.common.jsonchat.ClickEvent;
|
||||
import mineplex.core.common.jsonchat.HoverEvent;
|
||||
import mineplex.core.common.jsonchat.JsonMessage;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.common.util.UtilText;
|
||||
@ -34,10 +38,11 @@ import mineplex.core.creature.Creature;
|
||||
import mineplex.core.creature.event.CreatureKillEntitiesEvent;
|
||||
import mineplex.core.newnpc.command.NPCCommand;
|
||||
import mineplex.core.newnpc.command.NPCDeleteCommand;
|
||||
import mineplex.core.newnpc.command.NPCMoveCommand;
|
||||
import mineplex.core.newnpc.command.NPCEditCommand;
|
||||
import mineplex.core.newnpc.event.NPCInteractEvent;
|
||||
import mineplex.core.newnpc.event.NPCRefreshEvent;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
|
||||
/**
|
||||
* NPCManager is a new version of the previous NpcManager to improve usability and more general purpose.
|
||||
@ -56,7 +61,7 @@ public class NewNPCManager extends MiniPlugin
|
||||
BUILD_NPC_COMMAND,
|
||||
CLEAR_NPC_COMMAND,
|
||||
DELETE_NPC_COMMAND,
|
||||
REFRESH_NPC_COMMAND,
|
||||
EDIT_NPC_COMMAND,
|
||||
MOVE_NPC_COMMAND
|
||||
}
|
||||
|
||||
@ -66,7 +71,6 @@ public class NewNPCManager extends MiniPlugin
|
||||
|
||||
private final List<NPC> _npcs;
|
||||
private final Map<Player, NPCBuilder> _builders;
|
||||
private final Map<Player, Location> _teleportMap;
|
||||
|
||||
private NewNPCManager()
|
||||
{
|
||||
@ -76,18 +80,11 @@ public class NewNPCManager extends MiniPlugin
|
||||
_repository = new NewNPCRepository();
|
||||
_npcs = new ArrayList<>();
|
||||
_builders = new HashMap<>();
|
||||
_teleportMap = new HashMap<>();
|
||||
|
||||
// Loading NPCs on the main thread makes sure that _npcs is populated before anything tries to spawn NPCs.
|
||||
loadNPCs();
|
||||
// Any NPC with the metadata DUMMY will always be spawned regardless, useful for testing designs
|
||||
spawnNPCs("DUMMY", npc ->
|
||||
{
|
||||
if (npc instanceof PlayerNPC)
|
||||
{
|
||||
npc.getNameTag();
|
||||
}
|
||||
});
|
||||
spawnNPCs("DUMMY", null);
|
||||
|
||||
generatePermissions();
|
||||
}
|
||||
@ -98,7 +95,7 @@ public class NewNPCManager extends MiniPlugin
|
||||
PermissionGroup.ADMIN.setPermission(Perm.BUILD_NPC_COMMAND, true, true);
|
||||
PermissionGroup.DEV.setPermission(Perm.CLEAR_NPC_COMMAND, true, true);
|
||||
PermissionGroup.ADMIN.setPermission(Perm.DELETE_NPC_COMMAND, true, true);
|
||||
PermissionGroup.ADMIN.setPermission(Perm.REFRESH_NPC_COMMAND, true, true);
|
||||
PermissionGroup.ADMIN.setPermission(Perm.EDIT_NPC_COMMAND, true, true);
|
||||
PermissionGroup.ADMIN.setPermission(Perm.MOVE_NPC_COMMAND, true, true);
|
||||
}
|
||||
|
||||
@ -155,16 +152,6 @@ public class NewNPCManager extends MiniPlugin
|
||||
_creature.SetForce(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@link #loadNPCs()} then the {@link NPCRefreshEvent}
|
||||
*/
|
||||
public void refreshNPCS()
|
||||
{
|
||||
loadNPCs();
|
||||
|
||||
UtilServer.CallEvent(new NPCRefreshEvent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an NPC's entity and removes it from the database.
|
||||
*
|
||||
@ -172,7 +159,10 @@ public class NewNPCManager extends MiniPlugin
|
||||
*/
|
||||
public void deleteNPC(NPC npc)
|
||||
{
|
||||
runAsync(() -> _repository.deleteNPC(npc));
|
||||
if (npc instanceof StoredNPC)
|
||||
{
|
||||
runAsync(() -> _repository.deleteNPC((StoredNPC) npc));
|
||||
}
|
||||
|
||||
if (npc.getEntity() != null)
|
||||
{
|
||||
@ -206,19 +196,20 @@ public class NewNPCManager extends MiniPlugin
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawns an NPC and does not save it to the database.
|
||||
*
|
||||
* @param npc The NPC you want to spawn.
|
||||
* @see #addNPC(NPC, boolean)
|
||||
*/
|
||||
public void addNPC(NPC npc)
|
||||
{
|
||||
addNPC(npc, true);
|
||||
addNPC(npc, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds and spawns an NPC.
|
||||
*
|
||||
* @param npc The NPC you want to spawn.
|
||||
* @param saveToDB If true the NPC will be saved to the database.
|
||||
* @param saveToDB If true the NPC will be saved to the database, though npc must be a {@link StoredNPC}.
|
||||
*/
|
||||
public void addNPC(NPC npc, boolean saveToDB)
|
||||
{
|
||||
@ -227,38 +218,22 @@ public class NewNPCManager extends MiniPlugin
|
||||
_npcs.add(npc);
|
||||
npc.spawnEntity();
|
||||
|
||||
if (saveToDB)
|
||||
if (saveToDB && npc instanceof StoredNPC)
|
||||
{
|
||||
runAsync(() -> _repository.insertNPCIfNotExists(npc));
|
||||
runAsync(() -> _repository.insertNPCIfNotExists((StoredNPC) npc));
|
||||
}
|
||||
|
||||
_creature.SetForce(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by {@link NPCMoveCommand}. Has no other purpose.
|
||||
*/
|
||||
public void setPlayerTeleport(Player player)
|
||||
{
|
||||
_teleportMap.put(player, player.getLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleports an NPC to a location and saves that in the database for future reference.
|
||||
* Updates all the fields in the database for this NPC.
|
||||
*
|
||||
* @param npc The NPC you want to move.
|
||||
* @param location The Location you want to move the NPC to.
|
||||
* @param npc The NPC you wish to update.
|
||||
*/
|
||||
public void teleport(NPC npc, Location location)
|
||||
public void updateNPCProperties(StoredNPC npc)
|
||||
{
|
||||
// If there isn't an entity or the location to go is null, then don't teleport.
|
||||
if (npc.getEntity() == null || location == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
npc.getEntity().teleport(location);
|
||||
runAsync(() -> _repository.teleportNPC(npc, location));
|
||||
runAsync(() -> _repository.updateNPCProperties(npc));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -281,7 +256,6 @@ public class NewNPCManager extends MiniPlugin
|
||||
Player player = event.getPlayer();
|
||||
|
||||
_builders.remove(player);
|
||||
_teleportMap.remove(player);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -333,12 +307,7 @@ public class NewNPCManager extends MiniPlugin
|
||||
{
|
||||
String uppercase = event.getMessage().toUpperCase();
|
||||
|
||||
if (uppercase.equals("NULL"))
|
||||
{
|
||||
event.setMessage(uppercase);
|
||||
}
|
||||
|
||||
builder.setMetadata(event.getMessage());
|
||||
builder.setMetadata(uppercase.equals("NULL") ? null : event.getMessage());
|
||||
|
||||
if (builder.getType() == EntityType.PLAYER)
|
||||
{
|
||||
@ -374,7 +343,7 @@ public class NewNPCManager extends MiniPlugin
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles {@link NPCDeleteCommand} and {@link NPCMoveCommand} data input.
|
||||
* Handles NPC command interaction.
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void npcInteract(NPCInteractEvent event)
|
||||
@ -382,22 +351,66 @@ public class NewNPCManager extends MiniPlugin
|
||||
Player player = event.getPlayer();
|
||||
NPC npc = event.getNpc();
|
||||
|
||||
if (!(npc instanceof StoredNPC))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
StoredNPC storedNPC = (StoredNPC) npc;
|
||||
|
||||
if (!Recharge.Instance.usable(player, NPCDeleteCommand.RECHARGE_KEY))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
deleteNPC(npc);
|
||||
player.sendMessage(F.main(_moduleName, "Deleted " + F.name(npc.getEntity().getCustomName()) + " (" + F.elem(npc.getId()) + ")."));
|
||||
deleteNPC(storedNPC);
|
||||
player.sendMessage(F.main(_moduleName, "Deleted " + F.name(storedNPC.getColouredName() + " (" + F.elem(storedNPC.getId()) + ").")));
|
||||
Recharge.Instance.recharge(player, NPCDeleteCommand.RECHARGE_KEY);
|
||||
}
|
||||
else if (!Recharge.Instance.usable(player, NPCMoveCommand.RECHARGE_KEY))
|
||||
else if (!Recharge.Instance.usable(player, NPCEditCommand.RECHARGE_KEY))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
teleport(npc, _teleportMap.remove(player));
|
||||
player.sendMessage(F.main(_moduleName, "Moved " + F.name(npc.getEntity().getCustomName()) + " (" + F.elem(npc.getId()) + ")."));
|
||||
Recharge.Instance.recharge(player, NPCMoveCommand.RECHARGE_KEY);
|
||||
Recharge.Instance.recharge(player, NPCEditCommand.RECHARGE_KEY);
|
||||
player.sendMessage(F.main(_moduleName, "Editing " + F.name(storedNPC.getColouredName()) + "..."));
|
||||
player.sendMessage("");
|
||||
new JsonMessage(C.cGreenB + "[EDIT INFO]")
|
||||
.click(ClickEvent.SUGGEST_COMMAND, "/newnpc edit " + storedNPC.getId() + " info &e&lExample Line 1//&bExample Line 2")
|
||||
.hover(HoverEvent.SHOW_TEXT, C.cYellow + "Use // to separate lines.")
|
||||
.extra(" ")
|
||||
.extra(C.cYellowB + "[TELEPORT]")
|
||||
.click(ClickEvent.RUN_COMMAND, "/newnpc edit " + storedNPC.getId() + " spawn")
|
||||
.hover(HoverEvent.SHOW_TEXT, C.cYellow + "Click to teleport the npc to where you are standing.")
|
||||
.extra(" ")
|
||||
.extra(C.cGreenB + "[EQUIPMENT]")
|
||||
.click(ClickEvent.RUN_COMMAND, "/newnpc edit " + storedNPC.getId() + " equipment")
|
||||
.hover(HoverEvent.SHOW_TEXT, C.cYellow + "Click to give the npc what armor and items you have.")
|
||||
.extra(" ")
|
||||
.extra(C.cYellowB + "[SKIN]")
|
||||
.click(ClickEvent.RUN_COMMAND, "/newnpc edit " + storedNPC.getId() + " skin")
|
||||
.hover(HoverEvent.SHOW_TEXT, C.cYellow + "Click to give the npc your skin. Only works on players.")
|
||||
.extra(" ")
|
||||
.extra(C.cRedB + "[FINISH]")
|
||||
.click(ClickEvent.RUN_COMMAND, "/newnpc edit " + storedNPC.getId() + " update")
|
||||
.hover(HoverEvent.SHOW_TEXT, C.cYellow + "Click to finish and update the npc in the database.")
|
||||
.sendToPlayer(player);
|
||||
player.sendMessage("");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void updateInfo(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.SLOW)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_npcs.forEach(npc ->
|
||||
{
|
||||
if (npc instanceof StoredNPC && npc.getEntity() != null)
|
||||
{
|
||||
((StoredNPC) npc).updateInfo();
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Prevents chunk unloading when there is an NPC in it.
|
||||
*/
|
||||
@ -427,6 +440,15 @@ public class NewNPCManager extends MiniPlugin
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void entityVelocity(EntityVelocityChangeEvent event)
|
||||
{
|
||||
if (isNPC(event.getEntity()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void entityDamage(EntityDamageEvent event)
|
||||
{
|
||||
@ -470,6 +492,18 @@ public class NewNPCManager extends MiniPlugin
|
||||
event.GetEntities().removeIf(this::isNPC);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id The id of the NPC you wish to get the {@link NPC} object of.
|
||||
* @return The {@link NPC} that has the id or null.
|
||||
*/
|
||||
public StoredNPC getNPC(int id)
|
||||
{
|
||||
return (StoredNPC) _npcs.stream()
|
||||
.filter(npc -> npc instanceof StoredNPC && ((StoredNPC) npc).getId() == id)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param metadata The metadata you wish to find all the NPCs of.
|
||||
* @return A list of {@link NPC} that have the metadata which starts with that specified.
|
||||
|
@ -1,6 +1,7 @@
|
||||
package mineplex.core.newnpc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@ -13,9 +14,7 @@ import org.bukkit.entity.EntityType;
|
||||
import mineplex.serverdata.database.DBPool;
|
||||
import mineplex.serverdata.database.RepositoryBase;
|
||||
import mineplex.serverdata.database.column.Column;
|
||||
import mineplex.serverdata.database.column.ColumnDouble;
|
||||
import mineplex.serverdata.database.column.ColumnInt;
|
||||
import mineplex.serverdata.database.column.ColumnVarChar;
|
||||
|
||||
/**
|
||||
* A repository class that provides an interface for getting and saving NPCs.
|
||||
@ -26,23 +25,23 @@ class NewNPCRepository extends RepositoryBase
|
||||
/**
|
||||
* A SQL statement that returns all entries form the table.
|
||||
*/
|
||||
private static final String GET_NPCS = "SELECT * FROM newNPCs;";
|
||||
private static final String GET_NPCS = "SELECT * FROM newNPCsNew;";
|
||||
/**
|
||||
* A SQL statement that inserts an entry and returns the id field generated.
|
||||
*/
|
||||
private static final String INSERT_NPC = "INSERT INTO newNPCs (entity_type, name, world, x, y, z, yaw, pitch, in_hand, in_hand_data, helmet, chestplate, leggings, boots, metadata, skinValue, skinSignature) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
|
||||
private static final String INSERT_NPC = "INSERT INTO newNPCsNew (entity_type, name, info, world, x, y, z, yaw, pitch, in_hand, in_hand_data, helmet, chestplate, leggings, boots, metadata, skin_value, skin_signature) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
|
||||
/**
|
||||
* A SQL statement that deletes an entry with a specific id field.
|
||||
*/
|
||||
private static final String DELETE_NPC = "DELETE FROM newNPCs WHERE id=?;";
|
||||
private static final String DELETE_NPC = "DELETE FROM newNPCsNew WHERE id=?;";
|
||||
/**
|
||||
* A SQL statement that removes all entries from the table.
|
||||
*/
|
||||
private static final String CLEAR_NPCS = "DELETE FROM newNPCs;";
|
||||
private static final String CLEAR_NPCS = "DELETE FROM newNPCsNew;";
|
||||
/**
|
||||
* A SQL statement that adjusts the location properties of an entry with a specific id field.
|
||||
* A SQL statement that updates all the properties of an NPC.
|
||||
*/
|
||||
private static final String MOVE_NPC = "UPDATE newNPCs SET world=?, x=?, y=?, z=?, yaw=?, pitch=? WHERE id=?";
|
||||
private static final String UPDATE_NPC_PROPERTIES = "UPDATE newNPCsNew SET entity_type=?, name=?, info=?, world=?, x=?, y=?, z=?, yaw=?, pitch=?, in_hand=?, in_hand_data=?, helmet=?, chestplate=?, leggings=?, boots=?, metadata=?, skin_value=?, skin_signature=? WHERE id=?";
|
||||
|
||||
NewNPCRepository()
|
||||
{
|
||||
@ -59,11 +58,11 @@ class NewNPCRepository extends RepositoryBase
|
||||
*
|
||||
* @param response The consumer callback that supplies the list of NPCs.
|
||||
*/
|
||||
void getNPCs(Consumer<List<NPC>> response)
|
||||
void getNPCs(Consumer<List<StoredNPC>> response)
|
||||
{
|
||||
executeQuery(GET_NPCS, resultSet ->
|
||||
{
|
||||
List<NPC> npcs = new ArrayList<>();
|
||||
List<StoredNPC> npcs = new ArrayList<>();
|
||||
|
||||
// While there are more entries
|
||||
while (resultSet.next())
|
||||
@ -71,6 +70,7 @@ class NewNPCRepository extends RepositoryBase
|
||||
int id = resultSet.getInt("id");
|
||||
EntityType entityType = EntityType.valueOf(resultSet.getString("entity_type"));
|
||||
String name = resultSet.getString("name");
|
||||
String info = resultSet.getString("info");
|
||||
String worldName = resultSet.getString("world");
|
||||
double x = resultSet.getDouble("x");
|
||||
double y = resultSet.getDouble("y");
|
||||
@ -84,10 +84,10 @@ class NewNPCRepository extends RepositoryBase
|
||||
Material leggings = parseMaterial(resultSet.getString("leggings"));
|
||||
Material boots = parseMaterial(resultSet.getString("boots"));
|
||||
String metadata = resultSet.getString("metadata");
|
||||
String skinValue = resultSet.getString("skinValue");
|
||||
String skinSignature = resultSet.getString("skinSignature");
|
||||
String skinValue = resultSet.getString("skin_value");
|
||||
String skinSignature = resultSet.getString("skin_signature");
|
||||
|
||||
NPC npc;
|
||||
StoredNPC npc;
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
|
||||
// If the world is not loaded on the server then don't add it to the list
|
||||
@ -96,14 +96,21 @@ class NewNPCRepository extends RepositoryBase
|
||||
continue;
|
||||
}
|
||||
|
||||
List<String> infoList = new ArrayList<>(2);
|
||||
|
||||
if (info != null)
|
||||
{
|
||||
infoList.addAll(Arrays.asList(info.split(StoredNPC.LINE_DELIMITER)));
|
||||
}
|
||||
|
||||
// If the entity type is of player then the NPC must be specified as a PlayerNPC
|
||||
if (entityType == EntityType.PLAYER)
|
||||
{
|
||||
npc = new PlayerNPC(id, name, new Location(world, x, y, z, yaw, pitch), inHand, inHandData, helmet, chestplate, leggings, boots, metadata, skinValue, skinSignature);
|
||||
npc = new PlayerNPC(id, name, infoList, new Location(world, x, y, z, yaw, pitch), inHand, inHandData, helmet, chestplate, leggings, boots, metadata, skinValue, skinSignature);
|
||||
}
|
||||
else
|
||||
{
|
||||
npc = new NPC(id, entityType, name, new Location(world, x, y, z, yaw, pitch), inHand, inHandData, helmet, chestplate, leggings, boots, metadata);
|
||||
npc = new StoredNPC(id, entityType, name, infoList, new Location(world, x, y, z, yaw, pitch), inHand, inHandData, helmet, chestplate, leggings, boots, metadata);
|
||||
}
|
||||
|
||||
npcs.add(npc);
|
||||
@ -116,6 +123,11 @@ class NewNPCRepository extends RepositoryBase
|
||||
// Simply calls Material.valueOf, if invalid null
|
||||
private Material parseMaterial(String material)
|
||||
{
|
||||
if (material == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return Material.valueOf(material);
|
||||
@ -135,7 +147,7 @@ class NewNPCRepository extends RepositoryBase
|
||||
*
|
||||
* @param npc The NPC you want to insert into the database.
|
||||
*/
|
||||
void insertNPCIfNotExists(NPC npc)
|
||||
void insertNPCIfNotExists(StoredNPC npc)
|
||||
{
|
||||
// If the id isn't -1 then it has already been inserted
|
||||
if (npc.getId() != -1)
|
||||
@ -163,7 +175,7 @@ class NewNPCRepository extends RepositoryBase
|
||||
*
|
||||
* @param npc The NPC you want to delete.
|
||||
*/
|
||||
void deleteNPC(NPC npc)
|
||||
void deleteNPC(StoredNPC npc)
|
||||
{
|
||||
// If the id is -1 then it has never been inserted
|
||||
if (npc.getId() == -1)
|
||||
@ -188,22 +200,19 @@ class NewNPCRepository extends RepositoryBase
|
||||
/**
|
||||
* Executes the SQL insert:
|
||||
* <p>
|
||||
* {@value MOVE_NPC}
|
||||
* {@value UPDATE_NPC_PROPERTIES}
|
||||
* </p>
|
||||
*
|
||||
* @param npc The NPC you want to teleport.
|
||||
* @param location The Location that you want to the npc to teleport to.
|
||||
* @param npc The NPC you want to update.
|
||||
*/
|
||||
void teleportNPC(NPC npc, Location location)
|
||||
void updateNPCProperties(StoredNPC npc)
|
||||
{
|
||||
executeUpdate(MOVE_NPC,
|
||||
new ColumnVarChar("world", 32, location.getWorld().getName()),
|
||||
new ColumnDouble("x", location.getBlockX() + 0.5),
|
||||
new ColumnDouble("y", location.getY()),
|
||||
new ColumnDouble("z", location.getBlockZ() + 0.5),
|
||||
new ColumnInt("yaw", (int) location.getYaw()),
|
||||
new ColumnInt("pitch", (int) location.getPitch()),
|
||||
new ColumnInt("id", npc.getId())
|
||||
);
|
||||
Column<?>[] columns = npc.toDatabaseQuery().toArray(new Column[0]);
|
||||
Column<?>[] newColumns = new Column[columns.length + 1];
|
||||
|
||||
System.arraycopy(columns, 0, newColumns, 0, columns.length);
|
||||
newColumns[columns.length] = new ColumnInt("id", npc.getId());
|
||||
|
||||
executeUpdate(UPDATE_NPC_PROPERTIES, newColumns);
|
||||
}
|
||||
}
|
||||
|
@ -20,20 +20,19 @@ import mineplex.core.hologram.Hologram;
|
||||
import mineplex.serverdata.database.column.Column;
|
||||
import mineplex.serverdata.database.column.ColumnVarChar;
|
||||
|
||||
public class PlayerNPC extends NPC
|
||||
public class PlayerNPC extends StoredNPC
|
||||
{
|
||||
|
||||
private static final DisguiseManager MANAGER = Managers.require(DisguiseManager.class);
|
||||
|
||||
private final SkinData _skinData;
|
||||
|
||||
private SkinData _skinData;
|
||||
private DisguisePlayer _disguise;
|
||||
|
||||
public PlayerNPC(int id, String name, Location spawn, Material inHand, byte inHandData, Material helmet, Material chestplate, Material leggings, Material boots, String metadata, String skinValue, String skinSignature)
|
||||
PlayerNPC(int id, String name, List<String> info, Location spawn, Material inHand, byte inHandData, Material helmet, Material chestplate, Material leggings, Material boots, String metadata, String skinValue, String skinSignature)
|
||||
{
|
||||
super(id, EntityType.ARMOR_STAND, name, spawn, inHand, inHandData, helmet, chestplate, leggings, boots, metadata);
|
||||
super(id, EntityType.ARMOR_STAND, name, info, spawn, inHand, inHandData, helmet, chestplate, leggings, boots, metadata);
|
||||
|
||||
_skinData = new SkinData(skinValue, skinSignature);
|
||||
_skinData = skinValue != null && skinSignature != null ? new SkinData(skinValue, skinSignature) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -41,7 +40,7 @@ public class PlayerNPC extends NPC
|
||||
{
|
||||
LivingEntity entity = super.spawnEntity();
|
||||
|
||||
if (entity == null)
|
||||
if (entity == null || _skinData == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@ -50,6 +49,52 @@ public class PlayerNPC extends NPC
|
||||
profile.getProperties().clear();
|
||||
profile.getProperties().put("textures", _skinData.getProperty());
|
||||
|
||||
refreshDisguise(entity);
|
||||
getNameTag();
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hologram getNameTag()
|
||||
{
|
||||
if (!hasNameTag())
|
||||
{
|
||||
_disguise.getHologram().setText(_colouredName);
|
||||
}
|
||||
|
||||
return _disguise.getHologram();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNameTag()
|
||||
{
|
||||
return _disguise.hasHologram();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Column<?>> toDatabaseQuery()
|
||||
{
|
||||
List<Column<?>> columns = new ArrayList<>(super.toDatabaseQuery());
|
||||
|
||||
columns.set(0, new ColumnVarChar("entity_type", 32, EntityType.PLAYER.name()));
|
||||
columns.set(16, new ColumnVarChar("skin_value", 400, _skinData.getProperty().getValue()));
|
||||
columns.set(17, new ColumnVarChar("skin_signature", 700, _skinData.getProperty().getSignature()));
|
||||
|
||||
return columns;
|
||||
}
|
||||
|
||||
private void refreshDisguise(LivingEntity entity)
|
||||
{
|
||||
if (entity == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GameProfile profile = new GameProfile(UUID.randomUUID(), SkinData.getUnusedSkullName());
|
||||
profile.getProperties().clear();
|
||||
profile.getProperties().put("textures", _skinData.getProperty());
|
||||
|
||||
DisguisePlayer player = new DisguisePlayer(entity, profile);
|
||||
|
||||
EntityEquipment equipment = entity.getEquipment();
|
||||
@ -59,34 +104,21 @@ public class PlayerNPC extends NPC
|
||||
player.setLeggings(equipment.getLeggings());
|
||||
player.setBoots(equipment.getBoots());
|
||||
|
||||
if (_disguise != null)
|
||||
{
|
||||
MANAGER.undisguise(_disguise);
|
||||
}
|
||||
|
||||
_disguise = player;
|
||||
|
||||
// Ensure the entity is loaded before disguising
|
||||
MANAGER.runSyncLater(() -> MANAGER.disguise(player), 20);
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hologram getNameTag()
|
||||
public void setSkinData(SkinData skinData)
|
||||
{
|
||||
if (!_disguise.hasHologram())
|
||||
{
|
||||
_disguise.getHologram().setText(getEntity().getCustomName());
|
||||
}
|
||||
|
||||
return _disguise.getHologram();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Column<?>> toDatabaseQuery()
|
||||
{
|
||||
List<Column<?>> columns = new ArrayList<>(super.toDatabaseQuery());
|
||||
|
||||
columns.set(0, new ColumnVarChar("entity_type", 32, EntityType.PLAYER.name()));
|
||||
columns.set(15, new ColumnVarChar("skinValue", 400, _skinData.getProperty().getValue()));
|
||||
columns.set(16, new ColumnVarChar("skinSignature", 700, _skinData.getProperty().getSignature()));
|
||||
|
||||
return columns;
|
||||
_skinData = skinData;
|
||||
refreshDisguise(_entity);
|
||||
}
|
||||
|
||||
public DisguisePlayer getDisguise()
|
||||
|
109
Plugins/Mineplex.Core/src/mineplex/core/newnpc/SimpleNPC.java
Normal file
109
Plugins/Mineplex.Core/src/mineplex/core/newnpc/SimpleNPC.java
Normal file
@ -0,0 +1,109 @@
|
||||
package mineplex.core.newnpc;
|
||||
|
||||
import net.minecraft.server.v1_8_R3.Entity;
|
||||
import net.minecraft.server.v1_8_R3.EntityHorse;
|
||||
import net.minecraft.server.v1_8_R3.EntitySkeleton;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
||||
|
||||
import mineplex.core.Managers;
|
||||
import mineplex.core.common.util.UtilEnt;
|
||||
import mineplex.core.hologram.Hologram;
|
||||
import mineplex.core.hologram.HologramManager;
|
||||
|
||||
public class SimpleNPC implements NPC
|
||||
{
|
||||
|
||||
private static final HologramManager HOLOGRAM_MANAGER = Managers.require(HologramManager.class);
|
||||
|
||||
public static SimpleNPC of(Location location, Class<? extends LivingEntity> classOfEntity, String metadata)
|
||||
{
|
||||
return of(location, classOfEntity, metadata, 0);
|
||||
}
|
||||
|
||||
public static SimpleNPC of(Location location, Class<? extends LivingEntity> classOfEntity, String metadata, int variant)
|
||||
{
|
||||
Entity entity = ((CraftWorld) location.getWorld()).createEntity(location, classOfEntity);
|
||||
|
||||
if (entity instanceof EntitySkeleton)
|
||||
{
|
||||
((EntitySkeleton) entity).setSkeletonType(variant);
|
||||
}
|
||||
else if (entity instanceof EntityHorse)
|
||||
{
|
||||
((EntityHorse) entity).setType(variant);
|
||||
}
|
||||
|
||||
return new SimpleNPC(metadata, (LivingEntity) entity.getBukkitEntity());
|
||||
}
|
||||
|
||||
final String _metadata;
|
||||
|
||||
protected LivingEntity _entity;
|
||||
private Hologram _nameTag;
|
||||
|
||||
SimpleNPC(String metadata)
|
||||
{
|
||||
this(metadata, null);
|
||||
}
|
||||
|
||||
private SimpleNPC(String metadata, LivingEntity entity)
|
||||
{
|
||||
_metadata = metadata;
|
||||
_entity = entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity()
|
||||
{
|
||||
_entity.getLocation().getChunk().load(false);
|
||||
LivingEntity entity = ((CraftWorld) _entity.getWorld()).addEntity(((CraftEntity) _entity).getHandle(), SpawnReason.CUSTOM);
|
||||
|
||||
entity.setCanPickupItems(false);
|
||||
entity.setRemoveWhenFarAway(false);
|
||||
|
||||
UtilEnt.vegetate(entity, true);
|
||||
UtilEnt.ghost(entity, true, false);
|
||||
UtilEnt.setFakeHead(entity, true);
|
||||
UtilEnt.addFlag(entity, UtilEnt.FLAG_ENTITY_COMPONENT);
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity getEntity()
|
||||
{
|
||||
return _entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hologram getNameTag()
|
||||
{
|
||||
if (!hasNameTag())
|
||||
{
|
||||
_nameTag = new Hologram(HOLOGRAM_MANAGER, _entity.getLocation().add(0, UtilEnt.getHeight(_entity), 0), true, _entity.getCustomName())
|
||||
.start();
|
||||
|
||||
_entity.setCustomNameVisible(false);
|
||||
_entity.setCustomName(null);
|
||||
}
|
||||
|
||||
return _nameTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNameTag()
|
||||
{
|
||||
return _nameTag != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMetadata()
|
||||
{
|
||||
return _metadata;
|
||||
}
|
||||
}
|
232
Plugins/Mineplex.Core/src/mineplex/core/newnpc/StoredNPC.java
Normal file
232
Plugins/Mineplex.Core/src/mineplex/core/newnpc/StoredNPC.java
Normal file
@ -0,0 +1,232 @@
|
||||
package mineplex.core.newnpc;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.inventory.EntityEquipment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import mineplex.core.common.util.UtilEnt;
|
||||
import mineplex.core.itemstack.ItemStackFactory;
|
||||
import mineplex.serverdata.database.column.Column;
|
||||
import mineplex.serverdata.database.column.ColumnByte;
|
||||
import mineplex.serverdata.database.column.ColumnDouble;
|
||||
import mineplex.serverdata.database.column.ColumnInt;
|
||||
import mineplex.serverdata.database.column.ColumnVarChar;
|
||||
|
||||
public class StoredNPC extends SimpleNPC
|
||||
{
|
||||
|
||||
public static final String LINE_DELIMITER = "//";
|
||||
|
||||
private int _id;
|
||||
private final EntityType _entityType;
|
||||
protected final String _name, _colouredName;
|
||||
private final List<String> _info;
|
||||
private Location _spawn;
|
||||
private Material _inHand;
|
||||
private byte _inHandData;
|
||||
private Material _helmet, _chestplate, _leggings, _boots;
|
||||
|
||||
private final Map<String, Supplier<String>> _infoVariables;
|
||||
|
||||
StoredNPC(int id, EntityType entityType, String name, List<String> info, Location spawn, Material inHand, byte inHandData, Material helmet, Material chestplate, Material leggings, Material boots, String metadata)
|
||||
{
|
||||
super(metadata);
|
||||
|
||||
_id = id;
|
||||
_entityType = entityType;
|
||||
_name = name;
|
||||
_colouredName = name == null ? null : ChatColor.translateAlternateColorCodes('&', name);
|
||||
_info = info;
|
||||
_spawn = spawn;
|
||||
_inHand = inHand;
|
||||
_inHandData = inHandData;
|
||||
_helmet = helmet;
|
||||
_chestplate = chestplate;
|
||||
_leggings = leggings;
|
||||
_boots = boots;
|
||||
_infoVariables = new HashMap<>(2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnEntity()
|
||||
{
|
||||
_spawn.getChunk().load(false);
|
||||
LivingEntity entity = (LivingEntity) _spawn.getWorld().spawnEntity(_spawn, _entityType);
|
||||
boolean nullName = _name == null;
|
||||
|
||||
entity.setCanPickupItems(false);
|
||||
entity.setRemoveWhenFarAway(false);
|
||||
entity.setCustomName(nullName ? null : _colouredName);
|
||||
entity.setCustomNameVisible(!nullName);
|
||||
|
||||
EntityEquipment equipment = entity.getEquipment();
|
||||
|
||||
if (_inHand != null)
|
||||
{
|
||||
equipment.setItemInHand(ItemStackFactory.Instance.CreateStack(_inHand, _inHandData));
|
||||
}
|
||||
if (_helmet != null)
|
||||
{
|
||||
equipment.setHelmet(ItemStackFactory.Instance.CreateStack(_helmet));
|
||||
}
|
||||
if (_chestplate != null)
|
||||
{
|
||||
equipment.setChestplate(ItemStackFactory.Instance.CreateStack(_chestplate));
|
||||
}
|
||||
if (_leggings != null)
|
||||
{
|
||||
equipment.setLeggings(ItemStackFactory.Instance.CreateStack(_leggings));
|
||||
}
|
||||
if (_boots != null)
|
||||
{
|
||||
equipment.setBoots(ItemStackFactory.Instance.CreateStack(_boots));
|
||||
}
|
||||
|
||||
UtilEnt.vegetate(entity, true);
|
||||
UtilEnt.setFakeHead(entity, true);
|
||||
UtilEnt.CreatureLook(entity, _spawn.getPitch(), _spawn.getYaw());
|
||||
UtilEnt.ghost(entity, true, false);
|
||||
|
||||
if (entity instanceof ArmorStand)
|
||||
{
|
||||
ArmorStand stand = (ArmorStand) entity;
|
||||
stand.setVisible(false);
|
||||
stand.setGravity(false);
|
||||
}
|
||||
|
||||
_entity = entity;
|
||||
return entity;
|
||||
}
|
||||
|
||||
void setId(int id)
|
||||
{
|
||||
_id = id;
|
||||
}
|
||||
|
||||
public int getId()
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
public String getColouredName()
|
||||
{
|
||||
return _colouredName;
|
||||
}
|
||||
|
||||
public void addInfoVariable(String delimiter, Supplier<String> getText)
|
||||
{
|
||||
_infoVariables.put(delimiter, getText);
|
||||
}
|
||||
|
||||
public void setInfo(List<String> info)
|
||||
{
|
||||
_info.clear();
|
||||
_info.addAll(info);
|
||||
}
|
||||
|
||||
void updateInfo()
|
||||
{
|
||||
if (_info.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> textList = _info.stream()
|
||||
.map(text ->
|
||||
{
|
||||
for (Entry<String, Supplier<String>> entry : _infoVariables.entrySet())
|
||||
{
|
||||
text = text.replace(entry.getKey(), entry.getValue().get());
|
||||
}
|
||||
|
||||
return ChatColor.translateAlternateColorCodes('&', text);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
textList.add(0, _colouredName);
|
||||
getNameTag().setText(textList.toArray(new String[0]));
|
||||
}
|
||||
|
||||
public List<String> getInfo()
|
||||
{
|
||||
return _info;
|
||||
}
|
||||
|
||||
public void setSpawn(Location spawn)
|
||||
{
|
||||
_spawn = spawn;
|
||||
|
||||
if (_entity != null)
|
||||
{
|
||||
_entity.teleport(spawn);
|
||||
}
|
||||
}
|
||||
|
||||
public Location getSpawn()
|
||||
{
|
||||
return _spawn;
|
||||
}
|
||||
|
||||
public void setEquipment(ItemStack inHand, ItemStack[] armour)
|
||||
{
|
||||
if (inHand == null)
|
||||
{
|
||||
_inHand = Material.AIR;
|
||||
_inHandData = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_inHand = inHand.getType();
|
||||
_inHandData = (byte) Math.max(inHand.getData().getData(), 0);
|
||||
}
|
||||
|
||||
_boots = armour[0] == null ? null : armour[0].getType();
|
||||
_leggings = armour[1] == null ? null : armour[1].getType();
|
||||
_chestplate = armour[2] == null ? null : armour[2].getType();
|
||||
_helmet = armour[3] == null ? null : armour[3].getType();
|
||||
|
||||
if (_entity != null)
|
||||
{
|
||||
_entity.getEquipment().setItemInHand(inHand);
|
||||
_entity.getEquipment().setArmorContents(armour);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Column<?>> toDatabaseQuery()
|
||||
{
|
||||
return Arrays.asList(
|
||||
new ColumnVarChar("entity_type", 32, _entityType.name()),
|
||||
new ColumnVarChar("name", 32, _name),
|
||||
new ColumnVarChar("info", 128, _info.isEmpty() ? null : _info.stream()
|
||||
.collect(Collectors.joining(LINE_DELIMITER))),
|
||||
new ColumnVarChar("world", 32, _spawn.getWorld().getName()),
|
||||
new ColumnDouble("x", _spawn.getBlockX() + 0.5),
|
||||
new ColumnDouble("y", _spawn.getY()),
|
||||
new ColumnDouble("z", _spawn.getBlockZ() + 0.5),
|
||||
new ColumnInt("yaw", (int) _spawn.getYaw()),
|
||||
new ColumnInt("pitch", (int) _spawn.getPitch()),
|
||||
new ColumnVarChar("in_hand", 32, _inHand == null ? null : _inHand.name()),
|
||||
new ColumnByte("in_hand_data", _inHandData),
|
||||
new ColumnVarChar("helmet", 32, _helmet == null ? null : _helmet.name()),
|
||||
new ColumnVarChar("chestplate", 32, _chestplate == null ? null : _chestplate.name()),
|
||||
new ColumnVarChar("leggings", 32, _leggings == null ? null : _leggings.name()),
|
||||
new ColumnVarChar("boots", 32, _boots == null ? null : _boots.name()),
|
||||
new ColumnVarChar("metadata", 32, _metadata),
|
||||
new ColumnVarChar("skin_value", 400, null),
|
||||
new ColumnVarChar("skin_signature", 700, null)
|
||||
);
|
||||
}
|
||||
}
|
@ -18,8 +18,7 @@ public class NPCCommand extends MultiCommandBase<NewNPCManager>
|
||||
AddCommand(new NPCBuildCommand(plugin));
|
||||
AddCommand(new NPCDeleteCommand(plugin));
|
||||
AddCommand(new NPCClearCommand(plugin));
|
||||
AddCommand(new NPCRefreshCommand(plugin));
|
||||
AddCommand(new NPCMoveCommand(plugin));
|
||||
AddCommand(new NPCEditCommand(plugin));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -29,7 +28,6 @@ public class NPCCommand extends MultiCommandBase<NewNPCManager>
|
||||
caller.sendMessage(F.help("/" + _aliasUsed + " builder", "Creates a new NPC using the builder.", ChatColor.DARK_RED));
|
||||
caller.sendMessage(F.help("/" + _aliasUsed + " delete", "Deletes an NPC.", ChatColor.DARK_RED));
|
||||
caller.sendMessage(F.help("/" + _aliasUsed + " clear", "Removes all NPCs permanently.", ChatColor.DARK_RED));
|
||||
caller.sendMessage(F.help("/" + _aliasUsed + " refresh", "Reloads all NPCs.", ChatColor.DARK_RED));
|
||||
caller.sendMessage(F.help("/" + _aliasUsed + " move", "Moves an NPC.", ChatColor.DARK_RED));
|
||||
caller.sendMessage(F.help("/" + _aliasUsed + " edit", "Loads the edit menu for an npc.", ChatColor.DARK_RED));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,98 @@
|
||||
package mineplex.core.newnpc.command;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.command.CommandBase;
|
||||
import mineplex.core.common.skin.SkinData;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.newnpc.NewNPCManager;
|
||||
import mineplex.core.newnpc.NewNPCManager.Perm;
|
||||
import mineplex.core.newnpc.PlayerNPC;
|
||||
import mineplex.core.newnpc.StoredNPC;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
import mineplex.core.utils.UtilGameProfile;
|
||||
|
||||
public class NPCEditCommand extends CommandBase<NewNPCManager>
|
||||
{
|
||||
|
||||
public static final String RECHARGE_KEY = "Edit NPC";
|
||||
|
||||
NPCEditCommand(NewNPCManager plugin)
|
||||
{
|
||||
super(plugin, Perm.EDIT_NPC_COMMAND, "edit");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Execute(Player caller, String[] args)
|
||||
{
|
||||
if (args.length > 1)
|
||||
{
|
||||
String type = args[1];
|
||||
int id;
|
||||
|
||||
try
|
||||
{
|
||||
id = Integer.parseInt(args[0]);
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
sendInvalidNPC(caller);
|
||||
return;
|
||||
}
|
||||
|
||||
StoredNPC npc = Plugin.getNPC(id);
|
||||
|
||||
if (npc == null)
|
||||
{
|
||||
sendInvalidNPC(caller);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case "info":
|
||||
npc.setInfo(Arrays.asList
|
||||
(
|
||||
Arrays.stream(args)
|
||||
.skip(2)
|
||||
.collect(Collectors.joining(" "))
|
||||
.split(StoredNPC.LINE_DELIMITER)
|
||||
));
|
||||
break;
|
||||
case "spawn":
|
||||
npc.setSpawn(caller.getLocation());
|
||||
break;
|
||||
case "equipment":
|
||||
npc.setEquipment(caller.getItemInHand(), caller.getInventory().getArmorContents());
|
||||
break;
|
||||
case "skin":
|
||||
if (npc instanceof PlayerNPC)
|
||||
{
|
||||
((PlayerNPC) npc).setSkinData(SkinData.constructFromGameProfile(UtilGameProfile.getGameProfile(caller), true, true));
|
||||
}
|
||||
else
|
||||
{
|
||||
sendInvalidNPC(caller);
|
||||
}
|
||||
break;
|
||||
case "update":
|
||||
Plugin.updateNPCProperties(npc);
|
||||
caller.sendMessage(F.main(Plugin.getName(), "Updated the properties of " + F.name(npc.getEntity().getName()) + "."));
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
caller.sendMessage(F.main(Plugin.getName(), "Punch the NPC you wish to edit. You will have " + F.time("30 seconds") + " to do so."));
|
||||
Recharge.Instance.useForce(caller, RECHARGE_KEY, TimeUnit.SECONDS.toMillis(30));
|
||||
}
|
||||
|
||||
private void sendInvalidNPC(Player caller)
|
||||
{
|
||||
caller.sendMessage(F.main(Plugin.getName(), "That is not a valid npc."));
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package mineplex.core.newnpc.command;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.command.CommandBase;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.newnpc.NewNPCManager;
|
||||
import mineplex.core.newnpc.NewNPCManager.Perm;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
|
||||
public class NPCMoveCommand extends CommandBase<NewNPCManager>
|
||||
{
|
||||
|
||||
public static final String RECHARGE_KEY = "Move NPC";
|
||||
|
||||
NPCMoveCommand(NewNPCManager plugin)
|
||||
{
|
||||
super(plugin, Perm.DELETE_NPC_COMMAND, "move");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Execute(Player caller, String[] args)
|
||||
{
|
||||
caller.sendMessage(F.main(Plugin.getName(), "Punch the NPC you wish to move to this location. You will have " + F.time("30 seconds") + " to do so."));
|
||||
Plugin.setPlayerTeleport(caller);
|
||||
Recharge.Instance.useForce(caller, RECHARGE_KEY, TimeUnit.SECONDS.toMillis(30));
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package mineplex.core.newnpc.command;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.command.CommandBase;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.newnpc.NewNPCManager;
|
||||
import mineplex.core.newnpc.NewNPCManager.Perm;
|
||||
|
||||
public class NPCRefreshCommand extends CommandBase<NewNPCManager>
|
||||
{
|
||||
|
||||
NPCRefreshCommand(NewNPCManager plugin)
|
||||
{
|
||||
super(plugin, Perm.REFRESH_NPC_COMMAND, "refresh");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Execute(Player caller, String[] args)
|
||||
{
|
||||
caller.sendMessage(F.main(Plugin.getName(), "Refreshing NPCs..."));
|
||||
Plugin.runAsync(() -> Plugin.refreshNPCS());
|
||||
caller.sendMessage(F.main(Plugin.getName(), "Refreshed NPCs"));
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package mineplex.core.newnpc.event;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class NPCRefreshEvent extends Event
|
||||
{
|
||||
|
||||
private static final HandlerList _handlers = new HandlerList();
|
||||
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return _handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return getHandlerList();
|
||||
}
|
||||
|
||||
}
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
@ -48,49 +49,40 @@ public class NotePlayer
|
||||
|
||||
private void startThread()
|
||||
{
|
||||
Thread thread = new Thread(new Runnable()
|
||||
Thread thread = new Thread(() ->
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
while (!_finished)
|
||||
{
|
||||
long startTime = System.currentTimeMillis();
|
||||
while (!_finished)
|
||||
_tick++;
|
||||
if (_tick > _song.getLength())
|
||||
{
|
||||
_tick++;
|
||||
if (_tick > _song.getLength())
|
||||
if (_loop)
|
||||
{
|
||||
if (_loop)
|
||||
_tick = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
_finished = true;
|
||||
|
||||
_plugin.getServer().getScheduler().runTask(_plugin, () ->
|
||||
{
|
||||
_tick = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
_finished = true;
|
||||
SongFinishEvent event = new SongFinishEvent(_song);
|
||||
_plugin.getServer().getPluginManager().callEvent(event);
|
||||
});
|
||||
|
||||
_plugin.getServer().getScheduler().runTask(_plugin, new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
SongFinishEvent event = new SongFinishEvent(_song);
|
||||
_plugin.getServer().getPluginManager().callEvent(event);
|
||||
}
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
playTick(_tick);
|
||||
playTick(_tick);
|
||||
|
||||
try
|
||||
{
|
||||
Thread.sleep(_sleepMs);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
try
|
||||
{
|
||||
Thread.sleep(_sleepMs);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -102,10 +94,13 @@ public class NotePlayer
|
||||
{
|
||||
Player[] playerArray = (_players != null) ? _players : UtilServer.getPlayers();
|
||||
List<Player> players = new ArrayList<>(playerArray.length);
|
||||
|
||||
for (Player player : playerArray)
|
||||
{
|
||||
if (_shouldPlay != null && _shouldPlay.test(player))
|
||||
{
|
||||
players.add(player);
|
||||
}
|
||||
}
|
||||
|
||||
for (NoteLayer layer : _song.getLayers())
|
||||
@ -113,11 +108,16 @@ public class NotePlayer
|
||||
Note note = layer.getNote(tick);
|
||||
if (note != null)
|
||||
{
|
||||
Sound sound = UtilNote.getInstrumentSound(note.getInstrument());
|
||||
float volume = _volumeMult * (layer.getVolume() / 100F);
|
||||
float pitch = (float) UtilNote.getPitch(note.getNote() - 33);
|
||||
|
||||
for (Player player : players)
|
||||
{
|
||||
if (!_finished)
|
||||
player.playSound(player.getEyeLocation(), UtilNote.getInstrumentSound(note.getInstrument()), volume, (float) UtilNote.getPitch(note.getNote() - 33));
|
||||
if (!_finished)
|
||||
{
|
||||
player.playSound(player.getEyeLocation(), sound, volume, pitch);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -127,15 +127,7 @@ public class NpcManager extends MiniPlugin
|
||||
|
||||
_creature = creature;
|
||||
|
||||
_plugin.getServer().getScheduler().scheduleSyncRepeatingTask(_plugin, new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
updateNpcLocations();
|
||||
}
|
||||
}, 0L, 5L);
|
||||
|
||||
_plugin.getServer().getPluginManager().registerEvents(this, _plugin);
|
||||
runSyncTimer(this::updateNpcLocations, 0L, 5L);
|
||||
|
||||
require(DisguiseManager.class);
|
||||
|
||||
|
@ -18,16 +18,6 @@ public class HostPersonalEventServer extends CommandBase<PersonalServerManager>
|
||||
@Override
|
||||
public void Execute(Player caller, String[] args)
|
||||
{
|
||||
if (!Recharge.Instance.use(caller, "Host Event", 30000, false, false))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Plugin.getClients().Get(caller).isDisguised())
|
||||
{
|
||||
UtilPlayer.message(caller, F.main("Disguise", "You can't create a event server while you are disguised!"));
|
||||
return;
|
||||
}
|
||||
Plugin.hostServer(caller, caller.getName(), false, true);
|
||||
}
|
||||
}
|
@ -17,14 +17,6 @@ public class HostServerCommand extends CommandBase<PersonalServerManager>
|
||||
@Override
|
||||
public void Execute(Player caller, String[] args)
|
||||
{
|
||||
if (!Recharge.Instance.use(caller, "Host Server", 30000, false, false))
|
||||
return;
|
||||
|
||||
if (Plugin.getClients().Get(caller).isDisguised())
|
||||
{
|
||||
UtilPlayer.message(caller, F.main("Disguise", "You can't create a MPS while you are disguised!"));
|
||||
return;
|
||||
}
|
||||
Plugin.hostServer(caller, caller.getName(), false);
|
||||
}
|
||||
}
|
@ -1,33 +1,25 @@
|
||||
package mineplex.core.personalServer;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.account.permissions.Permission;
|
||||
import mineplex.core.account.permissions.PermissionGroup;
|
||||
import mineplex.core.common.jsonchat.ClickEvent;
|
||||
import mineplex.core.common.jsonchat.Color;
|
||||
import mineplex.core.common.jsonchat.HoverEvent;
|
||||
import mineplex.core.common.jsonchat.JsonMessage;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.communities.Community;
|
||||
import mineplex.core.itemstack.ItemStackFactory;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
import mineplex.serverdata.Region;
|
||||
import mineplex.serverdata.data.ServerGroup;
|
||||
import mineplex.serverdata.servers.ServerManager;
|
||||
import mineplex.serverdata.servers.ServerRepository;
|
||||
|
||||
@ReflectivelyCreateMiniPlugin
|
||||
public class PersonalServerManager extends MiniPlugin
|
||||
{
|
||||
public enum Perm implements Permission
|
||||
@ -42,25 +34,20 @@ public class PersonalServerManager extends MiniPlugin
|
||||
private CoreClientManager _clientManager;
|
||||
|
||||
private boolean _us;
|
||||
|
||||
private ItemStack _interfaceItem;
|
||||
private boolean _useInterfaceItem = true;
|
||||
|
||||
public PersonalServerManager(JavaPlugin plugin, CoreClientManager clientManager)
|
||||
private PersonalServerManager()
|
||||
{
|
||||
super("Personal Server Manager", plugin);
|
||||
super("MPS");
|
||||
|
||||
_clientManager = clientManager;
|
||||
_clientManager = require(CoreClientManager.class);
|
||||
|
||||
setupConfigValues();
|
||||
|
||||
_us = plugin.getConfig().getBoolean("serverstatus.us");
|
||||
_us = _plugin.getConfig().getBoolean("serverstatus.us");
|
||||
|
||||
Region region = _us ? Region.US : Region.EU;
|
||||
_repository = ServerManager.getServerRepository(region);
|
||||
|
||||
_interfaceItem = ItemStackFactory.Instance.CreateStack(Material.SPECKLED_MELON, (byte)0, 1, C.cGreen + "/hostserver");
|
||||
|
||||
|
||||
generatePermissions();
|
||||
}
|
||||
|
||||
@ -77,44 +64,6 @@ public class PersonalServerManager extends MiniPlugin
|
||||
PermissionGroup.ADMIN.setPermission(Perm.PERSONAL_EVENT_COMMAND, true, true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void openServer(PlayerInteractEvent event)
|
||||
{
|
||||
if (!_useInterfaceItem)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (_interfaceItem.equals(event.getPlayer().getItemInHand()))
|
||||
{
|
||||
if (!Recharge.Instance.use(event.getPlayer(), "Host Server Melon", 30000, false, false))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_clientManager.Get(event.getPlayer()).hasPermission(Perm.MPS))
|
||||
{
|
||||
showHostMessage(event.getPlayer());
|
||||
} else
|
||||
{
|
||||
UtilPlayer.message(event.getPlayer(), F.main("Server", "Only players with " + C.cGreen + "Legend" + C.mBody + "+ can host private servers"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void showHostMessage(Player player)
|
||||
{
|
||||
UtilPlayer.message(player, C.cRed + "------------------------------------------------");
|
||||
UtilPlayer.message(player, "This will create a Mineplex Player Server for you.");
|
||||
UtilPlayer.message(player, "Here you can play your favorite games with friends!");
|
||||
|
||||
new JsonMessage("Please ").click(ClickEvent.RUN_COMMAND, "/hostserver")
|
||||
.hover(HoverEvent.SHOW_TEXT, C.cGray + "Click to Create Server")
|
||||
.extra("CLICK HERE").color(Color.GREEN).extra(" to confirm you want to do this.")
|
||||
.color(Color.WHITE).send(JsonMessage.MessageType.CHAT_BOX, player);
|
||||
|
||||
UtilPlayer.message(player, C.cRed + "------------------------------------------------");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCommands()
|
||||
{
|
||||
@ -145,6 +94,17 @@ public class PersonalServerManager extends MiniPlugin
|
||||
|
||||
public void hostServer(Player player, String serverName, boolean eventServer, boolean eventgame)
|
||||
{
|
||||
if (!Recharge.Instance.use(player, "Host Server", 30000, false, false))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_clientManager.Get(player).isDisguised())
|
||||
{
|
||||
UtilPlayer.message(player, F.main("Disguise", "You can't create a MPS while you are disguised!"));
|
||||
return;
|
||||
}
|
||||
|
||||
int ram = 1024;
|
||||
int cpu = 1;
|
||||
|
||||
@ -241,9 +201,4 @@ public class PersonalServerManager extends MiniPlugin
|
||||
{
|
||||
return _clientManager;
|
||||
}
|
||||
|
||||
public void setUseInterfaceItem(boolean use)
|
||||
{
|
||||
_useInterfaceItem = use;
|
||||
}
|
||||
}
|
@ -54,7 +54,10 @@ public enum Preference implements Permission
|
||||
|
||||
INFORM_MUTED(false, PreferenceCategory.USER, Material.BARRIER, "Inform When Muted", "Inform people who message you if you are muted!"),
|
||||
|
||||
GAME_TIPS(true, PreferenceCategory.GAME_PLAY, Material.BOOK, "Show Game Tips", "Enabling this will show tips", "about the game in the lobby", "and during the game.")
|
||||
GAME_TIPS(true, PreferenceCategory.GAME_PLAY, Material.BOOK, "Show Game Tips", "Enabling this will show tips", "about the game in the lobby", "and during the game."),
|
||||
|
||||
UNLOCK_KITS(true, PreferenceCategory.EXCLUSIVE, Material.IRON_DOOR, "Unlock All Kits", "Enabling this will allow you", "to have access to every kit ", "in every game for free!"),
|
||||
AUTO_QUEUE(true, PreferenceCategory.USER, Material.EMERALD, "Teleport to Game Area", "Enabling this will teleport you to the", "game area instead of opening the server", "selector when choosing a game."),
|
||||
;
|
||||
|
||||
private static final Map<Integer, Preference> PREFERENCE_MAP = Maps.newHashMap();
|
||||
|
@ -1,6 +1,5 @@
|
||||
package mineplex.core.preferences;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
@ -8,16 +7,9 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
@ -29,17 +21,12 @@ import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.account.ILoginProcessor;
|
||||
import mineplex.core.account.permissions.Permission;
|
||||
import mineplex.core.account.permissions.PermissionGroup;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.UtilGear;
|
||||
import mineplex.core.common.util.UtilInv;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.incognito.IncognitoManager;
|
||||
import mineplex.core.itemstack.ItemStackFactory;
|
||||
import mineplex.core.preferences.command.PreferencesCommand;
|
||||
import mineplex.core.preferences.ui.PreferencesShop;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.core.utils.UtilGameProfile;
|
||||
|
||||
public class PreferencesManager extends MiniPlugin implements ILoginProcessor
|
||||
{
|
||||
@ -58,8 +45,6 @@ public class PreferencesManager extends MiniPlugin implements ILoginProcessor
|
||||
private final Set<UserPreferences> _saveBuffer = Sets.newHashSet();
|
||||
private final Map<Integer, UserPreferences> _preferences = Maps.newHashMap();
|
||||
|
||||
public boolean GiveItem;
|
||||
|
||||
public PreferencesManager(JavaPlugin plugin, IncognitoManager incognito, CoreClientManager clientManager)
|
||||
{
|
||||
super("Preferences", plugin);
|
||||
@ -105,6 +90,11 @@ public class PreferencesManager extends MiniPlugin implements ILoginProcessor
|
||||
{
|
||||
PermissionGroup.BUILDER.setPermission(p, true, true);
|
||||
}
|
||||
else if (p == Preference.UNLOCK_KITS)
|
||||
{
|
||||
PermissionGroup.CONTENT.setPermission(p, true, true);
|
||||
PermissionGroup.BUILDER.setPermission(p, true, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
PermissionGroup.ADMIN.setPermission(p, true, true);
|
||||
@ -130,14 +120,6 @@ public class PreferencesManager extends MiniPlugin implements ILoginProcessor
|
||||
if (p != null) _repository.saveUserPreferences(p);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void givePlayerItem(PlayerJoinEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
|
||||
handlePlayerJoin(player, false);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void storeBuffer(UpdateEvent event)
|
||||
{
|
||||
@ -160,21 +142,6 @@ public class PreferencesManager extends MiniPlugin implements ILoginProcessor
|
||||
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void playerInteract(PlayerInteractEvent event)
|
||||
{
|
||||
if (!GiveItem)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getItem() != null && event.getItem().getType() == Material.REDSTONE_COMPARATOR)
|
||||
{
|
||||
openMenu(event.getPlayer());
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public UserPreferences get(Player player)
|
||||
{
|
||||
UserPreferences preferences = _preferences.get(_clientManager.getAccountId(player));
|
||||
@ -210,40 +177,6 @@ public class PreferencesManager extends MiniPlugin implements ILoginProcessor
|
||||
_shop.attemptShopOpen(player);
|
||||
}
|
||||
|
||||
public void handlePlayerJoin(Player player, boolean force)
|
||||
{
|
||||
if (!GiveItem)
|
||||
return;
|
||||
|
||||
if (!UtilGear.isMat(player.getInventory().getItem(8), Material.SKULL_ITEM) || force)
|
||||
{
|
||||
ItemStack item = ItemStackFactory.Instance.CreateStack(Material.SKULL_ITEM, (byte) 3, 1, ChatColor.RESET + C.cGreen + "My Profile");
|
||||
SkullMeta meta = ((SkullMeta) item.getItemMeta());
|
||||
try
|
||||
{
|
||||
Field profileField = meta.getClass().getDeclaredField("profile");
|
||||
profileField.setAccessible(true);
|
||||
profileField.set(meta, UtilGameProfile.getGameProfile(player));
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
t.printStackTrace();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (!meta.hasOwner())
|
||||
{
|
||||
meta.setOwner(player.getName());
|
||||
}
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
|
||||
player.getInventory().setItem(8, item);
|
||||
|
||||
UtilInv.Update(player);
|
||||
}
|
||||
}
|
||||
|
||||
public void set(int accountId, UserPreferences preferences)
|
||||
{
|
||||
_preferences.put(accountId, preferences);
|
||||
|
@ -1,295 +0,0 @@
|
||||
package mineplex.core.profile;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||
import mineplex.core.account.CoreClient;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.achievement.Achievement;
|
||||
import mineplex.core.achievement.AchievementManager;
|
||||
import mineplex.core.achievement.leveling.LevelingManager;
|
||||
import mineplex.core.common.currency.GlobalCurrency;
|
||||
import mineplex.core.common.skin.SkinData;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.disguise.DisguiseManager;
|
||||
import mineplex.core.disguise.disguises.DisguisePlayer;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.donation.Donor;
|
||||
import mineplex.core.friend.FriendManager;
|
||||
import mineplex.core.friend.data.FriendStatus;
|
||||
import mineplex.core.hologram.Hologram;
|
||||
import mineplex.core.hologram.Hologram.HologramTarget;
|
||||
import mineplex.core.newnpc.NPC;
|
||||
import mineplex.core.newnpc.NewNPCManager;
|
||||
import mineplex.core.quests.Quest;
|
||||
import mineplex.core.quests.QuestClientData;
|
||||
import mineplex.core.quests.QuestManager;
|
||||
import mineplex.core.titles.Titles;
|
||||
import mineplex.core.titles.tracks.TrackManager;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.core.utils.UtilGameProfile;
|
||||
|
||||
@ReflectivelyCreateMiniPlugin
|
||||
public class ProfileManager extends MiniPlugin
|
||||
{
|
||||
|
||||
private static final String NPC_METADATA = "PROFILE";
|
||||
|
||||
private final AchievementManager _achievementManager;
|
||||
private final CoreClientManager _clientManager;
|
||||
private final DisguiseManager _disguiseManager;
|
||||
private final DonationManager _donationManager;
|
||||
private final FriendManager _friendManager;
|
||||
private final LevelingManager _levelingManager;
|
||||
private final NewNPCManager _npcManager;
|
||||
private final QuestManager _questManager;
|
||||
private final Titles _titles;
|
||||
private final TrackManager _trackManager;
|
||||
|
||||
private final Map<Player, Hologram> _hologramMap;
|
||||
|
||||
private final List<Function<Player, String>> _rotationLines;
|
||||
private int _lineIndex;
|
||||
|
||||
private NPC _profileNPC;
|
||||
|
||||
private ProfileManager()
|
||||
{
|
||||
super("Profile");
|
||||
|
||||
_achievementManager = require(AchievementManager.class);
|
||||
_clientManager = require(CoreClientManager.class);
|
||||
_disguiseManager = require(DisguiseManager.class);
|
||||
_donationManager = require(DonationManager.class);
|
||||
_friendManager = require(FriendManager.class);
|
||||
_levelingManager = require(LevelingManager.class);
|
||||
_npcManager = require(NewNPCManager.class);
|
||||
_questManager = require(QuestManager.class);
|
||||
_titles = require(Titles.class);
|
||||
_trackManager = require(TrackManager.class);
|
||||
|
||||
_hologramMap = new HashMap<>();
|
||||
|
||||
_rotationLines = Arrays.asList(
|
||||
// Achievements
|
||||
player ->
|
||||
{
|
||||
int completed = 0;
|
||||
|
||||
for (Achievement achievement : Achievement.values())
|
||||
{
|
||||
if (_achievementManager.get(player, achievement).getLevel() >= achievement.getMaxLevel())
|
||||
{
|
||||
completed++;
|
||||
}
|
||||
}
|
||||
|
||||
return "Achievements: " + C.cYellow + completed + C.cGray + "/" + C.cGreen + Achievement.values().length;
|
||||
},
|
||||
// Friends
|
||||
player ->
|
||||
{
|
||||
int online = 0;
|
||||
int total = 0;
|
||||
|
||||
for (FriendStatus status : _friendManager.Get(player).getFriends())
|
||||
{
|
||||
if (status.Online)
|
||||
{
|
||||
online++;
|
||||
}
|
||||
|
||||
total++;
|
||||
}
|
||||
|
||||
return "Friends: " + C.cYellow + online + C.cGray + "/" + C.cGreen + total;
|
||||
},
|
||||
// Missions
|
||||
player ->
|
||||
{
|
||||
QuestClientData data = _questManager.Get(player);
|
||||
int available = 5;
|
||||
long questExpire = TimeUnit.DAYS.toMillis(1);
|
||||
|
||||
for (int id : _questManager.getCurrentQuests())
|
||||
{
|
||||
if (data.getQuestFromAll(id) == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Quest quest = data.getQuestFromAll(id);
|
||||
|
||||
if (quest.isActive())
|
||||
{
|
||||
available--;
|
||||
}
|
||||
|
||||
if (!UtilTime.elapsed(quest.getLastCompleted(), questExpire))
|
||||
{
|
||||
available--;
|
||||
}
|
||||
}
|
||||
|
||||
return "Missions: " + C.cYellow + available + C.cGreen + " Available";
|
||||
}
|
||||
// Level Rewards
|
||||
// player ->
|
||||
// {
|
||||
// int available = 0;
|
||||
//
|
||||
// for (Entry<Integer, LevelReward> entry : _levelingManager.getLevelRewards().entrySet())
|
||||
// {
|
||||
// if (_levelingManager.canClaim(player, entry.getKey()) && !_levelingManager.hasClaimed(player, entry.getKey()))
|
||||
// {
|
||||
// available++;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return "Level Rewards: " + C.cYellow + available + C.cGreen + " Available";
|
||||
// }
|
||||
);
|
||||
|
||||
spawnNPC();
|
||||
}
|
||||
|
||||
private void spawnNPC()
|
||||
{
|
||||
_npcManager.spawnNPCs(NPC_METADATA, npc -> _profileNPC = npc);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerJoin(PlayerJoinEvent event)
|
||||
{
|
||||
if (_profileNPC == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
runSyncLater(() ->
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
GameProfile profile = UtilGameProfile.getGameProfile(player);
|
||||
|
||||
try
|
||||
{
|
||||
UtilGameProfile.changeId(profile, UUID.randomUUID());
|
||||
UtilGameProfile.changeName(profile, SkinData.getUnusedSkullName());
|
||||
}
|
||||
catch (ReflectiveOperationException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
DisguisePlayer playerDisguise = new DisguisePlayer(_profileNPC.getEntity(), profile);
|
||||
playerDisguise.getHologram()
|
||||
.setHologramTarget(HologramTarget.WHITELIST)
|
||||
.addPlayer(player);
|
||||
_hologramMap.put(player, playerDisguise.getHologram());
|
||||
updateHologram(player, playerDisguise.getHologram());
|
||||
_disguiseManager.disguise(playerDisguise, viewer -> viewer.equals(player));
|
||||
}, 20);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerQuit(PlayerQuitEvent event)
|
||||
{
|
||||
_hologramMap.remove(event.getPlayer()).stop();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void updateHologram(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.SLOW || _profileNPC == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
World world = _profileNPC.getEntity().getWorld();
|
||||
|
||||
_hologramMap.forEach((player, hologram) ->
|
||||
{
|
||||
if (!player.getWorld().equals(world))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
updateHologram(player, hologram);
|
||||
});
|
||||
|
||||
if (++_lineIndex == _rotationLines.size())
|
||||
{
|
||||
_lineIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateHologram(Player player, Hologram hologram)
|
||||
{
|
||||
CoreClient client = _clientManager.Get(player);
|
||||
Donor donor = _donationManager.Get(player);
|
||||
Function<Player, String> line = _rotationLines.get(_lineIndex);
|
||||
|
||||
|
||||
hologram.setText(
|
||||
C.cGoldB + "MY PROFILE",
|
||||
"Rank: " + client.getPrimaryGroup().getDisplay(true, true, true, true),
|
||||
"Gems: " + C.cGreen + donor.getBalance(GlobalCurrency.GEM),
|
||||
"Shards: " + C.cAqua + donor.getBalance(GlobalCurrency.TREASURE_SHARD),
|
||||
"Level: " + Achievement.getExperienceString(_achievementManager.getMineplexLevelNumber(player, false)),
|
||||
line.apply(player)
|
||||
);
|
||||
}
|
||||
|
||||
public AchievementManager getAchievementManager()
|
||||
{
|
||||
return _achievementManager;
|
||||
}
|
||||
|
||||
public CoreClientManager getClientManager()
|
||||
{
|
||||
return _clientManager;
|
||||
}
|
||||
|
||||
public DonationManager getDonationManager()
|
||||
{
|
||||
return _donationManager;
|
||||
}
|
||||
|
||||
public FriendManager getFriendManager()
|
||||
{
|
||||
return _friendManager;
|
||||
}
|
||||
|
||||
public LevelingManager getLevelingManager()
|
||||
{
|
||||
return _levelingManager;
|
||||
}
|
||||
|
||||
public Titles getTitles()
|
||||
{
|
||||
return _titles;
|
||||
}
|
||||
|
||||
public TrackManager getTrackManager()
|
||||
{
|
||||
return _trackManager;
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package mineplex.core.profile;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.profile.ui.ProfileMainPage;
|
||||
import mineplex.core.shop.ShopBase;
|
||||
import mineplex.core.shop.page.ShopPageBase;
|
||||
|
||||
public class ProfileShop extends ShopBase<ProfileManager>
|
||||
{
|
||||
|
||||
public ProfileShop(ProfileManager plugin, CoreClientManager clientManager, DonationManager donationManager, String name)
|
||||
{
|
||||
super(plugin, clientManager, donationManager, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ShopPageBase<ProfileManager, ? extends ShopBase<ProfileManager>> buildPagesFor(Player player)
|
||||
{
|
||||
return new ProfileMainPage(getPlugin(), this, player, getPlugin().getAchievementManager().getStatsManager().Get(player));
|
||||
}
|
||||
}
|
@ -1,96 +0,0 @@
|
||||
package mineplex.core.profile.ui;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import mineplex.core.achievement.Achievement;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.core.profile.ProfileManager;
|
||||
import mineplex.core.profile.ProfileShop;
|
||||
import mineplex.core.shop.item.IButton;
|
||||
import mineplex.core.shop.page.ShopPageBase;
|
||||
import mineplex.core.stats.PlayerStats;
|
||||
import mineplex.core.titles.tracks.Track;
|
||||
import mineplex.core.titles.tracks.TrackTier;
|
||||
|
||||
public class ProfileMainPage extends ShopPageBase<ProfileManager, ProfileShop>
|
||||
{
|
||||
|
||||
private static final String NO_TITLE = C.cGray + "No Title";
|
||||
private static final ItemStack STATS_ITEM = new ItemBuilder(Material.PAPER)
|
||||
.setTitle(C.cGoldB + "Stats")
|
||||
.addLore("", "View your Global and Game", "Statistics.", "", C.cGreen + "Click to open this page.")
|
||||
.build();
|
||||
|
||||
private final PlayerStats _stats;
|
||||
|
||||
public ProfileMainPage(ProfileManager plugin, ProfileShop shop, Player player, PlayerStats stats)
|
||||
{
|
||||
super(plugin, shop, plugin.getClientManager(), plugin.getDonationManager(), "Your Profile", player);
|
||||
|
||||
_stats = stats;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildPage()
|
||||
{
|
||||
addProfileButton();
|
||||
}
|
||||
|
||||
private void addProfileButton()
|
||||
{
|
||||
ItemBuilder builder = new ItemBuilder(Material.SKULL_ITEM, (byte) 3);
|
||||
builder.setPlayerHead(_client.getName());
|
||||
|
||||
int level = Achievement.GLOBAL_MINEPLEX_LEVEL.getLevelData(_stats.getStat(Achievement.GLOBAL_MINEPLEX_LEVEL.getStats()[0])).getLevel();
|
||||
builder.setTitle(Achievement.getExperienceString(level) + " " + _client.getPrimaryGroup().getDisplay(true, true, true, true) + " " + C.cYellow + _client.getName());
|
||||
|
||||
Track track = _plugin.getTitles().getActiveTrack(_player);
|
||||
|
||||
if (track != null)
|
||||
{
|
||||
TrackTier tier = track.getRequirements().getTier(_player);
|
||||
|
||||
if (tier != null)
|
||||
{
|
||||
builder.addLore(tier.getTitle());
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.addLore(NO_TITLE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.addLore(NO_TITLE);
|
||||
}
|
||||
|
||||
addButtonNoAction(0, builder.build());
|
||||
}
|
||||
|
||||
private void addStatsButton()
|
||||
{
|
||||
//addButton(11, STATS_ITEM, new PageChangeButton());
|
||||
}
|
||||
|
||||
private class PageChangeButton implements IButton
|
||||
{
|
||||
|
||||
private final ShopPageBase<ProfileManager, ProfileShop> _page;
|
||||
|
||||
PageChangeButton(ShopPageBase<ProfileManager, ProfileShop> page)
|
||||
{
|
||||
_page = page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(Player player, ClickType clickType)
|
||||
{
|
||||
_page.getShop().openPageForPlayer(player, _page);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package mineplex.core.profile.ui;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.profile.ProfileManager;
|
||||
import mineplex.core.profile.ProfileShop;
|
||||
import mineplex.core.shop.page.ShopPageBase;
|
||||
import mineplex.core.stats.PlayerStats;
|
||||
|
||||
public class StatsMainPage extends ShopPageBase<ProfileManager, ProfileShop>
|
||||
{
|
||||
|
||||
private final PlayerStats _stats;
|
||||
|
||||
public StatsMainPage(ProfileManager plugin, ProfileShop shop, Player player, PlayerStats stats)
|
||||
{
|
||||
super(plugin, shop, plugin.getClientManager(), plugin.getDonationManager(), "Stats", player);
|
||||
|
||||
_stats = stats;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildPage()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
@ -83,7 +83,7 @@ import mineplex.core.twofactor.TwoFactorAuth;
|
||||
@ReflectivelyCreateMiniPlugin
|
||||
public class Titles extends MiniDbClientPlugin<TitleData> implements IPacketHandler
|
||||
{
|
||||
public static int BOOK_SLOT = 7;
|
||||
public static int BOOK_SLOT = 8;
|
||||
|
||||
// Maps player to their selected track
|
||||
private final Map<UUID, Track> _selectedTrack = new HashMap<>();
|
||||
|
@ -29,6 +29,7 @@ import mineplex.core.titles.tracks.award.CCIITrack;
|
||||
import mineplex.core.titles.tracks.award.CastleSiegeTesterTrack;
|
||||
import mineplex.core.titles.tracks.award.ClansRaidTrack;
|
||||
import mineplex.core.titles.tracks.award.Minestrike2017Track;
|
||||
import mineplex.core.titles.tracks.award.NewHub2018Track;
|
||||
import mineplex.core.titles.tracks.custom.DongerTrack;
|
||||
import mineplex.core.titles.tracks.custom.EarlyBirdTrack;
|
||||
import mineplex.core.titles.tracks.custom.HappyGaryTrack;
|
||||
@ -127,6 +128,7 @@ public class TrackManager extends MiniPlugin
|
||||
registerTrack(new CCIITrack());
|
||||
registerTrack(new CCIIPublicTrack());
|
||||
registerTrack(new Bridges2017WinterTrack());
|
||||
registerTrack(new NewHub2018Track());
|
||||
|
||||
// Staff tracks
|
||||
registerTrack(new BuilderTrack());
|
||||
|
@ -0,0 +1,31 @@
|
||||
package mineplex.core.titles.tracks.award;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
import mineplex.core.titles.tracks.ItemizedTrack;
|
||||
import mineplex.core.titles.tracks.TrackFormat;
|
||||
import mineplex.core.titles.tracks.TrackTier;
|
||||
|
||||
public class NewHub2018Track extends ItemizedTrack
|
||||
{
|
||||
|
||||
public NewHub2018Track()
|
||||
{
|
||||
super(
|
||||
"new-hub-2018",
|
||||
ChatColor.GREEN,
|
||||
"Hub Explorer",
|
||||
"2018 Hub Explorer",
|
||||
"This track is awarded to players who found all the treasures in the new 2018 Hub.",
|
||||
true);
|
||||
|
||||
special();
|
||||
|
||||
getRequirements()
|
||||
.addTier(new TrackTier(
|
||||
"Hub Explorer",
|
||||
null,
|
||||
this::owns,
|
||||
new TrackFormat(ChatColor.AQUA, ChatColor.GREEN)
|
||||
)); }
|
||||
}
|
@ -159,6 +159,7 @@ public class TreasureLocation implements Listener
|
||||
|
||||
if (inUse())
|
||||
{
|
||||
player.closeInventory();
|
||||
player.sendMessage(F.main(getManager().getName(), "This station is already in use."));
|
||||
return false;
|
||||
}
|
||||
@ -197,7 +198,6 @@ public class TreasureLocation implements Listener
|
||||
player.sendMessage(F.main(getManager().getName(), "It looks like something went wrong when processing your request. Please try again."));
|
||||
// Using the variation of addItemToInventory with a callback so our request is processed ASAP
|
||||
getManager().getInventoryManager().addItemToInventory(null, player, treasure.getTreasureType().getItemName(), 1);
|
||||
session.cleanup(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -205,6 +205,7 @@ public class TreasureLocation implements Listener
|
||||
|
||||
UtilServer.CallEvent(new TreasureStartEvent(player, _session));
|
||||
|
||||
session.register();
|
||||
player.eject();
|
||||
player.leaveVehicle();
|
||||
player.teleport(_chest);
|
||||
@ -265,7 +266,7 @@ public class TreasureLocation implements Listener
|
||||
}
|
||||
}
|
||||
|
||||
private boolean inUse()
|
||||
public boolean inUse()
|
||||
{
|
||||
return _session != null;
|
||||
}
|
||||
@ -289,4 +290,9 @@ public class TreasureLocation implements Listener
|
||||
{
|
||||
return _session;
|
||||
}
|
||||
|
||||
public TreasureShop getShop()
|
||||
{
|
||||
return _shop;
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import mineplex.core.treasure.types.AncientTreasure;
|
||||
import mineplex.core.treasure.types.ChristmasTreasure;
|
||||
import mineplex.core.treasure.types.FreedomTreasure;
|
||||
import mineplex.core.treasure.types.GingerbreadTreasure;
|
||||
import mineplex.core.treasure.types.HauntedTreasure;
|
||||
import mineplex.core.treasure.types.IlluminatedTreasure;
|
||||
import mineplex.core.treasure.types.LoveTreasure;
|
||||
import mineplex.core.treasure.types.MOBATreasure;
|
||||
@ -34,12 +35,11 @@ import mineplex.core.treasure.types.MythicalTreasure;
|
||||
import mineplex.core.treasure.types.OldTreasure;
|
||||
import mineplex.core.treasure.types.OmegaTreasure;
|
||||
import mineplex.core.treasure.types.SpringTreasure;
|
||||
import mineplex.core.treasure.types.StPatricksTreasure;
|
||||
import mineplex.core.treasure.types.ThankfulTreasure;
|
||||
import mineplex.core.treasure.types.Treasure;
|
||||
import mineplex.core.treasure.types.TrickOrTreatTreasure2016;
|
||||
import mineplex.core.treasure.types.TrickOrTreatTreasure2017;
|
||||
import mineplex.core.treasure.types.ThankfulTreasure;
|
||||
import mineplex.core.treasure.types.StPatricksTreasure;
|
||||
import mineplex.core.treasure.types.HauntedTreasure;
|
||||
|
||||
@ReflectivelyCreateMiniPlugin
|
||||
public class TreasureManager extends MiniPlugin
|
||||
@ -105,6 +105,20 @@ public class TreasureManager extends MiniPlugin
|
||||
_treasureLocations.add(treasureLocation);
|
||||
}
|
||||
|
||||
public TreasureLocation getOpenTreasureLocation()
|
||||
{
|
||||
return _treasureLocations.stream()
|
||||
.filter(treasureLocation -> !treasureLocation.inUse())
|
||||
.findAny()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public boolean isOpeningTreasure(Player player)
|
||||
{
|
||||
return _treasureLocations.stream()
|
||||
.anyMatch(treasureLocation -> treasureLocation.inUse() && treasureLocation.getSession().getPlayer().equals(player));
|
||||
}
|
||||
|
||||
public int getChestsToOpen(Player player)
|
||||
{
|
||||
int chests = 0;
|
||||
|
@ -63,13 +63,13 @@ public class TreasureSession implements Listener
|
||||
_rewardData = new ArrayList<>(treasure.getRewardsPerChest());
|
||||
_openedChests = new ArrayList<>(treasure.getRewardsPerChest());
|
||||
_start = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
if (!hasFailed())
|
||||
{
|
||||
_rewards.forEach(reward -> reward.giveReward(player, _rewardData::add));
|
||||
_animation.setRunning(true);
|
||||
UtilServer.RegisterEvents(this);
|
||||
}
|
||||
public void register()
|
||||
{
|
||||
_rewards.forEach(reward -> reward.giveReward(_player, _rewardData::add));
|
||||
_animation.setRunning(true);
|
||||
UtilServer.RegisterEvents(this);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -135,7 +135,7 @@ public class TreasureSession implements Listener
|
||||
|
||||
if (isDone())
|
||||
{
|
||||
UtilServer.runSyncLater(() -> cleanup(true), 5 * 20);
|
||||
UtilServer.runSyncLater(this::cleanup, 5 * 20);
|
||||
}
|
||||
}
|
||||
|
||||
@ -147,19 +147,15 @@ public class TreasureSession implements Listener
|
||||
return;
|
||||
}
|
||||
|
||||
cleanup(true);
|
||||
cleanup();
|
||||
}
|
||||
|
||||
public void cleanup(boolean cleanLocation)
|
||||
public void cleanup()
|
||||
{
|
||||
UtilServer.Unregister(this);
|
||||
_animation.cleanup();
|
||||
_rewardAnimations.forEach(TreasureRewardAnimation::cleanup);
|
||||
|
||||
if (cleanLocation)
|
||||
{
|
||||
_treasureLocation.cleanup();
|
||||
}
|
||||
_treasureLocation.cleanup();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -235,7 +231,7 @@ public class TreasureSession implements Listener
|
||||
getPlayer().sendMessage(F.main(_treasureLocation.getManager().getName(), rewardData.getHeader() + " : " + rewardData.getFriendlyName()));
|
||||
}
|
||||
|
||||
cleanup(true);
|
||||
cleanup();
|
||||
}
|
||||
|
||||
public Player getPlayer()
|
||||
|
@ -454,8 +454,8 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
|
||||
loadClan(token, false);
|
||||
}
|
||||
_bannerManager.loadBanners(this);
|
||||
|
||||
new PersonalServerManager(plugin, _clientManager).setUseInterfaceItem(false);
|
||||
|
||||
require(PersonalServerManager.class);
|
||||
require(CommunityManager.class);
|
||||
|
||||
Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "Replay|Restrict");
|
||||
|
@ -117,7 +117,6 @@ public class ClansHub extends JavaPlugin
|
||||
|
||||
incognito.setPreferencesManager(preferenceManager);
|
||||
|
||||
preferenceManager.GiveItem = true;
|
||||
Creature creature = new Creature(this);
|
||||
NpcManager npcManager = new NpcManager(this, creature);
|
||||
InventoryManager inventoryManager = new InventoryManager(this, clientManager);
|
||||
|
@ -239,7 +239,7 @@ public class HubManager extends MiniPlugin implements IChatMessageFormatter
|
||||
|
||||
new SalesAnnouncementManager(plugin);
|
||||
|
||||
new PersonalServerManager(plugin, _clientManager).setUseInterfaceItem(false);
|
||||
require(PersonalServerManager.class);
|
||||
require(CommunityManager.class);
|
||||
require(TabListSorter.class);
|
||||
ScoreboardManager scoreboardManager = new ScoreboardManager(plugin)
|
||||
|
@ -26,6 +26,8 @@ import mineplex.core.elo.EloManager;
|
||||
import mineplex.core.energy.Energy;
|
||||
import mineplex.core.friend.FriendManager;
|
||||
import mineplex.core.gadget.gadgets.particle.king.CastleManager;
|
||||
import mineplex.core.game.MineplexGameManager;
|
||||
import mineplex.core.game.kit.GameKit;
|
||||
import mineplex.core.give.Give;
|
||||
import mineplex.core.hologram.HologramManager;
|
||||
import mineplex.core.ignore.IgnoreManager;
|
||||
@ -65,8 +67,6 @@ import mineplex.core.updater.Updater;
|
||||
import mineplex.core.velocity.VelocityFix;
|
||||
import mineplex.core.visibility.VisibilityManager;
|
||||
import mineplex.core.website.WebsiteLinkManager;
|
||||
import mineplex.hub.brawlfountain.FountainManager;
|
||||
import mineplex.hub.queue.QueueManager;
|
||||
import mineplex.hub.server.ServerManager;
|
||||
import mineplex.minecraft.game.classcombat.Class.ClassManager;
|
||||
import mineplex.minecraft.game.classcombat.Condition.SkillConditionManager;
|
||||
@ -121,12 +121,11 @@ public class Hub extends JavaPlugin implements IRelation
|
||||
|
||||
HologramManager hologramManager = require(HologramManager.class);
|
||||
|
||||
preferenceManager.GiveItem = true;
|
||||
Creature creature = new Creature(this);
|
||||
creature.SetDisableCustomDrops(true);
|
||||
NpcManager npcManager = new NpcManager(this, creature);
|
||||
InventoryManager inventoryManager = new InventoryManager(this, clientManager);
|
||||
CastleManager castleManager = new CastleManager(this, clientManager, hologramManager, true);
|
||||
CastleManager castleManager = new CastleManager(this, clientManager, hologramManager, false);
|
||||
PetManager petManager = new PetManager(this, clientManager, donationManager, inventoryManager, disguiseManager, creature, blockRestore);
|
||||
PollManager pollManager = new PollManager(this, clientManager, donationManager);
|
||||
|
||||
@ -148,15 +147,14 @@ public class Hub extends JavaPlugin implements IRelation
|
||||
|
||||
SkillConditionManager conditionManager = new SkillConditionManager(this);
|
||||
|
||||
new PersonalServerManager(this, clientManager);
|
||||
String boosterGroup = serverConfiguration.getServerGroup().getBoosterGroup();
|
||||
ThankManager thankManager = new ThankManager(this, clientManager, donationManager);
|
||||
BoosterManager boosterManager = new BoosterManager(this, boosterGroup, clientManager, donationManager, inventoryManager, thankManager);
|
||||
HubManager hubManager = new HubManager(clientManager, donationManager, inventoryManager, disguiseManager, portal, partyManager, preferenceManager, petManager, pollManager, statsManager, achievementManager, hologramManager, npcManager, punish, thankManager, boosterManager);
|
||||
|
||||
QueueManager queueManager = new QueueManager(this, clientManager, donationManager, eloManager, partyManager);
|
||||
new ServerManager(this, clientManager, donationManager, portal, partyManager, serverStatusManager, hubManager, queueManager, boosterManager);
|
||||
require(FountainManager.class);
|
||||
require(ServerManager.class);
|
||||
|
||||
require(MineplexGameManager.class);
|
||||
|
||||
Chat chat = new Chat(this, incognito, clientManager, preferenceManager, achievementManager, serverStatusManager.getCurrentServerName());
|
||||
new MessageManager(this, incognito, clientManager, preferenceManager, ignoreManager, punish, friendManager, chat);
|
||||
@ -184,14 +182,16 @@ public class Hub extends JavaPlugin implements IRelation
|
||||
ItemFactory itemFactory = new ItemFactory(this, blockRestore, conditionManager, damage, energy, fire, throwManager);
|
||||
SkillFactory skillManager = new SkillFactory(this, damage, this, combatManager, conditionManager, throwManager, disguiseManager, blockRestore, fire, new Movement(this), teleport, energy);
|
||||
ClassManager classManager = new ClassManager(this, clientManager, donationManager, hubManager.GetGadget(), skillManager, itemFactory);
|
||||
itemFactory.deregisterSelf();
|
||||
skillManager.deregisterSelf();
|
||||
|
||||
ClassShopManager shopManager = new ClassShopManager(this, classManager, skillManager, itemFactory, achievementManager, clientManager);
|
||||
|
||||
new ClassCombatShop(shopManager, clientManager, donationManager, false, "Brute", classManager.GetClass("Brute"), true);
|
||||
new ClassCombatShop(shopManager, clientManager, donationManager, false, "Mage", classManager.GetClass("Mage"), true);
|
||||
new ClassCombatShop(shopManager, clientManager, donationManager, false, "Ranger", classManager.GetClass("Ranger"), true);
|
||||
new ClassCombatShop(shopManager, clientManager, donationManager, false, "Knight", classManager.GetClass("Knight"), true);
|
||||
new ClassCombatShop(shopManager, clientManager, donationManager, false, "Assassin", classManager.GetClass("Assassin"), true);
|
||||
new ClassCombatShop(shopManager, clientManager, donationManager, false, "Brute", GameKit.CHAMPIONS_BRUTE, classManager.GetClass("Brute"), true);
|
||||
new ClassCombatShop(shopManager, clientManager, donationManager, false, "Mage", GameKit.CHAMPIONS_MAGE, classManager.GetClass("Mage"), true);
|
||||
new ClassCombatShop(shopManager, clientManager, donationManager, false, "Ranger",GameKit.CHAMPIONS_ARCHER, classManager.GetClass("Ranger"), true);
|
||||
new ClassCombatShop(shopManager, clientManager, donationManager, false, "Knight", GameKit.CHAMPIONS_KNIGHT, classManager.GetClass("Knight"), true);
|
||||
new ClassCombatShop(shopManager, clientManager, donationManager, false, "Assassin", GameKit.CHAMPIONS_ASSASSIN, classManager.GetClass("Assassin"), true);
|
||||
|
||||
//Velocity Fix
|
||||
new VelocityFix(this);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package mineplex.hub;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
@ -83,7 +84,6 @@ import mineplex.core.quests.QuestManager;
|
||||
import mineplex.core.scoreboard.ScoreboardManager;
|
||||
import mineplex.core.scoreboard.TabListSorter;
|
||||
import mineplex.core.stats.StatsManager;
|
||||
import mineplex.core.task.TaskManager;
|
||||
import mineplex.core.thank.ThankManager;
|
||||
import mineplex.core.treasure.TreasureManager;
|
||||
import mineplex.core.twofactor.TwoFactorAuth;
|
||||
@ -93,18 +93,21 @@ import mineplex.core.youtube.YoutubeManager;
|
||||
import mineplex.hub.commands.GadgetToggle;
|
||||
import mineplex.hub.doublejump.JumpManager;
|
||||
import mineplex.hub.gimmicks.AdminPunch;
|
||||
import mineplex.hub.gimmicks.SecretAreas;
|
||||
import mineplex.hub.gimmicks.staffbuild.StaffBuild;
|
||||
import mineplex.hub.hubgame.HubGameManager;
|
||||
import mineplex.hub.kit.HubKitManager;
|
||||
import mineplex.hub.modules.ForcefieldManager;
|
||||
import mineplex.hub.modules.HubVisibilityManager;
|
||||
import mineplex.hub.modules.ParkourManager;
|
||||
import mineplex.hub.modules.SoccerManager;
|
||||
import mineplex.hub.modules.TemporaryGemHuntersServerSender;
|
||||
import mineplex.hub.modules.salesannouncements.SalesAnnouncementManager;
|
||||
import mineplex.hub.news.NewsManager;
|
||||
import mineplex.hub.parkour.ParkourManager;
|
||||
import mineplex.hub.player.CreativeManager;
|
||||
import mineplex.hub.player.HubPlayerManager;
|
||||
import mineplex.hub.plugin.HubPlugin;
|
||||
import mineplex.hub.scoreboard.HubScoreboard;
|
||||
import mineplex.hub.treasurehunt.TreasureHuntManager;
|
||||
import mineplex.hub.world.HubPortalManager;
|
||||
import mineplex.hub.world.HubWorldManager;
|
||||
import mineplex.hub.world.WorldDataModule;
|
||||
import mineplex.minecraft.game.core.combat.DeathMessageType;
|
||||
@ -136,11 +139,14 @@ public class HubManager extends MiniClientPlugin<HubClient> implements IChatMess
|
||||
private final PetManager _petManager;
|
||||
private final JumpManager _jumpManager;
|
||||
private final HologramManager _hologramManager;
|
||||
private final ParkourManager _parkourManager;
|
||||
private final HubGameManager _hubGameManager;
|
||||
|
||||
private final HubPlugin _hubPlugin;
|
||||
|
||||
private final WorldDataModule _worldData;
|
||||
private final Location _spawn;
|
||||
private final List<Location> _lookAt;
|
||||
|
||||
private boolean _shuttingDown;
|
||||
|
||||
@ -156,24 +162,16 @@ public class HubManager extends MiniClientPlugin<HubClient> implements IChatMess
|
||||
|
||||
_worldData = require(WorldDataModule.class);
|
||||
_spawn = _worldData.getCustomLocation("SPAWN").get(0);
|
||||
_lookAt = _worldData.getCustomLocation("LOOK_AT");
|
||||
|
||||
// Disable item merging
|
||||
WorldServer nmsWorld = ((CraftWorld) _spawn.getWorld()).getHandle();
|
||||
nmsWorld.spigotConfig.itemMerge = 0;
|
||||
|
||||
// Disable chunk generation
|
||||
nmsWorld.generator = new VoidGenerator();
|
||||
|
||||
// Disable saving, enable chunk unloading
|
||||
nmsWorld.spigotConfig.saveWorld = false;
|
||||
nmsWorld.spigotConfig.unloadChunks = true;
|
||||
|
||||
new ParkourManager(this, donationManager, new TaskManager(_plugin, clientManager));
|
||||
_jumpManager = new JumpManager(this);
|
||||
|
||||
require(NewsManager.class);
|
||||
require(CreativeManager.class);
|
||||
require(HubWorldManager.class);
|
||||
require(HubKitManager.class);
|
||||
|
||||
new BenefitManager(_plugin, clientManager, inventoryManager);
|
||||
_gadgetManager = require(GadgetManager.class);
|
||||
@ -193,7 +191,7 @@ public class HubManager extends MiniClientPlugin<HubClient> implements IChatMess
|
||||
|
||||
//new MavericksManager(_plugin, cosmeticManager, hologramManager, this);
|
||||
|
||||
new SoccerManager(this, _gadgetManager);
|
||||
//new SoccerManager(this, _gadgetManager);
|
||||
|
||||
new MenuManager(_plugin);
|
||||
new NewInteractionsManager();
|
||||
@ -203,7 +201,7 @@ public class HubManager extends MiniClientPlugin<HubClient> implements IChatMess
|
||||
_petManager = petManager;
|
||||
_partyManager = partyManager;
|
||||
_preferences = preferences;
|
||||
_visibilityManager = new HubVisibilityManager(this);
|
||||
_visibilityManager = require(HubVisibilityManager.class);
|
||||
|
||||
new ForcefieldManager(this);
|
||||
|
||||
@ -226,22 +224,33 @@ public class HubManager extends MiniClientPlugin<HubClient> implements IChatMess
|
||||
|
||||
new QuestManager(hologramManager, null, inventoryManager, _donationManager);
|
||||
|
||||
new TemporaryGemHuntersServerSender(_portal);
|
||||
//new TemporaryGemHuntersServerSender(_portal);
|
||||
|
||||
require(TabListSorter.class);
|
||||
|
||||
Managers.put(new HubScoreboard(_plugin, this), ScoreboardManager.class);
|
||||
|
||||
require(TwoFactorAuth.class);
|
||||
require(HubGameManager.class);
|
||||
//require(ProfileManager.class);
|
||||
_hubGameManager = require(HubGameManager.class);
|
||||
require(HubPlayerManager.class);
|
||||
require(AdminPunch.class);
|
||||
//require(StaffBuild.class);
|
||||
//require(HubPortalManager.class);
|
||||
require(StaffBuild.class);
|
||||
require(SecretAreas.class);
|
||||
require(HubPortalManager.class);
|
||||
require(TreasureHuntManager.class);
|
||||
|
||||
_parkourManager = require(ParkourManager.class);
|
||||
_jumpManager = new JumpManager(this);
|
||||
|
||||
_hubPlugin = new HubPlugin();
|
||||
|
||||
// Disable chunk generation
|
||||
nmsWorld.generator = new VoidGenerator();
|
||||
|
||||
// Disable saving, enable chunk unloading
|
||||
//nmsWorld.spigotConfig.saveWorld = false;
|
||||
nmsWorld.spigotConfig.unloadChunks = true;
|
||||
|
||||
// Unload chunks every 60 seconds
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@ -372,7 +381,7 @@ public class HubManager extends MiniClientPlugin<HubClient> implements IChatMess
|
||||
public void playerPrivateMessage(PrivateMessageEvent event)
|
||||
{
|
||||
//Dont Let PM Near Spawn!
|
||||
if (UtilMath.offset2d(GetSpawn(), event.getSender().getLocation()) == 0 && _clientManager.Get(event.getSender()).hasPermission(Perm.SPAWN_PM))
|
||||
if (UtilMath.offset2dSquared(GetSpawn(), event.getSender().getLocation()) == 0 && _clientManager.Get(event.getSender()).hasPermission(Perm.SPAWN_PM))
|
||||
{
|
||||
UtilPlayer.message(event.getSender(), F.main("Chat", "You must leave spawn before you can Private Message!"));
|
||||
event.setCancelled(true);
|
||||
@ -395,7 +404,7 @@ public class HubManager extends MiniClientPlugin<HubClient> implements IChatMess
|
||||
return;
|
||||
|
||||
//Dont Let Chat Near Spawn!
|
||||
if (UtilMath.offset2d(GetSpawn(), event.getPlayer().getLocation()) == 0 && !_clientManager.Get(event.getPlayer()).hasPermission(Perm.SPAWN_PM))
|
||||
if (UtilMath.offset2dSquared(GetSpawn(), event.getPlayer().getLocation()) == 0 && !_clientManager.Get(event.getPlayer()).hasPermission(Perm.SPAWN_PM))
|
||||
{
|
||||
UtilPlayer.message(event.getPlayer(), F.main("Chat", "You must leave spawn before you can chat!"));
|
||||
event.setCancelled(true);
|
||||
@ -550,7 +559,17 @@ public class HubManager extends MiniClientPlugin<HubClient> implements IChatMess
|
||||
return _jumpManager;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public ParkourManager getParkourManager()
|
||||
{
|
||||
return _parkourManager;
|
||||
}
|
||||
|
||||
public HubGameManager getHubGameManager()
|
||||
{
|
||||
return _hubGameManager;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void ignoreVelocity(PlayerVelocityEvent event)
|
||||
{
|
||||
if (_clientManager.Get(event.getPlayer()).hasPermission(Preference.IGNORE_VELOCITY) && _preferences.get(event.getPlayer()).isActive(Preference.IGNORE_VELOCITY) && !getJumpManager().isDoubleJumping(event.getPlayer()))
|
||||
@ -594,6 +613,11 @@ public class HubManager extends MiniClientPlugin<HubClient> implements IChatMess
|
||||
}
|
||||
}
|
||||
|
||||
public List<Location> getLookAt()
|
||||
{
|
||||
return _lookAt;
|
||||
}
|
||||
|
||||
public boolean isNearSpawn(Location location)
|
||||
{
|
||||
return UtilMath.offsetSquared(GetSpawn(), location) < 100;
|
||||
|
@ -1,73 +0,0 @@
|
||||
package mineplex.hub.brawlfountain;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.newnpc.NPC;
|
||||
import mineplex.core.newnpc.NewNPCManager;
|
||||
import mineplex.core.newnpc.event.NPCInteractEvent;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.hub.server.ServerManager;
|
||||
|
||||
@ReflectivelyCreateMiniPlugin
|
||||
public class FountainManager extends MiniPlugin
|
||||
{
|
||||
|
||||
private final ServerManager _serverManager;
|
||||
private NPC _npc;
|
||||
private boolean _brawlActive = false;
|
||||
|
||||
public FountainManager()
|
||||
{
|
||||
super("Brawl");
|
||||
|
||||
_serverManager = require(ServerManager.class);
|
||||
require(NewNPCManager.class).spawnNPCs("BRAWL", npc -> _npc = npc);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void updateFountainCount(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.SLOW)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
updateBrawlActive();
|
||||
}
|
||||
|
||||
private void updateBrawlActive()
|
||||
{
|
||||
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("PST"));
|
||||
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
|
||||
_brawlActive = dayOfWeek == Calendar.FRIDAY || dayOfWeek == Calendar.SATURDAY || dayOfWeek == Calendar.SUNDAY;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void npcInteract(NPCInteractEvent event)
|
||||
{
|
||||
if (!event.getNpc().equals(_npc))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (_brawlActive)
|
||||
{
|
||||
_serverManager.getBrawlShop().attemptShopOpen(player);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.sendMessage(F.main(_moduleName, "Come back this weekend to play Weekend Brawl!"));
|
||||
}
|
||||
}
|
||||
}
|
@ -5,8 +5,14 @@ import java.util.Set;
|
||||
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerToggleFlightEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
@ -20,6 +26,7 @@ import mineplex.core.disguise.disguises.DisguiseBat;
|
||||
import mineplex.core.disguise.disguises.DisguiseChicken;
|
||||
import mineplex.core.disguise.disguises.DisguiseEnderman;
|
||||
import mineplex.core.disguise.disguises.DisguiseWither;
|
||||
import mineplex.core.gadget.event.GadgetBlockEvent;
|
||||
import mineplex.core.preferences.Preference;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
@ -29,8 +36,8 @@ import mineplex.hub.HubManager;
|
||||
public class JumpManager extends MiniPlugin
|
||||
{
|
||||
|
||||
public HubManager Manager;
|
||||
private Set<String> _preparedDoubleJump = new HashSet<>();
|
||||
public final HubManager Manager;
|
||||
private final Set<String> _preparedDoubleJump = new HashSet<>();
|
||||
|
||||
public JumpManager(HubManager manager)
|
||||
{
|
||||
@ -89,7 +96,7 @@ public class JumpManager extends MiniPlugin
|
||||
|
||||
for (Player player : UtilServer.getPlayersCollection())
|
||||
{
|
||||
if (player.getGameMode() == GameMode.CREATIVE)
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getAllowFlight())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -127,6 +134,28 @@ public class JumpManager extends MiniPlugin
|
||||
_preparedDoubleJump.remove(event.getPlayer().getName());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void jumpPad(PlayerMoveEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getTo().getBlock();
|
||||
|
||||
if (block.getType() == Material.GOLD_PLATE && Recharge.Instance.use(player, "Jump Pad", 500, false, false))
|
||||
{
|
||||
Location location = player.getLocation();
|
||||
Vector direction = location.getDirection().multiply(4);
|
||||
direction.setY(1.2);
|
||||
player.getWorld().playSound(location, Sound.CHICKEN_EGG_POP, 2, 0.5F);
|
||||
UtilAction.velocity(player, direction);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void gadgetBlock(GadgetBlockEvent event)
|
||||
{
|
||||
event.getBlocks().removeIf(block -> block.getRelative(BlockFace.DOWN).getType() == Material.GOLD_PLATE);
|
||||
}
|
||||
|
||||
public boolean hasDoubleJumped(Player player)
|
||||
{
|
||||
return _preparedDoubleJump.contains(player.getName());
|
||||
|
257
Plugins/Mineplex.Hub/src/mineplex/hub/gimmicks/SecretAreas.java
Normal file
257
Plugins/Mineplex.Hub/src/mineplex/hub/gimmicks/SecretAreas.java
Normal file
@ -0,0 +1,257 @@
|
||||
package mineplex.hub.gimmicks;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||
import mineplex.core.blockrestore.BlockRestore;
|
||||
import mineplex.core.common.util.UtilAction;
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.core.common.util.UtilEvent;
|
||||
import mineplex.core.common.util.UtilEvent.ActionType;
|
||||
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.UtilTime;
|
||||
import mineplex.core.noteblock.NBSReader;
|
||||
import mineplex.core.noteblock.NotePlayer;
|
||||
import mineplex.core.noteblock.NoteSong;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.hub.world.WorldDataModule;
|
||||
|
||||
@ReflectivelyCreateMiniPlugin
|
||||
public class SecretAreas extends MiniPlugin
|
||||
{
|
||||
|
||||
private static final String TANK_FILE = ".." + File.separator + ".." + File.separator + "update" + File.separator + "songs" + File.separator + "bebop.nbs";
|
||||
private static final long TANK_LENGTH = TimeUnit.MINUTES.toMillis(2);
|
||||
|
||||
private final BlockRestore _restore;
|
||||
|
||||
private final Block _konamiLocation;
|
||||
private int _konamiCode;
|
||||
private final Block _tankLocation;
|
||||
private NoteSong _tankSong;
|
||||
private long _lastTank;
|
||||
private final Location _cannonBall;
|
||||
private final List<Location> _cannons;
|
||||
|
||||
private SecretAreas()
|
||||
{
|
||||
super("Secret Areas");
|
||||
|
||||
_restore = require(BlockRestore.class);
|
||||
|
||||
WorldDataModule worldData = require(WorldDataModule.class);
|
||||
_konamiLocation = worldData.getCustomLocation("KONAMI").get(0).getBlock();
|
||||
_tankLocation = worldData.getCustomLocation("TANK").get(0).getBlock().getRelative(BlockFace.DOWN);
|
||||
|
||||
try
|
||||
{
|
||||
_tankSong = NBSReader.loadSong(TANK_FILE);
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
}
|
||||
|
||||
_cannonBall = worldData.getCustomLocation("CANNON BALL").get(0);
|
||||
_cannons = worldData.getCustomLocation("CANNON");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void secretDoorInteract(PlayerInteractEvent event)
|
||||
{
|
||||
if (!UtilEvent.isAction(event, ActionType.R_BLOCK))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
Block clicked = event.getClickedBlock();
|
||||
Block upBlock = _konamiLocation.getRelative(BlockFace.EAST);
|
||||
boolean up = upBlock.equals(clicked);
|
||||
boolean down = upBlock.getRelative(BlockFace.EAST).equals(clicked);
|
||||
boolean left = upBlock.getRelative(BlockFace.SOUTH).equals(clicked);
|
||||
boolean right = upBlock.getRelative(BlockFace.NORTH).equals(clicked);
|
||||
|
||||
if (!up && !down && !left && !right)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (up)
|
||||
{
|
||||
if (_konamiCode <= 1)
|
||||
{
|
||||
_konamiCode++;
|
||||
}
|
||||
else
|
||||
{
|
||||
_konamiCode = 0;
|
||||
}
|
||||
}
|
||||
else if (down)
|
||||
{
|
||||
if (_konamiCode == 2 || _konamiCode == 3)
|
||||
{
|
||||
_konamiCode++;
|
||||
}
|
||||
else
|
||||
{
|
||||
_konamiCode = 0;
|
||||
}
|
||||
}
|
||||
else if (left)
|
||||
{
|
||||
if (_konamiCode == 4 || _konamiCode == 6)
|
||||
{
|
||||
_konamiCode++;
|
||||
}
|
||||
else
|
||||
{
|
||||
_konamiCode = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_konamiCode == 5)
|
||||
{
|
||||
_konamiCode++;
|
||||
}
|
||||
else if (_konamiCode == 7)
|
||||
{
|
||||
_restore.add(_konamiLocation.getRelative(BlockFace.DOWN), 0, (byte) 0, 4000);
|
||||
playZeldaSound(player);
|
||||
_konamiCode = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_konamiCode = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void tankInteract(PlayerInteractEvent event)
|
||||
{
|
||||
if (!UtilEvent.isAction(event, ActionType.R_BLOCK) || _tankSong == null || !UtilTime.elapsed(_lastTank, TANK_LENGTH))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Block clicked = event.getClickedBlock();
|
||||
|
||||
if (clicked.equals(_tankLocation))
|
||||
{
|
||||
Location location = clicked.getLocation();
|
||||
|
||||
UtilParticle.PlayParticleToAll(ParticleType.NOTE, location, 1, 1, 1, 0, 10, ViewDist.NORMAL);
|
||||
new NotePlayer(_plugin, _tankSong, other -> UtilMath.offsetSquared(other.getLocation(), location) < 120, 1, false);
|
||||
_lastTank = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void updateCannon(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.FAST)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (Player player : UtilPlayer.getNearby(_cannonBall, 3))
|
||||
{
|
||||
player.teleport(UtilAlg.Random(_cannons));
|
||||
runSyncTimer(new BukkitRunnable()
|
||||
{
|
||||
int iterations = 0;
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
applyCannonVelocity(player);
|
||||
|
||||
if (++iterations == 3 || !player.isOnline())
|
||||
{
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
}, 0, 20);
|
||||
}
|
||||
}
|
||||
|
||||
private void applyCannonVelocity(Player player)
|
||||
{
|
||||
Location location = player.getLocation();
|
||||
player.getWorld().playSound(location, Sound.EXPLODE, 2, 1);
|
||||
UtilParticle.PlayParticleToAll(ParticleType.HUGE_EXPLOSION, location, 0, 0, 0, 0, 3, ViewDist.NORMAL);
|
||||
UtilAction.velocity(player, new Vector(0, 4, 8));
|
||||
}
|
||||
|
||||
private void playZeldaSound(Player player)
|
||||
{
|
||||
player.getWorld().playSound(player.getLocation(), Sound.PISTON_RETRACT, 1, 0.9F);
|
||||
|
||||
runSyncTimer(new BukkitRunnable()
|
||||
{
|
||||
int note = 0;
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
float pitch = 0;
|
||||
|
||||
switch (note)
|
||||
{
|
||||
case 0:
|
||||
pitch = 1.059F;
|
||||
break;
|
||||
case 1:
|
||||
pitch = 1;
|
||||
break;
|
||||
case 2:
|
||||
pitch = 0.840F;
|
||||
break;
|
||||
case 3:
|
||||
pitch = 0.594F;
|
||||
break;
|
||||
case 4:
|
||||
pitch = 0.561F;
|
||||
break;
|
||||
case 5:
|
||||
pitch = 0.890F;
|
||||
break;
|
||||
case 6:
|
||||
pitch = 1.12F;
|
||||
break;
|
||||
case 7:
|
||||
pitch = 1.414F;
|
||||
break;
|
||||
}
|
||||
|
||||
player.getWorld().playSound(player.getLocation(), Sound.NOTE_PIANO, 1, pitch);
|
||||
|
||||
if (++note == 8)
|
||||
{
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
}, 2, 4);
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package mineplex.hub.gimmicks.staffbuild;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.command.CommandBase;
|
||||
import mineplex.core.common.jsonchat.ClickEvent;
|
||||
import mineplex.core.common.jsonchat.HoverEvent;
|
||||
import mineplex.core.common.jsonchat.JsonMessage;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.hub.gimmicks.staffbuild.StaffBuild.Perm;
|
||||
|
||||
public class BuildHistoryCommand extends CommandBase<StaffBuild>
|
||||
{
|
||||
|
||||
BuildHistoryCommand(StaffBuild plugin)
|
||||
{
|
||||
super(plugin, Perm.BUILD_HISTORY, "buildhistory");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Execute(Player caller, String[] args)
|
||||
{
|
||||
Map<Block, String> buildHistory = Plugin.getBuildHistory();
|
||||
|
||||
if (args.length < 1)
|
||||
{
|
||||
caller.sendMessage(F.main(Plugin.getName(), "Build History:"));
|
||||
|
||||
buildHistory.values().stream()
|
||||
.distinct()
|
||||
.forEach(playerName ->
|
||||
{
|
||||
new JsonMessage(C.cYellowB + "[VIEW] " + F.name(playerName))
|
||||
.hover(HoverEvent.SHOW_TEXT, C.cGray + "Click to show all blocks placed by " + F.name(playerName) + ".")
|
||||
.click(ClickEvent.RUN_COMMAND, "/" + _aliasUsed + " " + playerName)
|
||||
.sendToPlayer(caller);
|
||||
});
|
||||
|
||||
new JsonMessage(C.cGreenB + "[RESET]")
|
||||
.hover(HoverEvent.SHOW_TEXT, C.cGray + "Resets your view of the staff build area.")
|
||||
.click(ClickEvent.RUN_COMMAND, "/" + _aliasUsed + " reset")
|
||||
.sendToPlayer(caller);
|
||||
}
|
||||
else
|
||||
{
|
||||
String playerToCheck = args[0];
|
||||
|
||||
if (playerToCheck.equals("reset"))
|
||||
{
|
||||
buildHistory.forEach((block, playerName) -> caller.sendBlockChange(block.getLocation(), block.getType(), block.getData()));
|
||||
caller.sendMessage(F.main(Plugin.getName(), "Reset your view of the staff build area."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!buildHistory.containsValue(playerToCheck))
|
||||
{
|
||||
caller.sendMessage(F.main(Plugin.getName(), F.name(playerToCheck) + " has never placed any blocks in the staff build area."));
|
||||
return;
|
||||
}
|
||||
|
||||
buildHistory.forEach((block, playerName) ->
|
||||
{
|
||||
if (playerToCheck.equals(playerName))
|
||||
{
|
||||
caller.sendBlockChange(block.getLocation(), block.getType(), block.getData());
|
||||
}
|
||||
else
|
||||
{
|
||||
caller.sendBlockChange(block.getLocation(), Material.AIR, (byte) 0);
|
||||
}
|
||||
});
|
||||
|
||||
caller.sendMessage(F.main(Plugin.getName(), "Viewing all blocks placed by " + F.name(playerToCheck) + "."));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package mineplex.hub.gimmicks.staffbuild;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.command.CommandBase;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.MapUtil;
|
||||
import mineplex.hub.gimmicks.staffbuild.StaffBuild.Perm;
|
||||
|
||||
public class ClearBuildCommand extends CommandBase<StaffBuild>
|
||||
{
|
||||
|
||||
ClearBuildCommand(StaffBuild plugin)
|
||||
{
|
||||
super(plugin, Perm.CLEAR_BUILD, "clearbuild");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Execute(Player caller, String[] args)
|
||||
{
|
||||
Plugin.getBuildHistory().keySet().forEach(block -> MapUtil.QuickChangeBlockAt(block.getLocation(), Material.AIR));
|
||||
Plugin.getBuildHistory().clear();
|
||||
caller.sendMessage(F.main(Plugin.getName(), "Cleared the staff build area."));
|
||||
}
|
||||
}
|
@ -1,14 +1,22 @@
|
||||
package mineplex.hub.gimmicks;
|
||||
package mineplex.hub.gimmicks.staffbuild;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.hanging.HangingPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||
@ -16,6 +24,9 @@ import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.account.permissions.Permission;
|
||||
import mineplex.core.account.permissions.PermissionGroup;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilItem;
|
||||
import mineplex.core.common.util.UtilItem.ItemCategory;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
@ -29,7 +40,9 @@ public class StaffBuild extends MiniPlugin
|
||||
|
||||
public enum Perm implements Permission
|
||||
{
|
||||
BUILD
|
||||
BUILD,
|
||||
BUILD_HISTORY,
|
||||
CLEAR_BUILD
|
||||
}
|
||||
|
||||
private static final int MAX_Y_DIFFERENCE = 50;
|
||||
@ -38,6 +51,7 @@ public class StaffBuild extends MiniPlugin
|
||||
private final CreativeManager _creativeManager;
|
||||
private final HubPlayerManager _playerManager;
|
||||
private final List<Location> _buildLocations;
|
||||
private final Map<Block, String> _buildHistory;
|
||||
|
||||
private StaffBuild()
|
||||
{
|
||||
@ -48,6 +62,7 @@ public class StaffBuild extends MiniPlugin
|
||||
_playerManager = require(HubPlayerManager.class);
|
||||
_buildLocations = require(WorldDataModule.class).getCustomLocation(String.valueOf(Material.RED_SANDSTONE.getId()));
|
||||
_buildLocations.forEach(location -> location.getBlock().setType(Material.AIR));
|
||||
_buildHistory = new HashMap<>();
|
||||
|
||||
generatePermissions();
|
||||
}
|
||||
@ -55,6 +70,15 @@ public class StaffBuild extends MiniPlugin
|
||||
private void generatePermissions()
|
||||
{
|
||||
PermissionGroup.BUILDER.setPermission(Perm.BUILD, true, true);
|
||||
PermissionGroup.ADMIN.setPermission(Perm.BUILD_HISTORY, true, true);
|
||||
PermissionGroup.ADMIN.setPermission(Perm.CLEAR_BUILD, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCommands()
|
||||
{
|
||||
addCommand(new BuildHistoryCommand(this));
|
||||
addCommand(new ClearBuildCommand(this));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -78,9 +102,18 @@ public class StaffBuild extends MiniPlugin
|
||||
}
|
||||
else if (!allowed && creative)
|
||||
{
|
||||
player.setGameMode(GameMode.ADVENTURE);
|
||||
sendMessage(player, false);
|
||||
_playerManager.giveHotbar(player);
|
||||
runSyncLater(() ->
|
||||
{
|
||||
if (isAllowed(player, player.getLocation()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
player.setGameMode(GameMode.ADVENTURE);
|
||||
sendMessage(player, false);
|
||||
UtilPlayer.clearPotionEffects(player);
|
||||
_playerManager.giveHotbar(player);
|
||||
}, 19);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -93,13 +126,81 @@ public class StaffBuild extends MiniPlugin
|
||||
@EventHandler
|
||||
public void blockBreak(BlockBreakEvent event)
|
||||
{
|
||||
event.setCancelled(!isAllowed(event.getPlayer(), event.getBlock().getLocation()));
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (!_creativeManager.isInCreative(player))
|
||||
{
|
||||
if (isAllowed(player, event.getBlock().getLocation()))
|
||||
{
|
||||
_buildHistory.remove(event.getBlock());
|
||||
}
|
||||
else
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void blockPlace(BlockPlaceEvent event)
|
||||
{
|
||||
event.setCancelled(!isAllowed(event.getPlayer(), event.getBlock().getLocation()));
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (!_creativeManager.isInCreative(player))
|
||||
{
|
||||
if (isAllowed(player, event.getBlock().getLocation()))
|
||||
{
|
||||
_buildHistory.put(event.getBlock(), player.getName());
|
||||
}
|
||||
else
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerDropItem(PlayerDropItemEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (_creativeManager.isInCreative(player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void hangingPlace(HangingPlaceEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (_creativeManager.isInCreative(player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void blockPlace(PlayerInteractEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (_creativeManager.isInCreative(player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack itemStack = player.getItemInHand();
|
||||
|
||||
if (UtilItem.isVehicle(itemStack) || UtilItem.isDoor(itemStack) || itemStack.getType() == Material.ARMOR_STAND)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isAllowed(Player player, Location location)
|
||||
@ -117,7 +218,7 @@ public class StaffBuild extends MiniPlugin
|
||||
{
|
||||
int delta = location.getBlockY() - buildLocation.getBlockY();
|
||||
|
||||
if (location.getBlockX() == buildLocation.getBlockX() && location.getBlockZ() == buildLocation.getBlockZ() && delta >= 0 && delta < MAX_Y_DIFFERENCE)
|
||||
if (location.getBlockX() == buildLocation.getBlockX() && location.getBlockZ() == buildLocation.getBlockZ() && delta >= 0 && delta <= MAX_Y_DIFFERENCE)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -125,4 +226,9 @@ public class StaffBuild extends MiniPlugin
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public Map<Block, String> getBuildHistory()
|
||||
{
|
||||
return _buildHistory;
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -15,18 +16,18 @@ import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilTextMiddle;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.gadget.GadgetManager;
|
||||
import mineplex.core.gadget.types.GadgetType;
|
||||
import mineplex.core.hologram.Hologram;
|
||||
import mineplex.core.hologram.HologramManager;
|
||||
import mineplex.core.newnpc.NPC;
|
||||
import mineplex.core.newnpc.NewNPCManager;
|
||||
import mineplex.core.newnpc.event.NPCInteractEvent;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.hub.HubManager;
|
||||
import mineplex.hub.hubgame.CycledGame.GameState;
|
||||
import mineplex.hub.hubgame.event.HubGamePlayerDeathEvent;
|
||||
import mineplex.hub.hubgame.ui.HubGameShop;
|
||||
@ -50,13 +51,13 @@ public class HubGameManager extends MiniPlugin
|
||||
private final CoreClientManager _clientManager;
|
||||
private final DonationManager _donationManager;
|
||||
private final GadgetManager _gadgetManager;
|
||||
private final HologramManager _hologramManager;
|
||||
private final HubManager _hubManager;
|
||||
private final HubPlayerManager _hotbarManager;
|
||||
private final NewNPCManager _npcManager;
|
||||
private final WorldDataModule _worldData;
|
||||
|
||||
private final HubGameShop _shop;
|
||||
private final List<HubGame> _games;
|
||||
private final Location _teleport;
|
||||
|
||||
private HubGameManager()
|
||||
{
|
||||
@ -65,13 +66,15 @@ public class HubGameManager extends MiniPlugin
|
||||
_clientManager = require(CoreClientManager.class);
|
||||
_donationManager = require(DonationManager.class);
|
||||
_gadgetManager = require(GadgetManager.class);
|
||||
_hologramManager = require(HologramManager.class);
|
||||
_hubManager = require(HubManager.class);
|
||||
_hotbarManager = require(HubPlayerManager.class);
|
||||
_npcManager = require(NewNPCManager.class);
|
||||
_worldData = require(WorldDataModule.class);
|
||||
WorldDataModule worldData = require(WorldDataModule.class);
|
||||
|
||||
_shop = new HubGameShop(this, _clientManager, _donationManager);
|
||||
_games = new ArrayList<>();
|
||||
_teleport = worldData.getCustomLocation("TELEPORT " + _moduleName).get(0);
|
||||
UtilAlg.lookAtNearest(_teleport, _hubManager.getLookAt());
|
||||
|
||||
runSyncLater(this::spawnNPCs, 50);
|
||||
}
|
||||
@ -83,19 +86,7 @@ public class HubGameManager extends MiniPlugin
|
||||
|
||||
private void spawnNPCs()
|
||||
{
|
||||
_games.forEach(game ->
|
||||
{
|
||||
_npcManager.spawnNPCs(game.getGameType().name(), npc ->
|
||||
{
|
||||
game.setNpc(npc);
|
||||
Hologram nameTag = npc.getNameTag();
|
||||
|
||||
nameTag.setText(C.cYellowB + "Click To Play", nameTag.getText()[0]);
|
||||
});
|
||||
|
||||
new Hologram(_hologramManager, _worldData.getCustomLocation(game.getGameType().name() + " INFO").get(0), true, game.getGameType().getDescription())
|
||||
.start();
|
||||
});
|
||||
_games.forEach(game -> _npcManager.spawnNPCs(game.getGameType().name(), game::setNpc));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -413,7 +404,8 @@ public class HubGameManager extends MiniPlugin
|
||||
game.getPlaces().add(player);
|
||||
clearPlayer(player);
|
||||
player.teleport(game.getSpawn());
|
||||
_hotbarManager.giveHotbar(player);
|
||||
|
||||
runSyncLater(() -> _hotbarManager.giveHotbar(player), 20);
|
||||
}
|
||||
|
||||
private void clearPlayer(Player player)
|
||||
@ -426,6 +418,12 @@ public class HubGameManager extends MiniPlugin
|
||||
player.setHealth(player.getMaxHealth());
|
||||
}
|
||||
|
||||
public boolean inQueue(Player player)
|
||||
{
|
||||
return _games.stream()
|
||||
.anyMatch(game -> game instanceof CycledGame && ((CycledGame) game).getQueuedPlayers().contains(player));
|
||||
}
|
||||
|
||||
public String getGameHeader(CycledGame game)
|
||||
{
|
||||
return C.cWhiteB + "Game" + C.cYellow + " - " + C.cWhiteB + getGameName(game);
|
||||
@ -436,6 +434,11 @@ public class HubGameManager extends MiniPlugin
|
||||
return game.getGameType().getName();
|
||||
}
|
||||
|
||||
public HubManager getHubManager()
|
||||
{
|
||||
return _hubManager;
|
||||
}
|
||||
|
||||
public CoreClientManager getClientManager()
|
||||
{
|
||||
return _clientManager;
|
||||
@ -450,4 +453,9 @@ public class HubGameManager extends MiniPlugin
|
||||
{
|
||||
return _shop;
|
||||
}
|
||||
|
||||
public Location getTeleport()
|
||||
{
|
||||
return _teleport;
|
||||
}
|
||||
}
|
||||
|
@ -6,24 +6,20 @@ import org.bukkit.inventory.ItemStack;
|
||||
public enum HubGameType
|
||||
{
|
||||
|
||||
TRON("Tron", new String[]
|
||||
TRON("Slime Cycles", new String[]
|
||||
{
|
||||
"Control your Slime by looking in",
|
||||
"the direction you want to go!",
|
||||
"Avoid other trails and walls.",
|
||||
"Last player standing wins!",
|
||||
}, new ItemStack(Material.SLIME_BALL), 2, 4),
|
||||
DUELS("Duels", new String[]
|
||||
DUELS("Gladiators", new String[]
|
||||
{
|
||||
"A 1v1 duel against another player.",
|
||||
"You do not regenerate health.",
|
||||
"You can place blocks!",
|
||||
"Kill your opponent to win!"
|
||||
}, new ItemStack(Material.DIAMOND_SWORD), 2, 2),
|
||||
FOOTBALL("Soccer", new String[]
|
||||
{
|
||||
|
||||
}, new ItemStack(Material.SLIME_BALL), 1, 6),
|
||||
;
|
||||
|
||||
private final String _name;
|
||||
|
@ -3,11 +3,16 @@ package mineplex.hub.hubgame.common.damage;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.player.PlayerVelocityEvent;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import mineplex.core.Managers;
|
||||
import mineplex.core.common.util.UtilAction;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
import mineplex.core.titles.Titles;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.hub.hubgame.CycledGame.GameState;
|
||||
import mineplex.hub.hubgame.HubGame;
|
||||
import mineplex.hub.hubgame.common.HubGameComponent;
|
||||
@ -47,26 +52,26 @@ public class DamageComponent extends HubGameComponent<HubGame>
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void entityDamage(EntityDamageEvent event)
|
||||
public void entityDamage(CustomDamageEvent event)
|
||||
{
|
||||
uncancelDamageEvent(event);
|
||||
}
|
||||
|
||||
private void uncancelDamageEvent(EntityDamageEvent event)
|
||||
private void uncancelDamageEvent(CustomDamageEvent event)
|
||||
{
|
||||
if (!(event.getEntity() instanceof Player))
|
||||
Player player = event.GetDamageePlayer();
|
||||
|
||||
if (player == null || !_game.isAlive(player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
event.GetCancellers().clear();
|
||||
|
||||
if (!_game.isAlive(player))
|
||||
if (!Recharge.Instance.use(player, "Damage", 400, false, false))
|
||||
{
|
||||
return;
|
||||
event.SetCancelled("Damage Component Rate");
|
||||
}
|
||||
|
||||
event.setCancelled(false);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -97,4 +102,40 @@ public class DamageComponent extends HubGameComponent<HubGame>
|
||||
UtilAction.zeroVelocity(player);
|
||||
_game.onPlayerDeath(player);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void playerVelocity(PlayerVelocityEvent event)
|
||||
{
|
||||
if (_game.isAlive(event.getPlayer()))
|
||||
{
|
||||
event.setCancelled(false);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void convertAbsorption(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.SEC)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (Player player : _game.getAlivePlayers())
|
||||
{
|
||||
if (!player.hasPotionEffect(PotionEffectType.ABSORPTION))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for (PotionEffect effect : player.getActivePotionEffects())
|
||||
{
|
||||
if (effect.getType().toString().equalsIgnoreCase(PotionEffectType.ABSORPTION.toString()))
|
||||
{
|
||||
player.removePotionEffect(PotionEffectType.ABSORPTION);
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles()));
|
||||
player.setHealth(Math.min(player.getHealth() + 4, player.getMaxHealth()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package mineplex.hub.hubgame.common.general;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
|
||||
import mineplex.hub.hubgame.CycledGame;
|
||||
import mineplex.hub.hubgame.CycledGame.GameState;
|
||||
@ -32,7 +33,7 @@ public class PlayerGameModeComponent extends HubGameComponent<CycledGame>
|
||||
_game.getAlivePlayers().forEach(player -> player.setGameMode(_gameMode));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void playerDeath(HubGamePlayerDeathEvent event)
|
||||
{
|
||||
event.getPlayer().setGameMode(GameMode.ADVENTURE);
|
||||
|
@ -11,7 +11,10 @@ import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
||||
import org.bukkit.event.player.PlayerBucketFillEvent;
|
||||
|
||||
import mineplex.core.common.Pair;
|
||||
import mineplex.core.common.util.MapUtil;
|
||||
@ -75,6 +78,20 @@ public class BlockRecorderComponent extends HubGameComponent<CycledGame>
|
||||
event.setCancelled(false);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void blockPhysics(BlockPhysicsEvent event)
|
||||
{
|
||||
Location location = event.getBlock().getLocation();
|
||||
|
||||
if (!UtilAlg.inBoundingBox(location, _cornerA, _cornerB))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_placedBlocks.add(event.getBlock().getLocation());
|
||||
event.setCancelled(false);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void end(HubGameStateChangeEvent event)
|
||||
{
|
||||
|
@ -7,6 +7,8 @@ import org.bukkit.event.EventHandler;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.gadget.event.GadgetBlockEvent;
|
||||
import mineplex.core.gadget.event.GadgetCollideEntityEvent;
|
||||
import mineplex.core.gadget.event.GadgetSelectLocationEvent;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
@ -46,11 +48,26 @@ public class PreventNonAlivePlayersComponent extends HubGameComponent<HubGame>
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void gadgetSelectBlock(GadgetSelectLocationEvent event)
|
||||
public void gadgetLocation(GadgetSelectLocationEvent event)
|
||||
{
|
||||
if (UtilAlg.inBoundingBox(event.getLocation(), _cornerA, _cornerB))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void gadgetBlock(GadgetBlockEvent event)
|
||||
{
|
||||
event.getBlocks().removeIf(block -> UtilAlg.inBoundingBox(block.getLocation(), _cornerA, _cornerB));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void gadgetCollide(GadgetCollideEntityEvent event)
|
||||
{
|
||||
if (event.getEntity() instanceof Player && _game.isAlive((Player) event.getEntity()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,78 +0,0 @@
|
||||
package mineplex.hub.hubgame.common.powerup;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
|
||||
public abstract class ItemPowerup implements Powerup, Listener
|
||||
{
|
||||
|
||||
private final String _name;
|
||||
private final ItemStack _itemStack;
|
||||
|
||||
public ItemPowerup(String name, ItemStack itemStack)
|
||||
{
|
||||
_name = name;
|
||||
_itemStack = new ItemBuilder(itemStack)
|
||||
.setTitle(name + C.cWhite + " - " + C.cYellowB + "Click")
|
||||
.build();
|
||||
|
||||
UtilServer.RegisterEvents(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCollect(Player player)
|
||||
{
|
||||
player.getInventory().addItem(_itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
return _itemStack;
|
||||
}
|
||||
|
||||
public abstract void onInteractItem(Player player);
|
||||
|
||||
@EventHandler
|
||||
public void playerInteract(PlayerInteractEvent event)
|
||||
{
|
||||
if (event.isCancelled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
ItemStack itemStack = player.getItemInHand();
|
||||
|
||||
if (itemStack == null || !itemStack.isSimilar(_itemStack))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
if (itemStack.getAmount() == 1)
|
||||
{
|
||||
player.setItemInHand(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
itemStack.setAmount(itemStack.getAmount() - 1);
|
||||
}
|
||||
|
||||
onInteractItem(player);
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package mineplex.hub.hubgame.common.powerup;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public interface Powerup
|
||||
{
|
||||
|
||||
void onCollect(Player player);
|
||||
|
||||
String getName();
|
||||
|
||||
ItemStack getItemStack();
|
||||
|
||||
}
|
@ -1,112 +0,0 @@
|
||||
package mineplex.hub.hubgame.common.powerup;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
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.UtilTime;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.hub.hubgame.CycledGame;
|
||||
import mineplex.hub.hubgame.common.HubGameComponent;
|
||||
|
||||
public class PowerupComponent extends HubGameComponent<CycledGame>
|
||||
{
|
||||
|
||||
private static final int MAX_POWERUPS = 2;
|
||||
|
||||
private final List<Powerup> _powerups;
|
||||
private final List<SpawnedPowerup> _spawnedPowerups;
|
||||
private final List<Location> _powerupSpawns;
|
||||
|
||||
public PowerupComponent(CycledGame game, List<Location> powerupSpawns)
|
||||
{
|
||||
super(game);
|
||||
|
||||
_powerups = new ArrayList<>();
|
||||
_spawnedPowerups = new ArrayList<>();
|
||||
_powerupSpawns = powerupSpawns;
|
||||
}
|
||||
|
||||
public void addPowerup(Powerup powerup)
|
||||
{
|
||||
_powerups.add(powerup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deactivate()
|
||||
{
|
||||
_spawnedPowerups.forEach(SpawnedPowerup::remove);
|
||||
|
||||
super.deactivate();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void updatePowerupSpawn(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.SEC || !_game.isLive() || !UtilTime.elapsed(_game.getLastStart(), 3000) || _spawnedPowerups.size() == MAX_POWERUPS || Math.random() > 0.1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Location location = UtilAlg.Random(_powerupSpawns);
|
||||
|
||||
// Too close to another powerup
|
||||
for (SpawnedPowerup powerup : _spawnedPowerups)
|
||||
{
|
||||
if (UtilMath.offset2dSquared(location, powerup.getLocation()) < 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Powerup powerup = UtilAlg.Random(_powerups);
|
||||
SpawnedPowerup spawnedPowerup = new SpawnedPowerup(powerup, location);
|
||||
particles(spawnedPowerup);
|
||||
_spawnedPowerups.add(spawnedPowerup);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void updatePowerupCollision(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.FASTEST)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (Player player : _game.getAlivePlayers())
|
||||
{
|
||||
_spawnedPowerups.removeIf(powerup ->
|
||||
{
|
||||
if (powerup.collided(player))
|
||||
{
|
||||
particles(powerup);
|
||||
powerup.getPowerup().onCollect(player);
|
||||
powerup.remove();
|
||||
|
||||
player.playSound(player.getLocation(), Sound.LEVEL_UP, 1, 1);
|
||||
player.sendMessage(F.main(_game.getManager().getName(), "You collected a " + F.name(powerup.getPowerup().getName()) + " Powerup!"));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void particles(SpawnedPowerup powerup)
|
||||
{
|
||||
UtilParticle.PlayParticleToAll(ParticleType.LAVA, powerup.getLocation(), 0.4F, 0.4F, 0.4F, 0.1F, 5, ViewDist.NORMAL);
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
package mineplex.hub.hubgame.common.powerup;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.util.UtilEnt;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
|
||||
public class SpawnedPowerup
|
||||
{
|
||||
|
||||
private final Powerup _powerup;
|
||||
private final ArmorStand _itemHolder;
|
||||
private final ArmorStand _hologram;
|
||||
|
||||
public SpawnedPowerup(Powerup powerup, Location location)
|
||||
{
|
||||
_powerup = powerup;
|
||||
|
||||
_itemHolder = spawnStand(location);
|
||||
_hologram = spawnStand(location.add(0, 0.2, 0));
|
||||
_hologram.setCustomName(powerup.getName());
|
||||
_hologram.setCustomNameVisible(true);
|
||||
|
||||
Item item = location.getWorld().dropItem(location, powerup.getItemStack());
|
||||
item.setPickupDelay(Integer.MAX_VALUE);
|
||||
_itemHolder.setPassenger(item);
|
||||
}
|
||||
|
||||
public Powerup getPowerup()
|
||||
{
|
||||
return _powerup;
|
||||
}
|
||||
|
||||
public Location getLocation()
|
||||
{
|
||||
return _itemHolder.getLocation().add(0, 2, 0);
|
||||
}
|
||||
|
||||
public boolean collided(Player player)
|
||||
{
|
||||
return UtilMath.offset2dSquared(player, _itemHolder) < 4;
|
||||
}
|
||||
|
||||
public void remove()
|
||||
{
|
||||
if (_itemHolder.getPassenger() != null)
|
||||
{
|
||||
_itemHolder.getPassenger().remove();
|
||||
}
|
||||
|
||||
_itemHolder.remove();
|
||||
_hologram.remove();
|
||||
}
|
||||
|
||||
private ArmorStand spawnStand(Location location)
|
||||
{
|
||||
ArmorStand stand = location.getWorld().spawn(location, ArmorStand.class);
|
||||
|
||||
UtilEnt.vegetate(stand);
|
||||
UtilEnt.ghost(stand, true, false);
|
||||
|
||||
stand.setVisible(false);
|
||||
stand.setGravity(false);
|
||||
|
||||
return stand;
|
||||
}
|
||||
}
|
@ -1,114 +0,0 @@
|
||||
package mineplex.hub.hubgame.common.powerup;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.common.util.UtilTextBottom;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
|
||||
public class TimedPowerup implements Powerup, Listener
|
||||
{
|
||||
|
||||
private final String _name;
|
||||
private final ItemStack _itemStack;
|
||||
private final long _length;
|
||||
|
||||
private final Set<TimedData> _data;
|
||||
|
||||
public TimedPowerup(String name, ItemStack itemStack, long length)
|
||||
{
|
||||
_name = name;
|
||||
_itemStack = itemStack;
|
||||
_length = length;
|
||||
_data = new HashSet<>();
|
||||
|
||||
UtilServer.RegisterEvents(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCollect(Player player)
|
||||
{
|
||||
_data.add(new TimedData(player, _length));
|
||||
onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
return _itemStack;
|
||||
}
|
||||
|
||||
public void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
public void onEnd()
|
||||
{
|
||||
}
|
||||
|
||||
public boolean isActive(Player player)
|
||||
{
|
||||
for (TimedData data : _data)
|
||||
{
|
||||
if (data.Player.equals(player))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void update(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.TICK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_data.removeIf(data ->
|
||||
{
|
||||
if (UtilTime.elapsed(data.Start, data.Length))
|
||||
{
|
||||
onEnd();
|
||||
return true;
|
||||
}
|
||||
|
||||
long timeLeft = data.Start + data.Length - System.currentTimeMillis();
|
||||
double percentage = (System.currentTimeMillis() - data.Start) / (double) data.Length;
|
||||
|
||||
UtilTextBottom.displayProgress(getName(), percentage, UtilTime.MakeStr(timeLeft), data.Player);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
private class TimedData
|
||||
{
|
||||
|
||||
Player Player;
|
||||
long Start;
|
||||
long Length;
|
||||
|
||||
TimedData(Player player, long length)
|
||||
{
|
||||
Player = player;
|
||||
Start = System.currentTimeMillis();
|
||||
Length = length;
|
||||
}
|
||||
}
|
||||
}
|
@ -19,7 +19,6 @@ import mineplex.hub.hubgame.CycledGame;
|
||||
import mineplex.hub.hubgame.HubGameManager;
|
||||
import mineplex.hub.hubgame.HubGameType;
|
||||
import mineplex.hub.hubgame.common.damage.DamageComponent;
|
||||
import mineplex.hub.hubgame.common.damage.PVPTrackerComponent;
|
||||
import mineplex.hub.hubgame.common.general.DoubleJumpComponent;
|
||||
import mineplex.hub.hubgame.common.general.GameDescriptionComponent;
|
||||
import mineplex.hub.hubgame.common.general.GameTimeoutComponent;
|
||||
@ -30,7 +29,6 @@ import mineplex.hub.hubgame.common.general.SingleWinnerComponent;
|
||||
import mineplex.hub.hubgame.common.map.BlockRecorderComponent;
|
||||
import mineplex.hub.hubgame.common.map.PreventNonAlivePlayersComponent;
|
||||
import mineplex.hub.hubgame.common.map.TeleportIntoMapComponent;
|
||||
import mineplex.hub.hubgame.ui.HubGamePage;
|
||||
|
||||
public class Duels extends CycledGame
|
||||
{
|
||||
@ -52,12 +50,10 @@ public class Duels extends CycledGame
|
||||
.setUnbreakable(true)
|
||||
.build(),
|
||||
new ItemStack(Material.WOOD, 64),
|
||||
new ItemStack(Material.LAVA_BUCKET),
|
||||
new ItemStack(Material.WATER_BUCKET),
|
||||
new ItemStack(Material.ARROW, 16),
|
||||
};
|
||||
private static final ItemStack[] ARMOUR = {
|
||||
new ItemBuilder(Material.DIAMOND_BOOTS)
|
||||
new ItemBuilder(Material.IRON_BOOTS)
|
||||
.setUnbreakable(true)
|
||||
.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 2)
|
||||
.build(),
|
||||
@ -80,7 +76,7 @@ public class Duels extends CycledGame
|
||||
super(manager, HubGameType.DUELS);
|
||||
|
||||
registerComponent(new DamageComponent(this));
|
||||
registerComponent(new PVPTrackerComponent(this));
|
||||
//registerComponent(new PVPTrackerComponent(this));
|
||||
registerComponent(new GameDescriptionComponent(this, player ->
|
||||
{
|
||||
for (Player other : getAlivePlayers())
|
||||
@ -141,9 +137,9 @@ public class Duels extends CycledGame
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public HubGamePage getInformationPage(Player player)
|
||||
{
|
||||
return new DuelsUI(getManager(), getManager().getShop(), getManager().getClientManager(), getManager().getDonationManager(), player, this);
|
||||
}
|
||||
// @Override
|
||||
// public HubGamePage getInformationPage(Player player)
|
||||
// {
|
||||
// return new DuelsUI(getManager(), getManager().getShop(), getManager().getClientManager(), getManager().getDonationManager(), player, this);
|
||||
// }
|
||||
}
|
||||
|
@ -25,9 +25,6 @@ import mineplex.hub.hubgame.common.general.GameTimeoutComponent;
|
||||
import mineplex.hub.hubgame.common.general.PlacesComponent;
|
||||
import mineplex.hub.hubgame.common.map.PreventNonAlivePlayersComponent;
|
||||
import mineplex.hub.hubgame.common.map.TeleportIntoMapComponent;
|
||||
import mineplex.hub.hubgame.common.powerup.PowerupComponent;
|
||||
import mineplex.hub.hubgame.tron.powerup.JumpPowerup;
|
||||
import mineplex.hub.hubgame.tron.powerup.SpeedPowerup;
|
||||
|
||||
public class Tron extends CycledGame
|
||||
{
|
||||
@ -41,18 +38,11 @@ public class Tron extends CycledGame
|
||||
private final Map<Player, TronBike> _bikes;
|
||||
private int _trailSize;
|
||||
|
||||
private final SpeedPowerup _speedPowerup;
|
||||
|
||||
public Tron(HubGameManager manager)
|
||||
{
|
||||
super(manager, HubGameType.TRON);
|
||||
_bikes = new HashMap<>();
|
||||
|
||||
PowerupComponent powerupComponent = registerComponent(new PowerupComponent(this, _worldData.getDataLocation("ORANGE")));
|
||||
_speedPowerup = new SpeedPowerup();
|
||||
powerupComponent.addPowerup(_speedPowerup);
|
||||
powerupComponent.addPowerup(new JumpPowerup());
|
||||
|
||||
registerComponent(new TeleportIntoMapComponent(this, _worldData.getDataLocation("RED")));
|
||||
registerComponent(new GameDescriptionComponent(this));
|
||||
registerComponent(new GameTimeoutComponent(this, TimeUnit.MINUTES.toMillis(3)));
|
||||
@ -100,7 +90,7 @@ public class Tron extends CycledGame
|
||||
|
||||
bike.updateDirection();
|
||||
|
||||
if (isLive() && bike.updateLocation(_speedPowerup.isActive(player)))
|
||||
if (isLive() && bike.updateLocation())
|
||||
{
|
||||
Location location = player.getLocation();
|
||||
|
||||
|
@ -33,7 +33,7 @@ public class TronBike
|
||||
private long _lastChange;
|
||||
private boolean _changeDirection;
|
||||
|
||||
public TronBike(Tron game, Player host, byte colour)
|
||||
TronBike(Tron game, Player host, byte colour)
|
||||
{
|
||||
_game = game;
|
||||
_host = host;
|
||||
@ -66,7 +66,7 @@ public class TronBike
|
||||
}
|
||||
}
|
||||
|
||||
public boolean updateLocation(boolean speed)
|
||||
public boolean updateLocation()
|
||||
{
|
||||
Location location = _bike.getLocation().add(0, 0.1, 0);
|
||||
Block block = location.getBlock();
|
||||
@ -99,12 +99,6 @@ public class TronBike
|
||||
deltaX += DELTA_TICK;
|
||||
}
|
||||
|
||||
if (speed)
|
||||
{
|
||||
deltaX *= 1.5;
|
||||
deltaZ *= 1.5;
|
||||
}
|
||||
|
||||
if (!block.equals(_lastBlock))
|
||||
{
|
||||
if (_trail.size() >= _game.getTrailSize())
|
||||
|
@ -1,33 +0,0 @@
|
||||
package mineplex.hub.hubgame.tron.powerup;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.hub.hubgame.common.powerup.ItemPowerup;
|
||||
|
||||
public class JumpPowerup extends ItemPowerup
|
||||
{
|
||||
|
||||
private static final ItemStack ITEM_STACK = new ItemStack(Material.FEATHER);
|
||||
private static final Vector DIRECTION = new Vector(0, 1.5, 0);
|
||||
|
||||
public JumpPowerup()
|
||||
{
|
||||
super(C.cGoldB + "Jump", ITEM_STACK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInteractItem(Player player)
|
||||
{
|
||||
Entity entity = player.getVehicle();
|
||||
|
||||
if (entity != null)
|
||||
{
|
||||
entity.setVelocity(DIRECTION);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package mineplex.hub.hubgame.tron.powerup;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.hub.hubgame.common.powerup.TimedPowerup;
|
||||
|
||||
public class SpeedPowerup extends TimedPowerup
|
||||
{
|
||||
|
||||
private static final ItemStack ITEM_STACK = new ItemStack(Material.DIAMOND_BOOTS);
|
||||
private static final long LENGTH = TimeUnit.SECONDS.toMillis(3);
|
||||
|
||||
public SpeedPowerup()
|
||||
{
|
||||
super(C.cGreenB + "Speed", ITEM_STACK, LENGTH);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package mineplex.hub.hubgame.ui;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.core.shop.page.ShopPageBase;
|
||||
import mineplex.hub.hubgame.HubGameManager;
|
||||
import mineplex.hub.parkour.ParkourData;
|
||||
import mineplex.hub.parkour.ParkourManager;
|
||||
|
||||
public class HubGamesPage extends ShopPageBase<HubGameManager, HubGameShop>
|
||||
{
|
||||
|
||||
private static final ItemStack LOBBY_GAMES = new ItemBuilder(Material.WOOL, (byte) 14)
|
||||
.setTitle(C.cGreenB + "Lobby Games")
|
||||
.addLore
|
||||
(
|
||||
"Goof off and play around with your best buds",
|
||||
"or people you just met hanging around the lobby!",
|
||||
"These mini-mini-games offer a super quick lobby",
|
||||
"only experience.",
|
||||
"",
|
||||
C.cWhite + "- " + C.cGreenB + "1v1 Gladiators",
|
||||
C.cWhite + "- " + C.cGreenB + "Slime Cycles",
|
||||
C.cWhite + "- " + C.cGray + "Under construction",
|
||||
"",
|
||||
"Click to teleport to the games!"
|
||||
)
|
||||
.build();
|
||||
|
||||
private final ParkourManager _parkourManager;
|
||||
|
||||
public HubGamesPage(HubGameManager plugin, Player player)
|
||||
{
|
||||
super(plugin, plugin.getShop(), plugin.getClientManager(), plugin.getDonationManager(), "Lobby Stuff", player, 27);
|
||||
|
||||
_parkourManager = plugin.getHubManager().getParkourManager();
|
||||
|
||||
buildPage();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildPage()
|
||||
{
|
||||
int index = 10;
|
||||
|
||||
for (ParkourData data : _parkourManager.getParkours())
|
||||
{
|
||||
ItemBuilder builder = new ItemBuilder(Material.GLASS)
|
||||
.setTitle(C.cYellowB + data.getName() + C.cGray + " - " + C.cAqua + "Parkour")
|
||||
.addLore(data.getDescription())
|
||||
.addLore("");
|
||||
|
||||
String difficulty = "";
|
||||
|
||||
switch (data.getDifficulty())
|
||||
{
|
||||
case ParkourManager.DIFFICULTY_EASY:
|
||||
builder.setType(Material.LEATHER_BOOTS);
|
||||
difficulty = C.cGreenB + "Easy";
|
||||
break;
|
||||
case ParkourManager.DIFFICULTY_MEDIUM:
|
||||
builder.setType(Material.IRON_BOOTS);
|
||||
difficulty = C.cGoldB + "Medium";
|
||||
break;
|
||||
case ParkourManager.DIFFICULTY_HARD:
|
||||
builder.setType(Material.DIAMOND_BOOTS);
|
||||
difficulty = C.cRedB + "Hard";
|
||||
break;
|
||||
}
|
||||
|
||||
builder.addLore(C.cWhite + "Difficulty - " + difficulty);
|
||||
addButton(index++, builder.build(), (player, clickType) -> player.teleport(data.getTeleport()));
|
||||
}
|
||||
|
||||
addButton(16, LOBBY_GAMES, (player, clickType) -> player.teleport(getPlugin().getTeleport()));
|
||||
}
|
||||
}
|
38
Plugins/Mineplex.Hub/src/mineplex/hub/kit/HubKitManager.java
Normal file
38
Plugins/Mineplex.Hub/src/mineplex/hub/kit/HubKitManager.java
Normal file
@ -0,0 +1,38 @@
|
||||
package mineplex.hub.kit;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.core.game.MineplexGameManager;
|
||||
import mineplex.hub.HubManager;
|
||||
import mineplex.hub.world.WorldDataModule;
|
||||
|
||||
@ReflectivelyCreateMiniPlugin
|
||||
public class HubKitManager extends MiniPlugin
|
||||
{
|
||||
|
||||
private HubKitManager()
|
||||
{
|
||||
super("Hub Kit");
|
||||
|
||||
MineplexGameManager gameManager = require(MineplexGameManager.class);
|
||||
WorldDataModule worldData = require(WorldDataModule.class);
|
||||
HubManager manager = require(HubManager.class);
|
||||
|
||||
gameManager.getKits().forEach(kit ->
|
||||
{
|
||||
List<Location> locations = worldData.getCustomLocation("KIT " + kit.getId());
|
||||
|
||||
if (!locations.isEmpty())
|
||||
{
|
||||
Location location = locations.get(0);
|
||||
UtilAlg.lookAtNearest(location, manager.getLookAt());
|
||||
kit.createNPC(location);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,284 +0,0 @@
|
||||
package mineplex.hub.modules;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.aprilfools.AprilFoolsManager;
|
||||
import mineplex.core.common.currency.GlobalCurrency;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.inventory.InventoryManager;
|
||||
import mineplex.core.titles.tracks.Track;
|
||||
import mineplex.core.titles.tracks.TrackManager;
|
||||
import mineplex.core.titles.tracks.award.AprilFools2017Track;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.Skull;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@ReflectivelyCreateMiniPlugin
|
||||
public class AprilFoolsTreasureHunt extends MiniPlugin
|
||||
{
|
||||
|
||||
private static final int SHARD_REWARD = 500;
|
||||
private static final String ITEM_REWARD = "Omega Chest";
|
||||
|
||||
private static final int[][] TREASURE = {
|
||||
{
|
||||
0, 72, -10
|
||||
},
|
||||
{
|
||||
-56, 71, -42
|
||||
},
|
||||
{
|
||||
171, 69, -67
|
||||
},
|
||||
{
|
||||
287, 71, -197
|
||||
},
|
||||
{
|
||||
306, 123, -182
|
||||
},
|
||||
{
|
||||
99, 68, -143
|
||||
},
|
||||
{
|
||||
122, 70, -27
|
||||
},
|
||||
{
|
||||
106, 86, 54
|
||||
},
|
||||
{
|
||||
48, 71, 71
|
||||
},
|
||||
{
|
||||
54, 64, 112
|
||||
},
|
||||
{
|
||||
45, 117, 113
|
||||
},
|
||||
{
|
||||
77, 93, 210
|
||||
},
|
||||
{
|
||||
-13, 65, 128
|
||||
},
|
||||
{
|
||||
-22, 65, 110
|
||||
},
|
||||
{
|
||||
-115, 67, 54
|
||||
},
|
||||
{
|
||||
-91, 56, 46
|
||||
},
|
||||
{
|
||||
-14, 29, -10
|
||||
},
|
||||
{
|
||||
13, 39, 36
|
||||
},
|
||||
{
|
||||
99, 48, 49
|
||||
},
|
||||
{
|
||||
-101, 70, 196
|
||||
},
|
||||
{
|
||||
29, 111, 39
|
||||
},
|
||||
{
|
||||
36, 60, -19
|
||||
},
|
||||
{
|
||||
-65, 70, -111
|
||||
},
|
||||
{
|
||||
-88, 55, -77
|
||||
},
|
||||
{
|
||||
-4, 73, -37
|
||||
},
|
||||
{
|
||||
120, 68, -20
|
||||
},
|
||||
{
|
||||
119, 79, 9
|
||||
},
|
||||
{
|
||||
213, 64, -111
|
||||
},
|
||||
{
|
||||
228, 63, -155
|
||||
},
|
||||
{
|
||||
34, 84, -5
|
||||
}
|
||||
};
|
||||
private static final BlockFace[] BLOCK_FACES = {
|
||||
BlockFace.NORTH,
|
||||
BlockFace.EAST,
|
||||
BlockFace.SOUTH,
|
||||
BlockFace.WEST,
|
||||
BlockFace.NORTH_EAST,
|
||||
BlockFace.SOUTH_EAST,
|
||||
BlockFace.SOUTH_WEST,
|
||||
BlockFace.NORTH_WEST
|
||||
};
|
||||
|
||||
private final AprilFoolsManager _aprilFools;
|
||||
private final CoreClientManager _client;
|
||||
private final DonationManager _donation;
|
||||
private final InventoryManager _inventory;
|
||||
private final TrackManager _track;
|
||||
|
||||
private final Map<UUID, List<Integer>> _foundTreasure;
|
||||
private final List<Location> _treasure;
|
||||
private boolean _set;
|
||||
|
||||
private AprilFoolsTreasureHunt()
|
||||
{
|
||||
super("Treasure Hunt");
|
||||
|
||||
_aprilFools = require(AprilFoolsManager.class);
|
||||
_client = require(CoreClientManager.class);
|
||||
_donation = require(DonationManager.class);
|
||||
_inventory = require(InventoryManager.class);
|
||||
_track = require(TrackManager.class);
|
||||
|
||||
_foundTreasure = new HashMap<>();
|
||||
_treasure = new ArrayList<>(TREASURE.length);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerJoin(PlayerJoinEvent event)
|
||||
{
|
||||
UUID key = event.getPlayer().getUniqueId();
|
||||
|
||||
_foundTreasure.put(key, new ArrayList<>(TREASURE.length));
|
||||
|
||||
runAsync(() -> _aprilFools.getRepository().getTreasure(data -> _foundTreasure.put(key, data), _client.Get(key)));
|
||||
|
||||
if (!_set)
|
||||
{
|
||||
_set = true;
|
||||
World world = Bukkit.getWorld("world");
|
||||
|
||||
for (int[] cords : TREASURE)
|
||||
{
|
||||
Location location = new Location(world, cords[0], cords[1], cords[2]);
|
||||
Block block = location.getBlock();
|
||||
block.setType(Material.SKULL);
|
||||
block.setData((byte) 1);
|
||||
Skull skull = (Skull) block.getState();
|
||||
skull.setSkullType(SkullType.PLAYER);
|
||||
skull.setOwner("Topplemop");
|
||||
skull.setRotation(BLOCK_FACES[UtilMath.r(BLOCK_FACES.length)]);
|
||||
skull.update();
|
||||
|
||||
_treasure.add(location);
|
||||
}
|
||||
|
||||
Location information = _treasure.get(0).clone();
|
||||
ArmorStand hologram = information.getWorld().spawn(information.add(.5, .5, .5), ArmorStand.class);
|
||||
|
||||
hologram.setSmall(true);
|
||||
hologram.setGravity(false);
|
||||
hologram.setVisible(false);
|
||||
hologram.setCustomNameVisible(true);
|
||||
hologram.setCustomName(C.cDPurple + C.Scramble + "ABC " + C.cPurpleB + "April Fools Treasure Hunt" + C.cDPurple + C.Scramble + " ABC");
|
||||
hologram.setRemoveWhenFarAway(false);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void interactBlock(PlayerInteractEvent event)
|
||||
{
|
||||
if (event.getClickedBlock() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
UUID key = event.getPlayer().getUniqueId();
|
||||
List<Integer> found = _foundTreasure.get(key);
|
||||
Location location = event.getClickedBlock().getLocation();
|
||||
int i = 0;
|
||||
|
||||
for (Location treasure : _treasure)
|
||||
{
|
||||
if (location.equals(treasure))
|
||||
{
|
||||
findChest(player, i);
|
||||
break;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
private void findChest(Player player, int treasureId)
|
||||
{
|
||||
List<Integer> found = _foundTreasure.get(player.getUniqueId());
|
||||
|
||||
if (found.contains(treasureId))
|
||||
{
|
||||
player.sendMessage(F.main(_moduleName, "You already have found this skull! You have found " + F.count(String.valueOf(found.size())) + "/" + F.count(String.valueOf(_treasure.size())) + "."));
|
||||
return;
|
||||
}
|
||||
|
||||
found.add(treasureId);
|
||||
player.playSound(player.getLocation(), Sound.CAT_MEOW, 1, 0.7F);
|
||||
player.sendMessage(F.main(_moduleName, "Found " + F.count(String.valueOf(found.size())) + "/" + F.count(String.valueOf(_treasure.size()))) + " Treasure Chests +" + F.currency(GlobalCurrency.TREASURE_SHARD, SHARD_REWARD) + ".");
|
||||
_donation.rewardCurrencyUntilSuccess(GlobalCurrency.TREASURE_SHARD, player, "", SHARD_REWARD);
|
||||
|
||||
runAsync(() -> _aprilFools.getRepository().saveTreasure(_client.Get(player.getUniqueId()), treasureId));
|
||||
|
||||
if (found.size() == 1)
|
||||
{
|
||||
player.sendMessage(F.main(_moduleName, "There are " + F.count("30") + " secret " + F.elem("Pirate Heads") + " to find through the lobby."));
|
||||
player.sendMessage(F.main(_moduleName, "Each one is worth " + F.currency(GlobalCurrency.TREASURE_SHARD, SHARD_REWARD) + "."));
|
||||
player.sendMessage(F.main(_moduleName, "If you find all " + F.count("30") + " you will receive an " + C.cAqua + "Omega Chest" + C.mBody + " and an exclusive " + F.elem("Title") + "!"));
|
||||
}
|
||||
else if (found.size() == TREASURE.length)
|
||||
{
|
||||
player.sendMessage(F.main(_moduleName, "Completed the " + F.name("Mineplex April Fools 2017 Treasure Hunt") + "."));
|
||||
|
||||
_inventory.addItemToInventory(data ->
|
||||
{
|
||||
if (data)
|
||||
{
|
||||
player.sendMessage(F.main(_moduleName, "+1 " + C.cAqua + ITEM_REWARD + C.mBody + "!"));
|
||||
}
|
||||
else
|
||||
{
|
||||
player.sendMessage(F.main(_moduleName, "Oops, somehow I could not give you the chest, you should inform a staff member!"));
|
||||
}
|
||||
}, player, ITEM_REWARD, 1);
|
||||
|
||||
Track track = _track.getTrack(AprilFools2017Track.class);
|
||||
|
||||
_track.unlockTrack(player, track, result ->
|
||||
{
|
||||
switch (result)
|
||||
{
|
||||
case UNKNOWN_ERROR:
|
||||
player.sendMessage(F.main(_moduleName, "Oops, somehow I could not give you the title track, you should inform a staff member!"));
|
||||
break;
|
||||
case SUCCESS:
|
||||
player.sendMessage(F.main(_moduleName, "Unlocked " + track.getColor() + track.getLongName() + C.mBody + " Title!"));
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -1,20 +1,15 @@
|
||||
package mineplex.hub.modules;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import mineplex.core.Managers;
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.common.util.UtilEnt;
|
||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.preferences.Preference;
|
||||
@ -23,20 +18,23 @@ import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.core.visibility.VisibilityManager;
|
||||
import mineplex.hub.HubManager;
|
||||
|
||||
@ReflectivelyCreateMiniPlugin
|
||||
public class HubVisibilityManager extends MiniPlugin
|
||||
{
|
||||
private static final String JUST_SPAWNED_FLAG = "JustSpawned";
|
||||
|
||||
private static final int HIDE_SPAWN_RADIUS_SQUARED = 4;
|
||||
|
||||
public HubManager Manager;
|
||||
private final HubManager _manager;
|
||||
private final VisibilityManager _visibilityManager;
|
||||
|
||||
private final Set<Player> _hiddenPlayers = new HashSet<>();
|
||||
private final Map<Player, Integer> _nextShownPlayer = new HashMap<>();
|
||||
|
||||
public HubVisibilityManager(HubManager manager)
|
||||
public HubVisibilityManager()
|
||||
{
|
||||
super("Visibility Manager", manager.getPlugin());
|
||||
Manager = manager;
|
||||
super("Hub Visibility");
|
||||
|
||||
_manager = require(HubManager.class);
|
||||
_visibilityManager = require(VisibilityManager.class);
|
||||
}
|
||||
|
||||
public void addHiddenPlayer(Player player)
|
||||
@ -55,13 +53,6 @@ public class HubVisibilityManager extends MiniPlugin
|
||||
Player player = event.getPlayer();
|
||||
|
||||
_hiddenPlayers.remove(player);
|
||||
_nextShownPlayer.remove(player);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerJoin(PlayerJoinEvent event)
|
||||
{
|
||||
UtilEnt.addFlag(event.getPlayer(), JUST_SPAWNED_FLAG);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -80,86 +71,38 @@ public class HubVisibilityManager extends MiniPlugin
|
||||
|
||||
for (Player perspective : online)
|
||||
{
|
||||
boolean closeToSpawn = closeToSpawn(perspective);
|
||||
boolean justSpawned = UtilEnt.hasFlag(perspective, JUST_SPAWNED_FLAG);
|
||||
|
||||
// Don't hide themselves OR they are currently being sent player data one by one
|
||||
if (perspective.equals(subject) || _nextShownPlayer.containsKey(perspective))
|
||||
// Don't hide themselves
|
||||
if (perspective.equals(subject))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Player has just spawned flag however they are no longer near the spawn
|
||||
if (justSpawned && !closeToSpawn)
|
||||
// Not hiding the subject and has preference
|
||||
if (!hideMe && _manager.getPreferences().get(perspective).isActive(Preference.SHOW_PLAYERS))
|
||||
{
|
||||
UtilEnt.removeFlag(perspective, JUST_SPAWNED_FLAG);
|
||||
_nextShownPlayer.put(perspective, 0);
|
||||
}
|
||||
|
||||
// Has preference AND is not close to the spawn AND has not just spawned
|
||||
boolean showOthers = Manager.getPreferences().get(perspective).isActive(Preference.SHOW_PLAYERS) && (!closeToSpawn || !justSpawned);
|
||||
|
||||
VisibilityManager vm = Managers.get(VisibilityManager.class);
|
||||
|
||||
if (!hideMe && showOthers)
|
||||
{
|
||||
vm.showPlayer(perspective, subject, "Hub Visibility Manager");
|
||||
_visibilityManager.showPlayer(perspective, subject, getName());
|
||||
}
|
||||
else
|
||||
{
|
||||
vm.hidePlayer(perspective, subject, "Hub Visibility Manager");
|
||||
_visibilityManager.hidePlayer(perspective, subject, getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void updateVisibility1(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.FASTEST)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Player[] online = UtilServer.getPlayers();
|
||||
Iterator<Player> iterator = _nextShownPlayer.keySet().iterator();
|
||||
VisibilityManager vm = Managers.get(VisibilityManager.class);
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
Player perspective = iterator.next();
|
||||
int index = _nextShownPlayer.get(perspective);
|
||||
|
||||
if (perspective == null || !perspective.isOnline() || online.length <= index)
|
||||
{
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
Player subject = online[index];
|
||||
|
||||
if (!perspective.equals(subject) && !shouldHide(subject))
|
||||
{
|
||||
vm.showPlayer(perspective, subject, "Hub Visibility Manager");
|
||||
}
|
||||
|
||||
_nextShownPlayer.put(perspective, ++index);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean shouldHide(Player subject)
|
||||
{
|
||||
return
|
||||
// Close to spawn
|
||||
closeToSpawn(subject) ||
|
||||
// Enabled Invisibility
|
||||
(Manager.getPreferences().get(subject).isActive(Preference.INVISIBILITY) && Manager.GetClients().Get(subject).hasPermission(Preference.INVISIBILITY)) ||
|
||||
(_manager.getPreferences().get(subject).isActive(Preference.INVISIBILITY) && _manager.GetClients().Get(subject).hasPermission(Preference.INVISIBILITY)) ||
|
||||
// OR Player has been explicitly hidden
|
||||
_hiddenPlayers.contains(subject);
|
||||
}
|
||||
|
||||
private boolean closeToSpawn(Player player)
|
||||
{
|
||||
return UtilMath.offset2dSquared(player.getLocation(), Manager.GetSpawn()) < HIDE_SPAWN_RADIUS_SQUARED;
|
||||
return UtilMath.offset2dSquared(player.getLocation(), _manager.GetSpawn()) < HIDE_SPAWN_RADIUS_SQUARED;
|
||||
}
|
||||
}
|
@ -1,554 +0,0 @@
|
||||
package mineplex.hub.modules;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerVelocityEvent;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.common.currency.GlobalCurrency;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.Callback;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilBlock;
|
||||
import mineplex.core.common.util.UtilEnt;
|
||||
import mineplex.core.common.util.UtilEvent;
|
||||
import mineplex.core.common.util.UtilEvent.ActionType;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.gadget.event.GadgetBlockEvent;
|
||||
import mineplex.core.gadget.event.GadgetEnableEvent;
|
||||
import mineplex.core.gadget.types.MusicGadget;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
import mineplex.core.task.TaskManager;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.hub.HubManager;
|
||||
import mineplex.hub.modules.parkour.ParkourData;
|
||||
|
||||
public class ParkourManager extends MiniPlugin
|
||||
{
|
||||
private final String[] RUINS_DESCRIPTION = {
|
||||
"This is an extremely difficult parkour.",
|
||||
"You will need to find the correct way through",
|
||||
"the ruins, overcoming many challenging jumps.",
|
||||
};
|
||||
|
||||
private final String[] GWEN_DESCRIPTION = {
|
||||
"Can you escape from our Guardians?",
|
||||
"I hear they have infested the water",
|
||||
"sending anyone who falls in back to the start!",
|
||||
};
|
||||
|
||||
private final String[] LAVA_DESCRIPTION = {
|
||||
"This parkour is HOT! It's so hot that you",
|
||||
"must keep sprinting for the entire course,",
|
||||
"or you will die in flames!"
|
||||
};
|
||||
|
||||
private final String[] DESERT_DESCRIPTION = {
|
||||
"Ever heard of Prince of Persia",
|
||||
"well, this isn't as exciting.",
|
||||
"yet...."
|
||||
};
|
||||
|
||||
private final int RUINS_GEMS = 10000;
|
||||
private final int GWEN_GEMS = 4000;
|
||||
private final int LAVA_GEMS = 5000;
|
||||
private final int DESERT_GEMS = 3000;
|
||||
|
||||
public HubManager Manager;
|
||||
|
||||
private Map<UUID, ParkourData> _active = Maps.newHashMap();
|
||||
|
||||
private HashSet<ParkourData> _parkour = new HashSet<ParkourData>();
|
||||
|
||||
//private Location _snakeParkourReturn;
|
||||
private Location _lavaParkourReturn;
|
||||
private Location _waterReturn;
|
||||
private WeakHashMap<Player, Location> _lavaLocation = new WeakHashMap<Player, Location>();
|
||||
private WeakHashMap<Player, Long> _lavaTimer = new WeakHashMap<Player, Long>();
|
||||
|
||||
//Modules
|
||||
protected DonationManager _donationManager;
|
||||
protected TaskManager _taskManager;
|
||||
|
||||
public ParkourManager(HubManager manager, DonationManager donation, TaskManager task)
|
||||
{
|
||||
super("Parkour", manager.getPlugin());
|
||||
|
||||
Manager = manager;
|
||||
|
||||
_taskManager = task;
|
||||
_donationManager = donation;
|
||||
|
||||
_parkour.add(new ParkourData("Ruins Parkour", RUINS_DESCRIPTION, RUINS_GEMS,
|
||||
new Location(Manager.GetSpawn().getWorld(), 113.5, 66, -46.5),
|
||||
new Location(Manager.GetSpawn().getWorld(), 124, 86, 18),
|
||||
new Location(Manager.GetSpawn().getWorld(), 105, 57, -53)));
|
||||
|
||||
_parkour.add(new ParkourData("G.W.E.N Parkour", GWEN_DESCRIPTION, GWEN_GEMS,
|
||||
new Location(Manager.GetSpawn().getWorld(), 55.5, 68, -94.5),
|
||||
new Location(Manager.GetSpawn().getWorld(), 106, 96, -142),
|
||||
new Location(Manager.GetSpawn().getWorld(), 52, 61, -81)));
|
||||
|
||||
_parkour.add(new ParkourData("Lava Parkour", LAVA_DESCRIPTION, LAVA_GEMS,
|
||||
new Location(Manager.GetSpawn().getWorld(), -93.5, 67, 37.5),
|
||||
new Location(Manager.GetSpawn().getWorld(), -144, 97, -21),
|
||||
new Location(Manager.GetSpawn().getWorld(), -88, 62, 41)));
|
||||
|
||||
_parkour.add(new ParkourData("Desert Village Parkour", DESERT_DESCRIPTION, DESERT_GEMS,
|
||||
new Location(Manager.GetSpawn().getWorld(), -63.5, 69, -32.5),
|
||||
new Location(Manager.GetSpawn().getWorld(), -57, 82, -35),
|
||||
new Location(Manager.GetSpawn().getWorld(), -122, 45, 57)));
|
||||
|
||||
_lavaParkourReturn = new Location(Manager.GetSpawn().getWorld(), -89.5, 68, 36.5);
|
||||
_lavaParkourReturn.setYaw(90);
|
||||
_waterReturn = new Location(Manager.GetSpawn().getWorld(), 56.5, 68, -88.5);
|
||||
_waterReturn.setYaw(-141);
|
||||
}
|
||||
|
||||
public boolean isParkourMode(Player player)
|
||||
{
|
||||
return _active.containsKey(player.getUniqueId());
|
||||
}
|
||||
|
||||
public void setParkourMode(Player player, boolean enabled, ParkourData data)
|
||||
{
|
||||
if (enabled)
|
||||
{
|
||||
player.setAllowFlight(false);
|
||||
player.setFlying(false);
|
||||
_active.put(player.getUniqueId(), data);
|
||||
UtilPlayer.message(player, F.main("Parkour", "You have entered " + F.elem("Parkour Mode") + "."));
|
||||
|
||||
Manager.GetGadget().disableAll(player);
|
||||
|
||||
player.setVelocity(new Vector(0, -1, 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
player.setAllowFlight(true);
|
||||
_active.remove(player.getUniqueId());
|
||||
UtilPlayer.message(player, F.main("Parkour", "You have exited " + F.elem("Parkour Mode") + "."));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerVelocity(PlayerVelocityEvent event)
|
||||
{
|
||||
if (isParkourMode(event.getPlayer()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void disableGadgets(GadgetEnableEvent event)
|
||||
{
|
||||
if (isParkourMode(event.getPlayer()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerEnterParkour(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.FAST)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (Player player : UtilServer.getPlayers())
|
||||
{
|
||||
if (isParkourMode(player))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
_parkour.stream()
|
||||
.filter(data -> UtilMath.offset(player.getLocation(), data.NPC) < 6)
|
||||
.filter(data -> Recharge.Instance.use(player, data.Name + " Info", 300000, false, false))
|
||||
.forEach(data -> data.Inform(player));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void parkourUpdate(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.TICK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
List<Player> players = Lists.newArrayList(_active.keySet().stream().map(Bukkit::getPlayer).collect(Collectors.toList()));
|
||||
for (Player player : players)
|
||||
{
|
||||
player.leaveVehicle();
|
||||
player.eject();
|
||||
if (!InsideParkour(player.getLocation()))
|
||||
{
|
||||
setParkourMode(player, false, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (PotionEffect potionEffect : player.getActivePotionEffects())
|
||||
{
|
||||
player.removePotionEffect(potionEffect.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
players.clear();
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerQuit(PlayerQuitEvent event)
|
||||
{
|
||||
_active.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void disallowBlockBreak(BlockBreakEvent event)
|
||||
{
|
||||
if (isParkourMode(event.getPlayer()))
|
||||
{
|
||||
event.getPlayer().teleport(Manager.GetSpawn());
|
||||
UtilPlayer.message(event.getPlayer(), F.main("Parkour", "You cannot break blocks in Parkour Mode!"));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void disallowBlockPlace(PlayerInteractEvent event)
|
||||
{
|
||||
if (event.getPlayer().getItemInHand() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.getPlayer().getItemInHand().getType().isBlock())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!UtilEvent.isAction(event, ActionType.R_BLOCK))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (isParkourMode(event.getPlayer()))
|
||||
{
|
||||
event.getPlayer().teleport(Manager.GetSpawn());
|
||||
UtilPlayer.message(event.getPlayer(), F.main("Parkour", "You cannot place blocks in Parkour Mode!"));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void lavaReturn(EntityDamageEvent event)
|
||||
{
|
||||
if (event.getCause() != DamageCause.LAVA)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getEntity() instanceof Player))
|
||||
{
|
||||
if (event.getEntity().hasMetadata("balloon"))
|
||||
return;
|
||||
event.getEntity().remove();
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
if (!isParkourMode(player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
event.getEntity().eject();
|
||||
event.getEntity().leaveVehicle();
|
||||
event.getEntity().teleport(_lavaParkourReturn);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void waterReturn(PlayerMoveEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (!isParkourMode(player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Arrays.equals(_active.get(player.getUniqueId()).Desc, GWEN_DESCRIPTION))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getTo().getBlock().getType() == Material.WATER || event.getTo().getBlock().getType() == Material.STATIONARY_WATER)
|
||||
{
|
||||
player.eject();
|
||||
player.leaveVehicle();
|
||||
player.teleport(_waterReturn);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onTeam(PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
if (event.getMessage().startsWith("/team ") && isParkourMode(event.getPlayer()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(F.main("Team", "You cannot join a team while in parkour mode!"));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void lavaBlockReturn(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.TICK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (Player player : UtilServer.getPlayers())
|
||||
{
|
||||
if (!UtilEnt.isGrounded(player))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isParkourMode(player))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int id = player.getLocation().getBlock().getRelative(BlockFace.DOWN).getTypeId();
|
||||
int data = player.getLocation().getBlock().getRelative(BlockFace.DOWN).getData();
|
||||
if (id != 0 && id != 112 && id != 114 && !(id == 43 && data == 6) && !(id == 44 && data == 6))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!_lavaLocation.containsKey(player) || UtilMath.offset(player.getLocation(), _lavaLocation.get(player)) > 1.5)
|
||||
{
|
||||
_lavaLocation.put(player, player.getLocation());
|
||||
_lavaTimer.put(player, System.currentTimeMillis());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (UtilTime.elapsed(_lavaTimer.get(player), 500))
|
||||
{
|
||||
boolean inCourse = false;
|
||||
for (Block block : UtilBlock.getInRadius(player.getLocation(), 1.5).keySet())
|
||||
{
|
||||
if (block.getType() == Material.NETHER_BRICK || block.getType() == Material.NETHER_BRICK_STAIRS)
|
||||
{
|
||||
inCourse = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!inCourse)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
_lavaLocation.remove(player);
|
||||
_lavaTimer.remove(player);
|
||||
|
||||
player.eject();
|
||||
player.leaveVehicle();
|
||||
player.teleport(_lavaParkourReturn);
|
||||
player.setFireTicks(0);
|
||||
|
||||
UtilPlayer.message(player, F.main("Parkour", "You cannot stop running during Lava Parkour!"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void finishParkour(PlayerInteractEntityEvent event)
|
||||
{
|
||||
if (event.getRightClicked() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getRightClicked() instanceof LivingEntity))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
LivingEntity ent = (LivingEntity) event.getRightClicked();
|
||||
|
||||
if (ent.getCustomName() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//Start Message
|
||||
if (ent.getCustomName().contains("Start"))
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
|
||||
for (ParkourData data : _parkour)
|
||||
{
|
||||
if (!ent.getCustomName().contains(data.Name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isParkourMode(player))
|
||||
{
|
||||
setParkourMode(player, false, data);
|
||||
}
|
||||
else
|
||||
{
|
||||
setParkourMode(player, true, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Finish Message
|
||||
if (ent.getCustomName().contains("Finish"))
|
||||
{
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
if (!isParkourMode(player))
|
||||
{
|
||||
//Inform
|
||||
UtilPlayer.message(player, F.main("Parkour", "You must be in " + F.elem("Parkour Mode") + " to cleanup."));
|
||||
UtilPlayer.message(player, F.main("Parkour", "Talk to the " + F.elem("Start NPC") + " to enter Parkour Mode."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Recharge.Instance.use(player, "Finish Parkour", 30000, false, false))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ParkourData data = _active.get(player.getUniqueId());
|
||||
|
||||
if (!ent.getCustomName().contains(data.Name))
|
||||
{
|
||||
UtilPlayer.message(player, F.main("Parkour", "This is not the entity you are looking for..."));
|
||||
player.teleport(data.NPC);
|
||||
player.playSound(player.getLocation(), Sound.ENDERMAN_TELEPORT, 1.0f, 1.0F);
|
||||
return;
|
||||
}
|
||||
//Inform
|
||||
UtilPlayer.message(player, F.main("Parkour", "You completed " + F.elem(data.Name) + "."));
|
||||
|
||||
setParkourMode(player, false, null);
|
||||
|
||||
//Gems
|
||||
if (!_taskManager.hasCompletedTask(player, data.Name))
|
||||
{
|
||||
final ParkourData fData = data;
|
||||
|
||||
_taskManager.completedTask(new Callback<Boolean>()
|
||||
{
|
||||
public void run(Boolean completed)
|
||||
{
|
||||
_donationManager.rewardCurrency(GlobalCurrency.GEM, player, "Parkour " + fData.Name, fData.Gems, success ->
|
||||
{
|
||||
if (completed)
|
||||
{
|
||||
UtilPlayer.message(player, F.main("Parkour", "You received " + F.elem(C.cGreen + fData.Gems + " Gems") + "."));
|
||||
|
||||
//Sound
|
||||
player.playSound(player.getLocation(), Sound.LEVEL_UP, 2f, 1.5f);
|
||||
}
|
||||
else
|
||||
{
|
||||
_taskManager.Get(player).TasksCompleted.remove(_taskManager.getTaskId(fData.Name));
|
||||
UtilPlayer.message(player, F.main("Parkour", "There was an error giving " + F.elem(C.cGreen + fData.Gems + " Gems to you. Please click the NPC again.") + "."));
|
||||
}
|
||||
});
|
||||
|
||||
//Sound
|
||||
player.playSound(player.getLocation(), Sound.LEVEL_UP, 2f, 1.5f);
|
||||
}
|
||||
}, player, fData.Name);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void gadgetBlockChange(GadgetBlockEvent event)
|
||||
{
|
||||
for (Iterator<Block> iterator = event.getBlocks().iterator(); iterator.hasNext(); )
|
||||
{
|
||||
Block block = iterator.next();
|
||||
|
||||
for (ParkourData data : _parkour)
|
||||
{
|
||||
if (data.InBoundary(block.getLocation()))
|
||||
{
|
||||
iterator.remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean InsideParkour(Location loc)
|
||||
{
|
||||
for (ParkourData data : _parkour)
|
||||
if (data.InBoundary(loc))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void musicDisable(GadgetEnableEvent event)
|
||||
{
|
||||
if (event.getGadget() instanceof MusicGadget)
|
||||
{
|
||||
if (InsideParkour(event.getPlayer().getLocation()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
package mineplex.hub.modules.parkour;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ParkourData
|
||||
{
|
||||
public String Name;
|
||||
public String[] Desc;
|
||||
public int Gems;
|
||||
public Location NPC;
|
||||
public Location CornerA;
|
||||
public Location CornerB;
|
||||
public double Distance;
|
||||
|
||||
public ParkourData(String name, String[] desc, int gems, Location npc, Location cornerA, Location cornerB)
|
||||
{
|
||||
Name = name;
|
||||
Desc = desc;
|
||||
Gems = gems;
|
||||
NPC = npc;
|
||||
CornerA = cornerA;
|
||||
CornerB = cornerB;
|
||||
}
|
||||
|
||||
public void Inform(Player player)
|
||||
{
|
||||
UtilPlayer.message(player, "");
|
||||
UtilPlayer.message(player, C.cDGreen + C.Strike + "=============================================");
|
||||
|
||||
UtilPlayer.message(player, "§f§l" + Name + " Course");
|
||||
UtilPlayer.message(player, "");
|
||||
|
||||
for (String cur : Desc)
|
||||
{
|
||||
UtilPlayer.message(player, " " + cur);
|
||||
}
|
||||
|
||||
UtilPlayer.message(player, "");
|
||||
UtilPlayer.message(player, C.cWhite + C.Bold + "You must " + C.cGreen + C.Bold + "Right-Click" + C.cWhite + C.Bold + " the NPC to begin!");
|
||||
|
||||
UtilPlayer.message(player, "");
|
||||
UtilPlayer.message(player, C.cDGreen + C.Strike + "=============================================");
|
||||
|
||||
player.playSound(player.getLocation(), Sound.ORB_PICKUP, 1f, 2f);
|
||||
}
|
||||
|
||||
public boolean InBoundary(Location loc)
|
||||
{
|
||||
return (UtilAlg.inBoundingBox(loc, CornerA, CornerB));
|
||||
}
|
||||
|
||||
public World getWorld()
|
||||
{
|
||||
return CornerA.getWorld();
|
||||
}
|
||||
}
|
@ -1,214 +0,0 @@
|
||||
package mineplex.hub.modules.parkour;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
|
||||
|
||||
public class ParkourSnake extends ParkourData
|
||||
{
|
||||
private ArrayList<SnakePart> _snakes;
|
||||
|
||||
public ParkourSnake(String name, String[] desc, int gems, Location npc, Location cornerA, Location cornerB)
|
||||
{
|
||||
super(name, desc, gems, npc, cornerA, cornerB);
|
||||
|
||||
//THIS SHOULD BE COMMENTED OUT
|
||||
//parseSnakes();
|
||||
|
||||
loadSnakes();
|
||||
}
|
||||
|
||||
public void loadSnakes()
|
||||
{
|
||||
_snakes = new ArrayList<SnakePart>();
|
||||
|
||||
try
|
||||
{
|
||||
BufferedReader br = new BufferedReader(new FileReader("SnakeRoutes.dat"));
|
||||
try
|
||||
{
|
||||
String line = br.readLine();
|
||||
|
||||
while (line != null)
|
||||
{
|
||||
if (line.length() > 6)
|
||||
_snakes.add(loadSnake(line));
|
||||
|
||||
line = br.readLine();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
br.close();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public SnakePart loadSnake(String locString)
|
||||
{
|
||||
ArrayList<Location> locs = new ArrayList<Location>();
|
||||
|
||||
for (String cur : locString.split(":"))
|
||||
{
|
||||
String[] tokens = cur.split(",");
|
||||
|
||||
try
|
||||
{
|
||||
Location loc = new Location(getWorld(), Integer.parseInt(tokens[0]), Integer.parseInt(tokens[1]), Integer.parseInt(tokens[2]));
|
||||
|
||||
if (InBoundary(loc))
|
||||
locs.add(loc);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("Invalid Hub Snake Location: " + cur);
|
||||
}
|
||||
}
|
||||
|
||||
return new SnakePart(locs);
|
||||
}
|
||||
|
||||
public void parseSnakes()
|
||||
{
|
||||
String locString = "-22,78,-72:-22,79,-72:-22,80,-72:-22,80,-71:-22,80,-70:-22,80,-69:-22,78,-68:-22,79,-68:-22,80,-68:-22,79,-57:-22,79,-56:-22,79,-55:-22,79,-54:-22,79,-53:-21,75,-78:-21,76,-78:-21,77,-78:-21,75,-77:-21,75,-76:-21,75,-75:-21,75,-74:-21,76,-74:-21,77,-74:-21,78,-74:-21,78,-73:-21,78,-72:-21,76,-68:-21,77,-68:-21,78,-68:-21,76,-67:-21,76,-66:-21,76,-65:-21,76,-64:-21,77,-64:-21,78,-64:-21,79,-64:-21,79,-63:-21,77,-62:-21,78,-62:-21,79,-62:-21,79,-57:-21,79,-56:-21,79,-55:-21,79,-54:-21,79,-53:-20,77,-78:-20,77,-62:-20,79,-57:-20,79,-56:-20,79,-55:-20,79,-54:-20,79,-53:-19,75,-78:-19,76,-78:-19,77,-78:-19,75,-77:-19,75,-76:-19,75,-75:-19,75,-74:-19,77,-74:-19,78,-74:-19,79,-74:-19,75,-73:-19,76,-73:-19,77,-73:-19,77,-62:-18,79,-74:-18,77,-62:-17,79,-74:-17,77,-62:-16,79,-74:-16,77,-62:-15,77,-74:-15,78,-74:-15,79,-74:-15,75,-73:-15,76,-73:-15,77,-73:-15,75,-72:-15,75,-71:-15,75,-70:-15,75,-69:-15,76,-69:-15,77,-69:-15,77,-68:-15,77,-67:-15,77,-66:-15,77,-65:-15,77,-64:-15,77,-63:-15,77,-62:-11,77,-68:-11,78,-68:-11,79,-68:-11,77,-67:-11,77,-66:-11,77,-65:-11,78,-65:-11,79,-65:-10,79,-68:-10,79,-65:-9,79,-68:-9,79,-65:-8,77,-68:-8,78,-68:-8,79,-68:-8,77,-67:-8,77,-66:-8,77,-65:-8,78,-65:-8,79,-65:-7,75,-75:-7,75,-74:-7,75,-73:-7,76,-73:-7,77,-73:-7,73,-71:-7,74,-71:-7,75,-71:-7,73,-70:-7,73,-69:-7,72,-66:-7,73,-66:-7,74,-66:-7,72,-65:-7,72,-64:-7,72,-63:-7,73,-63:-7,74,-63:-7,75,-63:-6,71,-79:-6,72,-79:-6,73,-79:-6,74,-79:-6,75,-79:-6,75,-78:-6,76,-78:-6,77,-78:-6,75,-75:-6,77,-73:-6,75,-71:-6,73,-69:-6,74,-66:-6,75,-63:-5,71,-79:-5,77,-78:-5,75,-75:-5,75,-74:-5,75,-73:-5,76,-73:-5,77,-73:-5,73,-71:-5,74,-71:-5,75,-71:-5,73,-70:-5,73,-69:-5,77,-69:-5,77,-68:-5,77,-67:-5,74,-66:-5,75,-66:-5,76,-66:-5,77,-66:-5,72,-63:-5,73,-63:-5,74,-63:-5,75,-63:-4,71,-79:-4,77,-78:-4,77,-69:-4,72,-63:-3,71,-79:-3,77,-78:-3,77,-69:-3,72,-63:-2,71,-79:-2,73,-79:-2,74,-79:-2,75,-79:-2,75,-78:-2,76,-78:-2,77,-78:-2,74,-69:-2,75,-69:-2,76,-69:-2,77,-69:-2,74,-68:-2,74,-67:-2,74,-66:-2,74,-65:-2,75,-65:-2,76,-65:-2,76,-64:-2,72,-63:-2,73,-63:-2,74,-63:-2,75,-63:-2,76,-63:-1,71,-79:-1,73,-79:0,71,-79:0,73,-79:1,71,-79:1,73,-79:1,74,-79:1,75,-79:1,75,-78:1,76,-78:1,77,-78:2,71,-79:2,77,-78:3,71,-79:3,77,-78:4,71,-79:4,73,-79:4,74,-79:4,75,-79:4,75,-78:4,76,-78:4,77,-78:5,71,-79:5,73,-79:6,71,-79:6,73,-79:7,71,-79:7,73,-79:7,74,-79:7,75,-79:7,75,-78:7,76,-78:7,77,-78:7,69,-67:7,70,-67:7,71,-67:7,71,-66:7,71,-65:7,69,-64:7,70,-64:7,71,-64:8,71,-79:8,77,-78:8,66,-74:8,67,-74:8,68,-74:8,68,-73:8,68,-72:8,68,-71:8,68,-70:8,68,-69:8,69,-69:8,70,-69:8,71,-69:8,69,-67:8,69,-64:9,71,-79:9,77,-78:9,66,-74:9,71,-69:9,69,-67:9,69,-64:10,71,-79:10,72,-79:10,73,-79:10,74,-79:10,75,-79:10,75,-78:10,76,-78:10,77,-78:10,66,-74:10,68,-74:10,69,-74:10,70,-74:10,71,-74:10,71,-73:10,69,-72:10,70,-72:10,71,-72:10,69,-71:10,69,-70:10,69,-69:10,70,-69:10,71,-69:10,69,-67:10,70,-67:10,71,-67:10,71,-66:10,71,-65:10,69,-64:10,70,-64:10,71,-64:11,66,-74:11,68,-74:12,66,-74:12,68,-74:13,75,-80:13,76,-80:13,77,-80:13,75,-79:13,75,-78:13,75,-77:13,76,-77:13,77,-77:13,66,-74:13,68,-74:13,69,-74:13,70,-74:13,71,-74:13,72,-74:13,71,-67:13,71,-66:13,71,-65:13,69,-64:13,70,-64:13,71,-64:13,69,-63:13,69,-62:13,69,-61:13,69,-60:13,69,-59:13,69,-58:14,77,-80:14,77,-77:14,66,-74:14,72,-74:14,71,-67:14,69,-58:15,77,-80:15,77,-77:15,66,-74:15,71,-74:15,72,-74:15,69,-67:15,70,-67:15,71,-67:15,69,-58:16,75,-80:16,76,-80:16,77,-80:16,75,-79:16,75,-78:16,75,-77:16,76,-77:16,77,-77:16,66,-74:16,71,-74:16,69,-67:16,69,-58:17,66,-74:17,71,-74:17,69,-67:17,69,-58:18,66,-74:18,71,-74:18,72,-74:18,73,-74:18,69,-67:18,70,-67:18,69,-58:19,74,-79:19,74,-78:19,74,-77:19,66,-74:19,73,-74:19,70,-67:19,67,-62:19,68,-62:19,69,-62:19,69,-61:19,69,-60:19,69,-59:19,69,-58:20,74,-79:20,74,-77:20,66,-74:20,67,-74:20,68,-74:20,69,-74:20,70,-74:20,71,-74:20,72,-74:20,73,-74:20,68,-67:20,69,-67:20,70,-67:20,67,-62:21,72,-79:21,73,-79:21,74,-79:21,72,-78:21,72,-77:21,73,-77:21,74,-77:21,68,-67:21,67,-62:22,68,-67:22,69,-67:22,70,-67:22,70,-66:22,69,-65:22,70,-65:22,69,-64:22,69,-63:22,67,-62:22,68,-62:22,69,-62:";
|
||||
|
||||
ArrayList<Location> locs = new ArrayList<Location>();
|
||||
|
||||
for (String cur : locString.split(":"))
|
||||
{
|
||||
String[] tokens = cur.split(",");
|
||||
|
||||
try
|
||||
{
|
||||
Location loc = new Location(getWorld(), Integer.parseInt(tokens[0]), Integer.parseInt(tokens[1]), Integer.parseInt(tokens[2]));
|
||||
|
||||
if (InBoundary(loc))
|
||||
locs.add(loc);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("Invalid Hub Snake Location: " + cur);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ArrayList<ArrayList<Location>> snakes = new ArrayList<ArrayList<Location>>();
|
||||
|
||||
//Get Blacks
|
||||
Iterator<Location> locIterator = locs.iterator();
|
||||
while (locIterator.hasNext())
|
||||
{
|
||||
Location loc = locIterator.next();
|
||||
|
||||
if (loc.getBlock().getData() != 0)
|
||||
continue;
|
||||
|
||||
ArrayList<Location> newSnake = new ArrayList<Location>();
|
||||
newSnake.add(loc);
|
||||
snakes.add(newSnake);
|
||||
locIterator.remove();
|
||||
}
|
||||
|
||||
//Get Body
|
||||
int partsAdded = 1;
|
||||
while (partsAdded > 0)
|
||||
{
|
||||
partsAdded = 0;
|
||||
|
||||
locIterator = locs.iterator();
|
||||
while (locIterator.hasNext())
|
||||
{
|
||||
Location loc = locIterator.next();
|
||||
|
||||
if (loc.getBlock().getData() == 15)
|
||||
continue;
|
||||
|
||||
for (ArrayList<Location> snake : snakes)
|
||||
{
|
||||
if (UtilMath.offset(loc, snake.get(snake.size() - 1)) != 1)
|
||||
continue;
|
||||
|
||||
snake.add(loc);
|
||||
locIterator.remove();
|
||||
|
||||
partsAdded++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Get Tail
|
||||
try
|
||||
{
|
||||
locIterator = locs.iterator();
|
||||
while (locIterator.hasNext())
|
||||
{
|
||||
Location loc = locIterator.next();
|
||||
|
||||
for (ArrayList<Location> snake : snakes)
|
||||
{
|
||||
if (UtilMath.offset(loc, snake.get(snake.size() - 1)) != 1)
|
||||
continue;
|
||||
|
||||
snake.add(loc);
|
||||
locIterator.remove();
|
||||
|
||||
partsAdded++;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//Write
|
||||
try
|
||||
{
|
||||
File file = new File("SnakeRoutes.dat");
|
||||
if (!file.exists())
|
||||
file.createNewFile();
|
||||
|
||||
FileWriter fw = new FileWriter(file.getAbsoluteFile());
|
||||
BufferedWriter bw = new BufferedWriter(fw);
|
||||
|
||||
for (ArrayList<Location> snake : snakes)
|
||||
{
|
||||
String out = "";
|
||||
|
||||
for (Location loc : snake)
|
||||
out += loc.getBlockX() + "," + loc.getBlockY() + "," + loc.getBlockZ() + ":";
|
||||
|
||||
bw.write(out + "\n\n\n");
|
||||
}
|
||||
|
||||
bw.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (_snakes == null)
|
||||
return;
|
||||
|
||||
for (SnakePart snake : _snakes)
|
||||
snake.Update();
|
||||
}
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
package mineplex.hub.modules.parkour;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import mineplex.core.common.util.MapUtil;
|
||||
import mineplex.core.common.util.UtilBlock;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilParticle;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.common.util.UtilParticle.ParticleType;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class SnakePart
|
||||
{
|
||||
private ArrayList<Location> _path = new ArrayList<Location>();
|
||||
private byte _color = 0;
|
||||
|
||||
private int _index = 0;
|
||||
private boolean _colorTick = false;
|
||||
|
||||
private int _pathId = 39;
|
||||
|
||||
public SnakePart(ArrayList<Location> path)
|
||||
{
|
||||
_path = path;
|
||||
|
||||
_color = path.get(1).getBlock().getData();
|
||||
|
||||
for (Location loc : path)
|
||||
MapUtil.QuickChangeBlockAt(loc, 35, _color);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (_path.isEmpty())
|
||||
return;
|
||||
|
||||
//Set Block
|
||||
sendBlock(_path.get(_index), 35, GetColor());
|
||||
|
||||
int back = _index - 10;
|
||||
while (back < 0)
|
||||
back += _path.size();
|
||||
|
||||
//Unset Tail
|
||||
sendBlock(_path.get(back), _pathId, (byte) 0);
|
||||
|
||||
//ALT
|
||||
if (_path.size() > 50)
|
||||
{
|
||||
int newIndex = (_index + (_path.size()/2))%_path.size();
|
||||
|
||||
//Set Block
|
||||
sendBlock(_path.get(newIndex), 35, GetColor());
|
||||
|
||||
back = newIndex - 10;
|
||||
if (back < 0)
|
||||
back += _path.size();
|
||||
|
||||
//Unset Tail
|
||||
sendBlock(_path.get(back), _pathId, (byte) 0);
|
||||
}
|
||||
|
||||
_index = (_index+1)%_path.size();
|
||||
_colorTick = !_colorTick;
|
||||
|
||||
/*
|
||||
for (Location loc : _path)
|
||||
if (loc.getBlock().getType() == Material.AIR)
|
||||
UtilParticle.PlayParticle(ParticleType.CRIT, loc, 0, 0, 0, 0, 1);
|
||||
*/
|
||||
}
|
||||
|
||||
public void sendBlock(Location loc, int id, byte data)
|
||||
{
|
||||
MapUtil.ChunkBlockChange(loc, id, data, false);
|
||||
|
||||
|
||||
for (Player player : UtilServer.getPlayers())
|
||||
{
|
||||
if (UtilMath.offset(player.getLocation(), loc) < 64)
|
||||
{
|
||||
player.sendBlockChange(loc, Material.getMaterial(id), data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public byte GetColor()
|
||||
{
|
||||
if (_colorTick)
|
||||
return _color;
|
||||
return _color;
|
||||
}
|
||||
}
|
@ -18,28 +18,42 @@ import mineplex.hub.world.WorldDataModule;
|
||||
public class ParkourData implements Listener
|
||||
{
|
||||
|
||||
protected final ParkourManager _manager;
|
||||
private final String _name;
|
||||
private final List<Location> _checkpoints;
|
||||
private final Location _reset;
|
||||
private final Location _cornerA;
|
||||
private final Location _cornerB;
|
||||
private static final int MAX_FALL_DISTANCE = 7;
|
||||
private static final double CHECKPOINT_PERCENTAGE = 0.8;
|
||||
|
||||
public ParkourData(ParkourManager manager, String name)
|
||||
protected final ParkourManager _manager;
|
||||
private final String _name, _key;
|
||||
private final String[] _description;
|
||||
private final int _difficulty;
|
||||
private final List<Location> _checkpoints;
|
||||
protected final Location _reset;
|
||||
private final Location _teleport, _cornerA, _cornerB;
|
||||
|
||||
public ParkourData(ParkourManager manager, String name, String[] description, int difficulty)
|
||||
{
|
||||
this(manager, name, name.toUpperCase(), description, difficulty);
|
||||
}
|
||||
|
||||
public ParkourData(ParkourManager manager, String name, String key, String[] description, int difficulty)
|
||||
{
|
||||
_manager = manager;
|
||||
_name = name;
|
||||
|
||||
name = name.toUpperCase();
|
||||
_key = key;
|
||||
_description = description;
|
||||
_difficulty = difficulty;
|
||||
|
||||
WorldDataModule worldData = manager.getWorldData();
|
||||
List<Location> corners = worldData.getCustomLocation(name + " BORDER");
|
||||
List<Location> lookAt = worldData.getCustomLocation("LOOK AT");
|
||||
_checkpoints = worldData.getCustomLocation(name + " CHECK");
|
||||
_reset = worldData.getCustomLocation(name + " RESET").get(0);
|
||||
UtilAlg.lookAtNearest(_reset, lookAt);
|
||||
List<Location> corners = worldData.getCustomLocation(key + " BORDER");
|
||||
_checkpoints = worldData.getCustomLocation(key + " CHECK");
|
||||
_reset = worldData.getCustomLocation(key + " RESET").get(0);
|
||||
UtilAlg.lookAtNearest(_reset, manager.getHubManager().getLookAt());
|
||||
_teleport = worldData.getCustomLocation(key + " TELEPORT").get(0);
|
||||
UtilAlg.lookAtNearest(_teleport, manager.getHubManager().getLookAt());
|
||||
|
||||
_cornerA = corners.get(0);
|
||||
_cornerA.setY(0);
|
||||
_cornerB = corners.get(1);
|
||||
_cornerB.setY(_cornerB.getWorld().getMaxHeight());
|
||||
|
||||
UtilServer.RegisterEvents(this);
|
||||
}
|
||||
@ -72,14 +86,14 @@ public class ParkourData implements Listener
|
||||
}
|
||||
}
|
||||
|
||||
protected void reset(Player player)
|
||||
public void reset(Player player)
|
||||
{
|
||||
player.teleport(_reset);
|
||||
}
|
||||
|
||||
protected boolean hasFailed(Player player)
|
||||
{
|
||||
return UtilEnt.isInWater(player);
|
||||
return player.getFallDistance() > MAX_FALL_DISTANCE || UtilEnt.isInWater(player);
|
||||
}
|
||||
|
||||
public String getName()
|
||||
@ -89,12 +103,27 @@ public class ParkourData implements Listener
|
||||
|
||||
public String getKey()
|
||||
{
|
||||
return _name.toUpperCase();
|
||||
return _key;
|
||||
}
|
||||
|
||||
public String[] getDescription()
|
||||
{
|
||||
return _description;
|
||||
}
|
||||
|
||||
public int getDifficulty()
|
||||
{
|
||||
return _difficulty;
|
||||
}
|
||||
|
||||
public Location getTeleport()
|
||||
{
|
||||
return _teleport;
|
||||
}
|
||||
|
||||
public boolean cheatCheck(ParkourAttempt attempt)
|
||||
{
|
||||
return attempt.getCheckpoints().size() > (_checkpoints.size() * 0.8D);
|
||||
return attempt.getCheckpoints().size() > (_checkpoints.size() * CHECKPOINT_PERCENTAGE);
|
||||
}
|
||||
|
||||
public boolean isInArea(Location location)
|
||||
|
@ -2,87 +2,132 @@ package mineplex.hub.parkour;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.event.player.PlayerVelocityEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilEvent;
|
||||
import mineplex.core.common.util.UtilEvent.ActionType;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilTextBottom;
|
||||
import mineplex.core.gadget.GadgetManager;
|
||||
import mineplex.core.gadget.event.GadgetBlockEvent;
|
||||
import mineplex.core.gadget.event.GadgetCollideEntityEvent;
|
||||
import mineplex.core.gadget.event.GadgetEnableEvent;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.core.newnpc.NPC;
|
||||
import mineplex.core.newnpc.NewNPCManager;
|
||||
import mineplex.core.newnpc.event.NPCInteractEvent;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
import mineplex.core.teleport.event.MineplexTeleportEvent;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.hub.HubManager;
|
||||
import mineplex.hub.doublejump.DoubleJumpPrepareEvent;
|
||||
import mineplex.hub.parkour.data.Snake;
|
||||
import mineplex.hub.parkour.data.SnakeParkourData;
|
||||
import mineplex.hub.parkour.data.WaterParkourData;
|
||||
import mineplex.hub.parkour.data.SprintingParkourData;
|
||||
import mineplex.hub.player.HubPlayerManager;
|
||||
import mineplex.hub.world.WorldDataModule;
|
||||
|
||||
@ReflectivelyCreateMiniPlugin
|
||||
public class ParkourManager extends MiniPlugin
|
||||
{
|
||||
|
||||
public static final int DIFFICULTY_EASY = 0;
|
||||
public static final int DIFFICULTY_MEDIUM = 1;
|
||||
public static final int DIFFICULTY_HARD = 2;
|
||||
private static final ItemStack RESTART_ITEM = new ItemBuilder(Material.FEATHER)
|
||||
.setTitle(C.cGreenB + "Reset your time")
|
||||
.addLore("Click me to restart your parkour", "time!")
|
||||
.build();
|
||||
|
||||
private final HubManager _hubManager;
|
||||
private final HubPlayerManager _hubPlayerManager;
|
||||
private final GadgetManager _gadgetManager;
|
||||
private final WorldDataModule _worldData;
|
||||
|
||||
private final Map<Player, ParkourAttempt> _attempts;
|
||||
private final Set<ParkourData> _parkours;
|
||||
private final List<ParkourData> _parkours;
|
||||
|
||||
private ParkourManager()
|
||||
{
|
||||
super("Parkour");
|
||||
|
||||
_hubManager = require(HubManager.class);
|
||||
_hubPlayerManager = require(HubPlayerManager.class);
|
||||
_gadgetManager = require(GadgetManager.class);
|
||||
_worldData = require(WorldDataModule.class);
|
||||
|
||||
_attempts = new HashMap<>();
|
||||
_parkours = new HashSet<>();
|
||||
_parkours = new ArrayList<>();
|
||||
|
||||
// _parkours.add(new ParkourData(this, "House"));
|
||||
// _parkours.add(new WaterParkourData(this));
|
||||
//
|
||||
// List<Snake> snakes = new ArrayList<>();
|
||||
// List<Location> path = _worldData.getCustomLocation(String.valueOf(Material.QUARTZ_ORE.getId()));
|
||||
//
|
||||
// for (Location head : _worldData.getDataLocation("LIGHT_BLUE"))
|
||||
// {
|
||||
// snakes.add(new Snake(head, path));
|
||||
// }
|
||||
//
|
||||
// _parkours.add(new SnakeParkourData(this, snakes));
|
||||
//
|
||||
// NewNPCManager npcManager = require(NewNPCManager.class);
|
||||
//
|
||||
// for (ParkourData data : _parkours)
|
||||
// {
|
||||
// npcManager.spawnNPCs(data.getKey() + " START", null);
|
||||
// npcManager.spawnNPCs(data.getKey() + " END", null);
|
||||
// }
|
||||
_parkours.add(new ParkourData(this, "HayYou", new String[]
|
||||
{
|
||||
"Jump fast and jump quick, just don't",
|
||||
"stick around long enough to wave to",
|
||||
"everyone or you'll have a bad time!"
|
||||
}, DIFFICULTY_EASY));
|
||||
|
||||
List<Snake> snakes = new ArrayList<>();
|
||||
List<Location> path = _worldData.getCustomLocation(String.valueOf(Material.QUARTZ_ORE.getId()));
|
||||
|
||||
for (Location head : _worldData.getDataLocation("LIGHT_BLUE"))
|
||||
{
|
||||
snakes.add(new Snake(head, path));
|
||||
}
|
||||
|
||||
_parkours.add(new SnakeParkourData(this, snakes));
|
||||
|
||||
|
||||
_parkours.add(new SprintingParkourData(this, "Splinter", new String[]
|
||||
{
|
||||
"Don't poke around to much or",
|
||||
"you might hurt yourself. You have",
|
||||
"to go fast to beat this one!"
|
||||
}, DIFFICULTY_MEDIUM));
|
||||
_parkours.add(new ParkourData(this, "Ruins", new String[]
|
||||
{
|
||||
"Something was here at some point,",
|
||||
"we aren't sure what, but you are free to",
|
||||
"jump around it a whole bunch."
|
||||
}, DIFFICULTY_MEDIUM));
|
||||
_parkours.add(new ParkourData(this, "Mystery Pillars", "HOUSE", new String[]
|
||||
{
|
||||
"This house came from the sky, only to leave",
|
||||
"these weird pillars all over the place. See",
|
||||
"if you can reach the top and collect it's prize!"
|
||||
}, DIFFICULTY_HARD));
|
||||
|
||||
NewNPCManager npcManager = require(NewNPCManager.class);
|
||||
|
||||
for (ParkourData data : _parkours)
|
||||
{
|
||||
npcManager.spawnNPCs(data.getKey() + " START", null);
|
||||
npcManager.spawnNPCs(data.getKey() + " END", null);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isParkourMode(Player player)
|
||||
public boolean isParkourMode(Entity player)
|
||||
{
|
||||
return _attempts.containsKey(player);
|
||||
return player instanceof Player && _attempts.containsKey(player);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -110,8 +155,9 @@ public class ParkourManager extends MiniPlugin
|
||||
|
||||
if (!attempt.getData().isInArea(playerLocation))
|
||||
{
|
||||
player.sendMessage(F.main(_moduleName, "You left the Parkour area."));
|
||||
attempt.getData().onEnd(player);
|
||||
_hubPlayerManager.giveHotbar(player);
|
||||
player.sendMessage(F.main(_moduleName, "You left the " + F.name("Parkour") + " area."));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -127,10 +173,7 @@ public class ParkourManager extends MiniPlugin
|
||||
return;
|
||||
}
|
||||
|
||||
_attempts.forEach((player, attempt) ->
|
||||
{
|
||||
UtilTextBottom.display(C.cGreenB + "Time: " + C.cPurple + ((System.currentTimeMillis() - attempt.getStart()) / 1000D) + " seconds", player);
|
||||
});
|
||||
_attempts.forEach((player, attempt) -> UtilTextBottom.display(C.cGreenB + "Time: " + C.cPurple + ((System.currentTimeMillis() - attempt.getStart()) / 1000D) + " seconds", player));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -155,7 +198,7 @@ public class ParkourManager extends MiniPlugin
|
||||
{
|
||||
if (!isParkourMode(player))
|
||||
{
|
||||
player.sendMessage(F.main(_moduleName, "You must be in parkour mode in order to complete parkour."));
|
||||
player.sendMessage(F.main(_moduleName, "You must be in " + F.name("Parkour mode") + " in order to complete parkour."));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -171,18 +214,36 @@ public class ParkourManager extends MiniPlugin
|
||||
double duration = (attempt.getDuration() / 1000D);
|
||||
player.sendMessage(F.main(_moduleName, "You completed " + F.name(data.getName()) + " in " + F.elem(duration) + " seconds."));
|
||||
rewardPlayer(player, data);
|
||||
_hubPlayerManager.giveHotbar(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void startParkour(Player player, ParkourData data)
|
||||
{
|
||||
if (_hubManager.getHubGameManager().inQueue(player))
|
||||
{
|
||||
player.sendMessage(F.main(_moduleName, "You cannot go into " + F.name("Parkour") + " when queueing for a game."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (isParkourMode(player))
|
||||
{
|
||||
player.sendMessage(F.main(_moduleName, "Reset your time for " + F.name(data.getName()) + "."));
|
||||
}
|
||||
else
|
||||
{
|
||||
_gadgetManager.disableAll(player);
|
||||
|
||||
_gadgetManager.disableAll(player);
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
|
||||
inventory.clear();
|
||||
inventory.setItem(0, RESTART_ITEM);
|
||||
inventory.setHeldItemSlot(0);
|
||||
}
|
||||
|
||||
player.setAllowFlight(false);
|
||||
player.setFallDistance(0);
|
||||
player.sendMessage(F.main(_moduleName, "Started " + F.name(data.getName()) + "."));
|
||||
_attempts.put(player, new ParkourAttempt(data));
|
||||
data.onStart(player);
|
||||
@ -200,6 +261,27 @@ public class ParkourManager extends MiniPlugin
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerInteract(PlayerInteractEvent event)
|
||||
{
|
||||
if (!UtilEvent.isAction(event, ActionType.R))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
ItemStack itemStack = player.getItemInHand();
|
||||
ParkourAttempt attempt = _attempts.get(player);
|
||||
|
||||
if (itemStack == null || !itemStack.equals(RESTART_ITEM) || attempt == null || !Recharge.Instance.use(player, "Restart Parkour", 1000, false, false))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
attempt.getData().reset(player);
|
||||
startParkour(player, attempt.getData());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerVelocity(PlayerVelocityEvent event)
|
||||
{
|
||||
@ -218,6 +300,24 @@ public class ParkourManager extends MiniPlugin
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void gadgetBlock(GadgetBlockEvent event)
|
||||
{
|
||||
for (ParkourData data : _parkours)
|
||||
{
|
||||
event.getBlocks().removeIf(block -> data.isInArea(block.getLocation()));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void gadgetCollide(GadgetCollideEntityEvent event)
|
||||
{
|
||||
if (isParkourMode(event.getEntity()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void doubleJump(DoubleJumpPrepareEvent event)
|
||||
{
|
||||
@ -237,6 +337,7 @@ public class ParkourManager extends MiniPlugin
|
||||
if (_attempts.remove(player) != null)
|
||||
{
|
||||
player.sendMessage(F.main(_moduleName, "You can't teleport during parkour."));
|
||||
_hubPlayerManager.giveHotbar(player);
|
||||
}
|
||||
}
|
||||
|
||||
@ -251,14 +352,14 @@ public class ParkourManager extends MiniPlugin
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onTeam(PlayerCommandPreprocessEvent event)
|
||||
public List<ParkourData> getParkours()
|
||||
{
|
||||
if (event.getMessage().startsWith("/team ") && isParkourMode(event.getPlayer()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(F.main("Team", "You cannot join a team while in parkour mode!"));
|
||||
}
|
||||
return _parkours;
|
||||
}
|
||||
|
||||
public HubManager getHubManager()
|
||||
{
|
||||
return _hubManager;
|
||||
}
|
||||
|
||||
public WorldDataModule getWorldData()
|
||||
|
@ -2,7 +2,6 @@ package mineplex.hub.parkour.data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
@ -11,17 +10,20 @@ import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.hub.parkour.ParkourData;
|
||||
import mineplex.hub.parkour.ParkourManager;
|
||||
|
||||
public class SnakeParkourData extends ParkourData implements Listener
|
||||
public class SnakeParkourData extends ParkourData
|
||||
{
|
||||
|
||||
private static final int MAX_FALL_DISTANCE = 3;
|
||||
|
||||
private final ParkourManager _manager;
|
||||
private final List<Snake> _snakes;
|
||||
|
||||
public SnakeParkourData(ParkourManager manager, List<Snake> snakes)
|
||||
{
|
||||
super(manager, "Snake");
|
||||
super(manager, "Snake", new String[]
|
||||
{
|
||||
"You have to be sssssssslipery",
|
||||
"to sssssneak past this parkour",
|
||||
"with no mistakes"
|
||||
}, ParkourManager.DIFFICULTY_MEDIUM);
|
||||
|
||||
_manager = manager;
|
||||
_snakes = snakes;
|
||||
@ -37,10 +39,4 @@ public class SnakeParkourData extends ParkourData implements Listener
|
||||
|
||||
_snakes.forEach(Snake::update);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasFailed(Player player)
|
||||
{
|
||||
return super.hasFailed(player) || player.getFallDistance() > MAX_FALL_DISTANCE;
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user