Skip to content

Commit 8f56c1a

Browse files
More Control listener cleanup
1 parent 4ff409f commit 8f56c1a

19 files changed

+616
-394
lines changed

src/main/java/me/eccentric_nz/TARDIS/control/TARDISControlListener.java

+48-337
Large diffs are not rendered by default.

src/main/java/me/eccentric_nz/TARDIS/control/TARDISControlMenuListener.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
import me.eccentric_nz.TARDIS.commands.tardis.TARDISRebuildCommand;
2929
import me.eccentric_nz.TARDIS.companionGUI.TARDISCompanionAddInventory;
3030
import me.eccentric_nz.TARDIS.companionGUI.TARDISCompanionInventory;
31+
import me.eccentric_nz.TARDIS.control.actions.FastReturnAction;
32+
import me.eccentric_nz.TARDIS.control.actions.LightSwitchAction;
33+
import me.eccentric_nz.TARDIS.control.actions.SiegeAction;
3134
import me.eccentric_nz.TARDIS.database.data.Tardis;
3235
import me.eccentric_nz.TARDIS.database.resultset.*;
3336
import me.eccentric_nz.TARDIS.enumeration.COMPASS;
@@ -268,12 +271,8 @@ public void onControlMenuInteract(InventoryClickEvent event) {
268271
}
269272
case 13 -> {
270273
// siege
271-
if (tcc != null && !tcc.hasMaterialisation()) {
272-
plugin.getMessenger().send(player, TardisModule.TARDIS, "NO_MAT_CIRCUIT");
273-
return;
274-
}
275274
close(player, true);
276-
new TARDISSiegeButton(plugin, player, tardis.isPowered_on(), id).clickButton();
275+
new SiegeAction(plugin).clickButton(tcc, player, tardis.isPowered_on(), id);
277276
}
278277
case 15 -> {
279278
// scanner
@@ -341,7 +340,7 @@ public void onControlMenuInteract(InventoryClickEvent event) {
341340
return;
342341
}
343342
close(player, false);
344-
new TARDISFastReturnButton(plugin, player, id, level).clickButton();
343+
new FastReturnAction(plugin).clickButton(player, id, tardis);
345344
}
346345
case 29 -> {
347346
// light switch
@@ -354,7 +353,7 @@ public void onControlMenuInteract(InventoryClickEvent event) {
354353
return;
355354
}
356355
close(player, true);
357-
new TARDISLightSwitch(plugin, id, lights, player, tardis.getSchematic().getLights()).flickSwitch();
356+
new LightSwitchAction(plugin, id, lights, player, tardis.getSchematic().getLights()).flickSwitch();
358357
}
359358
case 31 -> {
360359
// rebuild
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package me.eccentric_nz.TARDIS.control.actions;
2+
3+
import me.eccentric_nz.TARDIS.ARS.TARDISARSInventory;
4+
import me.eccentric_nz.TARDIS.TARDIS;
5+
import me.eccentric_nz.TARDIS.advanced.TARDISCircuitChecker;
6+
import me.eccentric_nz.TARDIS.blueprints.TARDISPermission;
7+
import me.eccentric_nz.TARDIS.control.TARDISThemeButton;
8+
import me.eccentric_nz.TARDIS.database.data.Tardis;
9+
import me.eccentric_nz.TARDIS.enumeration.TardisModule;
10+
import net.md_5.bungee.api.ChatColor;
11+
import org.bukkit.entity.Player;
12+
import org.bukkit.inventory.Inventory;
13+
import org.bukkit.inventory.ItemStack;
14+
15+
public class ARSAction {
16+
private final TARDIS plugin;
17+
18+
public ARSAction(TARDIS plugin) {
19+
this.plugin = plugin;
20+
}
21+
22+
public void openGUI(Player player, Tardis tardis, TARDISCircuitChecker tcc, int id) {
23+
if (!tardis.isHandbrake_on()) {
24+
plugin.getMessenger().send(player, TardisModule.TARDIS, "ARS_NO_TRAVEL");
25+
return;
26+
}
27+
// check they're in a compatible world
28+
if (!plugin.getUtils().canGrowRooms(tardis.getChunk())) {
29+
plugin.getMessenger().send(player, TardisModule.TARDIS, "ROOM_OWN_WORLD");
30+
return;
31+
}
32+
if (player.isSneaking()) {
33+
// check they have permission to change the desktop
34+
if (!TARDISPermission.hasPermission(player, "tardis.upgrade")) {
35+
plugin.getMessenger().send(player, TardisModule.TARDIS, "NO_PERM_UPGRADE");
36+
return;
37+
}
38+
if (tcc != null && !tcc.hasARS() && !plugin.getUtils().inGracePeriod(player, true)) {
39+
plugin.getMessenger().send(player, TardisModule.TARDIS, "ARS_MISSING");
40+
return;
41+
}
42+
// upgrade menu
43+
new TARDISThemeButton(plugin, player, tardis.getSchematic(), tardis.getArtron_level(), id).clickButton();
44+
} else {
45+
// check they have permission to grow rooms
46+
if (!TARDISPermission.hasPermission(player, "tardis.architectural")) {
47+
plugin.getMessenger().send(player, TardisModule.TARDIS, "NO_PERM_ROOMS");
48+
return;
49+
}
50+
if (tcc != null && !tcc.hasARS() && !plugin.getUtils().inGracePeriod(player, true)) {
51+
plugin.getMessenger().send(player, TardisModule.TARDIS, "ARS_MISSING");
52+
return;
53+
}
54+
ItemStack[] tars = new TARDISARSInventory(plugin, player).getARS();
55+
Inventory ars = plugin.getServer().createInventory(player, 54, ChatColor.DARK_RED + "Architectural Reconfiguration");
56+
ars.setContents(tars);
57+
player.openInventory(ars);
58+
}
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package me.eccentric_nz.TARDIS.control.actions;
2+
3+
import me.eccentric_nz.TARDIS.TARDIS;
4+
import me.eccentric_nz.TARDIS.database.data.Tardis;
5+
import me.eccentric_nz.TARDIS.hads.TARDISCloisterBell;
6+
7+
public class CloisterBellAction {
8+
9+
private final TARDIS plugin;
10+
11+
public CloisterBellAction(TARDIS plugin) {
12+
this.plugin = plugin;
13+
}
14+
15+
public void ring(int id, Tardis tardis) {
16+
if (plugin.getTrackerKeeper().getCloisterBells().containsKey(id)) {
17+
plugin.getServer().getScheduler().cancelTask(plugin.getTrackerKeeper().getCloisterBells().get(id));
18+
plugin.getTrackerKeeper().getCloisterBells().remove(id);
19+
} else {
20+
TARDISCloisterBell bell = new TARDISCloisterBell(plugin, Integer.MAX_VALUE, id, plugin.getServer().getPlayer(tardis.getUuid()));
21+
int taskID = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, bell, 2L, 70L);
22+
bell.setTask(taskID);
23+
plugin.getTrackerKeeper().getCloisterBells().put(id, taskID);
24+
}
25+
}
26+
}

src/main/java/me/eccentric_nz/TARDIS/utility/TARDISCustardCreamDispenser.java src/main/java/me/eccentric_nz/TARDIS/control/actions/CustardCreamAction.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
* You should have received a copy of the GNU General Public License
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
17-
package me.eccentric_nz.TARDIS.utility;
17+
package me.eccentric_nz.TARDIS.control.actions;
1818

19-
import java.util.HashMap;
2019
import me.eccentric_nz.TARDIS.TARDIS;
2120
import me.eccentric_nz.TARDIS.artron.TARDISArtronLevels;
2221
import me.eccentric_nz.TARDIS.enumeration.TardisModule;
@@ -29,14 +28,16 @@
2928
import org.bukkit.inventory.meta.ItemMeta;
3029
import org.bukkit.util.Vector;
3130

32-
public class TARDISCustardCreamDispenser {
31+
import java.util.HashMap;
32+
33+
public class CustardCreamAction {
3334

3435
private final TARDIS plugin;
3536
private final Player player;
3637
private final Block block;
3738
private final int id;
3839

39-
public TARDISCustardCreamDispenser(TARDIS plugin, Player player, Block block, int id) {
40+
public CustardCreamAction(TARDIS plugin, Player player, Block block, int id) {
4041
this.plugin = plugin;
4142
this.player = player;
4243
this.block = block;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package me.eccentric_nz.TARDIS.control.actions;
2+
3+
import me.eccentric_nz.TARDIS.TARDIS;
4+
import me.eccentric_nz.TARDIS.TARDISConstants;
5+
import me.eccentric_nz.TARDIS.advanced.TARDISSerializeInventory;
6+
import me.eccentric_nz.TARDIS.customblocks.TARDISDisplayItem;
7+
import me.eccentric_nz.TARDIS.customblocks.TARDISDisplayItemUtils;
8+
import me.eccentric_nz.TARDIS.database.resultset.ResultSetDiskStorage;
9+
import me.eccentric_nz.TARDIS.enumeration.GlowstoneCircuit;
10+
import me.eccentric_nz.TARDIS.enumeration.Storage;
11+
import me.eccentric_nz.TARDIS.enumeration.TardisModule;
12+
import me.eccentric_nz.TARDIS.floodgate.TARDISFloodgate;
13+
import me.eccentric_nz.TARDIS.utility.TARDISStaticUtils;
14+
import org.bukkit.Material;
15+
import org.bukkit.block.Block;
16+
import org.bukkit.entity.Player;
17+
import org.bukkit.inventory.Inventory;
18+
import org.bukkit.inventory.ItemStack;
19+
import org.bukkit.inventory.meta.ItemMeta;
20+
21+
import java.io.IOException;
22+
import java.util.HashMap;
23+
import java.util.UUID;
24+
25+
public class DiskStorageAction {
26+
27+
private final TARDIS plugin;
28+
29+
public DiskStorageAction(TARDIS plugin) {
30+
this.plugin = plugin;
31+
}
32+
33+
public void openGUI(UUID ownerUUID, Player player, int id, Block block) {
34+
UUID playerUUID = player.getUniqueId();
35+
if (plugin.getTrackerKeeper().getUpdatePlayers().containsKey(playerUUID)) {
36+
return;
37+
}
38+
// only the time lord of this tardis
39+
if (!ownerUUID.equals(playerUUID)) {
40+
plugin.getMessenger().send(player, TardisModule.TARDIS, "NOT_OWNER");
41+
return;
42+
}
43+
// do they have a storage record?
44+
HashMap<String, Object> wherestore = new HashMap<>();
45+
wherestore.put("uuid", playerUUID);
46+
ResultSetDiskStorage rsstore = new ResultSetDiskStorage(plugin, wherestore);
47+
ItemStack[] stack = new ItemStack[54];
48+
if (rsstore.resultSet()) {
49+
try {
50+
if (!rsstore.getSavesOne().isEmpty()) {
51+
stack = TARDISSerializeInventory.itemStacksFromString(rsstore.getSavesOne());
52+
} else {
53+
stack = TARDISSerializeInventory.itemStacksFromString(Storage.SAVE_1.getEmpty());
54+
}
55+
} catch (IOException ex) {
56+
plugin.debug("Could not get Storage Inventory: " + ex.getMessage());
57+
}
58+
} else {
59+
try {
60+
stack = TARDISSerializeInventory.itemStacksFromString(Storage.SAVE_1.getEmpty());
61+
for (ItemStack is : stack) {
62+
if (is != null && is.hasItemMeta()) {
63+
ItemMeta im = is.getItemMeta();
64+
if (im.hasDisplayName()) {
65+
if (is.getType().equals(Material.FILLED_MAP)) {
66+
GlowstoneCircuit glowstone = GlowstoneCircuit.getByName().get(im.getDisplayName());
67+
if (glowstone != null) {
68+
im.setCustomModelData(glowstone.getCustomModelData());
69+
is.setType(Material.GLOWSTONE_DUST);
70+
is.setItemMeta(im);
71+
}
72+
} else {
73+
if (TARDISStaticUtils.isMusicDisk(is)) {
74+
im.setCustomModelData(10000001);
75+
} else if (is.getType().equals(Material.LIME_WOOL)) {
76+
im.setCustomModelData(86);
77+
is.setType(Material.BOWL);
78+
is.setItemMeta(im);
79+
} else if (is.getType().equals(Material.RED_WOOL)) {
80+
im.setCustomModelData(87);
81+
is.setType(Material.BOWL);
82+
is.setItemMeta(im);
83+
} else if (is.getType().equals(Material.GLOWSTONE_DUST) && !im.hasCustomModelData() && im.getDisplayName().equals("Circuits")) {
84+
im.setCustomModelData(10001985);
85+
}
86+
is.setItemMeta(im);
87+
}
88+
}
89+
}
90+
}
91+
} catch (IOException ex) {
92+
plugin.debug("Could not get default Storage Inventory: " + ex.getMessage());
93+
}
94+
// make a record
95+
HashMap<String, Object> setstore = new HashMap<>();
96+
setstore.put("uuid", player.getUniqueId().toString());
97+
setstore.put("tardis_id", id);
98+
plugin.getQueryFactory().doInsert("storage", setstore);
99+
}
100+
Inventory inv = plugin.getServer().createInventory(player, 54, Storage.SAVE_1.getTitle());
101+
inv.setContents(stack);
102+
player.openInventory(inv);
103+
// update note block if it's not BARRIER + Item Display
104+
if (!TARDISFloodgate.isFloodgateEnabled() || !TARDISFloodgate.isBedrockPlayer(player.getUniqueId())) {
105+
if (block.getType().equals(Material.NOTE_BLOCK) || block.getType().equals(Material.MUSHROOM_STEM)) {
106+
block.setBlockData(TARDISConstants.BARRIER, true);
107+
TARDISDisplayItemUtils.set(TARDISDisplayItem.DISK_STORAGE, block);
108+
}
109+
}
110+
}
111+
}

src/main/java/me/eccentric_nz/TARDIS/control/TARDISFastReturnButton.java src/main/java/me/eccentric_nz/TARDIS/control/actions/FastReturnAction.java

+15-12
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
* You should have received a copy of the GNU General Public License
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
17-
package me.eccentric_nz.TARDIS.control;
17+
package me.eccentric_nz.TARDIS.control.actions;
1818

19-
import java.util.HashMap;
2019
import me.eccentric_nz.TARDIS.TARDIS;
2120
import me.eccentric_nz.TARDIS.api.event.TARDISTravelEvent;
21+
import me.eccentric_nz.TARDIS.database.data.Tardis;
2222
import me.eccentric_nz.TARDIS.database.resultset.ResultSetBackLocation;
2323
import me.eccentric_nz.TARDIS.database.resultset.ResultSetCurrentLocation;
2424
import me.eccentric_nz.TARDIS.enumeration.TardisModule;
@@ -27,26 +27,29 @@
2727
import me.eccentric_nz.TARDIS.travel.TravelCostAndType;
2828
import org.bukkit.entity.Player;
2929

30+
import java.util.HashMap;
31+
3032
/**
3133
* @author eccentric_nz
3234
*/
33-
public class TARDISFastReturnButton {
35+
public class FastReturnAction {
3436

3537
private final TARDIS plugin;
36-
private final Player player;
37-
private final int id;
38-
private final int level;
3938

40-
public TARDISFastReturnButton(TARDIS plugin, Player player, int id, int level) {
39+
public FastReturnAction(TARDIS plugin) {
4140
this.plugin = plugin;
42-
this.player = player;
43-
this.id = id;
44-
this.level = level;
4541
}
4642

47-
public void clickButton() {
43+
public void clickButton(Player player, int id, Tardis tardis) {
44+
if (plugin.getTrackerKeeper().getMaterialising().contains(id) || plugin.getTrackerKeeper().getDematerialising().contains(id) || (!tardis.isHandbrake_on() && !plugin.getTrackerKeeper().getDestinationVortex().containsKey(id)) || plugin.getTrackerKeeper().getHasRandomised().contains(id)) {
45+
plugin.getMessenger().send(player, TardisModule.TARDIS, "NOT_WHILE_TRAVELLING");
46+
return;
47+
}
48+
if (plugin.getTrackerKeeper().getDestinationVortex().containsKey(id)) {
49+
plugin.getTrackerKeeper().getHasRandomised().add(id);
50+
}
4851
int cost = plugin.getArtronConfig().getInt("travel");
49-
if (level < cost) {
52+
if (tardis.getArtron_level() < cost) {
5053
plugin.getMessenger().send(player, TardisModule.TARDIS, "NOT_ENOUGH_ENERGY");
5154
return;
5255
}

src/main/java/me/eccentric_nz/TARDIS/control/TARDISLightSwitch.java src/main/java/me/eccentric_nz/TARDIS/control/actions/LightSwitchAction.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,27 @@
1414
* You should have received a copy of the GNU General Public License
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
17-
package me.eccentric_nz.TARDIS.control;
17+
package me.eccentric_nz.TARDIS.control.actions;
1818

19-
import java.util.HashMap;
2019
import me.eccentric_nz.TARDIS.TARDIS;
2120
import me.eccentric_nz.TARDIS.artron.TARDISLampToggler;
2221
import me.eccentric_nz.TARDIS.enumeration.TardisLight;
2322
import org.bukkit.entity.Player;
2423

24+
import java.util.HashMap;
25+
2526
/**
2627
* @author eccentric_nz
2728
*/
28-
public class TARDISLightSwitch {
29+
public class LightSwitchAction {
2930

3031
private final TARDIS plugin;
3132
private final int id;
3233
private final boolean on;
3334
private final Player player;
3435
private final TardisLight light;
3536

36-
public TARDISLightSwitch(TARDIS plugin, int id, boolean on, Player player, TardisLight light) {
37+
public LightSwitchAction(TARDIS plugin, int id, boolean on, Player player, TardisLight light) {
3738
this.plugin = plugin;
3839
this.id = id;
3940
this.on = on;

0 commit comments

Comments
 (0)