Skip to content

Commit

Permalink
Merge pull request #2 from thejames10/reduce-queue-attempt
Browse files Browse the repository at this point in the history
Reduce queue attempt
  • Loading branch information
thejames10 authored Apr 7, 2021
2 parents 2ca6156 + 86acf13 commit 34bf78a
Show file tree
Hide file tree
Showing 5 changed files with 551 additions and 87 deletions.
Binary file modified server/plugins/TownyDiscordChat-1.0-SNAPSHOT.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import github.scarsz.discordsrv.api.Subscribe;
import github.scarsz.discordsrv.api.events.AccountLinkedEvent;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class TDCDiscordSRVListener {

Expand All @@ -19,12 +22,9 @@ public void accountLinked(AccountLinkedEvent event) {
return;
}

Player player = offlinePlayer.getPlayer();
if (player == null)
return;

TDCManager.givePlayerTownRole(player);
TDCManager.givePlayerNationRole(player);
String discordId = event.getUser().getId();
UUID UUID = offlinePlayer.getUniqueId();

TDCManager.discordUserRoleCheck(discordId, UUID);
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package com.TownyDiscordChat.TownyDiscordChat.Listeners;

import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.Timer;

import com.TownyDiscordChat.TownyDiscordChat.Main;
import com.TownyDiscordChat.TownyDiscordChat.TDCManager;
import com.palmergames.bukkit.towny.event.*;
import com.palmergames.bukkit.towny.object.Resident;

import github.scarsz.discordsrv.api.events.AccountLinkedEvent;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

Expand All @@ -33,7 +29,21 @@ public void onNewDay(NewDayEvent event) {

System.out.println("NewDayEvent fired!");

TDCManager.checkAllLinkedPlayers();
TDCManager.discordRoleChannelCreationCheckAllTownsAllNations();

Timer t = new java.util.Timer();
t.schedule(
new java.util.TimerTask() {
@Override
public void run() {
System.out.println("Running delayed task...");
TDCManager.discordUserRoleCheckAllLinked();
//t.cancel();
}
},
300000

);
}

@EventHandler
Expand All @@ -42,6 +52,8 @@ public void onPlayerJoinTown(TownAddResidentEvent event) {
System.out.println("TownAddResidentEvent fired!");

TDCManager.givePlayerRole(event.getResident().getPlayer(), event.getTown());

// Need to check if town also has a nation and add the player to the nation role / channels as well
}

@EventHandler
Expand All @@ -50,6 +62,8 @@ public void onPlayerLeaveTown(TownRemoveResidentEvent event) {
System.out.println("TownRemoveResidentEvent fired!");

TDCManager.removePlayerRole(event.getResident().getPlayer(), event.getTown());

// Need to check if town also has a nation and remove the player from the nation role / channels as well
}

@EventHandler
Expand All @@ -75,6 +89,7 @@ public void onTownLeaveNation(NationRemoveTownEvent event) {
for (Resident townResident : townResidents) {
TDCManager.removePlayerRole(townResident.getPlayer(), event.getTown());
}
// Need to check if town also has a nation and remove the players from the nation role / channels as well
}

@EventHandler
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
package com.TownyDiscordChat.TownyDiscordChat;

import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.TownyUniverse;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Town;
import github.scarsz.discordsrv.DiscordSRV;
import github.scarsz.discordsrv.dependencies.jda.api.entities.Guild;
import github.scarsz.discordsrv.util.DiscordUtil;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.Map;
import java.util.UUID;
import java.util.Timer;

public class TDCCommand implements CommandExecutor {

Expand All @@ -27,8 +15,6 @@ public boolean onCommand(@NotNull final CommandSender sender, @NotNull final Com
if (!(sender instanceof Player))
return true;

TDCManager.checkAllLinkedPlayers();

return true;
}
}
Loading

0 comments on commit 34bf78a

Please sign in to comment.