|
1 | 1 | import net.dv8tion.jda.api.JDA; |
2 | 2 | import net.dv8tion.jda.api.Permission; |
3 | 3 | import net.dv8tion.jda.api.entities.*; |
| 4 | +import net.dv8tion.jda.api.entities.channel.ChannelType; |
| 5 | +import net.dv8tion.jda.api.entities.channel.concrete.Category; |
| 6 | +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; |
| 7 | +import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel; |
| 8 | +import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; |
| 9 | +import net.dv8tion.jda.api.events.guild.GuildLeaveEvent; |
4 | 10 | import net.dv8tion.jda.api.events.guild.voice.*; |
| 11 | +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; |
5 | 12 | import net.dv8tion.jda.api.events.message.MessageReceivedEvent; |
6 | 13 | import net.dv8tion.jda.api.hooks.ListenerAdapter; |
7 | 14 | import net.dv8tion.jda.api.requests.restaction.ChannelAction; |
@@ -298,75 +305,82 @@ else if (content.startsWith(prefix + "setup")){ |
298 | 305 | } |
299 | 306 |
|
300 | 307 | @Override |
301 | | - public void onGuildVoiceJoin(GuildVoiceJoinEvent event){ |
302 | | - handleJoin(event); |
303 | | - } |
304 | | - |
305 | | - @Override |
306 | | - public void onGuildVoiceLeave(@NotNull GuildVoiceLeaveEvent event) { |
307 | | - handleLeft(event); |
308 | | - } |
309 | | - |
310 | | - @Override |
311 | | - public void onGuildVoiceMove(@NotNull GuildVoiceMoveEvent event) { |
312 | | - System.out.println("Moved from "+event.getChannelLeft().getName() + " to "+event.getChannelJoined().getName()); |
313 | | - handleJoin(event); |
314 | | - handleLeft(event); |
| 308 | + public void onGuildVoiceUpdate(@NotNull GuildVoiceUpdateEvent event) { |
| 309 | + //if left |
| 310 | + if (event.getChannelLeft() != null && event.getChannelJoined() == null){ |
| 311 | + handleLeft(event); |
| 312 | + } |
| 313 | + //if joined |
| 314 | + else if (event.getChannelLeft() == null && event.getChannelJoined() != null){ |
| 315 | + handleJoin(event); |
| 316 | + } |
| 317 | + //if moved |
| 318 | + else if (event.getChannelLeft() != null && event.getChannelJoined() != null){ |
| 319 | + if (!event.getChannelLeft().equals(event.getChannelJoined())){ |
| 320 | + handleLeft(event); |
| 321 | + handleJoin(event); |
| 322 | + } |
| 323 | + } |
| 324 | + super.onGuildVoiceUpdate(event); |
315 | 325 | } |
316 | 326 |
|
317 | | - public void handleJoin(GenericGuildVoiceUpdateEvent event){ |
318 | | - VoiceChannel vc = event.getChannelJoined(); |
319 | | - int usersInVC = vc.getMembers().size(); |
320 | | - if (usersInVC == 1){ |
321 | | - if (tmpChannelList.contains(vc)){ |
322 | | - VoiceChannel master = tmpChannelMapMaster.get(vc); |
323 | | - createTmpChannel(event.getGuild(), masterNames.get(master),tmpChannelCount.get(master)+1,vc.getPosition(),vc.getUserLimit(),master,vc.getParent(),vc.getBitrate()); |
324 | | - tmpChannelCount.put(master,tmpChannelCount.get(master)+1); |
325 | | - }else if (tmpMasterChannelList.contains(vc) && tmpChannelCount.get(vc) == 0){ |
326 | | - createTmpChannel(event.getGuild(), vc.getName(),1,vc.getPosition(),vc.getUserLimit(),vc,vc.getParent(),vc.getBitrate()); |
327 | | - tmpChannelCount.put(vc,1); |
| 327 | + public void handleJoin(GuildVoiceUpdateEvent event){ |
| 328 | + if (event.getChannelJoined() != null){ |
| 329 | + VoiceChannel vc = event.getChannelJoined().asVoiceChannel(); |
| 330 | + int usersInVC = vc.getMembers().size(); |
| 331 | + if (usersInVC == 1){ |
| 332 | + if (tmpChannelList.contains(vc)){ |
| 333 | + VoiceChannel master = tmpChannelMapMaster.get(vc); |
| 334 | + createTmpChannel(event.getGuild(), masterNames.get(master),tmpChannelCount.get(master)+1,vc.getPosition(),vc.getUserLimit(),master,vc.getParentCategory(),vc.getBitrate()); |
| 335 | + tmpChannelCount.put(master,tmpChannelCount.get(master)+1); |
| 336 | + }else if (tmpMasterChannelList.contains(vc) && tmpChannelCount.get(vc) == 0){ |
| 337 | + createTmpChannel(event.getGuild(), vc.getName(),1,vc.getPosition(),vc.getUserLimit(),vc,vc.getParentCategory(),vc.getBitrate()); |
| 338 | + tmpChannelCount.put(vc,1); |
| 339 | + } |
328 | 340 | } |
329 | 341 | } |
330 | 342 | } |
331 | 343 |
|
332 | | - public void handleLeft(GenericGuildVoiceUpdateEvent event){ |
333 | | - VoiceChannel vc = event.getChannelLeft(); |
334 | | - int usersInVC = vc.getMembers().size(); |
335 | | - if (vc.getMembers().size() <= 0){ |
336 | | - if (tmpChannelList.contains(vc)){ |
337 | | - VoiceChannel master = tmpChannelMapMaster.get(vc); |
338 | | - int count = tmpChannelCount.get(master); |
339 | | - count--; |
340 | | - String name = vc.getName(); |
341 | | - int pos = Integer.parseInt(name.split(";")[1]); |
342 | | - if (count <= 0){ |
343 | | - if (!isSomeoneInChannel(master)){ |
| 344 | + public void handleLeft(GuildVoiceUpdateEvent event){ |
| 345 | + if (event.getChannelLeft() != null){ |
| 346 | + VoiceChannel vc = event.getChannelLeft().asVoiceChannel(); |
| 347 | + int usersInVC = vc.getMembers().size(); |
| 348 | + if (vc.getMembers().size() <= 0){ |
| 349 | + if (tmpChannelList.contains(vc)){ |
| 350 | + VoiceChannel master = tmpChannelMapMaster.get(vc); |
| 351 | + int count = tmpChannelCount.get(master); |
| 352 | + count--; |
| 353 | + String name = vc.getName(); |
| 354 | + int pos = Integer.parseInt(name.split(";")[1]); |
| 355 | + if (count <= 0){ |
| 356 | + if (!isSomeoneInChannel(master)){ |
| 357 | + deleteChannel(vc); |
| 358 | + tmpChannelCount.put(master, 0); |
| 359 | + } |
| 360 | + }else if(pos <= count){ |
344 | 361 | deleteChannel(vc); |
345 | | - tmpChannelCount.put(master, 0); |
346 | | - } |
347 | | - }else if(pos <= count){ |
348 | | - deleteChannel(vc); |
349 | | - tmpChannelCount.put(master, count); |
350 | | - List<VoiceChannel> tmpChannelListClone = new ArrayList<>(tmpChannelList);; |
351 | | - for (VoiceChannel vcTmp : tmpChannelListClone){ |
352 | | - if (tmpChannelMapMaster.get(vcTmp) == master){ |
353 | | - if (count == 1 && !isSomeoneInChannel(master)){ |
354 | | - tmpChannelCount.put(master, 0); |
355 | | - deleteChannel(vcTmp); |
356 | | - }else { |
357 | | - int tmppos = Integer.parseInt(vcTmp.getName().split(";")[1]); |
358 | | - tmppos--; |
359 | | - vcTmp.getManager().setName("⏰;"+tmppos+";"+masterNames.get(master)).queue(); |
| 362 | + tmpChannelCount.put(master, count); |
| 363 | + List<VoiceChannel> tmpChannelListClone = new ArrayList<>(tmpChannelList);; |
| 364 | + for (VoiceChannel vcTmp : tmpChannelListClone){ |
| 365 | + if (tmpChannelMapMaster.get(vcTmp) == master){ |
| 366 | + if (count == 1 && !isSomeoneInChannel(master)){ |
| 367 | + tmpChannelCount.put(master, 0); |
| 368 | + deleteChannel(vcTmp); |
| 369 | + }else { |
| 370 | + int tmppos = Integer.parseInt(vcTmp.getName().split(";")[1]); |
| 371 | + tmppos--; |
| 372 | + vcTmp.getManager().setName("⏰;"+tmppos+";"+masterNames.get(master)).queue(); |
| 373 | + } |
360 | 374 | } |
361 | 375 | } |
362 | 376 | } |
363 | | - } |
364 | | - }else if(tmpMasterChannelList.contains(vc) && tmpChannelCount.get(vc) <= 1){ |
365 | | - List<VoiceChannel> tmpChannelListClone = new ArrayList<>(tmpChannelList); |
366 | | - for (VoiceChannel vc2 : tmpChannelListClone){ |
367 | | - if (tmpChannelMapMaster.get(vc2) == vc){ |
368 | | - deleteChannel(vc2); |
369 | | - tmpChannelCount.put(vc, 0); |
| 377 | + }else if(tmpMasterChannelList.contains(vc) && tmpChannelCount.get(vc) <= 1){ |
| 378 | + List<VoiceChannel> tmpChannelListClone = new ArrayList<>(tmpChannelList); |
| 379 | + for (VoiceChannel vc2 : tmpChannelListClone){ |
| 380 | + if (tmpChannelMapMaster.get(vc2) == vc){ |
| 381 | + deleteChannel(vc2); |
| 382 | + tmpChannelCount.put(vc, 0); |
| 383 | + } |
370 | 384 | } |
371 | 385 | } |
372 | 386 | } |
@@ -405,7 +419,7 @@ public void deleteAllTmpChannels(Guild guild){ |
405 | 419 | public void checkMasterChannels(){ |
406 | 420 | for (VoiceChannel vc : tmpMasterChannelList){ |
407 | 421 | if (vc.getMembers().size() > 0){ |
408 | | - createTmpChannel(vc.getGuild(), vc.getName(),1,vc.getPosition(),vc.getUserLimit(),vc,vc.getParent(),vc.getBitrate()); |
| 422 | + createTmpChannel(vc.getGuild(), vc.getName(),1,vc.getPosition(),vc.getUserLimit(),vc,vc.getParentCategory(),vc.getBitrate()); |
409 | 423 | tmpChannelCount.put(vc,1); |
410 | 424 | } |
411 | 425 | } |
|
0 commit comments