mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 06:28:49 +00:00
Add fabric builds for older MC versions & add checkstyle (#449)
* Remove instance getters, improve command logic, register APi * Publish multiple fabric builds, enforce checkstyle * Bump guava * Bump to 4.4.2
This commit is contained in:
1 parent
51baf196b3
commit
c9f5262292
219 files changed
+8032
-1392
No files matched your search
@@ -1,528 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import net.william278.annotaml.Annotaml;
|
||||
import net.william278.desertwell.util.Version;
|
||||
import net.william278.huskhomes.command.Command;
|
||||
import net.william278.huskhomes.command.SpongeCommand;
|
||||
import net.william278.huskhomes.config.Locales;
|
||||
import net.william278.huskhomes.config.Server;
|
||||
import net.william278.huskhomes.config.Settings;
|
||||
import net.william278.huskhomes.config.Spawn;
|
||||
import net.william278.huskhomes.database.Database;
|
||||
import net.william278.huskhomes.database.MySqlDatabase;
|
||||
import net.william278.huskhomes.database.SqLiteDatabase;
|
||||
import net.william278.huskhomes.event.SpongeEventDispatcher;
|
||||
import net.william278.huskhomes.hook.Hook;
|
||||
import net.william278.huskhomes.hook.SpongeEconomyHook;
|
||||
import net.william278.huskhomes.listener.SpongeEventListener;
|
||||
import net.william278.huskhomes.manager.Manager;
|
||||
import net.william278.huskhomes.network.Broker;
|
||||
import net.william278.huskhomes.network.PluginMessageBroker;
|
||||
import net.william278.huskhomes.network.RedisBroker;
|
||||
import net.william278.huskhomes.position.Location;
|
||||
import net.william278.huskhomes.position.World;
|
||||
import net.william278.huskhomes.random.NormalDistributionEngine;
|
||||
import net.william278.huskhomes.random.RandomTeleportEngine;
|
||||
import net.william278.huskhomes.user.ConsoleUser;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import net.william278.huskhomes.user.SavedUser;
|
||||
import net.william278.huskhomes.user.SpongeUser;
|
||||
import net.william278.huskhomes.util.SpongeSafetyResolver;
|
||||
import net.william278.huskhomes.util.SpongeTask;
|
||||
import net.william278.huskhomes.util.UnsafeBlocks;
|
||||
import net.william278.huskhomes.util.Validator;
|
||||
import org.bstats.charts.SimplePie;
|
||||
import org.bstats.sponge.Metrics;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.api.Game;
|
||||
import org.spongepowered.api.ResourceKey;
|
||||
import org.spongepowered.api.command.Command.Raw;
|
||||
import org.spongepowered.api.config.ConfigDir;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.lifecycle.ConstructPluginEvent;
|
||||
import org.spongepowered.api.event.lifecycle.RegisterCommandEvent;
|
||||
import org.spongepowered.api.event.lifecycle.StartedEngineEvent;
|
||||
import org.spongepowered.api.event.lifecycle.StoppingEngineEvent;
|
||||
import org.spongepowered.api.network.EngineConnection;
|
||||
import org.spongepowered.api.network.channel.ChannelBuf;
|
||||
import org.spongepowered.api.network.channel.raw.RawDataChannel;
|
||||
import org.spongepowered.api.network.channel.raw.play.RawPlayDataChannel;
|
||||
import org.spongepowered.api.network.channel.raw.play.RawPlayDataHandler;
|
||||
import org.spongepowered.math.vector.Vector3i;
|
||||
import org.spongepowered.plugin.PluginContainer;
|
||||
import org.spongepowered.plugin.builtin.jvm.Plugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Plugin("huskhomes")
|
||||
public class SpongeHuskHomes implements HuskHomes, SpongeTask.Supplier, SpongeSafetyResolver, SpongeEventDispatcher,
|
||||
RawPlayDataHandler<EngineConnection> {
|
||||
|
||||
/**
|
||||
* Metrics ID for <a href="https://bstats.org/plugin/sponge/HuskHomes/18423">HuskHomes on Sponge</a>.
|
||||
*/
|
||||
private static final int METRICS_ID = 18423;
|
||||
private static final ResourceKey PLUGIN_MESSAGE_CHANNEL_KEY = ResourceKey.of("bungeecord", "main");
|
||||
|
||||
// Instance of the plugin
|
||||
private static SpongeHuskHomes instance;
|
||||
|
||||
public static SpongeHuskHomes getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Inject
|
||||
@ConfigDir(sharedRoot = false)
|
||||
private Path pluginDirectory;
|
||||
@Inject
|
||||
private PluginContainer pluginContainer;
|
||||
@Inject
|
||||
private Game game;
|
||||
@Inject
|
||||
private Metrics.Factory metricsFactory;
|
||||
|
||||
private Set<SavedUser> savedUsers;
|
||||
private Settings settings;
|
||||
private Locales locales;
|
||||
private Database database;
|
||||
private Validator validator;
|
||||
private Manager manager;
|
||||
private RandomTeleportEngine randomTeleportEngine;
|
||||
private Spawn serverSpawn;
|
||||
private UnsafeBlocks unsafeBlocks;
|
||||
private List<Hook> hooks;
|
||||
private List<SpongeCommand> commands;
|
||||
private Map<String, List<String>> globalPlayerList;
|
||||
private Set<UUID> currentlyOnWarmup;
|
||||
private Server server;
|
||||
@Nullable
|
||||
private Broker broker;
|
||||
private RawPlayDataChannel channel;
|
||||
|
||||
@Listener
|
||||
public void onConstructPlugin(final ConstructPluginEvent event) {
|
||||
instance = this;
|
||||
|
||||
// Get plugin version from mod container
|
||||
this.savedUsers = new HashSet<>();
|
||||
this.globalPlayerList = new HashMap<>();
|
||||
this.currentlyOnWarmup = new HashSet<>();
|
||||
this.validator = new Validator(this);
|
||||
|
||||
// Load settings and locales
|
||||
initialize("plugin config & locale files", (plugin) -> {
|
||||
if (!loadConfigs()) {
|
||||
throw new IllegalStateException("Failed to load config files. Please check the console for errors");
|
||||
}
|
||||
});
|
||||
|
||||
// Initialize the database
|
||||
initialize(getSettings().getDatabaseType().getDisplayName() + " database connection", (plugin) -> {
|
||||
this.database = switch (getSettings().getDatabaseType()) {
|
||||
case MYSQL -> new MySqlDatabase(this);
|
||||
case SQLITE -> new SqLiteDatabase(this);
|
||||
};
|
||||
|
||||
database.initialize();
|
||||
});
|
||||
|
||||
// Initialize the network messenger if proxy mode is enabled
|
||||
if (getSettings().doCrossServer()) {
|
||||
initialize(settings.getBrokerType().getDisplayName() + " message broker", (plugin) -> {
|
||||
broker = switch (settings.getBrokerType()) {
|
||||
case PLUGIN_MESSAGE -> new PluginMessageBroker(this);
|
||||
case REDIS -> new RedisBroker(this);
|
||||
};
|
||||
broker.initialize();
|
||||
});
|
||||
}
|
||||
|
||||
// Check for updates
|
||||
this.checkForUpdates();
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onServerStarted(final StartedEngineEvent<org.spongepowered.api.Server> event) {
|
||||
// Initialize the manager
|
||||
this.manager = new Manager(this);
|
||||
|
||||
// Setup RTP engine
|
||||
setRandomTeleportEngine(new NormalDistributionEngine(this));
|
||||
|
||||
// Register events
|
||||
initialize("events", (plugin) -> new SpongeEventListener(this));
|
||||
|
||||
// Register permissions
|
||||
initialize("permissions", (plugin) -> registerPermissions());
|
||||
|
||||
// Initialize hooks
|
||||
initialize("hooks", (plugin) -> {
|
||||
this.registerHooks();
|
||||
|
||||
if (hooks.size() > 0) {
|
||||
hooks.forEach(hook -> {
|
||||
try {
|
||||
hook.initialize();
|
||||
} catch (Throwable e) {
|
||||
log(Level.WARNING, "Failed to initialize " + hook.getName() + " hook", e);
|
||||
}
|
||||
});
|
||||
log(Level.INFO, "Registered " + hooks.size() + " mod hooks: " + hooks.stream()
|
||||
.map(Hook::getName)
|
||||
.collect(Collectors.joining(", ")));
|
||||
}
|
||||
});
|
||||
|
||||
// Hook into bStats
|
||||
initialize("metrics", (plugin) -> this.registerMetrics(METRICS_ID));
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onShutdown(final StoppingEngineEvent<org.spongepowered.api.Server> event) {
|
||||
if (database != null) {
|
||||
database.terminate();
|
||||
}
|
||||
if (broker != null) {
|
||||
broker.close();
|
||||
}
|
||||
cancelTasks();
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onRegisterCommands(final RegisterCommandEvent<Raw> event) {
|
||||
initialize("commands", (plugin) -> this.commands = registerCommands(event));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ConsoleUser getConsole() {
|
||||
return new ConsoleUser(game.server());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<OnlineUser> getOnlineUsers() {
|
||||
return game.server().onlinePlayers().stream()
|
||||
.map(SpongeUser::adapt)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<SavedUser> getSavedUsers() {
|
||||
return savedUsers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Settings getSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSettings(@NotNull Settings settings) {
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Locales getLocales() {
|
||||
return locales;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLocales(@NotNull Locales locales) {
|
||||
this.locales = locales;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Spawn> getServerSpawn() {
|
||||
return Optional.ofNullable(serverSpawn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setServerSpawn(@NotNull Spawn spawn) {
|
||||
this.serverSpawn = spawn;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getServerName() {
|
||||
return server.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setServer(@NotNull Server server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUnsafeBlocks(@NotNull UnsafeBlocks unsafeBlocks) {
|
||||
this.unsafeBlocks = unsafeBlocks;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public UnsafeBlocks getUnsafeBlocks() {
|
||||
return unsafeBlocks;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Database getDatabase() {
|
||||
return database;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Validator getValidator() {
|
||||
return validator;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Manager getManager() {
|
||||
return manager;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Broker getMessenger() {
|
||||
if (broker == null) {
|
||||
throw new IllegalStateException("Attempted to access message broker when it was not initialized");
|
||||
}
|
||||
return broker;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public RandomTeleportEngine getRandomTeleportEngine() {
|
||||
return randomTeleportEngine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRandomTeleportEngine(@NotNull RandomTeleportEngine randomTeleportEngine) {
|
||||
this.randomTeleportEngine = randomTeleportEngine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setServerSpawn(@NotNull Location location) {
|
||||
try {
|
||||
// Create or update the spawn.yml file
|
||||
final File spawnFile = new File(getDataFolder(), "spawn.yml");
|
||||
if (spawnFile.exists() && !spawnFile.delete()) {
|
||||
log(Level.WARNING, "Failed to delete the existing spawn.yml file");
|
||||
}
|
||||
this.serverSpawn = Annotaml.create(spawnFile, new Spawn(location)).get();
|
||||
|
||||
// Update the world spawn location, too
|
||||
game.server().worldManager().worlds().forEach(world -> {
|
||||
if (world.properties().key().asString().equals(location.getWorld().getName())) {
|
||||
world.properties().setSpawnPosition(Vector3i.from(
|
||||
(int) location.getX(), (int) location.getY(), (int) location.getZ())
|
||||
);
|
||||
}
|
||||
});
|
||||
} catch (IOException | InvocationTargetException | InstantiationException | IllegalAccessException e) {
|
||||
log(Level.WARNING, "Failed to save the server spawn.yml file", e);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<Hook> getHooks() {
|
||||
return hooks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHooks(@NotNull List<Hook> hooks) {
|
||||
this.hooks = hooks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerHooks() {
|
||||
HuskHomes.super.registerHooks();
|
||||
|
||||
// Register the sponge economy service if it is available
|
||||
if (getSettings().doEconomy() && getGame().server().serviceProvider().economyService().isPresent()) {
|
||||
getHooks().add(new SpongeEconomyHook(this));
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public InputStream getResource(@NotNull String name) {
|
||||
return pluginContainer.openResource(URI.create(name))
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public File getDataFolder() {
|
||||
return pluginDirectory.toFile();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<World> getWorlds() {
|
||||
return game.server().worldManager().worlds()
|
||||
.stream()
|
||||
.map(world -> World.from(world.key().toString(), world.uniqueId()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return Version.fromString(pluginContainer.metadata().version().toString(), "-");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<Command> getCommands() {
|
||||
return commands.stream().map(SpongeCommand::getCommand).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<SpongeCommand> registerCommands(@NotNull RegisterCommandEvent<Raw> event) {
|
||||
final List<SpongeCommand> commands = new ArrayList<>();
|
||||
for (SpongeCommand.Type type : SpongeCommand.Type.values()) {
|
||||
final SpongeCommand command = new SpongeCommand(type.getCommand(), this);
|
||||
commands.add(command);
|
||||
command.registerCommand(event);
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
|
||||
public void registerPermissions() {
|
||||
commands.forEach(SpongeCommand::registerPermissions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDependencyLoaded(@NotNull String name) {
|
||||
return game.pluginManager().plugin(name).isPresent();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Map<String, List<String>> getGlobalPlayerList() {
|
||||
return globalPlayerList;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<UUID> getCurrentlyOnWarmup() {
|
||||
return currentlyOnWarmup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerMetrics(int metricsId) {
|
||||
if (!getVersion().getMetadata().isBlank()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
final Metrics metrics = metricsFactory.make(METRICS_ID);
|
||||
metrics.addCustomChart(new SimplePie("bungee_mode", () -> Boolean.toString(getSettings().doCrossServer())));
|
||||
if (getSettings().doCrossServer()) {
|
||||
metrics.addCustomChart(new SimplePie("messenger_type", () -> getSettings().getBrokerType().getDisplayName()));
|
||||
}
|
||||
metrics.addCustomChart(new SimplePie("language", () -> getSettings().getLanguage().toLowerCase()));
|
||||
metrics.addCustomChart(new SimplePie("database_type", () -> getSettings().getDatabaseType().getDisplayName()));
|
||||
metrics.addCustomChart(new SimplePie("using_economy", () -> Boolean.toString(getSettings().doEconomy())));
|
||||
metrics.addCustomChart(new SimplePie("using_map", () -> Boolean.toString(getSettings().doMapHook())));
|
||||
getMapHook().ifPresent(hook -> metrics.addCustomChart(new SimplePie("map_type", hook::getName)));
|
||||
} catch (Throwable e) {
|
||||
log(Level.WARNING, "Failed to register bStats metrics (" + e.getMessage() + ")");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializePluginChannels() {
|
||||
this.channel = game.channelManager().ofType(PLUGIN_MESSAGE_CHANNEL_KEY, RawDataChannel.class).play();
|
||||
this.channel.addHandler(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePayload(@NotNull ChannelBuf pluginMessage, @NotNull EngineConnection connection) {
|
||||
final Optional<OnlineUser> playerConnection = getOnlineUsers().stream()
|
||||
.filter(onlineUser -> ((SpongeUser) onlineUser).getPlayer().connection().equals(connection))
|
||||
.findFirst();
|
||||
|
||||
// Get the associated engine connection
|
||||
if (playerConnection.isEmpty()) {
|
||||
log(Level.WARNING, "Received a message from a player that is not online");
|
||||
return;
|
||||
}
|
||||
|
||||
// Read the message and handle
|
||||
final SpongeUser user = (SpongeUser) playerConnection.get();
|
||||
final String channel = pluginMessage.readUTF();
|
||||
if (broker instanceof PluginMessageBroker messenger && getSettings().getBrokerType() == Broker.Type.PLUGIN_MESSAGE) {
|
||||
messenger.onReceive(channel, user, pluginMessage.readBytes(pluginMessage.available()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(@NotNull Level level, @NotNull String message, Throwable... exceptions) {
|
||||
final org.apache.logging.log4j.Level adaptedLevel = Optional
|
||||
.ofNullable(org.apache.logging.log4j.Level.getLevel(level.getName()))
|
||||
.orElse(org.apache.logging.log4j.Level.INFO);
|
||||
|
||||
if (exceptions.length > 0) {
|
||||
pluginContainer.logger().log(adaptedLevel, message, exceptions[0]);
|
||||
return;
|
||||
}
|
||||
pluginContainer.logger().log(adaptedLevel, message);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public PluginContainer getPluginContainer() {
|
||||
return pluginContainer;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Game getGame() {
|
||||
return game;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public RawPlayDataChannel getPluginMessageChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public SpongeHuskHomes getPlugin() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,200 +0,0 @@
|
||||
/*
|
||||
* 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.command;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.william278.huskhomes.SpongeHuskHomes;
|
||||
import net.william278.huskhomes.teleport.TeleportRequest;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import net.william278.huskhomes.user.SpongeUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.api.command.Command.Raw;
|
||||
import org.spongepowered.api.command.CommandCause;
|
||||
import org.spongepowered.api.command.CommandCompletion;
|
||||
import org.spongepowered.api.command.CommandResult;
|
||||
import org.spongepowered.api.command.parameter.ArgumentReader;
|
||||
import org.spongepowered.api.entity.living.player.server.ServerPlayer;
|
||||
import org.spongepowered.api.event.lifecycle.RegisterCommandEvent;
|
||||
import org.spongepowered.api.service.permission.PermissionDescription;
|
||||
import org.spongepowered.api.util.Tristate;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class SpongeCommand implements Raw {
|
||||
|
||||
private final Command command;
|
||||
private final SpongeHuskHomes plugin;
|
||||
|
||||
public SpongeCommand(@NotNull Command command, @NotNull SpongeHuskHomes plugin) {
|
||||
this.command = command;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
// Register command
|
||||
public void registerCommand(@NotNull RegisterCommandEvent<Raw> event) {
|
||||
event.register(
|
||||
plugin.getPluginContainer(),
|
||||
this,
|
||||
command.getName(),
|
||||
command.getAliases().toArray(String[]::new)
|
||||
);
|
||||
}
|
||||
|
||||
// Register command permissions
|
||||
public void registerPermissions() {
|
||||
final Map<String, Boolean> permissionDescriptions = new HashMap<>(command.getAdditionalPermissions());
|
||||
permissionDescriptions.put(command.getPermission(), command.isOperatorCommand());
|
||||
|
||||
for (Map.Entry<String, Boolean> node : permissionDescriptions.entrySet()) {
|
||||
final PermissionDescription.Builder builder = plugin.getGame().server()
|
||||
.serviceProvider().permissionService()
|
||||
.newDescriptionBuilder(plugin.getPluginContainer())
|
||||
.id(node.getKey());
|
||||
|
||||
// Set default access level
|
||||
if (node.getValue()) {
|
||||
builder.defaultValue(Tristate.UNDEFINED)
|
||||
.assign(PermissionDescription.ROLE_ADMIN, true);
|
||||
} else {
|
||||
builder.defaultValue(Tristate.TRUE)
|
||||
.assign(PermissionDescription.ROLE_USER, true);
|
||||
}
|
||||
builder.register();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Command getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public CommandResult process(@NotNull CommandCause cause, @NotNull ArgumentReader.Mutable arguments) {
|
||||
command.onExecuted(resolveExecutor(cause), assimilateArguments(arguments));
|
||||
return CommandResult.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<CommandCompletion> complete(@NotNull CommandCause cause, @NotNull ArgumentReader.Mutable arguments) {
|
||||
if (this.command instanceof TabProvider provider) {
|
||||
return provider.getSuggestions(resolveExecutor(cause), assimilateArguments(arguments)).stream()
|
||||
.map(CommandCompletion::of)
|
||||
.toList();
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private CommandUser resolveExecutor(@NotNull CommandCause cause) {
|
||||
if (cause.root() instanceof ServerPlayer player) {
|
||||
return SpongeUser.adapt(player);
|
||||
}
|
||||
return plugin.getConsole();
|
||||
}
|
||||
|
||||
/**
|
||||
* Assimilate the arguments from a {@link ArgumentReader} into a spaced {@link String} array
|
||||
*
|
||||
* @param arguments the {@link ArgumentReader} to assimilate
|
||||
* @return the assimilated {@link String} array
|
||||
*/
|
||||
@NotNull
|
||||
private String[] assimilateArguments(@NotNull ArgumentReader.Mutable arguments) {
|
||||
final String argumentString = arguments.immutable().remaining();
|
||||
if (argumentString.isBlank()) {
|
||||
return new String[0];
|
||||
}
|
||||
return argumentString.split(" ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExecute(@NotNull CommandCause cause) {
|
||||
return resolveExecutor(cause).hasPermission(command.getPermission());
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Optional<Component> shortDescription(@NotNull CommandCause cause) {
|
||||
return Optional.of(Component.text(command.getDescription()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Optional<Component> extendedDescription(@NotNull CommandCause cause) {
|
||||
return shortDescription(cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Component usage(@NotNull CommandCause cause) {
|
||||
return Component.text(command.getUsage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Commands available on the Sponge HuskHomes implementation
|
||||
*/
|
||||
public enum Type {
|
||||
HOME_COMMAND(new PrivateHomeCommand(SpongeHuskHomes.getInstance())),
|
||||
SET_HOME_COMMAND(new SetHomeCommand(SpongeHuskHomes.getInstance())),
|
||||
HOME_LIST_COMMAND(new PrivateHomeListCommand(SpongeHuskHomes.getInstance())),
|
||||
DEL_HOME_COMMAND(new DelHomeCommand(SpongeHuskHomes.getInstance())),
|
||||
EDIT_HOME_COMMAND(new EditHomeCommand(SpongeHuskHomes.getInstance())),
|
||||
PUBLIC_HOME_COMMAND(new PublicHomeCommand(SpongeHuskHomes.getInstance())),
|
||||
PUBLIC_HOME_LIST_COMMAND(new PublicHomeListCommand(SpongeHuskHomes.getInstance())),
|
||||
WARP_COMMAND(new WarpCommand(SpongeHuskHomes.getInstance())),
|
||||
SET_WARP_COMMAND(new SetWarpCommand(SpongeHuskHomes.getInstance())),
|
||||
WARP_LIST_COMMAND(new WarpListCommand(SpongeHuskHomes.getInstance())),
|
||||
DEL_WARP_COMMAND(new DelWarpCommand(SpongeHuskHomes.getInstance())),
|
||||
EDIT_WARP_COMMAND(new EditWarpCommand(SpongeHuskHomes.getInstance())),
|
||||
TP_COMMAND(new TpCommand(SpongeHuskHomes.getInstance())),
|
||||
TP_HERE_COMMAND(new TpHereCommand(SpongeHuskHomes.getInstance())),
|
||||
TPA_COMMAND(new TeleportRequestCommand(SpongeHuskHomes.getInstance(), TeleportRequest.Type.TPA)),
|
||||
TPA_HERE_COMMAND(new TeleportRequestCommand(SpongeHuskHomes.getInstance(), TeleportRequest.Type.TPA_HERE)),
|
||||
TPACCEPT_COMMAND(new TpRespondCommand(SpongeHuskHomes.getInstance(), true)),
|
||||
TPDECLINE_COMMAND(new TpRespondCommand(SpongeHuskHomes.getInstance(), false)),
|
||||
RTP_COMMAND(new RtpCommand(SpongeHuskHomes.getInstance())),
|
||||
TP_IGNORE_COMMAND(new TpIgnoreCommand(SpongeHuskHomes.getInstance())),
|
||||
TP_OFFLINE_COMMAND(new TpOfflineCommand(SpongeHuskHomes.getInstance())),
|
||||
TP_ALL_COMMAND(new TpAllCommand(SpongeHuskHomes.getInstance())),
|
||||
TPA_ALL_COMMAND(new TpaAllCommand(SpongeHuskHomes.getInstance())),
|
||||
SPAWN_COMMAND(new SpawnCommand(SpongeHuskHomes.getInstance())),
|
||||
SET_SPAWN_COMMAND(new SetSpawnCommand(SpongeHuskHomes.getInstance())),
|
||||
BACK_COMMAND(new BackCommand(SpongeHuskHomes.getInstance())),
|
||||
HUSKHOMES_COMMAND(new HuskHomesCommand(SpongeHuskHomes.getInstance()));
|
||||
|
||||
private final Command command;
|
||||
|
||||
Type(@NotNull Command command) {
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Command getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* 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.william278.huskhomes.user.CommandUser;
|
||||
import net.william278.huskhomes.user.User;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.api.event.Cancellable;
|
||||
import org.spongepowered.api.event.Cause;
|
||||
import org.spongepowered.api.event.Event;
|
||||
|
||||
public class SpongeDeleteAllHomesEvent implements IDeleteAllHomesEvent, Event, Cancellable {
|
||||
|
||||
private boolean cancelled = false;
|
||||
private final User user;
|
||||
private final CommandUser deleter;
|
||||
|
||||
public SpongeDeleteAllHomesEvent(@NotNull User user, @NotNull CommandUser deleter) {
|
||||
this.user = user;
|
||||
this.deleter = deleter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public User getHomeOwner() {
|
||||
return user;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CommandUser getDeleter() {
|
||||
return deleter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cause cause() {
|
||||
return Cause.builder()
|
||||
.append(deleter)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* 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.william278.huskhomes.user.CommandUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.api.event.Cancellable;
|
||||
import org.spongepowered.api.event.Cause;
|
||||
import org.spongepowered.api.event.Event;
|
||||
|
||||
public class SpongeDeleteAllWarpsEvent implements IDeleteAllWarpsEvent, Event, Cancellable {
|
||||
|
||||
private boolean cancelled = false;
|
||||
private final CommandUser deleter;
|
||||
|
||||
public SpongeDeleteAllWarpsEvent(@NotNull CommandUser deleter) {
|
||||
this.deleter = deleter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CommandUser getDeleter() {
|
||||
return deleter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cause cause() {
|
||||
return Cause.builder()
|
||||
.append(deleter)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
/*
|
||||
* 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.william278.huskhomes.SpongeHuskHomes;
|
||||
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 org.spongepowered.api.event.Event;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SpongeEventDispatcher extends EventDispatcher {
|
||||
|
||||
@Override
|
||||
default <T extends net.william278.huskhomes.event.Event> boolean fireIsCancelled(@NotNull T event) {
|
||||
return getPlugin().getGame().eventManager().post((Event) event);
|
||||
}
|
||||
|
||||
@Override
|
||||
default ITeleportEvent getTeleportEvent(@NotNull Teleport teleport) {
|
||||
return new SpongeTeleportEvent(teleport);
|
||||
}
|
||||
|
||||
@Override
|
||||
default ITeleportWarmupEvent getTeleportWarmupEvent(@NotNull TimedTeleport teleport, int duration) {
|
||||
return new SpongeTeleportWarmupEvent(teleport, duration);
|
||||
}
|
||||
|
||||
@Override
|
||||
default ISendTeleportRequestEvent getSendTeleportRequestEvent(@NotNull OnlineUser sender, @NotNull TeleportRequest request) {
|
||||
return new SpongeSendTeleportRequestEvent(sender, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
default IReceiveTeleportRequestEvent getReceiveTeleportRequestEvent(@NotNull OnlineUser recipient, @NotNull TeleportRequest request) {
|
||||
return new SpongeReceiveTeleportRequestEvent(recipient, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
default IReplyTeleportRequestEvent getReplyTeleportRequestEvent(@NotNull OnlineUser recipient, @NotNull TeleportRequest request) {
|
||||
return new SpongeReplyTeleportRequestEvent(recipient, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
default IHomeCreateEvent getHomeCreateEvent(@NotNull User owner, @NotNull String name, @NotNull Position position, @NotNull CommandUser creator) {
|
||||
return new SpongeHomeCreateEvent(owner, name, position, creator);
|
||||
}
|
||||
|
||||
@Override
|
||||
default IHomeEditEvent getHomeEditEvent(@NotNull Home home, @NotNull CommandUser editor) {
|
||||
return new SpongeHomeEditEvent(home, editor);
|
||||
}
|
||||
|
||||
@Override
|
||||
default IHomeDeleteEvent getHomeDeleteEvent(@NotNull Home home, @NotNull CommandUser deleter) {
|
||||
return new SpongeHomeDeleteEvent(home, deleter);
|
||||
}
|
||||
|
||||
@Override
|
||||
default IWarpCreateEvent getWarpCreateEvent(@NotNull String name, @NotNull Position position, @NotNull CommandUser creator) {
|
||||
return new SpongeWarpCreateEvent(name, position, creator);
|
||||
}
|
||||
|
||||
@Override
|
||||
default IWarpEditEvent getWarpEditEvent(@NotNull Warp warp, @NotNull CommandUser editor) {
|
||||
return new SpongeWarpEditEvent(warp, editor);
|
||||
}
|
||||
|
||||
@Override
|
||||
default IWarpDeleteEvent getWarpDeleteEvent(@NotNull Warp warp, @NotNull CommandUser deleter) {
|
||||
return new SpongeWarpDeleteEvent(warp, deleter);
|
||||
}
|
||||
|
||||
@Override
|
||||
default IHomeListEvent getViewHomeListEvent(@NotNull List<Home> homes, @NotNull CommandUser listViewer, boolean publicHomeList) {
|
||||
return new SpongeHomeListEvent(homes, listViewer, publicHomeList);
|
||||
}
|
||||
|
||||
@Override
|
||||
default IWarpListEvent getViewWarpListEvent(@NotNull List<Warp> homes, @NotNull CommandUser listViewer) {
|
||||
return new SpongeWarpListEvent(homes, listViewer);
|
||||
}
|
||||
|
||||
@Override
|
||||
default IDeleteAllHomesEvent getDeleteAllHomesEvent(@NotNull User user, @NotNull CommandUser deleter) {
|
||||
return new SpongeDeleteAllHomesEvent(user, deleter);
|
||||
}
|
||||
|
||||
@Override
|
||||
default IDeleteAllWarpsEvent getDeleteAllWarpsEvent(@NotNull CommandUser deleter) {
|
||||
return new SpongeDeleteAllWarpsEvent(deleter);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
SpongeHuskHomes getPlugin();
|
||||
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* 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.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import net.william278.huskhomes.user.User;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.api.event.Cancellable;
|
||||
import org.spongepowered.api.event.Cause;
|
||||
import org.spongepowered.api.event.Event;
|
||||
|
||||
public class SpongeHomeCreateEvent implements IHomeCreateEvent, Event, Cancellable {
|
||||
|
||||
private boolean cancelled = false;
|
||||
private final User owner;
|
||||
private String name;
|
||||
private Position position;
|
||||
private final CommandUser creator;
|
||||
|
||||
public SpongeHomeCreateEvent(@NotNull User owner, @NotNull String name, @NotNull Position position, @NotNull CommandUser creator) {
|
||||
this.owner = owner;
|
||||
this.name = name;
|
||||
this.position = position;
|
||||
this.creator = creator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public User getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(@NotNull String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPosition(@NotNull Position position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CommandUser getCreator() {
|
||||
return creator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cause cause() {
|
||||
return Cause.builder()
|
||||
.append(creator)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* 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.william278.huskhomes.position.Home;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.api.event.Cancellable;
|
||||
import org.spongepowered.api.event.Cause;
|
||||
import org.spongepowered.api.event.Event;
|
||||
|
||||
public class SpongeHomeDeleteEvent implements IHomeDeleteEvent, Event, Cancellable {
|
||||
|
||||
private boolean cancelled = false;
|
||||
private final Home home;
|
||||
private final CommandUser deleter;
|
||||
|
||||
public SpongeHomeDeleteEvent(@NotNull Home home, @NotNull CommandUser deleter) {
|
||||
this.home = home;
|
||||
this.deleter = deleter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Home getHome() {
|
||||
return home;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CommandUser getDeleter() {
|
||||
return deleter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cause cause() {
|
||||
return Cause.builder()
|
||||
.append(deleter)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* 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.william278.huskhomes.position.Home;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.api.event.Cancellable;
|
||||
import org.spongepowered.api.event.Cause;
|
||||
import org.spongepowered.api.event.Event;
|
||||
|
||||
public class SpongeHomeEditEvent implements IHomeEditEvent, Event, Cancellable {
|
||||
|
||||
private boolean cancelled = false;
|
||||
private final Home home;
|
||||
private final CommandUser editor;
|
||||
|
||||
public SpongeHomeEditEvent(@NotNull Home home, @NotNull CommandUser editor) {
|
||||
this.home = home;
|
||||
this.editor = editor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Home getHome() {
|
||||
return home;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CommandUser getEditor() {
|
||||
return editor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cause cause() {
|
||||
return Cause.builder()
|
||||
.append(editor)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* 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.william278.huskhomes.position.Home;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.api.event.Cancellable;
|
||||
import org.spongepowered.api.event.Cause;
|
||||
import org.spongepowered.api.event.Event;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SpongeHomeListEvent implements IHomeListEvent, Event, Cancellable {
|
||||
|
||||
private boolean cancelled = false;
|
||||
private List<Home> homes;
|
||||
private final CommandUser listViewer;
|
||||
private final boolean publicHomeList;
|
||||
|
||||
public SpongeHomeListEvent(@NotNull List<Home> homes, @NotNull CommandUser listViewer, boolean publicHomeList) {
|
||||
this.homes = homes;
|
||||
this.listViewer = listViewer;
|
||||
this.publicHomeList = publicHomeList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<Home> getHomes() {
|
||||
return homes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHomes(@NotNull List<Home> homes) {
|
||||
this.homes = homes;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CommandUser getListViewer() {
|
||||
return listViewer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getIsPublicHomeList() {
|
||||
return publicHomeList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cause cause() {
|
||||
return Cause.builder()
|
||||
.append(listViewer)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
-69
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* 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.william278.huskhomes.teleport.TeleportRequest;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.api.event.Cancellable;
|
||||
import org.spongepowered.api.event.Cause;
|
||||
import org.spongepowered.api.event.Event;
|
||||
|
||||
public class SpongeReceiveTeleportRequestEvent implements IReceiveTeleportRequestEvent, Event, Cancellable {
|
||||
|
||||
private boolean cancelled = false;
|
||||
private final OnlineUser recipient;
|
||||
private final TeleportRequest request;
|
||||
|
||||
public SpongeReceiveTeleportRequestEvent(@NotNull OnlineUser recipient, @NotNull TeleportRequest request) {
|
||||
this.recipient = recipient;
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public OnlineUser getRecipient() {
|
||||
return recipient;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TeleportRequest getRequest() {
|
||||
return request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cause cause() {
|
||||
return Cause.builder()
|
||||
.append(recipient)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
-69
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* 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.william278.huskhomes.teleport.TeleportRequest;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.api.event.Cancellable;
|
||||
import org.spongepowered.api.event.Cause;
|
||||
import org.spongepowered.api.event.Event;
|
||||
|
||||
public class SpongeReplyTeleportRequestEvent implements IReplyTeleportRequestEvent, Event, Cancellable {
|
||||
|
||||
private boolean cancelled = false;
|
||||
private final OnlineUser recipient;
|
||||
private final TeleportRequest request;
|
||||
|
||||
public SpongeReplyTeleportRequestEvent(@NotNull OnlineUser recipient, @NotNull TeleportRequest request) {
|
||||
this.recipient = recipient;
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public OnlineUser getRecipient() {
|
||||
return recipient;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TeleportRequest getRequest() {
|
||||
return request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cause cause() {
|
||||
return Cause.builder()
|
||||
.append(recipient)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
-69
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* 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.william278.huskhomes.teleport.TeleportRequest;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.api.event.Cancellable;
|
||||
import org.spongepowered.api.event.Cause;
|
||||
import org.spongepowered.api.event.Event;
|
||||
|
||||
public class SpongeSendTeleportRequestEvent implements ISendTeleportRequestEvent, Event, Cancellable {
|
||||
|
||||
private boolean cancelled = false;
|
||||
private final OnlineUser sender;
|
||||
private final TeleportRequest request;
|
||||
|
||||
public SpongeSendTeleportRequestEvent(@NotNull OnlineUser sender, @NotNull TeleportRequest request) {
|
||||
this.sender = sender;
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public OnlineUser getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TeleportRequest getRequest() {
|
||||
return request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cause cause() {
|
||||
return Cause.builder()
|
||||
.append(sender)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* 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.william278.huskhomes.teleport.Teleport;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.api.event.Cancellable;
|
||||
import org.spongepowered.api.event.Cause;
|
||||
import org.spongepowered.api.event.Event;
|
||||
|
||||
public class SpongeTeleportEvent implements ITeleportEvent, Event, Cancellable {
|
||||
|
||||
private boolean cancelled = false;
|
||||
private final Teleport teleport;
|
||||
|
||||
public SpongeTeleportEvent(@NotNull Teleport teleport) {
|
||||
this.teleport = teleport;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Teleport getTeleport() {
|
||||
return teleport;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cause cause() {
|
||||
return Cause.builder()
|
||||
.append(teleport.getTeleporter())
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* 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.william278.huskhomes.teleport.TimedTeleport;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.api.event.Cancellable;
|
||||
import org.spongepowered.api.event.Cause;
|
||||
import org.spongepowered.api.event.Event;
|
||||
|
||||
public class SpongeTeleportWarmupEvent implements ITeleportWarmupEvent, Event, Cancellable {
|
||||
|
||||
private boolean cancelled = false;
|
||||
private final TimedTeleport teleport;
|
||||
private final int duration;
|
||||
|
||||
public SpongeTeleportWarmupEvent(@NotNull TimedTeleport teleport, int duration) {
|
||||
this.teleport = teleport;
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
@Override
|
||||
public Cause cause() {
|
||||
return Cause.builder()
|
||||
.append(teleport.getTeleporter())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWarmupDuration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TimedTeleport getTimedTeleport() {
|
||||
return teleport;
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* 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.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.api.event.Cancellable;
|
||||
import org.spongepowered.api.event.Cause;
|
||||
import org.spongepowered.api.event.Event;
|
||||
|
||||
public class SpongeWarpCreateEvent implements IWarpCreateEvent, Event, Cancellable {
|
||||
|
||||
private boolean cancelled = false;
|
||||
private String name;
|
||||
private Position position;
|
||||
private final CommandUser creator;
|
||||
|
||||
public SpongeWarpCreateEvent(@NotNull String name, @NotNull Position position, @NotNull CommandUser creator) {
|
||||
this.name = name;
|
||||
this.position = position;
|
||||
this.creator = creator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(@NotNull String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPosition(@NotNull Position position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CommandUser getCreator() {
|
||||
return creator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cause cause() {
|
||||
return Cause.builder()
|
||||
.append(creator)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* 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.william278.huskhomes.position.Warp;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.api.event.Cancellable;
|
||||
import org.spongepowered.api.event.Cause;
|
||||
import org.spongepowered.api.event.Event;
|
||||
|
||||
public class SpongeWarpDeleteEvent implements IWarpDeleteEvent, Event, Cancellable {
|
||||
|
||||
private boolean cancelled = false;
|
||||
private final Warp warp;
|
||||
private final CommandUser deleter;
|
||||
|
||||
public SpongeWarpDeleteEvent(@NotNull Warp warp, @NotNull CommandUser deleter) {
|
||||
this.warp = warp;
|
||||
this.deleter = deleter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Warp getWarp() {
|
||||
return warp;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CommandUser getDeleter() {
|
||||
return deleter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cause cause() {
|
||||
return Cause.builder()
|
||||
.append(deleter)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* 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.william278.huskhomes.position.Warp;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.api.event.Cancellable;
|
||||
import org.spongepowered.api.event.Cause;
|
||||
import org.spongepowered.api.event.Event;
|
||||
|
||||
public class SpongeWarpEditEvent implements IWarpEditEvent, Event, Cancellable {
|
||||
|
||||
private boolean cancelled = false;
|
||||
private final Warp warp;
|
||||
private final CommandUser editor;
|
||||
|
||||
public SpongeWarpEditEvent(@NotNull Warp warp, @NotNull CommandUser editor) {
|
||||
this.warp = warp;
|
||||
this.editor = editor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Warp getWarp() {
|
||||
return warp;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CommandUser getEditor() {
|
||||
return editor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cause cause() {
|
||||
return Cause.builder()
|
||||
.append(editor)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* 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.william278.huskhomes.position.Warp;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.api.event.Cancellable;
|
||||
import org.spongepowered.api.event.Cause;
|
||||
import org.spongepowered.api.event.Event;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SpongeWarpListEvent implements IWarpListEvent, Event, Cancellable {
|
||||
|
||||
private boolean cancelled = false;
|
||||
private List<Warp> warps;
|
||||
private final CommandUser listViewer;
|
||||
|
||||
public SpongeWarpListEvent(@NotNull List<Warp> warps, @NotNull CommandUser listViewer) {
|
||||
this.warps = warps;
|
||||
this.listViewer = listViewer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<Warp> getWarps() {
|
||||
return warps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWarps(@NotNull List<Warp> warps) {
|
||||
this.warps = warps;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CommandUser getListViewer() {
|
||||
return listViewer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cause cause() {
|
||||
return Cause.builder()
|
||||
.append(listViewer)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* 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.hook;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.SpongeHuskHomes;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.api.Server;
|
||||
import org.spongepowered.api.service.economy.Currency;
|
||||
import org.spongepowered.api.service.economy.EconomyService;
|
||||
import org.spongepowered.api.service.economy.account.Account;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class SpongeEconomyHook extends EconomyHook {
|
||||
private EconomyService economyService;
|
||||
private Currency currency;
|
||||
|
||||
public SpongeEconomyHook(@NotNull HuskHomes plugin) {
|
||||
super(plugin, "Sponge Economy");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getPlayerBalance(@NotNull OnlineUser player) {
|
||||
return economyService.findOrCreateAccount(player.getUuid())
|
||||
.map(account -> account.balance(currency))
|
||||
.orElse(BigDecimal.ZERO)
|
||||
.doubleValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changePlayerBalance(@NotNull OnlineUser player, double amount) {
|
||||
if (amount != 0d) {
|
||||
final Account account = economyService.findOrCreateAccount(player.getUuid())
|
||||
.orElseThrow(() -> new IllegalStateException("Account not found for " + player.getUsername()));
|
||||
final double currentBalance = getPlayerBalance(player);
|
||||
final double amountToChange = Math.abs(currentBalance - Math.max(0d, currentBalance + amount));
|
||||
if (amount < 0d) {
|
||||
account.withdraw(currency, BigDecimal.valueOf(amountToChange), getServer().causeStackManager().currentCause());
|
||||
} else {
|
||||
account.deposit(currency, BigDecimal.valueOf(amountToChange), getServer().causeStackManager().currentCause());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatCurrency(double amount) {
|
||||
return currency.format(BigDecimal.valueOf(amount)).insertion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
this.economyService = getServer().serviceProvider().economyService()
|
||||
.orElseThrow(() -> new IllegalStateException("No economy service has been registered!"));
|
||||
this.currency = economyService.defaultCurrency();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Server getServer() {
|
||||
return ((SpongeHuskHomes) plugin).getGame().server();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
/*
|
||||
* 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.listener;
|
||||
|
||||
import net.william278.huskhomes.SpongeHuskHomes;
|
||||
import net.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.user.SpongeUser;
|
||||
import net.william278.huskhomes.util.SpongeAdapter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.api.block.BlockType;
|
||||
import org.spongepowered.api.block.BlockTypes;
|
||||
import org.spongepowered.api.entity.living.player.server.ServerPlayer;
|
||||
import org.spongepowered.api.event.EventContextKeys;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.block.InteractBlockEvent;
|
||||
import org.spongepowered.api.event.cause.entity.MovementType;
|
||||
import org.spongepowered.api.event.cause.entity.MovementTypes;
|
||||
import org.spongepowered.api.event.entity.DestructEntityEvent;
|
||||
import org.spongepowered.api.event.entity.MoveEntityEvent;
|
||||
import org.spongepowered.api.event.entity.living.player.RespawnPlayerEvent;
|
||||
import org.spongepowered.api.event.network.ServerSideConnectionEvent;
|
||||
import org.spongepowered.api.world.portal.Portal;
|
||||
import org.spongepowered.api.world.portal.PortalTypes;
|
||||
import org.spongepowered.api.world.server.ServerLocation;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class SpongeEventListener extends EventListener {
|
||||
|
||||
public SpongeEventListener(@NotNull SpongeHuskHomes plugin) {
|
||||
super(plugin);
|
||||
plugin.getGame().eventManager().registerListeners(plugin.getPluginContainer(), this);
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onPlayerJoin(final ServerSideConnectionEvent.Join event) {
|
||||
super.handlePlayerJoin(SpongeUser.adapt(event.player()));
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onPlayerLeave(final ServerSideConnectionEvent.Disconnect event) {
|
||||
super.handlePlayerJoin(SpongeUser.adapt(event.player()));
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onPlayerDeath(final DestructEntityEvent.Death event) {
|
||||
if (event.entity() instanceof ServerPlayer player) {
|
||||
super.handlePlayerJoin(SpongeUser.adapt(player));
|
||||
}
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onPlayerRespawn(final RespawnPlayerEvent event) {
|
||||
final Optional<Portal> type = event.context().get(EventContextKeys.PORTAL);
|
||||
if (type.isPresent() && type.get().type().equals(PortalTypes.END.get())) {
|
||||
return;
|
||||
}
|
||||
super.handlePlayerJoin(SpongeUser.adapt(event.entity()));
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onPlayerTeleport(final MoveEntityEvent event) {
|
||||
if (event.entity() instanceof ServerPlayer player) {
|
||||
final Optional<MovementType> type = event.context().get(EventContextKeys.MOVEMENT_TYPE);
|
||||
if (type.isPresent() && type.get().equals(MovementTypes.ENTITY_TELEPORT.get())) {
|
||||
SpongeAdapter.adaptLocation(ServerLocation.of(player.world(), event.originalPosition()))
|
||||
.ifPresent(location -> super.handlePlayerTeleport(SpongeUser.adapt(player),
|
||||
Position.at(location, plugin.getServerName())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Listener
|
||||
@SuppressWarnings("unchecked")
|
||||
public void onPlayerUpdateRespawnLocation(InteractBlockEvent.Secondary event) {
|
||||
if (event.context().get(EventContextKeys.PLAYER).isPresent()) {
|
||||
final ServerPlayer player = (ServerPlayer) event.context().get(EventContextKeys.PLAYER).get();
|
||||
final BlockType type = event.block().state().type();
|
||||
|
||||
if (type.isAnyOf(BlockTypes.BLACK_BED, BlockTypes.BLUE_BED, BlockTypes.BROWN_BED, BlockTypes.CYAN_BED,
|
||||
BlockTypes.GRAY_BED, BlockTypes.GREEN_BED, BlockTypes.LIGHT_BLUE_BED, BlockTypes.LIGHT_GRAY_BED,
|
||||
BlockTypes.LIME_BED, BlockTypes.MAGENTA_BED, BlockTypes.ORANGE_BED, BlockTypes.PINK_BED,
|
||||
BlockTypes.PURPLE_BED, BlockTypes.RED_BED, BlockTypes.WHITE_BED, BlockTypes.YELLOW_BED,
|
||||
BlockTypes.RESPAWN_ANCHOR)) {
|
||||
|
||||
super.handlePlayerUpdateSpawnPoint(SpongeUser.adapt(player), Position.at(
|
||||
SpongeAdapter.adaptLocation(player.serverLocation()).orElseThrow(),
|
||||
plugin.getServerName()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,130 +0,0 @@
|
||||
/*
|
||||
* 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.user;
|
||||
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.william278.huskhomes.SpongeHuskHomes;
|
||||
import net.william278.huskhomes.position.Location;
|
||||
import net.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.util.SpongeAdapter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.api.data.Keys;
|
||||
import org.spongepowered.api.entity.living.player.server.ServerPlayer;
|
||||
import org.spongepowered.api.service.permission.SubjectData;
|
||||
import org.spongepowered.api.util.RespawnLocation;
|
||||
import org.spongepowered.api.world.server.ServerLocation;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class SpongeUser extends OnlineUser {
|
||||
|
||||
private final ServerPlayer player;
|
||||
private final SpongeHuskHomes plugin;
|
||||
|
||||
private SpongeUser(@NotNull ServerPlayer player) {
|
||||
super(player.uniqueId(), player.name());
|
||||
this.player = player;
|
||||
this.plugin = SpongeHuskHomes.getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapt a {@link ServerPlayer} to a {@link OnlineUser}
|
||||
*
|
||||
* @param player the online {@link ServerPlayer} to adapt
|
||||
* @return the adapted {@link OnlineUser}
|
||||
*/
|
||||
@NotNull
|
||||
public static SpongeUser adapt(@NotNull ServerPlayer player) {
|
||||
return new SpongeUser(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Position getPosition() {
|
||||
return Position.at(
|
||||
SpongeAdapter.adaptLocation(player.serverLocation())
|
||||
.orElseThrow(() -> new IllegalStateException("Failed to adapt player location")),
|
||||
plugin.getServerName()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Position> getBedSpawnPosition() {
|
||||
// Resolve the player's RespawnLocation from the world-key map and adapt as location
|
||||
return player.get(Keys.RESPAWN_LOCATIONS)
|
||||
.flatMap(resourceMap -> resourceMap.values().stream().findFirst())
|
||||
.flatMap(RespawnLocation::asLocation).flatMap(SpongeAdapter::adaptLocation)
|
||||
.map(location -> Position.at(location, plugin.getServerName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getHealth() {
|
||||
return player.health().asImmutable().get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NotNull String node) {
|
||||
return player.hasPermission(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Map<String, Boolean> getPermissions() {
|
||||
return player.transientSubjectData().permissions(SubjectData.GLOBAL_CONTEXT);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Audience getAudience() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleportLocally(@NotNull Location location, boolean asynchronous) {
|
||||
plugin.runSync(() -> {
|
||||
final Optional<ServerLocation> serverLocation = SpongeAdapter.adaptLocation(location);
|
||||
if (serverLocation.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
player.setLocation(serverLocation.get());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPluginMessage(@NotNull String channel, byte[] message) {
|
||||
plugin.getPluginMessageChannel().sendTo(player, channelBuf -> channelBuf.writeBytes(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMoving() {
|
||||
return player.velocity().get().lengthSquared() > 0.0075;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVanished() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ServerPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import net.william278.huskhomes.position.Location;
|
||||
import net.william278.huskhomes.position.World;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.api.ResourceKey;
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.world.WorldTypeTemplate;
|
||||
import org.spongepowered.api.world.server.ServerLocation;
|
||||
import org.spongepowered.api.world.server.ServerWorld;
|
||||
import org.spongepowered.api.world.server.WorldManager;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public final class SpongeAdapter {
|
||||
|
||||
/**
|
||||
* Adapt a Sponge {@link ServerLocation} to a HuskHomes {@link Location}
|
||||
*
|
||||
* @param location the Sponge {@link ServerLocation} to adapt
|
||||
* @return the adapted {@link Location}
|
||||
*/
|
||||
public static Optional<ServerLocation> adaptLocation(@NotNull Location location) {
|
||||
final WorldManager worldManager = Sponge.server().worldManager();
|
||||
return worldManager
|
||||
.world(ResourceKey.resolve(location.getWorld().getName()))
|
||||
.map(world -> ServerLocation.of(world, location.getX(), location.getY(), location.getZ()))
|
||||
.or(() -> {
|
||||
final Optional<ResourceKey> worldKey = worldManager.worldKey(location.getWorld().getUuid());
|
||||
return worldKey.flatMap(resourceKey -> worldManager.world(resourceKey)
|
||||
.map(world -> ServerLocation.of(world, location.getX(), location.getY(), location.getZ())));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapt a HuskHomes {@link Location} to a Sponge {@link ServerLocation}
|
||||
*
|
||||
* @param location the HuskHomes {@link Location} to adapt
|
||||
* @return the adapted {@link ServerLocation}
|
||||
*/
|
||||
public static Optional<Location> adaptLocation(@NotNull ServerLocation location) {
|
||||
return Optional.of(Location.at(
|
||||
location.x(), location.y(), location.z(),
|
||||
adaptWorld(location.world()).orElse(new World()))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapt a Sponge {@link ServerWorld} to a HuskHomes {@link World}
|
||||
*
|
||||
* @param world the Sponge {@link ServerWorld} to adapt
|
||||
* @return the adapted {@link World}
|
||||
*/
|
||||
public static Optional<World> adaptWorld(@Nullable ServerWorld world) {
|
||||
if (world == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
final String worldType = world.properties().worldType().asTemplate().key().asString();
|
||||
return Optional.of(World.from(
|
||||
world.key().toString(), world.uniqueId(),
|
||||
(worldType.equals(WorldTypeTemplate.theNether().key().toString()) ? World.Environment.NETHER
|
||||
: worldType.equals(WorldTypeTemplate.theEnd().key().toString()) ? World.Environment.THE_END
|
||||
: worldType.equals(WorldTypeTemplate.overworld().key().toString()) ? World.Environment.OVERWORLD
|
||||
: World.Environment.CUSTOM)
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import net.william278.huskhomes.position.Location;
|
||||
import net.william278.huskhomes.position.World;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.api.block.BlockState;
|
||||
import org.spongepowered.api.registry.RegistryTypes;
|
||||
import org.spongepowered.api.world.border.WorldBorder;
|
||||
import org.spongepowered.api.world.server.ServerLocation;
|
||||
import org.spongepowered.math.vector.Vector2d;
|
||||
import org.spongepowered.math.vector.Vector3i;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public interface SpongeSafetyResolver extends SafetyResolver {
|
||||
|
||||
@Override
|
||||
default CompletableFuture<Optional<Location>> findSafeGroundLocation(@NotNull Location location) {
|
||||
final Optional<ServerLocation> adaptedLocation = SpongeAdapter.adaptLocation(location);
|
||||
if (adaptedLocation.isEmpty()) {
|
||||
return CompletableFuture.completedFuture(Optional.empty());
|
||||
}
|
||||
|
||||
// Ensure the location is within the world border
|
||||
final ServerLocation serverLocation = adaptedLocation.get();
|
||||
if (isInBorder(serverLocation.world().border(), serverLocation.blockPosition())) {
|
||||
return CompletableFuture.completedFuture(Optional.empty());
|
||||
}
|
||||
|
||||
return CompletableFuture.completedFuture(findSafeLocationNear(serverLocation, location.getWorld()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for a safe ground location near the given location
|
||||
*
|
||||
* @param location The location to search around
|
||||
* @param world The world to search in
|
||||
* @return An optional safe location, within 4 blocks of the given location
|
||||
*/
|
||||
private Optional<Location> findSafeLocationNear(@NotNull ServerLocation location, @NotNull World world) {
|
||||
for (int x = -SEARCH_RADIUS; x <= SEARCH_RADIUS; x++) {
|
||||
for (int z = -SEARCH_RADIUS; z <= SEARCH_RADIUS; z++) {
|
||||
final Vector3i cursor = location.asHighestLocation().blockPosition().add(x, -1, z);
|
||||
final Vector3i cursorBody = location.asHighestLocation().blockPosition().add(x, 0, z);
|
||||
final Vector3i cursorHead = location.asHighestLocation().blockPosition().add(x, 1, z);
|
||||
final BlockState blockState = location.world().block(cursor);
|
||||
final BlockState bodyBlockState = location.world().block(cursorBody);
|
||||
final BlockState headBlockState = location.world().block(cursorHead);
|
||||
if (isBlockSafeForStanding(blockState.type().key(RegistryTypes.BLOCK_TYPE).asString())
|
||||
&& isBlockSafeForOccupation(bodyBlockState.type().key(RegistryTypes.BLOCK_TYPE).asString())
|
||||
&& isBlockSafeForOccupation(headBlockState.type().key(RegistryTypes.BLOCK_TYPE).asString())) {
|
||||
double locx = Math.floor(cursor.x());
|
||||
if (locx < 0) {
|
||||
locx += 1.5d;
|
||||
} else {
|
||||
locx = locx + 0.5d;
|
||||
}
|
||||
double locz = Math.floor(cursor.z());
|
||||
if (locz < 0) {
|
||||
locz += 1.5d;
|
||||
} else {
|
||||
locz = locz + 0.5d;
|
||||
}
|
||||
return Optional.of(Location.at(
|
||||
locx,
|
||||
cursor.y(),
|
||||
locz,
|
||||
world
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private boolean isInBorder(WorldBorder border, Vector3i position) {
|
||||
final Vector2d center = border.center();
|
||||
final double radius = border.diameter() / 2;
|
||||
final double x = position.x() - center.x();
|
||||
final double z = position.z() - center.y();
|
||||
return x * x + z * z < radius * radius;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.SpongeHuskHomes;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.api.scheduler.ScheduledTask;
|
||||
import org.spongepowered.api.util.Ticks;
|
||||
|
||||
import static org.spongepowered.api.scheduler.Task.builder;
|
||||
|
||||
public interface SpongeTask extends Task {
|
||||
|
||||
class Sync extends Task.Sync implements SpongeTask {
|
||||
|
||||
private ScheduledTask task;
|
||||
|
||||
protected Sync(@NotNull HuskHomes plugin, @NotNull Runnable runnable, long delayTicks) {
|
||||
super(plugin, runnable, delayTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
if (task != null && !cancelled) {
|
||||
task.cancel();
|
||||
}
|
||||
super.cancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!cancelled) {
|
||||
final SpongeHuskHomes plugin = ((SpongeHuskHomes) getPlugin());
|
||||
this.task = plugin.getGame().server().scheduler().submit(builder()
|
||||
.plugin(plugin.getPluginContainer())
|
||||
.delay(Ticks.of(delayTicks))
|
||||
.execute(runnable)
|
||||
.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Async extends Task.Async implements SpongeTask {
|
||||
|
||||
private ScheduledTask task;
|
||||
|
||||
protected Async(@NotNull HuskHomes plugin, @NotNull Runnable runnable) {
|
||||
super(plugin, runnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
if (task != null && !cancelled) {
|
||||
task.cancel();
|
||||
}
|
||||
super.cancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!cancelled) {
|
||||
final SpongeHuskHomes plugin = ((SpongeHuskHomes) getPlugin());
|
||||
this.task = plugin.getGame().asyncScheduler().submit(builder()
|
||||
.plugin(plugin.getPluginContainer())
|
||||
.execute(runnable)
|
||||
.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Repeating extends Task.Repeating implements SpongeTask {
|
||||
|
||||
private ScheduledTask task;
|
||||
|
||||
protected Repeating(@NotNull HuskHomes plugin, @NotNull Runnable runnable, long repeatingTicks) {
|
||||
super(plugin, runnable, repeatingTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
if (task != null && !cancelled) {
|
||||
task.cancel();
|
||||
}
|
||||
super.cancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!cancelled) {
|
||||
final SpongeHuskHomes plugin = ((SpongeHuskHomes) getPlugin());
|
||||
this.task = plugin.getGame().asyncScheduler().submit(builder()
|
||||
.plugin(plugin.getPluginContainer())
|
||||
.interval(Ticks.of(repeatingTicks))
|
||||
.execute(runnable)
|
||||
.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface Supplier extends Task.Supplier {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
default Task.Sync getSyncTask(@NotNull Runnable runnable, long delayTicks) {
|
||||
return new Sync(getPlugin(), runnable, delayTicks);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
default Task.Async getAsyncTask(@NotNull Runnable runnable) {
|
||||
return new Async(getPlugin(), runnable);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
default Task.Repeating getRepeatingTask(@NotNull Runnable runnable, long repeatingTicks) {
|
||||
return new Repeating(getPlugin(), runnable, repeatingTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
default void cancelTasks() {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user