Skip to content

Commit

Permalink
Merge pull request #501 from VolmitSoftware/Development
Browse files Browse the repository at this point in the history
Commands, Skill, and some achievements
  • Loading branch information
NextdoorPsycho authored Aug 4, 2024
2 parents 1f9337e + 6970cab commit 3036503
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 63 deletions.
30 changes: 15 additions & 15 deletions src/main/java/com/volmit/adapt/api/world/AdaptServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,31 +136,31 @@ public void on(ProjectileLaunchEvent e) {
Skill<?> skill = getSkillRegistry().getSkill(data.getSkill());
data.apply(p);
SoundNotification.builder()
.sound(Sound.ENTITY_ALLAY_AMBIENT_WITHOUT_ITEM)
.volume(0.35f).pitch(1.455f)
.build().play(getPlayer(p));
.sound(Sound.ENTITY_ALLAY_AMBIENT_WITHOUT_ITEM)
.volume(0.35f).pitch(1.455f)
.build().play(getPlayer(p));
SoundNotification.builder()
.sound(Sound.ENTITY_SHULKER_OPEN)
.volume(1f).pitch(1.655f)
.build().play(getPlayer(p));
.sound(Sound.ENTITY_SHULKER_OPEN)
.volume(1f).pitch(1.655f)
.build().play(getPlayer(p));
getPlayer(p).getNot().queue(AdvancementNotification.builder()
.icon(Material.BOOK)
.title(C.GRAY + "+ " + C.WHITE + data.getKnowledge() + " " + skill.getDisplayName() + " Knowledge")
.build());
.icon(Material.BOOK)
.title(C.GRAY + "+ " + C.WHITE + data.getKnowledge() + " " + skill.getDisplayName() + " Knowledge")
.build());
e.setCancelled(false);
e.getEntity().setVelocity(e.getEntity().getVelocity().multiply(1000));
} else {
ExperienceOrb.Data datax = ExperienceOrb.get(s.getItem());
if (datax != null) {
datax.apply(p);
SoundNotification.builder()
.sound(Sound.ENTITY_ALLAY_AMBIENT_WITHOUT_ITEM)
.volume(0.35f).pitch(1.455f)
.build().play(getPlayer(p));
.sound(Sound.ENTITY_ALLAY_AMBIENT_WITHOUT_ITEM)
.volume(0.35f).pitch(1.455f)
.build().play(getPlayer(p));
SoundNotification.builder()
.sound(Sound.ENTITY_SHULKER_OPEN)
.volume(1f).pitch(1.655f)
.build().play(getPlayer(p));
.sound(Sound.ENTITY_SHULKER_OPEN)
.volume(1f).pitch(1.655f)
.build().play(getPlayer(p));
e.setCancelled(false);
e.getEntity().setVelocity(e.getEntity().getVelocity().multiply(1000));
}
Expand Down
79 changes: 43 additions & 36 deletions src/main/java/com/volmit/adapt/command/CommandAdapt.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,21 @@
import com.volmit.adapt.util.decree.specialhandlers.NullablePlayerHandler;
import org.bukkit.entity.Player;

import java.util.HashMap;
import java.util.Map;

@Decree(name = "adapt", description = "Basic Command")
public class CommandAdapt implements DecreeExecutor {
private CommandDebug debug;

@Decree(description = "Boost Target player, or Global Experience gain.")
public void boost(
@Param(aliases = "seconds", description = "Amount of seconds", defaultValue = "10")
int seconds,
@Param(aliases = "multiplier", description = "Strength of the boost ", defaultValue = "10")
int multiplier,
@Param(description = "player", defaultValue = "---", customHandler = NullablePlayerHandler.class)
Player player
@Param(aliases = "seconds", description = "Amount of seconds", defaultValue = "10")
int seconds,
@Param(aliases = "multiplier", description = "Strength of the boost ", defaultValue = "10")
int multiplier,
@Param(description = "player", defaultValue = "---", customHandler = NullablePlayerHandler.class)
Player player

) {
if (!sender().hasPermission("adapt.boost")) {
Expand All @@ -48,12 +51,12 @@ public void boost(

@Decree(description = "Open the Adapt GUI")
public void gui(
@Param(aliases = "target", defaultValue = "[Main]")
AdaptationListingHandler.AdaptationList guiTarget,
@Param(aliases = "player", defaultValue = "---", customHandler = NullablePlayerHandler.class)
Player player,
@Param(aliases = "force", defaultValue = "false")
boolean force
@Param(aliases = "target", defaultValue = "[Main]")
AdaptationListingHandler.AdaptationList guiTarget,
@Param(aliases = "player", defaultValue = "---", customHandler = NullablePlayerHandler.class)
Player player,
@Param(aliases = "force", defaultValue = "false")
boolean force
) {
if (!sender().hasPermission("adapt.gui")) {
sender().sendMessage("You lack the Permission 'adapt.gui'");
Expand Down Expand Up @@ -103,12 +106,12 @@ public void gui(

@Decree(description = "Give yourself an experience orb")
public void experience(
@Param(aliases = "skill")
AdaptationListingHandler.AdaptationSkillList skillName,
@Param(aliases = "amount", defaultValue = "10")
int amount,
@Param(aliases = "player", defaultValue = "---", customHandler = NullablePlayerHandler.class)
Player player
@Param(aliases = "skill")
AdaptationListingHandler.AdaptationSkillList skillName,
@Param(aliases = "amount", defaultValue = "10")
int amount,
@Param(aliases = "player", defaultValue = "---", customHandler = NullablePlayerHandler.class)
Player player

) {
if (!sender().hasPermission("adapt.cheatitem")) {
Expand All @@ -128,9 +131,11 @@ public void experience(
}

if (skillName.equals("[all]")) {
Map<String, Double> experienceMap = new HashMap<>();
for (Skill<?> skill : SkillRegistry.skills.sortV()) {
targetPlayer.getInventory().addItem(ExperienceOrb.with(skill.getName(), amount));
experienceMap.put(skill.getName(), (double) amount);
}
targetPlayer.getInventory().addItem(ExperienceOrb.with(experienceMap));
FConst.success("Giving all orbs").send(sender());
return;
}
Expand All @@ -150,12 +155,12 @@ public void experience(

@Decree(description = "Give yourself a knowledge orb")
public void knowledge(
@Param(aliases = "skill")
AdaptationListingHandler.AdaptationSkillList skillName,
@Param(aliases = "amount", defaultValue = "10")
int amount,
@Param(aliases = "player", defaultValue = "---", customHandler = NullablePlayerHandler.class)
Player player
@Param(aliases = "skill")
AdaptationListingHandler.AdaptationSkillList skillName,
@Param(aliases = "amount", defaultValue = "10")
int amount,
@Param(aliases = "player", defaultValue = "---", customHandler = NullablePlayerHandler.class)
Player player
) {
if (!sender().hasPermission("adapt.cheatitem")) {
sender().sendMessage("You lack the Permission 'adapt.cheatitem'");
Expand All @@ -173,9 +178,11 @@ public void knowledge(
}

if (skillName.equals("[all]")) {
Map<String, Integer> knowledgeMap = new HashMap<>();
for (Skill<?> skill : SkillRegistry.skills.sortV()) {
targetPlayer.getInventory().addItem(KnowledgeOrb.with(skill.getName(), amount));
knowledgeMap.put(skill.getName(), amount);
}
targetPlayer.getInventory().addItem(KnowledgeOrb.with(knowledgeMap));
FConst.success("Giving all orbs").send(sender());
return;
}
Expand All @@ -195,16 +202,16 @@ public void knowledge(

@Decree(description = "Assign a skill, or UnAssign a skill as if you are learning / unlearning a skill.")
public void determine(
@Param(aliases = "adaptationTarget")
AdaptationListingHandler.AdaptationProvider adaptationTarget,
@Param(aliases = "assign")
boolean assign,
@Param(aliases = "force")
boolean force,
@Param(aliases = "level")
int level,
@Param(aliases = "player", defaultValue = "---", customHandler = NullablePlayerHandler.class)
Player player
@Param(aliases = "adaptationTarget")
AdaptationListingHandler.AdaptationProvider adaptationTarget,
@Param(aliases = "assign")
boolean assign,
@Param(aliases = "force")
boolean force,
@Param(aliases = "level")
int level,
@Param(aliases = "player", defaultValue = "---", customHandler = NullablePlayerHandler.class)
Player player

) {
if (!sender().hasPermission("adapt.determine")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.volmit.adapt.content.adaptation.rift;

import com.volmit.adapt.api.adaptation.SimpleAdaptation;
import com.volmit.adapt.util.C;
import com.volmit.adapt.util.Element;
import com.volmit.adapt.util.Localizer;
import lombok.NoArgsConstructor;
import org.bukkit.Material;
import org.bukkit.entity.Enderman;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.inventory.ItemStack;

public class RiftVisage extends SimpleAdaptation<RiftVisage.Config> {
public RiftVisage() {
super("rift-visage");
registerConfiguration(Config.class);
setDescription(Localizer.dLocalize("rift", "visage", "description"));
setDisplayName(Localizer.dLocalize("rift", "visage", "name"));
setIcon(Material.POPPED_CHORUS_FRUIT);
setBaseCost(getConfig().baseCost);
setCostFactor(getConfig().costFactor);
setMaxLevel(getConfig().maxLevel);
setInitialCost(getConfig().initialCost);
setInterval(1000);
}

@Override
public void addStats(int level, Element v) {
v.addLore(C.ITALIC + Localizer.dLocalize("rift", "visage", "lore1"));
}

@EventHandler
public void onEntityTarget(EntityTargetEvent event) {
Entity entity = event.getEntity();
if (entity instanceof Enderman) {
if (event.getTarget() instanceof Player player) {
if (hasAdaptation(player) && hasEnderPearl(player)) {
event.setCancelled(true);
}
}
}
}

private boolean hasEnderPearl(Player player) {
for (ItemStack item : player.getInventory().getContents()) {
if (item != null && item.getType() == Material.ENDER_PEARL) {
return true;
}
}
return false;
}

@Override
public void onTick() {
}

@Override
public boolean isEnabled() {
return getConfig().enabled;
}

@Override
public boolean isPermanent() {
return getConfig().permanent;
}

@NoArgsConstructor
protected static class Config {
boolean permanent = true;
boolean enabled = true;
int baseCost = 8;
double costFactor = 0;
int maxLevel = 1;
int initialCost = 2;
}
}
37 changes: 31 additions & 6 deletions src/main/java/com/volmit/adapt/content/item/ExperienceOrb.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@AllArgsConstructor
@Data
Expand All @@ -52,6 +54,10 @@ public static ItemStack with(String skill, double xp) {
return io.withData(new Data(skill, xp));
}

public static ItemStack with(Map<String, Double> experienceMap) {
return io.withData(new Data(experienceMap));
}

@Override
public Material getMaterial() {
return Material.SNOWBALL;
Expand All @@ -64,26 +70,45 @@ public Class<Data> getType() {

@Override
public void applyLore(Data data, List<String> lore) {
Skill<?> skill = Adapt.instance.getAdaptServer().getSkillRegistry().getSkill(data.skill);
lore.add(C.WHITE + Localizer.dLocalize("snippets", "experienceorb", "contains") + " " + C.UNDERLINE + C.WHITE + Form.f(data.experience, 0) + " " + skill.getDisplayName() + C.GRAY + " " + Localizer.dLocalize("snippets", "experienceorb", "xp"));
for (Map.Entry<String, Double> entry : data.getExperienceMap().entrySet()) {
String skill = entry.getKey();
double experience = entry.getValue();
lore.add(C.WHITE + Form.capitalize(Localizer.dLocalize("snippets", "experienceorb", "contains")) + " " + C.UNDERLINE + C.WHITE + Form.f(experience, 0) + " " + Adapt.instance.getAdaptServer().getSkillRegistry().getSkill(skill).getDisplayName() + C.GRAY + " " + Localizer.dLocalize("snippets", "experienceorb", "xp"));
}
lore.add(C.LIGHT_PURPLE + Localizer.dLocalize("snippets", "experienceorb", "rightclick") + " " + C.GRAY + Localizer.dLocalize("snippets", "experienceorb", "togainxp"));
}

@Override
public void applyMeta(Data data, ItemMeta meta) {
meta.addEnchant(Enchantment.BINDING_CURSE, 10, true);
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_ENCHANTS);
meta.setDisplayName(Adapt.instance.getAdaptServer().getSkillRegistry().getSkill(data.skill).getDisplayName() + " " + Localizer.dLocalize("snippets", "experienceorb", "xporb"));
meta.setDisplayName(Localizer.dLocalize("snippets", "experienceorb", "xporb"));
}

@AllArgsConstructor
@lombok.Data
public static class Data {
private String skill;
private double experience;
private Map<String, Double> experienceMap;

public Data(String skill, double experience) {
this.experienceMap = new HashMap<>();
this.experienceMap.put(skill, experience);
}

public String getSkill() {
return experienceMap.keySet().iterator().next();
}

public double getExperience() {
return experienceMap.values().iterator().next();
}

public void apply(Player p) {
Adapt.instance.getAdaptServer().getPlayer(p).getSkillLine(skill).giveXPFresh(Adapt.instance.getAdaptServer().getPlayer(p).getNot(), experience);
for (Map.Entry<String, Double> entry : experienceMap.entrySet()) {
String skill = entry.getKey();
double experience = entry.getValue();
Adapt.instance.getAdaptServer().getPlayer(p).getSkillLine(skill).giveXPFresh(Adapt.instance.getAdaptServer().getPlayer(p).getNot(), experience);
}
}
}
}
Loading

0 comments on commit 3036503

Please sign in to comment.