Advertisement
Camellias_

Untitled

Aug 15th, 2019
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.03 KB | None | 0 0
  1. package com.camellias.gulliverreborn;
  2.  
  3. import java.util.Arrays;
  4. import java.util.Collections;
  5. import java.util.List;
  6. import java.util.UUID;
  7.  
  8. import com.artemis.artemislib.util.attributes.ArtemisLibAttributes;
  9. import com.google.common.collect.HashMultimap;
  10. import com.google.common.collect.Lists;
  11. import com.google.common.collect.Multimap;
  12.  
  13. import net.minecraft.command.CommandBase;
  14. import net.minecraft.command.CommandException;
  15. import net.minecraft.command.ICommandSender;
  16. import net.minecraft.entity.SharedMonsterAttributes;
  17. import net.minecraft.entity.ai.attributes.AttributeModifier;
  18. import net.minecraft.entity.player.EntityPlayer;
  19. import net.minecraft.server.MinecraftServer;
  20. import net.minecraft.util.math.BlockPos;
  21. import net.minecraft.util.math.MathHelper;
  22.  
  23. public class OthersResizeCommand extends CommandBase
  24. {
  25.     private final List<String> aliases = Lists.newArrayList(GulliverReborn.MODID, "basesize", "bs");
  26.     private static UUID uuidHeight = UUID.fromString("5440b01a-974f-4495-bb9a-c7c87424bca4");
  27.     private static UUID uuidWidth = UUID.fromString("3949d2ed-b6cc-4330-9c13-98777f48ea51");
  28.     private static UUID uuidReach1 = UUID.fromString("854e0004-c218-406c-a9e2-590f1846d80b");
  29.     private static UUID uuidReach2 = UUID.fromString("216080dc-22d3-4eff-a730-190ec0210d5c");
  30.     private static UUID uuidHealth = UUID.fromString("3b901d47-2d30-495c-be45-f0091c0f6fb2");
  31.     private static UUID uuidStrength = UUID.fromString("558f55be-b277-4091-ae9b-056c7bc96e84");
  32.     private static UUID uuidSpeed = UUID.fromString("f2fb5cda-3fbe-4509-a0af-4fc994e6aeca");
  33.    
  34.     @Override
  35.     public String getName()
  36.     {
  37.         return "basesize";
  38.     }
  39.  
  40.     @Override
  41.     public String getUsage(ICommandSender sender)
  42.     {
  43.         return "gulliverreborn.commands.basesize.usage";
  44.     }
  45.    
  46.     @Override
  47.     public List<String> getAliases()
  48.     {
  49.         return aliases;
  50.     }
  51.    
  52.     @Override
  53.     public boolean checkPermission(MinecraftServer server, ICommandSender sender)
  54.     {
  55.         return true;
  56.     }
  57.    
  58.     @Override
  59.     public int getRequiredPermissionLevel()
  60.     {
  61.         return 2;
  62.     }
  63.    
  64.     @Override
  65.     public boolean isUsernameIndex(String[] args, int index)
  66.     {
  67.         return index == 0;
  68.     }
  69.    
  70.     @Override
  71.     public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos targetPos)
  72.     {
  73.         if(args.length == 0)
  74.         {
  75.             return Collections.emptyList();
  76.         }
  77.         else if(isUsernameIndex(args, args.length - 1))
  78.         {
  79.             return getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames());
  80.         }
  81.  
  82.         return super.getTabCompletions(server, sender, args, targetPos);
  83.     }
  84.    
  85.     @Override
  86.     public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
  87.     {
  88.         if(args.length < 2) return;
  89.        
  90.         String s = args[1];
  91.         float size = Float.parseFloat(s);
  92.        
  93.         EntityPlayer player = getPlayer(server, sender, args[0]);
  94.        
  95.         size = MathHelper.clamp(size, 0.125F, Config.MAX_SIZE);
  96.         Multimap<String, AttributeModifier> attributes = HashMultimap.create();
  97.         Multimap<String, AttributeModifier> removeableAttributes = HashMultimap.create();
  98.         Multimap<String, AttributeModifier> removeableAttributes2 = HashMultimap.create();
  99.        
  100.         attributes.put(ArtemisLibAttributes.ENTITY_HEIGHT.getName(), new AttributeModifier(uuidHeight, "Player Height", size - 1, 2));
  101.         attributes.put(ArtemisLibAttributes.ENTITY_WIDTH.getName(), new AttributeModifier(uuidWidth, "Player Width", MathHelper.clamp(size - 1, 0.4 - 1, Config.MAX_SIZE), 2));
  102.        
  103.         if(Config.SPEED_MODIFIER) attributes.put(SharedMonsterAttributes.MOVEMENT_SPEED.getName(), new AttributeModifier(uuidSpeed, "Player Speed", (size - 1) / 2, 2));
  104.         if(Config.REACH_MODIFIER) removeableAttributes.put(EntityPlayer.REACH_DISTANCE.getName(), new AttributeModifier(uuidReach1, "Player Reach 1", size - 1, 2));
  105.         if(Config.REACH_MODIFIER) removeableAttributes2.put(EntityPlayer.REACH_DISTANCE.getName(), new AttributeModifier(uuidReach2, "Player Reach 2", -MathHelper.clamp(size - 1, 0.33, Double.MAX_VALUE), 2));
  106.         if(Config.STRENGTH_MODIFIER) attributes.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(uuidStrength, "Player Strength", size - 1, 0));
  107.         if(Config.HEALTH_MODIFIER) attributes.put(SharedMonsterAttributes.MAX_HEALTH.getName(), new AttributeModifier(uuidHealth, "Player Health", (size - 1) * Config.HEALTH_MULTIPLIER, 2));
  108.        
  109.         if(size > 1)
  110.         {
  111.             ((EntityPlayer) sender).getAttributeMap().applyAttributeModifiers(removeableAttributes);
  112.         }
  113.         else
  114.         {
  115.             ((EntityPlayer) sender).getAttributeMap().removeAttributeModifiers(removeableAttributes);
  116.         }
  117.        
  118.         if(size < 1)
  119.         {
  120.             ((EntityPlayer) sender).getAttributeMap().applyAttributeModifiers(removeableAttributes2);
  121.         }
  122.         else
  123.         {
  124.             ((EntityPlayer) sender).getAttributeMap().removeAttributeModifiers(removeableAttributes2);
  125.         }
  126.        
  127.         player.getAttributeMap().applyAttributeModifiers(attributes);
  128.         player.setHealth(player.getMaxHealth());
  129.        
  130.         if(sender instanceof EntityPlayer) GulliverReborn.LOGGER.info(((EntityPlayer) sender).getDisplayNameString() + " set " + player.getDisplayNameString() +"'s size to " + size);
  131.     }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement