Skip to content

Commit

Permalink
Fixed error in thedragon with guardians generation
Browse files Browse the repository at this point in the history
  • Loading branch information
r3back committed Jun 22, 2023
1 parent db8d350 commit a0c3c67
Show file tree
Hide file tree
Showing 35 changed files with 218 additions and 133 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
*/*/*/build
*/*/*/*/build
/all-generated
/test-suite/mc-config/*
!/test-suite/mc-config/plugins
/test-suite/mc-config/plugins/*
!/test-suite/mc-config/plugins/TheAssistant-3.2.7.jar
!/test-suite/mc-config/plugins/TheAssistant.jar
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class PluginMessages extends OkaeriConfig {
private String successfullyReloaded = "&aPlugin has been reloaded successfully!";
private String invalidPlayer = "&cInvalid Player!";
private String useSyntax = "&cUsage: %usage%!";
private String noPermission = "&ecYou don't have permission to do that!";
private String noPermission = "&eYou don't have permission to do that!";
private String unknownCommand = "&cUnknown command!";
private String mustBeAPlayer = "&cYou must be a player to do that!";
private String invalidArguments = "&cInvalid Arguments!";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;

import java.util.Optional;

/**
* Alchemist Stand GUI
*/
Expand Down Expand Up @@ -63,7 +65,7 @@ public void onInventoryClose(final InventoryCloseEvent e) {
return;
}

this.standService.removeSession(this.alchemistStandManager.getLocation());
Optional.ofNullable(this.standService).ifPresent(this::removeSession);
}


Expand Down Expand Up @@ -97,4 +99,8 @@ public void onInventoryClick(final InventoryClickEvent e) {

this.alchemistStandManager.check(player);
}

