Skip to content

Commit

Permalink
denizenscript impl 1
Browse files Browse the repository at this point in the history
  • Loading branch information
NeumimTo committed Feb 12, 2022
1 parent e6facd3 commit 15e293b
Show file tree
Hide file tree
Showing 10 changed files with 450 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
@SoftDependency("HolographicDisplays"),
@SoftDependency("MythicMobs"),
@SoftDependency("MMOItems"),
@SoftDependency("RPGRegions")
@SoftDependency("RPGRegions"),
@SoftDependency("Mimic")
}
)
@DependsOn(
Expand Down
11 changes: 10 additions & 1 deletion Implementations/Spigot/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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"
}
Expand All @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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<ISpigotCharacter> {

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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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("<entity> 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());
}


}
Original file line number Diff line number Diff line change
@@ -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<CharacterTag> 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()));
}
}
Loading

0 comments on commit 15e293b

Please sign in to comment.