Skip to content

Commit

Permalink
Command application of buffs
Browse files Browse the repository at this point in the history
  • Loading branch information
UltraFaceguy committed May 21, 2021
1 parent def0fa7 commit 586a0d7
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 41 deletions.
2 changes: 1 addition & 1 deletion 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.0</version>
<version>3.4.1</version>
<packaging>jar</packaging>

<name>strife</name>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/land/face/strife/StrifePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,8 @@ public void enable() {
.registerCompletion("spawners", c -> spawnerManager.getSpawnerMap().keySet());
commandManager.getCommandCompletions()
.registerCompletion("abilities", c -> abilityManager.getLoadedAbilities().keySet());
commandManager.getCommandCompletions()
.registerCompletion("buffs", c -> buffManager.getLoadedBuffIds());

levelingRate = new LevelingRate();
maxSkillLevel = settings.getInt("config.leveling.max-skill-level", 60);
Expand Down
104 changes: 71 additions & 33 deletions src/main/java/land/face/strife/commands/StrifeCommand.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
/**
* The MIT License Copyright (c) 2015 Teal Cube Games
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p>
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
* <p>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package land.face.strife.commands;

Expand All @@ -37,6 +39,7 @@
import land.face.strife.data.LoreAbility;
import land.face.strife.data.StrifeMob;
import land.face.strife.data.ability.Ability;
import land.face.strife.data.buff.LoadedBuff;
import land.face.strife.data.champion.Champion;
import land.face.strife.data.champion.ChampionSaveData;
import land.face.strife.data.champion.LifeSkillType;
Expand Down Expand Up @@ -92,9 +95,12 @@ public void uniqueSummonCommand(Player sender, String entityId) {
@Subcommand("defeat")
@CommandCompletion("@players @players @range:1-30")
@CommandPermission("strife.admin")
public void defeatCommand(CommandSender sender, OnlinePlayer winner, OnlinePlayer loser, @Default("10") double weight) {
ChampionSaveData winData = plugin.getChampionManager().getChampion(winner.getPlayer()).getSaveData();
ChampionSaveData loseData = plugin.getChampionManager().getChampion(loser.getPlayer()).getSaveData();
public void defeatCommand(CommandSender sender, OnlinePlayer winner, OnlinePlayer loser,
@Default("10") double weight) {
ChampionSaveData winData = plugin.getChampionManager().getChampion(winner.getPlayer())
.getSaveData();
ChampionSaveData loseData = plugin.getChampionManager().getChampion(loser.getPlayer())
.getSaveData();

EloResponse response = EloUtil
.getEloChange(winData.getPvpScore(), loseData.getPvpScore(), (float) weight);
Expand All @@ -106,9 +112,11 @@ public void defeatCommand(CommandSender sender, OnlinePlayer winner, OnlinePlaye
loseData.setPvpScore(response.getNewLoserValue());

sendActionBar(winner.getPlayer(), PVP_WIN_MSG.replace("{0}",
String.valueOf(Math.round(response.getNewWinnerValue()))).replace("{1}", String.valueOf(Math.round(winDiff))));
String.valueOf(Math.round(response.getNewWinnerValue())))
.replace("{1}", String.valueOf(Math.round(winDiff))));
sendActionBar(loser.getPlayer(), PVP_LOSE_MSG.replace("{0}",
String.valueOf(Math.round(response.getNewLoserValue()))).replace("{1}", String.valueOf(Math.round(loseDiff))));
String.valueOf(Math.round(response.getNewLoserValue())))
.replace("{1}", String.valueOf(Math.round(loseDiff))));
}

@Subcommand("cd|cooldown")
Expand Down Expand Up @@ -144,7 +152,8 @@ public void reloadCommand(CommandSender sender) {
MessageUtils.sendMessage(p,
"&a&o&lATTENTION GAMER: &a&oOkay we're back now thanks for waiting :)");
}
sendMessage(sender, plugin.getSettings().getString("language.command.reload", "&aStrife reloaded!"));
sendMessage(sender,
plugin.getSettings().getString("language.command.reload", "&aStrife reloaded!"));
}

@Subcommand("profile")
Expand All @@ -157,15 +166,17 @@ public void profileCommand(CommandSender sender, OnlinePlayer target) {
new String[][]{{"%amount%", "" + champion.getUnusedStatPoints()}});
sendMessage(sender, "&6----------------------------------");
for (StrifeAttribute stat : plugin.getAttributeManager().getAttributes()) {
sendMessage(sender, ChatColor.GRAY + stat.getKey() + " - " + champion.getAttributeLevel(stat));
sendMessage(sender,
ChatColor.GRAY + stat.getKey() + " - " + champion.getAttributeLevel(stat));
}
sendMessage(sender, "&6----------------------------------");
}

@Subcommand("mobinfo|info")
@CommandPermission("strife.info")
public void infoCommand(Player sender) {
List<LivingEntity> targets = new ArrayList<>(TargetingUtil.getEntitiesInLine(sender.getEyeLocation(), 30, 2));
List<LivingEntity> targets = new ArrayList<>(
TargetingUtil.getEntitiesInLine(sender.getEyeLocation(), 30, 2));
targets.remove(sender);
if (targets.isEmpty()) {
sendMessage(sender, "&eNo target found...");
Expand All @@ -190,9 +201,11 @@ public void resetCommand(CommandSender sender, OnlinePlayer target) {
champion.setUnusedStatPoints(target.getPlayer().getLevel());
champion.getSaveData().getPathMap().clear();
plugin.getPathManager().buildPathBonus(champion);
sendMessage(sender, "You reset %player%", new String[][]{{"%player%", target.getPlayer().getDisplayName()}});
sendMessage(sender, "You reset %player%",
new String[][]{{"%player%", target.getPlayer().getDisplayName()}});
sendMessage(target.getPlayer(), "&aYour stats have been reset!");
sendMessage(target.getPlayer(), "&6You have unspent levelpoints! Use &f/levelup &6to spend them!");
sendMessage(target.getPlayer(),
"&6You have unspent levelpoints! Use &f/levelup &6to spend them!");
plugin.getChampionManager().update(target.getPlayer());
plugin.getStatUpdateManager().updateVanillaAttributes(champion.getPlayer());
}
Expand All @@ -209,7 +222,8 @@ public void clearCommand(CommandSender sender, OnlinePlayer target) {
}
champion.setUnusedStatPoints(0);
champion.setHighestReachedLevel(0);
sendMessage(sender, "You cleared <white>%player%", new String[][]{{"%player%", target.getPlayer().getDisplayName()}});
sendMessage(sender, "You cleared <white>%player%",
new String[][]{{"%player%", target.getPlayer().getDisplayName()}});
sendMessage(target.getPlayer(), "&aYour stats have been wiped :O");
plugin.getChampionManager().update(target.getPlayer());
plugin.getStatUpdateManager().updateVanillaAttributes(champion.getPlayer());
Expand All @@ -229,7 +243,8 @@ public void raiseCommand(CommandSender sender, OnlinePlayer target, @Default("1"
Champion champion = plugin.getChampionManager().getChampion(target.getPlayer());
plugin.getChampionManager().update(target.getPlayer());
sendMessage(sender, "&aYou raised &f%player% &ato level &f%level%.",
new String[][]{{"%player%", target.getPlayer().getDisplayName()}, {"%level%", "" + newLevel}});
new String[][]{{"%player%", target.getPlayer().getDisplayName()},
{"%level%", "" + newLevel}});
sendMessage(target.getPlayer(), "&aAn administrator has raised your level");
plugin.getStatUpdateManager().updateVanillaAttributes(champion.getPlayer());
}
Expand Down Expand Up @@ -269,7 +284,8 @@ public void removeAbilityCommand(CommandSender sender, OnlinePlayer target, int
sendMessage(sender, "<red>Invalid slot: " + slot);
return;
}
plugin.getChampionManager().getChampion(target.getPlayer()).getSaveData().setAbility(abilitySlot, null);
plugin.getChampionManager().getChampion(target.getPlayer()).getSaveData()
.setAbility(abilitySlot, null);
plugin.getAbilityIconManager().setAllAbilityIcons(target.getPlayer());
}

Expand Down Expand Up @@ -308,9 +324,11 @@ public void bindCommand(CommandSender sender, OnlinePlayer target, String loreAb
Champion champion = plugin.getChampionManager().getChampion(target.getPlayer());
boolean success = plugin.getChampionManager().addBoundLoreAbility(champion, ability);
if (success) {
sendMessage(sender, "&aBound loreAbility " + loreAbilityId + " to player " + target.getPlayer().getName());
sendMessage(sender,
"&aBound loreAbility " + loreAbilityId + " to player " + target.getPlayer().getName());
} else {
sendMessage(sender, "&cLoreAbility " + loreAbilityId + " already exists on " + target.getPlayer().getName());
sendMessage(sender,
"&cLoreAbility " + loreAbilityId + " already exists on " + target.getPlayer().getName());
}
}

Expand All @@ -326,9 +344,11 @@ public void unbindCommand(CommandSender sender, OnlinePlayer target, String lore
Champion champion = plugin.getChampionManager().getChampion(target.getPlayer());
boolean success = plugin.getChampionManager().removeBoundLoreAbility(champion, ability);
if (success) {
sendMessage(sender, "&aUnbound loreAbility " + loreAbilityId + " to player " + target.getPlayer().getName());
sendMessage(sender,
"&aUnbound loreAbility " + loreAbilityId + " to player " + target.getPlayer().getName());
} else {
sendMessage(sender, "&cLoreAbility " + loreAbilityId + " doesn't exist on " + target.getPlayer().getName());
sendMessage(sender,
"&cLoreAbility " + loreAbilityId + " doesn't exist on " + target.getPlayer().getName());
}
}

Expand All @@ -350,13 +370,15 @@ public void skillCommand(CommandSender sender, OnlinePlayer target, String skill
ChatColor color = type.getColor();
String name = type.getName();

plugin.getChampionManager().getChampion(target.getPlayer()).getSaveData().setSkillLevel(type, newLevel);
plugin.getChampionManager().getChampion(target.getPlayer()).getSaveData()
.setSkillLevel(type, newLevel);
sendMessage(target.getPlayer(), SET_LEVEL_MSG
.replace("{c}", "" + color)
.replace("{n}", name)
.replace("{a}", Integer.toString(newLevel))
);
sendMessage(sender, "Set " + name + " level of " + target.getPlayer().getName()+ " to " + newLevel);
sendMessage(sender,
"Set " + name + " level of " + target.getPlayer().getName() + " to " + newLevel);
}

@Subcommand("addskillxp|skillxp")
Expand All @@ -372,7 +394,8 @@ public void addSkillXp(CommandSender sender, OnlinePlayer target, String skill,
sendMessage(sender, "&cUnknown skill " + skill + "???");
return;
}
plugin.getSkillExperienceManager().addExperience(target.getPlayer(), type, amount, exact, !silent);
plugin.getSkillExperienceManager()
.addExperience(target.getPlayer(), type, amount, exact, !silent);
}

@Subcommand("addxp")
Expand All @@ -381,19 +404,34 @@ public void addSkillXp(CommandSender sender, OnlinePlayer target, String skill,
public void addXpCommand(CommandSender sender, OnlinePlayer player, double amount) {
plugin.getExperienceManager().addExperience(player.getPlayer(), amount, true);
sendMessage(player.player, "&aYou gained &f" + (int) amount + " &aXP!");
sendMessage(sender, "&a&oAwarded " + amount + " xp to " + player.getPlayer().getName() + " via command");
sendMessage(sender,
"&a&oAwarded " + amount + " xp to " + player.getPlayer().getName() + " via command");
}

@Subcommand("boost")
@CommandCompletion("@boosts @players @range:1-1000000")
@CommandCompletion("@boosts @players @range:1-10")
@CommandPermission("strife.admin")
public void startBoostCommand(CommandSender sender, String boostId, String creator, int duration) {
public void startBoostCommand(CommandSender sender, String boostId, String creator,
int duration) {
boolean success = plugin.getBoostManager().startBoost(creator, boostId, duration);
if (!success) {
sendMessage(sender, "&cBoost with that ID doesn't exist, or this boost is running");
}
}

@Subcommand("applybuff")
@CommandCompletion("@players @buffs @range:1-10")
@CommandPermission("strife.admin")
public void applyBuff(CommandSender sender, OnlinePlayer player, String buffId, int seconds) {
LoadedBuff buff = plugin.getBuffManager().getBuffFromId(buffId);
if (buff == null) {
sendMessage(sender, "&cBuff with that ID doesn't exist: " + buffId);
return;
}
plugin.getStrifeMobManager().getStatMob(player.getPlayer())
.addBuff(LoadedBuff.toRunningBuff(buff), seconds);
}

@Subcommand("reveal")
@CommandCompletion("@players")
@CommandPermission("strife.admin")
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/land/face/strife/data/buff/LoadedBuff.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ public double getSeconds() {
return seconds;
}

public static Buff toRunningBuff(LoadedBuff buff) {
return new Buff(buff.id, buff.stats, buff.maxStacks);
}

}
2 changes: 0 additions & 2 deletions src/main/java/land/face/strife/listeners/CombatListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,6 @@ public void strifeDamageHandler(EntityDamageByEntityEvent event) {
return;
}

Bukkit.getScheduler().runTaskLater(plugin, () -> defendEntity.setNoDamageTicks(0), 0L);

boolean isSneakAttack = attackEntity instanceof Player && plugin.getStealthManager()
.canSneakAttack((Player) attackEntity);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public UniqueSplashListener(StrifePlugin plugin) {
@EventHandler(priority = EventPriority.HIGHEST)
public void onAbilityPotionSplash(PotionSplashEvent event) {
List<Effect> hitEffects = ProjectileUtil.getHitEffects(event.getEntity());
if (hitEffects.isEmpty()) {
if (hitEffects == null || hitEffects.isEmpty()) {
return;
}
if (!(event.getEntity().getShooter() instanceof LivingEntity)) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/land/face/strife/managers/BuffManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import land.face.strife.data.buff.Buff;
import land.face.strife.data.buff.LoadedBuff;
import land.face.strife.stats.StrifeStat;
Expand All @@ -42,6 +43,10 @@ public Buff buildFromLoadedBuff(LoadedBuff loadedBuff) {
return new Buff(loadedBuff.getId(), loadedBuff.getStats(), loadedBuff.getMaxStacks());
}

public Set<String> getLoadedBuffIds() {
return buffList.keySet();
}

public void loadBuff(String key, ConfigurationSection cs) {
ConfigurationSection statsSection = cs.getConfigurationSection("stats");
Map<StrifeStat, Float> statsMap = StatUtil.getStatMapFromSection(statsSection);
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/land/face/strife/managers/DamageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,12 @@ public double dealDamage(StrifeMob attacker, StrifeMob defender, float damage, D
defender.getEntity().setHealth(defender.getEntity().getHealth() - damage);
return damage;
}
int noDamageTicks = defender.getEntity().getNoDamageTicks();
Vector velocity = defender.getEntity().getVelocity();
defender.getEntity().setNoDamageTicks(0);

handledDamages.put(attacker.getEntity().getUniqueId(), (double) damage);
defender.getEntity().damage(damage, attacker.getEntity());
handledDamages.remove(attacker.getEntity().getUniqueId());

defender.getEntity().setNoDamageTicks(noDamageTicks);
defender.getEntity().setVelocity(velocity);

return damage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ public void updateVanillaAttributes(Player player) {
}

public void updateVanillaAttributes(StrifeMob strifeMob) {
strifeMob.getEntity().setMaximumNoDamageTicks(0);
updateMovementSpeed(strifeMob);
updateAttackAttrs(strifeMob);
updateHealth(strifeMob);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public StrifeMob getStatMob(LivingEntity entity) {
StatUtil.updateMaxEnergy(strifeMob) * ((Player) entity).getFoodLevel() / 20 : 200000);
trackedEntities.put(entity, strifeMob);
}
entity.setMaximumNoDamageTicks(0);
return trackedEntities.get(entity);
}

Expand Down

0 comments on commit 586a0d7

Please sign in to comment.