Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #84

Merged
merged 5 commits into from
Dec 8, 2024
Merged
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.mcmiddleearth</groupId>
<artifactId>MCME-Architect</artifactId>
<version>2.9.14</version>
<version>2.9.15</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.mcmiddleearth.architect.specialBlockHandling.command.GetCommand;
import com.mcmiddleearth.architect.specialBlockHandling.command.InvCommand;
import com.mcmiddleearth.architect.specialBlockHandling.command.SwitchStickCommand;
import com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.CustomInventoryEditor;
import com.mcmiddleearth.architect.specialBlockHandling.data.*;
import com.mcmiddleearth.architect.specialBlockHandling.itemBlock.ItemBlockCommand;
import com.mcmiddleearth.architect.specialBlockHandling.itemBlock.ItemBlockListener;
Expand Down Expand Up @@ -146,7 +147,8 @@ public void onEnable() {
setCommandExecutor("switchstick", new SwitchStickCommand());
//setCommandExecutor("speed", new SpeedCommand());
// setCommandExecutor("newafkk", new NewAfkCommand());


CustomInventoryEditor.init(this);

rpSwitchTask = new RPSwitchTask().runTaskTimer(this, 500, 20);
ItemBlockManager.startEntityGlowTask();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/mcmiddleearth/architect/Permission.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public enum Permission {
INV_COMMAND ("architect.inventory"),
INV_OTHER ("architect.inventory.other"),
INV_SAVE ("architect.inventory.save"),
INV_EDIT ("architect.inventory.edit"),
INV_RELOAD_COMMAND ("architect.inventory.reload"),
INVENTORY_OPEN ("architect.inventory.open"),
NO_PHYSICS_LIST ("architect.noPhysicsList.view"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.mcmiddleearth.connect.log.Log;
import com.mcmiddleearth.util.DevUtil;
import com.mcmiddleearth.util.ResourceUtil;
import com.viaversion.viaversion.api.Via;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
Expand Down Expand Up @@ -213,6 +214,9 @@ private static ConfigurationSection getConfigSection(String rp, Player player) {
RpPlayerData data;
if (player != null) {
data = getPlayerData(player);
if(data.getProtocolVersion()==0) {
data.setProtocolVersion(Via.getAPI().getPlayerProtocolVersion(player.getUniqueId()).getVersion());
}
} else {
data = new RpPlayerData();
}
Expand Down Expand Up @@ -344,6 +348,7 @@ public static boolean setRp(String rpName, Player player, boolean force) {
RpPlayerData data = getPlayerData(player);
if(url!=null && data!=null && !url.equals("") && (force || !url.equals(data.getCurrentRpUrl()))) {
data.setCurrentRpUrl(url);
//Logger.getGlobal().info("Sending to "+player.getName()+"("+getPlayerData(player).getProtocolVersion()+") RP: "+url);
player.setResourcePack(url, getSHA(rpName, player));
savePlayerData(player);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class RpPluginMessageListener implements PluginMessageListener {
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, byte[] bytes) {
//Logger.getGlobal().info("Sodium client detected: "+player.getName());

Logger.getGlobal().info("Received message from player " + player.getName() + " on channel "
+ channel + " with data " + Arrays.toString(bytes));
//Logger.getGlobal().info("Received message from player " + player.getName() + " on channel "
// + channel + " with data " + Arrays.toString(bytes));
try (var dataStream = new DataInputStream(new ByteArrayInputStream(bytes))) {
int stringLength = readVarInt(dataStream);
String jsonString = new String(dataStream.readNBytes(stringLength));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@
*/

import com.mcmiddleearth.architect.ArchitectPlugin;
import com.mcmiddleearth.architect.Permission;
import com.mcmiddleearth.architect.serverResoucePack.RpManager;
import com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.CustomInventoryEditor;
import com.mcmiddleearth.architect.specialBlockHandling.data.SpecialBlockInventoryData;
import com.mcmiddleearth.architect.specialBlockHandling.data.SpecialHeadInventoryData;
import com.mcmiddleearth.architect.specialBlockHandling.data.SpecialItemInventoryData;
import com.mcmiddleearth.architect.specialBlockHandling.specialBlocks.SpecialBlock;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -339,6 +343,28 @@ void onCategoryChange(final InventoryClickEvent event) {
}
}
}

@EventHandler(priority = EventPriority.HIGHEST)
void onInventoryEdit(final InventoryClickEvent event) {
if (openInventories.containsKey(event.getInventory())) { //.getTitle.equals(name)) {
if (event.getWhoClicked() instanceof Player player
&& player.hasPermission(Permission.INV_EDIT.getPermissionNode())
&& event.getRawSlot() >= CATEGORY_SLOTS
&& event.getRawSlot() < event.getInventory().getSize()
&& event.isRightClick()
&& event.isShiftClick()) {//items.size()/9+1)*9
CustomInventoryState state = openInventories.get(event.getInventory());
String category = state.categoryNames[state.currentCategory];
String rpName = RpManager.getCurrentRpName(state.getPlayer());
event.getInventory().close();
if(event.getCurrentItem() == null) {
CustomInventoryEditor.addBlock(player, rpName, category, state, event.getRawSlot());
} else {
CustomInventoryEditor.editBlock(player, category, state, event.getRawSlot(), event.getCurrentItem());
}
}
}
}

@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
void onClose(final InventoryCloseEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.bukkit.inventory.ItemStack;

import java.util.*;
import java.util.logging.Logger;

/**
*
Expand Down Expand Up @@ -85,7 +86,10 @@ public boolean isVisible(Player player) {
}

public ItemStack getItem(String id) {
return items.stream().filter(item -> SpecialBlockInventoryData.getSpecialBlockId(item).equals(id)).findAny().orElse(null);
return items.stream().filter(item -> {
String blockId = SpecialBlockInventoryData.getSpecialBlockId(item);
return blockId != null && blockId.equals(id);
}).findAny().orElse(null);
}

public boolean isPublic() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.bukkit.inventory.meta.ItemMeta;

import java.util.*;
import java.util.logging.Logger;

/**
*
Expand Down Expand Up @@ -212,4 +213,8 @@ public boolean isDirectGet() {
public void setDirectGet(boolean directGet) {
this.directGet = directGet;
}

public SpecialBlock getBaseBlock() {
return baseBlock;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,8 @@ public static ItemStack newPagingItem(Material material, int cmd, String display
}

public abstract boolean usesSubcategories();

public Player getPlayer() {
return player;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,14 @@ public boolean isEmpty() {

public ItemStack getItem(String id) {
//Logger.getGlobal().info("search getItem: "+id);
return items.stream().filter(item -> item.getItemMeta().getLore().get(1).equals(id)).findFirst().orElse(null);
return items.stream().filter(item -> {
if(item.hasItemMeta() && item.getItemMeta().hasLore()) {
return item.getItemMeta().getLore().get(1).equals(id);
// } else {
// Logger.getGlobal().warning("Invalid item in search inventory: "+item);
}
return false;
}).findFirst().orElse(null);
}

public Set<NamespacedKey> getRecipeKeys() {
Expand Down
Loading
Loading