More and more bug fixes.

This commit is contained in:
GB6 2019-04-24 11:40:40 +02:00
parent 0135cbea8f
commit b7ef224b71
21 changed files with 106 additions and 57 deletions

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>EpicEnchants-Parent</artifactId>
<groupId>com.songoda</groupId>
<version>1.0.5-ALPHA</version>
<version>1.0.8-ALPHA</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -28,8 +28,8 @@ public class EnchantCommand extends BaseCommand {
@Description("Give enchant books to players")
@CommandPermission("epicenchants.give.book")
public void onGiveBook(CommandSender sender, @Flags("other") Player target, Enchant enchant, @Optional Integer level, @Optional Integer successRate, @Optional Integer destroyRate) {
if (level != null && level > enchant.getMaxLevel()) {
instance.getAction().perform(sender, "command.book.max-level",
if (level != null && (level > enchant.getMaxLevel() || level < 1)) {
instance.getAction().perform(sender, "command.book." + (level > enchant.getMaxLevel() ? "max-level" : "min-level"),
of("enchant", enchant.getIdentifier()),
of("max-level", enchant.getMaxLevel()));
return;
@ -67,6 +67,7 @@ public class EnchantCommand extends BaseCommand {
target.getInventory().addItem(instance.getSpecialItems().getBlackScroll(amount, successRate));
break;
default:
instance.getAction().perform(target, "command.give-unknown", of("unknown", giveType));
return;
}
@ -81,8 +82,9 @@ public class EnchantCommand extends BaseCommand {
@Description("Apply enchant to item in hand")
@CommandPermission("epicenchants.apply")
public void onApply(Player player, Enchant enchant, int level, @Optional Integer successRate, @Optional Integer destroyRate) {
if (player.getItemInHand() == null) {
instance.getAction().perform(player, "command.apply.noitem", of("enchant", enchant.getIdentifier()));
if (player.getItemInHand() == null || !enchant.getItemWhitelist().contains(player.getItemInHand().getType())) {
System.out.println("List = " + enchant.getItemWhitelist());
instance.getAction().perform(player, "command.apply.invalid-item", of("enchant", enchant.getIdentifier()));
return;
}

View File

@ -3,10 +3,7 @@ package com.songoda.epicenchants.listeners;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.enums.TriggerType;
import de.tr7zw.itemnbtapi.NBTEntity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@ -127,7 +124,7 @@ public class EntityListener implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onEntityExplode(EntityExplodeEvent event) {
if (event.getEntity().getCustomName().equals("ee")) {
if (event.getEntity().getCustomName() != null && event.getEntity().getCustomName().equals("ee")) {
event.blockList().clear();
}
}

View File

@ -28,7 +28,7 @@ public class CommandManager extends BukkitCommandManager {
instance.getEnchantManager().getKeys().stream().map(s -> s.replaceAll("\\s", "_")).collect(Collectors.toList()));
getCommandCompletions().registerCompletion("giveType", c ->
Arrays.stream(GiveType.values()).map(s -> s.toString().replace("_", "").toLowerCase()).collect(Collectors.toList()));
Arrays.stream(GiveType.values()).map(s -> s.toString().replace("_", "-").toLowerCase()).collect(Collectors.toList()));
getCommandCompletions().registerCompletion("levels", c ->
IntStream.rangeClosed(1, c.getContextValue(Enchant.class).getMaxLevel()).boxed().map(Objects::toString).collect(Collectors.toList()));
@ -49,7 +49,7 @@ public class CommandManager extends BukkitCommandManager {
new InvalidCommandArgument("No enchant exists by that name", false)));
getCommandContexts().registerContext(GiveType.class, c -> Arrays.stream(GiveType.values())
.filter(s -> s.toString().toLowerCase().replace("_", "").equalsIgnoreCase(c.popFirstArg()))
.filter(s -> s.toString().toLowerCase().replace("_", "-").equalsIgnoreCase(c.popFirstArg()))
.findFirst()
.orElseThrow(() -> new InvalidCommandArgument("No item by that type.", false)));

View File

@ -283,6 +283,6 @@ public class AlchemistMenu extends FastInv {
for (Placeholder placeholder : placeholders)
toTest = toTest.replace(placeholder.getPlaceholder(), placeholder.getToReplace().toString());
return (int) GeneralUtils.parseJS(toTest, "alchemist expression", 0);
return (int) Double.parseDouble(GeneralUtils.parseJS(toTest, "alchemist expression", 0).toString());
}
}

View File

@ -8,11 +8,17 @@ import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import static com.songoda.epicenchants.objects.Placeholder.of;
import static com.songoda.epicenchants.utils.single.Experience.*;
import static com.songoda.epicenchants.utils.single.GeneralUtils.*;
public class EnchanterMenu extends FastInv {
private final Map<UUID, Long> DELAY = new HashMap<>();
public EnchanterMenu(EpicEnchants instance, FileConfiguration config, Player player) {
super(config.getInt("rows") * 9, color(config.getString("title")));
@ -38,6 +44,11 @@ public class EnchanterMenu extends FastInv {
of("eco_left", ecoLeft)).build();
addItem(getSlots(section.getString("slot")), itemStack, event -> {
// Todo: wanna change this
if (DELAY.getOrDefault(player.getUniqueId(), 0L) > System.currentTimeMillis()) {
return;
}
if (!instance.getEconomy().has((player), ecoCost) || getExp(player) < expCost) {
instance.getAction().perform(player, "enchanter.cannot-afford");
return;
@ -52,6 +63,7 @@ public class EnchanterMenu extends FastInv {
changeExp(player, -expCost);
player.getInventory().addItem(instance.getSpecialItems().getMysteryBook(group));
DELAY.put(event.getPlayer().getUniqueId(), System.currentTimeMillis() + 120);
});
});
}

View File

@ -6,7 +6,6 @@ import com.songoda.epicenchants.objects.Group;
import com.songoda.epicenchants.utils.objects.FastInv;
import com.songoda.epicenchants.utils.objects.ItemBuilder;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import java.util.Iterator;
@ -37,9 +36,10 @@ public class InfoMenu extends FastInv {
slots.stream().filter(slot -> enchantIterator.hasNext()).forEach(slot -> {
Enchant enchant = enchantIterator.next();
String whitelist = instance.getItemGroup().getGroup(enchant.getItemWhitelist())
.map(s -> StringUtils.capitalize(s.getName().toLowerCase()))
.orElse(String.join(", ", enchant.getItemWhitelist().stream().map(Material::toString).collect(Collectors.toSet())));
String whitelist = instance.getItemGroup().getGroups(enchant.getItemWhitelist())
.stream()
.map(s -> StringUtils.capitalize(s.toLowerCase()))
.collect(Collectors.joining(", "));
addItem(slot, new ItemBuilder(config.getConfigurationSection("enchant-item"),
of("group_color", enchant.getGroup().getColor()),

View File

@ -25,6 +25,7 @@ public class Enchant {
private Group group;
private int maxLevel;
private Set<String> conflict;
//TODO: ISSUES
private Set<Material> itemWhitelist;
private Set<EffectExecutor> effectExecutors;
private List<String> description;

View File

@ -39,7 +39,6 @@ public class EnchantUtils {
Set<String> currentIds = currentEnchantMap.keySet().stream().map(Enchant::getIdentifier).collect(Collectors.toSet());
Set<String> currentConflicts = currentEnchantMap.keySet().stream().map(Enchant::getConflict).flatMap(Collection::stream).collect(Collectors.toSet());
if (enchant.getConflict().stream().anyMatch(currentIds::contains) || currentConflicts.contains(enchant.getIdentifier())) {
return Pair.of(itemStack, CONFLICT);
}
@ -70,7 +69,7 @@ public class EnchantUtils {
itemBuilder.removeLore(instance.getSpecialItems().getWhiteScrollLore());
}
itemBuilder.removeLore(enchant.getFormat().replace("{level}", "").trim());
itemBuilder.removeLore(enchant.getFormat(-1, instance.getFileManager().getConfiguration("config").getBoolean("roman-numbers")).replace("-1", "").trim());
itemBuilder.addLore(enchant.getFormat(level, instance.getFileManager().getConfiguration("config").getBoolean("roman-numbers")));
if (hasProtection) {

View File

@ -23,4 +23,8 @@ public class FileLocation {
public String getResourcePath(String dir) {
return (versionDependent ? "version-dependent/" + dir + "/" : "") + path;
}
public boolean isDirectory() {
return path.endsWith("/");
}
}

View File

@ -151,7 +151,7 @@ public class ItemBuilder {
}
public ItemBuilder removeLore(String string) {
if (!meta.hasLore()) {
if (meta == null || !meta.hasLore()) {
return this;
}

View File

@ -63,10 +63,7 @@ public class ItemGroup {
Optional<Group> optionalGroup = Group.from(key);
Set<Material> output = new HashSet<>();
optionalGroup.ifPresent(group -> {
output.addAll(groupMap.get(group));
output.addAll(group.getChildren().stream().map(groupMap::get).flatMap(Collection::stream).collect(Collectors.toSet()));
});
optionalGroup.ifPresent(group -> output.addAll(getMaterials(group)));
if (Material.matchMaterial(key) != null) {
output.add(Material.matchMaterial(key));
@ -75,6 +72,20 @@ public class ItemGroup {
return output;
}
public Set<String> getGroups(Set<Material> materials) {
Set<String> groups = new HashSet<>();
for (int i = 0; i < 5; i++) {
getGroup(materials).ifPresent(group -> {
groups.add(group.getName());
materials.removeAll(getMaterials(group));
});
}
groups.addAll(materials.stream().map(Material::toString).collect(Collectors.toSet()));
return groups;
}
public Optional<Group> getGroup(Set<Material> materials) {
Optional<Group> group = Arrays.stream(Group.values())
.filter(s -> !s.getChildren().isEmpty() && s.getChildren().stream().allMatch(child -> materials.containsAll(groupMap.get(child))))
@ -84,7 +95,20 @@ public class ItemGroup {
return group;
}
return groupMap.asMap().entrySet().stream().filter(s -> s.getValue().equals(materials)).map(Map.Entry::getKey).findFirst();
return groupMap.asMap().entrySet().stream().filter(s -> materials.containsAll(s.getValue())).map(Map.Entry::getKey).findFirst();
}
public Set<Material> getMaterials(Group group) {
Set<Material> out = new HashSet<>();
for (int i = 0; i < 5; i++) {
if (group.getChildren().isEmpty())
out.addAll(groupMap.get(group));
else
out.addAll(group.getChildren().stream().map(this::getMaterials).flatMap(Collection::stream).collect(Collectors.toSet()));
}
return out;
}

View File

@ -3,7 +3,7 @@ package com.songoda.epicenchants.utils.single;
import java.util.TreeMap;
public class RomanNumber {
private final static TreeMap<Integer, String> map = new TreeMap<Integer, String>() {{
private final static TreeMap<Integer, String> TREE_MAP = new TreeMap<Integer, String>() {{
put(1000, "M");
put(900, "CM");
put(500, "D");
@ -17,15 +17,14 @@ public class RomanNumber {
put(5, "V");
put(4, "IV");
put(1, "I");
put(-1, "-1");
}};
public static String toRoman(int number) {
int l = map.floorKey(number);
int l = TREE_MAP.floorKey(number);
if (number == l) {
return map.get(number);
return TREE_MAP.get(number);
}
return map.get(l) + toRoman(number - l);
return TREE_MAP.get(l) + toRoman(number - l);
}
}

View File

@ -6,12 +6,17 @@ command:
received: "&7You have been given a &6{enchant} &7book."
gave: "&7You gave {player} a &6{enchant} &7book."
max-level: "&cThe max level for {enchant} is {max-level}."
min-level: "&cThe min level for {enchant} is 1."
white-scroll:
received: "&7You have been given a whitescroll."
gave: "&7You gave {player} a whitescroll."
apply:
invalid-item: "&cYou cannot apply {enchant} to this item."
reload: "&6Configuration files reload"
give-unknown: "&cUnknown item to give: &f{unknown}."
black-scroll:
success: "&aSuccessfully blackscrolled: {group_color}{enchant} {level}&a."
@ -46,8 +51,9 @@ alchemist:
enchants:
invalid-material: "&cYou can not apply &6{enchant} &cto that item."
failure: "&6{enchant} &cfailed to apply..."
broken-failure: "&6{enchant} &cfailed to apply and broke your item..."
success: "&aYou have success fully applied &6{enchant}."
success: "&aYou have successfully applied &6{enchant}."
conflict: "&cYou cannot apply this enchant as it conflicts with another enchant."
maxed-out: "&cYou already have that enchant maxed on this item."
already-applied: "&cYou already have that enchant applied on this item."

View File

@ -1,5 +1,3 @@
#MASTER CONFIG
first-load: true
language: "en_US"

View File

@ -7,7 +7,7 @@ max-level: 3
# The group of this enchant. Configure the groups in the groups.yml file.
group: SIMPLE
# The item that the enchantment book is.
# The item that the enchantment book is. This will override it's group setting.
book-item:
material: BOOK
display-name: "&b&lExampleEnchant {level}"
@ -17,14 +17,13 @@ book-item:
- "&a{success_rate}% Success Rate"
- "&c{destroy_rate}% Destroy Rate"
# How the enchant should be formatted on the enchanted item.
# How the enchant should be formatted on the enchanted item. This will override it's group setting.
applied-format: "&cExampleEnchant {level}"
# What items this enchant can be applied too.
# For a full list of item groups, please visit: https://wiki.songoda.com/display/SON/EpicEnchants
item-whitelist:
- "DIAMOND_HELMET"
- "IRON_HELMET"
- "LEATHER_HELMET"
- "HELMETS"
# This enchantment can not be applied if then enchantment below is already on the item.
conflicting-enchants:
@ -36,13 +35,13 @@ effects:
POTION-1:
# The trigger that will fire this effect
trigger: DEFENSE_PLAYER_MELEE
# What player should the effect be ran on: WEARER/OPPONENT.
who: WEARER
# What player should the effect be ran on: USER/OPPONENT.
who: USER
# Potion Effect that should be applied.
potion-type: SPEED
# Duration of the Potion Effect in seconds.
duration: "10 * {level}"
# Chance that the Effect gets activated.
# Chance that the effect gets activated.
chance: "20 * {level}"
# Amplifier of 0 = SPEED 1 a Amplifier of 1 = SPEED 2, etc.
amplifier: "{level} - 1"
@ -51,17 +50,15 @@ effects:
who: WEARER
potion-type: INCREASE_DAMAGE
amplifier: "{level} - 1"
# Chance of spawning when damaged by another player.
mobs:
# Type of Mob
ZOMBIE:
SPAWN_MOB:
# The mob type
mob-type: CREEPER
# Trigger event that spawns the mob.
trigger: DEFENSE_PLAYER_MELEE
# Max amount mobs that will be spawned.
max-amount: "{level}"
# Chance of trigger the mob spawning.
spawn-percentage: "20 * {level}"
amount: "{random(low=0, up={level})}"
# Chance that the effect gets activated.
chance: "20 * {level}"
# Drop chance of the mob its equipment upon death.
equipment-drop-chance: "10 * {level}"
# Health of the mob.

View File

@ -8,7 +8,7 @@ white-scroll:
- "&ePlace scroll on item to apply."
black-scroll:
material: INC_SAC
material: INC_SACK
display-name: "&f&lBlack Scroll"
lore:
- "&7Removes a random enchantment"

View File

@ -35,12 +35,17 @@ contents:
data: 14
display-name: "&8[&eThe Alchemist&8]"
lore:
- "&7You will exchange"
- "&7The alchemist will exchange:"
- ""
- "&8- &f2x enchantment books"
- "&7(of the same type and level) &ffor"
- "&fthe same enchantment book"
- "&7(with a higher success rate)"
- "&7(of a higher level)"
- ""
- "&8- &f2x magic dust"
- "&7(of the same rarity) &ffor"
- "&fthe same dust"
- "&7(of a higher percentage)"
accept-after:
material: STAINED_GLASS_PANE
data: 5

View File

@ -8,7 +8,7 @@ white-scroll:
- "&ePlace scroll on item to apply."
black-scroll:
material: INK_SACK
material: INK_SAC
display-name: "&f&lBlack Scroll"
lore:
- "&7Removes a random enchantment"

View File

@ -33,12 +33,17 @@ contents:
material: RED_STAINED_GLASS_PANE
display-name: "&8[&eThe Alchemist&8]"
lore:
- "&7You will exchange"
- "&7The alchemist will exchange:"
- ""
- "&8- &f2x enchantment books"
- "&7(of the same type and level) &ffor"
- "&fthe same enchantment book"
- "&7(with a higher success rate)"
- "&7(of a higher level)"
- ""
- "&8- &f2x magic dust"
- "&7(of the same rarity) &ffor"
- "&fthe same dust"
- "&7(of a higher percentage)"
accept-after:
material: LIME_STAINED_GLASS_PANE
display-name: "&eClick to confirm"

View File

@ -7,7 +7,7 @@
<groupId>com.songoda</groupId>
<artifactId>EpicEnchants-Parent</artifactId>
<packaging>pom</packaging>
<version>1.0.5-ALPHA</version>
<version>1.0.8-ALPHA</version>
<modules>
<module>core</module>
</modules>