Skip to content

Commit

Permalink
Merge pull request #83 from BTEUK/Develop
Browse files Browse the repository at this point in the history
Location Specific Step Data
  • Loading branch information
george112n authored Sep 27, 2023
2 parents 221a74b + 3fcf678 commit aa6eaa4
Show file tree
Hide file tree
Showing 28 changed files with 1,083 additions and 316 deletions.
35 changes: 7 additions & 28 deletions src/main/java/teachingtutorials/TeachingTutorials.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import teachingtutorials.newlocation.NewLocation;
import teachingtutorials.tutorials.*;
import teachingtutorials.utils.DBConnection;
import teachingtutorials.utils.Display;
import teachingtutorials.utils.User;
import teachingtutorials.utils.VirtualBlock;

Expand Down Expand Up @@ -357,22 +358,15 @@ else if(szLines[iLine].startsWith("("))
return;
}
szFields = szLines[iLine].split(",");
//Field 1 is step name, field 2 is display type, field 3 is the instruction
if (szFields.length < 3)
//Field 1 is step name, field 2 is display type
if (szFields.length < 2)
{
Bukkit.getConsoleSender().sendMessage(ChatColor.RED +"Tutorial config is not configured correctly, line: "+(iLine+1));
return;
}
szType = "Step";

//Compiles instructions if commas were part of the instruction and split
String szInstructions = szFields[2];
for (int k = 3 ; k < szFields.length ; k++)
{
szInstructions = szInstructions +"," +szFields[k];
}

Step step = new Step(szFields[0].replace("(",""), szFields[1], szInstructions);
Step step = new Step(szFields[0].replace("(",""), szFields[1]);
lastStage.steps.add(step);
lastStep = step;
}
Expand Down Expand Up @@ -569,10 +563,9 @@ public boolean addNewTutorialToDB(Tutorial tutorial)
Step step = steps.get(j);
try
{
String szStepInstructions = step.getInstructions().replace("\'", "\'\'");
String szInstructionType = step.getInstructionDisplayType();
Display.DisplayType instructionDisplayType = step.getInstructionDisplayType();

sql = "INSERT INTO Steps (StepName, StageID, StepInStage, StepInstructions, InstructionDisplay) VALUES ('"+step.getName()+"', "+iStageID+", "+(j+1)+", '" +szStepInstructions +"' ,'" +szInstructionType +"')";
sql = "INSERT INTO Steps (StepName, StageID, StepInStage, InstructionDisplay) VALUES ('"+step.getName()+"', "+iStageID+", "+(j+1)+",'" +instructionDisplayType +"')";
Bukkit.getConsoleSender().sendMessage(sql);
SQL.executeUpdate(sql);

Expand Down Expand Up @@ -671,10 +664,6 @@ public Connection getConnection()

private boolean createTables()
{
//Is assumed true and if any of the tables fail to create will change to false
boolean bSuccess = true;
// int iCount = -1;

sql = "";

FileReader fileReader = null;
Expand Down Expand Up @@ -712,16 +701,6 @@ private boolean createTables()

//Executes the update and returns how many rows were changed
SQL.executeUpdate(statements[i]);

// //If only 1 record was changed, success is set to true - FCKING IDIOT
// if (iCount == 1)
// {
// }
// else
// {
// Bukkit.getConsoleSender().sendMessage(ChatColor.RED +"[TeachingTutorials] - Failed to execute table, iCount = "+iCount +"\n");
// bSuccess = false;
// }
Bukkit.getConsoleSender().sendMessage(ChatColor.AQUA +"[TeachingTutorials] - Executed command\n");
}
}
Expand Down Expand Up @@ -758,7 +737,7 @@ private boolean createTables()
}
dbConnection.disconnect();
}
return (bSuccess);
return true;
}

private String readAll(BufferedReader br)
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/teachingtutorials/TutorialPlaythrough.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public User getCreatorOrStudent()
return creatorOrStudent;
}

public void setFallListenerSafeLocation(org.bukkit.Location location)
{
//Raises the safe location by 1 block to ensure players do not tp inside blocks as used to happen sometimes
fallListener.setSafeLocation(location.add(0, 1, 0));
}

// Moves the tutorial on to the next stage
// Accessed after the end of each stage (Called from Stage.endStage() asynchronously)
// or at the start of the playthrough
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/teachingtutorials/compulsory/Compulsory.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public Compulsory(TeachingTutorials plugin, User user)
super(user, plugin, true);
}

