mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-24 19:45:43 +01:00
Parties integration (WIP); #1043
This commit is contained in:
parent
98dda3f946
commit
d32b8ad681
@ -30,80 +30,14 @@ import org.bukkit.entity.Player;
|
|||||||
*/
|
*/
|
||||||
public abstract class GroupAdapter<T> {
|
public abstract class GroupAdapter<T> {
|
||||||
|
|
||||||
/**
|
|
||||||
* How the implementation handles players.
|
|
||||||
*/
|
|
||||||
public enum Philosophy {
|
|
||||||
/**
|
|
||||||
* The group persists upon restarts.
|
|
||||||
* <p>
|
|
||||||
* DungeonsXL under no circumstances creates persistent external groups.
|
|
||||||
*/
|
|
||||||
PERSISTENT,
|
|
||||||
/**
|
|
||||||
* The group continues to exist as long as the server is running, but does not persist upon restarts.
|
|
||||||
*/
|
|
||||||
RUNTIME,
|
|
||||||
/**
|
|
||||||
* Players are kicked from the group when they leave the server.
|
|
||||||
*/
|
|
||||||
ONLINE
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ExternalGroupData<T> {
|
|
||||||
|
|
||||||
private T eGroup;
|
|
||||||
private boolean createdByDXL;
|
|
||||||
|
|
||||||
public ExternalGroupData(T eGroup, boolean createdByDXL) {
|
|
||||||
this.eGroup = eGroup;
|
|
||||||
this.createdByDXL = createdByDXL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the wrapped external group object.
|
|
||||||
*
|
|
||||||
* @return the wrapped external group object
|
|
||||||
*/
|
|
||||||
public T get() {
|
|
||||||
return eGroup;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns if the external group was created by DungeonsXL.
|
|
||||||
* <p>
|
|
||||||
* Groups may be created by DungeonsXL, for example through a command, a group sign or automatically if a dungeon is entered.
|
|
||||||
* The integration implementation should give dungeon groups equivalent groups from the external group plugin.
|
|
||||||
* External groups created to mirror dungeon groups should be removed when their dungeon group is deleted, but those created intentionally should not.
|
|
||||||
*
|
|
||||||
* @return if the external group was created by DungeonsXL.
|
|
||||||
*/
|
|
||||||
public boolean isCreatedByDXL() {
|
|
||||||
return createdByDXL;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected DungeonsAPI dxl;
|
protected DungeonsAPI dxl;
|
||||||
private Philosophy philosophy;
|
protected Map<PlayerGroup, T> groups = new HashMap<>();
|
||||||
protected Map<PlayerGroup, ExternalGroupData<T>> groups = new HashMap<>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param dxl the DungeonsAPI instance
|
* @param dxl the DungeonsAPI instance
|
||||||
* @param philosophy the player handling philosophy
|
|
||||||
*/
|
*/
|
||||||
protected GroupAdapter(DungeonsAPI dxl, Philosophy philosophy) {
|
protected GroupAdapter(DungeonsAPI dxl) {
|
||||||
this.dxl = dxl;
|
this.dxl = dxl;
|
||||||
this.philosophy = philosophy;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the player handling philosophy.
|
|
||||||
*
|
|
||||||
* @return the player handling philosophy
|
|
||||||
*/
|
|
||||||
public Philosophy getPhilosophy() {
|
|
||||||
return philosophy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -114,14 +48,6 @@ public abstract class GroupAdapter<T> {
|
|||||||
*/
|
*/
|
||||||
public abstract PlayerGroup createDungeonGroup(T eGroup);
|
public abstract PlayerGroup createDungeonGroup(T eGroup);
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an external group {@link #areCorresponding(PlayerGroup, Object) corresponding} with the dungeon group.
|
|
||||||
*
|
|
||||||
* @param dGroup the dungeon group
|
|
||||||
* @return an external group {@link #areCorresponding(PlayerGroup, Object) corresponding} with the dungeon group
|
|
||||||
*/
|
|
||||||
public abstract T createExternalGroup(PlayerGroup dGroup);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the dungeon group {@link #areCorresponding(PlayerGroup, Object) corresponding} with the external group or null of none exists.
|
* Returns the dungeon group {@link #areCorresponding(PlayerGroup, Object) corresponding} with the external group or null of none exists.
|
||||||
*
|
*
|
||||||
@ -129,8 +55,11 @@ public abstract class GroupAdapter<T> {
|
|||||||
* @return the dungeon group {@link #areCorresponding(PlayerGroup, Object) corresponding} with the external group
|
* @return the dungeon group {@link #areCorresponding(PlayerGroup, Object) corresponding} with the external group
|
||||||
*/
|
*/
|
||||||
public PlayerGroup getDungeonGroup(T eGroup) {
|
public PlayerGroup getDungeonGroup(T eGroup) {
|
||||||
for (Entry<PlayerGroup, ExternalGroupData<T>> entry : groups.entrySet()) {
|
if (eGroup == null) {
|
||||||
if (entry.getValue().get().equals(eGroup)) {
|
return null;
|
||||||
|
}
|
||||||
|
for (Entry<PlayerGroup, T> entry : groups.entrySet()) {
|
||||||
|
if (entry.getValue().equals(eGroup)) {
|
||||||
return entry.getKey();
|
return entry.getKey();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -144,8 +73,27 @@ public abstract class GroupAdapter<T> {
|
|||||||
* @return the external group {@link #areCorresponding(PlayerGroup, Object) corresponding} with the dungeon group
|
* @return the external group {@link #areCorresponding(PlayerGroup, Object) corresponding} with the dungeon group
|
||||||
*/
|
*/
|
||||||
public T getExternalGroup(PlayerGroup dGroup) {
|
public T getExternalGroup(PlayerGroup dGroup) {
|
||||||
ExternalGroupData<T> data = groups.get(dGroup);
|
return groups.get(dGroup);
|
||||||
return data != null ? data.get() : null;
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the dungeon group that mirrors the external group.
|
||||||
|
* <p>
|
||||||
|
* Creates a dungeon group if none exists and if the party has no more online members than maxSize.
|
||||||
|
*
|
||||||
|
* @param eGroup the dungeon group
|
||||||
|
* @param maxSize the maximum size of the group
|
||||||
|
* @return the dungeon group that mirrors the dungeon group
|
||||||
|
*/
|
||||||
|
public PlayerGroup getOrCreateDungeonGroup(T eGroup, int maxSize) {
|
||||||
|
if (eGroup == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
PlayerGroup dGroup = getDungeonGroup(eGroup);
|
||||||
|
if (dGroup == null && getGroupOnlineSize(eGroup) <= maxSize) {
|
||||||
|
dGroup = createDungeonGroup(eGroup);
|
||||||
|
}
|
||||||
|
return dGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -157,6 +105,9 @@ public abstract class GroupAdapter<T> {
|
|||||||
* @return the dungeon group that mirrors the dungeon group
|
* @return the dungeon group that mirrors the dungeon group
|
||||||
*/
|
*/
|
||||||
public PlayerGroup getOrCreateDungeonGroup(T eGroup) {
|
public PlayerGroup getOrCreateDungeonGroup(T eGroup) {
|
||||||
|
if (eGroup == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
PlayerGroup dGroup = getDungeonGroup(eGroup);
|
PlayerGroup dGroup = getDungeonGroup(eGroup);
|
||||||
if (dGroup == null) {
|
if (dGroup == null) {
|
||||||
dGroup = createDungeonGroup(eGroup);
|
dGroup = createDungeonGroup(eGroup);
|
||||||
@ -164,22 +115,6 @@ public abstract class GroupAdapter<T> {
|
|||||||
return dGroup;
|
return dGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the external group that mirrors the dungeon group.
|
|
||||||
* <p>
|
|
||||||
* Creates an external group if none exists.
|
|
||||||
*
|
|
||||||
* @param dGroup the dungeon group
|
|
||||||
* @return the external group that mirrors the dungeon group
|
|
||||||
*/
|
|
||||||
public T getOrCreateExternalGroup(PlayerGroup dGroup) {
|
|
||||||
T eGroup = getExternalGroup(dGroup);
|
|
||||||
if (eGroup == null && getPhilosophy() != Philosophy.PERSISTENT) {
|
|
||||||
eGroup = createExternalGroup(dGroup);
|
|
||||||
}
|
|
||||||
return eGroup;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the external group of the given group member.
|
* Returns the external group of the given group member.
|
||||||
*
|
*
|
||||||
@ -188,6 +123,14 @@ public abstract class GroupAdapter<T> {
|
|||||||
*/
|
*/
|
||||||
public abstract T getExternalGroup(Player member);
|
public abstract T getExternalGroup(Player member);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the amount of members in the external group who are online.
|
||||||
|
*
|
||||||
|
* @param eGroup the external group
|
||||||
|
* @return the amount of members in the external group who are online
|
||||||
|
*/
|
||||||
|
public abstract int getGroupOnlineSize(T eGroup);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if two groups are corresponding.
|
* Checks if two groups are corresponding.
|
||||||
* <p>
|
* <p>
|
||||||
@ -203,94 +146,43 @@ public abstract class GroupAdapter<T> {
|
|||||||
if (dGroup == null || eGroup == null) {
|
if (dGroup == null || eGroup == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ExternalGroupData<T> data = groups.get(dGroup);
|
T dExternal = groups.get(dGroup);
|
||||||
return data != null && eGroup.equals(data.get());
|
return dExternal != null && eGroup.equals(dExternal);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the external group corresponding with the given dungeon group.
|
* Returns if the player is a member of any external group.
|
||||||
*
|
|
||||||
* @param dGroup the dungeon group corresponding with the external one to delete
|
|
||||||
* @return if the deletion was successful
|
|
||||||
*/
|
|
||||||
public abstract boolean deleteCorrespondingGroup(PlayerGroup dGroup);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the two groups have the same members.
|
|
||||||
*
|
|
||||||
* @param dGroup the dungeon group
|
|
||||||
* @param eGroup the external group
|
|
||||||
* @return if the two groups have the same members
|
|
||||||
*/
|
|
||||||
public abstract boolean areSimilar(PlayerGroup dGroup, T eGroup);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ensures that the player is in {@link #areCorresponding(PlayerGroup, Object) corresponding} groups.
|
|
||||||
* <p>
|
|
||||||
* If the player is in an external group but not in a corresponding dungeon group, they are added to the corresponding dungeon group.
|
|
||||||
* If no dungeon group exists, it is created automatically. Switching dungeon groups forces the player to leave their dungeon.
|
|
||||||
* <p>
|
|
||||||
* If the player is in a dungeon group but not in an external group, the player is added to the corresponding external group if it exists.
|
|
||||||
* If no corresponding external group exists, a new one is created.
|
|
||||||
*
|
*
|
||||||
* @param player the player
|
* @param player the player
|
||||||
|
* @return if the player is a member of any external group
|
||||||
*/
|
*/
|
||||||
public void syncJoin(Player player) {
|
public boolean isExternalGroupMember(Player player) {
|
||||||
T eGroup = getExternalGroup(player);
|
return getExternalGroup(player) != null;
|
||||||
PlayerGroup dGroup = dxl.getPlayerGroup(player);
|
|
||||||
|
|
||||||
if (eGroup != null && !areCorresponding(dGroup, eGroup)) {
|
|
||||||
if (areSimilar(dGroup, eGroup)) {
|
|
||||||
// The groups are not yet marked as corresponding because one of them is still being created.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (dGroup != null) {
|
|
||||||
dGroup.removeMember(player, false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
dGroup = getDungeonGroup(eGroup);
|
|
||||||
if (dGroup != null && !dGroup.getMembers().contains(player)) {
|
|
||||||
dGroup.addMember(player);
|
|
||||||
} else {
|
|
||||||
dGroup = createDungeonGroup(eGroup);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (eGroup == null && dGroup != null) {
|
|
||||||
eGroup = getExternalGroup(dGroup);
|
|
||||||
if (eGroup == null) {
|
|
||||||
eGroup = createExternalGroup(dGroup);
|
|
||||||
}
|
|
||||||
if (!isExternalGroupMember(eGroup, player)) {
|
|
||||||
addExternalGroupMember(eGroup, player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns if the player is a member of the external group.
|
* Returns if the player is a member of the external group.
|
||||||
*
|
*
|
||||||
* @param eGroup the external group
|
* @param eGroup the external group
|
||||||
* @param player player
|
* @param player the player
|
||||||
* @return if the player is a member of the external group
|
* @return if the player is a member of the external group
|
||||||
*/
|
*/
|
||||||
public abstract boolean isExternalGroupMember(T eGroup, Player player);
|
public abstract boolean isExternalGroupMember(T eGroup, Player player);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the member to the external group.
|
* Clears the external / dungeon group references.
|
||||||
*
|
|
||||||
* @param eGroup the external group
|
|
||||||
* @param member the member
|
|
||||||
* @return if adding the member was successful
|
|
||||||
*/
|
*/
|
||||||
public abstract boolean addExternalGroupMember(T eGroup, Player member);
|
public void clear() {
|
||||||
|
groups.clear();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the member from the external group.
|
* Removes the external / dungeon group reference from the cache.
|
||||||
*
|
*
|
||||||
* @param eGroup the external group
|
* @param dGroup the DXL group that belongs to an external group.
|
||||||
* @param member the member
|
|
||||||
* @return if removing the player was successful
|
|
||||||
*/
|
*/
|
||||||
public abstract boolean removeExternalGroupMember(T eGroup, Player member);
|
public void removeReference(PlayerGroup dGroup) {
|
||||||
|
groups.remove(dGroup);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,7 @@ public interface PlayerGroup {
|
|||||||
* @param color the color
|
* @param color the color
|
||||||
*/
|
*/
|
||||||
default void setName(Color color) {
|
default void setName(Color color) {
|
||||||
setName(color.toString() + "#" + getId());
|
setName(color.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -243,7 +243,7 @@ public interface PlayerGroup {
|
|||||||
* @param player the player to add
|
* @param player the player to add
|
||||||
*/
|
*/
|
||||||
default void removeMember(Player player) {
|
default void removeMember(Player player) {
|
||||||
addMember(player, true);
|
removeMember(player, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -128,7 +128,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alessiodp.parties</groupId>
|
<groupId>com.alessiodp.parties</groupId>
|
||||||
<artifactId>parties-api</artifactId>
|
<artifactId>parties-api</artifactId>
|
||||||
<version>2.6.14</version>
|
<version>3.1.10</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<repositories>
|
<repositories>
|
||||||
@ -148,5 +148,9 @@
|
|||||||
<id>codemc-repo</id>
|
<id>codemc-repo</id>
|
||||||
<url>https://repo.codemc.org/repository/maven-public/</url>
|
<url>https://repo.codemc.org/repository/maven-public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>alessiodp-repo</id>
|
||||||
|
<url>https://repo.alessiodp.com/releases/</url>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
</project>
|
</project>
|
||||||
|
@ -18,6 +18,7 @@ package de.erethon.dungeonsxl.command;
|
|||||||
|
|
||||||
import de.erethon.dungeonsxl.DungeonsXL;
|
import de.erethon.dungeonsxl.DungeonsXL;
|
||||||
import de.erethon.dungeonsxl.api.event.DataReloadEvent;
|
import de.erethon.dungeonsxl.api.event.DataReloadEvent;
|
||||||
|
import de.erethon.dungeonsxl.api.player.GroupAdapter;
|
||||||
import de.erethon.dungeonsxl.api.player.InstancePlayer;
|
import de.erethon.dungeonsxl.api.player.InstancePlayer;
|
||||||
import de.erethon.dungeonsxl.config.DMessage;
|
import de.erethon.dungeonsxl.config.DMessage;
|
||||||
import de.erethon.dungeonsxl.player.DPermission;
|
import de.erethon.dungeonsxl.player.DPermission;
|
||||||
@ -100,6 +101,7 @@ public class ReloadCommand extends DCommand {
|
|||||||
plugin.initFolders();
|
plugin.initFolders();
|
||||||
plugin.initCaches();
|
plugin.initCaches();
|
||||||
plugin.checkState();
|
plugin.checkState();
|
||||||
|
plugin.getGroupAdapters().forEach(GroupAdapter::clear);
|
||||||
|
|
||||||
MessageUtil.sendPluginTag(sender, plugin);
|
MessageUtil.sendPluginTag(sender, plugin);
|
||||||
MessageUtil.sendCenteredMessage(sender, DMessage.CMD_RELOAD_SUCCESS.getMessage());
|
MessageUtil.sendCenteredMessage(sender, DMessage.CMD_RELOAD_SUCCESS.getMessage());
|
||||||
|
@ -19,6 +19,7 @@ package de.erethon.dungeonsxl.global;
|
|||||||
import de.erethon.caliburn.category.Category;
|
import de.erethon.caliburn.category.Category;
|
||||||
import de.erethon.dungeonsxl.DungeonsXL;
|
import de.erethon.dungeonsxl.DungeonsXL;
|
||||||
import de.erethon.dungeonsxl.api.event.group.GroupCreateEvent.Cause;
|
import de.erethon.dungeonsxl.api.event.group.GroupCreateEvent.Cause;
|
||||||
|
import de.erethon.dungeonsxl.api.player.GroupAdapter;
|
||||||
import de.erethon.dungeonsxl.config.DMessage;
|
import de.erethon.dungeonsxl.config.DMessage;
|
||||||
import de.erethon.dungeonsxl.player.DGroup;
|
import de.erethon.dungeonsxl.player.DGroup;
|
||||||
import de.erethon.dungeonsxl.util.commons.chat.MessageUtil;
|
import de.erethon.dungeonsxl.util.commons.chat.MessageUtil;
|
||||||
@ -163,12 +164,19 @@ public class GroupSign extends JoinSign {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
group = DGroup.create(plugin, Cause.GROUP_SIGN, player, groupName, null, dungeon);
|
for (GroupAdapter adapter : plugin.getGroupAdapters()) {
|
||||||
if (group == null) {
|
if (adapter.isExternalGroupMember(player)) {
|
||||||
return;
|
group = (DGroup) adapter.getOrCreateDungeonGroup(adapter.getExternalGroup(player), maxElements);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (group == null) {
|
||||||
|
group = DGroup.create(plugin, Cause.GROUP_SIGN, player, groupName, null, dungeon);
|
||||||
|
}
|
||||||
|
if (group != null) {
|
||||||
|
group.setDungeon(dungeon);
|
||||||
|
group.setGroupSign(this);
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
group.setGroupSign(this);
|
|
||||||
update();
|
|
||||||
|
|
||||||
} else if (topSign.getLine(0).equals(DMessage.SIGN_GLOBAL_JOIN_GROUP.getMessage())) {
|
} else if (topSign.getLine(0).equals(DMessage.SIGN_GLOBAL_JOIN_GROUP.getMessage())) {
|
||||||
group.addMember(player);
|
group.addMember(player);
|
||||||
|
@ -129,7 +129,10 @@ public class DGroup implements PlayerGroup {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
plugin.getGroupCache().remove(this);
|
||||||
|
untaggedName = name;
|
||||||
|
this.name = name + "#" + id;
|
||||||
|
plugin.getGroupCache().add(name, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUntaggedName() {
|
public String getUntaggedName() {
|
||||||
@ -194,12 +197,6 @@ public class DGroup implements PlayerGroup {
|
|||||||
MessageUtil.sendMessage(player, DMessage.PLAYER_JOIN_GROUP.getMessage());
|
MessageUtil.sendMessage(player, DMessage.PLAYER_JOIN_GROUP.getMessage());
|
||||||
}
|
}
|
||||||
players.add(player.getUniqueId());
|
players.add(player.getUniqueId());
|
||||||
plugin.getGroupAdapters().forEach(a -> a.syncJoin(player));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeMember(Player player) {
|
|
||||||
removeMember(player, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -219,8 +216,6 @@ public class DGroup implements PlayerGroup {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getGroupAdapters().forEach(a -> a.removeExternalGroupMember(a.getExternalGroup(player), player));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -552,8 +547,7 @@ public class DGroup implements PlayerGroup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
plugin.getGlobalProtectionCache().updateGroupSigns(this);
|
plugin.getGlobalProtectionCache().updateGroupSigns(this);
|
||||||
|
plugin.getGroupAdapters().forEach(a -> a.removeReference(this));
|
||||||
plugin.getGroupAdapters().forEach(a -> a.deleteCorrespondingGroup(this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkStartGame(Game game) {
|
public boolean checkStartGame(Game game) {
|
||||||
|
@ -17,9 +17,8 @@
|
|||||||
package de.erethon.dungeonsxl.player.groupadapter;
|
package de.erethon.dungeonsxl.player.groupadapter;
|
||||||
|
|
||||||
import com.alessiodp.parties.api.Parties;
|
import com.alessiodp.parties.api.Parties;
|
||||||
import com.alessiodp.parties.api.events.bukkit.party.BukkitPartiesPartyPostCreateEvent;
|
|
||||||
import com.alessiodp.parties.api.events.bukkit.party.BukkitPartiesPartyPreDeleteEvent;
|
import com.alessiodp.parties.api.events.bukkit.party.BukkitPartiesPartyPreDeleteEvent;
|
||||||
import com.alessiodp.parties.api.events.bukkit.party.BukkitPartiesPartyRenameEvent;
|
import com.alessiodp.parties.api.events.bukkit.party.BukkitPartiesPartyPreRenameEvent;
|
||||||
import com.alessiodp.parties.api.events.bukkit.player.BukkitPartiesPlayerPostJoinEvent;
|
import com.alessiodp.parties.api.events.bukkit.player.BukkitPartiesPlayerPostJoinEvent;
|
||||||
import com.alessiodp.parties.api.events.bukkit.player.BukkitPartiesPlayerPostLeaveEvent;
|
import com.alessiodp.parties.api.events.bukkit.player.BukkitPartiesPlayerPostLeaveEvent;
|
||||||
import com.alessiodp.parties.api.interfaces.PartiesAPI;
|
import com.alessiodp.parties.api.interfaces.PartiesAPI;
|
||||||
@ -28,11 +27,6 @@ import com.alessiodp.parties.api.interfaces.PartyPlayer;
|
|||||||
import de.erethon.dungeonsxl.api.DungeonsAPI;
|
import de.erethon.dungeonsxl.api.DungeonsAPI;
|
||||||
import de.erethon.dungeonsxl.api.player.GroupAdapter;
|
import de.erethon.dungeonsxl.api.player.GroupAdapter;
|
||||||
import de.erethon.dungeonsxl.api.player.PlayerGroup;
|
import de.erethon.dungeonsxl.api.player.PlayerGroup;
|
||||||
import de.erethon.dungeonsxl.config.DMessage;
|
|
||||||
import de.erethon.dungeonsxl.util.commons.chat.MessageUtil;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.UUID;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -49,38 +43,33 @@ public class PartiesAdapter extends GroupAdapter<Party> implements Listener {
|
|||||||
private PartiesAPI partiesAPI;
|
private PartiesAPI partiesAPI;
|
||||||
|
|
||||||
public PartiesAdapter(DungeonsAPI api) {
|
public PartiesAdapter(DungeonsAPI api) {
|
||||||
super(api, Philosophy.PERSISTENT);
|
super(api);
|
||||||
Bukkit.getPluginManager().registerEvents(this, api);
|
Bukkit.getPluginManager().registerEvents(this, api);
|
||||||
partiesAPI = Parties.getApi();
|
partiesAPI = Parties.getApi();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Party createExternalGroup(PlayerGroup dGroup) {
|
|
||||||
if (!partiesAPI.createParty(dGroup.getRawName(), partiesAPI.getPartyPlayer(dGroup.getLeader().getUniqueId()))) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Party eGroup = partiesAPI.getParty(dGroup.getRawName());
|
|
||||||
groups.put(dGroup, new ExternalGroupData<>(eGroup, true));
|
|
||||||
return eGroup;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlayerGroup createDungeonGroup(Party eGroup) {
|
public PlayerGroup createDungeonGroup(Party eGroup) {
|
||||||
PlayerGroup dGroup = dxl.createGroup(Bukkit.getPlayer(eGroup.getLeader()), eGroup.getName());
|
PlayerGroup dGroup = dxl.createGroup(Bukkit.getPlayer(eGroup.getLeader()), eGroup.getName());
|
||||||
eGroup.getMembers().forEach(uuid -> dGroup.addMember(Bukkit.getPlayer(uuid), false));
|
eGroup.getOnlineMembers().forEach(p -> dGroup.addMember(Bukkit.getPlayer(p.getPlayerUUID()), false));
|
||||||
groups.put(dGroup, new ExternalGroupData<>(eGroup, false));
|
groups.put(dGroup, eGroup);
|
||||||
return dGroup;
|
return dGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Party getExternalGroup(Player member) {
|
public Party getExternalGroup(Player member) {
|
||||||
PartyPlayer pPlayer = getPartyPlayer(member);
|
PartyPlayer pPlayer = partiesAPI.getPartyPlayer(member.getUniqueId());
|
||||||
if (pPlayer == null) {
|
if (pPlayer == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return partiesAPI.getParty(pPlayer.getPartyName());
|
return partiesAPI.getParty(pPlayer.getPartyName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getGroupOnlineSize(Party eGroup) {
|
||||||
|
return eGroup.getOnlineMembers().size();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isExternalGroupMember(Party eGroup, Player player) {
|
public boolean isExternalGroupMember(Party eGroup, Player player) {
|
||||||
if (eGroup == null) {
|
if (eGroup == null) {
|
||||||
@ -89,86 +78,22 @@ public class PartiesAdapter extends GroupAdapter<Party> implements Listener {
|
|||||||
return eGroup.getMembers().contains(player.getUniqueId());
|
return eGroup.getMembers().contains(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean addExternalGroupMember(Party eGroup, Player member) {
|
|
||||||
return eGroup.addMember(getPartyPlayer(member));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean removeExternalGroupMember(Party eGroup, Player member) {
|
|
||||||
PartyPlayer pPlayer = getPartyPlayer(member);
|
|
||||||
if (pPlayer == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (eGroup == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
eGroup.removeMember(pPlayer);
|
|
||||||
if (eGroup.getMembers().isEmpty()) {
|
|
||||||
eGroup.delete();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean deleteCorrespondingGroup(PlayerGroup dGroup) {
|
|
||||||
ExternalGroupData<Party> data = groups.get(dGroup);
|
|
||||||
if (data == null || !data.isCreatedByDXL()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
data.get().delete();
|
|
||||||
groups.remove(dGroup);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean areSimilar(PlayerGroup dGroup, Party eGroup) {
|
|
||||||
if (dGroup == null || eGroup == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Collection<UUID> members = new ArrayList<>(dGroup.getMembers().getUniqueIds());
|
|
||||||
for (UUID member : eGroup.getMembers()) {
|
|
||||||
if (!members.contains(member)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
members.remove(member);
|
|
||||||
}
|
|
||||||
return members.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onCreation(BukkitPartiesPartyPostCreateEvent event) {
|
|
||||||
// Event is called asynchronously
|
|
||||||
new BukkitRunnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
createDungeonGroup(event.getParty());
|
|
||||||
}
|
|
||||||
}.runTask(dxl);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onDeletion(BukkitPartiesPartyPreDeleteEvent event) {
|
public void onDeletion(BukkitPartiesPartyPreDeleteEvent event) {
|
||||||
PlayerGroup dGroup = getDungeonGroup(event.getParty());
|
PlayerGroup dGroup = getDungeonGroup(event.getParty());
|
||||||
if (dGroup != null) {
|
if (dGroup != null) {
|
||||||
groups.remove(dGroup); // This avoids circular deleting of groups
|
groups.remove(dGroup);
|
||||||
dGroup.delete();
|
dGroup.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onRename(BukkitPartiesPartyRenameEvent event) {
|
public void onRename(BukkitPartiesPartyPreRenameEvent event) {
|
||||||
PlayerGroup dGroup = getDungeonGroup(event.getParty());
|
PlayerGroup group = getDungeonGroup(event.getParty());
|
||||||
if (dGroup != null) {
|
if (group == null) {
|
||||||
dGroup.delete();
|
|
||||||
}
|
|
||||||
if (dxl.getGroupCache().get(event.getNewPartyName()) != null) {
|
|
||||||
MessageUtil.sendMessage(getPlayer(event.getPartyPlayer()), DMessage.ERROR_NAME_IN_USE.getMessage(event.getNewPartyName()));
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
dGroup.setName(event.getNewPartyName());
|
group.setName(event.getNewPartyName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -176,7 +101,11 @@ public class PartiesAdapter extends GroupAdapter<Party> implements Listener {
|
|||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
syncJoin(getPlayer(event.getPartyPlayer()));
|
PlayerGroup group = getDungeonGroup(event.getParty());
|
||||||
|
if (group == null || group.isPlaying()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
group.addMember(getPlayer(event.getPartyPlayer()), false);
|
||||||
}
|
}
|
||||||
}.runTask(dxl);
|
}.runTask(dxl);
|
||||||
}
|
}
|
||||||
@ -186,11 +115,11 @@ public class PartiesAdapter extends GroupAdapter<Party> implements Listener {
|
|||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Player player = getPlayer(event.getPartyPlayer());
|
PlayerGroup group = getDungeonGroup(event.getParty());
|
||||||
PlayerGroup group = dxl.getPlayerGroup(player);
|
if (group == null || group.isPlaying()) {
|
||||||
if (group != null) {
|
return;
|
||||||
group.removeMember(player);
|
|
||||||
}
|
}
|
||||||
|
group.removeMember(getPlayer(event.getPartyPlayer()), false);
|
||||||
}
|
}
|
||||||
}.runTask(dxl);
|
}.runTask(dxl);
|
||||||
}
|
}
|
||||||
@ -199,8 +128,4 @@ public class PartiesAdapter extends GroupAdapter<Party> implements Listener {
|
|||||||
return Bukkit.getPlayer(player.getPlayerUUID());
|
return Bukkit.getPlayer(player.getPlayerUUID());
|
||||||
}
|
}
|
||||||
|
|
||||||
private PartyPlayer getPartyPlayer(Player player) {
|
|
||||||
return partiesAPI.getPartyPlayer(player.getUniqueId());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user