use of net.minecraft.server.v1_15_R1.Tuple in project solinia3-core by mixxit.
the class PlayerUtils method GetCharacterText.
public static Tuple<String, TextComponent> GetCharacterText(ISoliniaPlayer solplayer, String optionalhidden, String optionalplayername, String optionalworldname, String optionalzone, boolean showPersonality) {
int lvl = (int) Math.floor(solplayer.getActualLevel());
int mentorLevel = (int) Math.floor(solplayer.getMentorLevel());
String racename = "UNKNOWN";
String classname = "UNKNOWN";
String godname = "UNKNOWN /setgod <name>";
String zone = "UNKNOWN";
if (optionalzone != null && !zone.equals(""))
zone = optionalzone;
String hidden = "";
if (optionalhidden != null && !optionalhidden.equals(""))
hidden = optionalhidden;
if (solplayer.getRace() != null)
racename = solplayer.getRace().getShortName();
if (solplayer.getClassObj() != null)
classname = solplayer.getClassObj().getShortName();
String message = hidden + " " + optionalplayername + " " + ChatColor.YELLOW + solplayer.getFullName().toUpperCase() + ChatColor.RESET + " [" + optionalworldname + "] - LVL " + ChatColor.AQUA + mentorLevel + "/" + lvl + ChatColor.RESET + " " + racename + " " + ChatColor.AQUA + classname + ChatColor.RESET + " Zone: " + ChatColor.AQUA + zone + ChatColor.RESET;
TextComponent tc = new TextComponent(TextComponent.fromLegacyText(message));
String worship = "I worship: " + godname + System.lineSeparator();
String ideal = "Ideal: I have no ideal" + System.lineSeparator();
String trait1 = "Trait: I have no primary trait" + System.lineSeparator();
String trait2 = "Trait: I have no secondary trait" + System.lineSeparator();
String bond = "Bond: I have no bond" + System.lineSeparator();
String flaw = "Flaw: I have no flaw" + System.lineSeparator();
String oath = "Oath: I have no oath" + System.lineSeparator();
if (solplayer.getGodId() > 0)
worship = "I worship: " + solplayer.getGod().getName() + System.lineSeparator();
String ageinfo = "Age: ???";
if (solplayer.getBirthday() != null) {
int age = 0;
String text = "2020-01-01 00:00:00.00";
LocalDateTime fromDate = Timestamp.valueOf(text).toLocalDateTime();
LocalDateTime toDate = solplayer.getBirthday().toLocalDateTime();
int characterbirthyear = CommandToday.getUTYear(fromDate, toDate);
int currentutyear = CommandToday.getCurrentUTYear();
ageinfo = "Age: " + (currentutyear - characterbirthyear);
}
String backstory = "My back story is a mystery" + System.lineSeparator();
if (solplayer.getBackStory() != null && !solplayer.getBackStory().equals(""))
backstory = "Backstory:" + solplayer.getBackStory() + System.lineSeparator();
if (solplayer.getPersonality().getIdealId() > 0)
ideal = "Ideal:" + solplayer.getPersonality().getIdeal().description + System.lineSeparator();
if (solplayer.getPersonality().getFirstTraitId() > 0)
trait1 = "Trait:" + solplayer.getPersonality().getFirstTrait().description + System.lineSeparator();
if (solplayer.getPersonality().getSecondTraitId() > 0)
trait2 = "Trait:" + solplayer.getPersonality().getSecondTrait().description + System.lineSeparator();
if (solplayer.getPersonality().getBondId() > 0)
bond = "Bond:" + solplayer.getPersonality().getBond().description + System.lineSeparator();
if (solplayer.getPersonality().getFlawId() > 0)
flaw = "Flaw:" + solplayer.getPersonality().getFlaw().description + System.lineSeparator();
String custom = "";
for (String customTrait : solplayer.getPersonality().getCustomPersonalityTraits()) {
custom += "Custom:" + customTrait + System.lineSeparator();
}
if (solplayer.getClassObj() != null && solplayer.getClassObj().getOaths().size() > 0 && solplayer.getOathId() != 0) {
oath = "Oath: " + solplayer.getOath().oathname + System.lineSeparator();
for (String tenet : solplayer.getOath().tenets) {
oath += " " + tenet;
}
}
String inspiration = "Inspiration Points: " + solplayer.getInspiration() + System.lineSeparator();
String details = ChatColor.GOLD + solplayer.getFullName().toUpperCase() + " Level " + lvl + " " + racename + " " + classname + ChatColor.RESET + System.lineSeparator() + ageinfo + " " + backstory + inspiration;
if (showPersonality) {
details += worship + ideal + trait1 + trait2 + bond + flaw + custom + oath;
} else {
details += "To see more information:" + System.lineSeparator() + "/personality player " + solplayer.getId() + " [or click]";
}
tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/personality player " + solplayer.getId()));
tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(details).create()));
return new Tuple<String, TextComponent>(message, tc);
}
use of net.minecraft.server.v1_15_R1.Tuple in project solinia3-core by mixxit.
the class SpellUtils method getHighestAAEffectEffectTypeTuple.
public static Tuple<Integer, Integer> getHighestAAEffectEffectTypeTuple(LivingEntity bukkitLivingEntity, SpellEffectType effectType, Integer filterbase2) {
if (!(bukkitLivingEntity instanceof Player))
return new Tuple<Integer, Integer>(0, 0);
// This is actually read from the CriticalSpellChance
boolean enforceSpellCritFormula = false;
if (effectType.equals(SpellEffectType.SpellCritDmgIncrease)) {
effectType = SpellEffectType.CriticalSpellChance;
enforceSpellCritFormula = true;
}
int highest = 0;
int highest2 = 0;
boolean firstRun = true;
try {
ISoliniaPlayer player = SoliniaPlayerAdapter.Adapt((Player) bukkitLivingEntity);
for (SoliniaAARankEffect effect : player.getRanksEffectsOfEffectType(SpellUtils.getEffectIdFromEffectType(effectType), true)) {
if (filterbase2 != null && effect.getBase2() != filterbase2)
continue;
// Everything else
if (enforceSpellCritFormula) {
int base = 0;
if (effect.getBase2() > 100)
base = effect.getBase2() - 100;
if (base > highest2 || firstRun) {
highest = effect.getBase1();
highest2 = base;
firstRun = false;
}
} else {
if (effect.getBase1() > highest || firstRun) {
highest = effect.getBase1();
highest2 = effect.getBase2();
firstRun = false;
}
}
}
return new Tuple<Integer, Integer>(highest, highest2);
} catch (CoreStateInitException e) {
return new Tuple<Integer, Integer>(0, 0);
}
}
use of net.minecraft.server.v1_15_R1.Tuple in project solinia3-core by mixxit.
the class SoliniaLivingEntity method aiCastSpell.
@Override
public boolean aiCastSpell(Plugin plugin, ISoliniaNPC npc, LivingEntity target, int iChance, int iSpellTypes, int npcEffectiveLevel) throws CoreStateInitException {
if (this.getClassObj() == null) {
return false;
}
NPCSpellList npcSpellList = null;
if (npc.getNpcSpellList() < 1 && this.getClassObj().getNpcspelllist() < 1)
return false;
ISoliniaLivingEntity tar = SoliniaLivingEntityAdapter.Adapt(target);
if (tar == null)
return false;
if (getClassObj().getNpcspelllist() > 0) {
npcSpellList = StateManager.getInstance().getConfigurationManager().getNPCSpellList(getClassObj().getNpcspelllist());
}
if (npc.getNpcSpellList() > 0) {
npcSpellList = StateManager.getInstance().getConfigurationManager().getNPCSpellList(npc.getNpcSpellList());
}
boolean cast_only_option = (isRooted() && !combatRange(tar));
if (!cast_only_option && iChance < 100) {
int roll = MathUtils.RandomBetween(0, 100);
if (roll >= iChance) {
return false;
}
}
// TODO escape distance
boolean checked_los = false;
double manaR = getManaRatio();
List<NPCSpellListEntry> spells = new ArrayList<NPCSpellListEntry>();
for (NPCSpellListEntry entry : npcSpellList.getSpellListEntry()) {
if (npcEffectiveLevel >= entry.getMinlevel() && npcEffectiveLevel <= entry.getMaxlevel()) {
spells.add(entry);
}
}
List<Integer> activeSpellIds = tar.getActiveSpells().stream().map(e -> e.getSpellId()).collect(Collectors.toList());
spells = spells.stream().filter(e -> !activeSpellIds.contains(e.getSpellid())).collect(Collectors.toList());
Collections.shuffle(spells);
// AI has spells?
if (spells.size() == 0) {
return false;
}
for (NPCSpellListEntry spelllistentry : spells) {
if ((iSpellTypes & spelllistentry.getType()) == spelllistentry.getType()) {
// Does spell types contain spelltype
ISoliniaSpell spell = StateManager.getInstance().getConfigurationManager().getSpell(spelllistentry.getSpellid());
if (spell == null) {
continue;
}
// Lets not cast anything thats really short lasting if we are outside of combat
if (!this.isInCombat()) {
if (!spell.isBeneficial())
continue;
if (spell.getBuffduration() < 150)
continue;
boolean noStack = false;
boolean foundBefore = false;
// this is just me so lets see if my spell can stack against me
for (SoliniaActiveSpell activeSpell : StateManager.getInstance().getEntityManager().getActiveEntitySpells(getBukkitLivingEntity()).getActiveSpells()) {
if (activeSpell.getSpellId() == spell.getId()) {
foundBefore = true;
continue;
}
int stackableResponse = StateManager.getInstance().getEntityManager().getActiveEntitySpells(getBukkitLivingEntity()).checkStackConflict(activeSpell.getSpell(), getBukkitLivingEntity().getUniqueId(), spell, getBukkitLivingEntity(), getBukkitLivingEntity());
if (stackableResponse == -1)
noStack = true;
}
if (foundBefore)
continue;
if (noStack)
continue;
}
// TODO Check mana
int mana_cost = spell.getActSpellCost(this);
if (mana_cost < 0)
mana_cost = 0;
ISoliniaLivingEntity soltarget = SoliniaLivingEntityAdapter.Adapt(target);
LocalDateTime datetime = LocalDateTime.now();
Timestamp nowtimestamp = Timestamp.valueOf(datetime);
Timestamp expiretimestamp = Timestamp.valueOf(datetime.plus(spell.getRecastTime() + 1000, ChronoUnit.MILLIS));
switch(spelllistentry.getType()) {
case SpellType.Heal:
if ((SoliniaSpell.isValidEffectForEntity(target, this.getBukkitLivingEntity(), spell).a()) && !SpellUtils.hasSpellActive(soltarget, spell) && (SpellUtils.getSpellTargetType(spell.getTargettype()).equals(SpellTargetType.Target) || target.getUniqueId().equals(getBukkitLivingEntity().getUniqueId())) && (nowtimestamp.after(StateManager.getInstance().getEntityManager().getDontSpellTypeMeBefore(target, SpellType.Heal))) && !(soltarget.isCurrentlyNPCPet())) {
double hpr = soltarget.getHPRatio();
// TODO player healing and non engaged healing of less than 50% hp
if (hpr <= 35) {
aiDoSpellCast(plugin, spell, soltarget, mana_cost);
StateManager.getInstance().getEntityManager().setDontSpellTypeMeBefore(target, SpellType.Heal, expiretimestamp);
return true;
}
}
break;
case SpellType.Root:
// TODO - Pick at random
if ((SoliniaSpell.isValidEffectForEntity(target, this.getBukkitLivingEntity(), spell).a()) && !SpellUtils.hasSpellActive(soltarget, spell) && !soltarget.isRooted() && MathUtils.RandomRoll(50) && nowtimestamp.after(StateManager.getInstance().getEntityManager().getDontSpellTypeMeBefore(target, SpellType.Root))) // TODO buff stacking
{
if (!checked_los) {
if (!this.checkLosFN(tar)) {
return false;
}
checked_los = true;
}
aiDoSpellCast(plugin, spell, soltarget, mana_cost);
StateManager.getInstance().getEntityManager().setDontSpellTypeMeBefore(target, SpellType.Root, expiretimestamp);
return true;
}
break;
case SpellType.InCombatBuff:
case SpellType.Buff:
if (((SoliniaSpell.isValidEffectForEntity(target, this.getBukkitLivingEntity(), spell).a()) && !SpellUtils.hasSpellActive(soltarget, spell) && SpellUtils.getSpellTargetType(spell.getTargettype()).equals(SpellTargetType.Target) || target.getUniqueId().equals(getBukkitLivingEntity().getUniqueId())) && nowtimestamp.after(StateManager.getInstance().getEntityManager().getDontSpellTypeMeBefore(target, SpellType.Buff)) && !spell.isInvisSpell()) // TODO Spell immunities
// TODO Spell stacking
// TODO NPC Pets
{
if (!checked_los) {
if (!this.checkLosFN(tar)) {
return false;
}
checked_los = true;
} else {
}
boolean success = aiDoSpellCast(plugin, spell, soltarget, mana_cost);
StateManager.getInstance().getEntityManager().setDontSpellTypeMeBefore(target, SpellType.Buff, expiretimestamp);
return true;
} else {
// could not cast as either the spell target was wrong, the target was not me or i have already buffed myself recently
}
break;
case SpellType.Escape:
// TODO Gate/Escape
return false;
case SpellType.Slow:
case SpellType.Debuff:
// TODO debuff at random
if ((SoliniaSpell.isValidEffectForEntity(target, this.getBukkitLivingEntity(), spell).a()) && !SpellUtils.hasSpellActive(soltarget, spell) && manaR >= 10 && MathUtils.RandomRoll(70)) // TODO buff stacking
{
if (!checked_los) {
if (!RaycastUtils.isEntityInLineOfSight(this, tar, true)) {
return false;
}
checked_los = true;
}
aiDoSpellCast(plugin, spell, soltarget, mana_cost);
return true;
}
break;
case SpellType.Nuke:
boolean nukeRoll = MathUtils.RandomRoll(70);
Tuple<Boolean, String> valid = SoliniaSpell.isValidEffectForEntity(target, this.getBukkitLivingEntity(), spell);
boolean hasSpellTargetActive = SpellUtils.hasSpellActive(soltarget, spell);
if (valid.a() && !hasSpellTargetActive && manaR >= 10 && nukeRoll) // TODO Buff Stacking check
{
if (!checked_los) {
if (!RaycastUtils.isEntityInLineOfSight(this, tar, true)) {
return false;
}
checked_los = true;
} else {
}
aiDoSpellCast(plugin, spell, soltarget, mana_cost);
return true;
} else {
/*DebugUtils.DebugLog("SoliniaLivingEntity","aiCastSpell",this.getBukkitLivingEntity(),
"NPC: " + npc.getName() + this.getBukkitLivingEntity().getUniqueId().toString()
+ " could not cast nuke as either my mana ratio was too low (" + !(manaR >= 10)
+ ") or i rolled badly roll failure: (" + nukeRoll + ")"
+ " or was not valid - valid: " + valid.a() + "["+valid.b()+"]"
+ " or has spell already " + hasSpellTargetActive);*/
}
break;
case SpellType.Dispel:
if ((SoliniaSpell.isValidEffectForEntity(target, this.getBukkitLivingEntity(), spell).a()) && !SpellUtils.hasSpellActive(soltarget, spell) && MathUtils.RandomRoll(15)) {
if (!checked_los) {
if (!RaycastUtils.isEntityInLineOfSight(this, tar, true)) {
return false;
}
checked_los = true;
}
if (soltarget.countDispellableBuffs() > 0) {
aiDoSpellCast(plugin, spell, soltarget, mana_cost);
return true;
}
}
break;
case SpellType.Mez:
if ((SoliniaSpell.isValidEffectForEntity(target, this.getBukkitLivingEntity(), spell).a()) && !SpellUtils.hasSpellActive(soltarget, spell) && MathUtils.RandomRoll(20)) {
aiDoSpellCast(plugin, spell, soltarget, mana_cost);
}
break;
case SpellType.Charm:
// TODO Charms
break;
case SpellType.Pet:
// TODO Pets
break;
case SpellType.Lifetap:
if ((SoliniaSpell.isValidEffectForEntity(target, this.getBukkitLivingEntity(), spell).a()) && !SpellUtils.hasSpellActive(soltarget, spell) && getHPRatio() <= 95 && MathUtils.RandomRoll(50)) // TODO Buff stacking
{
if (!checked_los) {
if (!RaycastUtils.isEntityInLineOfSight(this, tar, true)) {
return false;
}
checked_los = true;
}
aiDoSpellCast(plugin, spell, soltarget, mana_cost);
return true;
}
break;
case SpellType.Snare:
if ((SoliniaSpell.isValidEffectForEntity(target, this.getBukkitLivingEntity(), spell).a()) && !SpellUtils.hasSpellActive(soltarget, spell) && !soltarget.isRooted() && MathUtils.RandomRoll(50) && (nowtimestamp.after(StateManager.getInstance().getEntityManager().getDontSpellTypeMeBefore(target, SpellType.Snare)))) // TODO Buff stacking
{
if (!checked_los) {
if (!RaycastUtils.isEntityInLineOfSight(this, tar, true)) {
return false;
}
checked_los = true;
}
aiDoSpellCast(plugin, spell, soltarget, mana_cost);
StateManager.getInstance().getEntityManager().setDontSpellTypeMeBefore(target, SpellType.Snare, expiretimestamp);
return true;
}
break;
case SpellType.DOT:
if ((SoliniaSpell.isValidEffectForEntity(target, this.getBukkitLivingEntity(), spell).a()) && !SpellUtils.hasSpellActive(soltarget, spell) && (MathUtils.RandomRoll(60)) && (nowtimestamp.after(StateManager.getInstance().getEntityManager().getDontSpellTypeMeBefore(target, SpellType.DOT)))) // TODO buff stacking
{
if (!checked_los) {
if (!RaycastUtils.isEntityInLineOfSight(this, tar, true)) {
return false;
}
checked_los = true;
}
aiDoSpellCast(plugin, spell, soltarget, mana_cost);
StateManager.getInstance().getEntityManager().setDontSpellTypeMeBefore(target, SpellType.DOT, expiretimestamp);
return true;
}
break;
default:
// unknown spell type
break;
}
}
}
return false;
}
use of net.minecraft.server.v1_15_R1.Tuple in project solinia3-core by mixxit.
the class EntityManager method resetReverseAggro.
@Override
public void resetReverseAggro(UUID uniqueId) {
if (reverseHateList.get(uniqueId) != null) {
Entity entity = Bukkit.getEntity(uniqueId);
if (entity == null)
return;
if (reverseHateList.get(uniqueId).size() == 0) {
return;
}
// clear reverse hate list in advance
for (Entry<UUID, Tuple<Integer, Boolean>> entitesReverseHateList : reverseHateList.get(uniqueId).entrySet()) {
if (hateList.get(entitesReverseHateList.getKey()) == null) {
continue;
}
if (hateList.get(entitesReverseHateList.getKey()).get(uniqueId) != null) {
hateList.get(entitesReverseHateList.getKey()).remove(uniqueId);
Entity bukkitEntity = Bukkit.getEntity(entitesReverseHateList.getKey());
if (bukkitEntity != null && bukkitEntity instanceof LivingEntity) {
try {
ISoliniaLivingEntity solLivingEntity = SoliniaLivingEntityAdapter.Adapt((LivingEntity) bukkitEntity);
if (solLivingEntity != null && solLivingEntity.getAttackTarget().getUniqueId().equals(uniqueId)) {
if (solLivingEntity.isInHateList(uniqueId))
solLivingEntity.removeFromHateList(uniqueId);
solLivingEntity.checkHateTargets();
}
} catch (CoreStateInitException e) {
}
}
}
}
}
reverseHateList.put(uniqueId, new ConcurrentHashMap<UUID, Tuple<Integer, Boolean>>());
}
use of net.minecraft.server.v1_15_R1.Tuple in project solinia3-core by mixxit.
the class SoliniaSpell method isValidEffectForEntity.
public static Tuple<Boolean, String> isValidEffectForEntity(LivingEntity target, LivingEntity source, ISoliniaSpell soliniaSpell) throws CoreStateInitException {
try {
if (source == null) {
System.out.println("Source was null for isValidEffectForEntity: " + soliniaSpell.getName() + " on target: " + target.getCustomName());
return new Tuple<Boolean, String>(false, "Source was null for spell");
}
if (target == null) {
System.out.println("Target was null for isValidEffectForEntity: " + soliniaSpell.getName() + " from source: " + source.getCustomName());
return new Tuple<Boolean, String>(false, "Target was null for spell");
}
if (source.isDead() || target.isDead())
return new Tuple<Boolean, String>(false, "Source or target is dead");
ISoliniaLivingEntity solTarget = SoliniaLivingEntityAdapter.Adapt(target);
if (solTarget != null) {
switch(SpellUtils.getSpellTargetType(soliniaSpell.getTargettype())) {
case SummonedAE:
if (!solTarget.isUndead()) {
return new Tuple<Boolean, String>(false, "Only affects undead");
}
break;
case UndeadAE:
if (!solTarget.isUndead()) {
return new Tuple<Boolean, String>(false, "Only affects undead");
}
break;
case Undead:
if (!solTarget.isUndead()) {
source.sendMessage("This spell is only effective on Undead");
return new Tuple<Boolean, String>(false, "Only affects undead");
}
break;
case Summoned:
if (!solTarget.isCurrentlyNPCPet() && !solTarget.isCharmed()) {
source.sendMessage("This spell is only effective on Summoned");
return new Tuple<Boolean, String>(false, "Only affects summoned");
}
break;
case Animal:
if (!solTarget.isAnimal()) {
source.sendMessage("This spell is only effective on Animals");
return new Tuple<Boolean, String>(false, "Only affects animals");
}
break;
case Plant:
if (!solTarget.isPlant()) {
source.sendMessage("This spell is only effective on Plants");
return new Tuple<Boolean, String>(false, "Only affects plants");
}
break;
default:
break;
}
}
ISoliniaLivingEntity solSource = SoliniaLivingEntityAdapter.Adapt(source);
if (solTarget.isNPC()) {
if (source instanceof Player || solSource.isCurrentlyNPCPet()) {
ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(solTarget.getNpcid());
if (npc != null) {
if (npc.isBoss() || npc.isRaidboss())
if (!soliniaSpell.isBossApplyable()) {
source.sendMessage(ChatColor.RED + "This NPC is immune to runspeed, gravity and mezmersization changes");
return new Tuple<Boolean, String>(false, "Immune to runspeed/gravity/mez");
}
if (npc.isRaidheroic())
if (!soliniaSpell.isRaidApplyable()) {
source.sendMessage(ChatColor.RED + "This NPC is immune to runspeed, gravity and mezmersization changes");
return new Tuple<Boolean, String>(false, "Immune to runspeed/gravity/mez");
}
}
}
}
if (!solSource.isNPC() && solTarget.isImmuneToSpell(soliniaSpell)) {
source.sendMessage(ChatColor.RED + "Your target cannot be affected (with this spell) [Spell has maxlevel or effect already]");
return new Tuple<Boolean, String>(false, "Target is (currently) immune to spell - Spell maxlevel limit,haseffect etc..");
}
// Always allow self only spells if the target and source is the self
if (source.getUniqueId().equals(target.getUniqueId()) && SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.Self)) {
// just be sure to check the item its giving if its an item spell
for (SpellEffect effect : soliniaSpell.getBaseSpellEffects()) {
if (effect.getSpellEffectType().equals(SpellEffectType.SummonHorse)) {
if (source instanceof Player) {
if (source.getUniqueId().equals(target.getUniqueId())) {
if (StateManager.getInstance().getPlayerManager().getPlayerLastChangeChar(source.getUniqueId()) != null) {
source.sendMessage("You can only summon a mount once per server session. Please wait for the next 4 hourly restart");
return new Tuple<Boolean, String>(false, "Cannot summon mount this soon");
}
} else {
return new Tuple<Boolean, String>(false, "Source was not target");
}
} else {
return new Tuple<Boolean, String>(false, "Source wasnt player");
}
}
if (effect.getSpellEffectType().equals(SpellEffectType.SummonItem)) {
int itemId = effect.getBase();
try {
ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemId);
if (item == null) {
return new Tuple<Boolean, String>(false, "Item was null");
}
if (!item.isTemporary() && !soliniaSpell.isIgnoreSummonItemTemporaryCheck()) {
return new Tuple<Boolean, String>(false, "Item wasnt temporary");
}
if (!(target instanceof LivingEntity)) {
return new Tuple<Boolean, String>(false, "Targert wasnt living");
}
} catch (CoreStateInitException e) {
return new Tuple<Boolean, String>(false, "Plugin wasnt initialised");
}
}
}
// "), returning as valid, always");
return new Tuple<Boolean, String>(true, "Self only spell");
}
if (!source.getUniqueId().equals(target.getUniqueId()))
if (!solSource.isPlayer()) {
if (!solSource.checkLosFN(solTarget, true))
return new Tuple<Boolean, String>(false, "Target not in line of sight of source");
} else {
// we dont care about directional for players
if (!solSource.checkLosFN(solTarget, false))
return new Tuple<Boolean, String>(false, "Target not in line of sight of source");
}
// Try not to kill potentially friendly player tameables with hostile spells
if (solTarget.isCurrentlyNPCPet() && target instanceof Creature && !soliniaSpell.isBeneficial()) {
if (soliniaSpell.isCharmSpell() && source.getUniqueId().equals(solTarget.getOwnerEntity().getUniqueId())) {
// Our owner wants to renew his charm
return new Tuple<Boolean, String>(true, "Charm spell and source is target");
} else {
Creature cr = (Creature) target;
if (cr.getTarget() == null)
return new Tuple<Boolean, String>(false, "Target is null");
if (!cr.getTarget().getUniqueId().equals(source.getUniqueId()))
return new Tuple<Boolean, String>(false, "Target is not the source");
}
}
for (SpellEffect effect : soliniaSpell.getBaseSpellEffects()) {
// and the spell is a detrimental
if (source instanceof Player && target instanceof Player && soliniaSpell.isDetrimental()) {
ISoliniaPlayer solsourceplayer = SoliniaPlayerAdapter.Adapt((Player) source);
if (solsourceplayer.getGroup() != null) {
if (solsourceplayer.getGroup().getUnmodifiableGroupMembersForBuffs(true, false).contains(target.getUniqueId())) {
return new Tuple<Boolean, String>(false, "Detrimental against group member");
}
}
}
// Return false if the target is in the same faction as the npc and not self
if (!(source instanceof Player) && !(target instanceof Player) && soliniaSpell.isDetrimental() && !source.getUniqueId().equals(target.getUniqueId())) {
if (source instanceof LivingEntity && target instanceof LivingEntity) {
ISoliniaLivingEntity solsourceEntity = SoliniaLivingEntityAdapter.Adapt(source);
ISoliniaLivingEntity soltargetEntity = SoliniaLivingEntityAdapter.Adapt(target);
if (solsourceEntity.isNPC() && soltargetEntity.isNPC()) {
ISoliniaNPC sourceNpc = StateManager.getInstance().getConfigurationManager().getNPC(solsourceEntity.getNpcid());
ISoliniaNPC targetNpc = StateManager.getInstance().getConfigurationManager().getNPC(soltargetEntity.getNpcid());
if (sourceNpc.getFactionid() > 0 && targetNpc.getFactionid() > 0) {
if (sourceNpc.getFactionid() == targetNpc.getFactionid())
return new Tuple<Boolean, String>(false, "Faction is same");
}
}
}
}
if (effect.getSpellEffectType().equals(SpellEffectType.Revive)) {
if (!(target instanceof Player)) {
return new Tuple<Boolean, String>(false, "Target is not player");
}
if (!(source instanceof Player))
return new Tuple<Boolean, String>(false, "Source is not player");
Player sourcePlayer = (Player) source;
if (!sourcePlayer.getInventory().getItemInOffHand().getType().equals(Material.NAME_TAG)) {
sourcePlayer.sendMessage("You are not holding a Signaculum in your offhand (MC): " + sourcePlayer.getInventory().getItemInOffHand().getType().name());
return new Tuple<Boolean, String>(false, "Not holding item in offhand");
}
ItemStack item = sourcePlayer.getInventory().getItemInOffHand();
if (item.getEnchantmentLevel(Enchantment.DURABILITY) != 1) {
sourcePlayer.sendMessage("You are not holding a Signaculum in your offhand (EC)");
return new Tuple<Boolean, String>(false, "Not holding item in offhand");
}
if (!item.getItemMeta().getDisplayName().equals("Signaculum")) {
sourcePlayer.sendMessage("You are not holding a Signaculum in your offhand (NC)");
return new Tuple<Boolean, String>(false, "Not holding item in offhand");
}
if (item.getItemMeta().getLore().size() < 5) {
sourcePlayer.sendMessage("You are not holding a Signaculum in your offhand (LC)");
return new Tuple<Boolean, String>(false, "Not holding item in offhand");
}
String sigdataholder = item.getItemMeta().getLore().get(3);
String[] sigdata = sigdataholder.split("\\|");
if (sigdata.length != 2) {
sourcePlayer.sendMessage("You are not holding a Signaculum in your offhand (SD)");
return new Tuple<Boolean, String>(false, "Not holding item in offhand");
}
String str_experience = sigdata[0];
String str_stimetsamp = sigdata[1];
int experience = Integer.parseInt(str_experience);
Timestamp timestamp = Timestamp.valueOf(str_stimetsamp);
LocalDateTime datetime = LocalDateTime.now();
Timestamp currenttimestamp = Timestamp.valueOf(datetime);
long maxminutes = 60 * 7;
if ((currenttimestamp.getTime() - timestamp.getTime()) >= maxminutes * 60 * 1000) {
sourcePlayer.sendMessage("This Signaculum has lost its binding to the soul");
return new Tuple<Boolean, String>(false, "Expired signaculum");
}
String characterId = item.getItemMeta().getLore().get(4);
try {
ISoliniaPlayer soliniaPlayer = StateManager.getInstance().getConfigurationManager().getCharacterById(Integer.parseInt(characterId));
if (soliniaPlayer == null) {
sourcePlayer.sendMessage("You cannot resurrect that player as this character no longer exists");
return new Tuple<Boolean, String>(false, "Character no longer exists");
}
Player targetplayer = Bukkit.getPlayer(soliniaPlayer.getOwnerUUID());
if (targetplayer == null || !targetplayer.isOnline()) {
sourcePlayer.sendMessage("You cannot resurrect that player as they are offline");
return new Tuple<Boolean, String>(false, "Offline player");
}
} catch (NumberFormatException e) {
sourcePlayer.sendMessage("This signaculum has been corrupted by the void");
return new Tuple<Boolean, String>(false, "Character identifier is corrupted");
}
}
// Validate spelleffecttype rules
if (effect.getSpellEffectType().equals(SpellEffectType.CurrentHP) || effect.getSpellEffectType().equals(SpellEffectType.CurrentHPOnce)) {
// Ignore this rule if the spell is self
if (!SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.Self) && !SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.AECaster) && !SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.AEClientV1)) {
// If the effect is negative standard nuke and on self, cancel out
if (effect.getBase() < 0 && target.equals(source))
return new Tuple<Boolean, String>(false, "Target was self");
}
// cancel
if (source instanceof Player) {
if (!(target instanceof Player)) {
ISoliniaLivingEntity soltargetentity = SoliniaLivingEntityAdapter.Adapt(target);
if (!soltargetentity.isCurrentlyNPCPet()) {
if (effect.getBase() > 0)
return new Tuple<Boolean, String>(false, "Target wasnt a pet npc");
}
}
}
}
if (effect.getSpellEffectType().equals(SpellEffectType.Illusion) || effect.getSpellEffectType().equals(SpellEffectType.IllusionaryTarget) || effect.getSpellEffectType().equals(SpellEffectType.IllusionCopy) || effect.getSpellEffectType().equals(SpellEffectType.IllusionOther) || effect.getSpellEffectType().equals(SpellEffectType.IllusionPersistence)) {
// if target has spell effect of above already then we cant apply another
for (SoliniaActiveSpell activeSpell : StateManager.getInstance().getEntityManager().getActiveEntitySpells(target).getActiveSpells()) {
if (activeSpell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Illusion))
return new Tuple<Boolean, String>(false, "Contained illusion");
if (activeSpell.getSpell().getSpellEffectTypes().contains(SpellEffectType.IllusionaryTarget))
return new Tuple<Boolean, String>(false, "Contained illusion target");
if (activeSpell.getSpell().getSpellEffectTypes().contains(SpellEffectType.IllusionCopy))
return new Tuple<Boolean, String>(false, "Contained illusion copy");
if (activeSpell.getSpell().getSpellEffectTypes().contains(SpellEffectType.IllusionOther))
return new Tuple<Boolean, String>(false, "Contained illusion other");
if (activeSpell.getSpell().getSpellEffectTypes().contains(SpellEffectType.IllusionPersistence))
return new Tuple<Boolean, String>(false, "Contained illusion persistence");
}
}
if (effect.getSpellEffectType().equals(SpellEffectType.SummonItem)) {
System.out.println("Validating SummonItem for source: " + source.getCustomName());
int itemId = effect.getBase();
try {
ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemId);
System.out.println("Validating SummonItem for source: " + source.getCustomName());
if (item == null) {
System.out.println("Validating SummonItem said item was null");
return new Tuple<Boolean, String>(false, "Item didnt exist");
}
if (!item.isTemporary()) {
System.out.println("Validating SummonItem said item was not temporary");
return new Tuple<Boolean, String>(false, "Item was not temporary");
}
if (!(target instanceof LivingEntity)) {
System.out.println("Validating SummonItem said target was not a living entity");
return new Tuple<Boolean, String>(false, "Target not living");
}
} catch (CoreStateInitException e) {
return new Tuple<Boolean, String>(false, "Plugin not initialised");
}
}
if (!SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.Self) && !SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.AECaster) && !SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.AEClientV1))
if (effect.getSpellEffectType().equals(SpellEffectType.ResistAll) || effect.getSpellEffectType().equals(SpellEffectType.ResistCold) || effect.getSpellEffectType().equals(SpellEffectType.ResistFire) || effect.getSpellEffectType().equals(SpellEffectType.ResistMagic) || effect.getSpellEffectType().equals(SpellEffectType.ResistPoison) || effect.getSpellEffectType().equals(SpellEffectType.ResistDisease) || effect.getSpellEffectType().equals(SpellEffectType.ResistCorruption)) {
// If the effect is negative standard resist debuffer and on self, cancel out
if (effect.getBase() < 0 && target.equals(source))
return new Tuple<Boolean, String>(false, "Target of spell is source");
}
if (!SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.Self) && !SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.AECaster) && !SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.AEClientV1))
if (effect.getSpellEffectType().equals(SpellEffectType.Mez)) {
// If the effect is a mez, cancel out
if (target.equals(source))
return new Tuple<Boolean, String>(false, "Target of spell is source");
}
if (effect.getSpellEffectType().equals(SpellEffectType.Charm)) {
if (target instanceof Player)
return new Tuple<Boolean, String>(false, "Target of spell is player");
}
if (!SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.Self) && !SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.AECaster) && !SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.AEClientV1))
if (effect.getSpellEffectType().equals(SpellEffectType.Charm)) {
// If the effect is a charm, cancel out
if (target.equals(source))
return new Tuple<Boolean, String>(false, "Target of spell is source");
}
if (!SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.Self) && !SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.AECaster) && !SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.AEClientV1))
if (effect.getSpellEffectType().equals(SpellEffectType.Stun)) {
// If the effect is a stun, cancel out
if (target.equals(source))
return new Tuple<Boolean, String>(false, "Target of spell is source");
}
if (!SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.Self) && !SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.AECaster) && !SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.AEClientV1))
if (effect.getSpellEffectType().equals(SpellEffectType.Root)) {
// If the effect is a root, cancel out
if (target.equals(source))
return new Tuple<Boolean, String>(false, "Target of spell is source");
}
if (!SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.Self) && !SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.AECaster) && !SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.AEClientV1))
if (effect.getSpellEffectType().equals(SpellEffectType.Blind)) {
// If the effect is a blindness, cancel out
if (target.equals(source))
return new Tuple<Boolean, String>(false, "Target of spell is source");
}
if (effect.getSpellEffectType().equals(SpellEffectType.DamageShield) && !(target instanceof Player) && !SoliniaLivingEntityAdapter.Adapt(target).isCurrentlyNPCPet()) {
// If the effect is a mez, cancel out
if (target.equals(source))
return new Tuple<Boolean, String>(false, "Target of spell is source");
}
if (effect.getSpellEffectType().equals(SpellEffectType.NecPet) || effect.getSpellEffectType().equals(SpellEffectType.SummonPet) || effect.getSpellEffectType().equals(SpellEffectType.Teleport) || effect.getSpellEffectType().equals(SpellEffectType.Teleport2) || effect.getSpellEffectType().equals(SpellEffectType.Translocate) || effect.getSpellEffectType().equals(SpellEffectType.TranslocatetoAnchor)) {
// If the effect is teleport and the target is not a player then fail
if (!(target instanceof Player))
return new Tuple<Boolean, String>(false, "Target of spell not a player");
if (!(source instanceof Player))
return new Tuple<Boolean, String>(false, "Source of spell not a player");
// fail
if (effect.getSpellEffectType().equals(SpellEffectType.Teleport) || effect.getSpellEffectType().equals(SpellEffectType.Teleport2) || effect.getSpellEffectType().equals(SpellEffectType.Translocate) || effect.getSpellEffectType().equals(SpellEffectType.TranslocatetoAnchor)) {
// if target is not the player casting
if (!target.getUniqueId().equals(source.getUniqueId())) {
ISoliniaPlayer solplayertarget = SoliniaPlayerAdapter.Adapt((Player) target);
if (solplayertarget == null)
return new Tuple<Boolean, String>(false, "Target not found");
if (solplayertarget.getGroup() == null)
return new Tuple<Boolean, String>(false, "Group not found");
if (!(solplayertarget.getGroup().getUnmodifiableGroupMembersForBuffs(false, false).contains(source.getUniqueId())))
return new Tuple<Boolean, String>(false, "Group member not found");
}
}
if (effect.getSpellEffectType().equals(SpellEffectType.SummonPet) || effect.getSpellEffectType().equals(SpellEffectType.NecPet)) {
try {
ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getPetNPCByName(soliniaSpell.getTeleportZone());
if (npc == null) {
return new Tuple<Boolean, String>(false, "NPC not found for pet");
}
if (npc.isCorePet() == false) {
System.out.print("NPC " + soliniaSpell.getTeleportZone() + " is not defined as a pet");
return new Tuple<Boolean, String>(false, "Pet is not defined on spell");
}
} catch (CoreStateInitException e) {
return new Tuple<Boolean, String>(false, "Plugin not initialised");
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
return new Tuple<Boolean, String>(false, "Exception: " + e.getStackTrace() + " " + e.getMessage());
}
return new Tuple<Boolean, String>(true, "");
}
Aggregations