Implement basic Pet AI behaviors. Add /search command.

master
sigonasr2 8 years ago
parent 8e9053f308
commit ea59b4890c
  1. BIN
      TwosideKeeper.jar
  2. 5
      src/plugin.yml
  3. 16
      src/sig/plugin/TwosideKeeper/CustomDamage.java
  4. 93
      src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java
  5. 177
      src/sig/plugin/TwosideKeeper/HelperStructures/Pet.java
  6. 7
      src/sig/plugin/TwosideKeeper/HelperStructures/PetState.java
  7. 4
      src/sig/plugin/TwosideKeeper/HelperStructures/PlayerMode.java
  8. 1
      src/sig/plugin/TwosideKeeper/LivingEntityStructure.java
  9. 39
      src/sig/plugin/TwosideKeeper/Modes/Summoner.java
  10. 2
      src/sig/plugin/TwosideKeeper/MonsterController.java
  11. 103
      src/sig/plugin/TwosideKeeper/TwosideKeeper.java
  12. 63
      src/sig/plugin/TwosideKeeper/runServerTick.java

Binary file not shown.

@ -187,4 +187,9 @@ commands:
description: Determine if a player is a fresh blood player or not.
usage: /fb <player>
permission: TwosideKeeper.money
permission-message: No permissions!
search:
description: Displays a listing of items in Recycling Centers. Supply an argument to search for a specific item.
usage: /search [Item Name]
permission: TwosideKeeper.money
permission-message: No permissions!

