mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-03 22:16:34 +00:00
Add Fabric 1.19.4 server-side mod support (#348)
This commit is contained in:
1 parent
1bdf21dd7d
commit
29e0ed6ef4
181 files changed
+5566
-67
No files matched your search
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* This file is part of HuskHomes, licensed under the Apache License 2.0.
|
||||
*
|
||||
* Copyright (c) William278 <[email protected]>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.william278.huskhomes.event;
|
||||
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import net.william278.huskhomes.user.User;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public interface DeleteAllHomesCallback extends FabricEventCallback<IDeleteAllHomesEvent> {
|
||||
|
||||
@NotNull
|
||||
Event<DeleteAllHomesCallback> EVENT = EventFactory.createArrayBacked(DeleteAllHomesCallback.class,
|
||||
(listeners) -> (event) -> {
|
||||
for (DeleteAllHomesCallback listener : listeners) {
|
||||
final ActionResult result = listener.invoke(event);
|
||||
if (event.isCancelled()) {
|
||||
return ActionResult.CONSUME;
|
||||
} else if (result != ActionResult.PASS) {
|
||||
event.setCancelled(true);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
|
||||
@NotNull
|
||||
BiFunction<User, CommandUser, IDeleteAllHomesEvent> SUPPLIER = (owner, deleter) ->
|
||||
new IDeleteAllHomesEvent() {
|
||||
private boolean cancelled = false;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public User getHomeOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public CommandUser getDeleter() {
|
||||
return deleter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Event<DeleteAllHomesCallback> getEvent() {
|
||||
return EVENT;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* This file is part of HuskHomes, licensed under the Apache License 2.0.
|
||||
*
|
||||
* Copyright (c) William278 <[email protected]>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.william278.huskhomes.event;
|
||||
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public interface DeleteAllWarpsCallback extends FabricEventCallback<IDeleteAllWarpsEvent> {
|
||||
|
||||
@NotNull
|
||||
Event<DeleteAllWarpsCallback> EVENT = EventFactory.createArrayBacked(DeleteAllWarpsCallback.class,
|
||||
(listeners) -> (event) -> {
|
||||
for (DeleteAllWarpsCallback listener : listeners) {
|
||||
final ActionResult result = listener.invoke(event);
|
||||
if (event.isCancelled()) {
|
||||
return ActionResult.CONSUME;
|
||||
} else if (result != ActionResult.PASS) {
|
||||
event.setCancelled(true);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
|
||||
@NotNull
|
||||
Function<CommandUser, IDeleteAllWarpsEvent> SUPPLIER = (deleter) ->
|
||||
new IDeleteAllWarpsEvent() {
|
||||
private boolean cancelled = false;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public CommandUser getDeleter() {
|
||||
return deleter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Event<DeleteAllWarpsCallback> getEvent() {
|
||||
return EVENT;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* This file is part of HuskHomes, licensed under the Apache License 2.0.
|
||||
*
|
||||
* Copyright (c) William278 <[email protected]>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.william278.huskhomes.event;
|
||||
|
||||
import net.minecraft.util.ActionResult;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface FabricEventCallback<E extends Event> {
|
||||
|
||||
@NotNull
|
||||
ActionResult invoke(@NotNull E event);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* This file is part of HuskHomes, licensed under the Apache License 2.0.
|
||||
*
|
||||
* Copyright (c) William278 <[email protected]>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.william278.huskhomes.event;
|
||||
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.william278.huskhomes.FabricHuskHomes;
|
||||
import net.william278.huskhomes.position.Home;
|
||||
import net.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.position.Warp;
|
||||
import net.william278.huskhomes.teleport.Teleport;
|
||||
import net.william278.huskhomes.teleport.TeleportRequest;
|
||||
import net.william278.huskhomes.teleport.TimedTeleport;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import net.william278.huskhomes.user.User;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public interface FabricEventDispatcher extends EventDispatcher {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
default <T extends Event> boolean fireIsCancelled(@NotNull T event) {
|
||||
try {
|
||||
final Method field = event.getClass().getDeclaredMethod("getEvent");
|
||||
field.setAccessible(true);
|
||||
|
||||
net.fabricmc.fabric.api.event.Event<?> fabricEvent = (net.fabricmc.fabric.api.event.Event<?>) field.invoke(event);
|
||||
|
||||
final FabricEventCallback<T> invoker = (FabricEventCallback<T>) fabricEvent.invoker();
|
||||
return invoker.invoke(event) == ActionResult.FAIL;
|
||||
} catch (InvocationTargetException | NoSuchMethodException | IllegalAccessException e) {
|
||||
getPlugin().log(Level.WARNING, "Failed to fire event (" + event.getClass().getName() + ")", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
default ITeleportEvent getTeleportEvent(@NotNull Teleport teleport) {
|
||||
return TeleportCallback.SUPPLIER.apply(teleport);
|
||||
}
|
||||
|
||||
@Override
|
||||
default ITeleportWarmupEvent getTeleportWarmupEvent(@NotNull TimedTeleport teleport, int duration) {
|
||||
return TeleportWarmupCallback.SUPPLIER.apply(teleport, duration);
|
||||
}
|
||||
|
||||
@Override
|
||||
default ISendTeleportRequestEvent getSendTeleportRequestEvent(@NotNull OnlineUser sender, @NotNull TeleportRequest request) {
|
||||
return SendTeleportRequestCallback.SUPPLIER.apply(sender, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
default IReceiveTeleportRequestEvent getReceiveTeleportRequestEvent(@NotNull OnlineUser recipient, @NotNull TeleportRequest request) {
|
||||
return ReceiveTeleportRequestCallback.SUPPLIER.apply(recipient, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
default IReplyTeleportRequestEvent getReplyTeleportRequestEvent(@NotNull OnlineUser recipient, @NotNull TeleportRequest request) {
|
||||
return ReplyTeleportRequestCallback.SUPPLIER.apply(recipient, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
default IHomeCreateEvent getHomeCreateEvent(@NotNull User owner, @NotNull String name, @NotNull Position position, @NotNull CommandUser creator) {
|
||||
return HomeCreateCallback.SUPPLIER.apply(owner, name, position, creator);
|
||||
}
|
||||
|
||||
@Override
|
||||
default IHomeEditEvent getHomeEditEvent(@NotNull Home home, @NotNull CommandUser editor) {
|
||||
return HomeEditCallback.SUPPLIER.apply(home, editor);
|
||||
}
|
||||
|
||||
@Override
|
||||
default IHomeDeleteEvent getHomeDeleteEvent(@NotNull Home home, @NotNull CommandUser deleter) {
|
||||
return HomeDeleteCallback.SUPPLIER.apply(home, deleter);
|
||||
}
|
||||
|
||||
@Override
|
||||
default IWarpCreateEvent getWarpCreateEvent(@NotNull String name, @NotNull Position position, @NotNull CommandUser creator) {
|
||||
return WarpCreateCallback.SUPPLIER.apply(name, position, creator);
|
||||
}
|
||||
|
||||
@Override
|
||||
default IWarpEditEvent getWarpEditEvent(@NotNull Warp warp, @NotNull CommandUser editor) {
|
||||
return WarpEditCallback.SUPPLIER.apply(warp, editor);
|
||||
}
|
||||
|
||||
@Override
|
||||
default IWarpDeleteEvent getWarpDeleteEvent(@NotNull Warp warp, @NotNull CommandUser deleter) {
|
||||
return WarpDeleteCallback.SUPPLIER.apply(warp, deleter);
|
||||
}
|
||||
|
||||
@Override
|
||||
default IHomeListEvent getViewHomeListEvent(@NotNull List<Home> homes, @NotNull CommandUser listViewer, boolean publicHomeList) {
|
||||
return HomeListCallback.SUPPLIER.apply(homes, listViewer, publicHomeList);
|
||||
}
|
||||
|
||||
@Override
|
||||
default IWarpListEvent getViewWarpListEvent(@NotNull List<Warp> homes, @NotNull CommandUser listViewer) {
|
||||
return WarpListCallback.SUPPLIER.apply(homes, listViewer);
|
||||
}
|
||||
|
||||
@Override
|
||||
default IDeleteAllHomesEvent getDeleteAllHomesEvent(@NotNull User user, @NotNull CommandUser deleter) {
|
||||
return DeleteAllHomesCallback.SUPPLIER.apply(user, deleter);
|
||||
}
|
||||
|
||||
@Override
|
||||
default IDeleteAllWarpsEvent getDeleteAllWarpsEvent(@NotNull CommandUser deleter) {
|
||||
return DeleteAllWarpsCallback.SUPPLIER.apply(deleter);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
FabricHuskHomes getPlugin();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* This file is part of HuskHomes, licensed under the Apache License 2.0.
|
||||
*
|
||||
* Copyright (c) William278 <[email protected]>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.william278.huskhomes.event;
|
||||
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.data.client.BlockStateVariantMap.QuadFunction;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import net.william278.huskhomes.user.User;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface HomeCreateCallback extends FabricEventCallback<IHomeCreateEvent> {
|
||||
|
||||
@NotNull
|
||||
Event<HomeCreateCallback> EVENT = EventFactory.createArrayBacked(HomeCreateCallback.class,
|
||||
(listeners) -> (event) -> {
|
||||
for (HomeCreateCallback listener : listeners) {
|
||||
final ActionResult result = listener.invoke(event);
|
||||
if (event.isCancelled()) {
|
||||
return ActionResult.CONSUME;
|
||||
} else if (result != ActionResult.PASS) {
|
||||
event.setCancelled(true);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
|
||||
@NotNull
|
||||
QuadFunction<User, String, Position, CommandUser, IHomeCreateEvent> SUPPLIER = (user, name, position, creator) ->
|
||||
new IHomeCreateEvent() {
|
||||
private boolean cancelled = false;
|
||||
private String homeName = name;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public User getOwner() {
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return homeName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(@NotNull String name) {
|
||||
this.homeName = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPosition(@NotNull Position position) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull CommandUser getCreator() {
|
||||
return creator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Event<HomeCreateCallback> getEvent() {
|
||||
return EVENT;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* This file is part of HuskHomes, licensed under the Apache License 2.0.
|
||||
*
|
||||
* Copyright (c) William278 <[email protected]>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.william278.huskhomes.event;
|
||||
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.william278.huskhomes.position.Home;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public interface HomeDeleteCallback extends FabricEventCallback<IHomeDeleteEvent> {
|
||||
|
||||
@NotNull
|
||||
Event<HomeDeleteCallback> EVENT = EventFactory.createArrayBacked(HomeDeleteCallback.class,
|
||||
(listeners) -> (event) -> {
|
||||
for (HomeDeleteCallback listener : listeners) {
|
||||
final ActionResult result = listener.invoke(event);
|
||||
if (event.isCancelled()) {
|
||||
return ActionResult.CONSUME;
|
||||
} else if (result != ActionResult.PASS) {
|
||||
event.setCancelled(true);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
|
||||
@NotNull
|
||||
BiFunction<Home, CommandUser, IHomeDeleteEvent> SUPPLIER = (home, deleter) ->
|
||||
new IHomeDeleteEvent() {
|
||||
private boolean cancelled = false;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Home getHome() {
|
||||
return home;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public CommandUser getDeleter() {
|
||||
return deleter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Event<HomeDeleteCallback> getEvent() {
|
||||
return EVENT;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* This file is part of HuskHomes, licensed under the Apache License 2.0.
|
||||
*
|
||||
* Copyright (c) William278 <[email protected]>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.william278.huskhomes.event;
|
||||
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.william278.huskhomes.position.Home;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public interface HomeEditCallback extends FabricEventCallback<IHomeEditEvent> {
|
||||
|
||||
@NotNull
|
||||
Event<HomeEditCallback> EVENT = EventFactory.createArrayBacked(HomeEditCallback.class,
|
||||
(listeners) -> (event) -> {
|
||||
for (HomeEditCallback listener : listeners) {
|
||||
final ActionResult result = listener.invoke(event);
|
||||
if (event.isCancelled()) {
|
||||
return ActionResult.CONSUME;
|
||||
} else if (result != ActionResult.PASS) {
|
||||
event.setCancelled(true);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
|
||||
@NotNull
|
||||
BiFunction<Home, CommandUser, IHomeEditEvent> SUPPLIER = (home, editor) ->
|
||||
new IHomeEditEvent() {
|
||||
private boolean cancelled = false;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Home getHome() {
|
||||
return home;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public CommandUser getEditor() {
|
||||
return editor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Event<HomeEditCallback> getEvent() {
|
||||
return EVENT;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* This file is part of HuskHomes, licensed under the Apache License 2.0.
|
||||
*
|
||||
* Copyright (c) William278 <[email protected]>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.william278.huskhomes.event;
|
||||
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.william278.huskhomes.position.Home;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import org.apache.commons.lang3.function.TriFunction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface HomeListCallback extends FabricEventCallback<IHomeListEvent> {
|
||||
|
||||
@NotNull
|
||||
Event<HomeListCallback> EVENT = EventFactory.createArrayBacked(HomeListCallback.class,
|
||||
(listeners) -> (event) -> {
|
||||
for (HomeListCallback listener : listeners) {
|
||||
final ActionResult result = listener.invoke(event);
|
||||
if (event.isCancelled()) {
|
||||
return ActionResult.CONSUME;
|
||||
} else if (result != ActionResult.PASS) {
|
||||
event.setCancelled(true);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
|
||||
@NotNull
|
||||
TriFunction<List<Home>, CommandUser, Boolean, IHomeListEvent> SUPPLIER = (homes, viewer, publicHomes) ->
|
||||
new IHomeListEvent() {
|
||||
private boolean cancelled = false;
|
||||
private List<Home> listHomes = homes;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<Home> getHomes() {
|
||||
return listHomes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHomes(@NotNull List<Home> homes) {
|
||||
this.listHomes = homes;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public CommandUser getListViewer() {
|
||||
return viewer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getIsPublicHomeList() {
|
||||
return publicHomes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Event<HomeListCallback> getEvent() {
|
||||
return EVENT;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* This file is part of HuskHomes, licensed under the Apache License 2.0.
|
||||
*
|
||||
* Copyright (c) William278 <[email protected]>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.william278.huskhomes.event;
|
||||
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.william278.huskhomes.teleport.TeleportRequest;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public interface ReceiveTeleportRequestCallback extends FabricEventCallback<IReceiveTeleportRequestEvent> {
|
||||
|
||||
@NotNull
|
||||
Event<ReceiveTeleportRequestCallback> EVENT = EventFactory.createArrayBacked(ReceiveTeleportRequestCallback.class,
|
||||
(listeners) -> (event) -> {
|
||||
for (ReceiveTeleportRequestCallback listener : listeners) {
|
||||
final ActionResult result = listener.invoke(event);
|
||||
if (event.isCancelled()) {
|
||||
return ActionResult.CONSUME;
|
||||
} else if (result != ActionResult.PASS) {
|
||||
event.setCancelled(true);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
|
||||
@NotNull
|
||||
BiFunction<OnlineUser, TeleportRequest, IReceiveTeleportRequestEvent> SUPPLIER = (recipient, request) ->
|
||||
new IReceiveTeleportRequestEvent() {
|
||||
private boolean cancelled = false;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public OnlineUser getRecipient() {
|
||||
return recipient;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public TeleportRequest getRequest() {
|
||||
return request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Event<ReceiveTeleportRequestCallback> getEvent() {
|
||||
return EVENT;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* This file is part of HuskHomes, licensed under the Apache License 2.0.
|
||||
*
|
||||
* Copyright (c) William278 <[email protected]>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.william278.huskhomes.event;
|
||||
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.william278.huskhomes.teleport.TeleportRequest;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public interface ReplyTeleportRequestCallback extends FabricEventCallback<IReplyTeleportRequestEvent> {
|
||||
|
||||
@NotNull
|
||||
Event<ReplyTeleportRequestCallback> EVENT = EventFactory.createArrayBacked(ReplyTeleportRequestCallback.class,
|
||||
(listeners) -> (event) -> {
|
||||
for (ReplyTeleportRequestCallback listener : listeners) {
|
||||
final ActionResult result = listener.invoke(event);
|
||||
if (event.isCancelled()) {
|
||||
return ActionResult.CONSUME;
|
||||
} else if (result != ActionResult.PASS) {
|
||||
event.setCancelled(true);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
|
||||
@NotNull
|
||||
BiFunction<OnlineUser, TeleportRequest, IReplyTeleportRequestEvent> SUPPLIER = (recipient, request) ->
|
||||
new IReplyTeleportRequestEvent() {
|
||||
private boolean cancelled = false;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public OnlineUser getRecipient() {
|
||||
return recipient;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public TeleportRequest getRequest() {
|
||||
return request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Event<ReplyTeleportRequestCallback> getEvent() {
|
||||
return EVENT;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* This file is part of HuskHomes, licensed under the Apache License 2.0.
|
||||
*
|
||||
* Copyright (c) William278 <[email protected]>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.william278.huskhomes.event;
|
||||
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.william278.huskhomes.teleport.TeleportRequest;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public interface SendTeleportRequestCallback extends FabricEventCallback<ISendTeleportRequestEvent> {
|
||||
|
||||
@NotNull
|
||||
Event<SendTeleportRequestCallback> EVENT = EventFactory.createArrayBacked(SendTeleportRequestCallback.class,
|
||||
(listeners) -> (event) -> {
|
||||
for (SendTeleportRequestCallback listener : listeners) {
|
||||
final ActionResult result = listener.invoke(event);
|
||||
if (event.isCancelled()) {
|
||||
return ActionResult.CONSUME;
|
||||
} else if (result != ActionResult.PASS) {
|
||||
event.setCancelled(true);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
|
||||
@NotNull
|
||||
BiFunction<OnlineUser, TeleportRequest, ISendTeleportRequestEvent> SUPPLIER = (sender, request) ->
|
||||
new ISendTeleportRequestEvent() {
|
||||
private boolean cancelled = false;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public OnlineUser getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public TeleportRequest getRequest() {
|
||||
return request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Event<SendTeleportRequestCallback> getEvent() {
|
||||
return EVENT;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* This file is part of HuskHomes, licensed under the Apache License 2.0.
|
||||
*
|
||||
* Copyright (c) William278 <[email protected]>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.william278.huskhomes.event;
|
||||
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.teleport.Teleport;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public interface TeleportBackCallback extends FabricEventCallback<ITeleportBackEvent> {
|
||||
|
||||
@NotNull
|
||||
Event<TeleportBackCallback> EVENT = EventFactory.createArrayBacked(TeleportBackCallback.class,
|
||||
(listeners) -> (event) -> {
|
||||
for (TeleportBackCallback listener : listeners) {
|
||||
final ActionResult result = listener.invoke(event);
|
||||
if (event.isCancelled()) {
|
||||
return ActionResult.FAIL;
|
||||
} else if (result == ActionResult.FAIL) {
|
||||
event.setCancelled(true);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
|
||||
@NotNull
|
||||
Function<Teleport, ITeleportBackEvent> SUPPLIER = (teleport) ->
|
||||
new ITeleportBackEvent() {
|
||||
private boolean cancelled = false;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Position getLastPosition() {
|
||||
return (Position) getTeleport().getTarget();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Teleport getTeleport() {
|
||||
return teleport;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Event<TeleportBackCallback> getEvent() {
|
||||
return EVENT;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* This file is part of HuskHomes, licensed under the Apache License 2.0.
|
||||
*
|
||||
* Copyright (c) William278 <[email protected]>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.william278.huskhomes.event;
|
||||
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.william278.huskhomes.teleport.Teleport;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public interface TeleportCallback extends FabricEventCallback<ITeleportEvent> {
|
||||
|
||||
@NotNull
|
||||
Event<TeleportCallback> EVENT = EventFactory.createArrayBacked(TeleportCallback.class,
|
||||
(listeners) -> (event) -> {
|
||||
for (TeleportCallback listener : listeners) {
|
||||
final ActionResult result = listener.invoke(event);
|
||||
if (event.isCancelled()) {
|
||||
return ActionResult.FAIL;
|
||||
} else if (result == ActionResult.FAIL) {
|
||||
event.setCancelled(true);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
|
||||
@NotNull
|
||||
Function<Teleport, ITeleportEvent> SUPPLIER = (teleport) ->
|
||||
new ITeleportEvent() {
|
||||
private boolean cancelled = false;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Teleport getTeleport() {
|
||||
return teleport;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Event<TeleportCallback> getEvent() {
|
||||
return EVENT;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* This file is part of HuskHomes, licensed under the Apache License 2.0.
|
||||
*
|
||||
* Copyright (c) William278 <[email protected]>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.william278.huskhomes.event;
|
||||
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.william278.huskhomes.teleport.TimedTeleport;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public interface TeleportWarmupCallback extends FabricEventCallback<ITeleportWarmupEvent> {
|
||||
@NotNull
|
||||
Event<TeleportWarmupCallback> EVENT = EventFactory.createArrayBacked(TeleportWarmupCallback.class,
|
||||
(listeners) -> (event) -> {
|
||||
for (TeleportWarmupCallback listener : listeners) {
|
||||
final ActionResult result = listener.invoke(event);
|
||||
if (event.isCancelled()) {
|
||||
return ActionResult.FAIL;
|
||||
} else if (result == ActionResult.FAIL) {
|
||||
event.setCancelled(true);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
|
||||
@NotNull
|
||||
BiFunction<TimedTeleport, Integer, ITeleportWarmupEvent> SUPPLIER = (timedTeleport, duration) ->
|
||||
new ITeleportWarmupEvent() {
|
||||
private boolean cancelled = false;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public TimedTeleport getTimedTeleport() {
|
||||
return timedTeleport;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWarmupDuration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Event<TeleportWarmupCallback> getEvent() {
|
||||
return EVENT;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* This file is part of HuskHomes, licensed under the Apache License 2.0.
|
||||
*
|
||||
* Copyright (c) William278 <[email protected]>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.william278.huskhomes.event;
|
||||
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import org.apache.commons.lang3.function.TriFunction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface WarpCreateCallback extends FabricEventCallback<IWarpCreateEvent> {
|
||||
|
||||
@NotNull
|
||||
Event<WarpCreateCallback> EVENT = EventFactory.createArrayBacked(WarpCreateCallback.class,
|
||||
(listeners) -> (event) -> {
|
||||
for (WarpCreateCallback listener : listeners) {
|
||||
final ActionResult result = listener.invoke(event);
|
||||
if (event.isCancelled()) {
|
||||
return ActionResult.CONSUME;
|
||||
} else if (result != ActionResult.PASS) {
|
||||
event.setCancelled(true);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
|
||||
@NotNull
|
||||
TriFunction<String, Position, CommandUser, IWarpCreateEvent> SUPPLIER = (name, position, creator) ->
|
||||
new IWarpCreateEvent() {
|
||||
private boolean cancelled = false;
|
||||
private String homeName = name;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return homeName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(@NotNull String name) {
|
||||
this.homeName = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPosition(@NotNull Position position) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public CommandUser getCreator() {
|
||||
return creator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Event<WarpCreateCallback> getEvent() {
|
||||
return EVENT;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* This file is part of HuskHomes, licensed under the Apache License 2.0.
|
||||
*
|
||||
* Copyright (c) William278 <[email protected]>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.william278.huskhomes.event;
|
||||
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.william278.huskhomes.position.Warp;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public interface WarpDeleteCallback extends FabricEventCallback<IWarpDeleteEvent> {
|
||||
|
||||
@NotNull
|
||||
Event<WarpDeleteCallback> EVENT = EventFactory.createArrayBacked(WarpDeleteCallback.class,
|
||||
(listeners) -> (event) -> {
|
||||
for (WarpDeleteCallback listener : listeners) {
|
||||
final ActionResult result = listener.invoke(event);
|
||||
if (event.isCancelled()) {
|
||||
return ActionResult.CONSUME;
|
||||
} else if (result != ActionResult.PASS) {
|
||||
event.setCancelled(true);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
|
||||
@NotNull
|
||||
BiFunction<Warp, CommandUser, IWarpDeleteEvent> SUPPLIER = (warp, deleter) ->
|
||||
new IWarpDeleteEvent() {
|
||||
private boolean cancelled = false;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Warp getWarp() {
|
||||
return warp;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public CommandUser getDeleter() {
|
||||
return deleter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Event<WarpDeleteCallback> getEvent() {
|
||||
return EVENT;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* This file is part of HuskHomes, licensed under the Apache License 2.0.
|
||||
*
|
||||
* Copyright (c) William278 <[email protected]>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.william278.huskhomes.event;
|
||||
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.william278.huskhomes.position.Warp;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public interface WarpEditCallback extends FabricEventCallback<IWarpEditEvent> {
|
||||
|
||||
@NotNull
|
||||
Event<WarpEditCallback> EVENT = EventFactory.createArrayBacked(WarpEditCallback.class,
|
||||
(listeners) -> (event) -> {
|
||||
for (WarpEditCallback listener : listeners) {
|
||||
final ActionResult result = listener.invoke(event);
|
||||
if (event.isCancelled()) {
|
||||
return ActionResult.CONSUME;
|
||||
} else if (result != ActionResult.PASS) {
|
||||
event.setCancelled(true);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
|
||||
@NotNull
|
||||
BiFunction<Warp, CommandUser, IWarpEditEvent> SUPPLIER = (warp, editor) ->
|
||||
new IWarpEditEvent() {
|
||||
private boolean cancelled = false;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Warp getWarp() {
|
||||
return warp;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public CommandUser getEditor() {
|
||||
return editor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Event<WarpEditCallback> getEvent() {
|
||||
return EVENT;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* This file is part of HuskHomes, licensed under the Apache License 2.0.
|
||||
*
|
||||
* Copyright (c) William278 <[email protected]>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.william278.huskhomes.event;
|
||||
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.william278.huskhomes.position.Warp;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public interface WarpListCallback extends FabricEventCallback<IWarpListEvent> {
|
||||
|
||||
@NotNull
|
||||
Event<WarpListCallback> EVENT = EventFactory.createArrayBacked(WarpListCallback.class,
|
||||
(listeners) -> (event) -> {
|
||||
for (WarpListCallback listener : listeners) {
|
||||
final ActionResult result = listener.invoke(event);
|
||||
if (event.isCancelled()) {
|
||||
return ActionResult.CONSUME;
|
||||
} else if (result != ActionResult.PASS) {
|
||||
event.setCancelled(true);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
|
||||
@NotNull
|
||||
BiFunction<List<Warp>, CommandUser, IWarpListEvent> SUPPLIER = (warps, viewer) ->
|
||||
new IWarpListEvent() {
|
||||
private boolean cancelled = false;
|
||||
private List<Warp> listWarps = warps;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<Warp> getWarps() {
|
||||
return listWarps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWarps(@NotNull List<Warp> homes) {
|
||||
this.listWarps = homes;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public CommandUser getListViewer() {
|
||||
return viewer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Event<WarpListCallback> getEvent() {
|
||||
return EVENT;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user