Compare commits
6 Commits
cc6cac939f
...
11f0a1e910
| Author | SHA1 | Date |
|---|---|---|
|
|
11f0a1e910 | 3 weeks ago |
|
|
04436cb6ab | 3 weeks ago |
|
|
b34c89f1c2 | 3 weeks ago |
|
|
375f5983af | 4 weeks ago |
|
|
4f6bfdf26d | 1 month ago |
|
|
d664f51214 | 1 month ago |
15 changed files with 731 additions and 25 deletions
@ -0,0 +1,18 @@ |
|||||||
|
package xyz.soukup.ecoCraftCore.messages; |
||||||
|
|
||||||
|
import org.bukkit.event.EventHandler; |
||||||
|
import org.bukkit.event.Listener; |
||||||
|
import org.bukkit.event.player.PlayerJoinEvent; |
||||||
|
import org.bukkit.event.player.PlayerQuitEvent; |
||||||
|
|
||||||
|
public class JoinLeaveMessageSupress implements Listener { |
||||||
|
@EventHandler |
||||||
|
public void onJoin(PlayerJoinEvent event) { |
||||||
|
event.joinMessage(null); |
||||||
|
} |
||||||
|
|
||||||
|
@EventHandler |
||||||
|
public void onQuit(PlayerQuitEvent event) { |
||||||
|
event.quitMessage(null); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,187 @@ |
|||||||
|
package xyz.soukup.ecoCraftCore.sign; |
||||||
|
|
||||||
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder; |
||||||
|
import com.mojang.brigadier.context.CommandContext; |
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack; |
||||||
|
import io.papermc.paper.command.brigadier.Commands; |
||||||
|
import io.papermc.paper.dialog.Dialog; |
||||||
|
import io.papermc.paper.dialog.DialogResponseView; |
||||||
|
import io.papermc.paper.registry.data.dialog.ActionButton; |
||||||
|
import io.papermc.paper.registry.data.dialog.DialogBase; |
||||||
|
import io.papermc.paper.registry.data.dialog.action.DialogAction; |
||||||
|
import io.papermc.paper.registry.data.dialog.input.DialogInput; |
||||||
|
import io.papermc.paper.registry.data.dialog.type.DialogType; |
||||||
|
import net.kyori.adventure.audience.Audience; |
||||||
|
import net.kyori.adventure.text.Component; |
||||||
|
import net.kyori.adventure.text.event.ClickCallback; |
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage; |
||||||
|
import org.bukkit.Location; |
||||||
|
import org.bukkit.block.Block; |
||||||
|
import org.bukkit.block.BlockState; |
||||||
|
import org.bukkit.block.Sign; |
||||||
|
import org.bukkit.block.sign.Side; |
||||||
|
import org.bukkit.block.sign.SignSide; |
||||||
|
import org.bukkit.entity.Player; |
||||||
|
import org.bukkit.persistence.PersistentDataType; |
||||||
|
import xyz.soukup.ecoCraftCore.database.objects.Shop; |
||||||
|
import xyz.soukup.ecoCraftCore.messages.Messages; |
||||||
|
import xyz.soukup.ecoCraftCore.regions.RegionManager; |
||||||
|
import xyz.soukup.ecoCraftCore.utilities.PDC; |
||||||
|
|
||||||
|
import javax.sound.sampled.Line; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
|
||||||
|
public class SignEditCommand { |
||||||
|
|
||||||
|
private static final HashMap<Player, List<String>> clipBoard = new HashMap<>(); |
||||||
|
|
||||||
|
public static LiteralArgumentBuilder<CommandSourceStack> getCommand(){ |
||||||
|
return Commands.literal("edit-sign") |
||||||
|
.requires(source -> source.getSender() instanceof Player) |
||||||
|
.executes(SignEditCommand::openEditMenu); |
||||||
|
} |
||||||
|
|
||||||
|
private static int openEditMenu(CommandContext<CommandSourceStack> context){ |
||||||
|
Player player = (Player) context.getSource().getSender(); |
||||||
|
Block block = player.getTargetBlock(null, 10); |
||||||
|
BlockState blockState = block.getState(); |
||||||
|
|
||||||
|
if (!(blockState instanceof Sign sign)){ |
||||||
|
Messages.send(player, "sign-edit.error.not-sign"); |
||||||
|
return 1; |
||||||
|
} |
||||||
|
|
||||||
|
Location location = sign.getLocation(); |
||||||
|
|
||||||
|
if (!RegionManager.isAllowedToInteract(player, location)){ |
||||||
|
Messages.send(player, "region.error.not-allowed-to-interact"); |
||||||
|
return 1; |
||||||
|
} |
||||||
|
|
||||||
|
Dialog dialog = buildEditDialog(sign, player, null); |
||||||
|
player.showDialog(dialog); |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public static Dialog buildEditDialog(Sign sign, Player player, List<String> lines){ |
||||||
|
|
||||||
|
if (lines == null){ |
||||||
|
lines = getLines(sign); |
||||||
|
} |
||||||
|
|
||||||
|
List<ActionButton> actionButtons = new ArrayList<>(); |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
actionButtons.add(ActionButton.builder(Messages.get("gui.sign-edit.buttons.copy")) |
||||||
|
.action(DialogAction.customClick((view, audience) -> copySignText(view, player, sign), ClickCallback.Options.builder().build())) |
||||||
|
.build()); |
||||||
|
actionButtons.add(ActionButton.builder(Messages.get("gui.sign-edit.buttons.paste")) |
||||||
|
.action(DialogAction.customClick((view, audience) -> pasteSignText(sign, player), ClickCallback.Options.builder().build())) |
||||||
|
.build()); |
||||||
|
actionButtons.add(ActionButton.builder(Messages.get("gui.sign-edit.buttons.confirm")) |
||||||
|
.action(DialogAction.customClick((view, audience) -> editSign(view, sign, player), ClickCallback.Options.builder().build())) |
||||||
|
.build()); |
||||||
|
actionButtons.add(ActionButton.builder(Messages.get("gui.sign-edit.buttons.cancel")) |
||||||
|
.action(DialogAction.customClick((view, audience) -> audience.closeDialog(), ClickCallback.Options.builder().build())) |
||||||
|
.build()); |
||||||
|
|
||||||
|
|
||||||
|
List<String> finalLines = lines; |
||||||
|
|
||||||
|
return Dialog.create(builder -> builder.empty() |
||||||
|
.base(DialogBase.builder(Messages.get("gui.sign-edit.title")) |
||||||
|
.inputs(List.of( |
||||||
|
DialogInput.text("line1", Messages.get("gui.sign-edit.inputs.line1")) |
||||||
|
.initial(finalLines.getFirst()) |
||||||
|
.maxLength(256) |
||||||
|
.build(), |
||||||
|
DialogInput.text("line2", Messages.get("gui.sign-edit.inputs.line2")) |
||||||
|
.initial(finalLines.get(1)) |
||||||
|
.maxLength(256) |
||||||
|
.build(), |
||||||
|
DialogInput.text("line3", Messages.get("gui.sign-edit.inputs.line3")) |
||||||
|
.initial(finalLines.get(2)) |
||||||
|
.maxLength(256) |
||||||
|
.build(), |
||||||
|
DialogInput.text("line4", Messages.get("gui.sign-edit.inputs.line4")) |
||||||
|
.initial(finalLines.get(3)) |
||||||
|
.maxLength(256) |
||||||
|
.build() |
||||||
|
)) |
||||||
|
.build()) |
||||||
|
.type(DialogType.multiAction(actionButtons).build()) |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
private static List<String> getLines(Sign sign){ |
||||||
|
List<String> lines = new ArrayList<>(); |
||||||
|
|
||||||
|
if (PDC.getUniversal(sign, "line1", PersistentDataType.STRING) != null){ |
||||||
|
for (int i = 1; i<5; i++){ |
||||||
|
lines.add((String) PDC.getUniversal(sign, "line" + i,PersistentDataType.STRING)); |
||||||
|
} |
||||||
|
return lines; |
||||||
|
} |
||||||
|
|
||||||
|
SignSide signSide = sign.getSide(Side.FRONT); |
||||||
|
List<Component> componentLines = signSide.lines(); |
||||||
|
|
||||||
|
for (Component componentLine : componentLines){ |
||||||
|
lines.add(MiniMessage.miniMessage().serialize(componentLine)); |
||||||
|
} |
||||||
|
|
||||||
|
return lines; |
||||||
|
} |
||||||
|
|
||||||
|
private static void copySignText(DialogResponseView view, Player player, Sign sign){ |
||||||
|
List<String> lines = new ArrayList<>(); |
||||||
|
|
||||||
|
lines.add(view.getText("line1")); |
||||||
|
lines.add(view.getText("line2")); |
||||||
|
lines.add(view.getText("line3")); |
||||||
|
lines.add(view.getText("line4")); |
||||||
|
|
||||||
|
clipBoard.put(player, lines); |
||||||
|
Messages.send(player, "gui.sign-edit.success.copied"); |
||||||
|
pasteSignText(sign, player); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private static void pasteSignText(Sign sign, Player player){ |
||||||
|
Dialog dialog = buildEditDialog(sign, player, clipBoard.get(player)); |
||||||
|
player.showDialog(dialog); |
||||||
|
} |
||||||
|
|
||||||
|
private static void editSign(DialogResponseView view, Sign sign, Audience audience){ |
||||||
|
MiniMessage mm = MiniMessage.miniMessage(); |
||||||
|
SignSide signSide = sign.getSide(Side.FRONT); |
||||||
|
|
||||||
|
List<Component> lines = new ArrayList<>(); |
||||||
|
|
||||||
|
|
||||||
|
for (int i = 1; i < 5; i++) { |
||||||
|
String key = "line" + i; |
||||||
|
String line = view.getText(key); |
||||||
|
|
||||||
|
if (line == null){ |
||||||
|
line = ""; |
||||||
|
} |
||||||
|
|
||||||
|
PDC.setUniversal(sign, key, line, PersistentDataType.STRING); |
||||||
|
signSide.line(i-1, mm.deserialize(line)); |
||||||
|
|
||||||
|
} |
||||||
|
sign.update(); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
Loading…
Reference in new issue