Skip to content

Commit

Permalink
Bugfixes + import cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
NeumimTo committed Jul 4, 2021
1 parent 656a6a4 commit 420d5d2
Show file tree
Hide file tree
Showing 114 changed files with 343 additions and 344 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
)
@DependsOn(
value = {
@Dependency("EffectLib"),
@Dependency("ProtocolLib")
}
)
Expand Down
8 changes: 4 additions & 4 deletions Common/src/main/java/cz/neumimto/rpg/common/AbstractRpg.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,10 @@ public void init(Path workingDirPath, Object commandManager,

try {
for (RpgAddon addon : rpgAddons) {
bindings.putAll(addon.getBindings());
Map<String, Object> map = new HashMap<>();
map.put("WORKINGDIR", workingDirPath.toAbsolutePath().toString());
providers = addon.getProviders(map); //TODO something definitely wrong with this
bindings.putAll(addon.getBindings());
Map<String, Object> map = new HashMap<>();
map.put("WORKINGDIR", workingDirPath.toAbsolutePath().toString());
providers = addon.getProviders(map); //TODO something definitely wrong with this
}
injector = Guice.createInjector(fnInjProv.apply(bindings, providers));
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
import cz.neumimto.rpg.api.effects.IGlobalEffect;
import cz.neumimto.rpg.api.effects.model.EffectModelFactory;
import cz.neumimto.rpg.api.effects.model.EffectModelMapper;
import cz.neumimto.rpg.api.localization.Localization;
import cz.neumimto.rpg.api.localization.LocalizationService;
import cz.neumimto.rpg.api.logging.Log;
import cz.neumimto.rpg.api.scripting.IRpgScriptEngine;
import cz.neumimto.rpg.api.services.ILocalization;
import cz.neumimto.rpg.api.services.IPropertyContainer;
import cz.neumimto.rpg.api.skills.ISkill;
import cz.neumimto.rpg.api.skills.SkillService;
Expand All @@ -24,10 +22,10 @@
import javax.inject.Inject;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.ServiceLoader;
import java.util.stream.Stream;

import static cz.neumimto.rpg.api.logging.Log.info;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public abstract class AssetService {

Expand Down Expand Up @@ -41,6 +40,7 @@ public void copyDefaultClasses(Path path) {
copyToFileIfMissing("defaults/classes/races/Elf.conf", path.resolve("races/Rogue.conf"));
copyToFileIfMissing("defaults/classes/races/Human.conf", path.resolve("races/Human.conf"));
}

private Path tempDirectory;

public Path getTempWorkingDir() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void addExperiencesCommand(CommandIssuer executor, OnlineOtherPlayer targ

@Subcommand("skill")
@CommandCompletion("@skilltree @nothing @skillskctx")
public void adminExecuteSkillCommand(IActiveCharacter character, SkillTree tree, int level, ISkill skill) {
public void adminExecuteSkillCommand(IActiveCharacter character, SkillTree tree, int level, ISkill skill) {
long e = System.nanoTime();
commandExecuteSkill(character, tree, skill, level);
if (Rpg.get().getPluginConfig().DEBUG.isBalance()) {
Expand All @@ -130,7 +130,7 @@ public void adminExecuteSkillCommand(IActiveCharacter character, SkillTree tree,

@Subcommand("cast-skill-as")
@CommandCompletion("@skilltree @nothing @skillskctx")
public void adminExecuteSkillCommandAs(OnlineOtherPlayer executor, SkillTree tree, int level, ISkill skill) {
public void adminExecuteSkillCommandAs(OnlineOtherPlayer executor, SkillTree tree, int level, ISkill skill) {
commandExecuteSkill(executor.character, tree, skill, level);
}

Expand Down Expand Up @@ -424,7 +424,7 @@ public void commandAddUniqueSkillpoint(IActiveCharacter character, String classT
if (result.isOk()) {
characterService.putInSaveQueue(character.getCharacterBase());
} else {
Log.warn("Character " + character.getUUID() + " could not gain unique sp ClassType: " + classType + " " +result.getMessage());
Log.warn("Character " + character.getUUID() + " could not gain unique sp ClassType: " + classType + " " + result.getMessage());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public void openSKillTreeMenu(IActiveCharacter character, ClassDefinition classD
private static class CommandSyncCallback implements Runnable {
private final IActiveCharacter character;
private CharacterCommandFacade facade;

private CommandSyncCallback(IActiveCharacter character, CharacterCommandFacade facade) {
this.character = character;
this.facade = facade;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


package cz.neumimto.rpg.common.configuration;

import com.google.inject.Injector;
Expand Down Expand Up @@ -101,7 +99,7 @@ public void loadAsciiMaps(Config config, SkillTree skillTree) {
try {
ConfigList asciiMap = config.getList("AsciiMap");

int length = ((ConfigList)asciiMap.get(0)).size();
int length = ((ConfigList) asciiMap.get(0)).size();
int rows = asciiMap.size();
short[][] array = new short[rows][length];
int i = 0;
Expand All @@ -119,7 +117,8 @@ public void loadAsciiMaps(Config config, SkillTree skillTree) {
ISkillTreeInterfaceModel guiModelByCharacter = skillService.getGuiModelByCharacter(c1.charAt(0));
if (guiModelByCharacter != null) {
array[i][j] = guiModelByCharacter.getId();
} if (MathUtils.isNumeric(c1)) {
}
if (MathUtils.isNumeric(c1)) {
array[i][j] = Short.parseShort(c1);
}
j++;
Expand Down Expand Up @@ -393,7 +392,8 @@ private void loadSkill(SkillTree skillTree, Config c, SkillData info) {
}
Log.warn("Skill Upgrade for " + info.getSkillName() + " missing SkillId, skipping");
}
} catch (ConfigException missing) {}
} catch (ConfigException missing) {
}

try {
List<? extends ConfigObject> preprocessors = c.getObjectList("CastConditions");
Expand Down Expand Up @@ -485,7 +485,7 @@ private SkillData getSkillInfo(String id, SkillTree tree) {

private SkillData createSkillInfo(SkillTree tree, String lowercased) {

ISkill skill = Rpg.get().getSkillService().getSkillById(lowercased.replaceAll("\"",""));
ISkill skill = Rpg.get().getSkillService().getSkillById(lowercased.replaceAll("\"", ""));
if (skill == null) {
throw new InvalidSkillTreeException("Could not find a skill " + lowercased + " referenced in the skilltree " + tree.getId());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


package cz.neumimto.rpg.common.effects;

import cz.neumimto.rpg.api.Rpg;
Expand Down Expand Up @@ -167,7 +165,7 @@ public <T extends IEffect> boolean addEffect(T effect, IEffectSourceProvider eff
@Override
public <T extends IEffect> boolean addEffect(T effect, IEffectSourceProvider effectSourceProvider, IEntity entitySource) {
IEffectContainer eff = effect.getConsumer().getEffect(effect.getName());
if (Rpg.get().getPluginConfig().DEBUG.isDevelop()) {
if (Rpg.get().getPluginConfig().DEBUG.isDevelop()) {
IEffectConsumer consumer1 = effect.getConsumer();
if (consumer1 instanceof IActiveCharacter) {
IActiveCharacter chara = (IActiveCharacter) consumer1;
Expand Down Expand Up @@ -393,7 +391,8 @@ public void purgeEffectCache() {
for (IEffect iEffect : effectSet) {
try {
iEffect.onRemove(iEffect);
} catch (Throwable t){}
} catch (Throwable t) {
}
}
effectSet.clear();
pendingAdditions.clear();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


package cz.neumimto.rpg.common.effects.core;

import cz.neumimto.rpg.api.Rpg;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


package cz.neumimto.rpg.common.entity.parties;


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

package cz.neumimto.rpg.common.entity.players;

import cz.neumimto.rpg.api.IRpgElement;
Expand Down Expand Up @@ -667,7 +666,6 @@ public void upgradeSkill(T character, PlayerSkillContext playerSkillContext, ISk
}



/**
* @param character
* @param skill
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


package cz.neumimto.rpg.common.entity.players;

import cz.neumimto.rpg.api.Rpg;
Expand Down Expand Up @@ -308,7 +306,7 @@ public Map<String, Long> getCooldowns() {

@Override
public boolean hasCooldown(String thing) {
return cooldowns.getOrDefault(thing,0L) > System.currentTimeMillis();
return cooldowns.getOrDefault(thing, 0L) > System.currentTimeMillis();
}

private void mergeWeapons(ClassDefinition g) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public double getMaxValue() {

@Override
public void setMaxValue(double f) {
character.setProperty(CommonProperties.max_mana, f);
character.setProperty(CommonProperties.max_mana, f);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


package cz.neumimto.rpg.common.entity.players;

import cz.neumimto.rpg.api.Rpg;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


package cz.neumimto.rpg.common.persistance.dao;

import com.electronwill.nightconfig.core.Config;
Expand Down Expand Up @@ -44,7 +42,6 @@ public Path getClassDirectory() {
}



public Set<ClassDefinition> parseClassFiles(Path path) {
Set<ClassDefinition> set = new HashSet<>();
try {
Expand Down Expand Up @@ -86,7 +83,7 @@ private Map<String, Path> preloadClassDefs(Path path, Set<ClassDefinition> set)
Map<String, Path> map = new HashMap<>();

Files.walk(path)
.filter(f -> Files.isRegularFile(f) || (Files.isSymbolicLink(f) && ! Files.isDirectory(f)))
.filter(f -> Files.isRegularFile(f) || (Files.isSymbolicLink(f) && !Files.isDirectory(f)))
.forEach(p -> {
info("Preloading class definition file " + p.getFileName());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cz.neumimto.rpg.common.scripting;

public class DummyScriptEngine extends AbstractRpgScriptEngine{
public class DummyScriptEngine extends AbstractRpgScriptEngine {
@Override
public void prepareEngine() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@
import cz.neumimto.rpg.common.utils.Java12FieldUtils;
import org.graalvm.polyglot.*;
import org.graalvm.polyglot.impl.AbstractPolyglotImpl;
import sun.misc.Unsafe;

import javax.script.ScriptEngineManager;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.nio.file.Path;
import java.util.*;
import java.util.function.Function;
Expand Down Expand Up @@ -179,7 +176,9 @@ public SkillResult init(IActiveCharacter caster, PlayerSkillContext context) {

public interface ScriptLib {
Map<String, Value> getSkillHandlers();

List<Value> getGlobalEffects();

List<Value> getEventListeners();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@

public interface ISkillCastMechanic {

default SkillResult processBefore(IActiveCharacter character, PlayerSkillContext context){
default SkillResult processBefore(IActiveCharacter character, PlayerSkillContext context) {
return SkillResult.OK;
}

default void processAfterSuccess(IActiveCharacter character, PlayerSkillContext context){}
default void processAfterSuccess(IActiveCharacter character, PlayerSkillContext context) {
}

boolean isValidForContext(SkillData skillData);

default void notifyFailure(IActiveCharacter character, PlayerSkillContext context) {}
default void notifyFailure(IActiveCharacter character, PlayerSkillContext context) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap;
import org.codehaus.janino.SimpleCompiler;


import javax.inject.Inject;
import javax.inject.Singleton;
import java.lang.annotation.Annotation;
Expand Down Expand Up @@ -56,7 +55,7 @@ public Class<? extends ISkill> generate(ScriptSkillModel scriptSkillModel, Class
.addAnnotation(AnnotationSpec.builder(ResourceLoader.Skill.class).addMember("value", "$S", scriptSkillModel.getId()).build());

if (scriptSkillModel.getSuperType() == null) {
type.superclass(ParameterizedTypeName.get(ClassName.get(ActiveSkill.class), ClassName.get(characterClassImpl())))
type.superclass(ParameterizedTypeName.get(ClassName.get(ActiveSkill.class), ClassName.get(characterClassImpl())))
.addModifiers(PUBLIC);

type.addMethod(MethodSpec.methodBuilder("cast").addModifiers(PUBLIC)
Expand Down Expand Up @@ -98,7 +97,7 @@ public Class<? extends ISkill> generate(ScriptSkillModel scriptSkillModel, Class

Class<? extends ISkill> x = (Class<? extends ISkill>) sc.getClassLoader().loadClass(packagee + "." + className);
return x;
} catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
}
return null;
Expand All @@ -111,8 +110,8 @@ private CodeBlock parseSkillMeta(ScriptSkillModel scriptSkillModel) {
}
if (scriptSkillModel.getSkillTypes() != null) {
for (String skillType : scriptSkillModel.getSkillTypes()) {
Stream.of(SkillType.values()).filter(a->a.getId().equalsIgnoreCase(skillType)).findFirst()
.ifPresent(a-> builder.addStatement("addSkillType($T.$L)",SkillType.class, a.name().toUpperCase()));
Stream.of(SkillType.values()).filter(a -> a.getId().equalsIgnoreCase(skillType)).findFirst()
.ifPresent(a -> builder.addStatement("addSkillType($T.$L)", SkillType.class, a.name().toUpperCase()));

}
}
Expand All @@ -126,6 +125,7 @@ private static class MethodHandler {
final Method relevantMethod;
final Class returnType;
final String methodName;

private MethodHandler(Class mechanic, String fieldName, Method relevantMethod, Class returnType, String methodName) {
this.mechanic = mechanic;
this.fieldName = fieldName;
Expand All @@ -150,6 +150,7 @@ static MethodHandler of(Object mechanic) {
}

}

private CodeBlock parseModel(ScriptSkillModel scriptSkillModel) {
CodeBlock.Builder builder = CodeBlock.builder()
.addStatement("$T caster = ($T) caster0", characterClassImpl(), characterClassImpl()) //janino cant handle generics
Expand Down Expand Up @@ -313,7 +314,8 @@ private ParsedScript findLocalVarsAndFields(Config config) {

try {
parseLocalVarsAndFields(config, parsedScript);
} catch (Exception ignored) {}
} catch (Exception ignored) {
}

if (config.contains("Mechanics")) {
List<Config> list = config.get("Mechanics");
Expand Down Expand Up @@ -480,21 +482,22 @@ protected Object filterMechanicById(Config config) {
if (type == null) {
type = config.get("Target-Selector");
}
if (type!=null && type.startsWith("#")) {
if (type != null && type.startsWith("#")) {
return null;
}

return filterMechanicById(type);
}

protected static class MechanicParams {
public Map<String, Type> methodArgs = new LinkedHashMap<>();
public List<String> consumed = new ArrayList<>();
public Map<String, Type> methodArgs = new LinkedHashMap<>();
public List<String> consumed = new ArrayList<>();

public boolean available(String l) {
return !consumed.contains(l);
}
}

protected MechanicParams filterMechanicParams(Object mechanic, String str) {
Pattern compile = Pattern.compile("(([a-zA-Y]*)=([a-zA-Y]*)?((\\([^)]+\\))|'(.*?)')|([a-zA-Z=.]*))");
Matcher matcher = compile.matcher(str);
Expand Down
Loading

0 comments on commit 420d5d2

Please sign in to comment.