Skip to content

Commit 53ef919

Browse files
committed
provide PacketEvents user when clearing a dialog
1 parent b305abc commit 53ef919

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

packetevents/src/main/java/io/github/projectunified/unidialog/packetevents/PocketEventsDialogManager.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,17 +159,35 @@ public void unregisterAllCustomActions() {
159159
actions.clear();
160160
}
161161

162+
/**
163+
* Clear the dialog for a user, optionally specifying if it is a configuration dialog.
164+
*
165+
* @param user the user to clear the dialog for
166+
* @param configuration if true, clears as a configuration dialog; if false, clears as a play dialog
167+
*/
168+
public void clearDialog(User user, boolean configuration) {
169+
WrapperCommonServerClearDialog<?> wrapper = configuration
170+
? new WrapperConfigServerClearDialog()
171+
: new WrapperPlayServerClearDialog();
172+
user.sendPacket(wrapper);
173+
}
174+
175+
/**
176+
* Clear the dialog for a user, automatically determining if it is a configuration dialog based on the user's connection state.
177+
*
178+
* @param user the user to clear the dialog for
179+
*/
180+
public void clearDialog(User user) {
181+
clearDialog(user, user.getConnectionState() == ConnectionState.CONFIGURATION);
182+
}
183+
162184
@Override
163185
public boolean clearDialog(UUID uuid) {
164186
Object player = getPlayer(uuid);
165187
if (player == null) return false;
166188

167189
User user = PacketEvents.getAPI().getPlayerManager().getUser(player);
168-
WrapperCommonServerClearDialog<?> wrapper = user.getConnectionState() == ConnectionState.CONFIGURATION
169-
? new WrapperConfigServerClearDialog()
170-
: new WrapperPlayServerClearDialog();
171-
172-
PacketEvents.getAPI().getPlayerManager().sendPacket(player, wrapper);
190+
clearDialog(user);
173191
return true;
174192
}
175193
}

0 commit comments

Comments
 (0)