Skip to content

Commit

Permalink
Better bleed effects, fixed some barrier logic, added riptide effect,…
Browse files Browse the repository at this point in the history
… adding flying condition, adding libs disguises soundgroups
  • Loading branch information
UltraFaceguy committed Aug 6, 2021
1 parent d503904 commit 6f41323
Show file tree
Hide file tree
Showing 29 changed files with 442 additions and 126 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</parent>

<artifactId>strife</artifactId>
<version>3.4.4</version>
<version>3.4.5</version>
<packaging>jar</packaging>

<name>strife</name>
Expand Down Expand Up @@ -109,7 +109,7 @@
<dependency>
<groupId>LibsDisguises</groupId>
<artifactId>LibsDisguises</artifactId>
<version>10.0.16-SNAPSHOT</version>
<version>10.0.26-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
55 changes: 55 additions & 0 deletions src/main/java/land/face/strife/StrifePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ The MIT License Copyright (c) 2015 Teal Cube Games
*/
package land.face.strife;

import static com.comphenix.protocol.PacketType.Play.Server.ENTITY_METADATA;

import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.reflect.StructureModifier;
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
import com.comphenix.xp.lookup.LevelingRate;
import com.tealcube.minecraft.bukkit.facecore.logging.PluginLogger;
import com.tealcube.minecraft.bukkit.facecore.plugin.FacePlugin;
Expand Down Expand Up @@ -51,6 +58,7 @@ The MIT License Copyright (c) 2015 Teal Cube Games
import land.face.strife.data.UniqueEntity;
import land.face.strife.data.ability.Ability;
import land.face.strife.data.champion.LifeSkillType;
import land.face.strife.data.effects.Riptide;
import land.face.strife.data.effects.ShootBlock;
import land.face.strife.data.effects.TriggerLoreAbility;
import land.face.strife.hooks.SnazzyPartiesHook;
Expand Down Expand Up @@ -153,8 +161,11 @@ The MIT License Copyright (c) 2015 Teal Cube Games
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitTask;

