Skip to content

Commit e31df54

Browse files
committed
4.1.5 overhaul
1 parent 5d3a891 commit e31df54

1 file changed

Lines changed: 45 additions & 91 deletions

File tree

README.md

Lines changed: 45 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SimpAPI v4.1.2
1+
# SimpAPI v4.1.5
22
****
33
SimpAPI, finally a good API that can make coding MC Plugins much easier and less painful.
44
This API includes all of my primary utilities like *Menu Manager*, *Command Manager*, *ColorTranslator*, and more.
@@ -25,7 +25,7 @@ JavaDocs: https://kodysimpson.github.io/SimpAPI/index.html
2525
<dependency>
2626
<groupId>com.github.KodySimpson</groupId>
2727
<artifactId>SimpAPI</artifactId>
28-
<version>4.1.2</version>
28+
<version>4.1.5</version>
2929
</dependency>
3030
```
3131

@@ -51,14 +51,14 @@ repositories {
5151
Groovy:
5252
```groovy
5353
dependencies {
54-
implementation 'com.github.KodySimpson:SimpAPI:4.1.2'
54+
implementation 'com.github.KodySimpson:SimpAPI:4.1.5'
5555
}
5656
```
5757

5858
Kotlin:
5959
```kotlin
6060
dependencies {
61-
implementation("com.github.KodySimpson:SimpAPI:4.1.2")
61+
implementation("com.github.KodySimpson:SimpAPI:4.1.5")
6262
}
6363
```
6464

@@ -82,107 +82,61 @@ There is also a method for TextComponents called translateColorCodesToTextCompon
8282
****
8383
The Menu Manager is something I came up with a while ago and showed on my Youtube channel, but in the SimpAPI it is much more advanced and has been made much easier for the developers who use it.
8484

85-
**Step One**: Create your PlayerMenuUtility.
86-
The PlayerMenuUtility is a class system that allows you to pass data across your menu inventories, avoiding situations where you pass them by Items or other tricky methods.
87-
All you need to do is extend the AbstractPlayerMenuUtility and create the variables for the data you will be passing.
88-
89-
Example:
90-
```java
91-
public class PlayerMenuUtility extends AbstractPlayerMenuUtility {
92-
93-
//Define the data you want passed between menus
94-
private Player playerToFreeze;
95-
private Player playerToMelt;
96-
97-
//Make sure to call the super constructor
98-
public PlayerMenuUtility(Player p) {
99-
super(p);
100-
}
101-
102-
//define the methods to access the data
103-
public Player getPlayerToFreeze() {
104-
return playerToFreeze;
105-
}
106-
107-
public void setPlayerToFreeze(Player playerToFreeze) {
108-
this.playerToFreeze = playerToFreeze;
109-
}
110-
111-
public Player getPlayerToMelt() {
112-
return playerToMelt;
113-
}
114-
115-
public void setPlayerToMelt(Player playerToMelt) {
116-
this.playerToMelt = playerToMelt;
117-
}
118-
}
119-
```
120-
121-
**Step Two**: Setup and Initializise the MenuManager by calling the Setup method. Do this in the plugin's onEnable method and all you need to do is provide the PlayerMenuUtility you just created.
85+
**Step One**: Setup and Initializise the MenuManager by calling the Setup method. Do this in the plugin's onEnable method and all you need to do is provide the PlayerMenuUtility you just created.
12286

12387
```java
12488
@Override
12589
public void onEnable() {
12690
// Plugin startup logic
12791

12892
//Setup and register the MenuManager. It will take care of the annoying parts.
129-
MenuManager.setup(getServer(), this, PlayerMenuUtility.class);
93+
MenuManager.setup(getServer(), this);
13094

13195
}
13296
```
13397

134-
**Step Three**: Add Menus.
98+
**Step Two**: Add Menus.
13599

136100
```java
137101
public class FreezeMainMenu extends Menu {
138102

139-
//Make sure to add this constructor that calls the Menu superconstructor
140-
public FreezeMainMenu(AbstractPlayerMenuUtility pmu) {
141-
super(pmu);
103+
public FreezeMainMenu(PlayerMenuUtility playerMenuUtility) {
104+
super(playerMenuUtility);
142105
}
143106

144-
//Override these other methods to give the Menu it's properties and functionality
145107
@Override
146108
public String getMenuName() {
147109
return "Iceberg";
148110
}
149111

150-
//Max is 54 slots
151112
@Override
152113
public int getSlots() {
153114
return 9;
154115
}
155116

156-
//Return true for this if you want it so that the player cannot
157-
//move any items in the menu
158117
@Override
159118
public boolean cancelAllClicks() {
160119
return true;
161120
}
162121

163-
//This method is used to handle the clicks of this Menu,
164-
//you can see what items they clicked on and then handle it
165-
//accordingly.
166122
@Override
167123
public void handleMenu(InventoryClickEvent e) throws MenuManagerNotSetupException, MenuManagerException {
168124

169125
switch (e.getCurrentItem().getType()){
170126
case PACKED_ICE:
171127

172-
MenuManager.openMenu(FreezeListMenu.class, pmu);
128+
MenuManager.openMenu(FreezeListMenu.class, playerMenuUtility.getOwner());
173129

174130
break;
175131
case LAVA_BUCKET:
176132

177-
MenuManager.openMenu(MeltListMenu.class, pmu);
133+
MenuManager.openMenu(MeltListMenu.class, playerMenuUtility.getOwner());
178134

179135
break;
180136
}
181137

182138
}
183139

184-
//This is how you decide what items go into the menu and where.
185-
//inventory is obtained from the Menu superclass.
186140
@Override
187141
public void setMenuItems() {
188142

@@ -196,68 +150,68 @@ public class FreezeMainMenu extends Menu {
196150
}
197151
```
198152

199-
**How to Open Menus for a Player(Without Data Transfer)**:
153+
**How to Open Menus for a Player**:
200154

201155
This can be called anywhere. Just provide the correct arguments!
202156
```java
203-
MenuManager.openMenu(FreezeListMenu.class, pmu);
157+
MenuManager.openMenu(FreezeListMenu.class, player);
204158
```
205159
Provide the .class of the Menu Class you want to open for the player,
206-
and then provide an instance of PlayerMenuUtility. If you are already
207-
within another Menu, pmu is provided by the superclass. If you are outside
208-
of that, you will need to obtain a PlayerMenuUtility instance.
209-
210-
Outside of a Menu Example:
160+
and then provide an instance of the player to open it for.
211161

162+
**Storing Data in the PlayerMenuUtility to be passed between Menus:**
212163
```java
213-
@Override
214-
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
215-
216-
if (sender instanceof Player){
217-
218-
Player p = (Player) sender;
219-
220-
try {
221-
MenuManager.openMenu(FreezeMainMenu.class, MenuManager.getPlayerMenuUtility(p));
222-
} catch (MenuManagerException | MenuManagerNotSetupException e) {
223-
e.printStackTrace();
164+
@Override
165+
public void handleMenu(InventoryClickEvent e) throws MenuManagerNotSetupException, MenuManagerException {
166+
167+
switch (e.getCurrentItem().getType()){
168+
case PLAYER_HEAD:
169+
170+
Player target = Bukkit.getPlayer(ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName()));
171+
172+
playerMenuUtility.setData("playerToFreeze", target);
173+
174+
MenuManager.openMenu(ConfirmFreezeMenu.class, playerMenuUtility.getOwner());
175+
176+
break;
224177
}
225178

226179
}
227-
228-
return true;
229-
}
230180
```
231-
As you can see, the PlayerMenuUtility can be obtained from calling MenuManager.getPlayerMenuUtility()
232-
and passing in the player you want to open it for.
233-
234-
**How to Open Menus for a Player(With Data Transfer)**:
235181

182+
**Retrieving Data from the PlayerMenuUtility:**
236183
```java
237184
@Override
238185
public void handleMenu(InventoryClickEvent e) throws MenuManagerNotSetupException, MenuManagerException {
239186

240-
//Since you are doing a transfer of data, cast the AbstractPlayerMenuUtility into the PlayerMenuUtility you created.
241-
PlayerMenuUtility playerMenuUtility = (PlayerMenuUtility) pmu;
242-
243187
switch (e.getCurrentItem().getType()){
244-
case PLAYER_HEAD:
188+
case GREEN_BANNER:
245189

246-
Player target = Bukkit.getPlayer(ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName()));
190+
Player target = playerMenuUtility.getData("playerToFreeze", Player.class);
247191

248-
playerMenuUtility.setPlayerToFreeze(target);
192+
playerMenuUtility.getOwner().closeInventory();
193+
playerMenuUtility.getOwner().sendMessage(target.getDisplayName() + " has been frozen.");
249194

250-
MenuManager.openMenu(ConfirmFreezeMenu.class, playerMenuUtility);
195+
IcebergMenuManagerModule.getFrozenPlayers().add(target);
251196

197+
break;
198+
case RED_BANNER:
199+
MenuManager.openMenu(FreezeListMenu.class, playerMenuUtility.getOwner());
252200
break;
253201
}
254202

255203
}
256204
```
257205

258-
You only have to convert an AbstractPlayerMenuUtility into yours when you need to transfer data into the new menu being opened.
206+
I recommend also making an Enum to go along with your Menus that correspond to the data you will be storing in the PMC(PlayerMenuUtility), it will make it easier to remember and pass in the keys.
207+
```java
208+
public enum PMUData {
209+
PLAYER_TO_FREEZE,
210+
PLAYER_TO_MELT
211+
}
212+
```
259213

260-
To transfer data, simply call and use the setter methods you defined like done above.
214+
These enumerators can be passed into the PMC instead of a String key, they will be converted to a String internally.
261215

262216
## Command Manager
263217
*Video*: https://youtu.be/NFYg9Tmk-vo

0 commit comments

Comments
 (0)