Skip to content

Commit

Permalink
Exact fix for #354
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorinwasher committed Jun 10, 2024
1 parent e2cda20 commit 339fbba
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.sgrewritten.stargate.database;

import org.bukkit.Bukkit;
import org.sgrewritten.stargate.Stargate;
import org.sgrewritten.stargate.api.StargateAPI;
import org.sgrewritten.stargate.api.config.ConfigurationOption;
Expand Down Expand Up @@ -327,7 +328,9 @@ private void registerPortalGate(PortalData portalData, Network network, Stargate
}
gate.assignPortal(portal);
network.addPortal(portal);
new StargatePortalLoadEvent(portal).callEvent();
StargatePortalLoadEvent event = new StargatePortalLoadEvent(portal);
Bukkit.getPluginManager().callEvent(event);

Stargate.log(Level.FINEST, "Added as normal portal: " + network.getId() + ":" + portal.getName());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.sgrewritten.stargate.listener;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
Expand Down Expand Up @@ -171,16 +172,17 @@ public void onSignChange(SignChangeEvent event) {
portalBuilder.addEventHandling(player).addMessageReceiver(player).addPermissionCheck(player).setCost(ConfigurationHelper.getDouble(ConfigurationOption.CREATION_COST), player);
portalBuilder.setDestination(destinationName).setAdaptiveGatePositionGeneration(true).setDestinationServerName(networkOrServerName);
StargatePreCreatePortalEvent builderEvent = new StargatePreCreatePortalEvent(portalBuilder, gateBuilder, event.getLines(), player);
if (builderEvent.callEvent()) {
Bukkit.getPluginManager().callEvent(builderEvent);
if (!builderEvent.isCancelled()) {
portalBuilder.build();
}
} catch (NoFormatFoundException ignored) {

} catch (GateConflictException e){
} catch (GateConflictException e) {
MessageUtils.sendMessage(player, languageManager.getErrorMessage(TranslatableMessage.GATE_CONFLICT));
} catch(TranslatableException e) {
} catch (TranslatableException e) {
MessageUtils.sendMessage(player, e.getLocalisedMessage(languageManager));
} catch(InvalidStructureException ignored){
} catch (InvalidStructureException ignored) {
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.sgrewritten.stargate.util;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
Expand All @@ -20,7 +21,7 @@

public class BlockEventHelper {

private BlockEventHelper(){
private BlockEventHelper() {
throw new IllegalStateException("Utility class");
}

Expand All @@ -39,7 +40,8 @@ public static boolean onAnyBlockChangeEvent(Cancellable event, BlockEventType ty
}
if (type.canDestroyPortal()) {
StargateDestroyPortalEvent stargateDestroyPortalEvent = new StargateDestroyPortalEvent(portal, type);
if(stargateDestroyPortalEvent.callEvent()) {
Bukkit.getPluginManager().callEvent(stargateDestroyPortalEvent);
if (!stargateDestroyPortalEvent.isCancelled()) {
stargateAPI.getNetworkManager().destroyPortal(portal);
return true;
}
Expand All @@ -65,14 +67,14 @@ public static List<Block> getBlockList(List<BlockState> blockStates) {
/**
* Does event handling for any event that changes multiple block
*
* @param event <p>The event to possibly cancel</p>
* @param type <p>The type of event</p>
* @param blocks <p>The blocks affected</p>
* @param event <p>The event to possibly cancel</p>
* @param type <p>The type of event</p>
* @param blocks <p>The blocks affected</p>
*/
public static void onAnyMultiBlockChangeEvent(Cancellable event, BlockEventType type, List<Block> blocks, StargateAPI stargateAPI) {
Set<RealPortal> affectedPortals = new HashSet<>();
boolean canDestroy = type.canDestroyPortal();
if(type == BlockEventType.BLOCK_EXPLODE || type == BlockEventType.ENTITY_EXPLODE){
if (type == BlockEventType.BLOCK_EXPLODE || type == BlockEventType.ENTITY_EXPLODE) {
canDestroy = ConfigurationHelper.getBoolean(ConfigurationOption.DESTROY_ON_EXPLOSION);
}
for (Block block : blocks) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public static void sendMessage(@Nullable Entity receiver, String message) {
}
StargateComponent component = new StargateComponent(message);
StargateMessageEvent event = new StargateMessageEvent(component);
if (event.callEvent()) {
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
sendMessageWithoutCheck(receiver, event.getMessage());
}
}
Expand Down

0 comments on commit 339fbba

Please sign in to comment.