Skip to content

Commit 651ee79

Browse files
authored
Merge pull request #2 from hashtek-mc/dev
Destroy handler implementation
2 parents 85e6ffb + f6d36a0 commit 651ee79

20 files changed

+379
-52
lines changed

src/main/java/fr/hashtek/spigot/hashgui/PaginatedHashGui.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class PaginatedHashGui extends HashGui
2727
*
2828
* @param title GUI's title
2929
* @param size GUI's amount of lines (must be between 1 and 6).
30-
* @param guiManager Gui manager
30+
* @param guiManager GUI manager
3131
*/
3232
public PaginatedHashGui(String title, int size, HashGuiManager guiManager)
3333
{

src/main/java/fr/hashtek/spigot/hashgui/handler/click/HashGuiClick.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class HashGuiClick
1515

1616

1717
/**
18-
* Creates a new instance of HashGUIClick.
18+
* Creates a new instance of HashGuiClick.
1919
*/
2020
public HashGuiClick()
2121
{
@@ -58,7 +58,7 @@ public HashGuiClick addClickHandler(HashItem item)
5858
final ItemMeta meta = item.getItemStack().getItemMeta();
5959
final String itemName = meta.getDisplayName();
6060

61-
for (ClickHandler handler : item.getClickHandlers())
61+
for (ClickHandler handler : clickHandlers)
6262
this.addClickHandler(itemName, handler);
6363

6464
return this;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package fr.hashtek.spigot.hashgui.handler.destroy;
2+
3+
import org.bukkit.block.Block;
4+
import org.bukkit.entity.Player;
5+
import org.bukkit.inventory.ItemStack;
6+
7+
public interface DestroyAction
8+
{
9+
10+
/**
11+
* Function called when a block is destroyed using a
12+
* specific item.
13+
*
14+
* @param player Player who destroyed the block
15+
* @param item Used item
16+
* @param block Destroyed block
17+
*/
18+
void execute(
19+
Player player,
20+
ItemStack item,
21+
Block block
22+
);
23+
24+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package fr.hashtek.spigot.hashgui.handler.destroy;
2+
3+
public class DestroyHandler
4+
{
5+
6+
private DestroyAction destroyAction;
7+
8+
9+
/**
10+
* Creates an empty instance of DestroyHandler.
11+
*/
12+
public DestroyHandler() {}
13+
14+
15+
/**
16+
* Sets handler's destroy action. (on block destroy, then do...)
17+
*
18+
* @param destroyAction Destroy action
19+
* @return Returns itself.
20+
*/
21+
public DestroyHandler setDestroyAction(DestroyAction destroyAction)
22+
{
23+
this.destroyAction = destroyAction;
24+
return this;
25+
}
26+
27+
/**
28+
* @param handler Handler to compare
29+
* @return Returns true if both handlers contains the same instructions
30+
*/
31+
public boolean equals(DestroyHandler handler)
32+
{
33+
return this.destroyAction.equals(handler.destroyAction);
34+
}
35+
36+
37+
/**
38+
* @return Assigned action
39+
*/
40+
public DestroyAction getDestroyAction()
41+
{
42+
return this.destroyAction;
43+
}
44+
45+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package fr.hashtek.spigot.hashgui.handler.destroy;
2+
3+
import fr.hashtek.spigot.hashitem.HashItem;
4+
import org.bukkit.inventory.meta.ItemMeta;
5+
6+
import java.util.ArrayList;
7+
import java.util.HashMap;
8+
import java.util.List;
9+
10+
public class HashGuiDestroy
11+
{
12+
13+
private final HashMap<String, ArrayList<DestroyHandler>> destroyHandlers;
14+
15+
16+
/**
17+
* Creates a new instance of HashGuiDestroy.
18+
*/
19+
public HashGuiDestroy()
20+
{
21+
this.destroyHandlers = new HashMap<String, ArrayList<DestroyHandler>>();
22+
}
23+
24+
25+
/**
26+
* Adds a destroy handler for a certain title.
27+
*
28+
* @param title Title
29+
* @param handler Destroy handler
30+
* @return Returns itself.
31+
*/
32+
private HashGuiDestroy addDestroyHandler(String title, DestroyHandler handler)
33+
{
34+
this.destroyHandlers.computeIfAbsent(title, k -> new ArrayList<DestroyHandler>());
35+
36+
for (DestroyHandler h : this.destroyHandlers.get(title))
37+
if (handler.equals(h))
38+
return this;
39+
40+
this.destroyHandlers.get(title).add(handler);
41+
return this;
42+
}
43+
44+
/**
45+
* Adds a destroy handler for an item.
46+
*
47+
* @param item Item
48+
* @return Returns itself.
49+
*/
50+
public HashGuiDestroy addDestroyHandler(HashItem item)
51+
{
52+
List<DestroyHandler> destroyHandlers = item.getDestroyHandlers();
53+
54+
if (destroyHandlers == null || destroyHandlers.isEmpty())
55+
return this;
56+
57+
final ItemMeta meta = item.getItemStack().getItemMeta();
58+
final String itemName = meta.getDisplayName();
59+
60+
for (DestroyHandler handler: destroyHandlers)
61+
this.addDestroyHandler(itemName, handler);
62+
63+
return this;
64+
}
65+
66+
67+
/**
68+
* @return Registered interact handlers
69+
*/
70+
public HashMap<String, ArrayList<DestroyHandler>> getDestroyHandlers()
71+
{
72+
return this.destroyHandlers;
73+
}
74+
75+
}

src/main/java/fr/hashtek/spigot/hashgui/handler/hit/HashGuiHit.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class HashGuiHit
1414

1515

1616
/**
17-
* Creates a new instance of HashGUIInteraction.
17+
* Creates a new instance of HashGuiHit.
1818
*/
1919
public HashGuiHit()
2020
{
@@ -26,7 +26,7 @@ public HashGuiHit()
2626
* Adds a hit handler for a certain title.
2727
*
2828
* @param title Title
29-
* @param handler Interaction handler
29+
* @param handler Hit handler
3030
* @return Returns itself.
3131
*/
3232
private HashGuiHit addHitHandler(String title, HitHandler handler)
@@ -57,15 +57,15 @@ public HashGuiHit addHitHandler(HashItem item)
5757
final ItemMeta meta = item.getItemStack().getItemMeta();
5858
final String itemName = meta.getDisplayName();
5959

60-
for (HitHandler handler: item.getHitHandlers())
60+
for (HitHandler handler: hitHandlers)
6161
this.addHitHandler(itemName, handler);
6262

6363
return this;
6464
}
6565

6666

6767
/**
68-
* @return Registered interact handlers
68+
* @return Registered hit handlers
6969
*/
7070
public HashMap<String, ArrayList<HitHandler>> getHitHandlers()
7171
{

src/main/java/fr/hashtek/spigot/hashgui/handler/hit/HitAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ public interface HitAction
1010
* Function called when item is used in a hit.
1111
*
1212
* @param attacker Player who hit
13-
* @param victim Player who got hit
14-
* @param item Used item
13+
* @param victim Player who got hit
14+
* @param item Used item
1515
*/
1616
void execute(
1717
Player attacker,

src/main/java/fr/hashtek/spigot/hashgui/handler/hit/HitHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class HitHandler
88

99

1010
/**
11-
* Creates an empty instance of InteractHandler.
11+
* Creates an empty instance of HitHandler.
1212
*/
1313
public HitHandler()
1414
{

src/main/java/fr/hashtek/spigot/hashgui/handler/hold/HashGuiHold.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ private HashGuiHold addHoldHandler(String title, HoldHandler handler)
5353
*/
5454
public HashGuiHold addHoldHandler(HashItem item)
5555
{
56-
List<HoldHandler> clickHandlers = item.getHoldHandlers();
56+
List<HoldHandler> holdHandlers = item.getHoldHandlers();
5757

58-
if (clickHandlers == null || clickHandlers.isEmpty())
58+
if (holdHandlers == null || holdHandlers.isEmpty())
5959
return this;
6060

6161
final ItemMeta meta = item.getItemStack().getItemMeta();
6262
final String itemName = meta.getDisplayName();
6363

64-
for (HoldHandler handler : item.getHoldHandlers())
64+
for (HoldHandler handler : holdHandlers)
6565
this.addHoldHandler(itemName, handler);
6666

6767
return this;

src/main/java/fr/hashtek/spigot/hashgui/handler/hold/HoldHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class HoldHandler
88

99

1010
/**
11-
* Creates an empty instance of ClickHandler.
11+
* Creates an empty instance of HoldHandler.
1212
*/
1313
public HoldHandler() {}
1414

@@ -38,7 +38,7 @@ public HoldHandler setNotHoldAction(HoldAction notHoldAction)
3838
}
3939

4040
/**
41-
* @param handler Handler to compare
41+
* @param handler Handler to compare
4242
* @return Returns true if both handlers contains the same instructions
4343
*/
4444
public boolean equals(HoldHandler handler)

0 commit comments

Comments
 (0)