public void startLesson()
public boolean startLesson()
{
super.startLesson();
return super.startLesson();
}
}
2 changes: 1 addition & 1 deletion src/main/java/teachingtutorials/fundamentalTasks/Chat.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Chat(TeachingTutorials plugin, Player player, Group parentGroup, int iTas
this.szDetails = szDetails;

//Listen out for difficulty - There will only be one difficulty listener per chat to avoid bugs
difficultyListener = new DifficultyListener(this.plugin, this.player, this, FundamentalTask.chat);
difficultyListener = new DifficultyListener(this.plugin, this.player, this, FundamentalTaskType.chat);
difficultyListener.register();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public Command(TeachingTutorials plugin, Player player, Group parentGroup, int i
this.commandType = teachingtutorials.fundamentalTasks.commandType.valueOf(szDetails);

//Listen out for difficulty - There will only be one difficulty listener per command to avoid bugs
difficultyListener = new DifficultyListener(this.plugin, this.player, this, FundamentalTask.command);
difficultyListener = new DifficultyListener(this.plugin, this.player, this, FundamentalTaskType.command);
difficultyListener.register();

tasksInGroup = tasks;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package teachingtutorials.fundamentalTasks;

public enum FundamentalTask
public enum FundamentalTaskType
{
tpll, selection, command, place, chat
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ public static double[] convertToMCCoordinates(double dLatitude, double dLongitud
{
double[] xz = null;

final GeographicProjection projection = EarthGeneratorSettings.parse(EarthGeneratorSettings.BTE_DEFAULT_SETTINGS).projection();

try
{
xz = projection.fromGeo(dLongitude, dLatitude);
Expand All @@ -71,6 +69,21 @@ public static double[] convertToMCCoordinates(double dLatitude, double dLongitud
return xz;
}

public static double[] convertToGeometricCoordinates(double X, double Z)
{
double[] longLat = null;

try
{
longLat = projection.toGeo(X, Z);
}
catch (OutOfProjectionBoundsException e)
{
//Player has selected an area outside of the projection
}
return longLat;
}

public static boolean tpllPlayer(World world, double latitude, double longitude, Player player)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public Place(TeachingTutorials plugin, Player player, Group parentGroup, int iTa
this.szDetails = szDetails;

//Listen out for difficulty - There will only be one difficulty listener per place task to avoid bugs
difficultyListener = new DifficultyListener(this.plugin, this.player, this, FundamentalTask.tpll);
difficultyListener = new DifficultyListener(this.plugin, this.player, this, FundamentalTaskType.tpll);
difficultyListener.register();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public Selection(TeachingTutorials plugin, Player player, Group parentGroup, int
this.bSelection2Made = false;

//Listen out for difficulty - There will only be one difficulty listener per selection to avoid bugs
difficultyListener = new DifficultyListener(this.plugin, this.player, this, FundamentalTask.selection);
difficultyListener = new DifficultyListener(this.plugin, this.player, this, FundamentalTaskType.selection);
difficultyListener.register();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package teachingtutorials.fundamentalTasks;

import net.buildtheearth.terraminusminus.generator.EarthGeneratorSettings;
import net.buildtheearth.terraminusminus.projection.GeographicProjection;
import net.buildtheearth.terraminusminus.projection.OutOfProjectionBoundsException;
import net.buildtheearth.terraminusminus.util.geo.CoordinateParseUtils;
import net.buildtheearth.terraminusminus.util.geo.LatLng;
import org.bukkit.*;
Expand All @@ -15,7 +12,6 @@
import teachingtutorials.TeachingTutorials;
import teachingtutorials.newlocation.DifficultyListener;
import teachingtutorials.tutorials.Group;
import teachingtutorials.tutorials.Location;
import teachingtutorials.tutorials.LocationTask;
import teachingtutorials.utils.Display;

Expand Down Expand Up @@ -82,7 +78,7 @@ public TpllListener(TeachingTutorials plugin, Player player, Group parentGroup,
this.szDetails = szDetails;

//Listen out for difficulty - There will only be one difficulty listener per tpll command to avoid bugs
difficultyListener = new DifficultyListener(this.plugin, this.player, this, FundamentalTask.tpll);
difficultyListener = new DifficultyListener(this.plugin, this.player, this, FundamentalTaskType.tpll);
difficultyListener.register();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,7 @@ private void leftClicked(User u, int iSlot)
{
if (tutorials[iSlot].toggleInUse())
{
delete();
this.refresh();
u.mainGui.open(u);
}
else
{
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/teachingtutorials/guis/Gui.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,7 @@ public void open(User u) {

public void delete() {
for (Player p : Bukkit.getOnlinePlayers()) {
UUID u = openInventories.get(p.getUniqueId());
if (u != null) {
if (u.equals(getUuid())) {
p.closeInventory();
}
}
openInventories.remove(p.getUniqueId(), getUuid());
}
inventoriesByUUID.remove(getUuid());
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/teachingtutorials/guis/LibraryMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ public void rightClick(User u) {
@Override
public void leftClick(User u)
{
delete();

//Creates a NewLocation object
Lesson newLesson = new Lesson(user, plugin, tutorials[iSlot]);

//Launches them into the new location adding process
newLesson.startLesson();
if (newLesson.startLesson())
delete();
user.mainGui = null;
}
});
}
Expand Down
67 changes: 37 additions & 30 deletions src/main/java/teachingtutorials/guis/MainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@ public void rightClick(User u)
@Override
public void leftClick(User u)
{
//Deletes this gui
delete();

performEvent(EventType.COMPULSORY, u, plugin);
if (performEvent(EventType.COMPULSORY, u, plugin))
//Deletes this gui
delete();
}
});

Expand All @@ -83,10 +82,9 @@ public void rightClick(User u) {
}
@Override
public void leftClick(User u) {
//Deletes this gui
delete();

performEvent(EventType.LIBRARY, u, plugin);
if (performEvent(EventType.LIBRARY, u, plugin))
//Deletes this gui
delete();
}
});

Expand All @@ -100,10 +98,9 @@ public void rightClick(User u)
@Override
public void leftClick(User u)
{
//Deletes this gui
delete();

performEvent(EventType.CONTINUE, u, plugin);
if (performEvent(EventType.CONTINUE, u, plugin))
//Deletes this gui
delete();
}
});
}
Expand All @@ -129,10 +126,9 @@ public void rightClick(User u) {
}
@Override
public void leftClick(User u) {
//Deletes this gui
delete();

performEvent(EventType.COMPULSORY, u, plugin);
if (performEvent(EventType.COMPULSORY, u, plugin))
//Deletes this gui
delete();
}
});
}
Expand All @@ -149,10 +145,9 @@ public void rightClick(User u)
@Override
public void leftClick(User u)
{
//Deletes this gui
delete();

performEvent(EventType.CONTINUE, u, plugin);
if (performEvent(EventType.CONTINUE, u, plugin))
//Deletes this gui
delete();
}
});

