Skip to content

Commit 21847d4

Browse files
authored
Merge pull request #40 from AutoPluginsDev/rt_add_reopen_editor
re opening inventory after entering value in chat
2 parents f931b04 + d162d47 commit 21847d4

File tree

7 files changed

+44
-16
lines changed

7 files changed

+44
-16
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>fr</groupId>
88
<artifactId>AutoCommand</artifactId>
9-
<version>1.5.9</version>
9+
<version>1.5.10</version>
1010
<packaging>jar</packaging>
1111

1212
<repositories>

src/main/java/fr/lumi/CommandPatternObject/ACMDRelatedCommand.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package fr.lumi.CommandPatternObject;
22

33
import fr.lumi.Main;
4+
import fr.lumi.Util.autocommand;
45
import fr.lumi.Util.autocommandDataPattern;
56

67
public abstract class ACMDRelatedCommand extends autocommandDataPattern implements Command{
@@ -10,5 +11,12 @@ public ACMDRelatedCommand(Main plg) {
1011
}
1112

1213
public abstract void execute();
13-
14+
protected void setID(autocommand acmd) {
15+
acmd.setID(ID);
16+
int index = 0;
17+
while (plugin.acmdIdExist(acmd.getID())) {
18+
acmd.setID("acmd" + index);
19+
index++;
20+
}
21+
}
1422
}

src/main/java/fr/lumi/CommandPatternObject/CreateACMDCommand.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,7 @@ public void execute() {
5858

5959
}
6060

61-
private void setID(autocommand acmd) {
62-
acmd.setID(ID);
63-
int index = 0;
64-
while (plugin.acmdIdExist(acmd.getID())) {
65-
acmd.setID("acmd" + index);
66-
index++;
67-
}
68-
}
61+
6962

7063

7164
}

src/main/java/fr/lumi/Commandes/CommandRunnerCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
197197

198198
if (args.length == 2) {
199199
plugin.getModificationLock().lock(((Player)player).getUniqueId().toString());
200-
plugin.getAcmdGUIEditor().openACMDEditor((Player) sender, acmd, plugin.getcommandList().indexOf(acmd));
200+
plugin.getAcmdGUIEditor().openACMDEditor((Player) sender, plugin.getcommandList().indexOf(acmd));
201+
201202
return true;
202203
}
203204

src/main/java/fr/lumi/Commandes/CommandRunnerReload.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public CommandRunnerReload(Main plg) {
1818

1919
@Override
2020
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
21+
plugin.getAcmdGUIEditor().closeLastTennantInventory();
2122
plugin.onEnable();
2223
Bukkit.getConsoleSender().sendMessage(plugin.getUt().replacePlaceHoldersForConsolePlgVar(plugin.getLangConfig().getString("OnReload")));
2324
sender.sendMessage(plugin.getUt().replacePlaceHoldersForPlayerPlgVar(plugin.getLangConfig().getString("OnReload")));

src/main/java/fr/lumi/Util/CommandEditor.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.ArrayList;
1717
import java.util.List;
1818
import java.util.Objects;
19+
import java.util.UUID;
1920

2021

2122
public class CommandEditor implements Listener {
@@ -74,7 +75,25 @@ public void closeInventory(Player p) {
7475
clearLock(p);
7576
}
7677

77-
public void openACMDEditor(Player p, autocommand acmd, int nb) {
78+
public void closeLastTennantInventory() {
79+
// get player by uuid and not by name
80+
Player p = Bukkit.getPlayer(UUID.fromString(plugin.getModificationLock().getLastTennant()));
81+
82+
83+
if (p != null) {
84+
85+
if (p.getOpenInventory().equals(GUI_ChooseACMD)) {
86+
closeInventory(p);
87+
}
88+
if (editorsListe.contains(p.getOpenInventory())) {
89+
closeInventory(p);
90+
}
91+
92+
93+
}
94+
}
95+
96+
public void openACMDEditor(Player p,int nb) {
7897
//createGUI_EditACMD(acmd);
7998

8099
p.openInventory(editorsListe.get(nb));
@@ -98,7 +117,7 @@ public void GuiClickEvent(InventoryClickEvent e) {
98117
e.setCancelled(true);
99118
if (slot < plugin.getcommandList().size()) {
100119
closeInventory(p);
101-
openACMDEditor(p, plugin.getcommandList().get(slot), slot);
120+
openACMDEditor(p, slot);
102121
} else if (slot == 53) {
103122

104123
// Creating a new acmd using the CreateCommand.
@@ -218,6 +237,12 @@ public void onChat(AsyncPlayerChatEvent e) {
218237
waitForChat = "";
219238
reloadAllEditGUI();
220239
reloadGUI_ChoosingACMD();
240+
241+
242+
plugin.getServer().getScheduler().callSyncMethod(plugin, () -> {
243+
openACMDEditor(e.getPlayer(), LastOpened);
244+
return null;
245+
});
221246
}
222247
}
223248

@@ -440,7 +465,7 @@ public Inventory fillGUI_EditACMD(autocommand acmd, Inventory gui) {
440465
}
441466

442467
public Inventory createGUI_EditACMD(autocommand acmd) {
443-
Inventory gui = Bukkit.createInventory(null, 54, "§8§oEditing " + acmd.getName());
468+
Inventory gui = Bukkit.createInventory(null, 54, "§8§oEditing " + acmd.getID());
444469
return fillGUI_EditACMD(acmd, gui);
445470
}
446471

src/main/resources/plugin.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
name: AutoCommands
2-
version: 1.5.9
2+
version: 1.5.10
33
main: fr.lumi.Main
44
api-version: 1.15
55
authors:
66
- Lumi_
77
- Adi_
8-
prefix: AutoCommands 1.5.9
8+
prefix: AutoCommands 1.5.10
99
depends: [PlaceholderAPI]
1010
permissions:
1111
acmd.*:

0 commit comments

Comments
 (0)