mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-03 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
File renamed without changes.
+43
-48
@@ -93,13 +93,6 @@ public class SpongeHuskHomes implements HuskHomes, SpongeTask.Supplier, SpongeSa
|
||||
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;
|
||||
@@ -130,8 +123,6 @@ public class SpongeHuskHomes implements HuskHomes, SpongeTask.Supplier, SpongeSa
|
||||
|
||||
@Listener
|
||||
public void onConstructPlugin(final ConstructPluginEvent event) {
|
||||
instance = this;
|
||||
|
||||
// Get plugin version from mod container
|
||||
this.savedUsers = new HashSet<>();
|
||||
this.globalPlayerList = new HashMap<>();
|
||||
@@ -148,7 +139,7 @@ public class SpongeHuskHomes implements HuskHomes, SpongeTask.Supplier, SpongeSa
|
||||
// Initialize the database
|
||||
initialize(getSettings().getDatabaseType().getDisplayName() + " database connection", (plugin) -> {
|
||||
this.database = switch (getSettings().getDatabaseType()) {
|
||||
case MYSQL -> new MySqlDatabase(this);
|
||||
case MYSQL, MARIADB -> new MySqlDatabase(this);
|
||||
case SQLITE -> new SqLiteDatabase(this);
|
||||
};
|
||||
|
||||
@@ -232,7 +223,7 @@ public class SpongeHuskHomes implements HuskHomes, SpongeTask.Supplier, SpongeSa
|
||||
@Override
|
||||
public List<OnlineUser> getOnlineUsers() {
|
||||
return game.server().onlinePlayers().stream()
|
||||
.map(SpongeUser::adapt)
|
||||
.map(user -> SpongeUser.adapt(user, this))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@@ -274,6 +265,29 @@ public class SpongeHuskHomes implements HuskHomes, SpongeTask.Supplier, SpongeSa
|
||||
this.serverSpawn = spawn;
|
||||
}
|
||||
|
||||
@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 String getServerName() {
|
||||
@@ -334,29 +348,6 @@ public class SpongeHuskHomes implements HuskHomes, SpongeTask.Supplier, SpongeSa
|
||||
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() {
|
||||
@@ -414,13 +405,10 @@ public class SpongeHuskHomes implements HuskHomes, SpongeTask.Supplier, SpongeSa
|
||||
|
||||
@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;
|
||||
return SpongeCommand.Type.getCommands(getPlugin()).stream()
|
||||
.map(command -> new SpongeCommand(command, this))
|
||||
.peek(command -> command.registerCommand(event))
|
||||
.toList();
|
||||
}
|
||||
|
||||
public void registerPermissions() {
|
||||
@@ -452,14 +440,20 @@ public class SpongeHuskHomes implements HuskHomes, SpongeTask.Supplier, SpongeSa
|
||||
|
||||
try {
|
||||
final Metrics metrics = metricsFactory.make(METRICS_ID);
|
||||
metrics.addCustomChart(new SimplePie("bungee_mode", () -> Boolean.toString(getSettings().doCrossServer())));
|
||||
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("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())));
|
||||
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() + ")");
|
||||
@@ -487,7 +481,8 @@ public class SpongeHuskHomes implements HuskHomes, SpongeTask.Supplier, SpongeSa
|
||||
// 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) {
|
||||
if (broker instanceof PluginMessageBroker messenger
|
||||
&& getSettings().getBrokerType() == Broker.Type.PLUGIN_MESSAGE) {
|
||||
messenger.onReceive(channel, user, pluginMessage.readBytes(pluginMessage.available()));
|
||||
}
|
||||
}
|
||||
+47
-39
@@ -20,6 +20,7 @@
|
||||
package net.william278.huskhomes.command;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.SpongeHuskHomes;
|
||||
import net.william278.huskhomes.teleport.TeleportRequest;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
@@ -35,10 +36,8 @@ 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;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class SpongeCommand implements Raw {
|
||||
|
||||
@@ -109,13 +108,13 @@ public class SpongeCommand implements Raw {
|
||||
@NotNull
|
||||
private CommandUser resolveExecutor(@NotNull CommandCause cause) {
|
||||
if (cause.root() instanceof ServerPlayer player) {
|
||||
return SpongeUser.adapt(player);
|
||||
return SpongeUser.adapt(player, plugin);
|
||||
}
|
||||
return plugin.getConsole();
|
||||
}
|
||||
|
||||
/**
|
||||
* Assimilate the arguments from a {@link ArgumentReader} into a spaced {@link String} array
|
||||
* 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
|
||||
@@ -153,46 +152,55 @@ public class SpongeCommand implements Raw {
|
||||
}
|
||||
|
||||
/**
|
||||
* Commands available on the Sponge HuskHomes implementation
|
||||
* 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()));
|
||||
HOME_COMMAND(PrivateHomeCommand::new),
|
||||
SET_HOME_COMMAND(SetHomeCommand::new),
|
||||
HOME_LIST_COMMAND(PrivateHomeListCommand::new),
|
||||
DEL_HOME_COMMAND(DelHomeCommand::new),
|
||||
EDIT_HOME_COMMAND(EditHomeCommand::new),
|
||||
PUBLIC_HOME_COMMAND(PublicHomeCommand::new),
|
||||
PUBLIC_HOME_LIST_COMMAND(PublicHomeListCommand::new),
|
||||
WARP_COMMAND(WarpCommand::new),
|
||||
SET_WARP_COMMAND(SetWarpCommand::new),
|
||||
WARP_LIST_COMMAND(WarpListCommand::new),
|
||||
DEL_WARP_COMMAND(DelWarpCommand::new),
|
||||
EDIT_WARP_COMMAND(EditWarpCommand::new),
|
||||
TP_COMMAND(TpCommand::new),
|
||||
TP_HERE_COMMAND(TpHereCommand::new),
|
||||
TPA_COMMAND((plugin) -> new TeleportRequestCommand(plugin, TeleportRequest.Type.TPA)),
|
||||
TPA_HERE_COMMAND((plugin) -> new TeleportRequestCommand(plugin, TeleportRequest.Type.TPA_HERE)),
|
||||
TPACCEPT_COMMAND((plugin) -> new TpRespondCommand(plugin, true)),
|
||||
TPDECLINE_COMMAND((plugin) -> new TpRespondCommand(plugin, false)),
|
||||
RTP_COMMAND(RtpCommand::new),
|
||||
TP_IGNORE_COMMAND(TpIgnoreCommand::new),
|
||||
TP_OFFLINE_COMMAND(TpOfflineCommand::new),
|
||||
TP_ALL_COMMAND(TpAllCommand::new),
|
||||
TPA_ALL_COMMAND(TpaAllCommand::new),
|
||||
SPAWN_COMMAND(SpawnCommand::new),
|
||||
SET_SPAWN_COMMAND(SetSpawnCommand::new),
|
||||
BACK_COMMAND(BackCommand::new),
|
||||
HUSKHOMES_COMMAND(HuskHomesCommand::new);
|
||||
|
||||
private final Command command;
|
||||
private final Function<HuskHomes, Command> supplier;
|
||||
|
||||
Type(@NotNull Command command) {
|
||||
this.command = command;
|
||||
Type(@NotNull Function<HuskHomes, Command> supplier) {
|
||||
this.supplier = supplier;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Command getCommand() {
|
||||
return command;
|
||||
public Command createCommand(@NotNull HuskHomes plugin) {
|
||||
return supplier.apply(plugin);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<Command> getCommands(@NotNull SpongeHuskHomes plugin) {
|
||||
return Arrays.stream(values())
|
||||
.map(type -> type.createCommand(plugin))
|
||||
.map(command -> plugin.getSettings().isCommandDisabled(command) ? null : command)
|
||||
.filter(Objects::nonNull)
|
||||
.toList();
|
||||
}
|
||||
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
+21
-13
@@ -42,75 +42,83 @@ public interface SpongeEventDispatcher extends EventDispatcher {
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
default ITeleportEvent getTeleportEvent(@NotNull Teleport teleport) {
|
||||
return new SpongeTeleportEvent(teleport);
|
||||
}
|
||||
|
||||
@Override
|
||||
default ITeleportWarmupEvent getTeleportWarmupEvent(@NotNull TimedTeleport teleport, int duration) {
|
||||
default @NotNull ITeleportWarmupEvent getTeleportWarmupEvent(@NotNull TimedTeleport teleport, int duration) {
|
||||
return new SpongeTeleportWarmupEvent(teleport, duration);
|
||||
}
|
||||
|
||||
@Override
|
||||
default ISendTeleportRequestEvent getSendTeleportRequestEvent(@NotNull OnlineUser sender, @NotNull TeleportRequest request) {
|
||||
default @NotNull ISendTeleportRequestEvent getSendTeleportRequestEvent(@NotNull OnlineUser sender,
|
||||
@NotNull TeleportRequest request) {
|
||||
return new SpongeSendTeleportRequestEvent(sender, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
default IReceiveTeleportRequestEvent getReceiveTeleportRequestEvent(@NotNull OnlineUser recipient, @NotNull TeleportRequest request) {
|
||||
default @NotNull IReceiveTeleportRequestEvent getReceiveTeleportRequestEvent(@NotNull OnlineUser recipient,
|
||||
@NotNull TeleportRequest request) {
|
||||
return new SpongeReceiveTeleportRequestEvent(recipient, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
default IReplyTeleportRequestEvent getReplyTeleportRequestEvent(@NotNull OnlineUser recipient, @NotNull TeleportRequest request) {
|
||||
default @NotNull 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) {
|
||||
default @NotNull 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) {
|
||||
default @NotNull IHomeEditEvent getHomeEditEvent(@NotNull Home home, @NotNull CommandUser editor) {
|
||||
return new SpongeHomeEditEvent(home, editor);
|
||||
}
|
||||
|
||||
@Override
|
||||
default IHomeDeleteEvent getHomeDeleteEvent(@NotNull Home home, @NotNull CommandUser deleter) {
|
||||
default @NotNull 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) {
|
||||
default @NotNull 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) {
|
||||
default @NotNull IWarpEditEvent getWarpEditEvent(@NotNull Warp warp, @NotNull CommandUser editor) {
|
||||
return new SpongeWarpEditEvent(warp, editor);
|
||||
}
|
||||
|
||||
@Override
|
||||
default IWarpDeleteEvent getWarpDeleteEvent(@NotNull Warp warp, @NotNull CommandUser deleter) {
|
||||
default @NotNull 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) {
|
||||
default @NotNull 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) {
|
||||
default @NotNull IWarpListEvent getViewWarpListEvent(@NotNull List<Warp> homes, @NotNull CommandUser listViewer) {
|
||||
return new SpongeWarpListEvent(homes, listViewer);
|
||||
}
|
||||
|
||||
@Override
|
||||
default IDeleteAllHomesEvent getDeleteAllHomesEvent(@NotNull User user, @NotNull CommandUser deleter) {
|
||||
default @NotNull IDeleteAllHomesEvent getDeleteAllHomesEvent(@NotNull User user, @NotNull CommandUser deleter) {
|
||||
return new SpongeDeleteAllHomesEvent(user, deleter);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
default IDeleteAllWarpsEvent getDeleteAllWarpsEvent(@NotNull CommandUser deleter) {
|
||||
return new SpongeDeleteAllWarpsEvent(deleter);
|
||||
+2
-1
@@ -35,7 +35,8 @@ public class SpongeHomeCreateEvent implements IHomeCreateEvent, Event, Cancellab
|
||||
private Position position;
|
||||
private final CommandUser creator;
|
||||
|
||||
public SpongeHomeCreateEvent(@NotNull User owner, @NotNull String name, @NotNull Position position, @NotNull 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;
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+2
@@ -45,6 +45,7 @@ public class SpongeTeleportWarmupEvent implements ITeleportWarmupEvent, Event, C
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cause cause() {
|
||||
return Cause.builder()
|
||||
@@ -62,4 +63,5 @@ public class SpongeTeleportWarmupEvent implements ITeleportWarmupEvent, Event, C
|
||||
public TimedTeleport getTimedTeleport() {
|
||||
return teleport;
|
||||
}
|
||||
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+10
-2
@@ -54,9 +54,17 @@ public class SpongeEconomyHook extends EconomyHook {
|
||||
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());
|
||||
account.withdraw(
|
||||
currency,
|
||||
BigDecimal.valueOf(amountToChange),
|
||||
getServer().causeStackManager().currentCause()
|
||||
);
|
||||
} else {
|
||||
account.deposit(currency, BigDecimal.valueOf(amountToChange), getServer().causeStackManager().currentCause());
|
||||
account.deposit(
|
||||
currency,
|
||||
BigDecimal.valueOf(amountToChange),
|
||||
getServer().causeStackManager().currentCause()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
-10
@@ -51,18 +51,18 @@ public class SpongeEventListener extends EventListener {
|
||||
|
||||
@Listener
|
||||
public void onPlayerJoin(final ServerSideConnectionEvent.Join event) {
|
||||
super.handlePlayerJoin(SpongeUser.adapt(event.player()));
|
||||
super.handlePlayerJoin(SpongeUser.adapt(event.player(), (SpongeHuskHomes) plugin));
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onPlayerLeave(final ServerSideConnectionEvent.Disconnect event) {
|
||||
super.handlePlayerJoin(SpongeUser.adapt(event.player()));
|
||||
super.handlePlayerJoin(SpongeUser.adapt(event.player(), (SpongeHuskHomes) plugin));
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onPlayerDeath(final DestructEntityEvent.Death event) {
|
||||
if (event.entity() instanceof ServerPlayer player) {
|
||||
super.handlePlayerJoin(SpongeUser.adapt(player));
|
||||
super.handlePlayerJoin(SpongeUser.adapt(player, (SpongeHuskHomes) plugin));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public class SpongeEventListener extends EventListener {
|
||||
if (type.isPresent() && type.get().type().equals(PortalTypes.END.get())) {
|
||||
return;
|
||||
}
|
||||
super.handlePlayerJoin(SpongeUser.adapt(event.entity()));
|
||||
super.handlePlayerJoin(SpongeUser.adapt(event.entity(), (SpongeHuskHomes) plugin));
|
||||
}
|
||||
|
||||
@Listener
|
||||
@@ -81,8 +81,10 @@ public class SpongeEventListener extends EventListener {
|
||||
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())));
|
||||
.ifPresent(location -> super.handlePlayerTeleport(
|
||||
SpongeUser.adapt(player, (SpongeHuskHomes) plugin),
|
||||
Position.at(location, plugin.getServerName())
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,10 +102,11 @@ public class SpongeEventListener extends EventListener {
|
||||
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()
|
||||
));
|
||||
super.handlePlayerUpdateSpawnPoint(SpongeUser.adapt(player, (SpongeHuskHomes) plugin),
|
||||
Position.at(
|
||||
SpongeAdapter.adaptLocation(player.serverLocation()).orElseThrow(),
|
||||
plugin.getServerName()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
-11
@@ -39,21 +39,31 @@ public class SpongeUser extends OnlineUser {
|
||||
private final ServerPlayer player;
|
||||
private final SpongeHuskHomes plugin;
|
||||
|
||||
private SpongeUser(@NotNull ServerPlayer player) {
|
||||
private SpongeUser(@NotNull ServerPlayer player, @NotNull SpongeHuskHomes plugin) {
|
||||
super(player.uniqueId(), player.name());
|
||||
this.player = player;
|
||||
this.plugin = SpongeHuskHomes.getInstance();
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapt a {@link ServerPlayer} to a {@link OnlineUser}
|
||||
* 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);
|
||||
public static SpongeUser adapt(@NotNull ServerPlayer player, @NotNull SpongeHuskHomes plugin) {
|
||||
return new SpongeUser(player, plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link ServerPlayer} associated with this {@link OnlineUser}.
|
||||
*
|
||||
* @return the {@link ServerPlayer}
|
||||
*/
|
||||
@NotNull
|
||||
public ServerPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -97,7 +107,7 @@ public class SpongeUser extends OnlineUser {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleportLocally(@NotNull Location location, boolean asynchronous) {
|
||||
public void teleportLocally(@NotNull Location location, boolean async) {
|
||||
plugin.runSync(() -> {
|
||||
final Optional<ServerLocation> serverLocation = SpongeAdapter.adaptLocation(location);
|
||||
if (serverLocation.isEmpty()) {
|
||||
@@ -122,9 +132,4 @@ public class SpongeUser extends OnlineUser {
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ServerPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
}
|
||||
+3
-3
@@ -35,7 +35,7 @@ import java.util.Optional;
|
||||
public final class SpongeAdapter {
|
||||
|
||||
/**
|
||||
* Adapt a Sponge {@link ServerLocation} to a HuskHomes {@link Location}
|
||||
* Adapt a Sponge {@link ServerLocation} to a HuskHomes {@link Location}.
|
||||
*
|
||||
* @param location the Sponge {@link ServerLocation} to adapt
|
||||
* @return the adapted {@link Location}
|
||||
@@ -53,7 +53,7 @@ public final class SpongeAdapter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapt a HuskHomes {@link Location} to a Sponge {@link ServerLocation}
|
||||
* Adapt a HuskHomes {@link Location} to a Sponge {@link ServerLocation}.
|
||||
*
|
||||
* @param location the HuskHomes {@link Location} to adapt
|
||||
* @return the adapted {@link ServerLocation}
|
||||
@@ -66,7 +66,7 @@ public final class SpongeAdapter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapt a Sponge {@link ServerWorld} to a HuskHomes {@link World}
|
||||
* Adapt a Sponge {@link ServerWorld} to a HuskHomes {@link World}.
|
||||
*
|
||||
* @param world the Sponge {@link ServerWorld} to adapt
|
||||
* @return the adapted {@link World}
|
||||
+5
-5
@@ -51,7 +51,7 @@ public interface SpongeSafetyResolver extends SafetyResolver {
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for a safe ground location near the given location
|
||||
* Search for a safe ground location near the given location.
|
||||
*
|
||||
* @param location The location to search around
|
||||
* @param world The world to search in
|
||||
@@ -67,15 +67,15 @@ public interface SpongeSafetyResolver extends SafetyResolver {
|
||||
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());
|
||||
&& isBlockSafeForOccupation(bodyBlockState.type().key(RegistryTypes.BLOCK_TYPE).asString())
|
||||
&& isBlockSafeForOccupation(headBlockState.type().key(RegistryTypes.BLOCK_TYPE).asString())) {
|
||||
double locx = cursor.x();
|
||||
if (locx < 0) {
|
||||
locx += 1.5d;
|
||||
} else {
|
||||
locx = locx + 0.5d;
|
||||
}
|
||||
double locz = Math.floor(cursor.z());
|
||||
double locz = cursor.z();
|
||||
if (locz < 0) {
|
||||
locz += 1.5d;
|
||||
} else {
|
||||
Reference in new issue
Block a user