Skip to content

Commit

Permalink
Merge pull request #22 from DarkKnights22/edit-multiple-displays
Browse files Browse the repository at this point in the history
Add the ability to edit multiple displays at a time
  • Loading branch information
GoldenShad0w authored Feb 3, 2024
2 parents cce4e07 + e8d03c5 commit b4ffa97
Show file tree
Hide file tree
Showing 7 changed files with 566 additions and 334 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>goldenshadow</groupId>
<artifactId>DisplayEntityEditor</artifactId>
<version>1.0.13</version>
<version>1.0.14</version>
<packaging>jar</packaging>

<name>DisplayEntityEditor</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public final class DisplayEntityEditor extends JavaPlugin {
.build();
public static MessageManager messageManager;

private EditingHandler editingHandler;

/**
* Used for when the plugin starts up
*/
Expand All @@ -70,11 +72,13 @@ public void onEnable() {
plugin.getLogger().severe("Failed to load messages.yml!");
}

this.editingHandler = new EditingHandler();

conversationFactory = new ConversationFactory(plugin);
inventoryFactory = new InventoryFactory(new GUIItems(), new InventoryItems());
Objects.requireNonNull(getCommand("displayentityeditor")).setExecutor(new Command());
Objects.requireNonNull(getCommand("displayentityeditor")).setTabCompleter(new TabComplete());
Bukkit.getPluginManager().registerEvents(new Interact(), plugin);
Bukkit.getPluginManager().registerEvents(new Interact(editingHandler), plugin);
Bukkit.getPluginManager().registerEvents(new InventoryClick(), plugin);
Bukkit.getPluginManager().registerEvents(new InventoryClose(), plugin);
Bukkit.getPluginManager().registerEvents(new PlayerJoin(), plugin);
Expand Down Expand Up @@ -125,4 +129,8 @@ public static void checkForMessageFile() throws IOException {
}
messageManager = new MessageManager();
}

public EditingHandler getEditingHandler() {
return editingHandler;
}
}
48 changes: 48 additions & 0 deletions src/main/java/goldenshadow/displayentityeditor/EditingHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package goldenshadow.displayentityeditor;

import org.bukkit.entity.Display;
import org.bukkit.entity.Player;

import java.util.*;

public class EditingHandler {

/**
* The map of player UUIDs to the displays they are currently editing.
*/
private final Map<UUID, Collection<Display>> editingDisplaysMap = new HashMap<>();

/**
* @param player The player that should be editing the displays.
* @param displays The collection of displays the player should be editing.
*/
public void setEditingDisplays(Player player, Collection<Display> displays) {
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());
}

/**
* @param player The player that is editing display(s).
* @param lockSearchToggle Whether the searched entities should be locked/unlocked.
* @return The collection of displays the player is currently editing.
* If the player is not editing any displays, the nearest display entity to the player's location is returned
* as a singleton collection.
* @see Utilities#getNearestDisplayEntity(org.bukkit.Location, boolean)
*/
public Collection<Display> getEditingDisplays(Player player, boolean lockSearchToggle) {
Collection<Display> displays = editingDisplaysMap.get(player.getUniqueId());

if (displays == null) {
return Collections.singleton(Utilities.getNearestDisplayEntity(player.getLocation(), lockSearchToggle));
}

return displays;
}

}
815 changes: 483 additions & 332 deletions src/main/java/goldenshadow/displayentityeditor/events/Interact.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public ItemStack[] getInventoryArray(Player p) {
array[12] = inventoryItems.rightRotationX(p);
array[13] = inventoryItems.rightRotationY(p);
array[14] = inventoryItems.rightRotationZ(p);
array[15] = inventoryItems.groupSelectTool(p);

return array;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ public ItemStack toolPrecision() {
return itemStack;
}

/**
* Creates the clone item
* @return The item
*/
public ItemStack cloneTool() {
ItemStack itemStack = new ItemStack(Material.FLOWER_BANNER_PATTERN);
Utilities.setMeta(itemStack, DisplayEntityEditor.messageManager.getString("clone_tool_name"),
Expand All @@ -374,4 +378,18 @@ public ItemStack cloneTool() {
);
return itemStack;
}

/**
* Creates the group select item
* @return The item
*/
public ItemStack groupSelectTool(Player p) {
ItemStack itemStack = new ItemStack(Material.MINECART);
Utilities.setMeta(itemStack, DisplayEntityEditor.messageManager.getString("group_select_name"),
DisplayEntityEditor.messageManager.getList("group_select_lore"),
"InventoryGroupSelect",
Utilities.reduceFloatLength(Double.toString(Utilities.getToolPrecision(p)))
);
return itemStack;
}
}
6 changes: 6 additions & 0 deletions src/main/resources/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ tool_precision_name: "&eChange Tool Precision"
tool_precision_lore: ["&7Click to change the multiplier for", "&7your tools precision.", " ", "&e&lRIGHT-CLICK&r&e to increase by 1", "&e&lSHIFT RIGHT-CLICK&r&e to decrease by 1"]
clone_tool_name: "&eClone Display Entity"
clone_tool_lore: ["&7Click to duplicate the nearest", "&7display entity", " ", "&e&lRIGHT-CLICK&r&e to clone"]
group_select_name: "&eGroup Select"
group_select_lore: ["&7Click to add a display entities within", "&7the current range to a group, where", "&7all entities will be edited simultaneously", " ", "&e&lRIGHT-CLICK&r&e to select all within %s blocks", "&e&lSHIFT RIGHT-CLICK&r&e to clear group"]

# GUI Items
name_name: "&eSet Name"
Expand Down Expand Up @@ -147,6 +149,7 @@ unlock_fail: "There is no locked display entity within 5 blocks!"
unlock_success: "Display entity unlocked!"
tool_precision: "Tool Precision: %s"
gui_open_fail: "Someone else is editing this entity at the moment!"
gui_only_single_displays: "This GUI is only for modifying single display entities!"
yaw: "Yaw: %s"
pitch: "Pitch: %s"
move_x: "X: %s"
Expand All @@ -168,6 +171,9 @@ right_rot_y: "Right Rotation Y %s: %s"
right_rot_z: "Right Rotation Z %s: %s"
center_block: "Centered at: %f %f %f"
clone: "Display entity cloned!"
group_select_fail: "There are no unlocked display entities within the specified range!"
group_select_success: "Created group containing %s display entities!"
group_select_clear: "Cleared current editing group!"

# Input prompts
prompt_escape_word: "cancel"
Expand Down

0 comments on commit b4ffa97

Please sign in to comment.