forked from Slimefun/Slimefun4
-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
101 changed files
with
2,608 additions
and
607 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
before_install: | ||
- sdk install java 17.0.5-zulu | ||
- sdk use java 17.0.5-zulu | ||
- sdk install java 21.0.2-open | ||
- sdk use java 21.0.2-open | ||
- sdk install maven | ||
|
||
jdk: | ||
- openjdk21 | ||
|
||
install: | ||
- chmod 777 ./mvnw | ||
- ./mvnw -s .mvn/settings.xml install -DskipTests | ||
- ./mvnw -s .mvn/settings.xml install -DskipTests |
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
73 changes: 73 additions & 0 deletions
73
src/main/java/city/norain/slimefun4/api/menu/UniversalMenu.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,73 @@ | ||
package city.norain.slimefun4.api.menu; | ||
|
||
import java.util.UUID; | ||
import javax.annotation.Nonnull; | ||
import lombok.Getter; | ||
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; | ||
import me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu; | ||
import org.bukkit.Location; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
/** | ||
* This class represents a universal chest menu | ||
* which a menu located by certain identify id instead of location. | ||
*/ | ||
public class UniversalMenu extends DirtyChestMenu { | ||
@Getter | ||
private final UUID uuid; | ||
|
||
public UniversalMenu(@Nonnull UniversalMenuPreset preset, @Nonnull UUID uuid) { | ||
this(preset, uuid, (Location) null); | ||
} | ||
|
||
public UniversalMenu(@Nonnull UniversalMenuPreset preset, @Nonnull UUID uuid, Location lastPresent) { | ||
super(preset); | ||
this.uuid = uuid; | ||
|
||
preset.clone(this, lastPresent); | ||
this.getContents(); | ||
} | ||
|
||
public UniversalMenu( | ||
@Nonnull UniversalMenuPreset preset, @Nonnull UUID uuid, Location lastPresent, ItemStack[] contents) { | ||
super(preset); | ||
this.uuid = uuid; | ||
|
||
for (int i = 0; i < contents.length; i++) { | ||
var item = contents[i]; | ||
if (item == null || item.getType().isAir()) { | ||
continue; | ||
} | ||
addItem(i, item); | ||
} | ||
|
||
preset.clone(this, lastPresent); | ||
this.getContents(); | ||
} | ||
|
||
public UniversalMenu(@Nonnull UniversalMenuPreset preset, @Nonnull UUID uuid, ItemStack[] contents) { | ||
this(preset, uuid, null, contents); | ||
} | ||
|
||
public void update(@Nonnull Location lastPresent) { | ||
((UniversalMenuPreset) preset).clone(this, lastPresent); | ||
} | ||
|
||
/** | ||
* This method drops the contents of this {@link BlockMenu} on the ground at the given | ||
* {@link Location}. | ||
* | ||
* @param l Where to drop these items | ||
* @param slots The slots of items that should be dropped | ||
*/ | ||
public void dropItems(Location l, int... slots) { | ||
for (int slot : slots) { | ||
ItemStack item = getItemInSlot(slot); | ||
|
||
if (item != null) { | ||
l.getWorld().dropItemNaturally(l, item); | ||
replaceExistingItem(slot, null); | ||
} | ||
} | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
src/main/java/city/norain/slimefun4/api/menu/UniversalMenuPreset.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,75 @@ | ||
package city.norain.slimefun4.api.menu; | ||
|
||
import com.xzavier0722.mc.plugin.slimefun4.storage.util.StorageCacheUtils; | ||
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; | ||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; | ||
import me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu; | ||
import org.bukkit.Location; | ||
import org.bukkit.block.Block; | ||
|
||
public abstract class UniversalMenuPreset extends BlockMenuPreset { | ||
/** | ||
* Creates a new ChestMenu with the specified | ||
* Title | ||
* | ||
* @param title The title of the Menu | ||
*/ | ||
public UniversalMenuPreset(@Nonnull String id, @Nonnull String title) { | ||
super(id, title); | ||
} | ||
|
||
public void newInstance(@Nonnull UniversalMenu menu, @Nonnull Block b) { | ||
// This method can optionally be overridden by implementations | ||
} | ||
|
||
@Override | ||
protected void clone(@Nonnull DirtyChestMenu menu) { | ||
if (menu instanceof UniversalMenu universalMenu) { | ||
var uniData = StorageCacheUtils.getUniversalBlock(universalMenu.getUuid()); | ||
|
||
if (uniData == null) { | ||
return; | ||
} | ||
|
||
clone(universalMenu, uniData.getLastPresent().toLocation()); | ||
} | ||
} | ||
|
||
protected void clone(@Nonnull UniversalMenu menu, @Nonnull Location lastPresent) { | ||
menu.setPlayerInventoryClickable(true); | ||
|
||
for (int slot : occupiedSlots) { | ||
menu.addItem(slot, getItemInSlot(slot)); | ||
} | ||
|
||
if (getSize() > -1) { | ||
menu.addItem(getSize() - 1, null); | ||
} | ||
|
||
newInstance(menu, lastPresent.getBlock()); | ||
|
||
for (int slot = 0; slot < 54; slot++) { | ||
if (getMenuClickHandler(slot) != null) { | ||
menu.addMenuClickHandler(slot, getMenuClickHandler(slot)); | ||
} | ||
} | ||
|
||
menu.addMenuOpeningHandler(getMenuOpeningHandler()); | ||
menu.addMenuCloseHandler(getMenuCloseHandler()); | ||
} | ||
|
||
@Nullable public static UniversalMenuPreset getPreset(@Nullable String id) { | ||
if (id == null) { | ||
return null; | ||
} else { | ||
var preset = Slimefun.getRegistry().getMenuPresets().get(id); | ||
if (preset instanceof UniversalMenuPreset uniPreset) { | ||
return uniPreset; | ||
} else { | ||
return null; | ||
} | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/city/norain/slimefun4/compatibillty/VersionedAttribute.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,16 @@ | ||
package city.norain.slimefun4.compatibillty; | ||
|
||
import city.norain.slimefun4.SlimefunExtended; | ||
import lombok.experimental.UtilityClass; | ||
import org.bukkit.attribute.Attribute; | ||
|
||
@UtilityClass | ||
public class VersionedAttribute { | ||
public static Attribute getMaxHealth() { | ||
if (SlimefunExtended.getMinecraftVersion().isAtLeast(1, 21, 3)) { | ||
return Attribute.valueOf("MAX_HEALTH"); | ||
} else { | ||
return Attribute.valueOf("GENERIC_MAX_HEALTH"); | ||
} | ||
} | ||
} |
Oops, something went wrong.