Skip to content

Commit

Permalink
Merge pull request #11 from the-codeboy/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
dev-null-undefined authored Oct 14, 2021
2 parents d026437 + e8d14d2 commit 3382be4
Show file tree
Hide file tree
Showing 11 changed files with 295 additions and 33 deletions.
33 changes: 33 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
name: Bug report
about: Create a report to help us improve
title: "[BUG] "
labels: bug
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. Windows 11, Linux]
- Java version: [e.g. OpenJDK 1.8, 17]
- Minecraft version: [e.g. 1.8.8, 1.16.1]
- Plugin version: [e.g. 1.1, 1.2]

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
22 changes: 14 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.codeboy</groupId>
<artifactId>mcide</artifactId>
<version>1.2-SNAPSHOT</version>
<version>1.2.1</version>
<packaging>jar</packaging>

<name>Mcide</name>
Expand Down Expand Up @@ -44,6 +44,18 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.2.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
<resources>
<resource>
Expand Down Expand Up @@ -84,16 +96,10 @@
<artifactId>Piston4J</artifactId>
<version>v0.0.6</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.the-codeboy</groupId>
<artifactId>BukkitBootstrap</artifactId>
<version>d663859a9d</version>
<version>f821d5e8d4</version>
</dependency>
</dependencies>
</project>
9 changes: 8 additions & 1 deletion src/main/java/com/github/codeboy/mcide/Mcide.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
package com.github.codeboy.mcide;

import com.github.codeboy.mcide.commands.BoundItemCommand;
import com.github.codeboy.mcide.commands.CreateProject;
import com.github.codeboy.mcide.commands.IdeCommand;
import com.github.codeboy.mcide.commands.RunCommand;
import com.github.codeboy.mcide.config.Config;
import com.github.codeboy.mcide.config.Message;
import com.github.codeboy.mcide.services.CustomItemEventManager;
import com.github.codeboy.piston4j.api.ExecutionOutput;
import com.github.codeboy.piston4j.api.ExecutionResult;
import com.github.codeboy.piston4j.api.Piston;
import com.google.gson.Gson;
import ml.codeboy.bukkitbootstrap.CustomItem;
import ml.codeboy.bukkitbootstrap.config.ConfigReader;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;

import javax.management.InstanceAlreadyExistsException;
import java.io.File;
import java.util.Arrays;
import java.util.List;
Expand All @@ -38,7 +43,6 @@ public static Piston getPiston() {
@Override
public void onEnable() {
// Plugin startup logic

readConfigs();

piston = Piston.getInstance(Config.pistonEndPoint);
Expand All @@ -47,13 +51,16 @@ public void onEnable() {
getCommand("run").setExecutor(new RunCommand());
getCommand("ide").setExecutor(new IdeCommand());
getCommand("create-project").setExecutor(new CreateProject());
getCommand("bound-item").setExecutor(new BoundItemCommand());
getServer().getPluginManager().registerEvents(new Listener() {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
event.getPlayer().setResourcePack("https://github.com/the-codeboy/mcide/releases/download/latest/mcide.zip");
}
}, this);

getServer().getPluginManager().registerEvents(new CustomItemEventManager(), Mcide.getPlugin(Mcide.class));

}

private void readConfigs() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.github.codeboy.mcide.commands;

import com.github.codeboy.mcide.config.Message;
import com.github.codeboy.mcide.ide.gui.ProjectSelector;
import com.github.codeboy.mcide.services.CustomItemEventManager;
import ml.codeboy.bukkitbootstrap.CustomItem;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.block.Action;

public class BoundItemCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
return false;
}
Player player = (Player) sender;
CustomItem customItem = CustomItem.createItemOrGet(player.getPlayerListName(), Material.GOLD_HOE, (short) 0);
player.getInventory().addItem(customItem.getItem());

CustomItemEventManager.addInteraction(customItem, event -> {
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
Player p = event.getPlayer();
event.setCancelled(true);
ProjectSelector menu = new ProjectSelector(p);
menu.open(p);
event.setCancelled(true);
}
});
return true;
}
}
5 changes: 4 additions & 1 deletion src/main/java/com/github/codeboy/mcide/config/Config.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.github.codeboy.mcide.config;

import ml.codeboy.bukkitbootstrap.config.ConfigScope;
import ml.codeboy.bukkitbootstrap.config.ConfigValue;
import ml.codeboy.bukkitbootstrap.config.Configurable;

