2016-04-14 16:24:03 +00:00
|
|
|
package me.mrCookieSlime.Slimefun.Objects;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2019-08-27 14:26:35 +00:00
|
|
|
import java.util.Collection;
|
2016-04-14 16:24:03 +00:00
|
|
|
import java.util.Iterator;
|
2019-08-25 14:07:06 +00:00
|
|
|
import java.util.LinkedList;
|
2016-04-14 16:24:03 +00:00
|
|
|
import java.util.List;
|
2019-08-25 14:07:06 +00:00
|
|
|
import java.util.Set;
|
2016-04-14 16:24:03 +00:00
|
|
|
import java.util.UUID;
|
|
|
|
|
2019-08-25 14:07:06 +00:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.GameMode;
|
|
|
|
import org.bukkit.Sound;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Variable;
|
|
|
|
import me.mrCookieSlime.CSCoreLibPlugin.general.Particles.FireworkShow;
|
|
|
|
import me.mrCookieSlime.Slimefun.SlimefunStartup;
|
|
|
|
import me.mrCookieSlime.Slimefun.Events.ResearchUnlockEvent;
|
|
|
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
|
|
|
import me.mrCookieSlime.Slimefun.Setup.Messages;
|
2017-06-23 16:01:44 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.Setup.ResearchSetup;
|
2019-08-25 14:07:06 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.api.PlayerProfile;
|
2017-06-23 11:06:08 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
2016-04-14 16:24:03 +00:00
|
|
|
|
2017-06-23 11:06:08 +00:00
|
|
|
/**
|
2017-06-23 16:01:44 +00:00
|
|
|
* Statically handles researches. Represents a research, which is bound to one
|
|
|
|
* {@link SlimefunItem} or more and require XP levels to unlock this/these item(s).
|
2017-06-23 11:06:08 +00:00
|
|
|
* <p>
|
|
|
|
* See {@link #Research(int, String, int)} to create a research.
|
2017-06-23 16:01:44 +00:00
|
|
|
* <p>
|
|
|
|
* See {@link ResearchSetup} for the built-in researches.
|
2017-06-23 11:06:08 +00:00
|
|
|
*
|
|
|
|
* @author TheBusyBiscuit
|
|
|
|
* @since 4.0
|
|
|
|
*/
|
2016-04-14 16:24:03 +00:00
|
|
|
public class Research {
|
2019-03-27 19:38:30 +00:00
|
|
|
|
|
|
|
private static final int[] research_progress = {23, 44, 57, 92};
|
|
|
|
|
2017-06-23 11:13:22 +00:00
|
|
|
/**
|
2017-06-23 16:01:44 +00:00
|
|
|
* Whether researching is enabled or not;
|
2017-06-23 11:13:22 +00:00
|
|
|
* @since 4.0
|
|
|
|
*/
|
2019-08-25 14:07:06 +00:00
|
|
|
public static boolean enableResearching;
|
|
|
|
|
2017-06-23 11:13:22 +00:00
|
|
|
/**
|
2017-06-23 16:01:44 +00:00
|
|
|
* Contains all the registered researches;
|
2017-06-23 11:13:22 +00:00
|
|
|
* @since 4.0
|
2017-06-23 16:01:44 +00:00
|
|
|
* @see ResearchSetup
|
2017-06-23 11:13:22 +00:00
|
|
|
*/
|
2019-08-25 14:07:06 +00:00
|
|
|
public static List<Research> list = new LinkedList<>();
|
|
|
|
|
2019-08-25 20:39:59 +00:00
|
|
|
/**
|
|
|
|
* Contains all Research Titles
|
|
|
|
*/
|
|
|
|
public static List<String> titles;
|
|
|
|
|
2017-06-23 11:06:08 +00:00
|
|
|
/**
|
2017-06-23 16:01:44 +00:00
|
|
|
* Whether researching in creative is free.
|
2017-06-23 11:06:08 +00:00
|
|
|
* @since 4.0
|
|
|
|
*/
|
|
|
|
public static boolean creative_research = true;
|
2017-06-23 11:13:22 +00:00
|
|
|
|
2017-06-23 11:06:08 +00:00
|
|
|
private int id;
|
|
|
|
private String name;
|
|
|
|
private List<SlimefunItem> items;
|
|
|
|
private int cost;
|
2019-08-25 14:07:06 +00:00
|
|
|
private boolean enabled;
|
2017-06-23 11:13:22 +00:00
|
|
|
|
2017-06-23 11:06:08 +00:00
|
|
|
/**
|
|
|
|
* The constructor for a Research.
|
|
|
|
* <p>
|
|
|
|
* Create a new research by calling {@link #Research(int, String, int)}, then
|
|
|
|
* bind this research to the Slimefun items you want by calling
|
|
|
|
* {@link #addItems(SlimefunItem...)}. Once you're finished, call {@link #register()}
|
|
|
|
* to register it.
|
|
|
|
* <p>
|
|
|
|
* To speed up, directly setup the research by calling
|
|
|
|
* {@link Slimefun#registerResearch(Research, org.bukkit.inventory.ItemStack...)}.
|
|
|
|
*
|
|
|
|
* @param id Unique integer ID for this research, used for {@link #getByID(int)} and to
|
2017-06-23 11:13:22 +00:00
|
|
|
* register it in Researches.yml
|
2017-06-23 11:06:08 +00:00
|
|
|
* @param name Display name of the research
|
|
|
|
* @param cost Cost in XP levels to unlock the research
|
|
|
|
*
|
|
|
|
* @since 4.0
|
|
|
|
*/
|
|
|
|
public Research(int id, String name, int cost) {
|
2016-04-14 16:24:03 +00:00
|
|
|
this.id = id;
|
|
|
|
this.name = name;
|
2017-06-23 11:13:22 +00:00
|
|
|
this.cost = cost;
|
2019-06-20 08:12:34 +00:00
|
|
|
this.items = new ArrayList<>();
|
2019-08-25 14:07:06 +00:00
|
|
|
this.enabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isEnabled() {
|
|
|
|
return enableResearching && enabled;
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
2017-06-23 11:13:22 +00:00
|
|
|
|
2017-06-23 11:06:08 +00:00
|
|
|
/**
|
2017-06-23 16:01:44 +00:00
|
|
|
* Gets the ID of the research.
|
2017-06-23 11:06:08 +00:00
|
|
|
*
|
|
|
|
* @return ID of the research
|
|
|
|
*
|
|
|
|
* @since 4.0
|
|
|
|
*/
|
2016-04-14 16:24:03 +00:00
|
|
|
public int getID() {
|
2017-06-23 11:06:08 +00:00
|
|
|
return id;
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
2017-06-23 11:13:22 +00:00
|
|
|
|
2017-06-23 11:06:08 +00:00
|
|
|
/**
|
2017-06-23 16:01:44 +00:00
|
|
|
* Gets the display name of the research.
|
2017-06-23 11:06:08 +00:00
|
|
|
*
|
|
|
|
* @return The display name of the research
|
|
|
|
*
|
|
|
|
* @since 4.0
|
|
|
|
*/
|
2016-04-14 16:24:03 +00:00
|
|
|
public String getName() {
|
2017-06-23 11:06:08 +00:00
|
|
|
return name;
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
2017-06-23 11:13:22 +00:00
|
|
|
|
2017-06-23 11:06:08 +00:00
|
|
|
/**
|
2017-06-23 16:01:44 +00:00
|
|
|
* Gets the cost in XP levels to unlock the research.
|
2017-06-23 11:06:08 +00:00
|
|
|
*
|
|
|
|
* @return The cost in XP levels of the research
|
|
|
|
*
|
|
|
|
* @since 4.0
|
|
|
|
* @deprecated Moved to {@link #getCost()}
|
|
|
|
*/
|
|
|
|
@Deprecated
|
2016-04-14 16:24:03 +00:00
|
|
|
public int getLevel() {
|
2017-06-23 11:06:08 +00:00
|
|
|
return cost;
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
2017-06-23 11:13:22 +00:00
|
|
|
|
2017-06-23 11:06:08 +00:00
|
|
|
/**
|
2017-06-23 16:01:44 +00:00
|
|
|
* Sets the cost in XP levels to unlock the research.
|
2017-06-23 11:06:08 +00:00
|
|
|
*
|
|
|
|
* @param level Cost in XP levels
|
|
|
|
*
|
|
|
|
* @since 4.0
|
|
|
|
* @deprecated Moved to {@link #setCost(int)}
|
|
|
|
*/
|
|
|
|
@Deprecated
|
2016-04-14 16:24:03 +00:00
|
|
|
public void setLevel(int level) {
|
2017-06-23 11:06:08 +00:00
|
|
|
this.cost = level;
|
|
|
|
}
|
2017-06-23 11:13:22 +00:00
|
|
|
|
2017-06-23 11:06:08 +00:00
|
|
|
/**
|
2017-06-23 16:01:44 +00:00
|
|
|
* Gets the cost in XP levels to unlock the research.
|
2017-06-23 11:13:22 +00:00
|
|
|
*
|
|
|
|
* @return The cost in XP levels of the research
|
2017-06-23 11:06:08 +00:00
|
|
|
* @since 4.1.10
|
|
|
|
*/
|
|
|
|
public int getCost() {
|
2017-06-23 11:13:22 +00:00
|
|
|
return cost;
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
2017-06-23 11:13:22 +00:00
|
|
|
|
2017-06-23 11:06:08 +00:00
|
|
|
/**
|
2017-06-23 16:01:44 +00:00
|
|
|
* Sets the cost in XP levels to unlock the research.
|
2017-06-23 11:13:22 +00:00
|
|
|
*
|
|
|
|
* @param cost Cost in XP levels
|
|
|
|
*
|
2017-06-23 11:06:08 +00:00
|
|
|
* @since 4.1.10
|
|
|
|
*/
|
|
|
|
public void setCost(int cost) {
|
2017-06-23 11:13:22 +00:00
|
|
|
this.cost = cost;
|
2017-06-23 11:06:08 +00:00
|
|
|
}
|
2017-06-23 11:13:22 +00:00
|
|
|
|
2017-06-23 11:06:08 +00:00
|
|
|
/**
|
2017-06-23 16:01:44 +00:00
|
|
|
* Bind the specified Slimefun items to the research.
|
2017-06-23 11:06:08 +00:00
|
|
|
*
|
|
|
|
* @param items {@link SlimefunItem} to bind to the research
|
|
|
|
*
|
|
|
|
* @since 4.0
|
|
|
|
*/
|
2016-04-14 16:24:03 +00:00
|
|
|
public void addItems(SlimefunItem... items) {
|
|
|
|
for (SlimefunItem item: items) {
|
|
|
|
if (item != null) item.bindToResearch(this);
|
|
|
|
}
|
|
|
|
}
|
2017-06-23 11:13:22 +00:00
|
|
|
|
2017-06-23 11:06:08 +00:00
|
|
|
/**
|
2017-06-23 16:01:44 +00:00
|
|
|
* Gets the list of the Slimefun items bound to the research.
|
2017-06-23 11:06:08 +00:00
|
|
|
*
|
|
|
|
* @return the Slimefun items bound to the research
|
|
|
|
*
|
|
|
|
* @since 4.0
|
|
|
|
*/
|
2019-08-25 14:07:06 +00:00
|
|
|
public List<SlimefunItem> getAffectedItems() {
|
2017-06-23 11:06:08 +00:00
|
|
|
return items;
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
2017-06-23 11:13:22 +00:00
|
|
|
|
2017-06-23 11:06:08 +00:00
|
|
|
/**
|
2017-06-23 16:01:44 +00:00
|
|
|
* Convenience method to check if the player unlocked this research.
|
2017-06-23 11:06:08 +00:00
|
|
|
*
|
|
|
|
* @param p Player to check
|
|
|
|
* @return true if he unlocked the research, otherwise false
|
|
|
|
*
|
|
|
|
* @since 4.0
|
|
|
|
* @see #hasUnlocked(UUID)
|
|
|
|
*/
|
2019-08-25 14:07:06 +00:00
|
|
|
@Deprecated
|
2016-04-14 16:24:03 +00:00
|
|
|
public boolean hasUnlocked(Player p) {
|
|
|
|
return hasUnlocked(p.getUniqueId());
|
|
|
|
}
|
2017-06-23 11:13:22 +00:00
|
|
|
|
2017-06-23 11:06:08 +00:00
|
|
|
/**
|
2017-06-23 16:01:44 +00:00
|
|
|
* Checks if the player unlocked this research.
|
2017-06-23 11:06:08 +00:00
|
|
|
*
|
|
|
|
* @param uuid UUID of the player to check
|
|
|
|
* @return true if he unlocked the research, otherwise false
|
|
|
|
*
|
|
|
|
* @since 4.0
|
|
|
|
* @see #hasUnlocked(Player)
|
|
|
|
*/
|
2019-08-25 14:07:06 +00:00
|
|
|
@Deprecated
|
2016-04-14 16:24:03 +00:00
|
|
|
public boolean hasUnlocked(UUID uuid) {
|
2019-08-25 14:07:06 +00:00
|
|
|
return PlayerProfile.fromUUID(uuid).hasUnlocked(this);
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
2017-06-23 11:13:22 +00:00
|
|
|
|
2017-06-23 11:06:08 +00:00
|
|
|
/**
|
2017-06-23 16:01:44 +00:00
|
|
|
* Checks if the player can unlock this research.
|
2017-06-23 11:06:08 +00:00
|
|
|
*
|
|
|
|
* @param p Player to check
|
|
|
|
* @return true if he can unlock the research, otherwise false
|
|
|
|
*
|
|
|
|
* @since 4.1.10
|
|
|
|
*/
|
|
|
|
public boolean canUnlock(Player p) {
|
2019-08-25 14:07:06 +00:00
|
|
|
if (!isEnabled()) return true;
|
2017-06-23 11:13:22 +00:00
|
|
|
return (p.getGameMode() == GameMode.CREATIVE && creative_research) || p.getLevel() >= this.cost;
|
2017-06-23 11:06:08 +00:00
|
|
|
}
|
2017-06-23 11:13:22 +00:00
|
|
|
|
2017-06-23 11:06:08 +00:00
|
|
|
/**
|
2017-06-23 16:01:44 +00:00
|
|
|
* Locks the research for the specified player.
|
2017-06-23 11:06:08 +00:00
|
|
|
*
|
|
|
|
* @param p Player to lock the research
|
|
|
|
*
|
|
|
|
* @since 4.0
|
|
|
|
*/
|
2019-08-25 14:07:06 +00:00
|
|
|
@Deprecated
|
2016-04-14 16:24:03 +00:00
|
|
|
public void lock(Player p) {
|
2019-08-25 14:07:06 +00:00
|
|
|
PlayerProfile.fromUUID(p.getUniqueId()).setResearched(this, false);
|
2016-04-14 16:24:03 +00:00
|
|
|
Messages.local.sendTranslation(p, "commands.research.reset-target", true);
|
|
|
|
}
|
2017-06-23 11:13:22 +00:00
|
|
|
|
2017-06-23 11:06:08 +00:00
|
|
|
/**
|
2017-06-23 16:01:44 +00:00
|
|
|
* Unlocks the research for the specified player.
|
2017-06-23 11:06:08 +00:00
|
|
|
*
|
|
|
|
* @param p Player to unlock the research
|
|
|
|
* @param instant Whether to unlock the research instantly
|
|
|
|
*
|
|
|
|
* @since 4.0
|
|
|
|
*/
|
2016-04-14 16:24:03 +00:00
|
|
|
public void unlock(final Player p, boolean instant) {
|
|
|
|
if (!hasUnlocked(p)) {
|
|
|
|
ResearchUnlockEvent event = new ResearchUnlockEvent(p, this);
|
|
|
|
Bukkit.getPluginManager().callEvent(event);
|
2019-08-25 14:07:06 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
if (!event.isCancelled()) {
|
|
|
|
if (instant) {
|
2019-08-25 14:07:06 +00:00
|
|
|
PlayerProfile.fromUUID(p.getUniqueId()).setResearched(this, true);
|
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
Messages.local.sendTranslation(p, "messages.unlocked", true, new Variable("%research%", getName()));
|
2019-08-25 14:07:06 +00:00
|
|
|
if (SlimefunStartup.getCfg().getBoolean("options.research-give-fireworks")) {
|
2019-03-27 19:38:30 +00:00
|
|
|
FireworkShow.launchRandom(p, 1);
|
2019-08-25 14:07:06 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-27 12:08:09 +00:00
|
|
|
else if (!SlimefunStartup.instance.getUtilities().researching.contains(p.getUniqueId())){
|
|
|
|
SlimefunStartup.instance.getUtilities().researching.add(p.getUniqueId());
|
2016-04-14 16:24:03 +00:00
|
|
|
Messages.local.sendTranslation(p, "messages.research.start", true, new Variable("%research%", getName()));
|
2019-08-25 14:07:06 +00:00
|
|
|
|
2019-03-27 19:38:30 +00:00
|
|
|
for (int i = 1; i < research_progress.length + 1; i++) {
|
|
|
|
int j = i;
|
2019-08-25 14:07:06 +00:00
|
|
|
|
2019-03-27 19:38:30 +00:00
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, () -> {
|
2016-04-14 16:24:03 +00:00
|
|
|
p.playSound(p.getLocation(), Sound.ENTITY_BAT_TAKEOFF, 0.7F, 1F);
|
2019-03-27 19:38:30 +00:00
|
|
|
Messages.local.sendTranslation(p, "messages.research.progress", true, new Variable("%research%", getName()), new Variable("%progress%", research_progress[j - 1] + "%"));
|
2019-08-25 14:07:06 +00:00
|
|
|
}, i * 20L);
|
2019-03-27 19:38:30 +00:00
|
|
|
}
|
2019-08-25 14:07:06 +00:00
|
|
|
|
2019-03-27 19:38:30 +00:00
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, () -> {
|
2019-08-25 14:07:06 +00:00
|
|
|
PlayerProfile.fromUUID(p.getUniqueId()).setResearched(this, true);
|
2019-03-27 19:38:30 +00:00
|
|
|
Messages.local.sendTranslation(p, "messages.unlocked", true, new Variable("%research%", getName()));
|
2019-08-25 14:07:06 +00:00
|
|
|
|
|
|
|
if (SlimefunStartup.getCfg().getBoolean("options.research-unlock-fireworks")) {
|
2019-03-27 19:38:30 +00:00
|
|
|
FireworkShow.launchRandom(p, 1);
|
2019-08-25 14:07:06 +00:00
|
|
|
}
|
|
|
|
|
2019-08-27 12:08:09 +00:00
|
|
|
SlimefunStartup.instance.getUtilities().researching.remove(p.getUniqueId());
|
2019-08-25 14:07:06 +00:00
|
|
|
}, (research_progress.length + 1) * 20L);
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-23 11:13:22 +00:00
|
|
|
|
2017-06-23 11:06:08 +00:00
|
|
|
/**
|
2017-06-23 16:01:44 +00:00
|
|
|
* Registers the research.
|
2017-06-23 11:06:08 +00:00
|
|
|
*
|
|
|
|
* @since 4.0
|
|
|
|
*/
|
2016-04-14 16:24:03 +00:00
|
|
|
public void register() {
|
|
|
|
SlimefunStartup.getResearchCfg().setDefaultValue("enable-researching", true);
|
2017-06-23 11:13:22 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
if (SlimefunStartup.getResearchCfg().contains(this.getID() + ".enabled") && !SlimefunStartup.getResearchCfg().getBoolean(this.getID() + ".enabled")) {
|
|
|
|
Iterator<SlimefunItem> iterator = items.iterator();
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
SlimefunItem item = iterator.next();
|
|
|
|
if (item != null) item.bindToResearch(null);
|
|
|
|
iterator.remove();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2017-06-23 11:13:22 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
SlimefunStartup.getResearchCfg().setDefaultValue(this.getID() + ".name", this.getName());
|
2017-06-23 11:06:08 +00:00
|
|
|
SlimefunStartup.getResearchCfg().setDefaultValue(this.getID() + ".cost", this.getCost());
|
2016-04-14 16:24:03 +00:00
|
|
|
SlimefunStartup.getResearchCfg().setDefaultValue(this.getID() + ".enabled", true);
|
2017-06-23 11:13:22 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
this.name = SlimefunStartup.getResearchCfg().getString(this.getID() + ".name");
|
2017-06-23 11:06:08 +00:00
|
|
|
this.cost = SlimefunStartup.getResearchCfg().getInt(this.getID() + ".cost");
|
2019-08-25 14:07:06 +00:00
|
|
|
this.enabled = SlimefunStartup.getResearchCfg().getBoolean(this.getID() + ".enabled");
|
2017-06-23 11:13:22 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
list.add(this);
|
|
|
|
if (SlimefunStartup.getCfg().getBoolean("options.print-out-loading")) System.out.println("[Slimefun] Loaded Research \"" + this.getName() + "\"");
|
|
|
|
}
|
2017-06-23 11:13:22 +00:00
|
|
|
|
2017-06-23 11:06:08 +00:00
|
|
|
/**
|
2017-06-23 16:01:44 +00:00
|
|
|
* Gets the list of all registered researches.
|
2017-06-23 11:06:08 +00:00
|
|
|
*
|
|
|
|
* @return The list of registered researches
|
|
|
|
*
|
|
|
|
* @since 4.0
|
2017-06-23 16:01:44 +00:00
|
|
|
* @see ResearchSetup
|
2017-06-23 11:06:08 +00:00
|
|
|
*/
|
2016-04-14 16:24:03 +00:00
|
|
|
public static List<Research> list() {
|
|
|
|
return list;
|
|
|
|
}
|
2017-06-23 11:13:22 +00:00
|
|
|
|
2017-06-23 11:06:08 +00:00
|
|
|
/**
|
2017-06-23 16:01:44 +00:00
|
|
|
* Gets if the specified player is currently unlocking a research.
|
2017-06-23 11:06:08 +00:00
|
|
|
*
|
|
|
|
* @param p Player to check
|
|
|
|
* @return true if the player is unlocking a research, otherwise false
|
|
|
|
*
|
|
|
|
* @since 4.0
|
|
|
|
*/
|
2016-04-14 16:24:03 +00:00
|
|
|
public static boolean isResearching(Player p) {
|
2019-08-27 12:08:09 +00:00
|
|
|
return SlimefunStartup.instance.getUtilities().researching.contains(p.getUniqueId());
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
2017-06-23 11:13:22 +00:00
|
|
|
|
2017-06-23 11:06:08 +00:00
|
|
|
/**
|
2017-06-23 16:01:44 +00:00
|
|
|
* Sends the research statistics and title of the specified player to the command sender.
|
2017-06-23 11:06:08 +00:00
|
|
|
*
|
|
|
|
* @param sender CommandSender to send the statistics
|
|
|
|
* @param p Player to get the statistics
|
|
|
|
*
|
|
|
|
* @since 4.0
|
|
|
|
* @see #getTitle(Player, List)
|
|
|
|
*/
|
2019-08-25 14:07:06 +00:00
|
|
|
@Deprecated
|
2016-04-14 16:24:03 +00:00
|
|
|
public static void sendStats(CommandSender sender, Player p) {
|
2019-08-25 14:07:06 +00:00
|
|
|
PlayerProfile profile = PlayerProfile.fromUUID(p.getUniqueId());
|
|
|
|
Set<Research> researched = profile.getResearches();
|
2019-08-27 14:26:35 +00:00
|
|
|
int levels = researched.stream().mapToInt(Research::getCost).sum();
|
2019-08-25 14:07:06 +00:00
|
|
|
|
2019-08-27 13:27:38 +00:00
|
|
|
String progress = String.valueOf(Math.round(((researched.size() * 100.0F) / list().size()) * 100.0F) / 100.0F);
|
2016-04-14 16:24:03 +00:00
|
|
|
if (Float.parseFloat(progress) < 16.0F) progress = "&4" + progress + " &r% ";
|
|
|
|
else if (Float.parseFloat(progress) < 32.0F) progress = "&c" + progress + " &r% ";
|
|
|
|
else if (Float.parseFloat(progress) < 48.0F) progress = "&6" + progress + " &r% ";
|
|
|
|
else if (Float.parseFloat(progress) < 64.0F) progress = "&e" + progress + " &r% ";
|
|
|
|
else if (Float.parseFloat(progress) < 80.0F) progress = "&2" + progress + " &r% ";
|
|
|
|
else progress = "&a" + progress + " &r% ";
|
2017-06-23 11:13:22 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
sender.sendMessage("");
|
|
|
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7Statistics for Player: &b" + p.getName()));
|
|
|
|
sender.sendMessage("");
|
|
|
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7Title: &b" + getTitle(p, researched)));
|
|
|
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7Research Progress: " + progress + "&e(" + researched.size() + " / " + list().size() + ")"));
|
|
|
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7Total XP Levels spent: &b" + levels));
|
|
|
|
}
|
2017-06-23 11:13:22 +00:00
|
|
|
|
2017-06-23 11:06:08 +00:00
|
|
|
/**
|
2017-06-23 16:01:44 +00:00
|
|
|
* Gets the title of the specified player.
|
2017-06-23 11:06:08 +00:00
|
|
|
*
|
|
|
|
* @param p Player to get the rank
|
|
|
|
* @param researched List of the player's unlocked researches
|
|
|
|
* @return the title of the specified player
|
|
|
|
*
|
|
|
|
* @since 4.0
|
|
|
|
* @see #sendStats(CommandSender, Player)
|
|
|
|
*/
|
2019-08-25 14:07:06 +00:00
|
|
|
@Deprecated
|
2019-08-27 14:26:35 +00:00
|
|
|
public static String getTitle(Player p, Collection<Research> researched) {
|
2019-08-27 13:27:38 +00:00
|
|
|
int index = Math.round(Float.valueOf(String.valueOf(Math.round(((researched.size() * 100.0F) / list().size()) * 100.0F) / 100.0F)) / 100.0F) * titles.size();
|
2016-04-14 16:24:03 +00:00
|
|
|
if (index > 0) index--;
|
2019-08-25 20:39:59 +00:00
|
|
|
return titles.get(index);
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
2017-06-23 11:13:22 +00:00
|
|
|
|
2017-06-23 11:06:08 +00:00
|
|
|
/**
|
2017-06-23 16:01:44 +00:00
|
|
|
* Attempts to get the research with the given ID.
|
2017-06-23 11:06:08 +00:00
|
|
|
*
|
|
|
|
* @param id ID of the research to get
|
|
|
|
* @return Research if found, or null
|
|
|
|
*
|
|
|
|
* @since 4.0
|
|
|
|
*/
|
2016-04-14 16:24:03 +00:00
|
|
|
public static Research getByID(int id) {
|
|
|
|
for (Research research: list) {
|
|
|
|
if (research.getID() == id) return research;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2017-06-23 11:13:22 +00:00
|
|
|
|
2017-06-23 11:06:08 +00:00
|
|
|
/**
|
2017-06-23 16:01:44 +00:00
|
|
|
* Gets the list of unlocked researches for a player using his UUID.
|
2017-06-23 11:06:08 +00:00
|
|
|
*
|
|
|
|
* @param uuid UUID of the player
|
|
|
|
* @return the list of unlocked researches for the player
|
|
|
|
*
|
|
|
|
* @since 4.0
|
|
|
|
* @see #getResearches(String)
|
|
|
|
*/
|
2019-08-25 14:07:06 +00:00
|
|
|
@Deprecated
|
2016-04-14 16:24:03 +00:00
|
|
|
public static List<Research> getResearches(UUID uuid) {
|
2019-08-25 14:07:06 +00:00
|
|
|
List<Research> researched = new ArrayList<>();
|
2016-04-14 16:24:03 +00:00
|
|
|
for (Research r: list()) {
|
|
|
|
if (r.hasUnlocked(uuid)) researched.add(r);
|
|
|
|
}
|
|
|
|
return researched;
|
|
|
|
}
|
2017-06-23 11:13:22 +00:00
|
|
|
|
2017-06-23 11:06:08 +00:00
|
|
|
/**
|
|
|
|
* Convenience method to get the list of unlocked researches
|
2017-06-23 16:01:44 +00:00
|
|
|
* for a player using his UUID (specified as a String).
|
2017-06-23 11:06:08 +00:00
|
|
|
*
|
|
|
|
* @param uuid String representing the UUID of the player
|
|
|
|
* @return the list of unlocked researches for the player
|
|
|
|
*
|
|
|
|
* @since 4.0
|
|
|
|
* @see #getResearches(UUID)
|
|
|
|
*/
|
2019-08-25 14:07:06 +00:00
|
|
|
@Deprecated
|
2016-04-14 16:24:03 +00:00
|
|
|
public static List<Research> getResearches(String uuid) {
|
|
|
|
return getResearches(UUID.fromString(uuid));
|
|
|
|
}
|
2017-06-23 11:13:22 +00:00
|
|
|
}
|