private void removeSession(final StandService standService) {
standService.removeSession(this.alchemistStandManager.getLocation());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class PluginMessages extends OkaeriConfig {
public String invalidPlayer = "&cInvalid Player!";
public String useSyntax = "&cUsage: %usage%!";

public String noPermission = "&ecYou don't have permission to do that!";
public String noPermission = "&eYou don't have permission to do that!";
public String unknownCommand = "&cUnknown command!";
public String mustBeAPlayer = "&cYou must be a player to do that!";
public String invalidArguments = "&cInvalid Arguments!";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public class PluginMessages extends OkaeriConfig {

public String useSyntax = "&cUsage: %usage%!";

public String noPermission = "&ecYou don't have permission to do that!";
public String noPermission = "&eYou don't have permission to do that!";
public String unknownCommand = "&cUnknown command!";
public String mustBeAPlayer = "&cYou must be a player to do that!";
public String invalidArguments = "&cInvalid Arguments!";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class PluginMessages extends OkaeriConfig {

public String useSyntax = "&cUsage: %usage%!";

public String noPermission = "&ecYou don't have permission to do that!";
public String noPermission = "&eYou don't have permission to do that!";
public String unknownCommand = "&cUnknown command!";
public String mustBeAPlayer = "&cYou must be a player to do that!";
public String invalidArguments = "&cInvalid Arguments!";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static class PluginMessages extends OkaeriConfig {

public String useSyntax = "&cUsage: %usage%!";

public String noPermission = "&ecYou don't have permission to do that!";
public String noPermission = "&eYou don't have permission to do that!";
public String unknownCommand = "&cUnknown command!";
public String mustBeAPlayer = "&cYou must be a player to do that!";
public String invalidArguments = "&cInvalid Arguments!";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class PluginMessages extends OkaeriConfig {

public String useSyntax = "&cUsage: %usage%!";

public String noPermission = "&ecYou don't have permission to do that!";
public String noPermission = "&eYou don't have permission to do that!";
public String unknownCommand = "&cUnknown command!";
public String mustBeAPlayer = "&cYou must be a player to do that!";
public String invalidArguments = "&cInvalid Arguments!";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.bukkit.plugin.Plugin;

public interface TheDragonAPI {
GamePlayerCheckService getGamePlayerCheckService();
GuardianEditService getGuardianEditService();
StructureService getStructureService();
GuardianService getGuardianService();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.qualityplus.dragon.api.game.part;

import com.qualityplus.dragon.base.game.player.EventPlayer;

import java.util.List;

/**
* Implementation for the final phase of a DragonGame
*/
public interface GameEnd {
/**
* Send a Message when game finish
*/
void sendFinishMessage();
void sendFinishMessage(final List<EventPlayer> players);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ public interface GameExplosion {
*
* @return When Block explosion is finished
*/
CompletableFuture<Void> makeBlockExplosion(PasterSession session);
public CompletableFuture<Void> makeBlockExplosion(final PasterSession session);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@Getter
@Component
public final class TheDragonAPIImpl implements TheDragonAPI {
private @Inject GamePlayerCheckService gamePlayerCheckService;
private @Inject GuardianEditService guardianEditService;
private @Inject StructureService structureService;
private @Inject GuardianService guardianService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class PluginMessages extends OkaeriConfig {
public String successfullyReloaded = "&aPlugin has been reloaded successfully!";
public String invalidPlayer = "&cInvalid Player!";
public String useSyntax = "&cUsage: %usage%!";
public String noPermission = "&ecYou don't have permission to do that!";
public String noPermission = "&eYou don't have permission to do that!";
public String unknownCommand = "&cUnknown command!";
public String mustBeAPlayer = "&cYou must be a player to do that!";
public String invalidArguments = "&cInvalid Arguments!";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,26 @@ public final class DragonGuardianEvent extends DragonGameEvent {
private final Set<Entity> guardians = new HashSet<>();
private final int guardiansAmount;

public DragonGuardianEvent(SerializableEvent event) {
public DragonGuardianEvent(final SerializableEvent event) {
super(event.generalSettings.secondsDuration, event.generalSettings.repeatEventAfterSeconds, event.generalSettings.dragonSpeedAmplifier, event.generalSettings.keepDragonAFK);
this.guardiansAmount = event.guardianSettings.guardiansAmount;
this.guardiansConfig = event.guardianSettings.guardians;
}

@Override
public void start(DragonGame dragonGame) {
public void start(final DragonGame dragonGame) {
time = 0;
task = Bukkit.getScheduler().runTaskTimerAsynchronously(TheDragon.getApi().getPlugin(), () -> {
move(dragonGame);
//Cancelling Event
if(time >= duration)
if (time >= duration) {
finish();
else
} else {
//Chequear El Evento
if(time % repeat == 0)
if (time % repeat == 0) {
spawn();
}
}
time++;
}, 0, 20);
}
Expand All @@ -47,42 +49,49 @@ public void start(DragonGame dragonGame) {
public void finish() {
super.finish();

guardians.stream().filter(Objects::nonNull).forEach(entity -> Bukkit.getScheduler().runTask(TheDragon.getApi().getPlugin(), entity::remove));
guardians.stream()
.filter(Objects::nonNull)
.forEach(entity -> Bukkit.getScheduler().runTask(TheDragon.getApi().getPlugin(), entity::remove));
}


private void spawn(){
if(!isActive()) return;

Set<Location> locations = getRandomLocations(guardiansAmount);
if (!isActive()) {
return;
}

final Set<Location> locations = getRandomLocations(guardiansAmount);

locations.forEach(loc -> Bukkit.getScheduler().runTask(TheDragon.getApi().getPlugin(), () -> addGuardian(loc)));
}

private Set<Location> getRandomLocations(int amount){
Set<Location> locations = new HashSet<>();
private Set<Location> getRandomLocations(final int amount){
final Set<Location> locations = new HashSet<>();

for(int i = 0; locations.size()<amount; i++){
for (int i = 0; locations.size()<amount; i++) {
Location location = TheDragon.getApi().getGuardianService().getRandomLocation();

if(location == null) continue;
if (location == null) {
continue;
}

locations.add(location);

if(i == 100) break;
if (i == 100) {
break;
}
}

return locations;
}


private void addGuardian(Location location){
private void addGuardian(final Location location) {
try {
Guardian guardian = TheDragon.getApi().getGuardianService().getRandomGuardian(guardiansConfig);
final Guardian guardian = TheDragon.getApi().getGuardianService().getRandomGuardian(this.guardiansConfig);

guardians.add(guardian.spawn(location));
}catch (Exception e){
this.guardians.add(guardian.spawn(location));
} catch (final Exception e) {
Bukkit.getConsoleSender().sendMessage(StringUtils.color("&c[TheDragon] Error trying to spawn guardian!"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.qualityplus.assistant.lib.eu.okaeri.platform.core.annotation.Component;
import com.qualityplus.assistant.lib.eu.okaeri.tasker.core.Tasker;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import java.util.List;
Expand Down Expand Up @@ -64,7 +65,7 @@ public void start(){
@Override
public void finish() {
if(active) {
TheDragonAPI api = TheDragon.getApi();
final TheDragonAPI api = TheDragon.getApi();

active = false;

Expand All @@ -73,7 +74,8 @@ public void finish() {
.thenRun(api.getUserService()::sendFinishMessage)
.thenRun(api.getBossBarService()::stopBossBar)
.thenRun(api.getUserService()::resetData)
.thenRun(api.getGameService()::stopSwitching);
.thenRun(api.getGameService()::stopSwitching)
.thenRun(api.getGamePlayerCheckService()::stopChecking);

}
}
Expand Down Expand Up @@ -130,6 +132,7 @@ private void runGame(final PasterSession session){
private void startGame(){
final TheDragonAPI api = TheDragon.getApi();

api.getGamePlayerCheckService().startChecking();
api.getBossBarService().startBossBar();
api.getDragonService().spawnDragon();
api.getGameService().switchEvents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,26 @@ public final class GameCountdownImpl implements GameCountdown {


@Override
public CompletableFuture<Void> start(TheDragonEntity theDragonEntity) {
CompletableFuture<Void> future = new CompletableFuture<>();
public CompletableFuture<Void> start(final TheDragonEntity theDragonEntity) {
final CompletableFuture<Void> future = new CompletableFuture<>();

Optional<DragonSpawn> spawn = TheDragon.getApi().getStructureService().getSpawn();
final Optional<DragonSpawn> spawn = TheDragon.getApi().getStructureService().getSpawn();

if(!spawn.isPresent()) return future;
if (!spawn.isPresent()) {
return future;
}

this.time = configuration.eventSettings.generalSettings.dragonSpawnCountdownSeconds;

Messages.GameTitlesMessages titles = messages.gameTitlesMessages;
final Messages.GameTitlesMessages titles = this.messages.gameTitlesMessages;

taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(TheDragon.getApi().getPlugin(), () -> {
this.taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(TheDragon.getApi().getPlugin(), () -> {

if (this.time <= 0) {
getPlayersAround(spawn.get().getLocation()).forEach(player -> sendTitle(player, theDragonEntity, titles.dragonSpawned));
future.complete(null);
Bukkit.getScheduler().cancelTask(taskID);
return;
}

getPlayersAround(spawn.get().getLocation()).forEach(player -> sendTitle(player, theDragonEntity, titles.dragonSpawning));
Expand All @@ -65,14 +68,14 @@ public CompletableFuture<Void> start(TheDragonEntity theDragonEntity) {
}

private void sendTitle(Player player, TheDragonEntity theDragonEntity, ConfigTitle configTitle){
String dragonName = theDragonEntity == null ? "" : theDragonEntity.getDisplayName();
final String dragonName = theDragonEntity == null ? "" : theDragonEntity.getDisplayName();

List<IPlaceholder> placeholders = Arrays.asList(
final List<IPlaceholder> placeholders = Arrays.asList(
new Placeholder("thedragon_dragon_displayname", dragonName),
new Placeholder("thedragon_dragon_spawning_time", time));

String title = StringUtils.processMulti(configTitle.getTitle(), placeholders);
String subTitle = StringUtils.processMulti(configTitle.getSubtitle(), placeholders);
final String title = StringUtils.processMulti(configTitle.getTitle(), placeholders);
final String subTitle = StringUtils.processMulti(configTitle.getSubtitle(), placeholders);

TheAssistantPlugin.getAPI().getNms().sendTitle(player, title, subTitle, 5, 5, 5);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,25 @@

@Component
public final class GameEndImpl implements GameEnd {
private @Inject UserDBService userDBService;
private @Inject DragonRewardsFile rewards;
private @Inject GameRanking gameRanking;
private @Inject Messages messages;
private @Inject DragonRewardsFile rewards;

@Override
public void sendFinishMessage() {

gameRanking.refreshRanking();
public void sendFinishMessage(final List<EventPlayer> players) {
this.gameRanking.refreshRanking();

TheDragon.getApi()
.getUserService()
.getUsers()
.forEach(this::managePlayer);
players.forEach(this::managePlayer);
}

private void managePlayer(EventPlayer player){
List<String> finalMessage = StringUtils.processMulti(messages.setupMessages.newGameEndMessage, gameRanking.getPlaceholders(player));
private void managePlayer(final EventPlayer player){
final List<String> finalMessage = StringUtils.processMulti(messages.setupMessages.newGameEndMessage, gameRanking.getPlaceholders(player));

player.sendMessage(finalMessage);

TheDragonEntity theDragonEntity = TheDragon.getApi().getDragonService().getActiveDragon();
final TheDragonEntity theDragonEntity = TheDragon.getApi().getDragonService().getActiveDragon();

List<IPlaceholder> placeholders = Arrays.asList(
final List<IPlaceholder> placeholders = Arrays.asList(
new Placeholder("thedragon_player_reward_xp", theDragonEntity.getXp()),
new Placeholder("player", player.getName()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,26 @@ public Optional<EventPlayer> getByRank(int ranking) {

@Override
public void refreshRanking(){
TheDragonAPI api = TheDragon.getApi();
final TheDragonAPI api = TheDragon.getApi();

List<EventPlayer> eventPlayers = api.getUserService().getUsers();
final List<EventPlayer> eventPlayers = new ArrayList<>(api.getUserService().getUsers());

eventPlayers.sort((o1, o2) -> (int) (o2.getDamage() - o1.getDamage()));

this.eventPlayerMap.clear();

int ranking = 0;
int ranking = 1;

for(EventPlayer eventPlayer : eventPlayers){
for (EventPlayer eventPlayer : eventPlayers) {
this.eventPlayerMap.put(ranking, eventPlayer);
ranking++;
}
}

private String getRecordMessage(EventPlayer player){
Optional<UserData> dragonPlayer = userDBService.getData(player.getUuid());
private String getRecordMessage(final EventPlayer player){
final Optional<UserData> dragonPlayer = userDBService.getData(player.getUuid());

double oldRecord = dragonPlayer.map(UserData::getRecord).orElse(0.0);
final double oldRecord = dragonPlayer.map(UserData::getRecord).orElse(0.0);

return player.getDamage() > oldRecord ? messages.gameMessages.newRecordPlaceholder : "";
}
Expand Down
Loading

0 comments on commit a0c3c67

Please sign in to comment.