mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-21 11:45:19 +01:00
feat: Add event firing on remove road entity (#3955)
* feat: Add event firing on remove road entity Signed-off-by: ByteExceptionM <git@byteexception.eu> * chore: Add some more entity vars Signed-off-by: ByteExceptionM <git@byteexception.eu> * chore: Rename method Signed-off-by: ByteExceptionM <git@byteexception.eu> * chore: Code cleanup Signed-off-by: ByteExceptionM <git@byteexception.eu> * chore: Code reformat Signed-off-by: ByteExceptionM <git@byteexception.eu> * chore: Change iterator removal Signed-off-by: ByteExceptionM <git@byteexception.eu> * Comply with checkstyle --------- Signed-off-by: ByteExceptionM <git@byteexception.eu> Co-authored-by: Alexander Brandes <mc.cache@web.de>
This commit is contained in:
parent
84567bcb00
commit
5cce86d924
@ -71,6 +71,8 @@ import com.plotsquared.core.configuration.Storage;
|
||||
import com.plotsquared.core.configuration.caption.ChatFormatter;
|
||||
import com.plotsquared.core.configuration.file.YamlConfiguration;
|
||||
import com.plotsquared.core.database.DBFunc;
|
||||
import com.plotsquared.core.events.RemoveRoadEntityEvent;
|
||||
import com.plotsquared.core.events.Result;
|
||||
import com.plotsquared.core.generator.GeneratorWrapper;
|
||||
import com.plotsquared.core.generator.IndependentPlotGenerator;
|
||||
import com.plotsquared.core.generator.SingleWorldGenerator;
|
||||
@ -109,6 +111,7 @@ import com.plotsquared.core.uuid.CacheUUIDService;
|
||||
import com.plotsquared.core.uuid.UUIDPipeline;
|
||||
import com.plotsquared.core.uuid.offline.OfflineModeUUIDService;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@ -810,8 +813,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
||||
if (entity.hasMetadata("ps-tmp-teleport")) {
|
||||
continue;
|
||||
}
|
||||
iterator.remove();
|
||||
entity.remove();
|
||||
this.removeRoadEntity(entity, iterator);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@ -824,8 +826,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
||||
if (entity.hasMetadata("ps-tmp-teleport")) {
|
||||
continue;
|
||||
}
|
||||
iterator.remove();
|
||||
entity.remove();
|
||||
this.removeRoadEntity(entity, iterator);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
@ -835,7 +836,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
||||
case "DROPPED_ITEM":
|
||||
if (Settings.Enabled_Components.KILL_ROAD_ITEMS
|
||||
&& plotArea.getOwnedPlotAbs(BukkitUtil.adapt(entity.getLocation())) == null) {
|
||||
entity.remove();
|
||||
this.removeRoadEntity(entity, iterator);
|
||||
}
|
||||
// dropped item
|
||||
continue;
|
||||
@ -866,8 +867,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
||||
if (entity.hasMetadata("ps-tmp-teleport")) {
|
||||
continue;
|
||||
}
|
||||
iterator.remove();
|
||||
entity.remove();
|
||||
this.removeRoadEntity(entity, iterator);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -972,8 +972,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
||||
if (entity.hasMetadata("ps-tmp-teleport")) {
|
||||
continue;
|
||||
}
|
||||
iterator.remove();
|
||||
entity.remove();
|
||||
this.removeRoadEntity(entity, iterator);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -984,8 +983,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
||||
if (entity.hasMetadata("ps-tmp-teleport")) {
|
||||
continue;
|
||||
}
|
||||
iterator.remove();
|
||||
entity.remove();
|
||||
this.removeRoadEntity(entity, iterator);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -999,6 +997,17 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
||||
}), TaskTime.seconds(1L));
|
||||
}
|
||||
|
||||
private void removeRoadEntity(Entity entity, Iterator<Entity> entityIterator) {
|
||||
RemoveRoadEntityEvent event = eventDispatcher.callRemoveRoadEntity(BukkitAdapter.adapt(entity));
|
||||
|
||||
if (event.getEventResult() == Result.DENY) {
|
||||
return;
|
||||
}
|
||||
|
||||
entityIterator.remove();
|
||||
entity.remove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable
|
||||
final ChunkGenerator getDefaultWorldGenerator(
|
||||
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.core.events;
|
||||
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
/**
|
||||
* @since TODO
|
||||
*/
|
||||
public abstract class EntityEvent {
|
||||
|
||||
private final Entity entity;
|
||||
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* @since TODO
|
||||
*/
|
||||
public EntityEvent(Entity entity) {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain the entity involved in the event
|
||||
*
|
||||
* @return Entity
|
||||
* @since TODO
|
||||
*/
|
||||
public Entity getEntity() {
|
||||
return this.entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain the event's class name
|
||||
*
|
||||
* @return the event class name
|
||||
* @since TODO
|
||||
*/
|
||||
@NonNull public String getEventName() {
|
||||
if (this.name == null) {
|
||||
this.name = this.getClass().getSimpleName();
|
||||
}
|
||||
return this.name;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.core.events;
|
||||
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
|
||||
/**
|
||||
* @since TODO
|
||||
*/
|
||||
public class RemoveRoadEntityEvent extends EntityEvent implements CancellablePlotEvent {
|
||||
|
||||
private Result eventResult;
|
||||
|
||||
/**
|
||||
* RemoveRoadEntityEvent: Called when an entity on road is removed.
|
||||
*
|
||||
* @param entity The entity to remove
|
||||
* @since TODO
|
||||
*/
|
||||
public RemoveRoadEntityEvent(Entity entity) {
|
||||
super(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result getEventResult() {
|
||||
return this.eventResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEventResult(Result eventResult) {
|
||||
this.eventResult = eventResult;
|
||||
}
|
||||
|
||||
}
|
@ -45,6 +45,7 @@ import com.plotsquared.core.events.PlotFlagRemoveEvent;
|
||||
import com.plotsquared.core.events.PlotMergeEvent;
|
||||
import com.plotsquared.core.events.PlotRateEvent;
|
||||
import com.plotsquared.core.events.PlotUnlinkEvent;
|
||||
import com.plotsquared.core.events.RemoveRoadEntityEvent;
|
||||
import com.plotsquared.core.events.TeleportCause;
|
||||
import com.plotsquared.core.events.post.PostPlayerAutoPlotEvent;
|
||||
import com.plotsquared.core.events.post.PostPlotChangeOwnerEvent;
|
||||
@ -71,6 +72,7 @@ import com.plotsquared.core.plot.flag.types.BlockTypeWrapper;
|
||||
import com.plotsquared.core.plot.world.SinglePlotArea;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
@ -296,6 +298,12 @@ public class EventDispatcher {
|
||||
return event;
|
||||
}
|
||||
|
||||
public RemoveRoadEntityEvent callRemoveRoadEntity(Entity entity) {
|
||||
RemoveRoadEntityEvent event = new RemoveRoadEntityEvent(entity);
|
||||
eventBus.post(event);
|
||||
return event;
|
||||
}
|
||||
|
||||
public void doJoinTask(final PlotPlayer<?> player) {
|
||||
if (player == null) {
|
||||
return; //possible future warning message to figure out where we are retrieving null
|
||||
|
Loading…
Reference in New Issue
Block a user