-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implemented reloading mechanic for team menus to reload to everyone a…
…fter a change; implemented that a deleted team can not be opened
- Loading branch information
1 parent
ce16f52
commit 4c35fc6
Showing
7 changed files
with
80 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/de/j/stationofdoom/teams/TeamInventoryReload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package de.j.stationofdoom.teams; | ||
|
||
import de.j.deathMinigames.settings.GUI; | ||
import de.j.stationofdoom.main.Main; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.inventory.InventoryOpenEvent; | ||
import org.bukkit.inventory.Inventory; | ||
import org.bukkit.scheduler.BukkitRunnable; | ||
|
||
public class TeamInventoryReload implements Listener { | ||
private static final int secondsBetweenReloads = 1; | ||
|
||
@EventHandler | ||
public void onInventoryOpen(InventoryOpenEvent event) { | ||
if(event.getInventory().getHolder() instanceof TeamsMainMenuGUI || event.getInventory().getHolder() instanceof TeamSettingsGUI) { | ||
GUI gui = (GUI) event.getInventory().getHolder(); | ||
Player viewer = (Player) event.getPlayer(); | ||
Inventory inv = event.getInventory(); | ||
startTimer(inv, gui, viewer); | ||
} | ||
} | ||
|
||
private void startTimer(Inventory inv, GUI gui, Player viewer) { | ||
new BukkitRunnable() { | ||
@Override | ||
public void run() { | ||
if(!inv.getViewers().contains(viewer)) { | ||
cancel(); | ||
} | ||
else { | ||
int currentPage = inv.getItem(53).getAmount() - 1; | ||
if(gui instanceof TeamsMainMenuGUI teamsMainMenuGUI) { | ||
teamsMainMenuGUI.showPage(currentPage, viewer); | ||
} | ||
else if(gui instanceof TeamSettingsGUI teamSettingsGUI) { | ||
teamSettingsGUI.showPage(currentPage, viewer); | ||
} | ||
cancel(); | ||
} | ||
} | ||
}.runTaskTimer(Main.getPlugin(), 10, secondsBetweenReloads * 20); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters