Skip to content

Commit

Permalink
Merge pull request #89 from BTEUK/Develop
Browse files Browse the repository at this point in the history
Adds the video link feature, and also fixed the MySQL syntax issue.
  • Loading branch information
george112n authored Feb 3, 2024
2 parents aa6eaa4 + be63bbc commit 23d701d
Show file tree
Hide file tree
Showing 14 changed files with 267 additions and 73 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.bteuk</groupId>
<artifactId>TeachingTutorials</artifactId>
<version>1.1.0-Beta5</version>
<version>1.1.0-Beta6</version>
<packaging>jar</packaging>

<name>TeachingTutorials</name>
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/teachingtutorials/TeachingTutorials.java
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ public boolean addNewTutorialToDB(Tutorial tutorial)
try
{
SQL = TeachingTutorials.getInstance().getConnection().createStatement();
sql = "INSERT INTO Tutorials (TutorialName, Author) VALUES ('"+tutorial.szTutorialName+"', '"+tutorial.uuidAuthor +"')";
sql = "INSERT INTO `Tutorials` (`TutorialName`, `Author`) VALUES ('"+tutorial.szTutorialName+"', '"+tutorial.uuidAuthor +"')";
SQL.executeUpdate(sql);

sql = "Select LAST_INSERT_ID()";
Expand All @@ -515,7 +515,7 @@ public boolean addNewTutorialToDB(Tutorial tutorial)
{
try
{
sql = "INSERT INTO CategoryPoints (TutorialID, Category, Relevance) VALUES (" + iTutorialID + ", '" + tutorial.szCategoryEnumsInOrder[i] + "', " +((float) tutorial.categoryUsage[i])/100+ ")";
sql = "INSERT INTO `CategoryPoints` (`TutorialID`, `Category`, `Relevance`) VALUES (" + iTutorialID + ", '" + tutorial.szCategoryEnumsInOrder[i] + "', " +((float) tutorial.categoryUsage[i])/100+ ")";
Bukkit.getConsoleSender().sendMessage(sql);
SQL.executeUpdate(sql);
}
Expand All @@ -537,7 +537,7 @@ public boolean addNewTutorialToDB(Tutorial tutorial)
Stage stage = stages.get(i);
try
{
sql = "INSERT INTO Stages (StageName, TutorialID, `Order`) VALUES ('"+stage.getName()+"', "+iTutorialID+", "+(i+1)+")";
sql = "INSERT INTO `Stages` (`StageName`, `TutorialID`, `Order`) VALUES ('"+stage.getName()+"', "+iTutorialID+", "+(i+1)+")";
Bukkit.getConsoleSender().sendMessage(sql);
SQL.executeUpdate(sql);

Expand Down Expand Up @@ -565,7 +565,7 @@ public boolean addNewTutorialToDB(Tutorial tutorial)
{
Display.DisplayType instructionDisplayType = step.getInstructionDisplayType();

sql = "INSERT INTO Steps (StepName, StageID, StepInStage, InstructionDisplay) VALUES ('"+step.getName()+"', "+iStageID+", "+(j+1)+",'" +instructionDisplayType +"')";
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 @@ -593,7 +593,7 @@ public boolean addNewTutorialToDB(Tutorial tutorial)
Bukkit.getConsoleSender().sendMessage(ChatColor.AQUA +"Adding group "+k +". Name: "+group.getName());
try
{
sql = "INSERT INTO Groups (StepID)" +
sql = "INSERT INTO `Groups` (`StepID`)" +
" VALUES (" +iStepID+")";
Bukkit.getConsoleSender().sendMessage(sql);
SQL.executeUpdate(sql);
Expand Down Expand Up @@ -628,7 +628,7 @@ public boolean addNewTutorialToDB(Tutorial tutorial)

try
{
sql = "INSERT INTO Tasks (GroupID, TaskType, `Order`, Details)" +
sql = "INSERT INTO `Tasks` (`GroupID`, `TaskType`, `Order`, `Details`)" +
" VALUES (" +iGroupID+", '"+task.type+"', "+(l+1) +", '" +szDetails +"')";
Bukkit.getConsoleSender().sendMessage(sql);
SQL.executeUpdate(sql);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.bukkit.Material;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta;
import teachingtutorials.TeachingTutorials;
import teachingtutorials.guis.Gui;
import teachingtutorials.listeners.TextEditorBookListener;
Expand All @@ -30,9 +29,8 @@ public class StepEditorMenu extends Gui
private final Step step;
private final LocationStep locationStep;

private TextEditorBookListener bookListener;

private ItemStack book;
private TextEditorBookListener instructionsBookListener;
private TextEditorBookListener videoLinkBookListener;

public StepEditorMenu(TeachingTutorials plugin, User user, Step step, LocationStep locationStep)
{
Expand All @@ -42,10 +40,8 @@ public StepEditorMenu(TeachingTutorials plugin, User user, Step step, LocationSt
this.step = step;
this.locationStep = locationStep;

this.book = new ItemStack(Material.WRITABLE_BOOK, 1);
BookMeta bookMeta = (BookMeta) book.getItemMeta();
bookMeta.setTitle(step.getName());
this.book.setItemMeta(bookMeta);
this.videoLinkBookListener = new TextEditorBookListener(plugin, user, locationStep, StepEditorMenu.this, step.getName());
this.instructionsBookListener = new TextEditorBookListener(plugin, user, locationStep, StepEditorMenu.this, step.getInstructionDisplayType(), step.getName());

setItems();
}
Expand All @@ -59,11 +55,15 @@ public void setItems()
ItemStack teleportToStart = Utils.createItem(Material.VILLAGER_SPAWN_EGG, 1,
Component.text("Teleport back to the start location", NamedTextColor.GREEN));

ItemStack videoLink = Utils.createItem(Material.PAINTING, 1,
Component.text("Set the video tutorial link if one exists", NamedTextColor.GREEN),
Component.text("This is specific to each location of the tutorial", NamedTextColor.DARK_GREEN));

boolean bIsHologramNeeded = step.getInstructionDisplayType().equals(Display.DisplayType.hologram);
if (bIsHologramNeeded)
{
//Set start location coordinates to current location
setItem(11, setStartLocation, new guiAction() {
setItem(10, setStartLocation, new guiAction() {
@Override
public void rightClick(User u) {
leftClick(u);
Expand All @@ -79,7 +79,7 @@ public void leftClick(User u) {
ItemStack instructions = Utils.createItem(Material.WRITABLE_BOOK, 1,
Component.text("Set the instructions", NamedTextColor.GREEN));

setItem(13, instructions, new guiAction() {
setItem(12, instructions, new guiAction() {
@Override
public void rightClick(User u) {
leftClick(u);
Expand All @@ -88,16 +88,15 @@ public void rightClick(User u) {
@Override
public void leftClick(User u) {
//The book must have the step name as the title
Utils.giveItem(u.player, book, "Instructions editor book");
Utils.giveItem(u.player, instructionsBookListener.getBook(), "Instructions editor book");
Display display = new Display(u.player, Component.text("Use the instructions editor book to set the instructions", NamedTextColor.GREEN));
display.Message();

//Closes the current inventory
u.player.closeInventory(InventoryCloseEvent.Reason.PLUGIN);

//Sets up the book listener and registers it
bookListener = new TextEditorBookListener(plugin, u, locationStep, StepEditorMenu.this, step.getInstructionDisplayType(), step.getName(), book);
bookListener.register();
instructionsBookListener.register();

//step.tryNextStep() is called via instructionsEdited() from TextEditorBookListener once the book close event occurs
}
Expand All @@ -108,7 +107,7 @@ public void leftClick(User u) {
Component.text("Set the instructions hologram location", NamedTextColor.GREEN),
Component.text("Set the instructions hologram to your current position", NamedTextColor.DARK_GREEN));

setItem(15, hologramLocation, new guiAction() {
setItem(14, hologramLocation, new guiAction() {
@Override
public void rightClick(User u) {
leftClick(u);
Expand All @@ -120,10 +119,35 @@ public void leftClick(User u) {
step.tryNextStep();
}
});

//Set video link
setItem(16, videoLink, new guiAction() {
@Override
public void rightClick(User u) {
leftClick(u);
}

@Override
public void leftClick(User u) {
//The book must have the step name as the title
Utils.giveItem(u.player, videoLinkBookListener.getBook(), "Video link editor book");
Display display = new Display(u.player, Component.text("Use the video link editor book to set the video link", NamedTextColor.GREEN));
display.Message();

//Closes the current inventory
u.player.closeInventory(InventoryCloseEvent.Reason.PLUGIN);

//Sets up the book listener and registers it
videoLinkBookListener.register();

//The listener unregisters itself once the book is closed. We parse the location step by reference so it can edit the link itself
}
});
}
else
{
setItem(13, setStartLocation, new guiAction() {
//Set start location
setItem(12, setStartLocation, new guiAction() {
@Override
public void rightClick(User u) {
leftClick(u);
Expand All @@ -134,6 +158,30 @@ public void leftClick(User u) {
setStartLocation(u.player.getLocation());
}
});

//Set video link
setItem(14, videoLink, new guiAction() {
@Override
public void rightClick(User u) {
leftClick(u);
}

@Override
public void leftClick(User u) {
//The book must have the step name as the title
Utils.giveItem(u.player, videoLinkBookListener.getBook(), "Video link editor book");
Display display = new Display(u.player, Component.text("Use the video link editor book to set the video link", NamedTextColor.GREEN));
display.Message();

//Closes the current inventory
u.player.closeInventory(InventoryCloseEvent.Reason.PLUGIN);

//Sets up the book listener and registers it
videoLinkBookListener.register();

//The listener unregisters itself once the book is closed. We parse the location step by reference so it can edit the link itself
}
});
}

//Teleport to start
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
Expand All @@ -27,15 +28,47 @@ public class TextEditorBookListener implements Listener
private String szStepName;
private ItemStack book;

public TextEditorBookListener(TeachingTutorials plugin, User user, LocationStep locationStep, StepEditorMenu stepEditorMenu, Display.DisplayType displayType, String szStepName, ItemStack book)
private boolean bWasInstructions; //If not then it was video link

//Used for creating an instructions editor book
public TextEditorBookListener(TeachingTutorials plugin, User user, LocationStep locationStep, StepEditorMenu stepEditorMenu, Display.DisplayType displayType, String szStepName)
{
this.displayType = displayType;
this.bWasInstructions = true;

commonSetup(plugin, user, locationStep, stepEditorMenu, szStepName);
}

//Used for creating a video link editor book
public TextEditorBookListener(TeachingTutorials plugin, User user, LocationStep locationStep, StepEditorMenu stepEditorMenu, String szStepName)
{
this.bWasInstructions = false;

commonSetup(plugin, user, locationStep, stepEditorMenu, szStepName);
}

private void commonSetup(TeachingTutorials plugin, User user, LocationStep locationStep, StepEditorMenu stepEditorMenu, String szStepName)
{
this.plugin = plugin;
this.user = user;
this.locationStep = locationStep;
this.stepEditorMenu = stepEditorMenu;
this.displayType = displayType;
this.szStepName = szStepName;
this.book = book;

//Creates the book
this.book = new ItemStack(Material.WRITABLE_BOOK, 1);

//Extracts the book meta reference, and sets the title
BookMeta videoLinkBookMeta = (BookMeta) this.book.getItemMeta();
videoLinkBookMeta.setTitle(szStepName);

//Adds the meta of the book back in
this.book.setItemMeta(videoLinkBookMeta);
}

public ItemStack getBook()
{
return book;
}

public void register()
Expand Down Expand Up @@ -66,8 +99,11 @@ public void BookCloseEvent(PlayerEditBookEvent e)
//Removes the end space, the space after the last page is added in the loop but then needs to be removed
szNewContent = szNewContent.substring(0, szNewContent.length() - 1);

//Edits the step instructions
locationStep.setInstruction(szNewContent, displayType, user.player, szStepName);
//Edits the step instructions or video link
if (bWasInstructions)
locationStep.setInstruction(szNewContent, displayType, user.player, szStepName);
else
locationStep.setVideoLink(szNewContent);

//Saves the instructions in the book
BookMeta bookMeta = (BookMeta) book.getItemMeta();
Expand All @@ -85,7 +121,8 @@ public void BookCloseEvent(PlayerEditBookEvent e)
user.player.getInventory().getItemInMainHand().setAmount(0);

//Informs the menu that some instructions were edited
stepEditorMenu.instructionsEdited();
if (bWasInstructions)
stepEditorMenu.instructionsEdited();
}

private void unregister()
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/teachingtutorials/tutorials/Group.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public static ArrayList<Group> fetchGroupsByStepID(Player player, TeachingTutori
try
{
//Compiles the command to fetch groups
sql = "Select * FROM Groups WHERE StepID = "+step.iStepID;
sql = "Select * FROM `Groups` WHERE `StepID` = "+step.iStepID;
SQL = TeachingTutorials.getInstance().getConnection().createStatement();

//Executes the query
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/teachingtutorials/tutorials/Lesson.java
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ public boolean fetchCurrentFromUUID()
try
{
//Compiles the command to fetch the lesson in progress - assumes a player can only have one lesson ongoing at a time
sql = "Select * FROM Lessons WHERE UUID = '" +creatorOrStudent.player.getUniqueId() +"' AND Finished = 0";
sql = "SELECT * FROM `Lessons` WHERE `UUID` = '" +creatorOrStudent.player.getUniqueId() +"' AND `Finished` = 0";
SQL = TeachingTutorials.getInstance().getConnection().createStatement();

//Executes the query
Expand Down Expand Up @@ -761,7 +761,7 @@ private void addLessonToDB()
try
{
SQL = TeachingTutorials.getInstance().getConnection().createStatement();
szSql = "INSERT INTO Lessons (UUID, TutorialID, Finished, StageAt, StepAt, LocationID)" +
szSql = "INSERT INTO `Lessons` (`UUID`, `TutorialID`, `Finished`, `StageAt`, `StepAt`, `LocationID`)" +
" VALUES ("
+"'"+creatorOrStudent.player.getUniqueId()+"', "
+this.tutorial.getTutorialID()+", "
Expand All @@ -771,7 +771,7 @@ private void addLessonToDB()
+this.location.getLocationID() +")";
SQL.executeUpdate(szSql);

szSql = "Select LAST_INSERT_ID()";
szSql = "SELECT LAST_INSERT_ID()";
resultSet = SQL.executeQuery(szSql);
resultSet.next();
this.iLessonID = resultSet.getInt(1);
Expand All @@ -796,10 +796,10 @@ protected void savePositions()
SQL = TeachingTutorials.getInstance().getConnection().createStatement();

//At this point StageIndex actually refers to what stage they are on and is 1 indexed
szSql = "UPDATE Lessons SET StageAt = " +iStageIndex +" WHERE LessonID = "+ this.iLessonID;
szSql = "UPDATE `Lessons` SET `StageAt` = " +iStageIndex +" WHERE `LessonID` = "+ this.iLessonID;
SQL.executeUpdate(szSql);

szSql = "UPDATE Lessons SET StepAt = " +currentStage.getCurrentStep() +" WHERE LessonID = "+ this.iLessonID;
szSql = "UPDATE `Lessons` SET `StepAt` = " +currentStage.getCurrentStep() +" WHERE `LessonID` = "+ this.iLessonID;
SQL.executeUpdate(szSql);
}
catch (Exception e)
Expand All @@ -819,7 +819,7 @@ private void setLessonCompleteInDB()
try
{
SQL = TeachingTutorials.getInstance().getConnection().createStatement();
szSql = "UPDATE Lessons SET Finished = 1 WHERE LessonID = "+ this.iLessonID;
szSql = "UPDATE `Lessons` SET `Finished` = 1 WHERE `LessonID` = "+ this.iLessonID;
SQL.executeUpdate(szSql);
}
catch (Exception e)
Expand Down
Loading

0 comments on commit 23d701d

Please sign in to comment.