Skip to content

Commit

Permalink
feat(modifier): rework modifiers and design better inheritance (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
Snabeldier authored Dec 18, 2024
1 parent 086a536 commit 7c16a15
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 175 deletions.
53 changes: 10 additions & 43 deletions src/main/java/minevalley/core/api/armorstand/FakeArmorStand.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package minevalley.core.api.armorstand;

import minevalley.core.api.armorstand.modifiers.*;
import minevalley.core.api.users.OnlineUser;
import minevalley.core.api.armorstand.modifiers.MetadataModifier;
import minevalley.core.api.armorstand.modifiers.PassengerModifier;
import minevalley.core.api.armorstand.modifiers.PoseModifier;
import minevalley.core.api.armorstand.modifiers.RotationModifier;
import minevalley.core.api.modifiers.EquipmentModifier;
import minevalley.core.api.modifiers.InteractionModifier;
import minevalley.core.api.modifiers.LocationModifier;
import minevalley.core.api.modifiers.VisibilityModifier;

import java.util.function.BiConsumer;
import java.util.function.Function;

public interface FakeArmorStand extends EquipmentModifier, LocationModifier, MetadataModifier, PassengerModifier,
PoseModifier, RotationModifier {
public interface FakeArmorStand extends MetadataModifier, PassengerModifier, PoseModifier, RotationModifier,
EquipmentModifier, InteractionModifier, LocationModifier, VisibilityModifier {

/**
* Get the custom id from the armorstand
Expand Down Expand Up @@ -43,40 +46,4 @@ public interface FakeArmorStand extends EquipmentModifier, LocationModifier, Met
* @param visibilityRange range in blocks
*/
void setVisibilityRange(int visibilityRange);

/**
* Defines the action when a player interacts with the armorstand
*
* @param consumer is called whenever a user interacts with the armorstand
*/
void onClick(BiConsumer<OnlineUser, InteractType> consumer);

/**
* Defines which users can see the armorstand
* <br>
* <b>Default:</b> Everyone can see the armorstand
*
* @param function defines whether a specific user can see the armorstand
*/
void setVisibility(Function<OnlineUser, Boolean> function);

/**
* Updates the visibility of the armorstand
* <br>
* <b>Note:</b> This simply calls the function defined in {@link #setVisibility(Function)} for every user that the armorstand is or could be visible to
*/
void updateVisibility();

/**
* Updates the visibility of the armorstand for a specific user
* <br>
* <b>Note:</b> This simply calls the function defined in {@link #setVisibility(Function)} for this user
*
* @param user to update the visibility for
*/
void updateVisibility(OnlineUser user);

enum InteractType {
LEFT_CLICK, RIGHT_CLICK
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package minevalley.core.api.armorstand.modifiers;

@SuppressWarnings("unused")
public interface MetadataModifier {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

import java.util.List;

@SuppressWarnings("unused")
public interface PassengerModifier {

/**
* get the current passenger list
* Get the current passenger list
*
* @return a list with the passengers as entities
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.bukkit.util.EulerAngle;

@SuppressWarnings("unused")
public interface PoseModifier {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package minevalley.core.api.armorstand.modifiers;

@SuppressWarnings("unused")
public interface RotationModifier {

/**
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/minevalley/core/api/enums/InteractionType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package minevalley.core.api.enums;

@SuppressWarnings("unused")
public enum InteractionType {

LEFT_CLICK,
SHIFT_LEFT_CLICK,
RIGHT_CLICK,
SHIFT_RIGHT_CLICK;

public boolean isLeftClick() {
return this == LEFT_CLICK || this == SHIFT_LEFT_CLICK;
}

public boolean isRightClick() {
return this == RIGHT_CLICK || this == SHIFT_RIGHT_CLICK;
}

public boolean isShiftClick() {
return this == SHIFT_LEFT_CLICK || this == SHIFT_RIGHT_CLICK;
}
}
Original file line number Diff line number Diff line change
@@ -1,101 +1,102 @@
package minevalley.core.api.armorstand.modifiers;
package minevalley.core.api.modifiers;

import org.bukkit.inventory.ItemStack;

@SuppressWarnings("unused")
public interface EquipmentModifier {

/**
* Get the item in the armorstands left hand
* Get the item in the left hand
*
* @return item in left hand
*/
ItemStack getLeftHand();

/**
* Set the item in the armorstands left hand
* Set the item in the left hand
*
* @param itemStack item to set
* @return this
*/
EquipmentModifier setLeftHand(ItemStack itemStack);

/**
* Get the item in the armorstands right hand
* Get the item in the right hand
*
* @return item in right hand
*/
ItemStack getRightHand();

/**
* Set the item in the armorstands right hand
* Set the item in the right hand
*
* @param itemStack item to set
* @return this
*/
EquipmentModifier setRightHand(ItemStack itemStack);

/**
* Get the item in the armorstands helmet slot
* Get the item in the helmet slot
*
* @return item in helmet slot
*/
ItemStack getHelmet();

/**
* Set the item in the armorstands helmet slot
* Set the item in the helmet slot
*
* @param helmet item to set
* @return this
*/
EquipmentModifier setHelmet(ItemStack helmet);

/**
* Get the item in the armorstands chestplate slot
* Get the item in the chestplate slot
*
* @return item in chestplate slot
*/
ItemStack getChestplate();

/**
* Set the item in the armorstands chestplate slot
* Set the item in the chestplate slot
*
* @param chestplate item to set
* @return this
*/
EquipmentModifier setChestplate(ItemStack chestplate);

/**
* Get the item in the armorstands leggings slot
* Get the item in the leggings slot
*
* @return item in leggings slot
*/
ItemStack getLeggings();

/**
* Set the item in the armorstands leggings slot
* Set the item in the leggings slot
*
* @param leggings item to set
* @return this
*/
EquipmentModifier setLeggings(ItemStack leggings);

/**
* Get the item in the armorstands boots slot
* Get the item in the boots slot
*
* @return item in boots slot
*/
ItemStack getBoots();

/**
* Set the item in the armorstands boots slot
* Set the item in the boots slot
*
* @param boots item to set
* @return this
*/
EquipmentModifier setBoots(ItemStack boots);

/**
* Update the armorstands equipment
* Update the equipment
*/
void updateEquipment();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package minevalley.core.api.modifiers;

import minevalley.core.api.enums.InteractionType;
import minevalley.core.api.users.OnlineUser;

import java.util.function.BiConsumer;

@SuppressWarnings("unused")
public interface InteractionModifier {

/**
* Defines the action when a user interacts with this object.
*
* @param consumer is called whenever a user interacts with this object
*/
void onClick(BiConsumer<OnlineUser, InteractionType> consumer);
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
package minevalley.core.api.armorstand.modifiers;
package minevalley.core.api.modifiers;

import org.bukkit.Location;

@SuppressWarnings("unused")
public interface LocationModifier {

/**
* Get the location of the armorstand
* Get the location
*
* @return location
*/
Location getLocation();

/**
* Sets the armorstands location.
* Sets the location
* <br>
* <b>Note:</b> This ignores the yaw and pitch values.
*
* @param location new location of the armorstand.
* @param location new location.
*/
LocationModifier setLocation(Location location);

/**
* Update the location of the armorstand
* Update the location
*/
void updateLocation();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package minevalley.core.api.modifiers;

import minevalley.core.api.users.OnlineUser;

import java.util.function.Function;

@SuppressWarnings("unused")
public interface VisibilityModifier {

/**
* Defines who can see this object
* <br>
* <b>Default:</b> Everyone can see this object
*
* @param function defines whether a specific user can see this object
*/
void setVisibility(Function<OnlineUser, Boolean> function);

/**
* Updates the visibility of this object
* <br>
* <b>Note:</b> This simply calls the function defined in {@link #setVisibility(Function)} for every user that this object is or could be visible to
*/
void updateVisibility();

/**
* Updates the visibility of this object for a specific user
* <br>
* <b>Note:</b> This simply calls the function defined in {@link #setVisibility(Function)} for this user
*
* @param user to update the visibility for
*/
void updateVisibility(OnlineUser user);
}
Loading

0 comments on commit 7c16a15

Please sign in to comment.