Merge remote-tracking branch 'origin/master'

This commit is contained in:
Jules 2022-02-25 20:54:32 +01:00
commit 3e0f71aa37
12 changed files with 181 additions and 167 deletions

View File

@ -140,7 +140,7 @@
<dependency> <dependency>
<groupId>io.lumine</groupId> <groupId>io.lumine</groupId>
<artifactId>MythicLib-dist</artifactId> <artifactId>MythicLib-dist</artifactId>
<version>1.3-R28-SNAPSHOT</version> <version>1.3-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>

View File

@ -156,7 +156,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
int j = 0; int j = 0;
while (j < boundSkills.size()) while (j < boundSkills.size())
try { try {
boundSkills.set(j, getProfess().getSkill(boundSkills.get(j).getSkill())); boundSkills.set(j, Objects.requireNonNull(getProfess().getSkill(boundSkills.get(j).getSkill())));
} catch (Exception ignored) { } catch (Exception ignored) {
} finally { } finally {
j++; j++;
@ -555,7 +555,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
if (event.isCancelled()) if (event.isCancelled())
return; return;
experience += event.getExperience(); experience = Math.max(0, experience + event.getExperience());
// Calculate the player's next level // Calculate the player's next level
int oldLevel = level, needed; int oldLevel = level, needed;
@ -843,6 +843,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
} }
public void setBoundSkill(int slot, ClassSkill skill) { public void setBoundSkill(int slot, ClassSkill skill) {
Validate.notNull(skill, "Skill cannot be null");
if (boundSkills.size() < 6) if (boundSkills.size() < 6)
boundSkills.add(skill); boundSkills.add(skill);
else else

View File

@ -6,32 +6,23 @@ import net.Indyuce.mmocore.api.player.PlayerData;
import org.bukkit.Sound; import org.bukkit.Sound;
public class FriendRequest extends Request { public class FriendRequest extends Request {
private final PlayerData target; public FriendRequest(PlayerData creator, PlayerData target) {
super(creator, target);
}
public FriendRequest(PlayerData creator, PlayerData target) { @Override
super(creator); public void whenDenied() {
getTarget().getPlayer().playSound(getTarget().getPlayer().getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1);
}
this.target = target; @Override
} public void whenAccepted() {
getCreator().setLastActivity(PlayerActivity.FRIEND_REQUEST, 0);
public PlayerData getTarget() { getCreator().addFriend(getTarget().getUniqueId());
return target; getTarget().addFriend(getCreator().getUniqueId());
} if (getCreator().isOnline()) {
MMOCore.plugin.configManager.getSimpleMessage("now-friends", "player", getTarget().getPlayer().getName()).send(getCreator().getPlayer());
public void deny() { MMOCore.plugin.configManager.getSimpleMessage("now-friends", "player", getCreator().getPlayer().getName()).send(getTarget().getPlayer());
MMOCore.plugin.requestManager.unregisterRequest(getUniqueId()); }
if(!target.isOnline()) return; }
target.getPlayer().playSound(target.getPlayer().getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1);
}
public void accept() {
getCreator().setLastActivity(PlayerActivity.FRIEND_REQUEST, 0);
getCreator().addFriend(target.getUniqueId());
target.addFriend(getCreator().getUniqueId());
if(target.isOnline() && getCreator().isOnline()) {
MMOCore.plugin.configManager.getSimpleMessage("now-friends", "player", target.getPlayer().getName()).send(getCreator().getPlayer());
MMOCore.plugin.configManager.getSimpleMessage("now-friends", "player", getCreator().getPlayer().getName()).send(target.getPlayer());
}
MMOCore.plugin.requestManager.unregisterRequest(getUniqueId());
}
} }

View File

@ -1,31 +1,55 @@
package net.Indyuce.mmocore.api.player.social; package net.Indyuce.mmocore.api.player.social;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import org.apache.commons.lang.Validate;
import java.util.UUID; import java.util.UUID;
import net.Indyuce.mmocore.api.player.PlayerData;
public abstract class Request { public abstract class Request {
private final UUID uuid = UUID.randomUUID(); private final UUID uuid = UUID.randomUUID();
private final long date = System.currentTimeMillis(); private final long date = System.currentTimeMillis();
private final PlayerData creator; private final PlayerData creator, target;
public Request(PlayerData creator) { /**
this.creator = creator; * Any request time out is by default 2 minutes.
} */
private static final long TIME_OUT = 1000 * 60 * 2;
public PlayerData getCreator() { public Request(PlayerData creator, PlayerData target) {
return creator; this.creator = creator;
} this.target = target;
}
public UUID getUniqueId() { public PlayerData getCreator() {
return uuid; return creator;
} }
public boolean isTimedOut() { public PlayerData getTarget() {
return date + 1000 * 60 * 2 < System.currentTimeMillis(); return target;
} }
public abstract void accept(); public UUID getUniqueId() {
return uuid;
}
public abstract void deny(); public boolean isTimedOut() {
return date + TIME_OUT < System.currentTimeMillis();
}
public void accept() {
Validate.isTrue(target.isOnline(), "Target must be online");
whenAccepted();
MMOCore.plugin.requestManager.unregisterRequest(getUniqueId());
}
public abstract void whenAccepted();
public void deny() {
Validate.isTrue(target.isOnline(), "Target must be online");
whenDenied();
MMOCore.plugin.requestManager.unregisterRequest(getUniqueId());
}
public abstract void whenDenied();
} }

View File

@ -1,21 +1,21 @@
package net.Indyuce.mmocore.command.rpg.admin; package net.Indyuce.mmocore.command.rpg.admin;
import java.util.function.BiConsumer; import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
import io.lumine.mythic.lib.commands.mmolib.api.Parameter;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.command.CommandVerbose;
import net.Indyuce.mmocore.command.MMOCoreCommandTreeRoot;
import net.Indyuce.mmocore.experience.EXPSource;
import net.Indyuce.mmocore.experience.PlayerProfessions;
import net.Indyuce.mmocore.experience.Profession;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import net.Indyuce.mmocore.MMOCore; import java.util.function.BiConsumer;
import net.Indyuce.mmocore.experience.EXPSource;
import net.Indyuce.mmocore.experience.PlayerProfessions;
import net.Indyuce.mmocore.experience.Profession;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.command.CommandVerbose;
import net.Indyuce.mmocore.command.MMOCoreCommandTreeRoot;
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
import io.lumine.mythic.lib.commands.mmolib.api.Parameter;
public class ExperienceCommandTreeNode extends CommandTreeNode { public class ExperienceCommandTreeNode extends CommandTreeNode {
public ExperienceCommandTreeNode(CommandTreeNode parent) { public ExperienceCommandTreeNode(CommandTreeNode parent) {
@ -24,6 +24,8 @@ public class ExperienceCommandTreeNode extends CommandTreeNode {
addChild(new ActionCommandTreeNode(this, "set", PlayerData::setExperience, PlayerProfessions::setExperience)); addChild(new ActionCommandTreeNode(this, "set", PlayerData::setExperience, PlayerProfessions::setExperience));
addChild(new ActionCommandTreeNode(this, "give", (data, value) -> data.giveExperience(value, EXPSource.COMMAND), (professions, profession, addChild(new ActionCommandTreeNode(this, "give", (data, value) -> data.giveExperience(value, EXPSource.COMMAND), (professions, profession,
value) -> professions.giveExperience(profession, value, EXPSource.COMMAND, professions.getPlayerData().getPlayer().getLocation()))); value) -> professions.giveExperience(profession, value, EXPSource.COMMAND, professions.getPlayerData().getPlayer().getLocation())));
addChild(new ActionCommandTreeNode(this, "take", (data, value) -> data.giveExperience(-value, EXPSource.COMMAND), (professions, profession,
value) -> professions.giveExperience(profession, -value, EXPSource.COMMAND, professions.getPlayerData().getPlayer().getLocation())));
} }
public static class ActionCommandTreeNode extends CommandTreeNode { public static class ActionCommandTreeNode extends CommandTreeNode {
@ -56,6 +58,7 @@ public class ExperienceCommandTreeNode extends CommandTreeNode {
int amount; int amount;
try { try {
amount = Integer.parseInt(args[5]); amount = Integer.parseInt(args[5]);
Validate.isTrue(amount > 0);
} catch (NumberFormatException exception) { } catch (NumberFormatException exception) {
sender.sendMessage(ChatColor.RED + args[5] + " is not a valid number."); sender.sendMessage(ChatColor.RED + args[5] + " is not a valid number.");
return CommandResult.FAILURE; return CommandResult.FAILURE;

View File

@ -43,7 +43,7 @@ public class StatModifiersCommandTreeNode extends CommandTreeNode {
StatInstance instance = data.getStats().getInstance(stat); StatInstance instance = data.getStats().getInstance(stat);
sender.sendMessage("Stat Modifiers (" + instance.getKeys().size() + "):"); sender.sendMessage("Stat Modifiers (" + instance.getKeys().size() + "):");
for (String key : instance.getKeys()) { for (String key : instance.getKeys()) {
StatModifier mod = instance.getAttribute(key); StatModifier mod = instance.getModifier(key);
sender.sendMessage("- " + key + ": " + mod.getValue() + " " + mod.getType().name()); sender.sendMessage("- " + key + ": " + mod.getValue() + " " + mod.getType().name());
} }

View File

@ -177,7 +177,7 @@ public class PlayerProfessions {
if (event.isCancelled()) if (event.isCancelled())
return; return;
exp.put(profession.getId(), exp.containsKey(profession.getId()) ? exp.get(profession.getId()) + event.getExperience() : event.getExperience()); exp.put(profession.getId(), Math.max(0, exp.getOrDefault(profession.getId(), 0) + event.getExperience()));
int needed, exp, level, oldLevel = getLevel(profession); int needed, exp, level, oldLevel = getLevel(profession);
/* /*

View File

@ -1,50 +1,44 @@
package net.Indyuce.mmocore.guild.provided; package net.Indyuce.mmocore.guild.provided;
import org.bukkit.Bukkit;
import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.social.Request; import net.Indyuce.mmocore.api.player.social.Request;
import net.Indyuce.mmocore.manager.InventoryManager; import net.Indyuce.mmocore.manager.InventoryManager;
import org.bukkit.Bukkit;
public class GuildInvite extends Request { public class GuildInvite extends Request {
private final PlayerData target; private final Guild guild;
private final Guild guild;
public GuildInvite(Guild guild, PlayerData creator, PlayerData target) { public GuildInvite(Guild guild, PlayerData creator, PlayerData target) {
super(creator); super(creator, target);
this.guild = guild; this.guild = guild;
this.target = target; }
}
public Guild getGuild() { public Guild getGuild() {
return guild; return guild;
} }
public PlayerData getPlayer() { @Override
return target; public void whenDenied() {
} // Nothing
}
public void deny() { @Override
MMOCore.plugin.requestManager.unregisterRequest(getUniqueId()); public void whenAccepted() {
} guild.removeLastInvite(getCreator().getPlayer());
guild.getMembers().forEach(member -> {
if (Bukkit.getPlayer(member) != null) {
MMOCore.plugin.configManager.getSimpleMessage("guild-joined-other", "player",
getTarget().getPlayer().getName()).send(Bukkit.getPlayer(member));
public void accept() { MMOCore.plugin.configManager.getSimpleMessage("guild-joined", "owner",
guild.removeLastInvite(getCreator().getPlayer()); Bukkit.getPlayer(guild.getOwner()).getName()).send(getTarget().getPlayer());
guild.getMembers().forEach(member -> { }
if(Bukkit.getPlayer(member) != null) { }
MMOCore.plugin.configManager.getSimpleMessage("guild-joined-other", "player", );
target.getPlayer().getName()).send(Bukkit.getPlayer(member));
MMOCore.plugin.configManager.getSimpleMessage("guild-joined", "owner", guild.addMember(getTarget().getUniqueId());
Bukkit.getPlayer(guild.getOwner()).getName()).send(target.getPlayer()); InventoryManager.GUILD_VIEW.newInventory(getTarget()).open();
}} }
);
guild.addMember(target.getUniqueId());
InventoryManager.GUILD_VIEW.newInventory(target).open();
MMOCore.plugin.requestManager.unregisterRequest(getUniqueId());
}
} }

View File

@ -1,47 +1,41 @@
package net.Indyuce.mmocore.manager.social; package net.Indyuce.mmocore.manager.social;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Bukkit;
import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.social.Request; import net.Indyuce.mmocore.api.player.social.Request;
import org.bukkit.Bukkit;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
public class RequestManager { public class RequestManager {
private final Set<Request> requests = new HashSet<>(); private final Map<UUID, Request> requests = new HashMap<>();
/* /**
* flush friend requests every 5 minutes so there is no memory overleak * Flushes friend requests every 5 minutes so there is no memory overleak
*/ */
public RequestManager() { public RequestManager() {
Bukkit.getScheduler().runTaskTimer(MMOCore.plugin, this::flushRequests, 60 * 20, 60 * 20 * 5); Bukkit.getScheduler().runTaskTimer(MMOCore.plugin, this::flushRequests, 60 * 20, 60 * 20 * 5);
} }
public Request getRequest(UUID uuid) { public Request getRequest(UUID uuid) {
for (Request request : requests) return requests.get(uuid);
if (request.getUniqueId().equals(uuid)) }
return request;
return null;
}
public void registerRequest(Request request) { public void registerRequest(Request request) {
requests.add(request); requests.put(request.getUniqueId(), request);
} }
public void unregisterRequest(UUID uuid) { public void unregisterRequest(UUID uuid) {
for (Iterator<Request> iterator = requests.iterator(); iterator.hasNext();) { requests.remove(uuid);
Request next = iterator.next(); }
if (next.getUniqueId().equals(uuid)) {
iterator.remove();
break;
}
}
}
public void flushRequests() { private void flushRequests() {
requests.removeIf(Request::isTimedOut); for (Iterator<Request> iterator = requests.values().iterator(); iterator.hasNext(); ) {
} Request next = iterator.next();
if (next.isTimedOut())
iterator.remove();
}
}
} }

View File

@ -145,9 +145,8 @@ public class Party implements AbstractParty {
public void sendInvite(PlayerData inviter, PlayerData target) { public void sendInvite(PlayerData inviter, PlayerData target) {
invites.put(target.getUniqueId(), System.currentTimeMillis()); invites.put(target.getUniqueId(), System.currentTimeMillis());
Request request = new PartyInvite(this, inviter, target); Request request = new PartyInvite(this, inviter, target);
if (inviter.isOnline() && target.isOnline()) new ConfigMessage("party-invite").addPlaceholders("player", inviter.getPlayer().getName(), "uuid", request.getUniqueId().toString())
new ConfigMessage("party-invite").addPlaceholders("player", inviter.getPlayer().getName(), "uuid", request.getUniqueId().toString()) .sendAsJSon(target.getPlayer());
.sendAsJSon(target.getPlayer());
MMOCore.plugin.requestManager.registerRequest(request); MMOCore.plugin.requestManager.registerRequest(request);
} }

View File

@ -6,43 +6,38 @@ import net.Indyuce.mmocore.api.player.social.Request;
import net.Indyuce.mmocore.manager.InventoryManager; import net.Indyuce.mmocore.manager.InventoryManager;
public class PartyInvite extends Request { public class PartyInvite extends Request {
private final PlayerData target; private final Party party;
private final Party party;
public PartyInvite(Party party, PlayerData creator, PlayerData target) { public PartyInvite(Party party, PlayerData creator, PlayerData target) {
super(creator); super(creator, target);
this.party = party; this.party = party;
this.target = target; }
}
public Party getParty() { public Party getParty() {
return party; return party;
} }
public PlayerData getPlayer() { @Override
return target; public void whenDenied() {
} // Nothing
}
public void deny() { @Override
MMOCore.plugin.requestManager.unregisterRequest(getUniqueId()); public void whenAccepted() {
} if (party.getMembers().size() >= Math.max(2, MMOCore.plugin.getConfig().getInt("party.max-players", 8))) {
MMOCore.plugin.configManager.getSimpleMessage("party-is-full").send(getTarget().getPlayer());
public void accept() { return;
if(party.getMembers().size() >= Math.max(2, MMOCore.plugin.getConfig().getInt("party.max-players", 8))) { }
MMOCore.plugin.configManager.getSimpleMessage("party-is-full").send(target.getPlayer()); if (getCreator().isOnline())
return; party.removeLastInvite(getCreator().getPlayer());
} party.getMembers().forEach(member -> {
if(getCreator().isOnline()) if (member.isOnline())
party.removeLastInvite(getCreator().getPlayer()); MMOCore.plugin.configManager.getSimpleMessage("party-joined-other", "player", getTarget().getPlayer().getName()).send(member.getPlayer());
party.getMembers().forEach(member -> { });
if(member.isOnline() && target.isOnline()) if (party.getOwner().isOnline())
MMOCore.plugin.configManager.getSimpleMessage("party-joined-other", "player", target.getPlayer().getName()).send(member.getPlayer()); MMOCore.plugin.configManager.getSimpleMessage("party-joined", "owner", party.getOwner().getPlayer().getName()).send(getTarget().getPlayer());
}); party.addMember(getTarget());
if(party.getOwner().isOnline() && target.isOnline()) InventoryManager.PARTY_VIEW.newInventory(getTarget()).open();
MMOCore.plugin.configManager.getSimpleMessage("party-joined", "owner", party.getOwner().getPlayer().getName()).send(target.getPlayer()); }
party.addMember(target);
InventoryManager.PARTY_VIEW.newInventory(target).open();
MMOCore.plugin.requestManager.unregisterRequest(getUniqueId());
}
} }

View File

@ -90,4 +90,17 @@ public class RegisteredSkill {
public double getModifier(String modifier, int level) { public double getModifier(String modifier, int level) {
return defaultModifiers.get(modifier).calculate(level); return defaultModifiers.get(modifier).calculate(level);
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
RegisteredSkill that = (RegisteredSkill) o;
return handler.equals(that.handler) && triggerType.equals(that.triggerType);
}
@Override
public int hashCode() {
return Objects.hash(handler, triggerType);
}
} }