@Configurable(name = "config.yml",comments = "Edit these values however you like\n" +
"They should be self explanatory",scope = ConfigScope.PUBLIC)
public class Config {
@ConfigValue
public static String language = "english";

@ConfigValue(key = "piston.endpoint")
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/com/github/codeboy/mcide/config/Message.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package com.github.codeboy.mcide.config;

import ml.codeboy.bukkitbootstrap.config.ConfigValue;
import ml.codeboy.bukkitbootstrap.config.ConfigScope;
import ml.codeboy.bukkitbootstrap.config.Configurable;
import org.bukkit.ChatColor;

@Configurable(comments = "Edit these messages however you like\n" +
"It should be self explanatory where they are used",scope = ConfigScope.PUBLIC)
public class Message {

// region CUSTOM_ITEM
public static String
ITEM_PROJECT_SELECTOR = "Open Menu";
// endregion
// region GUI
@ConfigValue
public static String
RUN_OPTION_TITLE = "Run options",
RUN_CHAT_OPTION = "Chat output",
Expand All @@ -15,7 +21,6 @@ public class Message {
RUN_BOOK_OPTION_LORE = "Will redirect the output to written book";
// endregion
// region info
@ConfigValue
public static String PROJECTS = "projects",
EXECUTION_START = ChatColor.BLUE + "Running project {0}",
RIGHT_CLICK_TO_EDIT = ChatColor.BLUE + "Right click to edit. Move to cancel",
Expand All @@ -26,15 +31,13 @@ public class Message {
DELETE_FILE = ChatColor.RED + "delete file",
EDIT_CANCELLED = ChatColor.DARK_RED + "Cancelled editing file {0}";
//region error
@ConfigValue
public static String CMD_PLAYER_ONLY = ChatColor.RED + "Only players can use this command",
LANGUAGE_AND_NAME_REQUIRED = ChatColor.RED + "You need to specify a language and a name for the project",
NAME_REQUIRED = ChatColor.RED + "You need to specify a name!",
RUN_PROJECT_ERROR_OUTPUT = ChatColor.RED + "Your project \"{0}\" had an error:",
NOT_PROJECT_OWNER = ChatColor.RED + "You are not the owner of this project";
// endregion
//region success
@ConfigValue
public static String PROJECT_CREATE_SUCCESS = ChatColor.GREEN + "Project created successfully",
RUN_PROJECT_SUCCESS = ChatColor.GREEN + "Ran project \"{0}\" successfully. Here is your output:",
EDIT_SUCCESS = ChatColor.GREEN + "Edited file {0} successfully";
Expand Down
51 changes: 34 additions & 17 deletions src/main/java/com/github/codeboy/mcide/ide/gui/ProjectMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
import com.github.codeboy.mcide.config.Message;
import com.github.codeboy.mcide.ide.CodeProject;
import com.github.codeboy.mcide.ide.MCCodeFile;
import ml.codeboy.bukkitbootstrap.gui.Action;
import ml.codeboy.bukkitbootstrap.gui.Gui;
import ml.codeboy.bukkitbootstrap.gui.MultiPageGui;
import org.bukkit.Material;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

import java.util.ArrayList;

public class ProjectMenu extends MultiPageGui {
private final CodeProject project;
private final int filesPerPage = 9 * 4;

public ProjectMenu(CodeProject project) {
super(Mcide.getPlugin(Mcide.class), 54, project.getTitle(), (Gui page) -> {
Expand Down Expand Up @@ -43,29 +44,45 @@ protected int getPrevButtonIndex() {
return 50;
}

@Override
protected Gui createPage() {
Gui gui = super.createPage();
ItemStack item = createItem(Material.STAINED_GLASS_PANE, "-");
for (int i = 0; i < 9; i++) {
gui.addItem(item, 54 - 18 + i, Action.none);
}
return gui;
}

public void addFile(MCCodeFile file, boolean mainFile) {
ItemStack fileItem = createItem(Material.BOOK_AND_QUILL, file.getName(), mainFile);
addItem(fileItem, p -> project.editFile(file, p));
ArrayList<Gui> pages = getPages();
int index = 0;
Gui lastPage;
do {
lastPage = pages.get(index++);
} while (lastPage.getFreeSlot() > filesPerPage && index < pages.size());
int freeSlot = lastPage.getFreeSlot();
if (freeSlot > filesPerPage) {
addNextButton(lastPage);
lastPage = createPage();
pages.add(lastPage);
addPrevButton(lastPage);
}
lastPage.addItem(fileItem, p -> project.editFile(file, p));
}

public void removeFile() {
ArrayList<Gui>pages=getPages();
for (int i = pages.size() - 1; i >= 0; i--) {
Gui page=pages.get(i);
Inventory inventory= page.getInventory();

int index = inventory.getSize() - 1;
while (index>=0) {
if(isProjectFile(inventory.getItem(index))){
inventory.setItem(index,null);
return;
}
index--;
}
int files = project.getMCCodeFiles().size();
if (!project.getMCCodeFiles().get(files - 1).isMainFile()) {
int pageNumber = files / filesPerPage;
int slotNumber = files % filesPerPage;
Gui page = getPages().get(pageNumber);
page.removeItem(slotNumber);
}
}

private boolean isProjectFile(ItemStack itemStack){
return itemStack!=null&&itemStack.getType()==Material.BOOK_AND_QUILL;
private boolean isProjectFile(ItemStack itemStack) {
return itemStack != null && itemStack.getType() == Material.BOOK_AND_QUILL;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.github.codeboy.mcide.services;

import ml.codeboy.bukkitbootstrap.CustomItem;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;

import java.util.HashMap;
import java.util.function.Consumer;

public class CustomItemEventManager implements Listener {

private static final HashMap<CustomItem, Consumer<PlayerInteractEvent>> interactions = new HashMap<>();

@EventHandler
public void onPlayerUse(PlayerInteractEvent event) {
Player player = event.getPlayer();
ItemStack item = player.getItemInHand();
for(CustomItem customItem:interactions.keySet()){
if (customItem.itemIsInstance(item)) {
interactions.get(customItem).accept(event);
}
}
}

public static boolean addInteraction(CustomItem customItem,Consumer<PlayerInteractEvent> interaction){
if(interactions.containsKey(customItem)){
return false;
}
interactions.put(customItem,interaction);
return true;
}
}
3 changes: 2 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ website: https://github.com/the-codeboy
commands:
run:
ide:
create-project:
create-project:
bound-item:
Loading

0 comments on commit 3382be4

Please sign in to comment.