Skip to content

Commit

Permalink
Merge pull request #25 from NeumimTo/1.0.7
Browse files Browse the repository at this point in the history
1.0.7
  • Loading branch information
NeumimTo authored Jul 15, 2017
2 parents b50d0ae + d5869a6 commit 81e0af2
Show file tree
Hide file tree
Showing 107 changed files with 2,645 additions and 309 deletions.
2 changes: 1 addition & 1 deletion NT-RPG-WEBGUI/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<dependency>
<groupId>cz.neumimto.rpg</groupId>
<artifactId>NT-RPG</artifactId>
<version>1.0.6</version>
<version>1.0.7</version>
<scope>provided</scope>
</dependency>

Expand Down
2 changes: 1 addition & 1 deletion Plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<artifactId>NT-RPG</artifactId>
<groupId>cz.neumimto.rpg</groupId>
<version>1.0.6</version>
<version>1.0.7</version>

<properties>
<timestamp>${maven.build.timestamp}</timestamp>
Expand Down
2 changes: 1 addition & 1 deletion Plugin/src/main/java/cz/neumimto/rpg/NtRpgPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
/**
* Created by NeumimTo on 29.4.2015.
*/
@Plugin(id = "nt-rpg", version = "1.0.6", name = "NT-Rpg", dependencies = {
@Plugin(id = "nt-rpg", version = "1.0.7", name = "NT-Rpg", dependencies = {
@Dependency(id = "nt-core", version = "1.7",optional = false)
})
public class NtRpgPlugin {
Expand Down
45 changes: 38 additions & 7 deletions Plugin/src/main/java/cz/neumimto/rpg/commands/CommandAdmin.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,9 @@
import javax.annotation.Nullable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;


@ResourceLoader.Command
Expand Down Expand Up @@ -98,7 +96,7 @@ public CommandResult process(CommandSource commandSource, String s) throws Comma
}


if (commandSource.hasPermission("ntrpg.superadmin")) {
if (!commandSource.hasPermission("ntrpg.superadmin")) {
return CommandResult.empty();
}

Expand Down Expand Up @@ -136,7 +134,7 @@ public CommandResult process(CommandSource commandSource, String s) throws Comma

} else if (a[0].equalsIgnoreCase("delete")) {

} else if (a[0].equalsIgnoreCase("enchantment")) {
} else if (a[0].equalsIgnoreCase("enchantment") || a[0].equalsIgnoreCase("e")) {
if (a[1].equalsIgnoreCase("add")) {
String name = a[2];
name = name.replaceAll("_", " ");
Expand All @@ -148,7 +146,11 @@ public CommandResult process(CommandSource commandSource, String s) throws Comma
if (player.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
ItemStack itemStack = player.getItemInHand(HandTypes.MAIN_HAND).get();
CustomItemData itemData = inventoryService.getItemData(itemStack);
itemData.enchantements().put(globalEffect.getName(), a[3]);
Map<String, String> map = new HashMap<>();
map.putAll(itemData.getEnchantements());
map.put(globalEffect.getName(), a.length == 2 ? "" : a[3].replaceAll("_", " "));
itemStack = inventoryService.setEnchantments(map, itemStack);
player.setItemInHand(HandTypes.MAIN_HAND, itemStack);
player.sendMessage(Text.of("Enchantment " + globalEffect.getName() + " added"));
} else {
player.sendMessage(Text.of(Localization.NO_ITEM_IN_HAND));
Expand Down Expand Up @@ -256,4 +258,33 @@ public CommandResult process(CommandSource commandSource, String s) throws Comma
}
return CommandResult.success();
}

@Override
public List<String> getSuggestions(CommandSource source, String arguments, @Nullable Location<World> targetPosition) throws CommandException {
String[] a = arguments.split(" ");
List<String> ar = new ArrayList<>();
if (a[0].equalsIgnoreCase("enchantment") || a[0].equalsIgnoreCase("e") ) {
if (a.length == 1) {
ar.add("add");
ar.add("remove");
return ar;
} else if (a[1].equalsIgnoreCase("add")) {
if (a.length == 2) {
ar.addAll(effectService.getGlobalEffects().keySet());
} else {
String q = a[2].replaceAll("_", " ");
int lim = 20;
for (String e : effectService.getGlobalEffects().keySet()) {
if (e.toLowerCase().startsWith(q.toLowerCase())) {
ar.add(e);
lim --;
if (lim == 0)
return ar;
}
}
}
}
}
return ar.stream().map(w -> w.replaceAll(" ", "_")).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class Localization {
public static String WEAPON_EQUIPED = "You have equiped weapon %1";

@ConfigValue
public static String WEAPON_CANT_BE_EQUIPED = "You can't use %1";
public static String WEAPON_CANT_BE_EQUIPED = "You are not trained to use %1";

@ConfigValue
public static String CHARACTER_CREATION = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,12 @@ public class PluginConfig {
public static double MAX_PARTY_SIZE = -68458;


//todo see ActiveCharacter mergeWeapons
/*
@ConfigValue
@Comment(content = {"If a player chooses a race and a class, where both those groups define damage value for one specific weapon, or projectile" +
" this option specifies how the weapon damage will be calculated.",
"1 = sum",
"2 = take higher value"})
public static int WEAPON_MERGE_STRTATEGY = 2;
*/


}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import cz.neumimto.rpg.IEntity;
import cz.neumimto.rpg.effects.IEffect;
import cz.neumimto.rpg.effects.IEffectConsumer;
import cz.neumimto.rpg.players.IActiveCharacter;
import cz.neumimto.rpg.skills.ISkill;
import org.spongepowered.api.entity.living.player.Player;
Expand Down
15 changes: 14 additions & 1 deletion Plugin/src/main/java/cz/neumimto/rpg/effects/EffectBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class EffectBase<Value> implements IEffect<Value> {
private boolean stackable = false;
private String name;
private int level;
private Set<PotionEffect> potions = new HashSet<>();
private Set<PotionEffect> potions;
private IEffectConsumer consumer;
private long duration = -1;
private long period = -1;
Expand All @@ -50,6 +50,7 @@ public class EffectBase<Value> implements IEffect<Value> {
private Value value;
private EffectStackingStrategy<Value> effectStackingStrategy;
private IEffectContainer<Value, IEffect<Value>> container;
private boolean tickingDisabled = false;

public EffectBase(String name, IEffectConsumer consumer) {
this();
Expand Down Expand Up @@ -123,6 +124,8 @@ public void setConsumer(IEffectConsumer consumer) {

@Override
public Set<PotionEffect> getPotions() {
if (potions == null)
potions = new HashSet<>();
return potions;
}

Expand Down Expand Up @@ -278,4 +281,14 @@ protected void addEffectType(EffectType e) {
effectTypes = new HashSet<>();
effectTypes.add(e);
}

@Override
public boolean isTickingDisabled() {
return tickingDisabled;
}

@Override
public void setTickingDisabled(boolean tickingDisabled) {
this.tickingDisabled = tickingDisabled;
}
}
39 changes: 39 additions & 0 deletions Plugin/src/main/java/cz/neumimto/rpg/effects/EffectContainer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package cz.neumimto.rpg.effects;

import cz.neumimto.rpg.effects.common.stacking.UnstackableEffectData;

import java.util.HashSet;
import java.util.Set;

Expand Down Expand Up @@ -59,4 +61,41 @@ public K getStackedValue() {
public void setStackedValue(K k) {
this.value = k;
}


public static class UnstackableSingleInstance extends EffectContainer<UnstackableEffectData<?>, IEffect<UnstackableEffectData<?>>> {

public UnstackableSingleInstance(IEffect iEffect) {
super(iEffect);
}

@Override
public void stackEffect(IEffect<UnstackableEffectData<?>> unstackableEffectDataIEffect, IEffectSourceProvider effectSourceProvider) {
super.stackEffect(unstackableEffectDataIEffect, effectSourceProvider);
}

@Override
public void removeStack(IEffect<UnstackableEffectData<?>> iEffect) {
super.removeStack(iEffect);
updateStackedValue();
}


@Override
public void updateStackedValue() {
UnstackableEffectData stackedValue = getStackedValue();
IEffect<UnstackableEffectData<?>> next = null;
for (IEffect<UnstackableEffectData<?>> effect : getEffects()) {
if (stackedValue.isInferiorTo(effect.getValue())) {
if (next != null) {
next.setTickingDisabled(true);
}
next = effect;
setStackedValue(effect.getValue());
} else {
effect.setTickingDisabled(true);
}
}
}
}
}
43 changes: 26 additions & 17 deletions Plugin/src/main/java/cz/neumimto/rpg/effects/EffectService.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
public class EffectService {


public static final long TICK_PERIOD = 250L;
public static final long TICK_PERIOD = 5L;

private static final long unlimited_duration = -1;

Expand Down Expand Up @@ -136,8 +136,14 @@ public void run() {
* @param effect
*/
public void tickEffect(IEffect effect, long time) {
effect.onTick();
effect.tickCountIncrement();
if (!effect.isTickingDisabled()) {
if (effect.getConsumer().isDetached()) {
removeEffect(effect.getName(), effect.getConsumer(), effect.getEffectSourceProvider());
return;
}
effect.onTick();
effect.tickCountIncrement();
}
effect.setLastTickTime(time);
}

Expand All @@ -152,16 +158,14 @@ public void tickEffect(IEffect effect, long time) {
public void addEffect(IEffect iEffect, IEffectConsumer consumer, IEffectSourceProvider effectSourceProvider) {
IEffectContainer eff = consumer.getEffect(iEffect.getName());
if (eff == null) {
IEffectContainer iEffectContainer = iEffect.constructEffectContainer();
iEffect.setEffectContainer(iEffectContainer);
consumer.addEffect(iEffectContainer);
iEffect.setEffectSourceProvider(effectSourceProvider);
eff = iEffect.constructEffectContainer();
consumer.addEffect(eff);
iEffect.onApply();
} else if (eff.isStackable()) {
iEffect.setEffectContainer(eff);
iEffect.setEffectSourceProvider(effectSourceProvider);
eff.stackEffect(iEffect, effectSourceProvider);
}
iEffect.setEffectContainer(eff);
iEffect.setEffectSourceProvider(effectSourceProvider);
if (iEffect.requiresRegister())
runEffect(iEffect);
}
Expand All @@ -180,19 +184,24 @@ public void removeEffect(IEffect iEffect, IEffectConsumer consumer) {
}
}

public void removeEffect(IEffectContainer<?, IEffect<?>> container, IEffectConsumer consumer) {
container.forEach(a->removeEffect(a, consumer));
}

protected void removeEffect(IEffectContainer container, IEffect iEffect, IEffectConsumer consumer) {
if (iEffect == container) {
iEffect.onRemove();
if (!iEffect.getConsumer().isDetached()) {
iEffect.onRemove();
}
consumer.removeEffect(iEffect);
} else if (container.getEffects().contains(iEffect)){
container.removeStack(iEffect);
if (container.getEffects().isEmpty()) {
iEffect.onRemove();
consumer.removeEffect(container);
}
}
iEffect.setConsumer(null);
pendingRemovals.add(iEffect);
}

/**
Expand All @@ -210,14 +219,9 @@ public void removeEffect(String iEffect, IEffectConsumer consumer, IEffectSource
while (iterator.hasNext()) {
e = iterator.next();
if (e.getEffectSourceProvider() == effectSource) {
iterator.remove();
if (effectSet.contains(e))
effectSet.remove(e);
removeEffect(effect, e, consumer);
}
}
if (effect.getEffects().isEmpty()) {
consumer.removeEffect(effect);
}
}
}

Expand Down Expand Up @@ -251,6 +255,10 @@ public IGlobalEffect getGlobalEffect(String name) {
return globalEffects.get(name.toLowerCase());
}

public Map<String, IGlobalEffect> getGlobalEffects() {
return globalEffects;
}

/**
* Applies global effect with unlimited duration
*
Expand Down Expand Up @@ -285,6 +293,7 @@ public void removeGlobalEffectsAsEnchantments(Map<IGlobalEffect, String> itemEff
});
}


public boolean isGlobalEffect(String s) {
return globalEffects.containsKey(s.toLowerCase());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public enum EffectSourceType implements IEffectSource {
CLASS(false),
CHARM(true),
INTERNAL(true),
COMMAND(true);
COMMAND(true),
EFFECT(false);

private boolean m;

Expand Down
6 changes: 5 additions & 1 deletion Plugin/src/main/java/cz/neumimto/rpg/effects/IEffect.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static GlobalScope getGlobalScope() {

default void reApplyPotions() {
for (PotionEffect e : getPotions()) {
getConsumer().addPotionEffect(e.getType(), e.getAmplifier(), e.getDuration());
getConsumer().addPotionEffect(e.getType(), e.getAmplifier(), e.getDuration());
}
}

Expand Down Expand Up @@ -113,4 +113,8 @@ default <T extends IEffect<K>> IEffectContainer<K, T> constructEffectContainer()
IEffectContainer<K, IEffect<K>> getEffectContainer();

void setEffectContainer(IEffectContainer<K, IEffect<K>> iEffectContainer);

boolean isTickingDisabled();

void setTickingDisabled(boolean tickingDisabled);
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,6 @@ default void addPotionEffect(PotionEffect e) {
}

void sendMessage(String message);

boolean isDetached();
}
Loading

0 comments on commit 81e0af2

Please sign in to comment.