Expand All @@ -164,10 +159,9 @@ public void rightClick(User u) {
}
@Override
public void leftClick(User u) {
//Deletes this gui
delete();

performEvent(EventType.LIBRARY, u, plugin);
if (performEvent(EventType.LIBRARY, u, plugin))
//Deletes this gui
delete();
}
});
}
Expand All @@ -184,36 +178,42 @@ public void rightClick(User u) {
}
@Override
public void leftClick(User u) {
//Deletes this gui
delete();
performEvent(EventType.ADMIN_MENU, u, plugin);
if (performEvent(EventType.ADMIN_MENU, u, plugin))
//Deletes this gui
delete();
}
});
}
}

public static void performEvent(EventType event, User user, TeachingTutorials plugin)
public static boolean performEvent(EventType event, User user, TeachingTutorials plugin)
{
switch (event) {
case COMPULSORY -> {
//Starts the compulsory tutorial
Compulsory compulsory = new Compulsory(plugin, user);
compulsory.startLesson();
return compulsory.startLesson();
}
case CONTINUE -> {
//Creates a lesson with the user
Lesson lesson = new Lesson(user, plugin, false);
lesson.startLesson();
return lesson.startLesson();
}
case ADMIN_MENU ->
{
user.mainGui = new AdminMenu(plugin, user);
user.mainGui.open(user);
return true;
}
case LIBRARY ->
{
user.mainGui = new LibraryMenu(plugin, user, Tutorial.getInUseTutorialsWithLocations());
user.mainGui.open(user);
return true;
}
default ->
{
return false;
}
}
}
Expand All @@ -226,4 +226,11 @@ public void refresh()

this.open(user);
}

@Override
public void delete()
{
super.delete();
user.mainGui = null;
}
}
Loading

0 comments on commit aa6eaa4

Please sign in to comment.