Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,4 @@ buildNumber.properties

# Common working directory
run/
/build/
10 changes: 8 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import org.gradle.api.JavaVersion.VERSION_25

plugins {
id("java")
id("io.papermc.paperweight.userdev") version "2.0.0-beta.19"
id("io.papermc.paperweight.userdev") version "2.0.0-beta.21"
id("com.gradleup.shadow") version "9.3.1"
id("xyz.jpenilla.run-paper") version "3.0.2"
}
Expand All @@ -15,8 +15,14 @@ repositories {
}

dependencies {
paperweight.paperDevBundle("1.21.11-R0.1-SNAPSHOT")
paperweight.paperDevBundle("26.2.build.+")
implementation("org.bstats:bstats-bukkit:3.1.0")

compileOnly("org.projectlombok:lombok:1.18.46")
annotationProcessor("org.projectlombok:lombok:1.18.46")

testCompileOnly("org.projectlombok:lombok:1.18.46")
testAnnotationProcessor("org.projectlombok:lombok:1.18.46")
}

java {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package goldenshadow.displayentityeditor;

import goldenshadow.displayentityeditor.commands.DisplayEntityEditorBrigadierCommand;
import goldenshadow.displayentityeditor.events.*;
import goldenshadow.displayentityeditor.events.Interact;
import goldenshadow.displayentityeditor.events.InventoryClick;
import goldenshadow.displayentityeditor.events.InventoryClose;
import goldenshadow.displayentityeditor.events.OffhandSwap;
import goldenshadow.displayentityeditor.events.PlayerJoin;
import goldenshadow.displayentityeditor.events.PlayerLeave;
import goldenshadow.displayentityeditor.inventories.InventoryFactory;
import goldenshadow.displayentityeditor.items.GUIItems;
import goldenshadow.displayentityeditor.items.InventoryItems;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager;
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
import lombok.Getter;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
Expand All @@ -20,15 +26,21 @@
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.*;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;
import java.util.UUID;
import java.util.function.Consumer;

public final class DisplayEntityEditor extends JavaPlugin {

@Getter
private static DisplayEntityEditor plugin;
public static ConversationFactory conversationFactory;
public static InventoryFactory inventoryFactory;
Expand Down Expand Up @@ -60,6 +72,7 @@ public final class DisplayEntityEditor extends JavaPlugin {
public static NamespacedKey toolKey;

private final DisplayEntityEditorBrigadierCommand command = new DisplayEntityEditorBrigadierCommand();
@Getter
private EditingHandler editingHandler;

/**
Expand Down Expand Up @@ -87,13 +100,13 @@ public void onEnable() {

registerBrigadierCommand();

Bukkit.getPluginManager().registerEvents(new Interact(editingHandler), plugin);
Bukkit.getPluginManager().registerEvents(new OffhandSwap(editingHandler), plugin);
Bukkit.getPluginManager().registerEvents(new Interact(this.editingHandler), plugin);
Bukkit.getPluginManager().registerEvents(new OffhandSwap(this.editingHandler), plugin);
Bukkit.getPluginManager().registerEvents(new InventoryClick(), plugin);
Bukkit.getPluginManager().registerEvents(new InventoryClose(), plugin);
Bukkit.getPluginManager().registerEvents(new PlayerJoin(), plugin);
Bukkit.getPluginManager().registerEvents(new PlayerLeave(), plugin);

toolSelectionModeKey = new NamespacedKey(plugin, "toolSelectionMode");
toolSelectionRangeKey = new NamespacedKey(plugin, "toolSelectionRange");
toolSelectionMultipleKey = new NamespacedKey(plugin, "toolSelectionMultiple");
Expand All @@ -119,33 +132,23 @@ public void onEnable() {
getLogger().warning(messageManager.getString("messages_file_incomplete"));
}
}

}

@Override
public void onDisable() {
for (Player player : Bukkit.getOnlinePlayers()) {
command.returnInventory(player);
this.command.returnInventory(player);
}
}

@SuppressWarnings("UnstableApiUsage")
private void registerBrigadierCommand() {
LifecycleEventManager<Plugin> manager = this.getLifecycleManager();
manager.registerEventHandler(LifecycleEvents.COMMANDS, event -> {
final Commands commands = event.registrar();
commands.register(command.createCommand(), "Command for Display Entity Editor plugin", List.of("dee"));
commands.register(this.command.createCommand(), "Command for Display Entity Editor plugin", List.of("dee"));
});
}

/**
* Getter for the plugin instance
* @return The plugin
*/
public static DisplayEntityEditor getPlugin() {
return plugin;
}

/**
* Used to get the newest version of the plugin available on spigot
* @param consumer The consumer
Expand Down Expand Up @@ -173,11 +176,7 @@ public static void checkForMessageFile() throws IOException {
messageManager = new MessageManager();
}

public EditingHandler getEditingHandler() {
return editingHandler;
}

public DisplayEntityEditorBrigadierCommand command() {
return command;
return this.command;
}
}
19 changes: 10 additions & 9 deletions src/main/java/goldenshadow/displayentityeditor/EditingHandler.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package goldenshadow.displayentityeditor;

import goldenshadow.displayentityeditor.enums.LockSearchMode;
import org.bukkit.entity.Display;
import org.bukkit.entity.Player;

import goldenshadow.displayentityeditor.enums.LockSearchMode;

import javax.annotation.Nullable;
import java.util.*;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class EditingHandler {

Expand All @@ -20,28 +22,28 @@ public class EditingHandler {
* @param displays The collection of displays the player should be editing.
*/
public void setEditingDisplays(Player player, Collection<Display> displays) {
editingDisplaysMap.put(player.getUniqueId(), displays);
this.editingDisplaysMap.put(player.getUniqueId(), displays);
}

/**
* @param player The player that should no longer be editing any displays.
*/
public void removeEditingDisplays(Player player) {
editingDisplaysMap.remove(player.getUniqueId());
this.editingDisplaysMap.remove(player.getUniqueId());
}

/**
* @param player The player that is editing display(s).
* @return The collection of displays the player is currently editing.
* If the player is not editing any displays, an display search is being started according to the players' @{link SelectionMode}.
*
* <p>
* Please note that this method will use the players' currently selected {@link LockSearchMode}.
*/
@Nullable
public Collection<Display> getEditingDisplays(Player player) {
return getEditingDisplays(player, Utilities.getToolSearchMode(player));
}

/**
* @param player The player that is editing display(s).
* @param lockSearchMode The lock search mode to check if an entity should be included in the selection or not.
Expand All @@ -51,11 +53,10 @@ public Collection<Display> getEditingDisplays(Player player) {
*/
@Nullable
public Collection<Display> getEditingDisplays(Player player, LockSearchMode lockSearchMode) {
Collection<Display> displays = editingDisplaysMap.get(player.getUniqueId());
Collection<Display> displays = this.editingDisplaysMap.get(player.getUniqueId());
if (displays != null) {
return displays;
}
return Utilities.getToolSelectMode(player).select(player, lockSearchMode);
}

}
27 changes: 14 additions & 13 deletions src/main/java/goldenshadow/displayentityeditor/MessageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ public MessageManager() throws IOException {
File f = new File(DisplayEntityEditor.getPlugin().getDataFolder().getAbsolutePath() + "/messages.yml");
InputStream configStream = new FileInputStream(f);
assert fallbackFileStream != null;
fallbackMap = yaml.load(fallbackFileStream);
messageMap = yaml.load(configStream);
this.fallbackMap = yaml.load(fallbackFileStream);
this.messageMap = yaml.load(configStream);
configStream.close();
fallbackFileStream.close();
}

public String getString(String key) {
String s = "";
if (messageMap.containsKey(key) && DisplayEntityEditor.getPlugin().getConfig().getBoolean("use-messages-file")) {
Object o = messageMap.get(key);
if (this.messageMap.containsKey(key) && DisplayEntityEditor.getPlugin().getConfig().getBoolean("use-messages-file")) {
Object o = this.messageMap.get(key);
if (o instanceof String) {
s = (String) o;
}
} else {
if (fallbackMap.containsKey(key) && !key.equals("file_version")) { //file version should never be gotten from fallback
Object o = fallbackMap.get(key);
if (this.fallbackMap.containsKey(key) && !key.equals("file_version")) { //file version should never be gotten from fallback
Object o = this.fallbackMap.get(key);
if (o instanceof String) {
s = (String) o;
}
Expand All @@ -47,10 +47,10 @@ public String getString(String key) {

public List<String> getList(String key) {
Object o = null;
if (messageMap.containsKey(key) && DisplayEntityEditor.getPlugin().getConfig().getBoolean("use-messages-file")) {
o = messageMap.get(key);
} else if (fallbackMap.containsKey(key)) {
o = fallbackMap.get(key);
if (this.messageMap.containsKey(key) && DisplayEntityEditor.getPlugin().getConfig().getBoolean("use-messages-file")) {
o = this.messageMap.get(key);
} else if (this.fallbackMap.containsKey(key)) {
o = this.fallbackMap.get(key);
}

List<String> returnList = new ArrayList<>();
Expand All @@ -69,10 +69,11 @@ public List<String> getList(String key) {
* @return True if everything is fine, false if the file should be updated
*/
public boolean isMessageMapComplete() {
for (String key : fallbackMap.keySet()) {
if (!messageMap.containsKey(key)) return false;
for (String key : this.fallbackMap.keySet()) {
if (!this.messageMap.containsKey(key)) {
return false;
}
}
return true;
}

}
34 changes: 15 additions & 19 deletions src/main/java/goldenshadow/displayentityeditor/SelectionMode.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package goldenshadow.displayentityeditor;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Stream;

import goldenshadow.displayentityeditor.enums.LockSearchMode;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Display;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;

import goldenshadow.displayentityeditor.enums.LockSearchMode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Stream;

public abstract class SelectionMode {

Expand All @@ -37,9 +36,8 @@ public static SelectionMode get(String mode) {
@Override
protected Stream<Display> select(Player p, double range, Predicate<Display> lockFilter) {
return p.getWorld().getNearbyEntities(p.getLocation(), range, range, range).stream().filter(DISPLAY_FILTER).map(DISPLAY_CAST)
.filter(lockFilter);
.filter(lockFilter);
}

};

public static final SelectionMode RAYCAST = new SelectionMode("raycast") {
Expand All @@ -58,7 +56,7 @@ protected Stream<Display> select(Player p, double range, Predicate<Display> lock
List<Display> displays;
for (double distance = 0d; distance < range; distance += 0.25d) {
displays = world.getNearbyEntities(loc = new Location(world, x + dx * distance, y + dy * distance, z + dz * distance),
0.75d, 0.25d, 0.75d).stream().filter(DISPLAY_FILTER).map(DISPLAY_CAST).filter(lockFilter).toList();
0.75d, 0.25d, 0.75d).stream().filter(DISPLAY_FILTER).map(DISPLAY_CAST).filter(lockFilter).toList();
if (displays.isEmpty()) {
continue;
}
Expand All @@ -76,7 +74,6 @@ protected Stream<Display> select(Player p, double range, Predicate<Display> lock
}
return Stream.empty();
}

};

private final String id;
Expand All @@ -88,21 +85,21 @@ public SelectionMode(String id) {
}

public final String id() {
return id;
return this.id;
}

public final int index() {
return idOrder.indexOf(id);
return idOrder.indexOf(this.id);
}

public final SelectionMode previousMode() {
int i = idOrder.indexOf(id);
return idToMode.get(i == 0 ? idOrder.get(idOrder.size() - 1) : idOrder.get(i - 1));
int i = idOrder.indexOf(this.id);
return idToMode.get(i == 0 ? idOrder.getLast() : idOrder.get(i - 1));
}

public final SelectionMode nextMode() {
int i = idOrder.indexOf(id);
return idToMode.get(i + 1 == idOrder.size() ? idOrder.get(0) : idOrder.get(i + 1));
int i = idOrder.indexOf(this.id);
return idToMode.get(i + 1 == idOrder.size() ? idOrder.getFirst() : idOrder.get(i + 1));
}

public final List<Display> select(Player p, LockSearchMode lockSearchMode) {
Expand Down Expand Up @@ -131,5 +128,4 @@ public final List<Display> select(Player p, LockSearchMode lockSearchMode) {
}

protected abstract Stream<Display> select(Player p, double range, Predicate<Display> lockFilter);

}
Loading
Loading