Skip to content

Commit

Permalink
V1.0.10 (#22)
Browse files Browse the repository at this point in the history
* fixed lobby requirement not being enforced when creating an island

* added a block change cooldown

* fixed the dirt soil from causing the timer to end

* added /sb islands
  • Loading branch information
Tofpu authored Apr 23, 2022
1 parent 9720fe9 commit 71051b4
Show file tree
Hide file tree
Showing 14 changed files with 383 additions and 82 deletions.
14 changes: 10 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
plugins {
java
id("com.github.johnrengelman.shadow") version "7.0.0"
id("xyz.jpenilla.run-paper") version "1.0.6"
`maven-publish`
}

group = "io.tofpu.speedbridge2"
version = "1.0.9"
version = "1.0.10"

tasks {
compileJava {
Expand Down Expand Up @@ -40,6 +41,11 @@ tasks {
expand(project.properties)
}
}

runServer {
minecraftVersion("1.8.8")
pluginJars(project.file("libs/worldedit-bukkit-6.1.jar"))
}
}

publishing {
Expand Down Expand Up @@ -69,8 +75,8 @@ dependencies {

compileOnly("com.sk89q:worldedit:6.0.0-SNAPSHOT")

implementation("com.github.Revxrsal.Lamp:common:b3af8b94a0")
implementation("com.github.Revxrsal.Lamp:bukkit:b3af8b94a0")
implementation("com.github.Revxrsal.Lamp:common:3.0.3")
implementation("com.github.Revxrsal.Lamp:bukkit:3.0.3")

implementation("net.kyori:adventure-api:4.10.1")
implementation("net.kyori:adventure-platform-bukkit:4.0.1")
Expand All @@ -91,7 +97,7 @@ dependencies {

implementation("com.github.ben-manes.caffeine:caffeine:3.0.5")

implementation("com.github.cryptomorin:XSeries:8.6.1")
implementation("com.github.cryptomorin:XSeries:8.7.1")
implementation("com.github.tofpu.MultiWorldEdit:multiworldedit-api:0eb85d6cbd") {
exclude("de.schlichtherle", "truezip")
exclude("rhino", "js")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public static void load(final @NotNull Plugin plugin,
if (response.isEmpty()) {
return;
}
actor.reply(BridgeUtil.miniMessageToLegacy(response));

final BukkitCommandActor bukkitActor = (BukkitCommandActor) actor;
BridgeUtil.sendMessage(bukkitActor.getSender(), response);
});

commandHandler.registerSenderResolver(new SenderResolver() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package io.tofpu.speedbridge2.command.subcommand;

import io.tofpu.speedbridge2.model.common.presenter.MessagePresenterHolder;
import io.tofpu.speedbridge2.model.common.presenter.MessagePresenterHolderImpl;
import io.tofpu.speedbridge2.model.common.presenter.type.MessagePairPresenter;
import io.tofpu.speedbridge2.model.common.presenter.type.MessageTreePresenter;
import io.tofpu.speedbridge2.model.common.util.BridgeUtil;
import io.tofpu.speedbridge2.model.player.object.CommonBridgePlayer;
import net.kyori.adventure.text.Component;
Expand All @@ -14,62 +18,60 @@

import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.ArrayList;
import java.util.List;

public final class HelpCommandGenerator {
private static final String FIRST_CHARACTER = "<dark_gray>| ";
private static final String TITLE = FIRST_CHARACTER + "- <white><bold>%s</bold>";
private static final String SUBTITLE = FIRST_CHARACTER + "-- <yellow>%s";
private static final String PAIR_FORMAT = String.format(SUBTITLE, "%s: <white>%s");

private static final String HEADER = FIRST_CHARACTER +
"<<gold>-</gold>> <yellow><bold>SpeedBridge <white>V2</bold>";
private static final String COMMAND_FORMAT = String.format(SUBTITLE, "/sb %s %s" +
"<dark_gray>- <white>%s");
private static final String TITLE = "<white><bold>%s</bold>";
private static final String KEY_STYLE = "<yellow>%s";
private static final String VALUE_STYLE = "<white>%s";
private static final String COMMAND_STYLE = "<yellow>/sb %s %s<dark_gray>- <white>%s";

private static Component helpMessageComponent = null;

public static void generateHelpCommand(final @NotNull Plugin plugin) {
final Method[] declaredMethods = SpeedBridgeCommand.class.getDeclaredMethods();

final List<String> messages = new ArrayList<>();
messages.add(HEADER);
messages.add("");

messages.add(String.format(TITLE, "Information"));
messages.add(String.format(PAIR_FORMAT, "Author", "Tofpu"));
messages.add(String.format(PAIR_FORMAT, "Version", plugin.getDescription()
.getVersion()));
messages.add("");

messages.add(String.format(TITLE, "Commands"));
for (final Method method : declaredMethods) {
final Subcommand commandMethod = method.getAnnotation(Subcommand.class);
final Description commandDescription = method.getAnnotation(Description.class);
if (commandMethod == null) {
continue;
}
final String usage = generateUsageOfMethod(commandMethod, method);
final MessagePresenterHolder holder = new MessagePresenterHolderImpl("<yellow><bold>SpeedBridge <white>v2");

messages.add(String.format(COMMAND_FORMAT, commandMethod.value()[0],
usage, commandDescription.value()));
}
holder.append(() -> {
final MessagePairPresenter.Builder builder = new MessagePairPresenter.Builder();

messages.add("");
messages.add(String.format(TITLE, "Support"));
messages.add(String.format(PAIR_FORMAT, "Discord",
"<click:OPEN_URL:https://tofpu.me/discord>tofpu.me/discord"));
builder.title(String.format(TITLE, "Information"));
builder.pair(String.format(KEY_STYLE, "Author"), String.format(VALUE_STYLE, "Tofpu"))
.pair(String.format(KEY_STYLE, "Version"), String.format(VALUE_STYLE, plugin.getDescription()
.getVersion()));

final StringBuilder builder = new StringBuilder();
for (final String message : messages) {
if (builder.length() != 0) {
builder.append("\n");
return builder.build();
});

holder.append(() -> {
final MessageTreePresenter.Builder builder = new MessageTreePresenter.Builder();

builder.title(String.format(TITLE, "Commands"));
for (final Method method : declaredMethods) {
final Subcommand commandMethod = method.getAnnotation(Subcommand.class);
final Description commandDescription = method.getAnnotation(Description.class);
if (commandMethod == null) {
continue;
}
final String usage = generateUsageOfMethod(commandMethod, method);

builder.message(String.format(COMMAND_STYLE, commandMethod.value()[0], usage, commandDescription.value()));
}
builder.append(message);
}
return builder.build();
});

holder.append(() -> {
final MessagePairPresenter.Builder builder = new MessagePairPresenter.Builder();

builder.title(String.format(TITLE, "Support"))
.pair(String.format(KEY_STYLE, "Discord"), String.format(VALUE_STYLE,
"<click:OPEN_URL:https://tofpu" + ".me/discord>tofpu" +
".me/discord"));

return builder.build();
});

helpMessageComponent = BridgeUtil.translateMiniMessage(builder.toString());
helpMessageComponent = BridgeUtil.translateMiniMessage(holder.getResult());
}

public static String generateUsageOfMethod(final Subcommand subcommand,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
import io.tofpu.speedbridge2.model.blockmenu.BlockMenuManager;
import io.tofpu.speedbridge2.model.common.Message;
import io.tofpu.speedbridge2.model.common.config.manager.ConfigurationManager;
import io.tofpu.speedbridge2.model.common.presenter.MessagePresenterHolderImpl;
import io.tofpu.speedbridge2.model.common.presenter.type.MessagePairPresenter;
import io.tofpu.speedbridge2.model.common.util.BridgeUtil;
import io.tofpu.speedbridge2.model.island.IslandHandler;
import io.tofpu.speedbridge2.model.island.IslandService;
import io.tofpu.speedbridge2.model.island.object.Island;
import io.tofpu.speedbridge2.model.island.object.GameIsland;
import io.tofpu.speedbridge2.model.island.object.Island;
import io.tofpu.speedbridge2.model.island.object.setup.IslandSetup;
import io.tofpu.speedbridge2.model.island.object.setup.IslandSetupHandler;
import io.tofpu.speedbridge2.model.player.PlayerService;
import io.tofpu.speedbridge2.model.player.object.score.Score;
import io.tofpu.speedbridge2.model.player.object.BridgePlayer;
import io.tofpu.speedbridge2.model.player.object.CommonBridgePlayer;
import io.tofpu.speedbridge2.model.player.object.score.Score;
import io.tofpu.speedbridge2.plugin.SpeedBridgePlugin;
import org.bukkit.Bukkit;
import org.bukkit.Location;
Expand All @@ -39,6 +41,7 @@

import static io.tofpu.speedbridge2.model.common.Message.INSTANCE;
import static io.tofpu.speedbridge2.model.common.util.MessageUtil.Symbols.ARROW_RIGHT;
import static io.tofpu.speedbridge2.model.common.util.MessageUtil.Symbols.CHECK_MARK;
import static io.tofpu.speedbridge2.model.common.util.MessageUtil.Symbols.CROSS;

@Command({"sb", "speedbridge"})
Expand Down Expand Up @@ -86,6 +89,10 @@ public void onLobbySet(final BridgePlayer bridgePlayer) {
@RestrictConsole
public String onIslandCreate(final BridgePlayer player, final int slot, final String schematic,
@revxrsal.commands.annotation.Optional @Flag("c") String category) {
if (!isGeneralSetupComplete(player)) {
return "";
}

if (category == null || category.isEmpty()) {
category = ConfigurationManager.INSTANCE.getGeneralCategory()
.getDefaultIslandCategory();
Expand Down Expand Up @@ -268,14 +275,45 @@ public String onScore(final BridgePlayer bridgePlayer) {
return String.join("\n", scoreList);
}

@Command({"sb choose", "speedbridge choose" ,"choose"})
@Command({"sb choose", "speedbridge choose", "choose"})
@Description("Lets you choose a block")
@RestrictDummyModel
@RestrictConsole
public void chooseBlock(final BridgePlayer bridgePlayer) {
BlockMenuManager.INSTANCE.showInventory(bridgePlayer);
}

@Command({"sb islands", "speedbridge islands", "islands"})
public String showIslands() {
final MessagePresenterHolderImpl holder = new MessagePresenterHolderImpl(
"<yellow>List of Islands");

holder.append(() -> {
final MessagePairPresenter.Builder builder = new MessagePairPresenter.Builder();

for (final Island island : islandService.getAllIslands()) {
final String title = "<yellow><bold>Island Analysis<reset>\n";

final String schematicHover = title + "<yellow>Schematic: " +
(island.getSchematicClipboard() == null ?
"<red>" + CROSS.getSymbol() :
"<green>" + CHECK_MARK.getSymbol());

final String spawnPointHover = "<yellow>Spawnpoint: " +
(island.getAbsoluteLocation() == null ?
"<red>" + CROSS.getSymbol() :
"<green>" +
CHECK_MARK.getSymbol());

builder.pair("<yellow>Island-" + island.getSlot(), hover(
schematicHover + "\n" + spawnPointHover, island.isReady() ?
"<green" + ">Ready" : "<red>Not Ready"));
}
return builder.build();
});
return holder.getResult();
}

@Subcommand("reload")
@Description("Reloads the config")
@CommandPermission("speedbridge.reload")
Expand Down Expand Up @@ -406,4 +444,8 @@ public String cancelSetup(final BridgePlayer bridgePlayer) {
islandSetup.cancel();
return INSTANCE.setupCancelled;
}

private String hover(final String hoverContent, final String content) {
return "<hover:show_text:'" + hoverContent + "'>" + content;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.tofpu.speedbridge2.listener.wrapper.wrappers.PlayerInteractEventWrapper;
import io.tofpu.speedbridge2.model.player.PlayerService;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
Expand Down Expand Up @@ -52,13 +53,20 @@ private void callEvent(final @NotNull Event event) {

@EventHandler // skipcq: JAVA-W0324
private void onPlayerInteract(final @NotNull PlayerInteractEvent event) {
final EventWrapper<PlayerInteractEvent> eventWrapper =
PlayerInteractEventWrapper.wrap(playerService, event);
final EventWrapper<PlayerInteractEvent> eventWrapper = PlayerInteractEventWrapper.wrap(playerService, event);

if (event.getAction() != Action.PHYSICAL || !eventWrapper.isPlaying() ||
!eventWrapper.hasTimerStarted()) {
return;
}

// if the clicked block happen to be a soil block, or any
// other block in general, then return
if (event.getClickedBlock()
.getType() != Material.AIR) {
return;
}

callEvent(eventWrapper);
}
}
Loading

0 comments on commit 71051b4

Please sign in to comment.