Skip to content

Commit

Permalink
Fixed most of the bugs that occurred last time in the testing session.
Browse files Browse the repository at this point in the history
Need to still do 2 things:
1. Make fake manager NPC's
2. Make sure the manager side of things isn't buggy.
  • Loading branch information
its-c10 committed Feb 22, 2022
1 parent 4d972b3 commit fd70de9
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 50 deletions.
47 changes: 44 additions & 3 deletions src/main/java/net/dohaw/ironcraft/IronCraftCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.dohaw.ironcraft;

import net.dohaw.corelib.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
Expand All @@ -22,16 +24,18 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
if (args.length > 0 && sender instanceof Player && sender.hasPermission("diamondcraft.admin")) {

Player playerSender = (Player) sender;
if (args[0].equalsIgnoreCase("create")) {
String firstArg = args[0];
if (firstArg.equalsIgnoreCase("create")) {

Location senderLocation = playerSender.getLocation();
if (args[1].equalsIgnoreCase("chamber")) {
String secondArg = args[1];
if (secondArg.equalsIgnoreCase("chamber")) {
if (!isUniqueLocation(senderLocation, plugin.getAvailableChamberLocations())) {
sender.sendMessage("This is not a unique location!");
return false;
}
plugin.getAvailableChamberLocations().add(senderLocation);
} else if (args[1].equalsIgnoreCase("spawn")) {
} else if (secondArg.equalsIgnoreCase("spawn")) {
if (!isUniqueLocation(senderLocation, plugin.getJourneySpawnPoints())) {
sender.sendMessage("This is not a unique location!");
return false;
Expand All @@ -43,6 +47,43 @@ public boolean onCommand(CommandSender sender, Command command, String label, St

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

}else if(firstArg.equalsIgnoreCase("set")){
String secondArg = args[1];
if(args.length == 4){
String targetPlayerName = args[2];
String fourthArg = args[3];
if(secondArg.equalsIgnoreCase("obj") || secondArg.equalsIgnoreCase("ingame")){

Player targetPlayer = Bukkit.getPlayer(targetPlayerName);
if(targetPlayer == null){
sender.sendMessage(StringUtils.colorString("&cThis is not a valid player!"));
return false;
}

PlayerData targetPlayerData = plugin.getPlayerDataHandler().getData(targetPlayer);
if(secondArg.equalsIgnoreCase("obj")){
Objective objective;
try{
objective = Objective.valueOf(fourthArg.toUpperCase());
}catch(IllegalArgumentException e){
sender.sendMessage(StringUtils.colorString("&cThis is not a valid objective!"));
return false;
}
targetPlayerData.setCurrentTutorialObjective(objective);
}else{
boolean isInGame;
try{
isInGame = Boolean.parseBoolean(fourthArg);
}catch(IllegalArgumentException e){
sender.sendMessage(StringUtils.colorString("&cThis is not a valid argument! It must be \"true\" or \"false\""));
return false;
}
targetPlayerData.setInTutorial(isInGame);
targetPlayerData.initWorker(plugin);
}

}
}
}

}
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/net/dohaw/ironcraft/IronCraftPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
import net.dohaw.ironcraft.listener.ObjectiveWatcher;
import net.dohaw.ironcraft.listener.PlayerWatcher;
import net.dohaw.ironcraft.prompt.IDPrompt;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.*;
import org.bukkit.conversations.Conversation;
import org.bukkit.conversations.ConversationFactory;
import org.bukkit.entity.Player;
Expand All @@ -41,6 +38,8 @@
*/
public final class IronCraftPlugin extends JavaPlugin {

public static final NamespacedKey IN_SURVEY_PDC_KEY = NamespacedKey.minecraft("is-answering-survey");

private static IronCraftPlugin instance;

/**
Expand Down Expand Up @@ -85,7 +84,7 @@ public void onEnable() {

// Only useful if there are players on the server, and /plugman reload IronCraft gets ran
for (Player player : Bukkit.getOnlinePlayers()) {
if (player.isConversing()) {
if (player.isConversing() ) {
player.kickPlayer("Please rejoin the server!");
continue;
}
Expand Down Expand Up @@ -136,7 +135,10 @@ public void onPacketReceiving(PacketEvent event) {
Bukkit.getServer().getPluginManager().callEvent(new CompleteObjectiveEvent(playerData));
});
} else {
player.sendMessage(ChatColor.RED + "Oops! Looks like you just closed it. Try opening the recipe menu again...");
player.closeInventory();
Bukkit.getScheduler().runTaskLater(plugin, () -> {
player.sendMessage(ChatColor.RED + "Oops! Looks like you just closed it. Try opening the recipe menu again...");
}, 5);
}

}
Expand Down
34 changes: 27 additions & 7 deletions src/main/java/net/dohaw/ironcraft/PlayerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,36 +197,47 @@ public void startTeleporter(IronCraftPlugin plugin){
* @param plugin An instance of the plugin.
*/
public void startGameTimeTracker(IronCraftPlugin plugin){

if(gameTimeTracker != null){
gameTimeTracker.cancel();
}

gameTimeTracker = Bukkit.getScheduler().runTaskTimer(plugin, () -> {

if(isInTutorial){
gameTimeTracker.cancel();
return;
}

minutesInGame++;
if(minutesInGame == 7){

gameTimeTracker.cancel();
Player player = getPlayer();

Player player = getPlayer();
if(minutesInGame >= 7){

gameTimeTracker.cancel();

player.sendMessage(StringUtils.colorString("&cYour time is up!"));
player.sendMessage("You will now take a survey. You won't be able to move for the duration of this survey. Don't worry, it'll be quick!");

PlayerData managerData = plugin.getPlayerDataHandler().getData(manager);
if(managerData.getFocusedPlayerUUID().equals(uuid)){
if(managerData != null && managerData.getFocusedPlayerUUID().equals(uuid)){
managerData.setFocusedPlayerUUID(null);
this.manager = null;
}
this.manager = null;

Bukkit.getScheduler().runTaskLater(plugin, () -> {
player.getPersistentDataContainer().set(NamespacedKey.minecraft("is-answering-survey"), PersistentDataType.STRING, "marker");
player.getPersistentDataContainer().set(IronCraftPlugin.IN_SURVEY_PDC_KEY, PersistentDataType.STRING, "marker");
Conversation conv = new ConversationFactory(plugin).withFirstPrompt(new AutonomySurveyPrompt(0, plugin)).withLocalEcho(false).buildConversation(player);
conv.begin();
}, 20L * 3);

}else{
player.sendMessage(StringUtils.colorString("&7You have &e" + (7 - minutesInGame) + "&7 minute(s) to complete the game!"));
}

},20 * 60L, 20 * 60L);

}

public boolean isManager() {
Expand Down Expand Up @@ -254,6 +265,12 @@ public void setPlayerDataConfig(PlayerDataConfig playerDataConfig) {
}

public void saveData() {
if(gameTimeTracker != null){
gameTimeTracker.cancel();
}
if(teleporter != null){
teleporter.cancel();
}
playerDataConfig.saveData(this);
}

Expand Down Expand Up @@ -322,7 +339,7 @@ public void initManager(IronCraftPlugin plugin){
ManagerUtil.sendManagerMessage(player);
}

public void initWorker(){
public void initWorker(IronCraftPlugin plugin){
Player player = getPlayer();
this.isManager = false;
player.setGravity(true);
Expand All @@ -332,6 +349,7 @@ public void initWorker(){
if(teleporter != null){
teleporter.cancel();
}
startGameTimeTracker(plugin);
}

public SurveySession getSurveySession() {
Expand Down Expand Up @@ -431,10 +449,12 @@ public List<Integer> getDenseRewardSequence() {
}

public int getSparseTotalReward() {
if(sparseRewardSequence.size() == 0) return 0;
return sparseRewardSequence.get(sparseRewardSequence.size() - 1);
}

public int getDenseTotalReward() {
if(denseRewardSequence.size() == 0) return 0;
return denseRewardSequence.get(denseRewardSequence.size() - 1);
}

Expand Down
17 changes: 17 additions & 0 deletions src/main/java/net/dohaw/ironcraft/Reason.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package net.dohaw.ironcraft;

/**
* The different reasons the game has stopped.
*/
public enum Reason {

/**
* The player has ran out of time to complete the game (You currently only get 7 minutes).
*/
OUT_OF_TIME,

/**
* The player has completed the game.
*/
GAME_COMPLETE;
}
11 changes: 4 additions & 7 deletions src/main/java/net/dohaw/ironcraft/Reminder.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
public class Reminder extends BukkitRunnable {

private final IronCraftPlugin plugin;

private Map<UUID, Integer> playerIndexReminders = new HashMap<>();

private int counter = 0;

private final List<String> PLAYER_REMINDERS = new ArrayList<String>() {{
add("&bPress T to open chat so that you can read messages!");
add("&bUse your number keys to switch between items!");
Expand Down Expand Up @@ -53,17 +54,13 @@ public void run() {
message = PLAYER_REMINDERS.get(currentIndexReminder);
playerIndexReminders.put(uuid, currentIndexReminder);

// Reminds them of how much time they have left if they are in the actual game.
if(!data.isInTutorial()){
int minutesInGame = data.getMinutesInGame();
player.sendMessage(StringUtils.colorString("&7You have &e" + (7 - minutesInGame) + "&7 minutes to complete the game!"));
}

}
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(StringUtils.colorString(message)));

}

counter++;

}

@Override
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/net/dohaw/ironcraft/config/BaseConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ public List<Location> getSpawnLocations() {
spawnLocations.add(locationSerializer.toLocation(strLocation));
}

System.out.println("STR LOCATIONS: " + strLocations);
System.out.println("SPAWN LOCATIONS: " + spawnLocations);

return spawnLocations;

}
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/net/dohaw/ironcraft/event/EndGameEvent.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
package net.dohaw.ironcraft.event;

import net.dohaw.ironcraft.PlayerData;
import net.dohaw.ironcraft.Reason;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;

/**
* The event that fires when the game ends.
* The event that is fired when the game has stopped. This doesn't always mean that the game was completed successfully.
* @see CompleteGameEvent
*/
public class EndGameEvent extends Event {

private static final HandlerList HANDLERS_LIST = new HandlerList();

private PlayerData playerData;
private Reason reason;

public EndGameEvent(PlayerData playerData) {
public EndGameEvent(Reason reason, PlayerData playerData){
this.reason = reason;
this.playerData = playerData;
}

public static HandlerList getHandlerList() {
return HANDLERS_LIST;
}

@Override
public HandlerList getHandlers() {
return HANDLERS_LIST;
}

public static HandlerList getHandlerList() {
return HANDLERS_LIST;
public Reason getReason() {
return reason;
}

public PlayerData getPlayerData() {
return playerData;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void saveData(UUID uuid) {

public void saveAllData() {
for (PlayerData data : allPlayerData.values()) {
data.getPlayer().getPersistentDataContainer().remove(IronCraftPlugin.IN_SURVEY_PDC_KEY);
data.saveData();
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/net/dohaw/ironcraft/listener/ObjectiveWatcher.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.ironcraft.IronCraftPlugin;
import net.dohaw.ironcraft.Objective;
import net.dohaw.ironcraft.Reason;
import net.dohaw.ironcraft.event.CompleteObjectiveEvent;
import net.dohaw.ironcraft.event.EndGameEvent;
import net.dohaw.ironcraft.handler.PlayerDataHandler;
Expand Down Expand Up @@ -81,7 +82,7 @@ public void onPlayerMove(PlayerMoveEvent e) {
@EventHandler
public void onCraftSticks(CraftItemEvent e) {
checkIfPassedCraftingObjective(e, Objective.MAKE_STICKS, Material.STICK);
checkIfPassedCraftingObjective(e, Objective.MAKE_PLANKS, Material.OAK_PLANKS, Material.SPRUCE_PLANKS, Material.ACACIA_PLANKS, Material.DARK_OAK_PLANKS, Material.JUNGLE_PLANKS);
checkIfPassedCraftingObjective(e, Objective.MAKE_PLANKS, Material.OAK_PLANKS, Material.BIRCH_PLANKS, Material.SPRUCE_PLANKS, Material.ACACIA_PLANKS, Material.DARK_OAK_PLANKS, Material.JUNGLE_PLANKS);
checkIfPassedCraftingObjective(e, Objective.MAKE_CRAFTING_TABLE, Material.CRAFTING_TABLE);
checkIfPassedCraftingObjective(e, Objective.MAKE_WOODEN_PICKAXE, Material.WOODEN_PICKAXE);
checkIfPassedCraftingObjective(e, Objective.MAKE_STONE_PICKAXE, Material.STONE_PICKAXE);
Expand Down Expand Up @@ -171,7 +172,8 @@ public void onTakeSmeltedIron(FurnaceExtractEvent e) {
@EventHandler
public void onCompleteObjective(CompleteObjectiveEvent e){

Player player = e.getPlayerData().getPlayer();
PlayerData playerData = e.getPlayerData();
Player player = playerData.getPlayer();
World world = player.getWorld();
world.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);

Expand All @@ -184,6 +186,8 @@ public void onCompleteObjective(CompleteObjectiveEvent e){
firework.detonate();
}, 10L);

player.sendTitle("Objective Complete!", "New Objective: " + playerData.getCurrentTutorialObjective().toProperName(), 10, 100, 10);

}

private int getCountItem(PlayerInventory playerInventory, Material material) {
Expand Down Expand Up @@ -216,7 +220,7 @@ private void checkIfPassedCraftingObjective(CraftItemEvent e, Objective objectiv
// End of the tutorial. They have just crafted an iron pickaxe
concludeTutorial(player);
}else{
Bukkit.getServer().getPluginManager().callEvent(new EndGameEvent(playerData));
Bukkit.getServer().getPluginManager().callEvent(new EndGameEvent(Reason.GAME_COMPLETE, playerData));
}
} else {
playerData.setCurrentTutorialObjective(plugin.getNextObjective(objective));
Expand Down
Loading

0 comments on commit fd70de9

Please sign in to comment.