More bug fixes

This commit is contained in:
GB6 2019-02-08 13:08:13 +01:00
parent 12114a55f2
commit eff885270e
16 changed files with 50 additions and 67 deletions

View File

@ -77,7 +77,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
<version>1.18.2</version>
</dependency>
<dependency>

View File

@ -5,15 +5,9 @@ import co.aikar.commands.InvalidCommandArgument;
import com.songoda.epicenchants.commands.EnchantCommand;
import com.songoda.epicenchants.enums.GiveType;
import com.songoda.epicenchants.listeners.*;
import com.songoda.epicenchants.managers.EnchantManager;
import com.songoda.epicenchants.managers.FileManager;
import com.songoda.epicenchants.managers.GroupManager;
import com.songoda.epicenchants.managers.InfoManager;
import com.songoda.epicenchants.managers.*;
import com.songoda.epicenchants.objects.Enchant;
import com.songoda.epicenchants.utils.EnchantUtils;
import com.songoda.epicenchants.utils.FastInv;
import com.songoda.epicenchants.utils.SpecialItems;
import com.songoda.epicenchants.utils.VersionDependent;
import com.songoda.epicenchants.utils.*;
import lombok.Getter;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
@ -117,12 +111,7 @@ public class EpicEnchants extends JavaPlugin {
private void setupVersion() {
int currentVersion = Integer.parseInt(getServer().getClass().getPackage().getName().split("\\.")[3].split("_")[1]);
if (currentVersion >= 13) {
VersionDependent.initDefault(currentVersion);
} else {
VersionDependent.initLegacy(currentVersion);
}
VersionDependent.initLegacy(currentVersion);
}
public void reload() {

View File

@ -33,10 +33,16 @@ public class EnchantCommand extends BaseCommand {
//ee give book {player} {enchant} {group}
@Subcommand("give book")
@CommandCompletion("@giveType @players @enchants @nothing @nothing @nothing")
@CommandCompletion("@players @enchants @nothing @nothing @nothing")
@Description("Give enchant books to players")
@CommandPermission("epicenchants.give")
public void onGive(CommandSender sender, @Flags("other") Player target, Enchant enchant, @Optional Integer level, @Optional Integer successRate, @Optional Integer destroyRate) {
public void onGiveBook(CommandSender sender, @Flags("other") Player target, Enchant enchant, @Optional Integer level, @Optional Integer successRate, @Optional Integer destroyRate) {
if (level > enchant.getMaxLevel()) {
sender.sendMessage(instance.getLocale().getMessageWithPrefix("command.book.maxlevel",
of("enchant", enchant.getIdentifier()),
of("max-level", enchant.getMaxLevel())));
return;
}
target.getInventory().addItem(enchant.getBookItem().get(enchant, level, successRate, destroyRate));
target.sendMessage(instance.getLocale().getMessageWithPrefix("command.book.received", of("enchant", enchant.getIdentifier())));
sender.sendMessage(instance.getLocale().getMessageWithPrefix("command.book.gave", of("player", target.getName()), of("enchant", enchant.getIdentifier())));
@ -44,10 +50,10 @@ public class EnchantCommand extends BaseCommand {
//ee give item {player} {giveType} {group}
@Subcommand("give item")
@CommandCompletion("@giveType @players @enchants @nothing @nothing @nothing")
@CommandCompletion("@players @giveType @nothing @nothing")
@Description("Give enchant books to players")
@CommandPermission("epicenchants.give")
public void onGive(CommandSender sender, @Flags("other") Player target, String giveType, @Optional Integer amount, @Optional Integer successRate) {
public void onGiveItem(CommandSender sender, @Flags("other") Player target, String giveType, @Optional Integer amount, @Optional Integer successRate) {
String messageKey;
switch (giveType.toLowerCase()) {

View File

@ -7,8 +7,7 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Optional;
import static com.google.common.base.CaseFormat.UPPER_CAMEL;
import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
import static com.google.common.base.CaseFormat.*;
public class EffectManager {
@ -24,7 +23,7 @@ public class EffectManager {
Object object = constructor.newInstance(section);
return Optional.of((EffectExecutor) object);
} catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException | ClassCastException e) {
Bukkit.getLogger().severe("Invalid effect:" + section.getName());
Bukkit.getLogger().severe("Invalid effect: " + section.getName());
}
return Optional.empty();

View File

@ -15,10 +15,8 @@ public class CancelEvent extends EffectEventExecutor {
@Override
public void execute(Player player, LivingEntity opponent, int level, Event event, EventType eventType) {
if (!(event instanceof Cancellable)) {
return;
if (event instanceof Cancellable) {
((Cancellable) event).setCancelled(true);
}
((Cancellable) event).setCancelled(true);
}
}

View File

@ -20,6 +20,6 @@ public class Message extends EffectExecutor {
consume(entity -> entity.sendMessage(color(getSection().getString("message"))
.replace("{level}", "" + level)
.replace("{wearer}", wearer.getName())
.replace("{opponent}", opponent.getName())), wearer, opponent);
.replace("{opponent}", opponent == null ? "" : opponent.getName())), wearer, opponent);
}
}

View File

@ -1,7 +1,6 @@
package com.songoda.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectExecutor;
import com.songoda.epicenchants.enums.EffectType;
import com.songoda.epicenchants.enums.EventType;
import com.songoda.epicenchants.utils.Experience;
import org.bukkit.configuration.ConfigurationSection;
@ -11,8 +10,8 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class ModifyExp extends EffectExecutor {
public ModifyExp(ConfigurationSection section, EffectType... allowedEffects) {
super(section, allowedEffects);
public ModifyExp(ConfigurationSection section) {
super(section);
}
@Override

View File

@ -19,6 +19,8 @@ public class ModifyHealth extends EffectExecutor {
double amount = getAmount().get(level, 0);
if (entity.getHealth() + amount > entity.getMaxHealth()) {
entity.setHealth(entity.getMaxHealth());
} else if (entity.getHealth() + amount < 0) {
entity.setHealth(0);
} else {
entity.setHealth(entity.getHealth() + amount);
}

View File

@ -15,6 +15,7 @@ import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
import static com.songoda.epicenchants.enums.EnchantResult.*;
import static com.songoda.epicenchants.objects.Placeholder.of;
@ -32,9 +33,13 @@ public class BookListener implements Listener {
return;
}
NBTItem nbtItem = new NBTItem(event.getCursor());
@Nullable NBTItem nbtItem = new NBTItem(event.getCursor());
ItemStack toApplyTo = event.getCurrentItem();
if (nbtItem == null) {
return;
}
if (!nbtItem.getBoolean("book-item")) {
return;
}
@ -67,7 +72,7 @@ public class BookListener implements Listener {
event.getClickedInventory().clear(event.getSlot());
}
if (result.getRight() != CONFLICT && result.getRight() != MAXED_OUT) {
if (result.getRight() != CONFLICT && result.getRight() != MAXED_OUT && result.getRight() != ALREADY_APPLIED) {
if (event.getCursor().getAmount() > 1) {
ItemStack toSet = event.getCursor();
toSet.setAmount(toSet.getAmount() - 1);

View File

@ -3,17 +3,11 @@ package com.songoda.epicenchants.listeners;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.enums.EffectType;
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;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
import org.bukkit.event.entity.*;
import org.bukkit.projectiles.ProjectileSource;
import static com.songoda.epicenchants.enums.EffectType.*;
@ -66,7 +60,7 @@ public class EntityListener implements Listener {
if (event.getDamager() instanceof Player) {
opponent = ((LivingEntity) event.getDamager());
effectType = DEFENSE_PLAYER_MELEE;
} else if (event.getDamager() instanceof Monster) {
} else if (event.getDamager() instanceof LivingEntity && !(event.getDamager() instanceof Player)) {
opponent = ((LivingEntity) event.getDamager());
effectType = DEFENSE_MOB_MELEE;
}
@ -83,7 +77,7 @@ public class EntityListener implements Listener {
if (event.getEntity() instanceof Player) {
effectType = ATTACK_PLAYER_MELEE;
} else if (event.getEntity() instanceof Monster) {
} else if (event.getEntity() instanceof LivingEntity) {
effectType = ATTACK_MOB_MELEE;
}

View File

@ -14,7 +14,6 @@ import java.util.stream.Collectors;
import static com.songoda.epicenchants.objects.Placeholder.of;
import static com.songoda.epicenchants.utils.GeneralUtils.color;
import static com.songoda.epicenchants.utils.GeneralUtils.getSlot;
import static java.util.Arrays.stream;
public class InfoMenu extends FastInv {
@ -43,6 +42,6 @@ public class InfoMenu extends FastInv {
.stream()
.map(s -> "contents." + s)
.map(config::getConfigurationSection)
.forEach(section -> addItem(getSlot(section.getInt("row"), section.getInt("column")), new ItemBuilder(section).build()));
.forEach(section -> addItem(section.getInt("slot"), new ItemBuilder(section).build()));
}
}

View File

@ -3,7 +3,6 @@ package com.songoda.epicenchants.menus;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.objects.Group;
import com.songoda.epicenchants.utils.FastInv;
import com.songoda.epicenchants.utils.GeneralUtils;
import com.songoda.epicenchants.utils.ItemBuilder;
import org.bukkit.configuration.file.FileConfiguration;
@ -18,7 +17,7 @@ public class MainInfoMenu extends FastInv {
.map(s -> "contents." + s)
.map(config::getConfigurationSection)
.forEach(section -> {
addItem(GeneralUtils.getSlot(section.getInt("row"), section.getInt("column")), new ItemBuilder(section).build(), event -> {
addItem(section.getInt("slot"), new ItemBuilder(section).build(), event -> {
Group group = instance.getGroupManager().getGroup(section.getString("group"))
.orElseThrow(() -> new IllegalArgumentException("Invalid group: " + section.getString("group")));
instance.getInfoManager().getMenu(group).ifPresent(menu -> menu.open(event.getPlayer()));

View File

@ -67,7 +67,7 @@ public class VersionDependent {
};
}
public static void initDefault(int serverVersion) {
/*public static void initDefault(int serverVersion) {
version = serverVersion;
blacklist = new HashSet<Material>() {
{
@ -167,7 +167,7 @@ public class VersionDependent {
add(valueOf("YELLOW_SHULKER_BOX"));
}
};
}
}*/
public static Set<Material> getBlackList() {
return blacklist;

View File

@ -1,11 +1,10 @@
#General Messages
#General
general.nametag.prefix= "&8[&6EpicEnchants&8]"
#Command Messages
#Command
command.book.received= "&7You have been given a &6{enchant} &7book."
command.book.gave= "&7You gave {player} a &6{enchant} &7book."
command.book.maxlevel= "&cThe max level for {enchant} is {max-level}."
command.whitescroll;.received= "&7You have been given a whitescroll."
command.whitescroll.gave= "&7You gave {player} a whitescroll."
@ -17,14 +16,13 @@ command.reload= "&6Configuration files reload"
command.filereload.success= "&6{file-name} has been successfully reloaded."
command.filereload.failed= "&c{file-name} failed to be reloaded. &7Please check console for errors."
#Event Messages
#Event
event.general.nopermission= "&cYou do not have permission to do that."
event.purchase.noenchant= "&cThere is no enchant available for &6{group-name}&7."
event.purchase.cannotafford= "&cYou cannot afford this purchase."
event.purchase.success= "&7You successfully purchased a &6{group-name} &7Book."
#Enchant Messages
#Enchant
enchant.invalidmaterial= "&cYou can not apply &6{enchant} &cto that item."
enchant.failure= "&cYou failed to apply &6{enchant}."
enchant.brokenfailure= "&6{enchant} &cfailed to apply and broke your item..."
@ -33,7 +31,7 @@ enchant.conflict= "&cYou cannot apply this enchant as it conflicts with another
enchant.maxedout= "&cYou already have that enchant maxed on this item."
enchant.alreadyapplied= "&cYou already have that enchant with that level applied on this item."
#Item Messages
#Item
whitescroll.applied="&aThis item is now protected."
whitescroll.alreadyapplied= "&cThis item is already protected."
blackscroll.success= "&aYou have successfully extracted an enchant from this item."

View File

@ -9,7 +9,7 @@ group: SIMPLE
# The item that the enchantment book is.
book-item:
material: STONE
material: BOOK
display-name: "&b&lExampleEnchant {level}"
# The lore on the enchantments books.
lore:

View File

@ -6,29 +6,24 @@ contents:
material: "PAPER"
display-name: "&f&lSimple Enchantments"
group: SIMPLE
row: 1
column: 1
slot: 0
2:
material: "PAPER"
display-name: "&a&lUnique Enchantments"
group: UNIQUE
row: 1
column: 2
slot: 1
3:
material: "PAPER"
display-name: "&b&lElite Enchantments"
group: ELITE
row: 1
column: 3
slot: 2
4:
material: "PAPER"
display-name: "&e&lUltimate Enchantments"
group: ULTIMATE
row: 1
column: 4
slot: 3
5:
material: "PAPER"
display-name: "&6&lLegendary Enchantments"
group: LEGENDARY
row: 1
column: 5
slot: 4