-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
449 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
easyarmorstands-plugin/src/main/java/me/m56738/easyarmorstands/clipboard/Clipboard.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package me.m56738.easyarmorstands.clipboard; | ||
|
||
import me.m56738.easyarmorstands.api.menu.MenuClick; | ||
import me.m56738.easyarmorstands.api.property.Property; | ||
import me.m56738.easyarmorstands.api.property.PropertyMap; | ||
import me.m56738.easyarmorstands.api.property.type.PropertyType; | ||
import me.m56738.easyarmorstands.message.Message; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Clipboard { | ||
private final Player player; | ||
private final PropertyMap properties = new PropertyMap(); | ||
|
||
Clipboard(Player player) { | ||
this.player = player; | ||
} | ||
|
||
public PropertyMap getProperties() { | ||
return properties; | ||
} | ||
|
||
public <T> void handlePropertyShiftClick(Property<T> property, MenuClick click) { | ||
PropertyType<T> type = property.getType(); | ||
if (type.canCopy(click.player())) { | ||
properties.put(type, property.getValue()); | ||
click.sendMessage(Message.success("easyarmorstands.success.property-copied", type.getName())); | ||
} | ||
} | ||
|
||
void removeDisallowed() { | ||
List<PropertyType<?>> types = new ArrayList<>(); | ||
properties.forEach(property -> types.add(property.getType())); | ||
|
||
for (PropertyType<?> type : types) { | ||
if (!type.canCopy(player)) { | ||
properties.remove(type); | ||
} | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...morstands-plugin/src/main/java/me/m56738/easyarmorstands/clipboard/ClipboardListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package me.m56738.easyarmorstands.clipboard; | ||
|
||
import me.m56738.easyarmorstands.EasyArmorStandsPlugin; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerGameModeChangeEvent; | ||
import org.bukkit.event.player.PlayerQuitEvent; | ||
|
||
public class ClipboardListener implements Listener { | ||
private final ClipboardManager clipboardManager; | ||
|
||
public ClipboardListener(ClipboardManager clipboardManager) { | ||
this.clipboardManager = clipboardManager; | ||
} | ||
|
||
@EventHandler | ||
public void onQuit(PlayerQuitEvent event) { | ||
clipboardManager.remove(event.getPlayer()); | ||
} | ||
|
||
@EventHandler | ||
public void onGameModeChange(PlayerGameModeChangeEvent event) { | ||
EasyArmorStandsPlugin plugin = EasyArmorStandsPlugin.getInstance(); | ||
Bukkit.getScheduler().runTask(plugin, () -> clipboardManager.getClipboard(event.getPlayer()).removeDisallowed()); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...rmorstands-plugin/src/main/java/me/m56738/easyarmorstands/clipboard/ClipboardManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package me.m56738.easyarmorstands.clipboard; | ||
|
||
import org.bukkit.entity.Player; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class ClipboardManager { | ||
private final Map<Player, Clipboard> clipboards = new HashMap<>(); | ||
|
||
public Clipboard getClipboard(Player player) { | ||
return clipboards.computeIfAbsent(player, Clipboard::new); | ||
} | ||
|
||
public void remove(Player player) { | ||
clipboards.remove(player); | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
...armorstands-plugin/src/main/java/me/m56738/easyarmorstands/command/ClipboardCommands.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package me.m56738.easyarmorstands.command; | ||
|
||
import me.m56738.easyarmorstands.api.element.Element; | ||
import me.m56738.easyarmorstands.api.property.Property; | ||
import me.m56738.easyarmorstands.api.property.PropertyContainer; | ||
import me.m56738.easyarmorstands.api.property.type.PropertyType; | ||
import me.m56738.easyarmorstands.clipboard.Clipboard; | ||
import me.m56738.easyarmorstands.command.requirement.RequireElement; | ||
import me.m56738.easyarmorstands.command.requirement.RequireElementSelection; | ||
import me.m56738.easyarmorstands.command.sender.EasPlayer; | ||
import me.m56738.easyarmorstands.command.util.ElementSelection; | ||
import me.m56738.easyarmorstands.message.Message; | ||
import me.m56738.easyarmorstands.permission.Permissions; | ||
import me.m56738.easyarmorstands.util.PropertyCopier; | ||
import net.kyori.adventure.text.Component; | ||
import net.kyori.adventure.text.format.NamedTextColor; | ||
import org.incendo.cloud.annotations.Command; | ||
import org.incendo.cloud.annotations.CommandDescription; | ||
import org.incendo.cloud.annotations.Permission; | ||
|
||
@Command("eas") | ||
public class ClipboardCommands { | ||
@Command("clipboard") | ||
@Permission(Permissions.CLIPBOARD) | ||
@CommandDescription("easyarmorstands.command.description.clipboard") | ||
public void clipboard(EasPlayer sender, Clipboard clipboard) { | ||
if (clipboard.getProperties().isEmpty()) { | ||
sender.sendMessage(Message.warning("easyarmorstands.warning.clipboard-empty")); | ||
return; | ||
} | ||
sender.sendMessage(Message.title("easyarmorstands.title.clipboard")); | ||
clipboard.getProperties().forEach(property -> sender.sendMessage(Component.text() | ||
.content("* ") | ||
.color(NamedTextColor.GRAY) | ||
.append(describeProperty(property)))); | ||
sender.sendMessage(Message.hint("easyarmorstands.hint.paste-clipboard", Message.command("/eas paste"))); | ||
sender.sendMessage(Message.hint("easyarmorstands.hint.clear-clipboard", Message.command("/eas clipboard clear"))); | ||
} | ||
|
||
private <T> Component describeProperty(Property<T> property) { | ||
PropertyType<T> type = property.getType(); | ||
return Component.text() | ||
.append(type.getName()) | ||
.append(Component.text(": ")) | ||
.append(type.getValueComponent(property.getValue())) | ||
.build(); | ||
} | ||
|
||
@Command("clipboard clear") | ||
@Permission(Permissions.CLIPBOARD) | ||
@CommandDescription("easyarmorstands.command.description.clipboard.clear") | ||
public void clear(EasPlayer sender, Clipboard clipboard) { | ||
if (clipboard.getProperties().isEmpty()) { | ||
sender.sendMessage(Message.warning("easyarmorstands.warning.clipboard-empty")); | ||
} else { | ||
clipboard.getProperties().clear(); | ||
sender.sendMessage(Message.success("easyarmorstands.success.clipboard-cleared")); | ||
} | ||
} | ||
|
||
@Command("copy") | ||
@Permission(Permissions.CLIPBOARD) | ||
@CommandDescription("easyarmorstands.command.description.copy") | ||
@RequireElement | ||
public void copy(EasPlayer sender, Clipboard clipboard, Element element) { | ||
element.getProperties().forEach(property -> { | ||
if (property.getType().canCopy(sender.player())) { | ||
copyProperty(clipboard, property); | ||
} | ||
}); | ||
sender.sendMessage(Message.success("easyarmorstands.success.clipboard-copied")); | ||
sender.sendMessage(Message.hint("easyarmorstands.hint.show-clipboard", Message.command("/eas clipboard"))); | ||
sender.sendMessage(Message.hint("easyarmorstands.hint.paste-clipboard", Message.command("/eas paste"))); | ||
} | ||
|
||
private <T> void copyProperty(Clipboard clipboard, Property<T> property) { | ||
clipboard.getProperties().put(property.getType(), property.getValue()); | ||
} | ||
|
||
@Command("paste") | ||
@Permission(Permissions.CLIPBOARD) | ||
@CommandDescription("easyarmorstands.command.description.paste") | ||
@RequireElementSelection | ||
public void paste(EasPlayer sender, Clipboard clipboard, ElementSelection selection) { | ||
if (clipboard.getProperties().isEmpty()) { | ||
sender.sendMessage(Message.error("easyarmorstands.error.clipboard-empty")); | ||
sender.sendMessage(Message.hint("easyarmorstands.hint.copy-property")); | ||
sender.sendMessage(Message.hint("easyarmorstands.hint.copy-all-properties", Message.command("/eas copy"))); | ||
return; | ||
} | ||
|
||
PropertyCopier copier = new PropertyCopier(); | ||
PropertyContainer properties = selection.properties(sender); | ||
copier.copyProperties(properties, clipboard.getProperties()); | ||
properties.commit(Message.component("easyarmorstands.history.clipboard-pasted")); | ||
|
||
if (copier.getSuccessCount() > 0) { | ||
sender.sendMessage(Message.success("easyarmorstands.success.clipboard-pasted")); | ||
if (copier.getFailureCount() > 0) { | ||
sender.sendMessage(Message.warning("easyarmorstands.warning.clipboard-partial")); | ||
} | ||
} else if (copier.getFailureCount() > 0) { | ||
sender.sendMessage(Message.error("easyarmorstands.error.clipboard-failed")); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...s-plugin/src/main/java/me/m56738/easyarmorstands/command/processor/ClipboardInjector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package me.m56738.easyarmorstands.command.processor; | ||
|
||
import me.m56738.easyarmorstands.clipboard.Clipboard; | ||
import me.m56738.easyarmorstands.command.sender.EasCommandSender; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
import org.incendo.cloud.context.CommandContext; | ||
import org.incendo.cloud.injection.ParameterInjector; | ||
import org.incendo.cloud.util.annotation.AnnotationAccessor; | ||
|
||
import static me.m56738.easyarmorstands.command.processor.ClipboardProcessor.clipboardKey; | ||
|
||
public class ClipboardInjector implements ParameterInjector<EasCommandSender, Clipboard> { | ||
@Override | ||
public @Nullable Clipboard create(@NonNull CommandContext<EasCommandSender> context, @NonNull AnnotationAccessor annotationAccessor) { | ||
return context.getOrDefault(clipboardKey(), null); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...-plugin/src/main/java/me/m56738/easyarmorstands/command/processor/ClipboardProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package me.m56738.easyarmorstands.command.processor; | ||
|
||
import me.m56738.easyarmorstands.clipboard.Clipboard; | ||
import me.m56738.easyarmorstands.command.sender.EasCommandSender; | ||
import me.m56738.easyarmorstands.command.sender.EasPlayer; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
import org.incendo.cloud.context.CommandContext; | ||
import org.incendo.cloud.execution.preprocessor.CommandPreprocessingContext; | ||
import org.incendo.cloud.execution.preprocessor.CommandPreprocessor; | ||
import org.incendo.cloud.key.CloudKey; | ||
|
||
import static org.incendo.cloud.key.CloudKey.cloudKey; | ||
|
||
public class ClipboardProcessor implements CommandPreprocessor<EasCommandSender> { | ||
private static final CloudKey<Clipboard> KEY = cloudKey("clipboard", Clipboard.class); | ||
|
||
public static CloudKey<Clipboard> clipboardKey() { | ||
return KEY; | ||
} | ||
|
||
@Override | ||
public void accept(@NonNull CommandPreprocessingContext<EasCommandSender> context) { | ||
CommandContext<EasCommandSender> commandContext = context.commandContext(); | ||
EasCommandSender sender = commandContext.sender(); | ||
if (sender instanceof EasPlayer) { | ||
Clipboard clipboard = ((EasPlayer) sender).clipboard(); | ||
commandContext.set(KEY, clipboard); | ||
} | ||
} | ||
} |
Oops, something went wrong.