@ -689,6 +689,9 @@ public class CustomDamage {
LivingEntityStructure les = LivingEntityStructure.GetLivingEntityStructure(target);
les.SetTarget(getDamagerEntity(damager));
les.lastHitbyPlayer = TwosideKeeper.getServerTickTime();
if (getDamagerEntity(damager) instanceof Player) {
les.lastPlayerThatHit = (Player)getDamagerEntity(damager);
}
}
EntityUtils.applyDamageIndicator(target, damage, (isFlagSet(pd.lasthitproperties,IS_CRIT))?IndicatorType.CRIT:IndicatorType.REGULAR);
} else
@ -797,6 +800,7 @@ public class CustomDamage {
restoreHealthToPartyMembersWithProtectorSet(p);
applySustenanceSetonHitEffects(p);
reduceStrengthAmountForStealthSet(p);
triggerPetHelp(p,damager);
damage = handleBlockStacks(p,damage);
if (!isFlagSet(flags,NOAOE)) {
if (damage<p.getHealth()) {increaseArtifactArmorXP(p,(int)damage);}
@ -1089,6 +1093,15 @@ public class CustomDamage {
return damage;
}
private static void triggerPetHelp(Player p, Entity damager) {
PlayerStructure pd = PlayerStructure.GetPlayerStructure(p);
if (pd.myPet!=null && pd.myPet.getEntity().isValid()) {
if (getDamagerEntity(damager)!=null) {
pd.myPet.setTarget(getDamagerEntity(damager));
}
}
}
private static void applyShieldChargeEffect(Player p, ItemStack weapon, String reason) {
if (p.isSneaking() && (reason==null || !reason.equalsIgnoreCase("shield charge")) &&
weapon!=null && weapon.equals(p.getEquipment().getItemInMainHand())) {
@ -2435,6 +2448,9 @@ public class CustomDamage {
if ((shooter!=null && shooter.isDead()) || (target!=null && target.isDead())) {
return true;
}
if (shooter!=null && target!=null && LivingEntityStructure.isFriendly(shooter, target)) {
return true; //Cancel all damage for friendly targets.
}
target.setLastDamage(0);
target.setNoDamageTicks(0);
target.setMaximumNoDamageTicks(0);

@ -3022,6 +3022,9 @@ public class GenericFunctions {
}
public static String GetEntityDisplayName(Entity e) {
if (e==null) {
return "NULL";
}
if (e instanceof LivingEntity) {
LivingEntity l = (LivingEntity)e;
if (l.getCustomName()!=null) {
@ -3212,7 +3215,7 @@ public class GenericFunctions {
public static void PerformMobControl(Player player) {
PlayerStructure pd = (PlayerStructure)TwosideKeeper.playerdata.get(player.getUniqueId());
boolean hasFullSet = ItemSet.hasFullSet(player, ItemSet.DAWNTRACKER);
List<LivingEntity> le = GenericFunctions.getNearbyMobs(player.getLocation(), 16);
List<LivingEntity> le = GenericFunctions.getNearbyMobsIncludingPlayers(player.getLocation(), 16);
for (LivingEntity ent : le) {
boolean allowed=true;
if (ent instanceof Player && PVP.isFriendly(player, (Player)ent)) {
@ -4124,7 +4127,7 @@ public class GenericFunctions {
* ONLY FOR BLITZEN LIGHTNING STRIKE
*/
public static void DealBlitzenLightningStrikeToNearbyMobs(Location l, double basedmg, int range, Entity damager, int flags) {
List<LivingEntity> nearbyentities = getNearbyMobs(l,range);
List<LivingEntity> nearbyentities = getNearbyMobsIncludingPlayers(l,range);
for (LivingEntity ent : nearbyentities) {
boolean allowed=true;
if (ent instanceof Player && CustomDamage.getDamagerEntity(damager) instanceof Player &&
@ -4220,7 +4223,7 @@ public class GenericFunctions {
return (int)(GetModifiedCooldown(cooldown_time,p)-(TwosideKeeper.getServerTickTime()-current_cooldown));
}
public static List<LivingEntity> getNearbyMobs(Location l, int range) {
public static List<LivingEntity> getNearbyMobsIncludingPlayers(Location l, int range) {
Collection<Entity> ents = l.getWorld().getNearbyEntities(l, range, range, range);
List<LivingEntity> monsterlist = new ArrayList<LivingEntity>();
for (Entity e : ents) {
@ -5453,7 +5456,7 @@ public class GenericFunctions {
PlayerStructure pd = PlayerStructure.GetPlayerStructure(p);
if (pd.last_siphon+GetModifiedCooldown(TwosideKeeper.SIPHON_COOLDOWN,p)<=TwosideKeeper.getServerTickTime()) {
if (p.isOnGround()) {
List<LivingEntity> list = GenericFunctions.getNearbyMobs(p.getLocation(), 16);
List<LivingEntity> list = GenericFunctions.getNearbyMobsIncludingPlayers(p.getLocation(), 16);
List<LivingEntity> poisonlist = new ArrayList<LivingEntity>();
int totalpoisonstacks = 0;
for (LivingEntity ent : list) {
@ -5733,4 +5736,86 @@ public class GenericFunctions {
aPlugin.API.setItem(p, p.getOpenInventory(), i, view.getItem(i));
}
}
public static List<ItemContainer> getItemList(List<ItemStack> items) {
List<ItemContainer> itemsList = new ArrayList<ItemContainer>();
for (ItemStack i: items) {
boolean found=false;
for (ItemContainer ic : itemsList) {
if (ic.getItem().isSimilar(i)) {
ic.setAmount(ic.getAmount()+i.getAmount());
found=true;
break;
}
}
if (!found) {
itemsList.add(new ItemContainer(i));
}
}
return itemsList;
}
public static String generateItemList(List<ItemContainer> items) {
return generateItemList(items,null);
}
public static String generateItemList(List<ItemContainer> items, String[] args) {
List<String> filters = new ArrayList<String>();
if (args==null || args.length==0) {
//No filters applied.
} else {
for (String str : args) {
filters.add(str);
}
}
//Sort from highest to least. Then in alphabetical order.
List<ItemContainer> sortedlist = new ArrayList<ItemContainer>();
for (int i=0;i<items.size();i++) {
//Try to insert it into the list.
boolean found=false;
ItemContainer currentItem = items.get(i);
boolean matchesAll=true;
String displayName = GenericFunctions.UserFriendlyMaterialName(currentItem.getItem());
for (String s : filters) {
if (!displayName.toLowerCase().contains(s.toLowerCase())) {
//TwosideKeeper.log("Cannot find "+s+" in "+displayName, 1);
matchesAll=false;
break;
}
}
if (sortedlist.size()>0) {
//Compare through every item.
if (matchesAll) {
for (int j=0;j<sortedlist.size();j++) {
ItemContainer checkItem = sortedlist.get(j);
if (currentItem.getAmount()>checkItem.getAmount()) {
sortedlist.add(j,currentItem);
found=true;
break;
} else
if (currentItem.getAmount()==checkItem.getAmount() &&
GenericFunctions.UserFriendlyMaterialName(currentItem.getItem()).compareTo(GenericFunctions.UserFriendlyMaterialName(checkItem.getItem()))<0) {
sortedlist.add(j,currentItem);
found=true;
break;
}
}
if (!found) {
sortedlist.add(currentItem);
}
}
} else {
if (matchesAll) {
sortedlist.add(items.get(i));
}
}
}
return generateItemsList(sortedlist);
}
private static String generateItemsList(List<ItemContainer> list) {
StringBuilder sb = new StringBuilder("");
for (int i=0;i<list.size();i++) {
sb.append(ChatColor.GRAY+GenericFunctions.UserFriendlyMaterialName(list.get(i).getItem())+(TwosideKeeperAPI.isSetItem(list.get(i).getItem())?" (T"+TwosideKeeperAPI.getItemTier(list.get(i).getItem())+")":"")+(list.get(i).getAmount()>1?ChatColor.YELLOW+" x"+list.get(i).getAmount():"")+ChatColor.RESET+(i+1!=list.size()?", ":""));
}
return sb.toString();
}
}

@ -1,23 +1,38 @@
package sig.plugin.TwosideKeeper.HelperStructures;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import sig.plugin.TwosideKeeper.CustomDamage;
import sig.plugin.TwosideKeeper.LivingEntityStructure;
import sig.plugin.TwosideKeeper.PlayerStructure;
import sig.plugin.TwosideKeeper.TwosideKeeper;
import sig.plugin.TwosideKeeper.HelperStructures.Common.GenericFunctions;
import sig.plugin.TwosideKeeper.HelperStructures.Utils.MovementUtils;
import sig.plugin.TwosideKeeper.HelperStructures.Utils.PlayerUtils;
public class Pet {
final static public int LEASHRANGE = 16;
final static public int LEASHRANGE_SQUARED = LEASHRANGE*LEASHRANGE;
Player owner;
Location targetLoc;
Location lastPos;
double moveSpd = 1;
double jumpHeight = 3.0;
int attackRate = 10;
long lastAttacked = 0;
LivingEntity ent;
String name="";
int stuckTimer=0;
LivingEntity myTarget=null;
PetState myState = PetState.PASSIVE;
double myDamage = 5;
public Pet(Player owner, EntityType ent, String nickname) {
try {
@ -35,18 +50,156 @@ public class Pet {
}
public void run() {
if (owner==null || !owner.isValid()) {
if (owner==null || !owner.isValid() || ent==null || !ent.isValid()) {
cleanup();
return;
}
if (owner.getLocation().distanceSquared(ent.getLocation())>LEASHRANGE_SQUARED) {
ent.teleport(owner.getLocation());
grabEnemyTarget();
switch (myState) {
case PASSIVE:{
if (myTarget!=null && !myTarget.isValid()) {
myTarget=null;
//TwosideKeeper.log("My Target is now "+GenericFunctions.GetEntityDisplayName(myTarget), 1);
} else
if (myTarget!=null) { //This is a valid target. If we are too far away, move towards it. Perform an attack when close enough if possible.
if (ent.getLocation().distanceSquared(myTarget.getLocation())>2) {
setTargetLocation(myTarget.getLocation());
setState(PetState.MOVING);
} else {
//We are in attack range. Prepare an attack.
if (lastAttacked+attackRate<=TwosideKeeper.getServerTickTime()) {
myState=PetState.ATTACKING;
lastAttacked=TwosideKeeper.getServerTickTime();
}
}
}
if (owner.getLocation().distanceSquared(ent.getLocation())>LEASHRANGE_SQUARED) {
ent.teleport(owner.getLocation());
}
}break;
case MOVING:{
if (targetLoc!=null && ent.getLocation().distanceSquared(targetLoc)>2) {
Location loc = MoveTowardsPoint(targetLoc);
if (lastPos!=null) {
if (lastPos.distanceSquared(ent.getLocation())<4) {
stuckTimer++;
//TwosideKeeper.log("Stuck Timer: "+stuckTimer, 1);
} else {
stuckTimer=0;
lastPos=null;
setState(PetState.PASSIVE);
}
} else {
lastPos = loc.clone();
}
}
if (stuckTimer==20) {
//Try jumping.
ent.setVelocity(new Vector(0,jumpHeight,0));
stuckTimer++;
} else
if (stuckTimer==50) {
ent.teleport(owner);
stuckTimer=0;
lastPos=null;
targetLoc=null;
setState(PetState.PASSIVE);
}
if (targetLoc!=null && ent.getLocation().distanceSquared(targetLoc)<=2) {
targetLoc=null;
setState(PetState.PASSIVE);
}
if (targetLoc==null) {
setState(PetState.PASSIVE);
}
}break;
case ATTACKING:{
if (myTarget!=null) {
MoveTowardsPoint(myTarget.getLocation(),0.4);
//Deal damage.
CustomDamage.ApplyDamage(myDamage, ent, myTarget, null, "Pet Attack");
}
setState(PetState.PASSIVE);
}break;
}
if (targetLoc!=null && ent.getLocation().distanceSquared(targetLoc)>1) {
Vector dirToMove = MovementUtils.getVelocityTowardsLocation(ent.getLocation(), targetLoc, moveSpd);
ent.setVelocity(dirToMove);
}
private Location MoveTowardsPoint(Location targetLoc) {
return MoveTowardsPoint(targetLoc,1);
}
private Location MoveTowardsPoint(Location targetLoc, double mult) {
Vector dirToMove = MovementUtils.getVelocityTowardsLocation(ent.getLocation(), targetLoc, moveSpd*mult);
Location loc = ent.getLocation();
loc.setDirection(dirToMove);
ent.setVelocity(dirToMove);
ent.teleport(loc);
return loc;
}
public void setTarget(LivingEntity target) {
setTarget(target,false);
}
public void setTarget(LivingEntity target, boolean force) {
if (myTarget==null || myTarget.getLocation().distanceSquared(ent.getLocation())>64 || force) {
myTarget = target;
}
}
private void grabEnemyTarget() {
if (myTarget!=null){
if (myTarget.isValid()) {
if (!myTarget.getWorld().equals(ent.getWorld())) {
myTarget=null;
return;
}
if (myTarget.getLocation().distanceSquared(ent.getLocation())>64) {
myTarget=null;
return;
}
}
}
if (ent.hasAI() && isFighting()) {
ent.setAI(false);
if (myTarget==null || !myTarget.isValid()) {
//Attempt to find a target. Try the owner's target first.
PlayerStructure pd = PlayerStructure.GetPlayerStructure(owner);
myTarget = pd.target;
if (myTarget==null) {
//Try to find a nearby target.
List<LivingEntity> ents = GenericFunctions.getNearbyMonsters(ent.getLocation(), 4);
double closestrange = Integer.MAX_VALUE;
LivingEntity selectedent = null;
for (int i=0;i<ents.size();i++) {
LivingEntity ent = ents.get(i);
if (ent==this.ent || LivingEntityStructure.isFriendly(owner, ent)) {
ents.remove(i--);
} else {
double dist = ent.getLocation().distanceSquared(this.ent.getLocation());
if (closestrange>dist) {
closestrange = dist;
selectedent = ent;
}
}
}
if (selectedent!=null) {
myTarget=selectedent;
}
}
//TwosideKeeper.log("My Target is now "+GenericFunctions.GetEntityDisplayName(myTarget), 1);
}
} else
if (!ent.hasAI() && !isFighting()) {
ent.setAI(true);
}
}
public PetState getState() {
return myState;
}
public void setTargetLocation(Location loc) {
this.targetLoc=loc;
@ -76,4 +229,16 @@ public class Pet {
public void cleanup() {
ent.remove();
}
public boolean isFighting() {
if (owner!=null && PlayerUtils.PlayerIsInCombat(owner)) {
return true;
} else {
return false;
}
}
public void setState(PetState state) {
myState = state;
}
}

@ -0,0 +1,7 @@
package sig.plugin.TwosideKeeper.HelperStructures;
public enum PetState {
PASSIVE,
MOVING,
ATTACKING;
}

@ -304,5 +304,7 @@ public enum PlayerMode {
this.helperBook=descBook;
}
public static boolean isLeatherPlayerMode(PlayerMode mode) {
return mode==PlayerMode.RANGER || mode==PlayerMode.SUMMONER;
}
}

@ -52,6 +52,7 @@ public class LivingEntityStructure {
public long lastBurnTick=0;
public long lastHit=0;
public long lastHitbyPlayer=0;
public Player lastPlayerThatHit=null;
public float MoveSpeedMultBeforeCripple=1f;
public Channel currentChannel=null;
public boolean isImportantGlowEnemy=true;

@ -0,0 +1,39 @@
package sig.plugin.TwosideKeeper.Modes;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import sig.plugin.TwosideKeeper.PlayerStructure;
import sig.plugin.TwosideKeeper.HelperStructures.PetState;
public class Summoner {
/**
*
* @return False means stop the action from passing onto other sections of code.
*/
public static boolean HandleSummonerInteraction(Event e) {
if (e instanceof PlayerInteractEvent) {
PlayerInteractEvent ev = (PlayerInteractEvent)e;
PlayerStructure pd = PlayerStructure.GetPlayerStructure(ev.getPlayer());
if (ev.getAction()==Action.RIGHT_CLICK_BLOCK && pd.myPet!=null && pd.myPet.getState()==PetState.PASSIVE) {
PetMoveCommand(ev.getClickedBlock().getLocation(),ev.getPlayer());
}
} else
if (e instanceof PlayerInteractEntityEvent) {
PlayerInteractEntityEvent ev = (PlayerInteractEntityEvent)e;
}
return false;
}
private static void PetMoveCommand(Location targetLoc, Player p) {
PlayerStructure pd = PlayerStructure.GetPlayerStructure(p);
if (pd.myPet!=null) {
pd.myPet.setTargetLocation(targetLoc);
pd.myPet.setState(PetState.MOVING);
}
}
}

@ -231,7 +231,7 @@ public class MonsterController {
}
}
}
return (/*dist<4096*/ dist<2304 && (GenericFunctions.getNearbyMobs(ent.getLocation(), 16).size()<(nearbyplayers*2)+1));
return (/*dist<4096*/ dist<2304 && (GenericFunctions.getNearbyMobsIncludingPlayers(ent.getLocation(), 16).size()<(nearbyplayers*2)+1));
}
private static boolean meetsConditionsToBeElite(LivingEntity ent) {

@ -245,6 +245,7 @@ import sig.plugin.TwosideKeeper.HelperStructures.Pet;
import sig.plugin.TwosideKeeper.HelperStructures.PlayerMode;
import sig.plugin.TwosideKeeper.HelperStructures.Pronouns;
import sig.plugin.TwosideKeeper.HelperStructures.QuestStatus;
import sig.plugin.TwosideKeeper.HelperStructures.RecyclingCenterNode;
import sig.plugin.TwosideKeeper.HelperStructures.ServerType;
import sig.plugin.TwosideKeeper.HelperStructures.SessionState;
import sig.plugin.TwosideKeeper.HelperStructures.SpleefArena;
@ -297,6 +298,7 @@ import sig.plugin.TwosideKeeper.HolidayEvents.TreeBuilder;
import sig.plugin.TwosideKeeper.Logging.BowModeLogger;
import sig.plugin.TwosideKeeper.Logging.LootLogger;
import sig.plugin.TwosideKeeper.Logging.MysteriousEssenceLogger;
import sig.plugin.TwosideKeeper.Modes.Summoner;
import sig.plugin.TwosideKeeper.Monster.ChallengeBlaze;
import sig.plugin.TwosideKeeper.Monster.ChallengeGhast;
import sig.plugin.TwosideKeeper.Monster.Dummy;
@ -1424,6 +1426,25 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
aPlugin.API.discordSendRaw("Rolled **"+selectednumb+"**");
recentnumbers.add(selectednumb);
},"roll");
aPlugin.API.addCommand(args->{
List<ItemStack> recyclingCenterItems = populateRecyclingCenterItems();
if (args.length==0) {
//Get a master list of all Recycling Center items.
aPlugin.API.discordSendRaw("'''\n"+
GenericFunctions.generateItemList(
GenericFunctions.getItemList(recyclingCenterItems)
)+"\n'''"
);
} else {
//Try to use the search phrase given.
aPlugin.API.discordSendRaw("'''\n"+
GenericFunctions.generateItemList(
GenericFunctions.getItemList(recyclingCenterItems)
,args
)+"\n'''"
);
}
},"search");
}, 90);
}
@ -1722,6 +1743,25 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
return true;
}
else
if (cmd.getName().equalsIgnoreCase("search")) {
List<ItemStack> recyclingCenterItems = populateRecyclingCenterItems();
if (args.length==0) {
//Get a master list of all Recycling Center items.
sender.sendMessage(
GenericFunctions.generateItemList(
GenericFunctions.getItemList(recyclingCenterItems)
)
);
} else {
//Try to use the search phrase given.
sender.sendMessage(GenericFunctions.generateItemList(
GenericFunctions.getItemList(recyclingCenterItems)
,args
));
}
return false;
}
else
if (cmd.getName().equalsIgnoreCase("dailyloot")) {
if (args.length==1) {
UUID id = UUID.fromString(args[0]);
@ -3348,6 +3388,23 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
}
return false;
}
private static List<ItemStack> populateRecyclingCenterItems() {
List<ItemStack> recyclingCenterItems = new ArrayList<ItemStack>();
for (RecyclingCenterNode node : TwosideKeeper.TwosideRecyclingCenter.nodes) {
BlockState bs = node.getRecyclingCenterLocation().getBlock().getState();
if (bs instanceof Chest) {
Chest c = (Chest)bs;
for (ItemStack it : c.getBlockInventory().getContents()) {
if (ItemUtils.isValidItem(it)) {
recyclingCenterItems.add(it);
}
}
} else {
TwosideKeeper.log("WARNING! Cannot find chest at Node location "+node.toString()+"!", 1);
}
}
return recyclingCenterItems;
}
private void setTier(ItemStack piece, int tier) {
TwosideKeeperAPI.setItemTier(piece, tier);
piece.addUnsafeEnchantment(Enchantment.DURABILITY, 99);
@ -3639,6 +3696,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
@EventHandler(priority=EventPriority.LOW,ignoreCancelled = true)
public void onPlayerJoin(PlayerJoinEvent ev) {
final double hpratio = ev.getPlayer().getHealth()/ev.getPlayer().getMaxHealth();
for (int i=0;i<Bukkit.getOnlinePlayers().toArray().length;i++) {
Player p = (Player)Bukkit.getOnlinePlayers().toArray()[i];
@ -3659,17 +3717,14 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
PlayerStructure.removeTemporaryCooldownDisplayBuffs(ev.getPlayer());
ItemSet.updateItemSets(ev.getPlayer());
log("[TASK] New Player Data has been added. Size of array: "+playerdata.size(),4);
PLAYERJOINTOGGLE=true;
GenericFunctions.updateSetItemsInInventory(ev.getPlayer().getInventory());
PLAYERJOINTOGGLE=false;
ev.getPlayer().setCollidable(true);
Bukkit.getScheduler().runTaskLater(TwosideKeeper.plugin,()->{setPlayerMaxHealth(ev.getPlayer(),hpratio,true);},1);
ev.getPlayer().setVelocity(new Vector(0,0,0));
CustomDamage.removeIframe(ev.getPlayer());
//Update player max health. Check equipment too.
setPlayerMaxHealth(ev.getPlayer());
FilterCubeItem.populateFilterCubeItemList(ev.getPlayer());
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "scoreboard players set "+ev.getPlayer().getName()+" Deaths "+ev.getPlayer().getStatistic(Statistic.DEATHS));
GenericFunctions.logAndRemovePotionEffectFromEntity(PotionEffectType.GLOWING,ev.getPlayer());
@ -3767,7 +3822,9 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
PlayerStructure pd = (PlayerStructure)playerdata.get(ev.getPlayer().getUniqueId());
//Make sure to save the config for this player.
pd.saveConfig();
pd.myPet.cleanup();
if (pd.myPet!=null) {
pd.myPet.cleanup();
}
playerdata.remove(ev.getPlayer().getUniqueId());
//Bukkit.dispatchCommand(Bukkit.getServer().getConsoleSender(), "scoreboard players reset "+ev.getPlayer().getName().toLowerCase());
log("[TASK] Player Data for "+ev.getPlayer().getName()+" has been removed. Size of array: "+playerdata.size(),4);
@ -4683,6 +4740,12 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
PerformShieldCharge(p, pd);
}
if (PlayerMode.getPlayerMode(p)==PlayerMode.SUMMONER) {
if (!Summoner.HandleSummonerInteraction(ev)) {
return;
}
}
if (!Christmas.RunPlayerInteractEvent(ev)) {return;}
if (ev.getClickedBlock()!=null && ev.getClickedBlock().getType()==Material.CHEST &&
@ -5691,7 +5754,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
GenericFunctions.DealDamageToNearbyMobs(checkpos, 0, 1, true, 2, p, p.getEquipment().getItemInMainHand(), false, "Shield Charge");
}
}
List<LivingEntity> ents = GenericFunctions.getNearbyMobs(p.getLocation(), 16);
List<LivingEntity> ents = GenericFunctions.getNearbyMobsIncludingPlayers(p.getLocation(), 16);
for (LivingEntity ent : ents) {
if (!(ent instanceof Player)) {
LivingEntityStructure les = LivingEntityStructure.GetLivingEntityStructure(ent);
@ -6636,7 +6699,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
if (PlayerMode.getPlayerMode(p)==PlayerMode.BARBARIAN &&
((hasFullSet && pd.last_mock+GenericFunctions.GetModifiedCooldown(TwosideKeeper.MOCK_COOLDOWN/2,ev.getPlayer())<=TwosideKeeper.getServerTickTime()) || pd.last_mock+GenericFunctions.GetModifiedCooldown(TwosideKeeper.MOCK_COOLDOWN,ev.getPlayer())<=TwosideKeeper.getServerTickTime())) {
pd.last_mock=getServerTickTime();
List<LivingEntity> le = GenericFunctions.getNearbyMobs(p.getLocation(), 12);
List<LivingEntity> le = GenericFunctions.getNearbyMobsIncludingPlayers(p.getLocation(), 12);
for (LivingEntity ent : le) {
boolean allowed=true;
if (ent instanceof Player && PVP.isFriendly(ev.getPlayer(), (Player)ent)) {
@ -6869,6 +6932,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
ev.getInventory().getTitle()!=null) {
FilterCubeItem.populateFilterCubeItemList((Player)ev.getPlayer());
}
Bukkit.getScheduler().runTaskLater(TwosideKeeper.plugin, ()->{GenericFunctions.refreshInventoryView(p);}, 1);
}
}
public void DropDeathInventoryContents(Player p, Location deathloc) {
@ -9134,12 +9198,25 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
}
}
if (!(ms.GetTarget() instanceof Player) && ms.GetTarget()!=null && ms.GetTarget().isValid() && !ms.GetTarget().isDead()) {
LivingEntityStructure killerStructure = LivingEntityStructure.GetLivingEntityStructure(ms.GetTarget());
if (killerStructure.isPet &&
killerStructure.petOwner!=null) {
ms.SetTarget(killerStructure.petOwner);
}
}
if (killedByPlayer && (LivingEntityStructure.GetLivingEntityStructure(ev.getEntity()).lastHitbyPlayer+300>TwosideKeeper.getServerTickTime())) {
//Get the player that killed the monster.
int luckmult = 0;
int unluckmult = 0;
ms = (LivingEntityStructure)livingentitydata.get(m.getUniqueId());
Player p = (Player)ms.GetTarget();
Player p = null;
if (!(ms.GetTarget() instanceof Player)) {
p = ms.lastPlayerThatHit;
} else {
p = (Player)ms.GetTarget();
}
boolean isRanger=PlayerMode.isRanger(p);
boolean isSlayer=PlayerMode.isSlayer(p);
@ -10244,7 +10321,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
//See if this armor type is not being worn by the player.
if (armor.getType().toString().contains("BOOTS") &&
p.getEquipment().getBoots()==null &&
(!PlayerMode.isRanger(p) || (armor.getType().toString().contains("LEATHER"))) &&
(!PlayerMode.isLeatherPlayerMode(PlayerMode.getPlayerMode(p)) || (armor.getType().toString().contains("LEATHER"))) &&
!PlayerMode.isSlayer(p) &&
pd.equiparmor) {
p.getEquipment().setBoots(armor);
@ -10253,7 +10330,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} else
if (armor.getType().toString().contains("LEGGINGS") &&
p.getEquipment().getLeggings()==null &&
(!PlayerMode.isRanger(p) || (armor.getType().toString().contains("LEATHER"))) &&
(!PlayerMode.isLeatherPlayerMode(PlayerMode.getPlayerMode(p)) || (armor.getType().toString().contains("LEATHER"))) &&
!PlayerMode.isSlayer(p) &&
pd.equiparmor) {
p.getEquipment().setLeggings(armor);
@ -10262,7 +10339,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} else
if (armor.getType().toString().contains("CHESTPLATE") &&
p.getEquipment().getChestplate()==null &&
(!PlayerMode.isRanger(p) || (armor.getType().toString().contains("LEATHER"))) &&
(!PlayerMode.isLeatherPlayerMode(PlayerMode.getPlayerMode(p)) || (armor.getType().toString().contains("LEATHER"))) &&
!PlayerMode.isSlayer(p) &&
pd.equiparmor) {
p.getEquipment().setChestplate(armor);
@ -10271,7 +10348,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} else
if (armor.getType().toString().contains("HELMET") &&
p.getEquipment().getHelmet()==null &&
(!PlayerMode.isRanger(p) || (armor.getType().toString().contains("LEATHER"))) &&
(!PlayerMode.isLeatherPlayerMode(PlayerMode.getPlayerMode(p)) || (armor.getType().toString().contains("LEATHER"))) &&
!PlayerMode.isSlayer(p) &&
pd.equiparmor) {
p.getEquipment().setHelmet(armor);
@ -10281,7 +10358,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
if (armor.getType().toString().contains("SHIELD") &&
(p.getEquipment().getItemInMainHand().getType()==Material.AIR || p.getInventory().getExtraContents()[0]==null) &&
!PlayerMode.isStriker(p) &&
(!PlayerMode.isRanger(p) || (armor.getType().toString().contains("LEATHER"))) &&
(!PlayerMode.isLeatherPlayerMode(PlayerMode.getPlayerMode(p)) || (armor.getType().toString().contains("LEATHER"))) &&
pd.equipweapons) {
if (p.getEquipment().getItemInMainHand().getType()==Material.AIR) {
p.getEquipment().setItemInMainHand(armor);

@ -35,38 +35,41 @@ public class runServerTick implements Runnable{
}
for (Player p : Bukkit.getOnlinePlayers()) {
PlayerStructure pd = PlayerStructure.GetPlayerStructure(p);
//pd.myModel.displayModel(p.getLocation());
if (pd.myPet!=null) {
pd.myPet.run();
}
if (PlayerMode.isSummoner(p)) {
//long timer = System.nanoTime();
LivingEntity targetent = aPlugin.API.rayTraceTargetEntity(p, 16);
if (targetent!=null) {
LivingEntityStructure les = LivingEntityStructure.GetLivingEntityStructure(targetent);
if (LivingEntityStructure.isFriendly(p,targetent)) {
les.setGlow(p, Color.DARK_AQUA);
} else {
les.setGlow(p, Color.DARK_GRAY);
}
if (pd.lastTarget!=null && pd.lastTarget!=targetent) {
LivingEntityStructure les2 = LivingEntityStructure.GetLivingEntityStructure(pd.lastTarget);
les2.setGlow(p, null);
pd.lastTarget.setGlowing(false);
GlowAPI.setGlowing(pd.lastTarget, null, p);
pd.lastTarget=null;
if (!aPluginAPIWrapper.isAFK(p)) {
//pd.myModel.displayModel(p.getLocation());
if (pd.myPet!=null) {
pd.myPet.run();
}
if (PlayerMode.isSummoner(p)) {
//long timer = System.nanoTime();
LivingEntity targetent = aPlugin.API.rayTraceTargetEntity(p, 16);
if (targetent!=null) {
LivingEntityStructure les = LivingEntityStructure.GetLivingEntityStructure(targetent);
if (LivingEntityStructure.isFriendly(p,targetent)) {
les.setGlow(p, Color.DARK_AQUA);
} else {
les.setGlow(p, Color.DARK_GRAY);
}
if (pd.lastTarget!=null && pd.lastTarget!=targetent) {
LivingEntityStructure les2 = LivingEntityStructure.GetLivingEntityStructure(pd.lastTarget);
les2.setGlow(p, null);
pd.lastTarget.setGlowing(false);
GlowAPI.setGlowing(pd.lastTarget, null, p);
pd.lastTarget=null;
}
pd.lastTarget=targetent;
}
pd.lastTarget=targetent;
//TwosideKeeper.log("Time Execution took: "+((System.nanoTime()-timer)/1000000)+"ms", 1);
}
//TwosideKeeper.log("Time Execution took: "+((System.nanoTime()-timer)/1000000)+"ms", 1);
}
if (pd.mouseoverhealthbar && pd.lastGrabbedTarget+10<=TwosideKeeper.getServerTickTime()) {
LivingEntity targetent = aPlugin.API.rayTraceTargetEntity(p, 16);
if (targetent!=null && (!(targetent instanceof ArmorStand) || (targetent instanceof ArmorStand && ((ArmorStand)targetent).isVisible())) &&
!targetent.hasPotionEffect(PotionEffectType.INVISIBILITY) && (pd.lastViewedTarget==null || !pd.lastViewedTarget.equals(targetent.getUniqueId()))) {
pd.customtitle.updateCombatBar(p, targetent);
pd.lastGrabbedTarget=TwosideKeeper.getServerTickTime();
pd.lastViewedTarget = targetent.getUniqueId();
if (pd.mouseoverhealthbar && pd.lastGrabbedTarget+10<=TwosideKeeper.getServerTickTime()) {
LivingEntity targetent = aPlugin.API.rayTraceTargetEntity(p, 16);
if (targetent!=null && (!(targetent instanceof ArmorStand) || (targetent instanceof ArmorStand && ((ArmorStand)targetent).isVisible())) &&
!targetent.hasPotionEffect(PotionEffectType.INVISIBILITY) && (pd.lastViewedTarget==null || !pd.lastViewedTarget.equals(targetent.getUniqueId()))
&& targetent.hasLineOfSight(p)) {
pd.customtitle.updateCombatBar(p, targetent);
pd.lastGrabbedTarget=TwosideKeeper.getServerTickTime();
pd.lastViewedTarget = targetent.getUniqueId();
}
}
}
}

Loading…
Cancel
Save