Skip to content

Commit

Permalink
fixed the bug that caused players not to be able to player multiple r…
Browse files Browse the repository at this point in the history
…ounds of the game.
  • Loading branch information
its-c10 committed Feb 27, 2022
1 parent 6504d4d commit dd77efe
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 39 deletions.
3 changes: 2 additions & 1 deletion src/main/java/net/dohaw/ironcraft/IronCraftCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ public boolean onCommand(CommandSender sender, Command command, String label, St

sender.sendMessage("This location has been set!");

// ic set obj
}else if(firstArg.equalsIgnoreCase("set")){
String secondArg = args[1];
if(args.length == 4){
if(args.length >= 3){
String targetPlayerName = args[2];
String fourthArg = args[3];
if(secondArg.equalsIgnoreCase("obj") || secondArg.equalsIgnoreCase("ingame")){
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/dohaw/ironcraft/PlayerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ public void startGameTimeTracker(IronCraftPlugin plugin){
gameTimeTracker = Bukkit.getScheduler().runTaskTimer(plugin, () -> {

if(isInTutorial){
this.minutesInGame = 0;
gameTimeTracker.cancel();
return;
}
Expand Down
27 changes: 2 additions & 25 deletions src/main/java/net/dohaw/ironcraft/listener/PlayerWatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ public void onGameEnd(EndGameEvent e) {
PlayerData playerData = e.getPlayerData();
Player player = playerData.getPlayer();

playerData.incrementRoundsPlayed();

Reason reason = e.getReason();
if(reason == Reason.OUT_OF_TIME){
player.sendTitle("Game Over", "You ran out of time!", 10, 50, 9);
Expand All @@ -273,31 +275,6 @@ public void onGameEnd(EndGameEvent e) {
conv.begin();
}

playerData.incrementRoundsPlayed();
int roundsPlayed = playerData.getRoundsPlayed();
System.out.println("Rounds played: " + roundsPlayed);
if(playerData.getRoundsPlayed() < 3){

player.sendMessage(StringUtils.colorString("You have played " + roundsPlayed + " rounds. You have " + (3 - roundsPlayed) + " more round(s) to go!"));
Location randomSpawnPoint = plugin.getRandomJourneySpawnPoint();
if (randomSpawnPoint == null) {
plugin.getLogger().severe("There has been an error trying to teleport a player to a random spawn point");
player.sendRawMessage("You could not be teleported to a random spawn point at this moment. Please contact an administrator...");
return;
}

// Lets them play the game again.
Bukkit.getScheduler().runTaskLater(plugin, () -> {
playerData.setCurrentTutorialObjective(Objective.MOVE);
player.teleport(randomSpawnPoint);
playerData.setMinutesInGame(0);
playerData.initWorker(plugin);
}, 20 * 3);

}else{
player.sendMessage(StringUtils.colorString("Congratulations. You are finished."));
}

}

/**
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/net/dohaw/ironcraft/manager/ManagerUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ private static void setupNPCManager(PlayerData user){
CitizensNPC npc = (CitizensNPC) CitizensAPI.getNPCRegistry().createNPC(EntityType.PLAYER, "C10_MC");
user.setManagerNPC(npc);
npc.spawn(getNPCManagerTPLocation(user.getPlayer()));
npc.setAlwaysUseNameHologram(false);

LivingEntity entity = (LivingEntity) npc.getEntity();
entity.setAI(false);
Expand All @@ -94,12 +95,8 @@ private static void setupNPCManager(PlayerData user){
*/
public static void ensurePlayersHaveManagers(IronCraftPlugin plugin){
for(PlayerData pd : plugin.getPlayerDataHandler().getPlayerDataList()){
System.out.println("Looping");
if(pd.getManager() == null && !pd.isManager() && !pd.isInTutorial()){
System.out.println("Assign him!");
ManagerUtil.assignManager(pd);
System.out.println("Managerment type: " + pd.getManagementType());
System.out.println("Manager: " + pd.getManagerNPC());
}
}
}
Expand Down
42 changes: 33 additions & 9 deletions src/main/java/net/dohaw/ironcraft/prompt/AutonomySurveyPrompt.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.dohaw.corelib.StringUtils;
import net.dohaw.corelib.helpers.MathHelper;
import net.dohaw.ironcraft.IronCraftPlugin;
import net.dohaw.ironcraft.Objective;
import net.dohaw.ironcraft.SurveySession;
import net.dohaw.ironcraft.handler.PlayerDataHandler;
import net.dohaw.ironcraft.manager.ManagementType;
Expand All @@ -11,6 +12,7 @@
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.PumpStreamHandler;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.conversations.*;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -101,12 +103,36 @@ public Prompt acceptInput(ConversationContext context, String input) {
}

// Write their data to file and calculate their proficiency score.
try {
playerData.writeDataToFile(plugin);
} catch (IOException e) {
e.printStackTrace();
// try {
// playerData.writeDataToFile(plugin);
// } catch (IOException e) {
// e.printStackTrace();
// }
// calculateProficiencyScore(player);

int roundsPlayed = playerData.getRoundsPlayed();
System.out.println("Rounds played: " + roundsPlayed);
if(playerData.getRoundsPlayed() < 3){

player.sendRawMessage("You have played " + roundsPlayed + " rounds. You have " + (3 - roundsPlayed) + " more round(s) to go!");
Location randomSpawnPoint = plugin.getRandomJourneySpawnPoint();
if (randomSpawnPoint == null) {
plugin.getLogger().severe("There has been an error trying to teleport a player to a random spawn point");
player.sendRawMessage("You could not be teleported to a random spawn point at this moment. Please contact an administrator...");
return END_OF_CONVERSATION;
}

// Lets them play the game again.
Bukkit.getScheduler().runTaskLater(plugin, () -> {
playerData.setCurrentTutorialObjective(Objective.COLLECT_WOOD);
player.teleport(randomSpawnPoint);
playerData.setMinutesInGame(0);
playerData.initWorker(plugin);
}, 20 * 3);

}else{
player.sendRawMessage("Congratulations. You are finished.");
}
calculateProficiencyScore(player);

return END_OF_CONVERSATION;

Expand Down Expand Up @@ -141,15 +167,13 @@ private int calculateProficiencyScore(Player player){
DefaultExecutor executor = new DefaultExecutor();
executor.setStreamHandler(streamHandler);

int exitCode;
try {
exitCode = executor.execute(cmdLine);
executor.execute(cmdLine);
} catch (IOException e) {
e.printStackTrace();
return 0;
}

return exitCode;
return 0;

}

Expand Down

0 comments on commit dd77efe

Please sign in to comment.