-
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.
- Separated all functions in classes - Fixed the counter who used Thread.sleep()
- Loading branch information
Showing
10 changed files
with
633 additions
and
486 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package fr.ezzud.hunting.management; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
import java.util.function.Consumer; | ||
|
||
// Thanks to https://www.spigotmc.org/members/expdev.174734/ | ||
|
||
public class CountdownTimer implements Runnable { | ||
|
||
private JavaPlugin plugin; | ||
|
||
private Integer assignedTaskId; | ||
|
||
private int seconds; | ||
private int secondsLeft; | ||
|
||
private Consumer<CountdownTimer> everySecond; | ||
private Runnable beforeTimer; | ||
private Runnable afterTimer; | ||
|
||
public CountdownTimer(JavaPlugin plugin, int seconds, | ||
Runnable beforeTimer, Runnable afterTimer, | ||
Consumer<CountdownTimer> everySecond) { | ||
this.plugin = plugin; | ||
|
||
this.seconds = seconds; | ||
this.secondsLeft = seconds; | ||
|
||
this.beforeTimer = beforeTimer; | ||
this.afterTimer = afterTimer; | ||
this.everySecond = everySecond; | ||
} | ||
|
||
|
||
@Override | ||
public void run() { | ||
if (secondsLeft < 1) { | ||
afterTimer.run(); | ||
|
||
if (assignedTaskId != null) Bukkit.getScheduler().cancelTask(assignedTaskId); | ||
return; | ||
} | ||
|
||
if (secondsLeft == seconds) beforeTimer.run(); | ||
|
||
everySecond.accept(this); | ||
|
||
secondsLeft--; | ||
} | ||
|
||
|
||
public int getTotalSeconds() { | ||
return seconds; | ||
} | ||
|
||
public int getSecondsLeft() { | ||
return secondsLeft; | ||
} | ||
|
||
public void scheduleTimer() { | ||
this.assignedTaskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, this, 0L, 20L); | ||
} | ||
|
||
} |
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,67 @@ | ||
package fr.ezzud.hunting.management; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.entity.Player; | ||
|
||
import fr.ezzud.hunting.Main; | ||
|
||
public class colorManager { | ||
static Main plugin = Main.getInstance(); | ||
public static void setColors() { | ||
ArrayList<?> list2 = new ArrayList<>(Bukkit.getOnlinePlayers()); | ||
list2.forEach((p) -> { | ||
Player player = ((Player) p); | ||
|
||
|
||
|
||
Iterator<?> team1Var = plugin.getConfig().getStringList("team1").iterator(); | ||
|
||
while(team1Var.hasNext()) { | ||
String member = (String)team1Var.next(); | ||
if(member.equals(player.getName())) { | ||
player.setDisplayName(plugin.getConfig().getString("team1Color").replaceAll("&", "§") + player.getName() + ChatColor.RESET); | ||
player.setPlayerListName(plugin.getConfig().getString("team1Color").replaceAll("&", "§") + player.getName() + ChatColor.RESET); | ||
} | ||
} | ||
|
||
Iterator<?> team2Var = plugin.getConfig().getStringList("team2").iterator(); | ||
|
||
while(team2Var.hasNext()) { | ||
String member = (String)team2Var.next(); | ||
if(member.equals(player.getName())) { | ||
player.setDisplayName(plugin.getConfig().getString("team2Color").replaceAll("&", "§") + player.getName() + ChatColor.RESET); | ||
player.setPlayerListName(plugin.getConfig().getString("team2Color").replaceAll("&", "§") + player.getName() + ChatColor.RESET); | ||
} | ||
} | ||
|
||
String teamHVar = plugin.getConfig().getString("hunted"); | ||
if(teamHVar.equals(player.getName())) { | ||
player.setDisplayName(plugin.getConfig().getString("huntedColor").replaceAll("&", "§") + player.getName() + ChatColor.RESET); | ||
player.setPlayerListName(plugin.getConfig().getString("huntedColor").replaceAll("&", "§") + player.getName() + ChatColor.RESET); | ||
} | ||
|
||
Iterator<?> teamGVar = plugin.getConfig().getStringList("guards").iterator(); | ||
|
||
while(teamGVar.hasNext()) { | ||
String member = (String)teamGVar.next(); | ||
if(member.equals(player.getName())) { | ||
player.setDisplayName(ChatColor.GOLD + player.getName() + ChatColor.RESET); | ||
player.setPlayerListName(plugin.getConfig().getString("guardColor").replaceAll("&", "§") + player.getName() + ChatColor.RESET); | ||
} | ||
} | ||
Iterator<?> teamSVar = plugin.getConfig().getStringList("spectators").iterator(); | ||
|
||
while(teamSVar.hasNext()) { | ||
String member = (String)teamSVar.next(); | ||
if(member.equals(player.getName())) { | ||
player.setDisplayName(plugin.getConfig().getString("spectatorColor").replaceAll("&", "§") + player.getName() + ChatColor.RESET); | ||
player.setPlayerListName(plugin.getConfig().getString("spectatorColor").replaceAll("&", "§") + player.getName() + ChatColor.RESET); | ||
} | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.