small cleanup

This commit is contained in:
Indyuce 2021-08-20 11:32:34 +02:00
parent fb75868e8d
commit 7353cba619
9 changed files with 88 additions and 69 deletions

21
pom.xml
View File

@ -184,27 +184,6 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.Zrips.CMI</groupId>
<artifactId>CMI</artifactId>
<version>8.6.5.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sainttx.holograms</groupId>
<artifactId>Holograms</artifactId>
<version>2.9.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.gmail.filoghost.holographicdisplays</groupId>
<artifactId>holographicdisplays-api</artifactId>
<version>2.4.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.citizensnpcs</groupId>
<artifactId>Citizens</artifactId>

View File

@ -1,5 +1,6 @@
package net.Indyuce.mmocore.api.experience;
import java.util.Objects;
import java.util.UUID;
public class Booster {
@ -12,6 +13,8 @@ public class Booster {
/**
* Length is not final because boosters can stacks. This allows to reduce
* the amount of boosters displayed in the main player menu
*
* See {@link net.Indyuce.mmocore.manager.social.BoosterManager#register(Booster)}
*/
private long length;
@ -26,18 +29,19 @@ public class Booster {
}
/**
* @param author
* The booster creator
* @param extra
* 1 for +100% experience, 3 for 300% etc.
* @param length
* Booster length in milliseconds
* Main class experience booster
*
* @param author The booster creator
* @param extra 1 for +100% experience, 3 for 300% etc.
* @param length Booster length in milliseconds
*/
public Booster(String author, double extra, long length) {
this(author, null, extra, length);
}
/**
* Profession experience booster
*
* @param author
* The booster creator
* @param profession
@ -99,6 +103,19 @@ public class Booster {
}
public boolean canStackWith(Booster booster) {
return extra == booster.extra && (profession != null ? profession.equals(booster.getProfession()) : booster.getProfession() == null);
return extra == booster.extra && Objects.equals(profession, booster.profession);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Booster booster = (Booster) o;
return Objects.equals(uuid, booster.uuid);
}
@Override
public int hashCode() {
return Objects.hash(uuid);
}
}

View File

@ -4,13 +4,12 @@ import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.utils.holograms.Hologram;
import io.lumine.mythic.utils.serialize.Position;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.ConfigMessage;
import net.Indyuce.mmocore.api.event.PlayerExperienceGainEvent;
import net.Indyuce.mmocore.api.event.PlayerLevelUpEvent;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.api.util.math.particle.SmallParticleEffect;
import net.Indyuce.mmocore.manager.SoundManager;
import org.bukkit.Bukkit;
@ -20,7 +19,6 @@ import org.bukkit.Particle;
import org.bukkit.configuration.ConfigurationSection;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
@ -139,10 +137,8 @@ public class PlayerProfessions {
value = MMOCore.plugin.boosterManager.calculateExp(profession, value);
// display hologram
if (hologramLocation != null && playerData.isOnline()) {
Hologram holo = Hologram.create(Position.of(hologramLocation.add(.5, 1.5, .5)), Arrays.asList(MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message()));
Bukkit.getScheduler().runTaskLater(MMOCore.plugin, () -> holo.despawn(), 20);
}
if (hologramLocation != null && playerData.isOnline())
MMOCoreUtils.displayIndicator(hologramLocation.add(.5, 1.5, .5), MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message());
PlayerExperienceGainEvent event = new PlayerExperienceGainEvent(playerData, profession, value, source);
Bukkit.getPluginManager().callEvent(event);

View File

@ -2,6 +2,7 @@ package net.Indyuce.mmocore.api.experience;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.logging.Level;
import org.apache.commons.lang.Validate;
@ -171,4 +172,17 @@ public class Profession extends PostLoadObject {
return def;
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Profession that = (Profession) o;
return id.equals(that.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
}

View File

@ -1,8 +1,6 @@
package net.Indyuce.mmocore.api.player;
import io.lumine.mythic.lib.api.player.MMOPlayerData;
import io.lumine.mythic.utils.holograms.Hologram;
import io.lumine.mythic.utils.serialize.Position;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.ConfigMessage;
import net.Indyuce.mmocore.api.Waypoint;
@ -26,6 +24,7 @@ import net.Indyuce.mmocore.api.skill.Skill;
import net.Indyuce.mmocore.api.skill.Skill.SkillInfo;
import net.Indyuce.mmocore.api.skill.SkillResult;
import net.Indyuce.mmocore.api.skill.SkillResult.CancelReason;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.api.util.math.particle.SmallParticleEffect;
import net.Indyuce.mmocore.listener.SpellCast.SkillCasting;
import net.Indyuce.mmocore.manager.SoundManager;
@ -472,10 +471,8 @@ public class PlayerData extends OfflinePlayerData {
}
// Experience hologram
if (hologramLocation != null && isOnline()) {
Hologram holo = Hologram.create(Position.of(hologramLocation.add(.5, 1.5, .5)), Arrays.asList(MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message()));
Bukkit.getScheduler().runTaskLater(MMOCore.plugin, () -> holo.despawn(), 20);
}
if (hologramLocation != null && isOnline())
MMOCoreUtils.displayIndicator(hologramLocation.add(.5, 1.5, .5), MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message());
value = MMOCore.plugin.boosterManager.calculateExp(null, value);
value *= 1 + getStats().getStat(StatType.ADDITIONAL_EXPERIENCE) / 100;

View File

@ -3,6 +3,9 @@ package net.Indyuce.mmocore.api.util;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.version.VersionMaterial;
import io.lumine.mythic.utils.holograms.Hologram;
import io.lumine.mythic.utils.serialize.Position;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@ -53,6 +56,20 @@ public class MMOCoreUtils {
return builder.toString();
}
/**
* Displays an in game indicator using a hologram. This uses
* LumineUtils hologramFactory to summon holograms
* <p>
* The hologram despawns after 1sec
*
* @param loc Target location
* @param message Message to display
*/
public static void displayIndicator(Location loc, String message) {
Hologram holo = Hologram.create(Position.of(loc), Arrays.asList(message));
Bukkit.getScheduler().runTaskLater(MMOCore.plugin, () -> holo.despawn(), 20);
}
public static boolean isPlayerHead(Material material) {
return material == VersionMaterial.PLAYER_HEAD.toMaterial() || material == VersionMaterial.PLAYER_WALL_HEAD.toMaterial();
}

View File

@ -3,6 +3,7 @@ package net.Indyuce.mmocore.gui.api.item;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
import net.Indyuce.mmocore.gui.api.GeneratedInventory;
import net.Indyuce.mmocore.gui.api.PluginInventory;
import org.bukkit.configuration.ConfigurationSection;
@ -16,7 +17,7 @@ public class TriggerItem extends InventoryItem {
}
@Override
public Placeholders getPlaceholders(PluginInventory inv, int n) {
public Placeholders getPlaceholders(GeneratedInventory inv, int n) {
return new Placeholders();
}

View File

@ -1,10 +1,15 @@
package net.Indyuce.mmocore.listener.profession;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
import io.lumine.mythic.lib.version.VersionSound;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.droptable.dropitem.fishing.FishingDropItem;
import net.Indyuce.mmocore.api.event.CustomPlayerFishEvent;
import net.Indyuce.mmocore.api.experience.EXPSource;
import net.Indyuce.mmocore.api.loot.LootBuilder;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.stats.StatType;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.manager.profession.FishingManager.FishingDropTable;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -23,16 +28,10 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.droptable.dropitem.fishing.FishingDropItem;
import net.Indyuce.mmocore.api.event.CustomPlayerFishEvent;
import net.Indyuce.mmocore.api.experience.EXPSource;
import net.Indyuce.mmocore.api.loot.LootBuilder;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.stats.StatType;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.manager.profession.FishingManager.FishingDropTable;
import io.lumine.mythic.lib.version.VersionSound;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
public class FishingListener implements Listener {
private final Set<UUID> fishing = new HashSet<>();
@ -55,9 +54,7 @@ public class FishingListener implements Listener {
return;
new FishingData(player, hook, table);
if (MMOCore.plugin.hasHolograms())
MMOCore.plugin.hologramSupport.displayIndicator(hook.getLocation().add(0, 1.25, 0),
MMOCore.plugin.configManager.getSimpleMessage("caught-fish").message());
MMOCoreUtils.displayIndicator(hook.getLocation().add(0, 1.25, 0), MMOCore.plugin.configManager.getSimpleMessage("caught-fish").message());
}
}
@ -173,9 +170,8 @@ public class FishingListener implements Listener {
// calculate velocity
Item item = hook.getWorld().dropItemNaturally(hook.getLocation(), collect);
if (MMOCore.plugin.hasHolograms())
MMOCore.plugin.hologramSupport.displayIndicator(location.add(0, 1.25, 0),
MMOCore.plugin.configManager.getSimpleMessage("fish-out-water" + (isCrit() ? "-crit" : "")).message());
MMOCoreUtils.displayIndicator(location.add(0, 1.25, 0),
MMOCore.plugin.configManager.getSimpleMessage("fish-out-water" + (isCrit() ? "-crit" : "")).message());
Vector vec = player.getLocation().subtract(hook.getLocation()).toVector();
vec.setY(vec.getY() * .031 + vec.length() * .05);
vec.setX(vec.getX() * .08);

View File

@ -1,12 +1,13 @@
package net.Indyuce.mmocore.manager.social;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import net.Indyuce.mmocore.api.experience.Booster;
import net.Indyuce.mmocore.api.experience.Profession;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
public class BoosterManager {
private final List<Booster> map = new ArrayList<>();
@ -51,7 +52,7 @@ public class BoosterManager {
double d = 1;
for (Booster booster : map)
if (booster.getProfession() == profession && !booster.isTimedOut())
if (Objects.equals(profession, booster.getProfession()) && !booster.isTimedOut())
d += booster.getExtra();
return d;
@ -68,8 +69,9 @@ public class BoosterManager {
public List<Booster> getBoosters() {
return map;
}
/**
* @return Same as getBoosters() but does not include timed out boosters
* @return Same as {@link #getBoosters()} but does not include timed out boosters
*/
public List<Booster> getActiveBoosters() {
return map.stream().filter((b) -> !b.isTimedOut()).collect(Collectors.toList());