Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to lowercase this library or the project wouldn't build, but it's not related to issue #4260

Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@
</dependency>
<!-- This needs to be before Spigot because MockBukkit will fail otherwise. -->
<dependency>
<groupId>com.github.MockBukkit</groupId>
<groupId>com.github.mockbukkit</groupId>
<artifactId>MockBukkit</artifactId>
<version>c7cc678834</version>
<scope>test</scope>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,15 @@ public void scan(@Nonnull Player p, @Nonnull Block block, int page) {
String title = "&4" + Slimefun.getLocalization().getResourceString(p, "tooltips.results");
ChestMenu menu = new ChestMenu(title);

// Prevent both shift-clicking and number key usage
menu.setPlayerInventoryClickable(false);
menu.setEmptySlotsClickable(false);

// Add click handler to explicitly deny shift and number key actions
menu.addPlayerInventoryClickHandler((player, slot, item, action) -> {
return false; // Deny all player inventory interactions
});

for (int slot : backgroundSlots) {
menu.addItem(slot, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
* The {@link GPSNetwork} is a manager class for all {@link GPSTransmitter Transmitters} and waypoints.
* There can only be one instance of this class per {@link Server}.
* It is also responsible for teleportation and resource management.
*
*
* @author TheBusyBiscuit
*
*
* @see TeleportationManager
* @see ResourceManager
*
Expand All @@ -64,7 +64,7 @@ public class GPSNetwork {
/**
* This constructs a new {@link GPSNetwork}.
* Note that this network is per {@link Server} and not per {@link Player}.
*
*
* @param plugin
* Our {@link Slimefun} instance
*/
Expand All @@ -74,7 +74,7 @@ public GPSNetwork(@Nonnull Slimefun plugin) {

/**
* This method updates the status of a {@link GPSTransmitter}.
*
*
* @param l
* The {@link Location} of the {@link GPSTransmitter}
* @param uuid
Expand All @@ -96,10 +96,10 @@ public void updateTransmitter(@Nonnull Location l, @Nonnull UUID uuid, boolean o
* This method calculates the GPS complexity for the given {@link UUID}.
* The complexity is determined by the Y level of each {@link GPSTransmitter}
* multiplied by the multiplier of that transmitter.
*
*
* @param uuid
* The {@link UUID} who to calculate it for
*
*
* @return The network complexity for that {@link UUID}
*/
public int getNetworkComplexity(@Nonnull UUID uuid) {
Expand All @@ -124,10 +124,10 @@ public int getNetworkComplexity(@Nonnull UUID uuid) {
/**
* This method returns the amount of {@link GPSTransmitter Transmitters} for the
* given {@link UUID}.
*
*
* @param uuid
* The {@link UUID} who these transmitters belong to
*
*
* @return The amount of transmitters
*/
public int countTransmitters(@Nonnull UUID uuid) {
Expand All @@ -138,13 +138,23 @@ public int countTransmitters(@Nonnull UUID uuid) {
/**
* This method opens the {@link GPSTransmitter} control panel to the given
* {@link Player}.
*
*
* @param p
* The {@link Player}
*/
public void openTransmitterControlPanel(@Nonnull Player p) {
ChestMenu menu = new ChestMenu(ChatColor.BLUE + Slimefun.getLocalization().getMessage(p, "machines.GPS_CONTROL_PANEL.title"));

// Prevent both shift-clicking and number key usage
menu.setPlayerInventoryClickable(false);
menu.setEmptySlotsClickable(false);

// Add click handler to explicitly deny shift and number key actions
menu.addPlayerInventoryClickHandler((player, slot, item, action) -> {
return false; // Deny all player inventory interactions
});

// Rest of the method remains unchanged
for (int slot : border) {
menu.addItem(slot, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
}
Expand Down Expand Up @@ -192,14 +202,14 @@ public void openTransmitterControlPanel(@Nonnull Player p) {
* The icon is dependent on the {@link Environment} of the waypoint's {@link World}.
* However if the name of this waypoint indicates that this is actually a deathmarker
* then a different texture will be used.
*
*
* Otherwise it will return a globe, a nether or end sphere according to the {@link Environment}.
*
*
* @param name
* The name of a waypoint
* @param environment
* The {@link Environment} of the waypoint's {@link World}
*
*
* @return An icon for this waypoint
*/
@ParametersAreNonnullByDefault
Expand Down Expand Up @@ -228,6 +238,15 @@ public void openWaypointControlPanel(@Nonnull Player p) {
PlayerProfile.get(p, profile -> {
ChestMenu menu = new ChestMenu(ChatColor.BLUE + Slimefun.getLocalization().getMessage(p, "machines.GPS_CONTROL_PANEL.title"));

// Prevent both shift-clicking and number key usage
menu.setPlayerInventoryClickable(false);
menu.setEmptySlotsClickable(false);

// Add click handler to explicitly deny shift and number key actions
menu.addPlayerInventoryClickHandler((player, slot, item, action) -> {
return false; // Deny all player inventory interactions
});

for (int slot : border) {
menu.addItem(slot, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
}
Expand Down Expand Up @@ -273,7 +292,7 @@ public void openWaypointControlPanel(@Nonnull Player p) {
/**
* This method will prompt the given {@link Player} to enter a name for a waypoint.
* After entering the name, it will be added to his waypoint list.
*
*
* @param p
* The {@link Player} who should get a new waypoint
* @param l
Expand All @@ -298,7 +317,7 @@ public void createWaypoint(@Nonnull Player p, @Nonnull Location l) {

/**
* This method adds a new waypoint with the given name and {@link Location} for that {@link Player}.
*
*
* @param p
* The {@link Player} to get the new waypoint
* @param name
Expand Down Expand Up @@ -343,10 +362,10 @@ public void addWaypoint(@Nonnull Player p, @Nonnull String name, @Nonnull Locati
/**
* This method returns a {@link Set} of {@link Location Locations} for all {@link GPSTransmitter Transmitters}
* owned by the given {@link UUID}.
*
*
* @param uuid
* The {@link UUID} owning those transmitters
*
*
* @return A {@link Set} with all {@link Location Locations} of transmitters for this {@link UUID}
*/
@Nonnull
Expand All @@ -357,7 +376,7 @@ public Set<Location> getTransmitters(@Nonnull UUID uuid) {
/**
* This returns the {@link TeleportationManager} for this {@link GPSNetwork}.
* It is responsible for all actions that relate to the {@link Teleporter}.
*
*
* @return The {@link TeleportationManager} for this {@link GPSNetwork}
*/
@Nonnull
Expand All @@ -368,7 +387,7 @@ public TeleportationManager getTeleportationManager() {
/**
* This returns the {@link ResourceManager} for this {@link GPSNetwork}.
* Use this to access {@link GEOResource GEOResources}.
*
*
* @return The {@link ResourceManager} for this {@link GPSNetwork}
*/
@Nonnull
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package me.mrCookieSlime.CSCoreLibPlugin.general.Inventory;

import org.bukkit.event.inventory.InventoryClickEvent;

/**
* An old remnant of CS-CoreLib.
* This will be removed once we updated everything.
Expand All @@ -9,10 +11,18 @@ public class ClickAction {

private boolean right;
private boolean shift;
private boolean numberKey;

public ClickAction(boolean rightClicked, boolean shiftClicked) {
this.right = rightClicked;
this.shift = shiftClicked;
this.numberKey = false;
}

public ClickAction(InventoryClickEvent e) {
this.right = e.isRightClick();
this.shift = e.isShiftClick();
this.numberKey = e.getClick().name().equals("NUMBER_KEY");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you checking the name instead of just the enum itself?

@RaphaelFakhri RaphaelFakhri Mar 7, 2025

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Because comparing an enum to a string always returns false
  2. Because the bukkit API does not have a native isNumberKey() method, which I would have used

Another way of writing this would be this.numberKey = e.getClick() == ClickType.NUMBER_KEY;, I just thought that a string would be more simple

}

public boolean isRightClicked() {
Expand All @@ -22,5 +32,8 @@ public boolean isRightClicked() {
public boolean isShiftClicked() {
return shift;
}


public boolean isNumberKey() {
return numberKey;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ public void onClick(InventoryClickEvent e) {
if (handler == null) {
e.setCancelled(!menu.isEmptySlotsClickable() && (e.getCurrentItem() == null || e.getCurrentItem().getType() == Material.AIR));
} else if (handler instanceof AdvancedMenuClickHandler) {
e.setCancelled(!((AdvancedMenuClickHandler) handler).onClick(e, (Player) e.getWhoClicked(), e.getSlot(), e.getCursor(), new ClickAction(e.isRightClick(), e.isShiftClick())));
e.setCancelled(!((AdvancedMenuClickHandler) handler).onClick(e, (Player) e.getWhoClicked(), e.getSlot(), e.getCursor(), new ClickAction(e)));
} else {
e.setCancelled(!handler.onClick((Player) e.getWhoClicked(), e.getSlot(), e.getCurrentItem(), new ClickAction(e.isRightClick(), e.isShiftClick())));
e.setCancelled(!handler.onClick((Player) e.getWhoClicked(), e.getSlot(), e.getCurrentItem(), new ClickAction(e)));
}
} else {
e.setCancelled(!menu.getPlayerInventoryClickHandler().onClick((Player) e.getWhoClicked(), e.getSlot(), e.getCurrentItem(), new ClickAction(e.isRightClick(), e.isShiftClick())));
e.setCancelled(!menu.getPlayerInventoryClickHandler().onClick((Player) e.getWhoClicked(), e.getSlot(), e.getCurrentItem(), new ClickAction(e)));
}
}
}
Expand Down