From 15e293bf58e31325a93ee7c296aa9754994ae958 Mon Sep 17 00:00:00 2001 From: NeumimTo Date: Sun, 13 Feb 2022 00:17:52 +0100 Subject: [PATCH] denizenscript impl 1 --- .../cz/neumimto/rpg/SpigotRpgBootstrap.java | 3 +- Implementations/Spigot/build.gradle | 11 ++- .../neumimto/rpg/spigot/SpigotRpgPlugin.java | 7 ++ .../spigot/bridges/denizen/DenizenHook.java | 23 +++++ .../denizen/DenizenScriptSkillWrapper.java | 51 ++++++++++ .../denizen/EntityCastSkillDenizenEvent.java | 77 +++++++++++++++ .../bridges/denizen/tags/CharacterTag.java | 89 +++++++++++++++++ .../bridges/denizen/tags/SkillContextTag.java | 91 +++++++++++++++++ .../rpg/spigot/bridges/mimic/MimicHook.java | 99 +++++++++++++++++++ gradle.properties | 1 + 10 files changed, 450 insertions(+), 2 deletions(-) create mode 100644 Implementations/Spigot/src/main/java/cz/neumimto/rpg/spigot/bridges/denizen/DenizenHook.java create mode 100644 Implementations/Spigot/src/main/java/cz/neumimto/rpg/spigot/bridges/denizen/DenizenScriptSkillWrapper.java create mode 100644 Implementations/Spigot/src/main/java/cz/neumimto/rpg/spigot/bridges/denizen/EntityCastSkillDenizenEvent.java create mode 100644 Implementations/Spigot/src/main/java/cz/neumimto/rpg/spigot/bridges/denizen/tags/CharacterTag.java create mode 100644 Implementations/Spigot/src/main/java/cz/neumimto/rpg/spigot/bridges/denizen/tags/SkillContextTag.java create mode 100644 Implementations/Spigot/src/main/java/cz/neumimto/rpg/spigot/bridges/mimic/MimicHook.java diff --git a/Bootstrap/Spigot/src/main/java/cz/neumimto/rpg/SpigotRpgBootstrap.java b/Bootstrap/Spigot/src/main/java/cz/neumimto/rpg/SpigotRpgBootstrap.java index bf89886c3..46a038a8c 100644 --- a/Bootstrap/Spigot/src/main/java/cz/neumimto/rpg/SpigotRpgBootstrap.java +++ b/Bootstrap/Spigot/src/main/java/cz/neumimto/rpg/SpigotRpgBootstrap.java @@ -25,7 +25,8 @@ @SoftDependency("HolographicDisplays"), @SoftDependency("MythicMobs"), @SoftDependency("MMOItems"), - @SoftDependency("RPGRegions") + @SoftDependency("RPGRegions"), + @SoftDependency("Mimic") } ) @DependsOn( diff --git a/Implementations/Spigot/build.gradle b/Implementations/Spigot/build.gradle index beb0cde71..a0abb7555 100644 --- a/Implementations/Spigot/build.gradle +++ b/Implementations/Spigot/build.gradle @@ -33,7 +33,12 @@ repositories { includeGroupByRegex "(net\\.Indyuce|io\\.lumine)" } } - + maven { + url "https://ci.citizensnpcs.co/job/Denizen/" + } + maven { + url = "https://repo.citizensnpcs.co" + } } group = 'cz.neumimto.rpg' @@ -56,6 +61,7 @@ dependencies { compileOnly 'io.papermc.paper:paper-api:' + project.spigotapi + compileOnly"com.denizenscript:denizen:1.2.3-SNAPSHOT" compileOnly("org.spigotmc:plugin-annotations:" + project.pluginannotations) { exclude group: "org.bukkit", module: "bukkit" } @@ -65,10 +71,13 @@ dependencies { } api 'com.elmakers.mine.bukkit:EffectLib:' + project.effectlib + + // compileOnly 'placeholderapi.me.clip:placeholderapi:' + project.papi compileOnly 'com.gmail.filoghost.holographicdisplays:holographicdisplays-api:' + project.hdisplays compileOnly "co.aikar:acf-paper:" + project.acf compileOnly "io.papermc.paper:paper-api:1.17.1-R0.1-SNAPSHOT" + compileOnly "ru.endlesscode.mimic:mimic-bukkit-api:" + project.mimic // compileOnly('net.Indyuce:MMOItems:' + project.mmoitems) { // exclude group: 'com.mojang', module: 'authlib' diff --git a/Implementations/Spigot/src/main/java/cz/neumimto/rpg/spigot/SpigotRpgPlugin.java b/Implementations/Spigot/src/main/java/cz/neumimto/rpg/spigot/SpigotRpgPlugin.java index aa721c0a6..0b4f9bfcc 100644 --- a/Implementations/Spigot/src/main/java/cz/neumimto/rpg/spigot/SpigotRpgPlugin.java +++ b/Implementations/Spigot/src/main/java/cz/neumimto/rpg/spigot/SpigotRpgPlugin.java @@ -17,6 +17,7 @@ import cz.neumimto.rpg.persistence.flatfiles.FlatFilesModule; import cz.neumimto.rpg.spigot.bridges.HolographicDisplaysExpansion; import cz.neumimto.rpg.spigot.bridges.NtRpgPlaceholderExpansion; +import cz.neumimto.rpg.spigot.bridges.mimic.MimicHook; import cz.neumimto.rpg.spigot.bridges.mmoitems.MMOItemsExpansion; import cz.neumimto.rpg.spigot.bridges.mythicalmobs.MythicalMobsExpansion; import cz.neumimto.rpg.spigot.bridges.rpgregions.RpgRegionsClassExpReward; @@ -161,6 +162,12 @@ public void enable(Data data) { Rpg.get().registerListeners(injector.getInstance(OnKeyPress.class)); PacketHandler.init(); new SpigotSkillTreeViewModel(); //just to call static block + + if (Bukkit.getPluginManager().isPluginEnabled("Mimic")) { + MimicHook mimicHook = injector.getInstance(MimicHook.class); + mimicHook.init(plugin); + } + }); if (!testEnv) { diff --git a/Implementations/Spigot/src/main/java/cz/neumimto/rpg/spigot/bridges/denizen/DenizenHook.java b/Implementations/Spigot/src/main/java/cz/neumimto/rpg/spigot/bridges/denizen/DenizenHook.java new file mode 100644 index 000000000..f7f4740de --- /dev/null +++ b/Implementations/Spigot/src/main/java/cz/neumimto/rpg/spigot/bridges/denizen/DenizenHook.java @@ -0,0 +1,23 @@ +package cz.neumimto.rpg.spigot.bridges.denizen; + +import com.denizenscript.denizen.events.entity.EntityKilledScriptEvent; +import com.denizenscript.denizencore.events.ScriptEvent; +import com.denizenscript.denizencore.objects.ObjectFetcher; +import cz.neumimto.rpg.common.skills.SkillConfigLoader; +import cz.neumimto.rpg.common.skills.SkillConfigLoaders; +import cz.neumimto.rpg.spigot.bridges.denizen.tags.CharacterTag; +import cz.neumimto.rpg.spigot.bridges.denizen.tags.SkillContextTag; +import org.bukkit.plugin.Plugin; + +public class DenizenHook { + + public static SkillConfigLoader DENIZEN_SCRIPT = new SkillConfigLoader("denizen", DenizenScriptSkillWrapper.class); + + public void init(Plugin plugin) { + SkillConfigLoaders.register(DENIZEN_SCRIPT); + ObjectFetcher.registerWithObjectFetcher(CharacterTag.class, CharacterTag.tagProcessor); // char@ + ObjectFetcher.registerWithObjectFetcher(SkillContextTag.class, SkillContextTag.tagProcessor); // skillcontext@ + ScriptEvent.registerScriptEvent(EntityKilledScriptEvent.class); + } + +} diff --git a/Implementations/Spigot/src/main/java/cz/neumimto/rpg/spigot/bridges/denizen/DenizenScriptSkillWrapper.java b/Implementations/Spigot/src/main/java/cz/neumimto/rpg/spigot/bridges/denizen/DenizenScriptSkillWrapper.java new file mode 100644 index 000000000..2239b2d75 --- /dev/null +++ b/Implementations/Spigot/src/main/java/cz/neumimto/rpg/spigot/bridges/denizen/DenizenScriptSkillWrapper.java @@ -0,0 +1,51 @@ +package cz.neumimto.rpg.spigot.bridges.denizen; + +import cz.neumimto.rpg.common.ResourceLoader; +import cz.neumimto.rpg.common.skills.PlayerSkillContext; +import cz.neumimto.rpg.common.skills.SkillData; +import cz.neumimto.rpg.common.skills.SkillResult; +import cz.neumimto.rpg.common.skills.types.ActiveSkill; +import cz.neumimto.rpg.spigot.entities.players.ISpigotCharacter; + +public class DenizenScriptSkillWrapper extends ActiveSkill { + + private String catalogId; + + public DenizenScriptSkillWrapper() { + ResourceLoader.Skill sk = this.getClass().getAnnotation(ResourceLoader.Skill.class); + if (sk != null) { + catalogId = sk.value().toLowerCase(); + } + } + + @Override + public SkillResult cast(ISpigotCharacter character, PlayerSkillContext info) { + EntityCastSkillDenizenEvent event = new EntityCastSkillDenizenEvent(); + event.character = character; + event.context = info; + event.fire(); + return SkillResult.OK; + } + + @Override + public DenizenSkillData constructSkillData() { + return new DenizenSkillData(getId()); + } + + public static class DenizenSkillData extends SkillData { + + private String scriptPath; + + public DenizenSkillData(String skill) { + super(skill); + } + + public String getScriptPath() { + return scriptPath; + } + + public void setScriptPath(String scriptPath) { + this.scriptPath = scriptPath; + } + } +} diff --git a/Implementations/Spigot/src/main/java/cz/neumimto/rpg/spigot/bridges/denizen/EntityCastSkillDenizenEvent.java b/Implementations/Spigot/src/main/java/cz/neumimto/rpg/spigot/bridges/denizen/EntityCastSkillDenizenEvent.java new file mode 100644 index 000000000..98b341046 --- /dev/null +++ b/Implementations/Spigot/src/main/java/cz/neumimto/rpg/spigot/bridges/denizen/EntityCastSkillDenizenEvent.java @@ -0,0 +1,77 @@ +package cz.neumimto.rpg.spigot.bridges.denizen; + +import com.denizenscript.denizen.events.BukkitScriptEvent; +import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData; +import com.denizenscript.denizencore.objects.ObjectTag; +import com.denizenscript.denizencore.scripts.ScriptEntryData; +import cz.neumimto.rpg.common.skills.PlayerSkillContext; +import cz.neumimto.rpg.spigot.bridges.denizen.tags.CharacterTag; +import cz.neumimto.rpg.spigot.bridges.denizen.tags.SkillContextTag; +import cz.neumimto.rpg.spigot.entities.players.ISpigotCharacter; + +public class EntityCastSkillDenizenEvent extends BukkitScriptEvent { + + public ISpigotCharacter character; + public PlayerSkillContext context; + + public static EntityCastSkillDenizenEvent instance; + + public EntityCastSkillDenizenEvent() { + this.registerCouldMatcher(" casts skill <'skill'>"); + instance = this; + } + + + @Override + public boolean matches(ScriptPath path) { + String cmd = path.eventArgLowerAt(1); + String arg0 = path.eventArgLowerAt(0); + String arg2 = path.eventArgLowerAt(2); + String arg3 = path.eventArgLowerAt(3); + String attacker = cmd.equals("kills") ? arg0 : arg2.equals("by") ? arg3 : ""; + String target = cmd.equals("kills") ? arg2 : arg0; + + // if (!attacker.isEmpty()) { + // if (damager != null) { + // if (!cause.asString().equals(attacker) && + // !tryEntity(projectile, attacker) && !tryEntity(damager, attacker)) { + // return false; + // } + // } + // else if (!cause.asString().equals(attacker)) { + // return false; + // } + // } + + // if (!tryEntity(entity, target)) { + // return false; + // } + + // if (!runInCheck(path, entity.getLocation())) { + // return false; + // } + + return super.matches(path); + } + + @Override + public String getName() { + return "EntityCastsSkill"; + } + + public ObjectTag getContext(String name) { + switch (name) { + case "caster": + return new CharacterTag(character); + case "skill_context": + return new SkillContextTag(context, character); + } + return super.getContext(name); + } + + public ScriptEntryData getScriptEntryData() { + return new BukkitScriptEntryData(character.getPlayer()); + } + + +} diff --git a/Implementations/Spigot/src/main/java/cz/neumimto/rpg/spigot/bridges/denizen/tags/CharacterTag.java b/Implementations/Spigot/src/main/java/cz/neumimto/rpg/spigot/bridges/denizen/tags/CharacterTag.java new file mode 100644 index 000000000..ec6a58075 --- /dev/null +++ b/Implementations/Spigot/src/main/java/cz/neumimto/rpg/spigot/bridges/denizen/tags/CharacterTag.java @@ -0,0 +1,89 @@ +package cz.neumimto.rpg.spigot.bridges.denizen.tags; + +import com.denizenscript.denizen.objects.EntityFormObject; +import com.denizenscript.denizen.objects.EntityTag; +import com.denizenscript.denizen.objects.PlayerTag; +import com.denizenscript.denizencore.objects.Fetchable; +import com.denizenscript.denizencore.objects.ObjectTag; +import com.denizenscript.denizencore.tags.ObjectTagProcessor; +import com.denizenscript.denizencore.tags.TagContext; +import cz.neumimto.rpg.common.Rpg; +import cz.neumimto.rpg.common.entity.players.IActiveCharacter; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + +import java.util.UUID; + +public class CharacterTag implements EntityFormObject { + + private IActiveCharacter character; + private String prefix; + + public static ObjectTagProcessor tagProcessor = new ObjectTagProcessor<>(); + + public CharacterTag(IActiveCharacter character) { + this.character = character; + } + + public IActiveCharacter getCharacter() { + return character; + } + + public Player player() { + return (Player) character.getEntity(); + } + + @Override + public EntityTag getDenizenEntity() { + return new EntityTag((Entity) character.getEntity()); + } + + @Override + public String getPrefix() { + return prefix; + } + + @Override + public boolean isUnique() { + return true; + } + + @Override + public String getObjectType() { + return "Character"; + } + + @Override + public String identify() { + return "char@" + character.getUUID(); + } + + @Fetchable("char") + public static CharacterTag valueOf(String string, TagContext context) { + if (string == null) { + return null; + } else { + if (string.startsWith("char@")) { + string = string.substring("char@".length()); + UUID uuid = UUID.fromString(string); + return new CharacterTag(Rpg.get().getCharacterService().getCharacter(uuid)); + } + } + return null; + } + + @Override + public String identifySimple() { + return this.identify(); + } + + @Override + public ObjectTag setPrefix(String s) { + this.prefix = s; + return this; + } + + public static void registerTags() { + tagProcessor.registerTag(PlayerTag.class, "player", (attribute, object) -> new PlayerTag(object.player())); + } +} diff --git a/Implementations/Spigot/src/main/java/cz/neumimto/rpg/spigot/bridges/denizen/tags/SkillContextTag.java b/Implementations/Spigot/src/main/java/cz/neumimto/rpg/spigot/bridges/denizen/tags/SkillContextTag.java new file mode 100644 index 000000000..2229ce2f6 --- /dev/null +++ b/Implementations/Spigot/src/main/java/cz/neumimto/rpg/spigot/bridges/denizen/tags/SkillContextTag.java @@ -0,0 +1,91 @@ +package cz.neumimto.rpg.spigot.bridges.denizen.tags; + +import com.denizenscript.denizencore.objects.Fetchable; +import com.denizenscript.denizencore.objects.ObjectTag; +import com.denizenscript.denizencore.objects.core.ElementTag; +import com.denizenscript.denizencore.tags.ObjectTagProcessor; +import com.denizenscript.denizencore.tags.TagContext; +import cz.neumimto.rpg.common.Rpg; +import cz.neumimto.rpg.common.entity.players.IActiveCharacter; +import cz.neumimto.rpg.common.skills.PlayerSkillContext; + +import java.util.UUID; + +public class SkillContextTag implements ObjectTag { + + private PlayerSkillContext context; + private IActiveCharacter character; + private String prefix; + + public static ObjectTagProcessor tagProcessor = new ObjectTagProcessor<>(); + + + public SkillContextTag(PlayerSkillContext context, IActiveCharacter character) { + this.context = context; + this.character = character; + } + + public double getValue(String value) { + return context.getDoubleNodeValue(value); + } + + public int getSkillLevel() { + return context.getTotalLevel(); + } + + @Override + public String getPrefix() { + return prefix; + } + + @Override + public boolean isUnique() { + return true; + } + + @Override + public String getObjectType() { + return "SkillContext"; + } + + @Override + public String identify() { + return "skillContext@"+context.getSkill().getId() + ","+character.getUUID(); + } + + @Fetchable("skillContext") + public static SkillContextTag valueOf(String string, TagContext context) { + if (string == null) { + return null; + } else { + if (string.startsWith("skillContext@")) { + string = string.substring("skillContext@".length()); + String[] split = string.split(","); + UUID uuid = UUID.fromString(split[1]); + String skillId = split[0]; + IActiveCharacter character = Rpg.get().getCharacterService().getCharacter(uuid); + PlayerSkillContext psc = character.getSkill(skillId); + return new SkillContextTag(psc, character); + } + } + return null; + } + + @Override + public String identifySimple() { + return identify(); + } + + @Override + public ObjectTag setPrefix(String s) { + prefix = s; + return this; + } + + public static void registerTags() { + tagProcessor.registerTag(ElementTag.class, "value", (attribute, object) -> { + attribute.fulfill(1); + return new ElementTag(object.context.getDoubleNodeValue(attribute.getRawParam())); + }); + } +} diff --git a/Implementations/Spigot/src/main/java/cz/neumimto/rpg/spigot/bridges/mimic/MimicHook.java b/Implementations/Spigot/src/main/java/cz/neumimto/rpg/spigot/bridges/mimic/MimicHook.java new file mode 100644 index 000000000..130137b50 --- /dev/null +++ b/Implementations/Spigot/src/main/java/cz/neumimto/rpg/spigot/bridges/mimic/MimicHook.java @@ -0,0 +1,99 @@ +package cz.neumimto.rpg.spigot.bridges.mimic; + + +import cz.neumimto.rpg.common.classes.ClassService; +import cz.neumimto.rpg.common.entity.players.IActiveCharacter; +import cz.neumimto.rpg.spigot.entities.players.SpigotCharacterService; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.ServicePriority; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import ru.endlesscode.mimic.Mimic; +import ru.endlesscode.mimic.classes.BukkitClassSystem; +import ru.endlesscode.mimic.level.BukkitLevelSystem; +import ru.endlesscode.mimic.level.ExpLevelConverter; + +import javax.inject.Inject; +import java.util.ArrayList; +import java.util.List; + +public class MimicHook { + + @Inject + private ClassService classService; + + @Inject + private SpigotCharacterService characterService; + + public void init(Plugin plugin) { + Mimic.getInstance().registerClassSystem(NTClassSystem::new, 1, plugin, ServicePriority.Highest); + Mimic.getInstance().registerLevelSystem(NtLevelSystem::new, 1, plugin, ServicePriority.Highest); + } + + private class NTClassSystem extends BukkitClassSystem { + + public NTClassSystem(@NotNull Player player) { + super(player); + } + + private IActiveCharacter getCharacter() { + return characterService.getCharacter(getPlayer()); + } + + @NotNull + @Override + public List getClasses() { + return new ArrayList<>(getCharacter().getClasses().keySet()); + } + + @Nullable + @Override + public String getPrimaryClass() { + return getCharacter().getPrimaryClass().getClassDefinition().getName(); + } + + } + + private class NtLevelSystem extends BukkitLevelSystem { + + public NtLevelSystem(@NotNull Player player) { + super(player); + } + + private IActiveCharacter getCharacter() { + return characterService.getCharacter(getPlayer()); + } + + @NotNull + @Override + public ExpLevelConverter getConverter() { + return null; + } + + @Override + public int getLevel() { + IActiveCharacter character = getCharacter(); + if (character.getPrimaryClass() != null) { + return character.getPrimaryClass().getCharacterClass().getLevel(); + } + return 0; + } + + @Override + public double getExp() { + return getCharacter().getPrimaryClass().getCharacterClass().getExperiences(); + } + + @Override + public void setExp(double v) { + + } + + @Override + public void setLevel(int i) { + + } + } + +} diff --git a/gradle.properties b/gradle.properties index 73b041dbd..8404b6ae1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,6 +21,7 @@ mmoitems=6.5.5 mythiclib=1.0.17 mythicmobs=4.12.0 rpgregions=9e46ca8d +mimic=0.7 # Test gson=2.8.5 fastutil=8.2.1