public class StrifePlugin extends FacePlugin {
Expand Down Expand Up @@ -537,6 +548,37 @@ public void enable() {

DamageUtil.refresh();

Riptide.buildNMSEnum(this);
Riptide.startTask(this);

ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(this, ENTITY_METADATA) {
public void onPacketSending(PacketEvent event) {
try {
int entityId = event.getPacket().getIntegers().read(0);
if (entityId < 0) {
return;
}
Entity entity = event.getPacket()
.getEntityModifier(event.getPlayer().getWorld()).read(0);
if (entity instanceof LivingEntity && Riptide
.isRiptideAnimationPlaying((LivingEntity) entity)) {
StructureModifier<List<WrappedWatchableObject>> watcher = event.getPacket()
.getWatchableCollectionModifier();
for (WrappedWatchableObject watch : watcher.read(0)) {
if (watch.getIndex() == 6) {
watch.setValue(Riptide.RIPTIDE_POSE_ENUM);
}
if (watch.getIndex() == 7) {
watch.setValue((byte) 4);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
});

LogUtil.printInfo("Loaded " + uniqueEntityManager.getLoadedUniquesMap().size() + " mobs");
LogUtil.printInfo("Loaded " + effectManager.getLoadedEffects().size() + " effects");
LogUtil.printInfo("Loaded " + abilityManager.getLoadedAbilities().size() + " abilities");
Expand All @@ -552,6 +594,7 @@ public void disable() {
entityHider.close();
HandlerList.unregisterAll(this);
Bukkit.getScheduler().cancelTasks(this);
ProtocolLibrary.getProtocolManager().removePacketListeners(this);

strifeMobManager.despawnAllTempEntities();
bossBarManager.clearBars();
Expand Down Expand Up @@ -579,6 +622,18 @@ public void disable() {
LogUtil.printInfo("Successfully disabled Strife-v" + getDescription().getVersion());
}

public static Class<?> getNMSClass(String name, Plugin plugin) {
String version = plugin.getServer().getClass().getPackage().getName().split("\\.")[3];
try {
return Class.forName("net.minecraft.server." + version + "." + name);
}

catch (ClassNotFoundException e) {
e.printStackTrace();
return null;
}
}

private VersionedSmartYamlConfiguration defaultSettingsLoad(String name) {
return new VersionedSmartYamlConfiguration(new File(getDataFolder(), name),
getResource(name), VersionedConfiguration.VersionUpdateType.BACKUP_AND_UPDATE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public enum LifeSkillType {

CRAFTING("Crafting", "crafting", ChatColor.YELLOW),
ENCHANTING("Enchanting", "enchant", ChatColor.of(new Color(128, 93, 255))),
ENCHANTING("Enchanting", "enchant", ChatColor.of(new Color(113, 79, 236))),
FISHING("Fishing", "fishing", ChatColor.AQUA),
MINING("Mining", "mining", ChatColor.DARK_GREEN),
FARMING("Gathering", "farming", ChatColor.of(new Color(255, 192, 87))),
Expand All @@ -15,6 +15,7 @@ public enum LifeSkillType {
SNEAK("Sneak", "sneak", ChatColor.GRAY),
AGILITY("Agility", "agility", ChatColor.DARK_AQUA),
TRADING("Trading", "trading", ChatColor.DARK_GREEN),
FLYING("Flying", "flying", ChatColor.of(new Color(114, 187, 255))),
SWORDSMANSHIP("Swordsmanship", "sword", ChatColor.RED, true),
DAGGER_MASTERY("Dagger Mastery", "dagger", ChatColor.of(new Color(204, 246, 102)), true),
AXE_MASTERY("Axe Mastery", "axe", ChatColor.RED, true),
Expand Down Expand Up @@ -61,7 +62,7 @@ public ChatColor getColor() {
return color;
}

public boolean isComnbat() {
public boolean isCombat() {
return combat;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public enum ConditionType {
ENTITY_TYPE,
UNIQUE_ID,
FACTION_MEMBER,
FLYING,
VELOCITY,
GROUNDED,
BLEEDING,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package land.face.strife.data.conditions;

import land.face.strife.data.StrifeMob;

public class FlyingCondition extends Condition {

public boolean isMet(StrifeMob attacker, StrifeMob target) {
if (getCompareTarget() == CompareTarget.SELF) {
target = attacker;
}
return target.getEntity().isGliding();
}
}
2 changes: 1 addition & 1 deletion src/main/java/land/face/strife/data/effects/Damage.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void apply(StrifeMob caster, StrifeMob target) {
mods.setApplyOnHitEffects(applyOnHitEffects);
mods.setShowPopoffs(showPopoffs);
mods.setBypassBarrier(bypassBarrier);
mods.setScaleChancesWithAttack(true);
mods.setScaleChancesWithAttack(false);
if (canSneakAttack && caster.getEntity() instanceof Player && getPlugin().getStealthManager()
.canSneakAttack((Player) caster.getEntity())) {
mods.setSneakAttack(true);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/land/face/strife/data/effects/Effect.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public enum EffectType {
RESTORE_ENERGY,
INCREASE_RAGE,
PROJECTILE,
RIPTIDE,
EQUIPMENT_SWAP,
EVOKER_FANGS,
FALLING_BLOCK,
Expand Down
49 changes: 34 additions & 15 deletions src/main/java/land/face/strife/data/effects/Push.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package land.face.strife.data.effects;

import com.tealcube.minecraft.bukkit.shade.apache.commons.lang3.StringUtils;
import land.face.strife.data.StrifeMob;
import land.face.strife.util.LogUtil;
import org.bukkit.craftbukkit.libs.org.apache.commons.lang3.StringUtils;
import lombok.Setter;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.util.Vector;
Expand All @@ -13,6 +14,8 @@ public class Push extends Effect {
private double height;
private boolean cancelFall;
private boolean clamp;
@Setter
private boolean uncheckedHeight;
private PushType pushType;
private Vector tempVector;

Expand All @@ -32,19 +35,22 @@ public void apply(StrifeMob caster, StrifeMob target) {
direction = getEffectVelocity(caster.getEntity().getLocation().toVector(), target.getEntity());
break;
case CASTER_DIRECTION:
Vector casterDir = caster.getEntity().getLocation().getDirection();
if (casterDir.getX() == 0 && casterDir.getZ() == 0) {
direction = new Vector(power / 10, 0, 0);
} else {
direction = casterDir.setY(0).normalize().multiply(power / 10);
direction = caster.getEntity().getLocation().getDirection();
if (!uncheckedHeight) {
direction.setY(0.001);
}
direction.normalize().multiply(power / 10);
break;
case TEMP_DIRECTION:
LogUtil.printDebug(tempVector.getX() + " " + tempVector.getY() + " " + tempVector.getZ());
direction = getEffectVelocity(tempVector, target.getEntity());
break;
case WSE_DIRECTION:
direction = tempVector.clone().setY(0.001).normalize().multiply(power / 10);
direction = tempVector.clone();
if (!uncheckedHeight) {
direction.setY(0.001);
}
direction.normalize().multiply(power / 10);
break;
default:
return;
Expand All @@ -57,13 +63,23 @@ public void apply(StrifeMob caster, StrifeMob target) {
}
target.getEntity().setFallDistance(0);
}
if (clamp) {
newVelocity.setX(clampRay(oldVelocity.getX(), direction.getX()));
newVelocity.setY(clampRay(oldVelocity.getY(), height / 10));
newVelocity.setZ(clampRay(oldVelocity.getZ(), direction.getZ()));
if (uncheckedHeight) {
if (clamp) {
newVelocity.setX(clampRay(oldVelocity.getX(), direction.getX()));
newVelocity.setY(clampRay(oldVelocity.getY(), direction.getY()));
newVelocity.setZ(clampRay(oldVelocity.getZ(), direction.getZ()));
} else {
newVelocity.add(direction);
}
} else {
newVelocity.add(direction);
newVelocity.add(new Vector(0, height / 10, 0));
if (clamp) {
newVelocity.setX(clampRay(oldVelocity.getX(), direction.getX()));
newVelocity.setY(clampRay(oldVelocity.getY(), height / 10));
newVelocity.setZ(clampRay(oldVelocity.getZ(), direction.getZ()));
} else {
newVelocity.add(direction);
newVelocity.add(new Vector(0, height / 10, 0));
}
}
target.getEntity().setVelocity(newVelocity);
}
Expand Down Expand Up @@ -91,8 +107,11 @@ private Vector getEffectVelocity(Vector originLocation, Entity to) {
if (originLocation.equals(to.getLocation().toVector())) {
return new Vector(0, power / 10, 0);
}
return to.getLocation().toVector().subtract(originLocation).setY(0.001).normalize()
.multiply(power / 10);
Vector velocity = to.getLocation().toVector().subtract(originLocation);
if (!uncheckedHeight) {
velocity.setY(0.001);
}
return velocity.normalize().multiply(power / 10);
}

public void setPower(double power) {
Expand Down
114 changes: 114 additions & 0 deletions src/main/java/land/face/strife/data/effects/Riptide.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package land.face.strife.data.effects;

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import java.util.Iterator;
import java.util.Map;
import java.util.WeakHashMap;
import land.face.strife.StrifePlugin;
import land.face.strife.data.StrifeMob;
import lombok.Setter;
import org.bukkit.Bukkit;
import org.bukkit.entity.LivingEntity;
import org.bukkit.scheduler.BukkitTask;

public class Riptide extends Effect {

public static Object RIPTIDE_POSE_ENUM = null;
public static Object STANDING_POSE_ENUM = null;
private static Map<LivingEntity, Integer> RIPTIDE_MAP = new WeakHashMap<>();
private static BukkitTask TASK = null;

@Setter
private int ticks;

@Override
public void apply(StrifeMob caster, StrifeMob target) {
if (RIPTIDE_POSE_ENUM == null || STANDING_POSE_ENUM == null) {
return;
}
RIPTIDE_MAP.put(target.getEntity(), ticks);
try {
PacketContainer fakeSpin = ProtocolLibrary.getProtocolManager()
.createPacket(PacketType.Play.Server.ENTITY_METADATA);

WrappedDataWatcher w = WrappedDataWatcher.getEntityWatcher(target.getEntity());
w.setObject(6, RIPTIDE_POSE_ENUM);
w.setObject(7, (byte) 4);

fakeSpin.getWatchableCollectionModifier().write(0, w.getWatchableObjects());

ProtocolLibrary.getProtocolManager().broadcastServerPacket(fakeSpin);
} catch (Exception e) {
sendCancelPacket(target.getEntity());
e.printStackTrace();
}
}

private static void tickRiptide() {
Iterator<LivingEntity> iterator = RIPTIDE_MAP.keySet().iterator();
while (iterator.hasNext()) {
LivingEntity le = iterator.next();
if (!le.isValid()) {
Bukkit.getLogger().info("CANCELED INVALID");
sendCancelPacket(le);
continue;
}
if (le.getVelocity().getY() < 0.1 && le.isOnGround()) {
Bukkit.getLogger().info("CANCELED GROUND");
continue;
}
if (RIPTIDE_MAP.get(le) < 1) {
Bukkit.getLogger().info("CANCELED TIMEOUT");
sendCancelPacket(le);
continue;
}
RIPTIDE_MAP.put(le, RIPTIDE_MAP.get(le) - 1);
}
}

public static boolean isRiptideAnimationPlaying(LivingEntity target) {
return RIPTIDE_MAP.containsKey(target);
}

public static void sendCancelPacket(LivingEntity target) {
RIPTIDE_MAP.remove(target);
try {
PacketContainer restoreStanding = ProtocolLibrary.getProtocolManager()
.createPacket(PacketType.Play.Server.ENTITY_METADATA);

WrappedDataWatcher w = WrappedDataWatcher.getEntityWatcher(target);
w.setObject(6, STANDING_POSE_ENUM);
w.setObject(7, (byte) 0);

restoreStanding.getWatchableCollectionModifier().write(0, w.getWatchableObjects());

ProtocolLibrary.getProtocolManager().broadcastServerPacket(restoreStanding);
} catch (Exception e) {
e.printStackTrace();
}
}

public static void startTask(StrifePlugin plugin) {
if (TASK != null) {
TASK.cancel();
}
if (TASK == null || TASK.isCancelled()) {
TASK = Bukkit.getScheduler().runTaskTimer(plugin, Riptide::tickRiptide, 200L, 2L);
}
}

public static void buildNMSEnum(StrifePlugin plugin) {
try {
RIPTIDE_POSE_ENUM = StrifePlugin.getNMSClass("EntityPose", plugin)
.getField("SPIN_ATTACK").get(null);
STANDING_POSE_ENUM = StrifePlugin.getNMSClass("EntityPose", plugin)
.getField("STANDING").get(null);
} catch (Exception e) {
e.printStackTrace();
}
}

}
Loading

0 comments on commit 6f41323

Please sign in to comment.