Tidy up mounts and implement the mount skins
This commit is contained in:
parent
8ee5faf4d9
commit
ece1461384
@ -2,6 +2,8 @@ package mineplex.game.clans.clans.mounts;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftHorse;
|
||||
import org.bukkit.entity.EntityType;
|
||||
@ -13,8 +15,16 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import mineplex.core.common.TriConsumer;
|
||||
import mineplex.core.common.util.C;
|
||||
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.UtilServer;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.disguise.disguises.DisguiseBase;
|
||||
import mineplex.core.disguise.disguises.DisguiseCow;
|
||||
import mineplex.core.disguise.disguises.DisguiseSheep;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.game.clans.clans.ClansManager;
|
||||
import net.minecraft.server.v1_8_R3.GenericAttributes;
|
||||
|
||||
public class Mount
|
||||
@ -64,6 +74,16 @@ public class Mount
|
||||
public void despawn(boolean forced)
|
||||
{
|
||||
UtilServer.CallEvent(new MountDespawnEvent(this, forced));
|
||||
_entity.getInventory().setSaddle(null);
|
||||
_entity.getInventory().setArmor(null);
|
||||
for (ItemStack item : _entity.getInventory().getContents())
|
||||
{
|
||||
if (item == null || item.getType() == Material.AIR)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
_entity.getWorld().dropItem(_entity.getLocation(), item);
|
||||
}
|
||||
_entity.remove();
|
||||
}
|
||||
|
||||
@ -78,25 +98,108 @@ public class Mount
|
||||
|
||||
public static enum SkinType
|
||||
{
|
||||
INFERNAL_HORROR(1, "Clans Infernal Horror Mount Skin", C.cRed + "Infernal Horror", Material.BONE, Color.BLACK, Variant.SKELETON_HORSE, Style.BLACK_DOTS, horse -> {}, horse ->
|
||||
{
|
||||
UtilParticle.PlayParticleToAll(ParticleType.FLAME, horse.getLocation().add(0, 1, 0),
|
||||
0.25f, 0.25f, 0.25f, 0, 2,ViewDist.NORMAL);
|
||||
}, MountType.HORSE),
|
||||
GLACIAL_STEED(2, "Clans Glacial Steed Mount Skin", C.cGray + "Glacial Steed", Material.SNOW_BALL, Color.WHITE, Variant.HORSE, Style.WHITE, horse -> {}, horse ->
|
||||
{
|
||||
UtilParticle.PlayParticleToAll(ParticleType.SNOW_SHOVEL, horse.getLocation().add(0, 1, 0),
|
||||
0.25f, 0.25f, 0.25f, 0.1f, 4, ViewDist.NORMAL);
|
||||
}, MountType.HORSE),
|
||||
ZOMBIE_HORSE(3, "Clans Zombie Horse Mount Skin", C.cDGray + "Zombie Horse", Material.ROTTEN_FLESH, Color.BLACK, Variant.UNDEAD_HORSE, Style.BLACK_DOTS, horse -> {}, horse ->
|
||||
{
|
||||
UtilParticle.PlayParticleToAll(ParticleType.FOOTSTEP, horse.getLocation(),
|
||||
null, 0, 1, ViewDist.NORMAL);
|
||||
}, MountType.HORSE),
|
||||
@SuppressWarnings("deprecation")
|
||||
RAINBOW_SHEEP(4, "Clans Rainbow Sheep Mount Skin", C.cGreen + "Rainbow " + C.cAqua + "Sheep", new ItemBuilder(Material.WOOL).setData(DyeColor.RED.getWoolData()).build(),Color.WHITE, Variant.HORSE, Style.NONE, horse ->
|
||||
{
|
||||
DisguiseSheep disguise = new DisguiseSheep(horse);
|
||||
disguise.setName(horse.getCustomName());
|
||||
ClansManager.getInstance().getDisguiseManager().disguise(disguise);
|
||||
}, horse ->
|
||||
{
|
||||
DisguiseBase base = ClansManager.getInstance().getDisguiseManager().getActiveDisguise(horse);
|
||||
if (base == null || !(base instanceof DisguiseSheep))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DisguiseSheep sheep = (DisguiseSheep)base;
|
||||
|
||||
if (horse.getTicksLived() % 4 == 0) sheep.setColor(DyeColor.RED);
|
||||
else if (horse.getTicksLived() % 4 == 1) sheep.setColor(DyeColor.YELLOW);
|
||||
else if (horse.getTicksLived() % 4 == 2) sheep.setColor(DyeColor.GREEN);
|
||||
else if (horse.getTicksLived() % 4 == 3) sheep.setColor(DyeColor.BLUE);
|
||||
}, MountType.HORSE),
|
||||
ROYAL_STEED(5, "Clans Royal Steed Mount Skin", C.cGold + "Royal Steed", Material.DIAMOND_BARDING, Color.WHITE, Variant.HORSE, Style.WHITE, horse ->
|
||||
{
|
||||
horse.getInventory().setArmor(new ItemBuilder(Material.DIAMOND_BARDING).setTitle(C.cGoldB + "Royal Armor").build());
|
||||
}, horse ->
|
||||
{
|
||||
UtilParticle.PlayParticleToAll(ParticleType.BLOCK_DUST.getParticle(Material.GOLD_BLOCK, 0), horse.getLocation().add(0, 1, 0),
|
||||
0.25f, 0.25f, 0.25f, 0, 3, ViewDist.NORMAL);
|
||||
}, MountType.HORSE),
|
||||
ROYAL_GUARD_STEED(6, "Clans Royal Guard Steed Mount Skin", C.cGray + "Royal Guard's Steed", Material.GOLD_BARDING, Color.BLACK, Variant.HORSE, Style.NONE, horse ->
|
||||
{
|
||||
horse.getInventory().setArmor(new ItemBuilder(Material.GOLD_BARDING).setTitle(C.cGoldB + "Guardian Armor").build());
|
||||
}, horse ->
|
||||
{
|
||||
UtilParticle.PlayParticleToAll(ParticleType.BLOCK_DUST.getParticle(Material.IRON_BLOCK, 0), horse.getLocation().add(0, 1, 0),
|
||||
0.25f, 0.25f, 0.25f, 0, 3, ViewDist.NORMAL);
|
||||
}, MountType.HORSE),
|
||||
KNIGHT_STEED(7, "Clans Knight Steed Mount Skin", C.cDRed + "Knight's Steed", Material.IRON_BARDING, Color.GRAY, Variant.HORSE, Style.NONE, horse ->
|
||||
{
|
||||
horse.getInventory().setArmor(new ItemBuilder(Material.IRON_BARDING).setTitle(C.cGoldB + "Knightly Armor").build());
|
||||
}, horse ->
|
||||
{
|
||||
UtilParticle.PlayParticleToAll(ParticleType.ICON_CRACK.getParticle(Material.APPLE, 0), horse.getLocation().add(0, 1, 0),
|
||||
0.25f, 0.25f, 0.25f, 0, 3, ViewDist.NORMAL);
|
||||
}, MountType.HORSE),
|
||||
COW(8, "Clans Cow Mount Skin", C.cWhite + "Cow", Material.MILK_BUCKET, Color.WHITE, Variant.HORSE, Style.NONE, horse ->
|
||||
{
|
||||
DisguiseCow disguise = new DisguiseCow(horse);
|
||||
disguise.setName(horse.getCustomName());
|
||||
ClansManager.getInstance().getDisguiseManager().disguise(disguise);
|
||||
}, horse -> {}, MountType.HORSE),
|
||||
SHEEP(9, "Clans Sheep Mount Skin", C.cWhite + "Sheep", Material.WOOL, Color.WHITE, Variant.HORSE, Style.NONE, horse ->
|
||||
{
|
||||
DisguiseSheep disguise = new DisguiseSheep(horse);
|
||||
disguise.setName(horse.getCustomName());
|
||||
ClansManager.getInstance().getDisguiseManager().disguise(disguise);
|
||||
}, horse -> {}, MountType.HORSE),
|
||||
TRUSTY_MULE(10, "Clans Trusty Mule Mount Skin", C.cBlue + "Trusty Mule", Material.APPLE, Color.BROWN, Variant.MULE, Style.NONE, horse -> {}, horse -> {}, MountType.DONKEY)
|
||||
;
|
||||
|
||||
private final int _id;
|
||||
private final String _packageName;
|
||||
private final String _displayName;
|
||||
private final ItemStack _baseDisplayItem;
|
||||
private final Color _color;
|
||||
private final Variant _variant;
|
||||
private final Style _style;
|
||||
private final Consumer<CraftHorse> _onUpdate;
|
||||
private final Consumer<CraftHorse> _onSpawn, _onUpdate;
|
||||
private final MountType[] _possibleTypes;
|
||||
|
||||
private SkinType(int id, String packageName, String displayName, Color color, Variant variant, Style style, Consumer<CraftHorse> onUpdate)
|
||||
private SkinType(int id, String packageName, String displayName, Material displayType, Color color, Variant variant, Style style, Consumer<CraftHorse> onSpawn, Consumer<CraftHorse> onUpdate, MountType... possibleTypes)
|
||||
{
|
||||
this(id, packageName, displayName, new ItemStack(displayType), color, variant, style, onSpawn, onUpdate, possibleTypes);
|
||||
}
|
||||
|
||||
private SkinType(int id, String packageName, String displayName, ItemStack baseDisplayItem, Color color, Variant variant, Style style, Consumer<CraftHorse> onSpawn, Consumer<CraftHorse> onUpdate, MountType... possibleTypes)
|
||||
{
|
||||
_id = id;
|
||||
_packageName = packageName;
|
||||
_displayName = displayName;
|
||||
_baseDisplayItem = baseDisplayItem;
|
||||
_color = color;
|
||||
_variant = variant;
|
||||
_style = style;
|
||||
_onSpawn = onSpawn;
|
||||
_onUpdate = onUpdate;
|
||||
_possibleTypes = possibleTypes;
|
||||
}
|
||||
|
||||
public int getId()
|
||||
@ -114,6 +217,11 @@ public class Mount
|
||||
return _displayName;
|
||||
}
|
||||
|
||||
public ItemStack getBaseDisplay()
|
||||
{
|
||||
return _baseDisplayItem;
|
||||
}
|
||||
|
||||
public Color getColor()
|
||||
{
|
||||
return _color;
|
||||
@ -129,11 +237,21 @@ public class Mount
|
||||
return _style;
|
||||
}
|
||||
|
||||
public void onSpawn(CraftHorse horse)
|
||||
{
|
||||
_onSpawn.accept(horse);
|
||||
}
|
||||
|
||||
public void onUpdate(CraftHorse horse)
|
||||
{
|
||||
_onUpdate.accept(horse);
|
||||
}
|
||||
|
||||
public MountType[] getPossibleTypes()
|
||||
{
|
||||
return _possibleTypes;
|
||||
}
|
||||
|
||||
public static SkinType getFromId(int id)
|
||||
{
|
||||
for (SkinType type : SkinType.values())
|
||||
@ -156,19 +274,20 @@ public class Mount
|
||||
horse.setAdult();
|
||||
horse.setAgeLock(true);
|
||||
horse.setBreed(false);
|
||||
horse.setCustomNameVisible(true);
|
||||
horse.setCustomName(owner.getName() + "'s " + (skin == null ? "Horse" : ChatColor.stripColor(skin.getDisplayName())));
|
||||
if (skin != null)
|
||||
{
|
||||
horse.setVariant(skin.getVariant());
|
||||
horse.setColor(skin.getColor());
|
||||
horse.setStyle(skin.getStyle());
|
||||
skin.onSpawn(horse);
|
||||
}
|
||||
horse.setTamed(true);
|
||||
horse.getInventory().setSaddle(new ItemStack(Material.SADDLE));
|
||||
horse.setOwner(owner);
|
||||
horse.setJumpStrength(MountManager.getJump(stats.JumpStars));
|
||||
horse.getHandle().getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(MountManager.getSpeed(stats.SpeedStars));
|
||||
horse.setCustomNameVisible(true);
|
||||
horse.setCustomName(owner.getName() + "'s " + (skin == null ? "Horse" : skin.getDisplayName()));
|
||||
//horse.setPassenger(owner);
|
||||
Mount mount = new Mount(owner, horse, skin, MountManager.getStrength(stats.StrengthStars));
|
||||
UtilServer.CallEvent(new MountSpawnEvent(mount));
|
||||
@ -179,9 +298,12 @@ public class Mount
|
||||
horse.setAdult();
|
||||
horse.setAgeLock(true);
|
||||
horse.setBreed(false);
|
||||
horse.setCustomNameVisible(true);
|
||||
horse.setCustomName(owner.getName() + "'s " + (skin == null ? "Donkey" : ChatColor.stripColor(skin.getDisplayName())));
|
||||
if (skin != null)
|
||||
{
|
||||
horse.setVariant(skin.getVariant());
|
||||
skin.onSpawn(horse);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -192,8 +314,6 @@ public class Mount
|
||||
horse.setOwner(owner);
|
||||
horse.setJumpStrength(MountManager.getJump(stats.JumpStars));
|
||||
horse.getHandle().getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(MountManager.getSpeed(stats.SpeedStars));
|
||||
horse.setCustomNameVisible(true);
|
||||
horse.setCustomName(owner.getName() + "'s " + (skin == null ? "Donkey" : skin.getDisplayName()));
|
||||
horse.setCarryingChest(true);
|
||||
//horse.setPassenger(owner);
|
||||
Mount mount = new Mount(owner, horse, skin, MountManager.getStrength(stats.StrengthStars));
|
||||
|
@ -6,7 +6,6 @@ import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
@ -90,7 +89,7 @@ public class MountManager extends MiniDbClientPlugin<MountOwnerData>
|
||||
{
|
||||
if (args.length < 4)
|
||||
{
|
||||
UtilPlayer.message(caller, F.main(getName(), "Usage: /" + _aliasUsed + " <SPEED>, <JUMP>, <STRENGTH>, <TYPE>"));
|
||||
UtilPlayer.message(caller, F.main(getName(), "Usage: /" + _aliasUsed + " <SPEED> <JUMP> <STRENGTH> <TYPE>"));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -154,6 +153,14 @@ public class MountManager extends MiniDbClientPlugin<MountOwnerData>
|
||||
return _repository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable()
|
||||
{
|
||||
_summoning.clear();
|
||||
_spawnedMounts.keySet().forEach(CraftHorse::remove);
|
||||
_spawnedMounts.clear();
|
||||
}
|
||||
|
||||
public boolean summonMount(Player player, MountToken token)
|
||||
{
|
||||
if (_summoning.containsKey(player))
|
||||
@ -171,6 +178,11 @@ public class MountManager extends MiniDbClientPlugin<MountOwnerData>
|
||||
UtilPlayer.message(player, F.main(getName(), "You cannot summon a mount in the Nether!"));
|
||||
return false;
|
||||
}
|
||||
if (ClansManager.getInstance().getWorldEvent().getRaidManager().isInRaid(player.getLocation()))
|
||||
{
|
||||
UtilPlayer.message(player, F.main(getName(), "You cannot summon a mount inside a raid!"));
|
||||
return false;
|
||||
}
|
||||
if (!Recharge.Instance.usable(player, "Mount Spawn Delay"))
|
||||
{
|
||||
UtilPlayer.message(player, F.main(getName(), "You cannot summon a mount so soon after your last one was forcibly despawned!"));
|
||||
@ -194,6 +206,23 @@ public class MountManager extends MiniDbClientPlugin<MountOwnerData>
|
||||
_repository.saveMount(ClientManager.getAccountId(player), tokens.getLeft(), tokens.getRight());
|
||||
}
|
||||
|
||||
public void removeMountToken(Player player, MountToken token, Runnable after)
|
||||
{
|
||||
getRepository().deleteMount(token, id ->
|
||||
{
|
||||
Get(player).removeMount(id.intValue());
|
||||
Pair<Long, MountToken> summonPair = _summoning.get(player);
|
||||
if (summonPair != null)
|
||||
{
|
||||
if (summonPair.getRight().Id == id)
|
||||
{
|
||||
UtilEnt.addFlag(player, "REMOVED_MOUNT_TOKEN");
|
||||
}
|
||||
}
|
||||
after.run();
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onUpdate(UpdateEvent event)
|
||||
{
|
||||
@ -221,6 +250,18 @@ public class MountManager extends MiniDbClientPlugin<MountOwnerData>
|
||||
entry.getValue().despawn(false);
|
||||
continue;
|
||||
}
|
||||
if (ClansManager.getInstance().getNetherManager().isInNether(entry.getKey().getLocation()))
|
||||
{
|
||||
mountIterator.remove();
|
||||
entry.getValue().despawn(false);
|
||||
continue;
|
||||
}
|
||||
if (ClansManager.getInstance().getWorldEvent().getRaidManager().isInRaid(entry.getKey().getLocation()))
|
||||
{
|
||||
mountIterator.remove();
|
||||
entry.getValue().despawn(false);
|
||||
continue;
|
||||
}
|
||||
if (entry.getKey().getPassenger() == null)
|
||||
{
|
||||
if (UtilEnt.GetMetadata(entry.getKey(), "DISMOUNT_TIME") != null)
|
||||
@ -249,9 +290,31 @@ public class MountManager extends MiniDbClientPlugin<MountOwnerData>
|
||||
while (summoningIterator.hasNext())
|
||||
{
|
||||
Entry<Player, Pair<Long, MountToken>> entry = summoningIterator.next();
|
||||
if (UtilEnt.hasFlag(entry.getKey(), "REMOVED_MOUNT_TOKEN"))
|
||||
{
|
||||
summoningIterator.remove();
|
||||
UtilEnt.removeFlag(entry.getKey(), "REMOVED_MOUNT_TOKEN");
|
||||
continue;
|
||||
}
|
||||
if (UtilTime.elapsed(entry.getValue().getLeft(), SUMMON_WARMUP))
|
||||
{
|
||||
summoningIterator.remove();
|
||||
if (entry.getKey().isDead() || !entry.getKey().isValid() || !entry.getKey().isOnline())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (Spawn.getInstance().isSafe(entry.getKey().getLocation()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (ClansManager.getInstance().getNetherManager().isInNether(entry.getKey().getLocation()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (ClansManager.getInstance().getWorldEvent().getRaidManager().isInRaid(entry.getKey().getLocation()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
entry.getValue().getRight().Type.spawn(entry.getKey(), entry.getValue().getRight().Skin, Get(entry.getKey()).getStatToken(entry.getValue().getRight()));
|
||||
continue;
|
||||
}
|
||||
@ -333,20 +396,21 @@ public class MountManager extends MiniDbClientPlugin<MountOwnerData>
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void handleHits(CustomDamageEvent event)
|
||||
public void handleHorseHits(CustomDamageEvent event)
|
||||
{
|
||||
if (event.GetDamageeEntity() == null)
|
||||
if (event.GetDamageeEntity() == null || !(event.GetDamageeEntity() instanceof Horse))
|
||||
{
|
||||
return;
|
||||
}
|
||||
Mount[] spawned = _spawnedMounts.values().toArray(new Mount[_spawnedMounts.size()]);
|
||||
for (Mount mount : spawned)
|
||||
{
|
||||
if (mount.getEntity().getEntityId() == event.GetDamageeEntity().getEntityId())
|
||||
Mount mount = _spawnedMounts.get(event.GetDamageeEntity());
|
||||
if (mount == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (event.GetDamagerPlayer(true) != null && event.GetDamagerPlayer(true).getEntityId() == mount.getOwner().getEntityId())
|
||||
{
|
||||
event.SetCancelled("Damaging own mount");
|
||||
mount.despawn(false);
|
||||
return;
|
||||
}
|
||||
event.setDamagee(mount.getOwner());
|
||||
@ -354,17 +418,28 @@ public class MountManager extends MiniDbClientPlugin<MountOwnerData>
|
||||
{
|
||||
mount.handleHit();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void handleRiderHits(CustomDamageEvent event)
|
||||
{
|
||||
if (event.GetDamageePlayer() == null || event.GetDamageePlayer().getVehicle() == null || !(event.GetDamageePlayer().getVehicle() instanceof Horse))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (mount.getOwner().getEntityId() == event.GetDamageeEntity().getEntityId())
|
||||
if (event.GetDamagerPlayer(true) != null && event.GetDamagerPlayer(true).getEntityId() == event.GetDamageePlayer().getEntityId())
|
||||
{
|
||||
return;
|
||||
}
|
||||
Mount mount = _spawnedMounts.get(event.GetDamageePlayer().getVehicle());
|
||||
if (mount == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (event.GetCause() != DamageCause.FALL)
|
||||
{
|
||||
mount.handleHit();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -374,9 +449,15 @@ public class MountManager extends MiniDbClientPlugin<MountOwnerData>
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_spawnedMounts.containsKey(event.getClickedInventory().getHolder()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (event.getSlot() == 0 || event.getSlot() == 1)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void mountInteract(PlayerInteractEntityEvent event)
|
||||
@ -385,12 +466,12 @@ public class MountManager extends MiniDbClientPlugin<MountOwnerData>
|
||||
{
|
||||
return;
|
||||
}
|
||||
Optional<Mount> opt = _spawnedMounts.entrySet().stream().filter(entry -> entry.getKey().getEntityId() == event.getRightClicked().getEntityId()).map(Entry::getValue).findAny();
|
||||
if (!opt.isPresent())
|
||||
Mount mount = _spawnedMounts.get(event.getRightClicked());
|
||||
if (mount == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (opt.get().getOwner().getEntityId() == event.getPlayer().getEntityId())
|
||||
if (mount.getOwner().getEntityId() == event.getPlayer().getEntityId())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package mineplex.game.clans.clans.mounts;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
@ -11,7 +11,7 @@ import mineplex.game.clans.clans.mounts.Mount.MountType;
|
||||
|
||||
public class MountOwnerData
|
||||
{
|
||||
private Map<MountToken, MountStatToken> _mounts = new HashMap<>();
|
||||
private Map<MountToken, MountStatToken> _mounts = new LinkedHashMap<>();
|
||||
|
||||
public List<Pair<MountToken, MountStatToken>> getOwnedMounts(boolean onlyInitialized)
|
||||
{
|
||||
|
@ -36,6 +36,7 @@ public class MountOverviewPage extends ShopPageBase<MountManager, MountShop>
|
||||
{
|
||||
ItemBuilder builder = new ItemBuilder(mountToken.Type.getDisplayType());
|
||||
builder.setTitle(mountToken.Type.getDisplayName() + " Mount");
|
||||
builder.addLore(C.cPurple + "Skin: " + (mountToken.Skin == null ? C.cYellow + "Default" : mountToken.Skin.getDisplayName()));
|
||||
String strength = C.cYellow;
|
||||
for (int i = 0; i < statToken.StrengthStars; i++)
|
||||
{
|
||||
@ -93,8 +94,7 @@ public class MountOverviewPage extends ShopPageBase<MountManager, MountShop>
|
||||
}
|
||||
else if (clickType == ClickType.RIGHT)
|
||||
{
|
||||
playDenySound(player);
|
||||
//getShop().openPageForPlayer(player, page);
|
||||
getShop().openPageForPlayer(player, new MountSkinPage(this, player, tokens.getLeft()));
|
||||
}
|
||||
else if (clickType == ClickType.SHIFT_RIGHT)
|
||||
{
|
||||
@ -106,9 +106,8 @@ public class MountOverviewPage extends ShopPageBase<MountManager, MountShop>
|
||||
@Override
|
||||
public void process(ConfirmationCallback callback)
|
||||
{
|
||||
getPlugin().getRepository().deleteMount(tokens.getLeft(), id ->
|
||||
getPlugin().removeMountToken(player, tokens.getLeft(), () ->
|
||||
{
|
||||
getPlugin().Get(getPlayer()).removeMount(id.intValue());
|
||||
MountOverviewPage.this.refresh();
|
||||
callback.resolve("Mount successfully deleted!");
|
||||
});
|
||||
@ -139,8 +138,7 @@ public class MountOverviewPage extends ShopPageBase<MountManager, MountShop>
|
||||
}
|
||||
else if (clickType == ClickType.RIGHT)
|
||||
{
|
||||
playDenySound(player);
|
||||
//getShop().openPageForPlayer(player, page);
|
||||
getShop().openPageForPlayer(player, new MountSkinPage(this, player, tokens.getLeft()));
|
||||
}
|
||||
else if (clickType == ClickType.SHIFT_RIGHT)
|
||||
{
|
||||
@ -152,9 +150,8 @@ public class MountOverviewPage extends ShopPageBase<MountManager, MountShop>
|
||||
@Override
|
||||
public void process(ConfirmationCallback callback)
|
||||
{
|
||||
getPlugin().getRepository().deleteMount(tokens.getLeft(), id ->
|
||||
getPlugin().removeMountToken(player, tokens.getLeft(), () ->
|
||||
{
|
||||
getPlugin().Get(getPlayer()).removeMount(id.intValue());
|
||||
MountOverviewPage.this.refresh();
|
||||
callback.resolve("Mount successfully deleted!");
|
||||
});
|
||||
|
@ -0,0 +1,142 @@
|
||||
package mineplex.game.clans.clans.mounts.gui;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.core.shop.page.ShopPageBase;
|
||||
import mineplex.game.clans.clans.mounts.Mount.SkinType;
|
||||
import mineplex.game.clans.clans.mounts.MountManager;
|
||||
import mineplex.game.clans.clans.mounts.MountToken;
|
||||
|
||||
public class MountSkinPage extends ShopPageBase<MountManager, MountShop>
|
||||
{
|
||||
private MountOverviewPage _overview;
|
||||
private MountToken _token;
|
||||
|
||||
public MountSkinPage(MountOverviewPage overview, Player player, MountToken token)
|
||||
{
|
||||
super(overview.getPlugin(), overview.getShop(), overview.getClientManager(), overview.getDonationManager(), "Skin Management", player, 54);
|
||||
|
||||
_overview = overview;
|
||||
_token = token;
|
||||
buildPage();
|
||||
}
|
||||
|
||||
private List<SkinType> getAllowed()
|
||||
{
|
||||
List<SkinType> allowed = new LinkedList<>();
|
||||
|
||||
for (SkinType type : SkinType.values())
|
||||
{
|
||||
if (Arrays.asList(type.getPossibleTypes()).contains(_token.Type))
|
||||
{
|
||||
allowed.add(type);
|
||||
}
|
||||
}
|
||||
|
||||
return allowed;
|
||||
}
|
||||
|
||||
private boolean hasUnlocked(Player player, SkinType type)
|
||||
{
|
||||
if (getClientManager().Get(player).GetRank().has(Rank.ADMIN))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return getDonationManager().Get(player).ownsUnknownSalesPackage(type.getPackageName());
|
||||
}
|
||||
|
||||
private boolean hasUnlocked(SkinType type)
|
||||
{
|
||||
return hasUnlocked(getPlayer(), type);
|
||||
}
|
||||
|
||||
private ItemStack buildResetItem()
|
||||
{
|
||||
ItemBuilder builder = new ItemBuilder(Material.WATER_BUCKET);
|
||||
|
||||
builder.setTitle(C.cYellow + "Default Skin");
|
||||
if (_token.Skin == null)
|
||||
{
|
||||
builder.setLore(C.cRed, C.cGreenB + "SELECTED");
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private ItemStack buildSkinItem(SkinType type)
|
||||
{
|
||||
ItemBuilder builder = new ItemBuilder(type.getBaseDisplay());
|
||||
|
||||
builder.setTitle(type.getDisplayName());
|
||||
builder.setLore(C.cRed);
|
||||
if (_token.Skin == type)
|
||||
{
|
||||
builder.addLore(C.cGreenB + "SELECTED");
|
||||
}
|
||||
else if (hasUnlocked(type))
|
||||
{
|
||||
builder.addLore(C.cGreenB + "UNLOCKED");
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.addLore(C.cGray + "Available at http://www.mineplex.com/shop");
|
||||
builder.addLore(C.cRedB + "LOCKED");
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildPage()
|
||||
{
|
||||
addButton(0, new ItemBuilder(Material.BED).setTitle(C.cGreen + "Back").build(), (player, clickType) ->
|
||||
{
|
||||
_overview.refresh();
|
||||
getShop().openPageForPlayer(player, _overview);
|
||||
});
|
||||
addButton(13, buildResetItem(), (player, clickType) ->
|
||||
{
|
||||
if (_token.Skin == null)
|
||||
{
|
||||
playDenySound(player);
|
||||
}
|
||||
else
|
||||
{
|
||||
playAcceptSound(player);
|
||||
_token.Skin = null;
|
||||
getPlugin().getRepository().saveMount(getClientManager().Get(player).getAccountId(), _token, getPlugin().Get(player).getStatToken(_token));
|
||||
refresh();
|
||||
}
|
||||
});
|
||||
int[] skinSlots = {20, 21, 22, 23, 24, 29, 30, 31, 32, 33, 38, 39, 40, 41, 42};
|
||||
List<SkinType> allowed = getAllowed();
|
||||
for (int i = 0; i < skinSlots.length && i < allowed.size(); i++)
|
||||
{
|
||||
SkinType type = allowed.get(i);
|
||||
addButton(skinSlots[i], buildSkinItem(type), (player, clickType) ->
|
||||
{
|
||||
if (hasUnlocked(player, type) && _token.Skin != type)
|
||||
{
|
||||
playAcceptSound(player);
|
||||
_token.Skin = type;
|
||||
getPlugin().getRepository().saveMount(getClientManager().Get(player).getAccountId(), _token, getPlugin().Get(player).getStatToken(_token));
|
||||
refresh();
|
||||
}
|
||||
else
|
||||
{
|
||||
playDenySound(player);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user