Skip to content

Commit 7be8f7e

Browse files
committed
Fully convert to MV5 api
1 parent b4c368a commit 7be8f7e

File tree

8 files changed

+201
-156
lines changed

8 files changed

+201
-156
lines changed

build.gradle

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ repositories {
2828
name = 'onarandombox'
2929
url = uri('https://repo.onarandombox.com/content/groups/public/')
3030
}
31+
32+
maven {
33+
// todo: remove before mv5 release
34+
name = 'benwoo1110'
35+
url = uri('https://repo.c0ding.party/multiverse-beta')
36+
}
3137
}
3238

3339
dependencies {
@@ -37,7 +43,7 @@ dependencies {
3743
}
3844

3945
// Core
40-
implementation 'org.mvplugins.multiverse.core:multiverse-core:local'
46+
implementation 'org.mvplugins.multiverse.core:multiverse-core:5.0.0-SNAPSHOT'
4147

4248
// Utils
4349
api('com.dumptruckman.minecraft:Logging:1.1.1') {

src/main/java/org/mvplugins/multiverse/signportals/MultiverseSignPortals.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
import com.dumptruckman.minecraft.util.Logging;
1111
import org.mvplugins.multiverse.core.MultiverseCore;
12-
import org.mvplugins.multiverse.core.api.MVConfig;
13-
import org.mvplugins.multiverse.core.api.MVCore;
14-
import org.mvplugins.multiverse.core.api.MVPlugin;
12+
import org.mvplugins.multiverse.core.api.config.MVCoreConfig;
1513
import org.mvplugins.multiverse.core.inject.PluginServiceLocator;
14+
import org.mvplugins.multiverse.core.submodules.MVCore;
15+
import org.mvplugins.multiverse.core.submodules.MVPlugin;
1616
import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service;
1717
import org.mvplugins.multiverse.external.vavr.control.Option;
1818
import org.mvplugins.multiverse.external.vavr.control.Try;
@@ -57,7 +57,7 @@ public void onEnable() {
5757

5858
initializeDependencyInjection();
5959
registerEvents();
60-
Logging.setDebugLevel(serviceLocator.getActiveService(MVConfig.class).getGlobalDebug());
60+
Logging.setDebugLevel(serviceLocator.getActiveService(MVCoreConfig.class).getGlobalDebug());
6161

6262
this.core.incrementPluginCount();
6363
Logging.log(true, Level.INFO, " Enabled - By %s", getAuthors());

src/main/java/org/mvplugins/multiverse/signportals/MultiverseSignPortalsPluginBinder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.mvplugins.multiverse.signportals;
22

3-
import org.mvplugins.multiverse.core.api.MVPlugin;
43
import org.mvplugins.multiverse.core.inject.binder.JavaPluginBinder;
4+
import org.mvplugins.multiverse.core.submodules.MVPlugin;
55
import org.mvplugins.multiverse.external.glassfish.hk2.utilities.binding.ScopedBindingBuilder;
66
import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull;
77

src/main/java/org/mvplugins/multiverse/signportals/listeners/MVSPBlockListener.java

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,15 @@
88
package org.mvplugins.multiverse.signportals.listeners;
99

1010
import com.dumptruckman.minecraft.util.Logging;
11-
import org.jetbrains.annotations.NotNull;
11+
import org.bukkit.Bukkit;
12+
import org.bukkit.permissions.Permission;
13+
import org.bukkit.permissions.PermissionDefault;
14+
import org.bukkit.plugin.PluginManager;
15+
import org.mvplugins.multiverse.core.api.destination.DestinationInstance;
16+
import org.mvplugins.multiverse.core.api.destination.DestinationsProvider;
17+
import org.mvplugins.multiverse.core.api.teleportation.SafetyTeleporter;
1218
import org.mvplugins.multiverse.external.jakarta.inject.Inject;
19+
import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull;
1320
import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service;
1421
import org.mvplugins.multiverse.signportals.MultiverseSignPortals;
1522
import org.mvplugins.multiverse.signportals.utils.PortalDetector;
@@ -28,19 +35,30 @@
2835
import org.bukkit.event.block.SignChangeEvent;
2936
import org.bukkit.material.RedstoneTorch;
3037

38+
import static org.mvplugins.multiverse.core.permissions.PermissionUtils.hasPermission;
39+
3140
@Service
3241
public class MVSPBlockListener implements SignPortalsListener {
3342
private final String CREATE_PERM = "multiverse.signportal.create";
3443
private final MultiverseSignPortals plugin;
3544
private final PortalDetector pd;
36-
// private MVPermissions permissions;
45+
private final PortalDetector portalDetector;
46+
private final DestinationsProvider destinationsProvider;
47+
private final SafetyTeleporter safetyTeleporter;
3748

3849
@Inject
39-
public MVSPBlockListener(@NotNull MultiverseSignPortals plugin, @NotNull PortalDetector pd) {
50+
public MVSPBlockListener(@NotNull MultiverseSignPortals plugin,
51+
@NotNull PortalDetector pd,
52+
@NotNull PluginManager pluginManager,
53+
@NotNull PortalDetector portalDetector,
54+
@NotNull DestinationsProvider destinationsProvider,
55+
@NotNull SafetyTeleporter safetyTeleporter) {
4056
this.plugin = plugin;
4157
this.pd = pd;
42-
// this.permissions = this.plugin.getCore().getMVPerms();
43-
// this.permissions.addPermission(CREATE_PERM, PermissionDefault.OP);
58+
this.portalDetector = portalDetector;
59+
this.destinationsProvider = destinationsProvider;
60+
this.safetyTeleporter = safetyTeleporter;
61+
pluginManager.addPermission(new Permission(CREATE_PERM, PermissionDefault.OP));
4462
}
4563

4664
@EventHandler
@@ -80,33 +98,20 @@ public void redstonePower(BlockRedstoneEvent event) {
8098
}
8199

82100
private void takeEntityToDestination(Entity entity, String destString) {
83-
// if (destString != null) {
84-
// SafeTTeleporter teleporter = plugin.getCore().getSafeTTeleporter();
85-
// MVDestination d = plugin.getCore().getDestFactory().getDestination(destString);
86-
// Logging.finer("Found a Destination! (" + d + ")");
87-
// if (entity instanceof Player) {
88-
// Player player = (Player) entity;
89-
// if (plugin.getPortalDetector().playerCanGoToDestination(player, d)) {
90-
// TeleportResult result = teleporter.safelyTeleport(Bukkit.getConsoleSender(), player, d);
91-
// if (result == TeleportResult.FAIL_UNSAFE) {
92-
// Logging.finer("The Destination was not safe! (" + ChatColor.RED + d + ChatColor.WHITE + ")");
93-
// } else {
94-
// Logging.finer("Teleported " + entity + " to: " + ChatColor.GREEN + d);
95-
// }
96-
// } else {
97-
// Logging.finer("Denied permission to go to destination!");
98-
// }
99-
// } else {
100-
// TeleportResult result = teleporter.safelyTeleport(Bukkit.getConsoleSender(), entity, d.getLocation(entity), true);
101-
// if (result == TeleportResult.FAIL_UNSAFE) {
102-
// Logging.finer("The Destination was not safe! (" + ChatColor.RED + d + ChatColor.WHITE + ")");
103-
// } else {
104-
// Logging.finer("Teleported " + entity + " to: " + ChatColor.GREEN + d);
105-
// }
106-
// }
107-
// } else {
108-
// Logging.finer("The destination was not set on the sign!");
109-
// }
101+
if (destString == null) {
102+
Logging.finer("The destination was not set on the sign!");
103+
}
104+
DestinationInstance<?, ?> d = destinationsProvider.parseDestination(destString).getOrNull();
105+
if (d == null) {
106+
Logging.warning("Could not find destination: " + destString);
107+
return;
108+
}
109+
Logging.finer("Found a Destination! (" + d + ")");
110+
safetyTeleporter.to(d)
111+
.by(Bukkit.getConsoleSender())
112+
.teleport(entity)
113+
.onSuccess(() -> Logging.finer("Teleported " + entity + " to: " + ChatColor.GREEN + d))
114+
.onFailure(error -> Logging.warning("Failed to teleport " + entity + " to: " + d + " (" + error + ")"));
110115
}
111116

112117
private Block getNearbySign(Block block, boolean torch) {
@@ -148,11 +153,11 @@ public void onBlockBreak(BlockBreakEvent event) {
148153
if (state instanceof Sign) {
149154
Sign s = (Sign) state;
150155
if (pd.getSignStatus(s) == SignStatus.NetherPortalSign || pd.getSignStatus(s) == SignStatus.SignPortal) {
151-
// if (!this.permissions.hasPermission(event.getPlayer(), CREATE_PERM, true)) {
152-
// event.setCancelled(true);
153-
// event.getPlayer().sendMessage("You don't have permission to destroy a SignPortal!");
154-
// event.getPlayer().sendMessage(ChatColor.GREEN + CREATE_PERM);
155-
// }
156+
if (!hasPermission(event.getPlayer(), CREATE_PERM)) {
157+
event.setCancelled(true);
158+
event.getPlayer().sendMessage("You don't have permission to destroy a SignPortal!");
159+
event.getPlayer().sendMessage(ChatColor.GREEN + CREATE_PERM);
160+
}
156161
}
157162
}
158163
}
@@ -167,16 +172,16 @@ private void checkForHack(SignChangeEvent event) {
167172
}
168173

169174
private void createMultiverseSignPortal(SignChangeEvent event) {
170-
// if (this.plugin.getCore().getMVPerms().hasPermission(event.getPlayer(), "multiverse.signportal.create", true)) {
171-
// Logging.finer("MV SignPortal Created");
172-
// event.setLine(1, ChatColor.DARK_GREEN + event.getLine(1));
173-
// checkRedstoneTeleportTargets(event);
174-
// } else {
175-
// Logging.finer("No Perms to create");
176-
// event.setLine(1, ChatColor.DARK_RED + event.getLine(1));
177-
// event.getPlayer().sendMessage("You don't have permission to create a SignPortal!");
178-
// event.getPlayer().sendMessage(ChatColor.GREEN + CREATE_PERM);
179-
// }
175+
if (hasPermission(event.getPlayer(), "multiverse.signportal.create")) {
176+
Logging.finer("MV SignPortal Created");
177+
event.setLine(1, ChatColor.DARK_GREEN + event.getLine(1));
178+
checkRedstoneTeleportTargets(event);
179+
} else {
180+
Logging.finer("No Perms to create");
181+
event.setLine(1, ChatColor.DARK_RED + event.getLine(1));
182+
event.getPlayer().sendMessage("You don't have permission to create a SignPortal!");
183+
event.getPlayer().sendMessage(ChatColor.GREEN + CREATE_PERM);
184+
}
180185
}
181186

182187
private void checkRedstoneTeleportTargets(SignChangeEvent event) {

src/main/java/org/mvplugins/multiverse/signportals/listeners/MVSPPlayerListener.java

Lines changed: 58 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,15 @@
88
package org.mvplugins.multiverse.signportals.listeners;
99

1010
import com.dumptruckman.minecraft.util.Logging;
11-
import org.jetbrains.annotations.NotNull;
11+
import org.bukkit.Location;
12+
import org.bukkit.permissions.Permission;
13+
import org.bukkit.permissions.PermissionDefault;
14+
import org.bukkit.plugin.PluginManager;
15+
import org.mvplugins.multiverse.core.api.destination.DestinationInstance;
16+
import org.mvplugins.multiverse.core.api.destination.DestinationsProvider;
17+
import org.mvplugins.multiverse.core.api.teleportation.SafetyTeleporter;
1218
import org.mvplugins.multiverse.external.jakarta.inject.Inject;
19+
import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull;
1320
import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service;
1421
import org.mvplugins.multiverse.signportals.MultiverseSignPortals;
1522
import org.mvplugins.multiverse.signportals.exceptions.MoreThanOneSignFoundException;
@@ -24,21 +31,26 @@
2431
import org.bukkit.event.player.PlayerInteractEvent;
2532
import org.bukkit.event.player.PlayerPortalEvent;
2633

34+
import static org.mvplugins.multiverse.core.permissions.PermissionUtils.hasPermission;
35+
2736
@Service
2837
public class MVSPPlayerListener implements SignPortalsListener {
2938

3039
private static final String USE_PERMISSION = "multiverse.signportal.use";
3140
private static final String VALIDATE_PERMISSION = "multiverse.signportal.validate";
32-
private final MultiverseSignPortals plugin;
33-
// private final MVPermissions permissions;
41+
private final DestinationsProvider destinationsProvider;
42+
private final SafetyTeleporter safetyTeleporter;
3443
private final PortalDetector pd;
3544

3645
@Inject
37-
MVSPPlayerListener(@NotNull MultiverseSignPortals plugin, @NotNull PortalDetector pd) {
38-
this.plugin = plugin;
39-
// this.permissions = this.plugin.getCore().getMVPerms();
40-
// this.permissions.addPermission(VALIDATE_PERMISSION, PermissionDefault.OP);
41-
// this.permissions.addPermission(USE_PERMISSION, PermissionDefault.TRUE);
46+
MVSPPlayerListener(@NotNull PortalDetector pd,
47+
@NotNull PluginManager pluginManager,
48+
@NotNull DestinationsProvider destinationsProvider,
49+
@NotNull SafetyTeleporter safetyTeleporter) {
50+
this.destinationsProvider = destinationsProvider;
51+
this.safetyTeleporter = safetyTeleporter;
52+
pluginManager.addPermission(new Permission(VALIDATE_PERMISSION, PermissionDefault.OP));
53+
pluginManager.addPermission(new Permission(USE_PERMISSION, PermissionDefault.TRUE));
4254
this.pd = pd;
4355
}
4456

@@ -55,21 +67,26 @@ public void playerPortal(PlayerPortalEvent event) {
5567
String destString = pd.getNotchPortalDestination(event.getPlayer(), event.getFrom());
5668
if (destString != null) {
5769
Logging.finer("Found a Multiverse Sign");
58-
// DestinationFactory df = this.plugin.getCore().getDestFactory();
59-
// destString = ChatColor.stripColor(destString);
60-
// MVDestination dest = df.getDestination(destString);
61-
// MVSPTravelAgent travelAgent = new MVSPTravelAgent(this.plugin.getCore(), dest, event.getPlayer());
62-
// travelAgent.setPortalEventTravelAgent(event);
63-
// event.setTo(dest.getLocation(event.getPlayer()));
70+
destString = ChatColor.stripColor(destString);
71+
DestinationInstance<?, ?> dest = destinationsProvider.parseDestination(destString).getOrNull();
72+
if (dest == null) {
73+
Logging.warning("Could not find destination: " + destString);
74+
return;
75+
}
76+
Location destLocation = dest.getLocation(event.getPlayer()).getOrNull();
77+
if (destLocation == null) {
78+
Logging.warning("Could not find Location for destination: " + destString);
79+
return;
80+
}
81+
event.setTo(destLocation);
6482
}
6583

6684
} catch (NoMultiverseSignFoundException e) {
6785
// This will simply act as a notch portal.
6886
Logging.finer("Did NOT find a Multiverse Sign");
6987
} catch (MoreThanOneSignFoundException e) {
70-
// this.plugin.getCore().getMessaging().sendMessage(event.getPlayer(),
71-
// String.format("%sSorry %sbut more than 1 sign was found where the second line was [mv] or [multiverse]. Please remove one of the signs.",
72-
// ChatColor.RED, ChatColor.WHITE), false);
88+
event.getPlayer().sendMessage(String.format("%sSorry %sbut more than 1 sign was found where the second line was [mv] or [multiverse]. Please remove one of the signs.",
89+
ChatColor.RED, ChatColor.WHITE));
7390
event.setCancelled(true);
7491
}
7592
}
@@ -102,12 +119,12 @@ public void playerInteract(PlayerInteractEvent event) {
102119
Player player = event.getPlayer();
103120
switch (status) {
104121
case SignPortal:
105-
// if (permissions.hasPermission(player, USE_PERMISSION, false)) {
106-
// String destString = this.pd.processSign(s);
107-
// this.takePlayerToDestination(player, destString);
108-
// } else {
109-
// player.sendMessage(ChatColor.RED + "You do not have the required permission to use SignPortals (" + USE_PERMISSION + ")");
110-
// }
122+
if (hasPermission(player, USE_PERMISSION)) {
123+
String destString = this.pd.processSign(s);
124+
this.takePlayerToDestination(player, destString);
125+
} else {
126+
player.sendMessage(ChatColor.RED + "You do not have the required permission to use SignPortals (" + USE_PERMISSION + ")");
127+
}
111128
event.setCancelled(true);
112129
break;
113130
case Legacy:
@@ -124,23 +141,23 @@ public void playerInteract(PlayerInteractEvent event) {
124141
}
125142

126143
private void takePlayerToDestination(Player player, String destString) {
127-
// if (destString != null) {
128-
// Logging.finer("Found a SignPortal! (" + destString + ")");
129-
// SafeTTeleporter teleporter = this.plugin.getCore().getSafeTTeleporter();
130-
// DestinationFactory df = this.plugin.getCore().getDestFactory();
131-
//
132-
// MVDestination d = df.getDestination(destString);
133-
// Logging.finer("Found a Destination! (" + d + ")");
134-
// if (this.pd.playerCanGoToDestination(player, d)) {
135-
// TeleportResult result = teleporter.safelyTeleport(player, player, d);
136-
// if (result == TeleportResult.FAIL_UNSAFE) {
137-
// player.sendMessage("The Destination was not safe! (" + ChatColor.RED + d + ChatColor.WHITE + ")");
138-
// }
139-
// } else {
140-
// Logging.finer("Denied permission to go to destination!");
141-
// }
142-
// } else {
143-
// player.sendMessage("The Destination was not set on the sign!");
144-
// }
144+
if (destString != null) {
145+
Logging.finer("Found a SignPortal! (" + destString + ")");
146+
DestinationInstance<?, ?> d = destinationsProvider.parseDestination(destString).getOrNull();
147+
if (d == null) {
148+
Logging.warning("Could not find destination: " + destString);
149+
return;
150+
}
151+
Logging.finer("Found a Destination! (" + d + ")");
152+
if (this.pd.playerCanGoToDestination(player, d)) {
153+
safetyTeleporter.to(d).teleport(player)
154+
.onSuccess(() -> player.sendMessage("Teleported " + player.getName() + " to: " + ChatColor.GREEN + d))
155+
.onFailure(result -> player.sendMessage("Could not teleport " + player.getName() + " to: " + ChatColor.RED + d));
156+
} else {
157+
Logging.finer("Denied permission to go to destination!");
158+
}
159+
} else {
160+
player.sendMessage("The Destination was not set on the sign!");
161+
}
145162
}
146163
}

src/main/java/org/mvplugins/multiverse/signportals/listeners/MVSPPluginListener.java

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

88
package org.mvplugins.multiverse.signportals.listeners;
99

10-
import org.jetbrains.annotations.NotNull;
1110
import org.mvplugins.multiverse.external.jakarta.inject.Inject;
11+
import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull;
1212
import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service;
1313
import org.mvplugins.multiverse.signportals.MultiverseSignPortals;
1414
import org.bukkit.event.EventHandler;

0 commit comments

Comments
 (0)