Skip to content

Commit

Permalink
Stopping for now.
Browse files Browse the repository at this point in the history
  • Loading branch information
its-c10 committed Feb 27, 2022
1 parent fd70de9 commit 329f2c7
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 17 deletions.
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,20 @@
<id>dmulloy2-repo</id>
<url>https://repo.dmulloy2.net/repository/public/</url>
</repository>
<repository>
<id>everything</id>
<url>http://repo.citizensnpcs.co/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>net.citizensnpcs</groupId>
<artifactId>citizens-main</artifactId>
<version>2.0.29-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/net/dohaw/ironcraft/IronCraftPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Score;
Expand Down Expand Up @@ -98,7 +99,9 @@ public void onEnable() {
new Reminder(this).runTaskTimer(this, 0L, 20 * 10);

// collect data every tick
new DataCollector(this).runTaskTimer(this, 0L, 40);
new DataCollector(this).runTaskTimer(this, 0L, 1);

startSurveyWarner();

formPacketListeners();

Expand Down Expand Up @@ -239,6 +242,19 @@ public Objective getNextObjective(Objective currentObjective) {
return Objective.values()[ordinal + 1];
}

/**
* Starts the runnable that sends a title to players telling them that they are being surveyed.
*/
private void startSurveyWarner(){
Bukkit.getScheduler().runTaskTimer(this, () -> {
for(Player player : Bukkit.getOnlinePlayers()){
if(player.getPersistentDataContainer().has(IronCraftPlugin.IN_SURVEY_PDC_KEY, PersistentDataType.STRING) && player.isConversing()){
player.sendTitle("Take the survey", "Look in chat", 2, 20, 5);
}
}
}, 0, 20);
}

public List<Location> getJourneySpawnPoints() {
return journeySpawnPoints;
}
Expand Down
42 changes: 37 additions & 5 deletions src/main/java/net/dohaw/ironcraft/PlayerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.dohaw.ironcraft.data_collection.DataCollectionUtil;
import net.dohaw.ironcraft.manager.ManagerUtil;
import net.dohaw.ironcraft.prompt.AutonomySurveyPrompt;
import net.dohaw.ironcraft.util.LocationUtil;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
Expand All @@ -14,6 +15,7 @@
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.conversations.Conversation;
import org.bukkit.conversations.ConversationFactory;
import org.bukkit.entity.NPC;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataType;
Expand Down Expand Up @@ -167,6 +169,13 @@ public class PlayerData {
// Bad name. Can't figure out how else to explain it though.
private HashSet<String> firstPickItems = new HashSet<>();

private int roundsPlayed;

/**
* The player's manager NPC.
*/
private NPC managerNPC;

public PlayerData(UUID uuid, String providedID) {
this.providedID = providedID;
this.uuid = uuid;
Expand All @@ -189,7 +198,15 @@ public void startTeleporter(IronCraftPlugin plugin){
if(teleporter != null){
teleporter.cancel();
}
teleporter = Bukkit.getScheduler().runTaskTimer(plugin, () -> teleportToFocusedPlayer(), 0L, 1L);
teleporter = Bukkit.getScheduler().runTaskTimer(plugin, () -> {
if(isManager){
teleportToFocusedPlayer();
}else{
if(managementType == ManagementType.AI){
managerNPC.teleport(LocationUtil.getRelativeManagerLocation(getPlayer()));
}
}
}, 0L, 1L);
}

/**
Expand Down Expand Up @@ -322,10 +339,7 @@ public int getNextGainIndex() {
public void teleportToFocusedPlayer(){
Player focusedPlayer = Bukkit.getPlayer(focusedPlayerUUID);
if(focusedPlayer == null) return;
Location focusedPlayerLoc = focusedPlayer.getLocation();
Location clone = focusedPlayerLoc.clone();
Location tpLoc = clone.clone().add(clone.getDirection().multiply(-2.5)).add(0, 0.5, 0);
getPlayer().teleport(tpLoc);
getPlayer().teleport(LocationUtil.getRelativeManagerLocation(focusedPlayer));
}

public void initManager(IronCraftPlugin plugin){
Expand All @@ -342,13 +356,15 @@ public void initManager(IronCraftPlugin plugin){
public void initWorker(IronCraftPlugin plugin){
Player player = getPlayer();
this.isManager = false;
player.getInventory().clear();
player.setGravity(true);
player.setInvisible(false);
player.setAllowFlight(false);
player.setFlying(false);
if(teleporter != null){
teleporter.cancel();
}
plugin.giveEssentialItems(player);
startGameTimeTracker(plugin);
}

Expand Down Expand Up @@ -376,6 +392,14 @@ public void incrementCurrentStep() {
durationSteps++;
}

public void incrementRoundsPlayed(){
this.roundsPlayed++;
}

public int getRoundsPlayed() {
return roundsPlayed;
}

public Map<String, Integer> getItemToTimeStepGained() {
return itemToTimeStepGained;
}
Expand Down Expand Up @@ -535,6 +559,14 @@ public void setMinutesInGame(int minutesInGame) {
this.minutesInGame = minutesInGame;
}

public void setManagerNPC(NPC managerNPC) {
this.managerNPC = managerNPC;
}

public NPC getManagerNPC() {
return managerNPC;
}

public void writeDataToFile(IronCraftPlugin plugin) throws IOException {

File file = new File(plugin.getDataFolder() + File.separator + "end_game_data", "input_" + uuid.toString() + ".yml");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.bukkit.event.HandlerList;

/**
* Fires when a user gets assigned a manager.
* Fires when a user gets assigned a human manager.
*/
public class AssignManagerEvent extends Event {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.dohaw.ironcraft.listener;

import net.dohaw.ironcraft.CraftUtil;
import net.dohaw.ironcraft.util.CraftUtil;
import net.dohaw.ironcraft.IronCraftPlugin;
import net.dohaw.ironcraft.data_collection.DataCollectionUtil;
import net.dohaw.ironcraft.PlayerData;
Expand Down
33 changes: 29 additions & 4 deletions src/main/java/net/dohaw/ironcraft/listener/PlayerWatcher.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.dohaw.ironcraft.listener;

import net.dohaw.corelib.StringUtils;
import net.dohaw.ironcraft.Objective;
import net.dohaw.ironcraft.Reason;
import net.dohaw.ironcraft.event.AssignManagerEvent;
import net.dohaw.ironcraft.IronCraftPlugin;
Expand Down Expand Up @@ -215,8 +216,13 @@ public void onPlayerTakeDamage(EntityDamageEvent e) {
public void onGameEnd(EndGameEvent e) {

PlayerData playerData = e.getPlayerData();

Player player = playerData.getPlayer();

Reason reason = e.getReason();
if(reason == Reason.OUT_OF_TIME){
player.sendTitle("Game Over", "You ran out of time!", 10, 50, 9);
}

player.sendMessage(StringUtils.colorString("&aCongratulations! &fYou have successfully completed the game!"));
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!");
Bukkit.getScheduler().runTaskLater(plugin, () -> {
Expand All @@ -233,9 +239,28 @@ public void onGameEnd(EndGameEvent e) {
conv.begin();
}

Reason reason = e.getReason();
if(reason == Reason.OUT_OF_TIME){
player.sendTitle("Game Over", "You ran out of time!", 10, 100, 10);
playerData.incrementRoundsPlayed();
int roundsPlayed = playerData.getRoundsPlayed();
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
16 changes: 16 additions & 0 deletions src/main/java/net/dohaw/ironcraft/manager/ManagerUtil.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package net.dohaw.ironcraft.manager;

import net.citizensnpcs.api.CitizensAPI;
import net.dohaw.corelib.StringUtils;
import net.dohaw.ironcraft.IronCraftPlugin;
import net.dohaw.ironcraft.event.AssignManagerEvent;
import net.dohaw.ironcraft.PlayerData;
import net.dohaw.ironcraft.util.LocationUtil;
import org.bukkit.Bukkit;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.NPC;
import org.bukkit.entity.Player;

import java.util.ArrayList;
Expand Down Expand Up @@ -65,6 +69,18 @@ public static void assignManager(PlayerData data) {

}

private static void setupNPCManager(PlayerData user){

NPC npc = (NPC) CitizensAPI.getNPCRegistry().createNPC(EntityType.PLAYER, "C10_MC");
user.setManagerNPC(npc);

npc.setAI(false);
npc.setGravity(false);
npc.setCollidable(false);
npc.setAware(false);

}

public static void sendManagerMessage(Player player){
player.sendRawMessage("You are a manager in the iron pickaxe factory. You will supervise 2 to 5 workers, who should make an iron pickaxe within 7 mins.");
player.sendRawMessage("As a manager, your task is to keep an eye on their performance and evaluate them after the 7-min session expires. You can rate each of them on three levels: Beginner level ($0), Intermediate level ($0.2), or Advanced level ($0.5). Your ratings will decide their pay in the session as shown in the brackets.");
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/net/dohaw/ironcraft/prompt/IDPrompt.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ public Prompt acceptInput(ConversationContext context, String providedID) {
return null;
}

player.getInventory().clear();
plugin.giveEssentialItems(player);
player.teleport(randomChamberLocation);
data.setChamberLocation(randomChamberLocation);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ public Prompt acceptInput(ConversationContext context, String input) {
playerData.setCurrentTutorialObjective(Objective.COLLECT_WOOD);
playerData.setInTutorial(false);
Bukkit.getScheduler().runTaskLater(plugin, () -> {
player.getInventory().clear();
plugin.giveEssentialItems(player);
player.teleport(randomSpawnPoint);
playerData.initWorker(plugin);
}, 20L * 3);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.dohaw.ironcraft;
package net.dohaw.ironcraft.util;

import org.bukkit.inventory.CraftingInventory;
import org.bukkit.inventory.Inventory;
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/net/dohaw/ironcraft/util/LocationUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package net.dohaw.ironcraft.util;

import org.bukkit.Location;
import org.bukkit.entity.Player;

public class LocationUtil {

/**
* Acquires the location that the NPC manager is supposed to be relative to the user.
* @param relativeUser The user playing the game.
* @return The location that the NPC manager is supposed to be relative to the user.
*/
public static Location getRelativeManagerLocation(Player relativeUser){
Location focusedPlayerLoc = relativeUser.getLocation();
Location clone = focusedPlayerLoc.clone();
return clone.clone().add(clone.getDirection().multiply(-2.5)).add(0, 0.5, 0);
}

}
1 change: 1 addition & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ main: net.dohaw.ironcraft.IronCraftPlugin
api-version: 1.16
depend:
- ProtocolLib
- Citizens

commands:
ironcraft:
Expand Down

0 comments on commit 329f2c7

Please sign in to comment.