Skip to content

Commit ec28b2e

Browse files
committed
feat(sort): add permissible sort
1 parent 8f56e9d commit ec28b2e

5 files changed

Lines changed: 15 additions & 4 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
}
88

99
group = 'com.nextplugins'
10-
version = '1.0.0'
10+
version = '1.0.1'
1111

1212
tasks.build.dependsOn('shadowJar')
1313

src/main/java/com/nextplugins/sorteios/api/prize/Prize.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
public class Prize {
1616

1717
private final String coloredName;
18+
private final String sortBanPermission;
1819
private final List<String> commands;
1920

2021
}

src/main/java/com/nextplugins/sorteios/executor/SelectWinnerExecutor.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
import org.bukkit.entity.Player;
1010
import org.bukkit.plugin.PluginManager;
1111

12+
import java.util.List;
1213
import java.util.Random;
14+
import java.util.stream.Collectors;
1315

1416
/**
1517
* @author Yuhtin
@@ -25,12 +27,18 @@ public final class SelectWinnerExecutor implements Runnable {
2527
public void run() {
2628
PrizeManager prizeManager = NextSorteios.getInstance().getPrizeManager();
2729

28-
int randomNumberPlayer = RANDOM.nextInt(Bukkit.getOnlinePlayers().size());
2930
int randomNumberPrizes = RANDOM.nextInt(prizeManager.getPrizes().size());
3031

31-
Player player = (Player) Bukkit.getOnlinePlayers().toArray()[randomNumberPlayer];
3232
Prize prize = prizeManager.getPrizes().get(randomNumberPrizes);
3333

34+
final List<Player> onlinePlayers = Bukkit.getOnlinePlayers()
35+
.stream()
36+
.filter(value -> !value.hasPermission(prize.getSortBanPermission()))
37+
.collect(Collectors.toList());
38+
39+
int randomNumberPlayer = RANDOM.nextInt(onlinePlayers.size());
40+
Player player = (Player) onlinePlayers.toArray()[randomNumberPlayer];
41+
3442
if (player == null || prize == null) return;
3543

3644
PluginManager pluginManager = Bukkit.getPluginManager();

src/main/java/com/nextplugins/sorteios/parser/PrizeParser.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public final class PrizeParser {
1818

1919
public List<Prize> parseListSection(ConfigurationSection section) {
2020

21-
if (section == null) NextSorteios.getInstance().getLogger().info("foda");
21+
if (section == null) throw new IllegalArgumentException("Section inexistente!");
2222

2323
return section.getKeys(false)
2424
.stream()
@@ -34,6 +34,7 @@ public Prize parseSection(ConfigurationSection section) {
3434
return Prize.builder()
3535
.coloredName(ColorUtils.colored(section.getString("coloredName")))
3636
.commands(section.getStringList("commands"))
37+
.sortBanPermission(section.getString("cantSortPermission", "nextsorteios.sort"))
3738
.build();
3839

3940
}

src/main/resources/prizes.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
premios:
22
premio1:
33
coloredName: '&95x Key NextPlugins'
4+
cantSortPermission: sort.ban.premio1
45
commands:
56
- 'givekey @player nextplugins 5'
67
- 'give @player diamond_pickaxe'

0 commit comments

Comments
 (0)