Skip to content

Commit

Permalink
feat: size add argument
Browse files Browse the repository at this point in the history
  • Loading branch information
maximjsx committed Nov 27, 2024
1 parent 43ec0a4 commit 98dc54d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group = 'com.maximde'
version = '1.5.4'
version = '1.6.0'

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ private void applyAttributeModifiers(LivingEntity entity, double newScale) {
modifiers.forEach(modifier -> modifier.apply(entity, newScale));
}

public double getSize(LivingEntity livingEntity) {
return livingEntity.getAttribute(Attribute.GENERIC_SCALE).getBaseValue();
}

public void resetSize(Player player) {
List.of(
new AttributeModifier(Attribute.GENERIC_SCALE, 1.0D),
Expand Down Expand Up @@ -148,4 +152,6 @@ public Optional<LivingEntity> getEntity(Player player, int range) {
.filter(e -> playerLookDir.angle(
e.getLocation().toVector().subtract(playerEyeLocation)) < 0.4f);
}


}
4 changes: 4 additions & 0 deletions src/main/java/com/maximde/entitysize/EntitySize.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public void setSize(LivingEntity livingEntity, double newScale) {
modifierService.setSize(livingEntity, newScale);
}

public double getSize(LivingEntity livingEntity) {
return modifierService.getSize(livingEntity);
}

public Optional<LivingEntity> getEntity(Player player, int range) {
return modifierService.getEntity(player, range);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityToggleGlideEvent;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.StringUtil;
Expand Down Expand Up @@ -38,7 +39,31 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
if(args.length < 1) return sendCommands(sender);

switch (args[0].toLowerCase()) {
case "player" -> {
case "add" -> {
if (!hasPermission(sender, entitySize.getPermission("add"))) {
sender.sendMessage(entitySize.getPrimaryColor() + "You don't have the permission to execute this subcommand!");
return false;
}
if (!(sender instanceof Player player)) {
sender.sendMessage(entitySize.getPrimaryColor() + "This command can only be used by players!");
return false;
}
if (args.length < 2) {
sender.sendMessage(entitySize.getPrimaryColor() + "Usage: /entitysize add <size>");
return false;
}
try {
double currentSize = entitySize.getSize(player);
double deltaSize = Double.parseDouble(args[1]);
double newSize = currentSize + deltaSize;

setSize(sender, player, newSize, -1);
sender.sendMessage(entitySize.getPrimaryColor() + "Your size has been updated to " + newSize + "!");
} catch (NumberFormatException e) {
sender.sendMessage(entitySize.getPrimaryColor() + "Invalid number format!");
}
}
case "player" -> {
if(!hasPermission(sender, entitySize.getPermission("player"))) {
sender.sendMessage(entitySize.getPrimaryColor() + "You don't have the permission to execute this subcommand!");
return false;
Expand Down Expand Up @@ -376,6 +401,7 @@ public void run() {
private boolean sendCommands(CommandSender sender) {
sender.sendMessage(entitySize.getPrimaryColor() +
"/entitysize reload (Reload config)\n" +
"/entitysize add <size> (Add or subtract from your current size)\n" +
"/entitysize reset <optional player / @a> (Reset size to default)\n" +
"/entitysize <size> [time] (Change your own size)\n" +
"/entitysize player <player> <size> [time]\n" +
Expand All @@ -399,6 +425,7 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
List<String> commands = new ArrayList<>();

if (args.length == 1) {
if (hasPermission(sender, entitySize.getPermission("add"))) commands.add("add");
if (hasPermission(sender, entitySize.getPermission("player"))) commands.add("player");
if (hasPermission(sender, entitySize.getPermission("entity"))) commands.add("entity");
if (hasPermission(sender, entitySize.getPermission("reload"))) commands.add("reload");
Expand All @@ -407,6 +434,13 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
StringUtil.copyPartialMatches(args[0], commands, completions);
}

if (args.length == 2) {
if ("add".equalsIgnoreCase(args[0]) && hasPermission(sender, entitySize.getPermission("add"))) {
commands.add("<size>");
}
StringUtil.copyPartialMatches(args[1], commands, completions);
}

if (args.length == 2) {
if(args[0].equalsIgnoreCase("player") && hasPermission(sender, entitySize.getPermission("player"))) {
Bukkit.getOnlinePlayers().forEach(player -> {
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,8 @@ permissions:
description: Allows bypassing size limits
default: op
op: true
entitysize.add:
description: Allows the player to use /entitysize add
default: op
op: true

0 comments on commit 98dc54d

Please sign in to comment.